* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-1999 The LyX Team.
+ * Copyright 1995-2000 The LyX Team.
*
* ====================================================== */
#include "FontLoader.h"
#include "support/lstrings.h"
-extern LyXRC * lyxrc;
// The global fontloader
FontLoader fontloader;
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
OFF,
OFF,
OFF,
- OFF,
- LTR_DIR };
+ OFF };
LyXFont::FontBits LyXFont::inherit = {
INHERIT_FAMILY,
INHERIT,
INHERIT,
INHERIT,
- INHERIT,
- INHERIT_DIR };
+ INHERIT };
LyXFont::FontBits LyXFont::ignore = {
IGNORE_FAMILY,
IGNORE,
IGNORE,
IGNORE,
- IGNORE,
- IGNORE_DIR };
+ IGNORE };
/// Decreases font size by one
/// 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'
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());
setLatex(INHERIT);
if (color() == tmplt.color())
setColor(LColor::inherit);
- if (direction() == tmplt.direction())
- setDirection(INHERIT_DIR);
}
if (bits.color == LColor::inherit) {
bits.color = tmplt.bits.color;
}
- if (bits.direction == INHERIT_DIR) {
- bits.direction = tmplt.bits.direction;
- }
return *this;
}
shape() != INHERIT_SHAPE && size() != INHERIT_SIZE &&
emph() != INHERIT && underbar() != INHERIT &&
noun() != INHERIT && latex() != INHERIT &&
- color() != LColor::inherit &&
- direction() != INHERIT_DIR);
+ color() != LColor::inherit);
}
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;
}
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;
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()]
}
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;
++count;
}
}
+
return count;
}
-#endif
LColor::color LyXFont::realColor() 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();
}
+// 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 {
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);