]> git.lyx.org Git - features.git/blobdiff - src/lyxfont.C
new painter,workarea and lcolor. Read the diff/sources and ChangeLog...
[features.git] / src / lyxfont.C
index d7231df75a453c7ad2600294a021cfa9f9293203..82c42aec7a26e5231e1edca3a296822433e72280 100644 (file)
@@ -62,11 +62,14 @@ string const GUIMiscNames[5] =
 string const GUIDirectionNames[5] = 
 { N_("LTR"), N_("RTL"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
 
+
+#ifndef USE_PAINTER
 string const GUIColorNames[13] = 
 { N_("None"), N_("Black"), N_("White"), N_("Red"), N_("Green"), N_("Blue"),
   N_("Cyan"), N_("Magenta"), 
   N_("Yellow"), N_("Math"), N_("Inset"), N_("Inherit"), N_("Ignore") };
+#endif
+
 //
 // Strings used to read and write .lyx format files
 //
@@ -87,9 +90,11 @@ string const LyXSizeNames[14] =
 string const LyXMiscNames[12] = 
 { "off", "on", "toggle", "default", "error" };
 
+#ifndef USE_PAINTER
 string const LyXColorNames[13] = 
 { "none", "black", "white", "red", "green", "blue", "cyan", "magenta", 
   "yellow", "matherror", "inseterror", "default", "error" };
+#endif
 
 //
 // Strings used to write LaTeX files
@@ -107,10 +112,59 @@ string const LaTeXShapeNames[6] =
 string const LaTeXSizeNames[14] = 
 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
   "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
+
+#ifndef USE_PAINTER
 string const LaTeXColorNames[13] = 
 { "none", "black", "white", "red", "green", "blue", "cyan", "magenta", 
   "yellow", "error12", "error13", "error14", "error15" };
+#endif
+
+#ifdef NEW_BITS
+LyXFont::FontBits LyXFont::sane = { ROMAN_FAMILY,
+                 MEDIUM_SERIES,
+                 UP_SHAPE,
+                 SIZE_NORMAL,
+#ifdef USE_PAINTER
+                 LColor::none,
+#else
+                 NONE,
+#endif
+                 OFF,
+                 OFF,
+                 OFF,
+                 OFF,
+                 LTR_DIR };
+
+LyXFont::FontBits LyXFont::inherit = { INHERIT_FAMILY, 
+                     INHERIT_SERIES, 
+                     INHERIT_SHAPE, 
+                     INHERIT_SIZE,
+#ifdef USE_PAINTER
+                     LColor::inherit,
+#else
+                     INHERIT_COLOR,
+#endif
+                     INHERIT,
+                     INHERIT,
+                     INHERIT,
+                     INHERIT,
+                     INHERIT_DIR };
+
+LyXFont::FontBits LyXFont::ignore = { IGNORE_FAMILY,
+                    IGNORE_SERIES,
+                    IGNORE_SHAPE,
+                    IGNORE_SIZE,
+#ifdef USE_PAINTER
+                    LColor::ignore,
+#else
+                    IGNORE_COLOR,
+#endif
+                    IGNORE,
+                    IGNORE,
+                    IGNORE,
+                    IGNORE,
+                    IGNORE_DIR };
+#endif
 
 /// Decreases font size by one
 LyXFont & LyXFont::decSize() 
@@ -139,7 +193,7 @@ LyXFont & LyXFont::decSize()
                lyxerr <<"Can't LyXFont::decSize on IGNORE_SIZE" << endl;
                break;
        }
-       return (*this);
+       return *this;
 }
 
 
@@ -170,7 +224,7 @@ LyXFont & LyXFont::incSize()
                lyxerr <<"Can't LyXFont::incSize on IGNORE_SIZE" << endl;
                break;
        }
-       return (*this);
+       return *this;
 }
 
 
@@ -256,10 +310,17 @@ void LyXFont::update(LyXFont const & newfont, bool toggleall)
                setDirection(newfont.direction());
        }
 
+#ifdef USE_PAINTER
+       if(newfont.color() == color() && toggleall)
+               setColor(LColor::inherit); // toggle 'back'
+       else if (newfont.color() != LColor::ignore)
+               setColor(newfont.color());
+#else
        if(newfont.color() == color() && toggleall)
