]> git.lyx.org Git - lyx.git/blobdiff - src/Painter.C
fix typo that put too many include paths for most people
[lyx.git] / src / Painter.C
index 603ac4e6ed75e5b505e4120bafe65a61e71d90f9..6b8d760bbbb0488b1a24cc5bd41ee7b3a2f7c3a0 100644 (file)
@@ -1,10 +1,9 @@
-// -*- C++ -*-
 /* This file is part of
  * ======================================================
- * 
+ *
  *           LyX, The Document Processor
- *      
- *         Copyright 1998-2000 The LyX Team
+ *
+ *         Copyright 1998-2001 The LyX Team
  *
  *======================================================*/
 
 #pragma implementation
 #endif
 
-#ifdef USE_STL_MEMORY
-#include <memory>
-#endif
-
-#include <cmath>
-
-#include FORMS_H_LOCATION
 #include "Painter.h"
 #include "LString.h"
 #include "debug.h"
 #include "lyxfont.h"
-#include "support/LAssert.h"
-#include "support/lstrings.h"
 #include "WorkArea.h"
 #include "font.h"
 #include "ColorHandler.h"
+#include "lyxrc.h"
+#include "encoding.h"
+#include "language.h"
+
+#include "frontends/GUIRunTime.h"
+#include "graphics/GraphicsImage.h"
+
+#include "support/LAssert.h"
+#include "support/lstrings.h"
+
+#include <boost/smart_ptr.hpp>
+
+#include <cmath>
+
 
 using std::endl;
 using std::max;
 
-Painter::Painter(WorkArea & wa)
-       : PainterBase(wa)
+namespace {
+
+inline
+Display * display()
 {
-       display = fl_display;
+       return GUIRunTime::x11Display();
 }
 
+}
+
+
+Painter::Painter(WorkArea & wa)
+       : PainterBase(wa)
+{}
 
-/* Basic drawing routines */
 
-extern bool Lgb_bug_find_hack;
+// Basic drawing routines
 
 PainterBase & Painter::point(int x, int y, LColor::color c)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "point not called from "
-                               "workarea::workhandler\n";
-               lyxerr.debug() << "Painter drawable: "
-                              << owner.getPixmap() << endl;
-       }
-       
-       XDrawPoint(display, owner.getPixmap(),
+       XDrawPoint(display(), owner.getPixmap(),
                   lyxColorHandler->getGCForeground(c), x, y);
        return *this;
 }
 
 
 PainterBase & Painter::line(int x1, int y1, int x2, int y2,
-                       LColor::color col,
-                       enum line_style ls,
-                       enum line_width lw)
+                           LColor::color col,
+                           enum line_style ls,
+                           enum line_width lw)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "line not called from "
-                               "workarea::workhandler\n";
-               lyxerr.debug() << "Painter drawable: "
-                              << owner.getPixmap() << endl;
-       }
-       
-       XDrawLine(display, owner.getPixmap(), 
+       XDrawLine(display(), owner.getPixmap(),
                  lyxColorHandler->getGCLinepars(ls, lw, col),
                  x1, y1, x2, y2);
        return *this;
@@ -86,33 +81,19 @@ PainterBase & Painter::lines(int const * xp, int const * yp, int np,
                             enum line_style ls,
                             enum line_width lw)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "lines not called from "
-                               "workarea::workhandler\n";
-               lyxerr.debug() << "Painter drawable: "
-                              << owner.getPixmap() << endl;
-       }
-       
-#ifndef HAVE_AUTO_PTR
-       XPoint * points = new XPoint[np];
-#else
-       auto_ptr<XPoint> points(new Xpoint[np]);
-#endif
+       boost::scoped_array<XPoint> points(new XPoint[np]);
+
        for (int i = 0; i < np; ++i) {
                points[i].x = xp[i];
                points[i].y = yp[i];
        }
 
-        XDrawLines(display, owner.getPixmap(),
-                  lyxColorHandler->getGCLinepars(ls, lw, col), 
-                  points, np, CoordModeOrigin);
+       XDrawLines(display(), owner.getPixmap(),
+                  lyxColorHandler->getGCLinepars(ls, lw, col),
+                  points.get(), np, CoordModeOrigin);
 
-#ifndef HAVE_AUTO_PTR
-       delete[] points;
-#endif 
        return *this;
-}      
+}
 
 
 PainterBase & Painter::rectangle(int x, int y, int w, int h,
@@ -120,143 +101,90 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
                                 enum line_style ls,
                                 enum line_width lw)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "rectangle not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: "
-                      << owner.getPixmap() << endl;
-       }
-       
-       XDrawRectangle(display, owner.getPixmap(),
-                      lyxColorHandler->getGCLinepars(ls, lw, col), 
+       XDrawRectangle(display(), owner.getPixmap(),
+                      lyxColorHandler->getGCLinepars(ls, lw, col),
                       x, y, w, h);
        return *this;
 }
 
 
 PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
