]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfont.C
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / lyxfont.C
index 17ba20c572b79cd33e2a7fe904cfc1fe41790b7d..d6ec93f0fc6cdb92f589d31daaab08d8762f1638 100644 (file)
@@ -1,35 +1,30 @@
 /* This file is part of
-* ======================================================
-* 
-*           LyX, The Document Processor
-*       
-         Copyright (C) 1995 Matthias Ettrich
-*           Copyright (C) 1995-1998 The LyX Team.
-*
-*======================================================*/
+ * ======================================================
+ 
+ *           LyX, The Document Processor
+ *      
+ *         Copyright (C) 1995 Matthias Ettrich
+ *          Copyright (C) 1995-1999 The LyX Team.
+ *
+ * ======================================================*/
 
 #include <config.h>
-#include <locale.h>
+#include <clocale>
 
 #ifdef __GNUG__
 #pragma implementation "lyxfont.h"
 #endif
 
-#include <ctype.h>
+#include <cctype>
 #include "gettext.h"
 #include "definitions.h"
 #include "lyxfont.h"
-#include "error.h"
+#include "debug.h"
 #include "lyxrc.h"
 #include "lyxlex.h"
 #include "lyxdraw.h"
 #include "FontLoader.h"
-
-//     $Id: lyxfont.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $   
-
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: lyxfont.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $";
-#endif /* lint */
+#include "support/lstrings.h"
 
 extern LyXRC * lyxrc;
 
@@ -40,31 +35,31 @@ FontLoader fontloader;
 // Names for the GUI
 //
 
-LString const GUIFamilyNames[6] =
+string const GUIFamilyNames[6] =
 { N_("Roman"), N_("Sans serif"), N_("Typewriter"), N_("Symbol"), N_("Inherit"),
     N_("Ignore") };
   
-LString const GUISeriesNames[4] =
+string const GUISeriesNames[4] =
 { N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") };
 
-LString const GUIShapeNames[6] =
+string const GUIShapeNames[6] =
 { N_("Upright"), N_("Italic"), N_("Slanted"), N_("Smallcaps"), N_("Inherit"),
     N_("Ignore") };
 
-LString const GUISizeNames[14] =
+string const GUISizeNames[14] =
 { N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"),
   N_("Larger"), N_("Largest"), N_("Huge"), N_("Huger"), N_("Increase"), N_("Decrease"), 
   N_("Inherit"), N_("Ignore") };
  
-LString const lGUISizeNames[15] =
+string const lGUISizeNames[15] =
 { N_("tiny"), N_("smallest"), N_("smaller"), N_("small"), N_("normal"), N_("large"),
   N_("larger"), N_("largest"), N_("huge"), N_("huger"), N_("increase"), N_("decrease"),
-  N_("inherit"), N_("ignore"), LString() };
+  N_("inherit"), N_("ignore"), string() };
  
