]> git.lyx.org Git - lyx.git/blobdiff - src/Painter.C
citation patch from Angus
[lyx.git] / src / Painter.C
index b638691601f259d1424b79e0b799204f03cc207f..d3216b9ef93c27515be46b26e61ed2cb63aa1079 100644 (file)
@@ -30,6 +30,8 @@
 #include "WorkArea.h"
 #include "font.h"
 #include "ColorHandler.h"
+#include "lyxrc.h"
+#include "encoding.h"
 
 using std::endl;
 using std::max;
@@ -41,16 +43,13 @@ Painter::Painter(WorkArea & wa)
 }
 
 
-Painter::~Painter() {}
-
-
 /* Basic drawing routines */
 
 extern bool Lgb_bug_find_hack;
 
 PainterBase & Painter::point(int x, int y, LColor::color c)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "point not called from "
                                "workarea::workhandler\n";
@@ -69,7 +68,7 @@ PainterBase & Painter::line(int x1, int y1, int x2, int y2,
                        enum line_style ls,
                        enum line_width lw)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "line not called from "
                                "workarea::workhandler\n";
@@ -89,7 +88,7 @@ PainterBase & Painter::lines(int const * xp, int const * yp, int np,
                             enum line_style ls,
                             enum line_width lw)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "lines not called from "
                                "workarea::workhandler\n";
@@ -123,7 +122,7 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
                                 enum line_style ls,
                                 enum line_width lw)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "rectangle not called from "
                                "workarea::workhandler\n";
@@ -141,7 +140,7 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
 PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
                                 LColor::color col)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "fillrectangle not called from "
                                "workarea::workhandler\n";
@@ -158,7 +157,7 @@ PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
 PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
                               LColor::color col)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr <<"fillpolygon not called from "
                                "workarea::workhandler\n";
@@ -189,7 +188,7 @@ PainterBase & Painter::arc(int x, int y,
                  unsigned int w, unsigned int h,
                  int a1, int a2, LColor::color col)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "arc not called from "
                                "workarea::workhandler\n";
@@ -209,7 +208,7 @@ PainterBase & Painter::segments(int const * x1, int const * y1,
                            LColor::color col,
                            enum line_style ls, enum line_width lw)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "segments not called from "
                                "workarea::workhandler\n";
@@ -239,7 +238,7 @@ PainterBase & Painter::segments(int const * x1, int const * y1,
 
 PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "workAreaExpose not called from "
                                "workarea::workhandler\n";
@@ -273,7 +272,30 @@ 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)
 {
-       if (lyxerr.debugging()) {
+       if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
+               XChar2b * xs = new XChar2b[ls];
+               Encoding const * encoding = f.language()->encoding();
+               LyXFont const * font = &f; 
+               if (f.family() == LyXFont::SYMBOL_FAMILY) {
+#ifdef USE_UNICODE_FOR_SYMBOLS
+                       LyXFont font2 = f;
+                       font2.setFamily(LyXFont::ROMAN_FAMILY);
+                       font2.setShape(LyXFont::UP_SHAPE);
+                       font = &font2;
+#endif
+                       encoding = &symbol_encoding;
+               }
+               for (int 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, ls, *font);
+               delete[] xs;
+               return *this;
+       }
+
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "text not called from "
                                "workarea::workhandler\n";
@@ -296,31 +318,66 @@ PainterBase & Painter::text(int x, int y, char const * s, int ls,
                                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);
                                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 && f.latex() != 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());
+       if (lyxerr.debugging(Debug::GUI)) {
+               if (!Lgb_bug_find_hack)
+                       lyxerr << "text not called from "
+                               "workarea::workhandler\n";
+               lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
+       }
+       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 = {0, 0};
+               int tmpx = x;
+               for(int i = 0; i < ls; ++i) {
+                       if (s[i].byte1 == 0 && islower(s[i].byte2)) {
+                               c.byte2 = toupper(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, &s[i], 1);
+                               tmpx += lyxfont::XTextWidth16(f, const_cast<XChar2b *>(&s[i]), 1);
+                       }
+               }
        }
+       if (f.underbar() == LyXFont::ON && f.latex() != 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 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());
 }