-                                LColor::color col)
+                                    LColor::color col)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "fillrectangle not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: "
-                      << owner.getPixmap() << endl;
-       }
-       
-       XFillRectangle(display, owner.getPixmap(),
+       XFillRectangle(display(), owner.getPixmap(),
                       lyxColorHandler->getGCForeground(col), x, y, w, h);
        return *this;
 }
 
 
 PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
-                              LColor::color col)
+                                  LColor::color col)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr <<"fillpolygon not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
-       }
-       
-#ifndef HAVE_AUTO_PTR
-       XPoint * points = new XPoint[np];
-#else
-       auto_ptr<XPoint> points(new XPoint[np]);
-#endif
-       for (int i=0; i < np; ++i) {
+       boost::scoped_array<XPoint> points(new XPoint[np]);
+
+       for (int i = 0; i < np; ++i) {
                points[i].x = xp[i];
                points[i].y = yp[i];
        }
 
-       XFillPolygon(display, owner.getPixmap(),
-                    lyxColorHandler->getGCForeground(col), points, np, 
+       XFillPolygon(display(), owner.getPixmap(),
+                    lyxColorHandler->getGCForeground(col), points.get(), np,
                     Nonconvex, CoordModeOrigin);
-#ifndef HAVE_AUTO_PTR
-       delete[] points;
-#endif 
+
        return *this;
-}      
+}
 
 
 PainterBase & Painter::arc(int x, int y,
-                 unsigned int w, unsigned int h,
-                 int a1, int a2, LColor::color col)
+                          unsigned int w, unsigned int h,
+                          int a1, int a2, LColor::color col)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "arc not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
-       }
-       
-        XDrawArc(display, owner.getPixmap(),
+       XDrawArc(display(), owner.getPixmap(),
                 lyxColorHandler->getGCForeground(col),
-                 x, y, w, h, a1, a2);
+                x, y, w, h, a1, a2);
        return *this;
-}     
+}
 
 
 /// Draw lines from x1,y1 to x2,y2. They are arrays
-PainterBase & Painter::segments(int const * x1, int const * y1, 
-                           int const * x2, int const * y2, int ns,
-                           LColor::color col,
-                           enum line_style ls, enum line_width lw)
+PainterBase & Painter::segments(int const * x1, int const * y1,
+                               int const * x2, int const * y2, int ns,
+                               LColor::color col,
+                               enum line_style ls, enum line_width lw)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "segments not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
-       }
-       
-#ifndef HAVE_AUTO_PTR
-       XSegment * s= new XSegment[ns];
-#else
-       auto_ptr<XSegment> s(new XSegment[ns]);
-#endif
-       for (int i=0; i<ns; ++i) {
+       boost::scoped_array<XSegment> s(new XSegment[ns]);
+
+       for (int i = 0; i < ns; ++i) {
                s[i].x1 = x1[i];
                s[i].y1 = y1[i];
                s[i].x2 = x2[i];
                s[i].y2 = y2[i];
        }
-       XDrawSegments(display, owner.getPixmap(),
-                     lyxColorHandler->getGCLinepars(ls, lw, col), s, ns);
+       XDrawSegments(display(), owner.getPixmap(),
+                     lyxColorHandler->getGCLinepars(ls, lw, col),
+                     s.get(), ns);
 
-#ifndef HAVE_AUTO_PTR
-       delete [] s;
-#endif
        return *this;
 }
 
 
-PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
+PainterBase & Painter::image(int x, int y, int w, int h,
+                            grfx::GImage const & image)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "workAreaExpose not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
-       }
-       
        XGCValues val;
        val.function = GXcopy;
-       GC gc = XCreateGC(display, owner.getPixmap(),
+       GC gc = XCreateGC(display(), owner.getPixmap(),
                          GCFunction, &val);
-       XCopyArea(display, bitmap, owner.getPixmap(), gc,
+       XCopyArea(display(), image.getPixmap(), owner.getPixmap(), gc,
                  0, 0, w, h, x, y);
-       XFreeGC(display, gc);
+       XFreeGC(display(), gc);
        return *this;
 }
 
 
 PainterBase & Painter::text(int x, int y, string const & s, LyXFont const & f)
 {
-       return text(x, y, s.c_str(), s.length(), f);
+       return text(x, y, s.data(), s.length(), f);
 }
 
 
@@ -267,57 +195,109 @@ PainterBase & Painter::text(int x, int y, char c, LyXFont const & f)
 }
 
 