-LString const GUIMiscNames[5] = 
+string const GUIMiscNames[5] = 
 { N_("Off"), N_("On"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
 
-LString const GUIColorNames[13] = 
+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") };
@@ -72,24 +67,24 @@ LString const GUIColorNames[13] =
 //
 // Strings used to read and write .lyx format files
 //
-LString const LyXFamilyNames[6] =
+string const LyXFamilyNames[6] =
 { "roman", "sans", "typewriter", "symbol", "default", "error" };
  
-LString const LyXSeriesNames[4] =
+string const LyXSeriesNames[4] =
 { "medium", "bold", "default", "error" };
  
-LString const LyXShapeNames[6] = 
+string const LyXShapeNames[6] = 
 { "up", "italic", "slanted", "smallcaps", "default", "error" };
  
-LString const LyXSizeNames[14] =
+string const LyXSizeNames[14] =
 { "tiny", "scriptsize", "footnotesize", "small", "normal", "large",
   "larger", "largest", "huge", "giant", 
   "increase-error", "decrease-error", "default", "error" };
 
-LString const LyXMiscNames[12] =
+string const LyXMiscNames[12] =
 { "off", "on", "toggle", "default", "error" };
 
-LString const LyXColorNames[13] =
+string const LyXColorNames[13] =
 { "none", "black", "white", "red", "green", "blue", "cyan", "magenta", 
   "yellow", "matherror", "inseterror", "default", "error" };
 
@@ -97,20 +92,20 @@ LString const LyXColorNames[13] =
 // Strings used to write LaTeX files
 //
 
-LString const LaTeXFamilyNames[6] =
+string const LaTeXFamilyNames[6] =
 { "textrm", "textsf", "texttt", "error1", "error2", "error3" };
  
-LString const LaTeXSeriesNames[4] =
+string const LaTeXSeriesNames[4] =
 { "textmd", "textbf", "error4", "error5" };
  
-LString const LaTeXShapeNames[6] =
+string const LaTeXShapeNames[6] =
 { "textup", "textit", "textsl", "textsc", "error6", "error7" };
  
-LString const LaTeXSizeNames[14] =
+string const LaTeXSizeNames[14] =
 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
   "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
  
-LString const LaTeXColorNames[13] =
+string const LaTeXColorNames[13] =
 { "none", "black", "white", "red", "green", "blue", "cyan", "magenta", 
   "yellow", "error12", "error13", "error14", "error15" };
 
@@ -129,16 +124,16 @@ LyXFont& LyXFont::decSize()
        case SIZE_SCRIPT:       setSize(SIZE_TINY);     break;
        case SIZE_TINY:         break;
        case INCREASE_SIZE:
-               lyxerr.print("Can't LyXFont::decSize on INCREASE_SIZE");
+               lyxerr << "Can't LyXFont::decSize on INCREASE_SIZE" << endl;
                break;
        case DECREASE_SIZE:
-               lyxerr.print("Can't LyXFont::decSize on DECREASE_SIZE");
+               lyxerr <<"Can't LyXFont::decSize on DECREASE_SIZE" << endl;
                break;
        case INHERIT_SIZE:
-               lyxerr.print("Can't LyXFont::decSize on INHERIT_SIZE");
+               lyxerr <<"Can't LyXFont::decSize on INHERIT_SIZE" << endl;
                break;
        case IGNORE_SIZE:
-               lyxerr.print("Can't LyXFont::decSize on IGNORE_SIZE");
+               lyxerr <<"Can't LyXFont::decSize on IGNORE_SIZE" << endl;
                break;
        }
        return (*this);
@@ -160,16 +155,16 @@ LyXFont& LyXFont::incSize()
        case SIZE_SCRIPT:       setSize(SIZE_FOOTNOTE); break;
        case SIZE_TINY:         setSize(SIZE_SCRIPT);   break;
        case INCREASE_SIZE:
-               lyxerr.print("Can't LyXFont::incSize on INCREASE_SIZE");
+               lyxerr <<"Can't LyXFont::incSize on INCREASE_SIZE" << endl;
                break;
        case DECREASE_SIZE:
-               lyxerr.print("Can't LyXFont::incSize on DECREASE_SIZE");
+               lyxerr <<"Can't LyXFont::incSize on DECREASE_SIZE" << endl;
                break;
        case INHERIT_SIZE:
-               lyxerr.print("Can't LyXFont::incSize on INHERIT_SIZE");
+               lyxerr <<"Can't LyXFont::incSize on INHERIT_SIZE" << endl;
                break;
        case IGNORE_SIZE:
-               lyxerr.print("Can't LyXFont::incSize on IGNORE_SIZE");
+               lyxerr <<"Can't LyXFont::incSize on IGNORE_SIZE" << endl;
                break;
        }
        return (*this);
@@ -186,8 +181,8 @@ LyXFont::FONT_MISC_STATE LyXFont::setMisc(FONT_MISC_STATE newfont,
                else if (org == OFF)
                        return ON;
                else {
-                       lyxerr.print("LyXFont::setMisc: Need state"
-                                     " ON or OFF to toggle. Setting to ON");
+                       lyxerr <<"LyXFont::setMisc: Need state"
+                               " ON or OFF to toggle. Setting to ON" << endl;
                        return ON;
                }
        } else if (newfont == IGNORE)
@@ -345,128 +340,130 @@ bool LyXFont::resolved() const
 }
 
 /// Build GUI description of font state
