]> git.lyx.org Git - lyx.git/blobdiff - src/Painter.C
Small fixes
[lyx.git] / src / Painter.C
index cb0cd4e740fac0f81cbde9d61933dce9b9d531ca..34f54f2a33bd6ec142fd8fcb9c005cd2b32f56ba 100644 (file)
 #include "lyxrc.h"
 #include "encoding.h"
 
+#include "frontends/support/LyXImage.h"
+
 using std::endl;
 using std::max;
 
 Painter::Painter(WorkArea & wa)
        : PainterBase(wa)
 {
-       display = fl_display;
+       display = fl_get_display();
 }
 
 
@@ -49,7 +51,7 @@ 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";
@@ -68,7 +70,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";
@@ -88,7 +90,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";
@@ -122,7 +124,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";
@@ -140,7 +142,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";
@@ -157,7 +159,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";
@@ -188,7 +190,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";
@@ -208,7 +210,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";
@@ -235,16 +237,15 @@ PainterBase & Painter::segments(int const * x1, int const * y1,
        return *this;
 }
 
-
 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";
                lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
        }
-       
+
        XGCValues val;
        val.function = GXcopy;
        GC gc = XCreateGC(display, owner.getPixmap(),
@@ -255,6 +256,13 @@ PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
        return *this;
 }
 
+PainterBase & Painter::image(int x, int y, int w, int h, LyXImage const * image)
+{
+       Pixmap bitmap = image->getPixmap();
+
+       return pixmap(x, y, w, h, bitmap);
+}
+
 
 PainterBase & Painter::text(int x, int y, string const & s, LyXFont const & f)
 {
@@ -269,23 +277,31 @@ PainterBase & Painter::text(int x, int y, char c, LyXFont const & f)
 }
 
 
-PainterBase & Painter::text(int x, int y, char const * s, int ls,
+PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
                        LyXFont const & f)
 {
        if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
                XChar2b * xs = new XChar2b[ls];
-               Encoding const * enc = f.language()->encoding();
-               for (int i = 0; i < ls; ++i) {
-                       Uchar c = enc->ucs(s[i]);
+               Encoding const * encoding = f.language()->encoding();
+               LyXFont font(f);
+               if (f.family() == LyXFont::SYMBOL_FAMILY) {
+#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, ls, f);
+               }
+               text(x , y, xs, ls, font);
                delete[] xs;
                return *this;
        }
 
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "text not called from "
                                "workarea::workhandler\n";
@@ -300,7 +316,7 @@ PainterBase & Painter::text(int x, int y, char const * s, int ls,
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
                char c;
                int tmpx = x;
-               for(int i = 0; i < ls; ++i) {
+               for (size_t i = 0; i < ls; ++i) {
                        c = s[i];
                        if (islower(static_cast<unsigned char>(c))) {
                                c = toupper(c);
@@ -308,13 +324,11 @@ 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);
                        }
                }
        }
@@ -327,7 +341,7 @@ PainterBase & Painter::text(int x, int y, char const * s, int ls,
 PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
                        LyXFont const & f)
 {
-       if (lyxerr.debugging()) {
+       if (lyxerr.debugging(Debug::GUI)) {
                if (!Lgb_bug_find_hack)
                        lyxerr << "text not called from "
                                "workarea::workhandler\n";
@@ -342,7 +356,7 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
                smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
                static XChar2b c = {0, 0};
                int tmpx = x;
-               for(int i = 0; i < ls; ++i) {
+               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);