-               setColor(INHERIT_COLOR); // toggle 'back'
-       else if (newfont.color() != IGNORE_COLOR)
+               setColor(LyXFont::INHERIT_COLOR); // toggle 'back'
+       else if (newfont.color() != LyXFont::IGNORE_COLOR)
                setColor(newfont.color());
+#endif
 }
 
 
@@ -282,8 +343,13 @@ void LyXFont::reduce(LyXFont const & tmplt)
                setNoun(INHERIT);
        if (latex() == tmplt.latex())
                setLatex(INHERIT);
+#ifdef USE_PAINTER
        if (color() == tmplt.color())
-               setColor(INHERIT_COLOR);
+               setColor(LColor::inherit);
+#else
+       if (color() == tmplt.color())
+               setColor(LyXFont::INHERIT_COLOR);
+#endif
        if (direction() == tmplt.direction())
                setDirection(INHERIT_DIR);
 }
@@ -291,6 +357,54 @@ void LyXFont::reduce(LyXFont const & tmplt)
 
 /// Realize font from a template
 // This one is not pretty, but it's extremely fast (Asger)
+#ifdef NEW_BITS
+LyXFont & LyXFont::realize(LyXFont const & tmplt)
+{
+       if (bits == inherit) {
+               bits = tmplt.bits;
+               return *this;
+       }
+       
+       if (bits.family == INHERIT_FAMILY) {
+               bits.family = tmplt.bits.family;
+       }
+       if (bits.series == INHERIT_SERIES) {
+               bits.series = tmplt.bits.series;
+       }
+       if (bits.shape == INHERIT_SHAPE) {
+               bits.shape = tmplt.bits.shape;
+       }
+       if (bits.size == INHERIT_SIZE) {
+               bits.size = tmplt.bits.size;
+       }
+       if (bits.emph == INHERIT) {
+               bits.emph = tmplt.bits.emph;
+       }
+       if (bits.underbar == INHERIT) {
+               bits.underbar = tmplt.bits.underbar;
+       }
+       if (bits.noun == INHERIT) {
+               bits.noun = tmplt.bits.noun;
+       }
+       if (bits.latex == INHERIT) {
+               bits.latex = tmplt.bits.latex;
+       }
+#ifdef USE_PAINTER
+       if (bits.color == LColor::inherit) {
+               bits.color = tmplt.bits.color;
+       }
+#else
+       if (bits.color == INHERIT_COLOR) {
+               bits.color = tmplt.bits.color;
+       }
+#endif
+       if (bits.direction == INHERIT_DIR) {
+               bits.direction = tmplt.bits.direction;
+       }
+
+       return *this;
+}
+#else
 LyXFont & LyXFont::realize(LyXFont const & tmplt)
 {
        if (bits == inherit) {
@@ -338,11 +452,19 @@ LyXFont & LyXFont::realize(LyXFont const & tmplt)
                        bits &= ~(Misc_Mask << Lat_Pos);
                        bits |= (tmplt.bits & Misc_Mask << Lat_Pos);
                }
+#ifdef USE_PAINTER
+       if ((bits & (Col_Mask << Col_Pos)) == ui32(LColor::inherit) << Col_Pos)
+               {
+                       bits &= ~(Col_Mask << Col_Pos);
+                       bits |= (tmplt.bits & Col_Mask << Col_Pos);
+               }
+#else
        if ((bits & (Col_Mask << Col_Pos)) == ui32(INHERIT_COLOR) << Col_Pos)
                {
                        bits &= ~(Col_Mask << Col_Pos);
                        bits |= (tmplt.bits & Col_Mask << Col_Pos);
                }
+#endif
        if ((bits & (Dir_Mask << Dir_Pos)) == ui32(INHERIT_DIR) << Dir_Pos)
                {
                        bits &= ~(Dir_Mask << Dir_Pos);
@@ -351,9 +473,21 @@ LyXFont & LyXFont::realize(LyXFont const & tmplt)
 
        return *this;
 }
+#endif
 
 
 /// Is font resolved?
+#ifdef USE_PAINTER
+bool LyXFont::resolved() const
+{
+       return (family() != INHERIT_FAMILY && series() != INHERIT_SERIES &&
+               shape() != INHERIT_SHAPE && size() != INHERIT_SIZE &&
+               emph() != INHERIT && underbar() != INHERIT && 
+               noun() != INHERIT && latex() != INHERIT && 
+               color() != LColor::inherit &&
+               direction() != INHERIT_DIR);
+}
+#else
 bool LyXFont::resolved() const
 {
        return (family() != INHERIT_FAMILY && series() != INHERIT_SERIES &&
@@ -363,6 +497,7 @@ bool LyXFont::resolved() const
                color() != INHERIT_COLOR &&
                direction() != INHERIT_DIR);
 }
+#endif
 
 
 /// Build GUI description of font state
@@ -377,9 +512,13 @@ string LyXFont::stateText() const
                buf += string(_(GUIShapeNames[shape()].c_str())) + ", ";
        if (size() != INHERIT_SIZE)
                buf += string(_(GUISizeNames[size()].c_str())) + ", ";
+#ifdef USE_PAINTER
+       if (color() != LColor::inherit)
+               buf += lcolor.getGUIName(color()) + ", ";
+#else
        if (color() != INHERIT_COLOR)
                buf += string(_(GUIColorNames[color()].c_str())) + ", ";
+#endif
        if (emph() != INHERIT)
                buf += string(_("Emphasis ")) + _(GUIMiscNames[emph()].c_str()) + ", ";
        if (underbar() != INHERIT)
@@ -476,6 +615,9 @@ LyXFont::FONT_MISC_STATE LyXFont::setLyXMisc(string const & siz)
 /// Sets color after LyX text format
 LyXFont & LyXFont::setLyXColor(string const & col)
 {
+#ifdef USE_PAINTER
+       setColor(lcolor.getFromLyXName(col));
+#else
        string s = lowercase(col);
        int i= 0;
        while (s != LyXColorNames[i] && LyXColorNames[i] != "error") ++i;
@@ -484,6 +626,7 @@ LyXFont & LyXFont::setLyXColor(string const & col)
        } else
                lyxerr << "LyXFont::setLyXColor: Unknown Color `"
                       << s << '\'' << endl;
+#endif
        return *this;
 }
 