-LString LyXFont::stateText() const
+string LyXFont::stateText() const
 {
-       LString buf;
+       string buf;
        if (family() != INHERIT_FAMILY)
-               buf += LString(_(GUIFamilyNames[family()].c_str())) + ", ";
+               buf += string(_(GUIFamilyNames[family()].c_str())) + ", ";
        if (series() != INHERIT_SERIES)
-               buf += LString(_(GUISeriesNames[series()].c_str())) + ", ";
+               buf += string(_(GUISeriesNames[series()].c_str())) + ", ";
        if (shape() != INHERIT_SHAPE)
-               buf += LString(_(GUIShapeNames[shape()].c_str())) + ", ";
+               buf += string(_(GUIShapeNames[shape()].c_str())) + ", ";
        if (size() != INHERIT_SIZE)
-               buf += LString(_(GUISizeNames[size()].c_str())) + ", ";
+               buf += string(_(GUISizeNames[size()].c_str())) + ", ";
        if (color() != INHERIT_COLOR)
-               buf += LString(_(GUIColorNames[color()].c_str())) + ", ";
+               buf += string(_(GUIColorNames[color()].c_str())) + ", ";
  
        if (emph() != INHERIT)
-               buf += LString(_("Emphasis ")) + _(GUIMiscNames[emph()].c_str()) + ", ";
+               buf += string(_("Emphasis ")) + _(GUIMiscNames[emph()].c_str()) + ", ";
        if (underbar() != INHERIT)
-               buf += LString(_("Underline ")) + _(GUIMiscNames[underbar()].c_str()) + ", ";
+               buf += string(_("Underline ")) + _(GUIMiscNames[underbar()].c_str()) + ", ";
        if (noun() != INHERIT)
-               buf += LString(_("Noun ")) + _(GUIMiscNames[noun()].c_str()) + ", ";
+               buf += string(_("Noun ")) + _(GUIMiscNames[noun()].c_str()) + ", ";
        if (latex() != INHERIT)
-               buf += LString(_("Latex ")) + _(GUIMiscNames[latex()].c_str()) + ", ";
+               buf += string(_("Latex ")) + _(GUIMiscNames[latex()].c_str()) + ", ";
        if (buf.empty())
                buf = _("Default");
-       buf.strip(' ');
-       buf.strip(',');
+       buf = strip(buf, ' ');
+       buf = strip(buf, ',');
        return buf;
 }
 
 
 // Set family according to lyx format string
-LyXFont& LyXFont::setLyXFamily(LString const & fam)
+LyXFont& LyXFont::setLyXFamily(string const & fam)
 {
-       LString s = fam;
-       s.lowercase();
+       string s = lowercase(fam);
+
        int i=0;
        while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") i++;
        if (s == LyXFamilyNames[i]) {
                setFamily(LyXFont::FONT_FAMILY(i));
        } else
-               lyxerr.print("LyXFont::setLyXFamily: Unknown family `"+s+'\'');
+               lyxerr << "LyXFont::setLyXFamily: Unknown family `"
+                      << s << '\'' << endl;
        return (*this);
 }
 
 
 // Set series according to lyx format string
-LyXFont& LyXFont::setLyXSeries(LString const & ser)
+LyXFont& LyXFont::setLyXSeries(string const & ser)
 {
-       LString s = ser;
-       s.lowercase();
+       string s = lowercase(ser);
+
        int i=0;
        while (s != LyXSeriesNames[i] && LyXSeriesNames[i] != "error") i++;
        if (s == LyXSeriesNames[i]) {
                setSeries(LyXFont::FONT_SERIES(i));
        } else
-               lyxerr.print("LyXFont::setLyXSeries: Unknown series `"+s+'\'');
+               lyxerr << "LyXFont::setLyXSeries: Unknown series `"
+                      << s << '\'' << endl;
        return (*this);
 }
 
 
 // Set shape according to lyx format string
-LyXFont& LyXFont::setLyXShape(LString const & sha)
+LyXFont& LyXFont::setLyXShape(string const & sha)
 {
-       LString s = sha;
-       s.lowercase();
+       string s = lowercase(sha);
+
        int i=0;
        while (s != LyXShapeNames[i] && LyXShapeNames[i] != "error") i++;
        if (s == LyXShapeNames[i]) {
                setShape(LyXFont::FONT_SHAPE(i));
        } else
-               lyxerr.print("LyXFont::setLyXShape: Unknown shape `"+s+'\'');
+               lyxerr << "LyXFont::setLyXShape: Unknown shape `"
+                      << s << '\'' << endl;
        return (*this);
 }
 
 
 // Set size according to lyx format string
-LyXFont& LyXFont::setLyXSize(LString const & siz)
+LyXFont& LyXFont::setLyXSize(string const & siz)
 {
-       LString s = siz;
-       s.lowercase();
+       string s = lowercase(siz);
        int i=0;
        while (s != LyXSizeNames[i] && LyXSizeNames[i] != "error") i++;
        if (s == LyXSizeNames[i]) {
                setSize(LyXFont::FONT_SIZE(i));
        } else
-               lyxerr.print("LyXFont::setLyXSize: Unknown size `"+s+'\'');
+               lyxerr << "LyXFont::setLyXSize: Unknown size `"
+                      << s << '\'' << endl;
        return (*this);
 }
 
 // Set size according to lyx format string