-PainterBase & Painter::text(int x, int y, char const * s, int ls,
-                       LyXFont const & f)
+PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
+                           LyXFont const & f)
 {
-       if (lyxerr.debugging()) {
-               if (!Lgb_bug_find_hack)
-                       lyxerr << "text not called from "
-                               "workarea::workhandler\n";
-               lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
+       if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
+               boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
+               Encoding const * encoding = f.language()->encoding();
+               LyXFont font(f);
+               if (f.isSymbolFont()) {
+#ifdef USE_UNICODE_FOR_SYMBOLS
+                       font.setFamily(LyXFont::ROMAN_FAMILY);
+                       font.setShape(LyXFont::UP_SHAPE);
+#endif
+                       encoding = encodings.symbol_encoding();
+               }
+               for (size_t i = 0; i < ls; ++i) {
+                       Uchar c = encoding->ucs(s[i]);
+                       xs[i].byte1 = c >> 8;
+                       xs[i].byte2 = c & 0xff;
+               }
+               text(x , y, xs.get(), ls, font);
+               return *this;
        }
+
        GC gc = lyxColorHandler->getGCForeground(f.realColor());
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
-               lyxfont::XSetFont(display, gc, f);
-               XDrawString(display, owner.getPixmap(), gc, x, y, s, ls);
+               lyxfont::XSetFont(display(), gc, f);
+               XDrawString(display(), owner.getPixmap(), gc, x, y, s, ls);
        } else {
                LyXFont smallfont(f);
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
-               char c;
                int tmpx = x;
-               for(int i = 0; i < ls; ++i) {
-                       c = s[i];
-                       if (islower(static_cast<unsigned char>(c))) {
-                               c = toupper(c);
-                               lyxfont::XSetFont(display, gc, smallfont);
-                               XDrawString(display, owner.getPixmap(),
-                                           gc, tmpx, y, &c, 1);
+               for (size_t i = 0; i < ls; ++i) {
+                       char const c = uppercase(s[i]);
+                       if (c != s[i]) {
+                               lyxfont::XSetFont(display(), gc, smallfont);
+                               XDrawString(display(), owner.getPixmap(), gc,
+                                           tmpx, y, &c, 1);
                                tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
-                               //tmpx += lyxfont::width(c, f);
                        } else {
-                               lyxfont::XSetFont(display, gc, f);
-                               XDrawString(display, owner.getPixmap(),
-                                           gc, tmpx, y, &c, 1);
+                               lyxfont::XSetFont(display(), gc, f);
+                               XDrawString(display(), owner.getPixmap(), gc,
+                                           tmpx, y, &c, 1);
                                tmpx += lyxfont::XTextWidth(f, &c, 1);
-                               //tmpx += lyxfont::width(c, f);
                        }
                }
        }
-       underline(f, x, y, lyxfont::width(s, ls, f));
+
+       if (f.underbar() == LyXFont::ON) {
+               underline(f, x, y, lyxfont::width(s, ls, f));
+       }
+
        return *this;
 }
 
 
-void Painter::underline(LyXFont const & f, int x, int y, int width)
+PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
+                           LyXFont const & f)
 {
-       // What about underbars?
-       if (f.underbar() == LyXFont::ON && f.latex() != LyXFont::ON) {
-               int below = max(lyxfont::maxDescent(f) / 2, 2);
-               int height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
-               if (height < 2)
-                       line(x, y + below, x + width, y + below, f.color());
-               else
-                       fillRectangle(x, y + below, width, below + height,
-                                     f.color());
+       GC gc = lyxColorHandler->getGCForeground(f.realColor());
+       if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               lyxfont::XSetFont(display(), gc, f);
+               XDrawString16(display(), owner.getPixmap(), gc, x, y, s, ls);
+       } else {
+               LyXFont smallfont(f);
+               smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
+               static XChar2b c;
+               int tmpx = x;
+               for (int i = 0; i < ls; ++i) {
+                       if (s[i].byte1)
+                               c = s[i];
+                       else {
+                               c.byte1 = s[i].byte1;
+                               c.byte2 = uppercase(s[i].byte2);
+                       }
+                       if (c.byte2 != s[i].byte2) {
+                               lyxfont::XSetFont(display(), gc, smallfont);
+                               XDrawString16(display(), owner.getPixmap(), gc,
+                                             tmpx, y, &c, 1);
+                               tmpx += lyxfont::XTextWidth16(smallfont, &c, 1);
+                       } else {
+                               lyxfont::XSetFont(display(), gc, f);
+                               XDrawString16(display(), owner.getPixmap(), gc,
+                                             tmpx, y, &c, 1);
+                               tmpx += lyxfont::XTextWidth16(f, &c, 1);
+                       }
+               }
        }
+
+       if (f.underbar() == LyXFont::ON) {
+               underline(f, x, y, lyxfont::width(s, ls, f));
+       }
+
+       return *this;
+}
+
+
+void Painter::underline(LyXFont const & f, int x, int y, int width)
+{
+       int const below = max(lyxfont::maxDescent(f) / 2, 2);
+       int const height = max((lyxfont::maxDescent(f) / 4) - 1, 1);
+       if (height < 2)
+               line(x, y + below, x + width, y + below, f.color());
+       else
+               fillRectangle(x, y + below, width, below + height,
+                             f.color());
 }