@@ -491,6 +634,12 @@ LyXFont & LyXFont::setLyXColor(string const & col)
 /// Sets size after GUI name
 LyXFont & LyXFont::setGUISize(string const & siz)
 {
+#ifdef USE_PAINTER
+       /// ??????
+       // this is how it was how it was done in the lyx repository...
+       // but this does not make sense.
+       setColor(lcolor.getFromGUIName(siz));
+#else
        string s = lowercase(siz);
        int i = 0;
        while (!lGUISizeNames[i].empty() &&
@@ -501,6 +650,7 @@ LyXFont & LyXFont::setGUISize(string const & siz)
        } else
                lyxerr << "LyXFont::setGUISize: Unknown Size `"
                       << s << '\'' << endl;
+#endif
        return *this;
 }
 
@@ -592,7 +742,7 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
                        error = true;
                }
        }
-       return * this;
+       return *this;
 }
 
 
@@ -650,9 +800,15 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const
                break;
                }
        }
+#ifdef USE_PAINTER
+       if (orgfont.color() != color()) {
+               os << "\\color " << lcolor.getLyXName(color()) << "\n";
+       }
+#else
        if (orgfont.color() != color()) {
                os << "\\color " << LyXColorNames[color()] << "\n";
        }
+#endif
        if (orgfont.direction() != direction()) {
                switch (direction()) {
                case RTL_DIR:   os << "\\direction rtl \n"; break;
@@ -672,7 +828,8 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const
 
 /// Writes the head of the LaTeX needed to impose this font
 // Returns number of chars written.
-int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base, LyXFont const & prev) const
+int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base,
+                                   LyXFont const & prev) const
 {
        LyXFont f = *this;
        f.reduce(base);
@@ -718,6 +875,15 @@ int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base, LyXFont
                count += LaTeXShapeNames[f.shape()].length() + 2;
                env = true; //We have opened a new environment
        }
+#ifdef USE_PAINTER
+       if (f.color() != LColor::inherit) {
+               file += "\\textcolor{";
+               file += lcolor.getLaTeXName(f.color());
+               file += "}{";
+               count += lcolor.getLaTeXName(f.color()).length() + 13;
+               env = true; //We have opened a new environment
+       }
+#else
        if (f.color() != INHERIT_COLOR) {
                file += "\\textcolor{";
                file += LaTeXColorNames[f.color()];
@@ -725,6 +891,7 @@ int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base, LyXFont
                count += LaTeXColorNames[f.color()].length() + 13;
                env = true; //We have opened a new environment
        }