-LyXFont::FONT_MISC_STATE LyXFont::setLyXMisc(LString const & siz)
+LyXFont::FONT_MISC_STATE LyXFont::setLyXMisc(string const & siz)
 {
-       LString s = siz;
-       s.lowercase();
+       string s = lowercase(siz);
        int i=0;
        while (s != LyXMiscNames[i] && LyXMiscNames[i] != "error") i++;
        if (s == LyXMiscNames[i])
                return FONT_MISC_STATE(i);
-       lyxerr.print("LyXFont::setLyXMisc: Unknown misc flag `"+s+'\'');
+       lyxerr << "LyXFont::setLyXMisc: Unknown misc flag `"
+              << s << '\'' << endl;
        return OFF;
 }
 
 /// Sets color after LyX text format
-LyXFont& LyXFont::setLyXColor(LString const & col)
+LyXFont& LyXFont::setLyXColor(string const & col)
 {
-       LString s = col;
-       s.lowercase();
+       string s = lowercase(col);
        int i=0;
        while (s != LyXColorNames[i] && LyXColorNames[i] != "error") i++;
        if (s == LyXColorNames[i]) {
                setColor(LyXFont::FONT_COLOR(i));
        } else
-               lyxerr.print("LyXFont::setLyXColor: Unknown Color `"+s+'\'');
+               lyxerr << "LyXFont::setLyXColor: Unknown Color `"
+                      << s << '\'' << endl;
        return (*this);
 }
 
 
 /// Sets size after GUI name
-LyXFont& LyXFont::setGUISize(LString const & siz)
+LyXFont& LyXFont::setGUISize(string const & siz)
 {
-       LString s = siz;
-       s.lowercase();
+       string s = lowercase(siz);
        int i=0;
        while (!lGUISizeNames[i].empty() &&
               s != _(lGUISizeNames[i].c_str()))
@@ -474,13 +471,14 @@ LyXFont& LyXFont::setGUISize(LString const & siz)
        if (s == _(lGUISizeNames[i].c_str())) {
                setSize(LyXFont::FONT_SIZE(i));
        } else
-               lyxerr.print("LyXFont::setGUISize: Unknown Size `"+s+'\'');
+               lyxerr << "LyXFont::setGUISize: Unknown Size `"
+                      << s << '\'' << endl;
        return (*this);
 }
 
 
 // Returns size in latex format
-LString LyXFont::latexSize() const
+string LyXFont::latexSize() const
 {
        return LaTeXSizeNames[size()];
 }
@@ -494,8 +492,7 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
        bool finished = false;
        while (!finished && lex.IsOK() && !error) {
                lex.next();
-               LString tok = lex.GetString();
-               tok.lowercase();
+               string tok = lowercase(lex.GetString());
 
                if (tok.empty()) {
                        continue;
@@ -503,24 +500,23 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
                        finished = true;
                } else if (tok == "family") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        setLyXFamily(tok);
                } else if (tok == "series") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        setLyXSeries(tok);
                } else if (tok == "shape") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        setLyXShape(tok);
                } else if (tok == "size") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        setLyXSize(tok);
                } else if (tok == "latex") {
                        lex.next();
-                       LString tok = lex.GetString();
-                       tok.lowercase();
+                       string tok = lowercase(lex.GetString());
 
                        if (tok == "no_latex") {
                                setLatex(OFF);
@@ -531,8 +527,7 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
                        }
                } else if (tok == "misc") {
                        lex.next();
-                       LString tok = lex.GetString();
-                       tok.lowercase();
+                       string tok = lowercase(lex.GetString());
 
                        if (tok == "no_bar") {
                                setUnderbar(OFF);
@@ -551,7 +546,7 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
                        }
                } else if (tok == "color") {
                        lex.next();
-                       LString tok = lex.GetString();
+                       string tok = lex.GetString();
                        setLyXColor(tok);
                } else {
                        lex.printError("Unknown tag `$$Token'");
@@ -588,12 +583,14 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, FILE * file) const
                switch (underbar()) {
                case OFF:       fprintf(file, "\\bar no \n"); break;
                case ON:        fprintf(file, "\\bar under \n"); break;
-               case TOGGLE:    lyxerr.print("LyXFont::lyxWriteFontChanges: "
-                                             "TOGGLE should not appear here!");
+               case TOGGLE:    lyxerr << "LyXFont::lyxWriteFontChanges: "
+                                       "TOGGLE should not appear here!"
+                                      << endl;
                                break;
                case INHERIT:   fprintf(file, "\\bar default \n"); break;
-               case IGNORE:    lyxerr.print("LyXFont::lyxWriteFontChanges: "
-                                             "IGNORE should not appear here!");
+               case IGNORE:    lyxerr << "LyXFont::lyxWriteFontChanges: "
+                                       "IGNORE should not appear here!"
+                                      << endl;
                                break;
                }
        }
