]> git.lyx.org Git - lyx.git/blob - src/Font.cpp
Speed up FileName operator== (Georg's solution).
[lyx.git] / src / Font.cpp
1 /**
2  * \file src/Font.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  * \author André Pönitz
10  * \author Dekel Tsur
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #include <config.h>
16
17 #include "Font.h"
18
19 #include "BufferParams.h" // stateText
20 #include "ColorSet.h"
21 #include "Encoding.h"
22 #include "Language.h"
23 #include "LaTeXFeatures.h"
24 #include "Lexer.h"
25 #include "LyXRC.h"
26 #include "output_latex.h"
27 #include "OutputParams.h"
28
29 #include "support/lassert.h"
30 #include "support/convert.h"
31 #include "support/debug.h"
32 #include "support/gettext.h"
33 #include "support/lstrings.h"
34
35 #include <cstring>
36
37 using namespace std;
38 using namespace lyx::support;
39
40 namespace lyx {
41
42 //
43 // Names for the GUI
44 //
45
46 namespace {
47
48 char const * GUIFamilyNames[NUM_FAMILIES + 2 /* default & error */] =
49 { N_("Roman"), N_("Sans Serif"), N_("Typewriter"), N_("Symbol"),
50   "cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "wasy", "esint",
51   N_("Inherit"), N_("Ignore") };
52
53 char const * GUISeriesNames[4] =
54 { N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") };
55
56 char const * GUIShapeNames[6] =
57 { N_("Upright"), N_("Italic"), N_("Slanted"), N_("Smallcaps"), N_("Inherit"),
58   N_("Ignore") };
59
60 char const * GUISizeNames[14] =
61 { N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"),
62   N_("Larger"), N_("Largest"), N_("Huge"), N_("Huger"), N_("Increase"), N_("Decrease"),
63   N_("Inherit"), N_("Ignore") };
64
65 char const * GUIMiscNames[5] =
66 { N_("Off"), N_("On"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
67
68
69 //
70 // Strings used to read and write .lyx format files
71 //
72 char const * LyXFamilyNames[NUM_FAMILIES + 2 /* default & error */] =
73 { "roman", "sans", "typewriter", "symbol",
74   "cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "wasy", "esint",
75   "default", "error" };
76
77 char const * LyXSeriesNames[4] =
78 { "medium", "bold", "default", "error" };
79
80 char const * LyXShapeNames[6] =
81 { "up", "italic", "slanted", "smallcaps", "default", "error" };
82
83 char const * LyXSizeNames[14] =
84 { "tiny", "scriptsize", "footnotesize", "small", "normal", "large",
85   "larger", "largest", "huge", "giant",
86   "increase", "decrease", "default", "error" };
87
88 char const * LyXMiscNames[5] =
89 { "off", "on", "toggle", "default", "error" };
90
91 //
92 // Strings used to write LaTeX files
93 //
94 char const * LaTeXFamilyNames[6] =
95 { "textrm", "textsf", "texttt", "error1", "error2", "error3" };
96
97 char const * LaTeXSeriesNames[4] =
98 { "textmd", "textbf", "error4", "error5" };
99
100 char const * LaTeXShapeNames[6] =
101 { "textup", "textit", "textsl", "textsc", "error6", "error7" };
102
103 char const * LaTeXSizeNames[14] =
104 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
105   "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
106
107 } // namespace anon
108
109
110 Font::Font(FontInfo bits, Language const * l)
111         : bits_(bits), lang_(l), misspelled_(false), open_encoding_(false)
112 {
113         if (!lang_)
114                 lang_ = default_language;
115 }
116
117
118 bool Font::isRightToLeft() const
119 {
120         return lang_->rightToLeft();
121 }
122
123
124 bool Font::isVisibleRightToLeft() const
125 {
126         return (lang_->rightToLeft() &&
127                 bits_.number() != FONT_ON);
128 }
129
130
131 void Font::setLanguage(Language const * l)
132 {
133         lang_ = l;
134 }
135
136
137 /// Updates font settings according to request
138 void Font::update(Font const & newfont,
139                      Language const * document_language,
140                      bool toggleall)
141 {
142         bits_.update(newfont.fontInfo(), toggleall);
143
144         if (newfont.language() == language() && toggleall)
145                 if (language() == document_language)
146                         setLanguage(default_language);
147                 else
148                         setLanguage(document_language);
149         else if (newfont.language() == reset_language)
150                 setLanguage(document_language);
151         else if (newfont.language() != ignore_language)
152                 setLanguage(newfont.language());
153 }
154
155
156 docstring const stateText(FontInfo const & f)
157 {
158         odocstringstream os;
159         if (f.family() != INHERIT_FAMILY)
160                 os << _(GUIFamilyNames[f.family()]) << ", ";
161         if (f.series() != INHERIT_SERIES)
162                 os << _(GUISeriesNames[f.series()]) << ", ";
163         if (f.shape() != INHERIT_SHAPE)
164                 os << _(GUIShapeNames[f.shape()]) << ", ";
165         if (f.size() != FONT_SIZE_INHERIT)
166                 os << _(GUISizeNames[f.size()]) << ", ";
167         if (f.color() != Color_inherit)
168                 os << lcolor.getGUIName(f.color()) << ", ";
169         // FIXME: uncomment this when we support background.
170         //if (f.background() != Color_inherit)
171         //      os << lcolor.getGUIName(f.background()) << ", ";
172         if (f.emph() != FONT_INHERIT)
173                 os << bformat(_("Emphasis %1$s, "),
174                               _(GUIMiscNames[f.emph()]));
175         if (f.underbar() != FONT_INHERIT)
176                 os << bformat(_("Underline %1$s, "),
177                               _(GUIMiscNames[f.underbar()]));
178         if (f.noun() != FONT_INHERIT)
179                 os << bformat(_("Noun %1$s, "),
180                               _(GUIMiscNames[f.noun()]));
181         if (f == inherit_font)
182                 os << _("Default") << ", ";
183
184         return os.str();
185 }
186
187
188 docstring const Font::stateText(BufferParams * params) const
189 {
190         odocstringstream os;
191         os << lyx::stateText(bits_);
192         if (!params || (language() != params->language))
193                 os << bformat(_("Language: %1$s, "),
194                               _(language()->display()));
195         if (bits_.number() != FONT_OFF)
196                 os << bformat(_("  Number %1$s"),
197                               _(GUIMiscNames[bits_.number()]));
198         return rtrim(os.str(), ", ");
199 }
200
201
202 // Set family according to lyx format string
203 void setLyXFamily(string const & fam, FontInfo & f)
204 {
205         string const s = ascii_lowercase(fam);
206
207         int i = 0;
208         while (LyXFamilyNames[i] != s &&
209                LyXFamilyNames[i] != string("error"))
210                 ++i;
211         if (s == LyXFamilyNames[i])
212                 f.setFamily(FontFamily(i));
213         else
214                 lyxerr << "setLyXFamily: Unknown family `"
215                        << s << '\'' << endl;
216 }
217
218
219 // Set series according to lyx format string
220 void setLyXSeries(string const & ser, FontInfo & f)
221 {
222         string const s = ascii_lowercase(ser);
223
224         int i = 0;
225         while (LyXSeriesNames[i] != s &&
226                LyXSeriesNames[i] != string("error")) ++i;
227         if (s == LyXSeriesNames[i]) {
228                 f.setSeries(FontSeries(i));
229         } else
230                 lyxerr << "setLyXSeries: Unknown series `"
231                        << s << '\'' << endl;
232 }
233
234
235 // Set shape according to lyx format string
236 void setLyXShape(string const & sha, FontInfo & f)
237 {
238         string const s = ascii_lowercase(sha);
239
240         int i = 0;
241         while (LyXShapeNames[i] != s && LyXShapeNames[i] != string("error"))
242                         ++i;
243         if (s == LyXShapeNames[i])
244                 f.setShape(FontShape(i));
245         else
246                 lyxerr << "Font::setLyXShape: Unknown shape `"
247                        << s << '\'' << endl;
248 }
249
250
251 // Set size according to lyx format string
252 void setLyXSize(string const & siz, FontInfo & f)
253 {
254         string const s = ascii_lowercase(siz);
255         int i = 0;
256         while (LyXSizeNames[i] != s && LyXSizeNames[i] != string("error"))
257                 ++i;
258         if (s == LyXSizeNames[i]) {
259                 f.setSize(FontSize(i));
260         } else
261                 lyxerr << "Font::setLyXSize: Unknown size `"
262                        << s << '\'' << endl;
263 }
264
265
266 // Set size according to lyx format string
267 FontState Font::setLyXMisc(string const & siz)
268 {
269         string const s = ascii_lowercase(siz);
270         int i = 0;
271         while (LyXMiscNames[i] != s &&
272                LyXMiscNames[i] != string("error")) ++i;
273         if (s == LyXMiscNames[i])
274                 return FontState(i);
275         lyxerr << "Font::setLyXMisc: Unknown misc flag `"
276                << s << '\'' << endl;
277         return FONT_OFF;
278 }
279
280
281 /// Sets color after LyX text format
282 void setLyXColor(string const & col, FontInfo & f)
283 {
284         f.setColor(lcolor.getFromLyXName(col));
285 }
286
287
288 // Returns size in latex format
289 string const Font::latexSize() const
290 {
291         return LaTeXSizeNames[bits_.size()];
292 }
293
294
295 // Read a font definition from given file in lyx format
296 // Used for layouts
297 FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
298 {
299         FontInfo f = fi;
300         bool error = false;
301         bool finished = false;
302         while (!finished && lex.isOK() && !error) {
303                 lex.next();
304                 string const tok = ascii_lowercase(lex.getString());
305
306                 if (tok.empty()) {
307                         continue;
308                 } else if (tok == "endfont") {
309                         finished = true;
310                 } else if (tok == "family") {
311                         lex.next();
312                         string const ttok = lex.getString();
313                         setLyXFamily(ttok, f);
314                 } else if (tok == "series") {
315                         lex.next();
316                         string const ttok = lex.getString();
317                         setLyXSeries(ttok, f);
318                 } else if (tok == "shape") {
319                         lex.next();
320                         string const ttok = lex.getString();
321                         setLyXShape(ttok, f);
322                 } else if (tok == "size") {
323                         lex.next();
324                         string const ttok = lex.getString();
325                         setLyXSize(ttok, f);
326                 } else if (tok == "misc") {
327                         lex.next();
328                         string const ttok = ascii_lowercase(lex.getString());
329
330                         if (ttok == "no_bar") {
331                                 f.setUnderbar(FONT_OFF);
332                         } else if (ttok == "no_emph") {
333                                 f.setEmph(FONT_OFF);
334                         } else if (ttok == "no_noun") {
335                                 f.setNoun(FONT_OFF);
336                         } else if (ttok == "emph") {
337                                 f.setEmph(FONT_ON);
338                         } else if (ttok == "underbar") {
339                                 f.setUnderbar(FONT_ON);
340                         } else if (ttok == "noun") {
341                                 f.setNoun(FONT_ON);
342                         } else {
343                                 lex.printError("Illegal misc type");
344                         }
345                 } else if (tok == "color") {
346                         lex.next();
347                         string const ttok = lex.getString();
348                         setLyXColor(ttok, f);
349                 } else {
350                         lex.printError("Unknown tag");
351                         error = true;
352                 }
353         }
354         return f;
355 }
356
357
358 /// Writes the changes from this font to orgfont in .lyx format in file
359 void Font::lyxWriteChanges(Font const & orgfont,
360                               ostream & os) const
361 {
362         os << "\n";
363         if (orgfont.fontInfo().family() != bits_.family())
364                 os << "\\family " << LyXFamilyNames[bits_.family()] << "\n";
365         if (orgfont.fontInfo().series() != bits_.series())
366                 os << "\\series " << LyXSeriesNames[bits_.series()] << "\n";
367         if (orgfont.fontInfo().shape() != bits_.shape())
368                 os << "\\shape " << LyXShapeNames[bits_.shape()] << "\n";
369         if (orgfont.fontInfo().size() != bits_.size())
370                 os << "\\size " << LyXSizeNames[bits_.size()] << "\n";
371         if (orgfont.fontInfo().emph() != bits_.emph())
372                 os << "\\emph " << LyXMiscNames[bits_.emph()] << "\n";
373         if (orgfont.fontInfo().number() != bits_.number())
374                 os << "\\numeric " << LyXMiscNames[bits_.number()] << "\n";
375         if (orgfont.fontInfo().underbar() != bits_.underbar()) {
376                 // This is only for backwards compatibility
377                 switch (bits_.underbar()) {
378                 case FONT_OFF:  os << "\\bar no\n"; break;
379                 case FONT_ON:        os << "\\bar under\n"; break;
380                 case FONT_TOGGLE:       lyxerr << "Font::lyxWriteFontChanges: "
381                                         "FONT_TOGGLE should not appear here!"
382                                        << endl;
383                 break;
384                 case FONT_INHERIT:   os << "\\bar default\n"; break;
385                 case FONT_IGNORE:    lyxerr << "Font::lyxWriteFontChanges: "
386                                         "IGNORE should not appear here!"
387                                        << endl;
388                 break;
389                 }
390         }
391         if (orgfont.fontInfo().noun() != bits_.noun()) {
392                 os << "\\noun " << LyXMiscNames[bits_.noun()] << "\n";
393         }
394         if (orgfont.fontInfo().color() != bits_.color())
395                 os << "\\color " << lcolor.getLyXName(bits_.color()) << '\n';
396         // FIXME: uncomment this when we support background.
397         //if (orgfont.fontInfo().background() != bits_.background())
398         //      os << "\\color " << lcolor.getLyXName(bits_.background()) << '\n';
399         if (orgfont.language() != language() &&
400             language() != latex_language) {
401                 if (language())
402                         os << "\\lang " << language()->lang() << "\n";
403                 else
404                         os << "\\lang unknown\n";
405         }
406 }
407
408
409 /// Writes the head of the LaTeX needed to impose this font
410 // Returns number of chars written.
411 int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
412                                     OutputParams const & runparams,
413                                     Font const & base,
414                                     Font const & prev) const
415 {
416         bool env = false;
417
418         int count = 0;
419         if (language()->babel() != base.language()->babel() &&
420             language() != prev.language()) {
421                 if (language()->lang() == "farsi") {
422                         os << "\\textFR{";
423                         count += 8;
424                 } else if (!isRightToLeft() &&
425                             base.language()->lang() == "farsi") {
426                         os << "\\textLR{";
427                         count += 8;
428                 } else if (language()->lang() == "arabic_arabi") {
429                         os << "\\textAR{";
430                         count += 8;
431                 } else if (!isRightToLeft() &&
432                                 base.language()->lang() == "arabic_arabi") {
433                         os << "\\textLR{";
434                         count += 8;
435                 // currently the remaining RTL languages are arabic_arabtex and hebrew
436                 } else if (isRightToLeft() != prev.isRightToLeft()) {
437                         if (isRightToLeft()) {
438                                 os << "\\R{";
439                                 count += 3;
440                         } else {
441                                 os << "\\L{";
442                                 count += 3;
443                         }
444                 } else if (!language()->babel().empty()) {
445                         string const tmp =
446                                 subst(lyxrc.language_command_local,
447                                       "$$lang", language()->babel());
448                         os << from_ascii(tmp);
449                         count += tmp.length();
450                 } else {
451                         os << '{';
452                         count += 1;
453                 }
454         }
455
456         if (language()->encoding()->package() == Encoding::CJK) {
457                 pair<bool, int> const c = switchEncoding(os, bparams,
458                                 runparams, *(language()->encoding()));
459                 if (c.first) {
460                         open_encoding_ = true;
461                         count += c.second;
462                         runparams.encoding = language()->encoding();
463                 }
464         }
465
466         // When the current language is Hebrew, Arabic, or Farsi
467         // the numbers are written Left-to-Right. ArabTeX package
468         // reorders the number automatically but the packages used
469         // for Hebrew and Farsi (Arabi) do not.
470         if (bits_.number() == FONT_ON && prev.fontInfo().number() != FONT_ON
471                 && (language()->lang() == "hebrew"
472                         || language()->lang() == "farsi" 
473                         || language()->lang() == "arabic_arabi")) {
474                 os << "{\\beginL ";
475                 count += 9;
476         }
477
478         FontInfo f = bits_;
479         f.reduce(base.bits_);
480
481         if (f.family() != INHERIT_FAMILY) {
482                 os << '\\'
483                    << LaTeXFamilyNames[f.family()]
484                    << '{';
485                 count += strlen(LaTeXFamilyNames[f.family()]) + 2;
486                 env = true; //We have opened a new environment
487         }
488         if (f.series() != INHERIT_SERIES) {
489                 os << '\\'
490                    << LaTeXSeriesNames[f.series()]
491                    << '{';
492                 count += strlen(LaTeXSeriesNames[f.series()]) + 2;
493                 env = true; //We have opened a new environment
494         }
495         if (f.shape() != INHERIT_SHAPE) {
496                 os << '\\'
497                    << LaTeXShapeNames[f.shape()]
498                    << '{';
499                 count += strlen(LaTeXShapeNames[f.shape()]) + 2;
500                 env = true; //We have opened a new environment
501         }
502         if (f.color() != Color_inherit && f.color() != Color_ignore) {
503                 os << "\\textcolor{"
504                    << from_ascii(lcolor.getLaTeXName(f.color()))
505                    << "}{";
506                 count += lcolor.getLaTeXName(f.color()).length() + 13;
507                 env = true; //We have opened a new environment
508         }
509         // FIXME: uncomment this when we support background.
510         /*
511         if (f.background() != Color_inherit && f.background() != Color_ignore) {
512                 os << "\\textcolor{"
513                    << from_ascii(lcolor.getLaTeXName(f.background()))
514                    << "}{";
515                 count += lcolor.getLaTeXName(f.background()).length() + 13;
516                 env = true; //We have opened a new environment
517         }
518         */
519         if (f.emph() == FONT_ON) {
520                 os << "\\emph{";
521                 count += 6;
522                 env = true; //We have opened a new environment
523         }
524         if (f.underbar() == FONT_ON) {
525                 os << "\\underbar{";
526                 count += 10;
527                 env = true; //We have opened a new environment
528         }
529         // \noun{} is a LyX special macro
530         if (f.noun() == FONT_ON) {
531                 os << "\\noun{";
532                 count += 6;
533                 env = true; //We have opened a new environment
534         }
535         if (f.size() != FONT_SIZE_INHERIT) {
536                 // If we didn't open an environment above, we open one here
537                 if (!env) {
538                         os << '{';
539                         ++count;
540                 }
541                 os << '\\'
542                    << LaTeXSizeNames[f.size()]
543                    << ' ';
544                 count += strlen(LaTeXSizeNames[f.size()]) + 2;
545         }
546         return count;
547 }
548
549
550 /// Writes ending block of LaTeX needed to close use of this font
551 // Returns number of chars written
552 // This one corresponds to latexWriteStartChanges(). (Asger)
553 int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams,
554                                   OutputParams const & runparams,
555                                   Font const & base,
556                                   Font const & next,
557                                   bool const & closeLanguage) const
558 {
559         int count = 0;
560         bool env = false;
561
562         // reduce the current font to changes against the base
563         // font (of the layout). We use a temporary for this to
564         // avoid changing this font instance, as that would break
565         FontInfo f = bits_;
566         f.reduce(base.bits_);
567
568         if (f.family() != INHERIT_FAMILY) {
569                 os << '}';
570                 ++count;
571                 env = true; // Size change need not bother about closing env.
572         }
573         if (f.series() != INHERIT_SERIES) {
574                 os << '}';
575                 ++count;
576                 env = true; // Size change need not bother about closing env.
577         }
578         if (f.shape() != INHERIT_SHAPE) {
579                 os << '}';
580                 ++count;
581                 env = true; // Size change need not bother about closing env.
582         }
583         if (f.color() != Color_inherit && f.color() != Color_ignore) {
584                 os << '}';
585                 ++count;
586                 env = true; // Size change need not bother about closing env.
587         }
588         if (f.emph() == FONT_ON) {
589                 os << '}';
590                 ++count;
591                 env = true; // Size change need not bother about closing env.
592         }
593         if (f.underbar() == FONT_ON) {
594                 os << '}';
595                 ++count;
596                 env = true; // Size change need not bother about closing env.
597         }
598         if (f.noun() == FONT_ON) {
599                 os << '}';
600                 ++count;
601                 env = true; // Size change need not bother about closing env.
602         }
603         if (f.size() != FONT_SIZE_INHERIT) {
604                 // We only have to close if only size changed
605                 if (!env) {
606                         os << '}';
607                         ++count;
608                 }
609         }
610
611         // When the current language is Hebrew, Arabic, or Farsi
612         // the numbers are written Left-to-Right. ArabTeX package
613         // reorders the number automatically but the packages used
614         // for Hebrew and Farsi (Arabi) do not.
615         if (bits_.number() == FONT_ON && next.fontInfo().number() != FONT_ON
616                 && (language()->lang() == "hebrew"
617                         || language()->lang() == "farsi"
618                         || language()->lang() == "arabic_arabi")) {
619                 os << "\\endL}";
620                 count += 6;
621         }
622
623         if (open_encoding_) {
624                 // We need to close the encoding even if it does not change
625                 // to do correct environment nesting
626                 Encoding const * const ascii = encodings.fromLyXName("ascii");
627                 pair<bool, int> const c = switchEncoding(os, bparams,
628                                 runparams, *ascii);
629                 LASSERT(c.first, /**/);
630                 count += c.second;
631                 runparams.encoding = ascii;
632                 open_encoding_ = false;
633         }
634
635         if (closeLanguage &&
636                         language() != base.language() && language() != next.language()) {
637                 os << '}';
638                 ++count;
639         }
640
641         return count;
642 }
643
644
645 string Font::toString(bool const toggle) const
646 {
647         string const lang = (language() == reset_language)
648                 ? "reset" : language()->lang();
649
650         ostringstream os;
651         os << "family " << bits_.family() << '\n'
652            << "series " << bits_.series() << '\n'
653            << "shape " << bits_.shape() << '\n'
654            << "size " << bits_.size() << '\n'
655            << "emph " << bits_.emph() << '\n'
656            << "underbar " << bits_.underbar() << '\n'
657            << "noun " << bits_.noun() << '\n'
658            << "number " << bits_.number() << '\n'
659            << "color " << bits_.color() << '\n'
660            << "language " << lang << '\n'
661            << "toggleall " << convert<string>(toggle);
662         return os.str();
663 }
664
665
666 bool Font::fromString(string const & data, bool & toggle)
667 {
668         istringstream is(data);
669         Lexer lex;
670         lex.setStream(is);
671
672         int nset = 0;
673         while (lex.isOK()) {
674                 string token;
675                 if (lex.next())
676                         token = lex.getString();
677
678                 if (token.empty() || !lex.next())
679                         break;
680
681                 if (token == "family") {
682                         int const next = lex.getInteger();
683                         bits_.setFamily(FontFamily(next));
684
685                 } else if (token == "series") {
686                         int const next = lex.getInteger();
687                         bits_.setSeries(FontSeries(next));
688
689                 } else if (token == "shape") {
690                         int const next = lex.getInteger();
691                         bits_.setShape(FontShape(next));
692
693                 } else if (token == "size") {
694                         int const next = lex.getInteger();
695                         bits_.setSize(FontSize(next));
696
697                 } else if (token == "emph" || token == "underbar" ||
698                            token == "noun" || token == "number") {
699
700                         int const next = lex.getInteger();
701                         FontState const misc = FontState(next);
702
703                         if (token == "emph")
704                                 bits_.setEmph(misc);
705                         else if (token == "underbar")
706                                 bits_.setUnderbar(misc);
707                         else if (token == "noun")
708                                 bits_.setNoun(misc);
709                         else if (token == "number")
710                                 bits_.setNumber(misc);
711
712                 } else if (token == "color") {
713                         int const next = lex.getInteger();
714                         bits_.setColor(ColorCode(next));
715
716                 /**
717                 } else if (token == "background") {
718                         int const next = lex.getInteger();
719                         bits_.setBackground(ColorCode(next));
720                 */
721
722                 } else if (token == "language") {
723                         string const next = lex.getString();
724                         setLanguage(languages.getLanguage(next));
725
726                 } else if (token == "toggleall") {
727                         toggle = lex.getBool();
728
729                 } else {
730                         // Unrecognised token
731                         break;
732                 }
733
734                 ++nset;
735         }
736         return (nset > 0);
737 }
738
739
740 void Font::validate(LaTeXFeatures & features) const
741 {
742         BufferParams const & bparams = features.bufferParams();
743         Language const * doc_language = bparams.language;
744
745         if (bits_.noun() == FONT_ON) {
746                 LYXERR(Debug::LATEX, "font.noun: " << bits_.noun());
747                 features.require("noun");
748                 LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText(0)));
749         }
750         switch (bits_.color()) {
751                 case Color_none:
752                 case Color_inherit:
753                 case Color_ignore:
754                         // probably we should put here all interface colors used for
755                         // font displaying! For now I just add this ones I know of (Jug)
756                 case Color_latex:
757                 case Color_notelabel:
758                         break;
759                 default:
760                         features.require("color");
761                         LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText(0)));
762         }
763
764         // FIXME: Do something for background and soul package?
765
766         if (lang_->babel() != doc_language->babel() &&
767                 lang_ != ignore_language &&
768                 lang_ != latex_language)
769         {
770                 features.useLanguage(lang_);
771                 LYXERR(Debug::LATEX, "Found language " << lang_->lang());
772         }
773 }
774
775
776 ostream & operator<<(ostream & os, FontState fms)
777 {
778         return os << int(fms);
779 }
780
781
782 ostream & operator<<(ostream & os, FontInfo const & f)
783 {
784         return os << "font:"
785                 << " family " << f.family()
786                 << " series " << f.series()
787                 << " shape " << f.shape()
788                 << " size " << f.size()
789                 << " color " << f.color()
790                 // FIXME: uncomment this when we support background.
791                 //<< " background " << f.background()
792                 << " emph " << f.emph()
793                 << " underbar " << f.underbar()
794                 << " noun " << f.noun()
795                 << " number " << f.number();
796 }
797
798
799 ostream & operator<<(ostream & os, Font const & font)
800 {
801         return os << font.bits_
802                 << " lang: " << (font.lang_ ? font.lang_->lang() : 0);
803 }
804
805
806 } // namespace lyx