+#endif
        if (f.emph() == ON) {
                file += "\\emph{";
                count += 6;
@@ -759,7 +926,8 @@ int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base, LyXFont
 /// Writes ending block of LaTeX needed to close use of this font
 // Returns number of chars written
 // This one corresponds to latexWriteStartChanges(). (Asger)
-int LyXFont::latexWriteEndChanges(string & file, LyXFont const & base, LyXFont const & next) const
+int LyXFont::latexWriteEndChanges(string & file, LyXFont const & base,
+                                 LyXFont const & next) const
 {
        LyXFont f = *this; // why do you need this?
        f.reduce(base); // why isn't this just "reduce(base);" (Lgb)
@@ -796,11 +964,19 @@ int LyXFont::latexWriteEndChanges(string & file, LyXFont const & base, LyXFont c
                ++count;
                env = true; // Size change need not bother about closing env.
        }
+#ifdef USE_PAINTER
+       if (f.color() != LColor::inherit) {
+               file += '}';
+               ++count;
+               env = true; // Size change need not bother about closing env.
+       }
+#else
        if (f.color() != INHERIT_COLOR) {
                file += '}';
                ++count;
                env = true; // Size change need not bother about closing env.
        }
+#endif
        if (f.emph() == ON) {
                file += '}';
                ++count;
@@ -828,6 +1004,18 @@ int LyXFont::latexWriteEndChanges(string & file, LyXFont const & base, LyXFont c
 }
 
 
+#ifdef USE_PAINTER
+LColor::color LyXFont::realColor() const
+{
+       if (latex() == ON)
+               return LColor::latex;
+       if (color() == LColor::none)
+               return LColor::foreground;
+       return color();
+}
+#endif
+
+
 // Convert logical attributes to concrete shape attribute
 LyXFont::FONT_SHAPE LyXFont::realShape() const
 {
@@ -845,6 +1033,7 @@ LyXFont::FONT_SHAPE LyXFont::realShape() const
 }
 
 
+#ifndef USE_PAINTER
 GC LyXFont::getGC() const
 {
        GC gc;
@@ -864,6 +1053,7 @@ GC LyXFont::getGC() const
        XSetFont(fl_display, gc, getXFontstruct()->fid);
        return gc;
 }
+#endif
 
 
 XFontStruct * LyXFont::getXFontstruct() const
@@ -991,6 +1181,53 @@ int LyXFont::signedStringWidth(string const & s) const
 }
 
 
+#ifdef USE_PAINTER
+int LyXFont::drawText(char const * s, int n, Pixmap, 
+                     int, int x) const
+{
+       if (realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               /* XDrawString(fl_display,
+                  pm,
+                  getGC(),
+                  x, baseline,
+                  s, n);
+                  XFlush(fl_display); */
+               return XTextWidth(getXFontstruct(), s, n);
+
+       } else {
+               // emulate smallcaps since X doesn't support this
+               char c;
+               int sx = x;
+               LyXFont smallfont = *this;
+               smallfont.decSize();
+               smallfont.decSize();
+               smallfont.setShape(LyXFont::UP_SHAPE);
+               for (int i = 0; i < n; ++i) {
+                       c = s[i];
+                       if (islower(static_cast<unsigned char>(c))){
+                               c = toupper(c);
+                               /* XDrawString(fl_display,
+                                  pm,
+                                  smallfont.getGC(),
+                                  x, baseline,
+                                  &c, 1); */
+                               x += XTextWidth(smallfont.getXFontstruct(),
+                                               &c, 1);
+                               //XFlush(fl_display);
+                       } else {
+                               /* XDrawString(fl_display,
+                                  pm,
+                                  getGC(),
+                                  x, baseline,
+                                  &c, 1);*/
+                               x += XTextWidth(getXFontstruct(), &c, 1);
+                               //XFlush(fl_display);
+                       }
+               }
+               return x - sx;
+       }
+}
+#else
 int LyXFont::drawText(char const * s, int n, Pixmap pm, 
                      int baseline, int x) const
 {
@@ -1036,6 +1273,7 @@ int LyXFont::drawText(char const * s, int n, Pixmap pm,
                return x - sx;
        }
 }
+#endif
 
 
 int LyXFont::drawString(string const & s, Pixmap pm, int baseline, int x) const