@@ -605,12 +602,14 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, FILE * file) const
                switch (latex()) {
                case OFF:       fprintf(file, "\\latex no_latex \n"); break;
                case ON:        fprintf(file, "\\latex latex \n"); break;
-               case TOGGLE:    lyxerr.print("LyXFont::lyxWriteFontChanges: "
-                                             "TOGGLE should not appear here!");
+               case TOGGLE:    lyxerr << "LyXFont::lyxWriteFontChanges: "
+                                       "TOGGLE should not appear here!"
+                                      << endl;
                                break;
                case INHERIT:   fprintf(file, "\\latex default \n"); break;
-               case IGNORE:    lyxerr.print("LyXFont::lyxWriteFontChanges: "
-                                             "IGNORE should not appear here!");
+               case IGNORE:    lyxerr << "LyXFont::lyxWriteFontChanges: "
+                                       "IGNORE should not appear here!"
+                                      << endl;
                                break;
                }
        }
@@ -624,7 +623,7 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, FILE * file) const
 // Returns number of chars written.
 int LyXFont::latexWriteStartChanges(FILE * file, LyXFont const & base) const
 {
-       LString font;
+       string font;
        int count = latexWriteStartChanges(font, base);
        fprintf(file, "%s", font.c_str());
        return count;
@@ -633,7 +632,7 @@ int LyXFont::latexWriteStartChanges(FILE * file, LyXFont const & base) const
 
 /// Writes the head of the LaTeX needed to impose this font
 // Returns number of chars written.
-int LyXFont::latexWriteStartChanges(LString & file, LyXFont const & base) const
+int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base) const
 {
        LyXFont f = *this;
        f.reduce(base);
@@ -708,7 +707,7 @@ int LyXFont::latexWriteStartChanges(LString & file, LyXFont const & base) const
 // This one corresponds to latexWriteStartChanges(). (Asger)
 int LyXFont::latexWriteEndChanges(FILE * file, LyXFont const & base) const
 {
-       LString ending;
+       string ending;
        int count = latexWriteEndChanges(ending, base);
        fprintf(file, "%s", ending.c_str());
        return count;
@@ -718,7 +717,7 @@ int LyXFont::latexWriteEndChanges(FILE * file, LyXFont const & base) const
 /// 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(LString & file, LyXFont const & base) const
+int LyXFont::latexWriteEndChanges(string & file, LyXFont const & base) const
 {
        LyXFont f = *this; // why do you need this?
        f.reduce(base); // why isn't this just "reduce(base);" (Lgb)
@@ -897,13 +896,13 @@ int LyXFont::textWidth(char const *s, int n) const
 }
 
 
-int LyXFont::stringWidth(LString const & s) const
+int LyXFont::stringWidth(string const & s) const
 {
        if (s.empty()) return 0;
        return textWidth(s.c_str(), s.length());
 }
 
-int LyXFont::signedStringWidth(LString const & s) const
+int LyXFont::signedStringWidth(string const & s) const
 {
        if (s.empty()) return 0;
        if (s.c_str()[0] == '-')
@@ -960,7 +959,7 @@ int LyXFont::drawText(char const* s, int n, Pixmap pm,
 }
 
 
-int LyXFont::drawString(LString const &s, Pixmap pm, int baseline, int x) const
+int LyXFont::drawString(string const &s, Pixmap pm, int baseline, int x) const
 {
        return drawText(s.c_str(), s.length(), pm, baseline, x);
 }
@@ -972,3 +971,8 @@ bool LyXFont::equalExceptLatex(LyXFont const &f) const
        f1.setLatex(f.latex());
        return f1 == f;
 }
+
+ostream & operator<<(ostream & o, LyXFont::FONT_MISC_STATE fms)
+{
+       return o << int(fms);
+}