X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfont.C;h=e793b80ea23f441071c642938eea558b0e376af1;hb=90343c7ade8fb41afe6c50d4902b7a15bfa8c4e6;hp=f481b1d9eb4719cb65b7620352c24d52bd12fad2;hpb=abb623f7872ba960a92a6d069dcb6aa5add0d8b0;p=lyx.git diff --git a/src/lyxfont.C b/src/lyxfont.C index f481b1d9eb..e793b80ea2 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-1999 The LyX Team. + * Copyright 1995-2000 The LyX Team. * * ====================================================== */ @@ -25,7 +25,6 @@ #include "FontLoader.h" #include "support/lstrings.h" -extern LyXRC * lyxrc; // The global fontloader FontLoader fontloader; @@ -58,9 +57,6 @@ string const lGUISizeNames[15] = string const GUIMiscNames[5] = { N_("Off"), N_("On"), N_("Toggle"), N_("Inherit"), N_("Ignore") }; -string const GUIDirectionNames[5] = -{ N_("LTR"), N_("RTL"), N_("Toggle"), N_("Inherit"), N_("Ignore") }; - // // Strings used to read and write .lyx format files @@ -109,8 +105,7 @@ LyXFont::FontBits LyXFont::sane = { OFF, OFF, OFF, - OFF, - LTR_DIR }; + OFF }; LyXFont::FontBits LyXFont::inherit = { INHERIT_FAMILY, @@ -121,8 +116,7 @@ LyXFont::FontBits LyXFont::inherit = { INHERIT, INHERIT, INHERIT, - INHERIT, - INHERIT_DIR }; + INHERIT }; LyXFont::FontBits LyXFont::ignore = { IGNORE_FAMILY, @@ -133,8 +127,7 @@ LyXFont::FontBits LyXFont::ignore = { IGNORE, IGNORE, IGNORE, - IGNORE, - IGNORE_DIR }; + IGNORE }; /// Decreases font size by one @@ -221,7 +214,8 @@ LyXFont::FONT_MISC_STATE LyXFont::setMisc(FONT_MISC_STATE newfont, /// Updates font settings according to request -void LyXFont::update(LyXFont const & newfont, bool toggleall) +void LyXFont::update(LyXFont const & newfont, + Language const * document_language, bool toggleall) { if(newfont.family() == family() && toggleall) setFamily(INHERIT_FAMILY); // toggle 'back' @@ -268,20 +262,16 @@ void LyXFont::update(LyXFont const & newfont, bool toggleall) setNoun(setMisc(newfont.noun(), noun())); setLatex(setMisc(newfont.latex(), latex())); - switch(newfont.direction()) { - case TOGGLE_DIR: - if (direction() == LTR_DIR) - setDirection(RTL_DIR); + if (newfont.language() != ignore_language) + if (language() == newfont.language()) + if (language() == document_language) + setLanguage(default_language); + else + setLanguage(document_language); else - setDirection(LTR_DIR); - break; - case IGNORE_DIR: - break; - default: - setDirection(newfont.direction()); - } + setLanguage(newfont.language()); - if(newfont.color() == color() && toggleall) + if (newfont.color() == color() && toggleall) setColor(LColor::inherit); // toggle 'back' else if (newfont.color() != LColor::ignore) setColor(newfont.color()); @@ -309,8 +299,6 @@ void LyXFont::reduce(LyXFont const & tmplt) setLatex(INHERIT); if (color() == tmplt.color()) setColor(LColor::inherit); - if (direction() == tmplt.direction()) - setDirection(INHERIT_DIR); } @@ -349,9 +337,6 @@ LyXFont & LyXFont::realize(LyXFont const & tmplt) if (bits.color == LColor::inherit) { bits.color = tmplt.bits.color; } - if (bits.direction == INHERIT_DIR) { - bits.direction = tmplt.bits.direction; - } return *this; } @@ -364,8 +349,7 @@ bool LyXFont::resolved() const shape() != INHERIT_SHAPE && size() != INHERIT_SIZE && emph() != INHERIT && underbar() != INHERIT && noun() != INHERIT && latex() != INHERIT && - color() != LColor::inherit && - direction() != INHERIT_DIR); + color() != LColor::inherit); } @@ -391,12 +375,11 @@ string LyXFont::stateText() const buf += string(_("Noun ")) + _(GUIMiscNames[noun()].c_str()) + ", "; if (latex() != INHERIT) buf += string(_("Latex ")) + _(GUIMiscNames[latex()].c_str()) + ", "; - if (direction() != INHERIT_DIR) - buf += string(_("Direction ")) + _(GUIDirectionNames[direction()].c_str()) + ", "; if (buf.empty()) buf = _("Default"); buf = strip(buf, ' '); buf = strip(buf, ','); + buf += " " + string(_("Language: ")) + _(language()->display.c_str()); return buf; } @@ -567,17 +550,6 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex) lex.next(); string tok = lex.GetString(); setLyXColor(tok); - } else if (tok == "direction") { - lex.next(); - string tok = lowercase(lex.GetString()); - - if (tok == "ltr") { - setDirection(LTR_DIR); - } else if (tok == "rtl") { - setDirection(RTL_DIR); - } else { - lex.printError("Illegal type`$$Token'"); - } } else { lex.printError("Unknown tag `$$Token'"); error = true; @@ -644,52 +616,47 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const if (orgfont.color() != color()) { os << "\\color " << lcolor.getLyXName(color()) << "\n"; } - if (orgfont.direction() != direction()) { - switch (direction()) { - case RTL_DIR: os << "\\direction rtl \n"; break; - case LTR_DIR: os << "\\direction ltr\n"; break; - case TOGGLE_DIR: lyxerr << "LyXFont::lyxWriteFontChanges: " - "TOGGLE should not appear here!" - << endl; - case INHERIT_DIR: os << "\\direction default \n"; break; - case IGNORE_DIR: lyxerr << "LyXFont::lyxWriteFontChanges: " - "IGNORE should not appear here!" - << endl; - break; - } + if (orgfont.language() != language()) { + if (language()) + os << "\\lang " << language()->lang << endl; + else + os << "\\lang unknown\n"; } } /// Writes the head of the LaTeX needed to impose this font // Returns number of chars written. -#ifdef USE_OSTREAM_ONLY int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, LyXFont const & prev) const { - LyXFont f = *this; - f.reduce(base); - - if (f.bits == inherit) - return 0; - int count = 0; bool env = false; - FONT_DIRECTION direction = f.direction(); - if (direction != prev.direction()) { - if (direction == LTR_DIR) { - os << "\\L{"; - count += 3; - env = true; //We have opened a new environment - } - if (direction == RTL_DIR) { - os << "\\R{"; - count += 3; + if (language() != prev.language()) { + if (isRightToLeft() != prev.isRightToLeft()) { + if (isRightToLeft()) { + os << "\\R{"; + count += 3; + env = true; //We have opened a new environment + } else { + os << "\\L{"; + count += 3; + env = true; //We have opened a new environment + } + } else { + string tmp = '{' + + subst(lyxrc.language_command_begin, + "$$lang", language()->lang); + os << tmp; + count += tmp.length(); env = true; //We have opened a new environment } } + LyXFont f = *this; + f.reduce(base); + if (f.family() != INHERIT_FAMILY) { os << '\\' << LaTeXFamilyNames[f.family()] @@ -747,191 +714,29 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, } return count; } -#else -int LyXFont::latexWriteStartChanges(string & file, LyXFont const & base, - LyXFont const & prev) const -{ - LyXFont f = *this; - f.reduce(base); - - if (f.bits == inherit) - return 0; - - int count = 0; - bool env = false; - FONT_DIRECTION direction = f.direction(); - if (direction != prev.direction()) { - if (direction == LTR_DIR) { - file += "\\L{"; - count += 3; - env = true; //We have opened a new environment - } - if (direction == RTL_DIR) { - file += "\\R{"; - count += 3; - env = true; //We have opened a new environment - } - } - - if (f.family() != INHERIT_FAMILY) { - file += '\\'; - file += LaTeXFamilyNames[f.family()]; - file += '{'; - count += LaTeXFamilyNames[f.family()].length() + 2; - env = true; //We have opened a new environment - } - if (f.series() != INHERIT_SERIES) { - file += '\\'; - file += LaTeXSeriesNames[f.series()]; - file += '{'; - count += LaTeXSeriesNames[f.series()].length() + 2; - env = true; //We have opened a new environment - } - if (f.shape() != INHERIT_SHAPE) { - file += '\\'; - file += LaTeXShapeNames[f.shape()]; - file += '{'; - count += LaTeXShapeNames[f.shape()].length() + 2; - env = true; //We have opened a new environment - } - 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 - } - if (f.emph() == ON) { - file += "\\emph{"; - count += 6; - env = true; //We have opened a new environment - } - if (f.underbar() == ON) { - file += "\\underbar{"; - count += 10; - env = true; //We have opened a new environment - } - // \noun{} is a LyX special macro - if (f.noun() == ON) { - file += "\\noun{"; - count += 8; - env = true; //We have opened a new environment - } - if (f.size() != INHERIT_SIZE) { - // If we didn't open an environment above, we open one here - if (!env) { - file += '{'; - ++count; - } - file += '\\'; - file += LaTeXSizeNames[f.size()]; - file += ' '; - count += LaTeXSizeNames[f.size()].length() + 2; - } - return count; -} -#endif - -#ifndef USE_OSTREAM_ONLY /// 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, +int LyXFont::latexWriteEndChanges(ostream & os, 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) - // Because this function is const. Everything breaks if this - // method changes the font it represents. There is no speed penalty - // by using the temporary. (Asger) - - if (f.bits == inherit) - return 0; - int count = 0; bool env = false; - FONT_DIRECTION direction = f.direction(); - if ( direction != next.direction() - && (direction == RTL_DIR || direction == LTR_DIR) ) { - file += '}'; + if (language() != next.language()) { + os << "}"; ++count; env = true; // Size change need not bother about closing env. } - if (f.family() != INHERIT_FAMILY) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.series() != INHERIT_SERIES) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.shape() != INHERIT_SHAPE) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.color() != LColor::inherit) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.emph() == ON) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.underbar() == ON) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.noun() == ON) { - file += '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.size() != INHERIT_SIZE) { - // We only have to close if only size changed - if (!env) { - file += '}'; - ++count; - } - } - return count; -} -#else -/// 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(ostream & os, 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) // Because this function is const. Everything breaks if this // method changes the font it represents. There is no speed penalty // by using the temporary. (Asger) - if (f.bits == inherit) - return 0; - - int count = 0; - bool env = false; - - FONT_DIRECTION direction = f.direction(); - if ( direction != next.direction() - && (direction == RTL_DIR || direction == LTR_DIR) ) { - os << '}'; - ++count; - env = true; // Size change need not bother about closing env. - } - if (f.family() != INHERIT_FAMILY) { os << '}'; ++count; @@ -974,9 +779,9 @@ int LyXFont::latexWriteEndChanges(ostream & os, LyXFont const & base, ++count; } } + return count; } -#endif LColor::color LyXFont::realColor() const @@ -1050,17 +855,6 @@ int LyXFont::descent(char c) const } -// Specialized after profiling. (Asger) -int LyXFont::width(char c) const -{ - if (realShape() != LyXFont::SMALLCAPS_SHAPE){ - return XTextWidth(getXFontstruct(), &c, 1); - } else { - return textWidth(&c, 1); - } -} - - int LyXFont::lbearing(char c) const { XFontStruct * finfo = getXFontstruct(); @@ -1087,8 +881,22 @@ int LyXFont::rbearing(char c) const } +// Specialized after profiling. (Asger) +int LyXFont::width(char c) const +{ + if (realShape() != LyXFont::SMALLCAPS_SHAPE){ + return lyxrc.use_gui ? XTextWidth(getXFontstruct(), &c, 1) : 1; + } else { + return textWidth(&c, 1); + } +} + + int LyXFont::textWidth(char const * s, int n) const { + if (!lyxrc.use_gui) + return n; + if (realShape() != LyXFont::SMALLCAPS_SHAPE){ return XTextWidth(getXFontstruct(), s, n); } else { @@ -1191,18 +999,6 @@ bool LyXFont::equalExceptLatex(LyXFont const & f) const return f1 == f; } - -LyXDirection LyXFont::getFontDirection() const -{ - if (lyxrc->rtl_support - && direction() == LyXFont::RTL_DIR - && latex() != LyXFont::ON) - return LYX_DIR_RIGHT_TO_LEFT; - else - return LYX_DIR_LEFT_TO_RIGHT; -} - - ostream & operator<<(ostream & o, LyXFont::FONT_MISC_STATE fms) { return o << int(fms);