]> git.lyx.org Git - lyx.git/blob - src/Font.cpp
a1492db03233f6909792ca7dd318ec375d7a279d
[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 "Color.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/convert.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
32 #include "support/lstrings.h"
33
34 using namespace std;
35
36 namespace lyx {
37
38 using support::ascii_lowercase;
39 using support::bformat;
40 using support::rtrim;
41 using support::subst;
42
43 //
44 // Names for the GUI
45 //
46
47 namespace {
48
49 char const * GUIFamilyNames[NUM_FAMILIES + 2 /* default & error */] =
50 { N_("Roman"), N_("Sans Serif"), N_("Typewriter"), N_("Symbol"),
51   "cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "wasy", "esint",
52   N_("Inherit"), N_("Ignore") };
53
54 char const * GUISeriesNames[4] =
55 { N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") };
56
57 char const * GUIShapeNames[6] =
58 { N_("Upright"), N_("Italic"), N_("Slanted"), N_("Smallcaps"), N_("Inherit"),
59   N_("Ignore") };
60
61 char const * GUISizeNames[14] =
62 { N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"),
63   N_("Larger"), N_("Largest"), N_("Huge"), N_("Huger"), N_("Increase"), N_("Decrease"),
64   N_("Inherit"), N_("Ignore") };
65
66 char const * GUIMiscNames[5] =
67 { N_("Off"), N_("On"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
68
69
70 //
71 // Strings used to read and write .lyx format files
72 //
73 char const * LyXFamilyNames[NUM_FAMILIES + 2 /* default & error */] =
74 { "roman", "sans", "typewriter", "symbol",
75   "cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "wasy", "esint",
76   "default", "error" };
77
78 char const * LyXSeriesNames[4] =
79 { "medium", "bold", "default", "error" };
80
81 char const * LyXShapeNames[6] =
82 { "up", "italic", "slanted", "smallcaps", "default", "error" };
83
84 char const * LyXSizeNames[14] =
85 { "tiny", "scriptsize", "footnotesize", "small", "normal", "large",
86   "larger", "largest", "huge", "giant",
87   "increase", "decrease", "default", "error" };
88
89 char const * LyXMiscNames[5] =
90 { "off", "on", "toggle", "default", "error" };
91
92 //
93 // Strings used to write LaTeX files
94 //
95 char const * LaTeXFamilyNames[6] =
96 { "textrm", "textsf", "texttt", "error1", "error2", "error3" };
97
98 char const * LaTeXSeriesNames[4] =
99 { "textmd", "textbf", "error4", "error5" };
100
101 char const * LaTeXShapeNames[6] =
102 { "textup", "textit", "textsl", "textsc", "error6", "error7" };
103
104 char const * LaTeXSizeNames[14] =
105 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
106   "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
107
108 } // namespace anon
109
110
111 Font::Font(FontInfo bits, Language const * l)
112         : bits_(bits), lang_(l), open_encoding_(false)
113 {
114         if (!lang_)
115                 lang_ = default_language;
116 }
117
118
119 bool Font::isRightToLeft() const
120 {
121         return lang_->rightToLeft();
122 }
123
124
125 bool Font::isVisibleRightToLeft() const
126 {
127         return (lang_->rightToLeft() &&
128                 bits_.number() != FONT_ON);
129 }
130
131
132 void Font::setLanguage(Language const * l)
133 {
134         lang_ = l;
135 }
136
137
138 /// Updates font settings according to request
139 void Font::update(Font const & newfont,
140                      Language const * document_language,
141                      bool toggleall)
142 {
143         bits_.update(newfont.fontInfo(), toggleall);
144
145         if (newfont.language() == language() && toggleall)
146                 if (language() == document_language)
147                         setLanguage(default_language);
148                 else
149                         setLanguage(document_language);
150         else if (newfont.language() != ignore_language)
151                 setLanguage(newfont.language());
152 }
153
154
155 docstring const stateText(FontInfo const & f)
156 {
157         odocstringstream os;
158         if (f.family() != INHERIT_FAMILY)
159                 os << _(GUIFamilyNames[f.family()]) << ", ";
160         if (f.series() != INHERIT_SERIES)
161                 os << _(GUISeriesNames[f.series()]) << ", ";
162         if (f.shape() != INHERIT_SHAPE)
163                 os << _(GUIShapeNames[f.shape()]) << ", ";
164         if (f.size() != FONT_SIZE_INHERIT)
165                 os << _(GUISizeNames[f.size()]) << ", ";
166         if (f.color() != Color_inherit)
167                 os << lcolor.getGUIName(f.color()) << ", ";
168         // FIXME: uncomment this when we support background.
169         //if (f.background() != Color_inherit)
170         //      os << lcolor.getGUIName(f.background()) << ", ";
171         if (f.emph() != FONT_INHERIT)
172                 os << bformat(_("Emphasis %1$s, "),
173                               _(GUIMiscNames[f.emph()]));
174         if (f.underbar() != FONT_INHERIT)
175                 os << bformat(_("Underline %1$s, "),
176                               _(GUIMiscNames[f.underbar()]));
177         if (f.noun() != FONT_INHERIT)
178                 os << bformat(_("Noun %1$s, "),
179                               _(GUIMiscNames[f.noun()]));
180         if (f == inherit_font)
181                 os << _("Default") << ", ";
182
183         return os.str();
184 }
185
186
187 docstring const Font::stateText(BufferParams * params) const
188 {
189         odocstringstream os;
190         os << lyx::stateText(bits_);
191         if (!params || (language() != params->language))
192                 os << bformat(_("Language: %1$s, "),
193                               _(language()->display()));
194         if (bits_.number() != FONT_OFF)
195                 os << bformat(_("  Number %1$s"),
196                               _(GUIMiscNames[bits_.number()]));
197         return rtrim(os.str(), ", ");
198 }
199
200
201 // Set family according to lyx format string
202 void setLyXFamily(string const & fam, FontInfo & f)
203 {
204         string const s = ascii_lowercase(fam);
205
206         int i = 0;
207         while (LyXFamilyNames[i] != s &&
208                LyXFamilyNames[i] != string("error"))
209                 ++i;
210         if (s == LyXFamilyNames[i])
211                 f.setFamily(FontFamily(i));
212         else
213                 lyxerr << "setLyXFamily: Unknown family `"
214                        << s << '\'' << endl;
215 }
216
217
218 // Set series according to lyx format string
219 void setLyXSeries(string const & ser, FontInfo & f)
220 {
221         string const s = ascii_lowercase(ser);
222
223         int i = 0;
224         while (LyXSeriesNames[i] != s &&
225                LyXSeriesNames[i] != string("error")) ++i;
226         if (s == LyXSeriesNames[i]) {
227                 f.setSeries(FontSeries(i));
228         } else
229                 lyxerr << "setLyXSeries: Unknown series `"
230                        << s << '\'' << endl;
231 }
232
233
234 // Set shape according to lyx format string
235 void setLyXShape(string const & sha, FontInfo & f)
236 {
237         string const s = ascii_lowercase(sha);
238
239         int i = 0;
240         while (LyXShapeNames[i] != s && LyXShapeNames[i] != string("error"))
241                         ++i;
242         if (s == LyXShapeNames[i])
243                 f.setShape(FontShape(i));
244         else
245                 lyxerr << "Font::setLyXShape: Unknown shape `"
246                        << s << '\'' << endl;
247 }
248
249
250 // Set size according to lyx format string
251 void setLyXSize(string const & siz, FontInfo & f)
252 {
253         string const s = ascii_lowercase(siz);
254         int i = 0;
255         while (LyXSizeNames[i] != s && LyXSizeNames[i] != string("error"))
256                 ++i;
257         if (s == LyXSizeNames[i]) {
258                 f.setSize(FontSize(i));
259         } else
260                 lyxerr << "Font::setLyXSize: Unknown size `"
261                        << s << '\'' << endl;
262 }
263
264
265 // Set size according to lyx format string
266 FontState Font::setLyXMisc(string const & siz)
267 {
268         string const s = ascii_lowercase(siz);
269         int i = 0;
270         while (LyXMiscNames[i] != s &&
271                LyXMiscNames[i] != string("error")) ++i;
272         if (s == LyXMiscNames[i])
273                 return FontState(i);
274         lyxerr << "Font::setLyXMisc: Unknown misc flag `"
275                << s << '\'' << endl;
276         return FONT_OFF;
277 }
278
279
280 /// Sets color after LyX text format
281 void setLyXColor(string const & col, FontInfo & f)
282 {
283         f.setColor(lcolor.getFromLyXName(col));
284 }
285
286
287 // Returns size in latex format
288 string const Font::latexSize() const
289 {
290         return LaTeXSizeNames[bits_.size()];
291 }
292
293
294 // Read a font definition from given file in lyx format
295 // Used for layouts
296 FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
297 {
298         FontInfo f = fi;
299         bool error = false;
300         bool finished = false;
301         while (!finished && lex.isOK() && !error) {
302                 lex.next();
303                 string const tok = ascii_lowercase(lex.getString());
304
305                 if (tok.empty()) {
306                         continue;
307                 } else if (tok == "endfont") {
308                         finished = true;
309                 } else if (tok == "family") {
310                         lex.next();
311                         string const ttok = lex.getString();
312                         setLyXFamily(ttok, f);
313                 } else if (tok == "series") {
314                         lex.next();
315                         string const ttok = lex.getString();
316                         setLyXSeries(ttok, f);
317                 } else if (tok == "shape") {
318                         lex.next();
319                         string const ttok = lex.getString();
320                         setLyXShape(ttok, f);
321                 } else if (tok == "size") {
322                         lex.next();
323                         string const ttok = lex.getString();
324                         setLyXSize(ttok, f);
325                 } else if (tok == "misc") {
326                         lex.next();
327                         string const ttok = ascii_lowercase(lex.getString());
328
329                         if (ttok == "no_bar") {
330                                 f.setUnderbar(FONT_OFF);
331                         } else if (ttok == "no_emph") {
332                                 f.setEmph(FONT_OFF);
333                         } else if (ttok == "no_noun") {
334                                 f.setNoun(FONT_OFF);
335                         } else if (ttok == "emph") {
336                                 f.setEmph(FONT_ON);
337                         } else if (ttok == "underbar") {
338                                 f.setUnderbar(FONT_ON);
339                         } else if (ttok == "noun") {
340                                 f.setNoun(FONT_ON);
341                         } else {
342                                 lex.printError("Illegal misc type `$$Token'");
343                         }
344                 } else if (tok == "color") {
345                         lex.next();
346                         string const ttok = lex.getString();
347                         setLyXColor(ttok, f);
348                 } else {
349                         lex.printError("Unknown tag `$$Token'");
350                         error = true;
351                 }
352         }
353         return f;
354 }
355
356
357 /// Writes the changes from this font to orgfont in .lyx format in file
358 void Font::lyxWriteChanges(Font const & orgfont,
359                               ostream & os) const
360 {
361         os << "\n";
362         if (orgfont.fontInfo().family() != bits_.family())
363                 os << "\\family " << LyXFamilyNames[bits_.family()] << "\n";
364         if (orgfont.fontInfo().series() != bits_.series())
365                 os << "\\series " << LyXSeriesNames[bits_.series()] << "\n";
366         if (orgfont.fontInfo().shape() != bits_.shape())
367                 os << "\\shape " << LyXShapeNames[bits_.shape()] << "\n";
368         if (orgfont.fontInfo().size() != bits_.size())
369                 os << "\\size " << LyXSizeNames[bits_.size()] << "\n";
370         if (orgfont.fontInfo().emph() != bits_.emph())
371                 os << "\\emph " << LyXMiscNames[bits_.emph()] << "\n";
372         if (orgfont.fontInfo().number() != bits_.number())
373                 os << "\\numeric " << LyXMiscNames[bits_.number()] << "\n";
374         if (orgfont.fontInfo().underbar() != bits_.underbar()) {
375                 // This is only for backwards compatibility
376                 switch (bits_.underbar()) {
377                 case FONT_OFF:  os << "\\bar no\n"; break;
378                 case FONT_ON:        os << "\\bar under\n"; break;
379                 case FONT_TOGGLE:       lyxerr << "Font::lyxWriteFontChanges: "
380                                         "FONT_TOGGLE should not appear here!"
381                                        << endl;
382                 break;
383                 case FONT_INHERIT:   os << "\\bar default\n"; break;
384                 case FONT_IGNORE:    lyxerr << "Font::lyxWriteFontChanges: "
385                                         "IGNORE should not appear here!"
386                                        << endl;
387                 break;
388                 }
389         }
390         if (orgfont.fontInfo().noun() != bits_.noun()) {
391                 os << "\\noun " << LyXMiscNames[bits_.noun()] << "\n";
392         }
393         if (orgfont.fontInfo().color() != bits_.color())
394                 os << "\\color " << lcolor.getLyXName(bits_.color()) << '\n';
395         // FIXME: uncomment this when we support background.
396         //if (orgfont.fontInfo().background() != bits_.background())
397         //      os << "\\color " << lcolor.getLyXName(bits_.background()) << '\n';
398         if (orgfont.language() != language() &&
399             language() != latex_language) {
400                 if (language())
401                         os << "\\lang " << language()->lang() << "\n";
402                 else
403                         os << "\\lang unknown\n";
404         }
405 }
406
407
408 /// Writes the head of the LaTeX needed to impose this font
409 // Returns number of chars written.
410 int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
411                                     OutputParams const & runparams,
412                                     Font const & base,
413                                     Font const & prev) const
414 {
415         bool env = false;
416
417         int count = 0;
418         if (language()->babel() != base.language()->babel() &&
419             language() != prev.language()) {
420                 if (language()->lang() == "farsi") {
421                         os << "\\textFR{";
422                         count += 8;
423                 } else if (!isRightToLeft() &&
424                             base.language()->lang() == "farsi") {
425                         os << "\\textLR{";
426                         count += 8;
427                 } else if (language()->lang() == "arabic_arabi") {
428                         os << "\\textAR{";
429                         count += 8;
430                 } else if (!isRightToLeft() &&
431                                 base.language()->lang() == "arabic_arabi") {
432                         os << "\\textLR{";
433                         count += 8;
434                 // currently the remaining RTL languages are arabic_arabtex and hebrew
435                 } else if (isRightToLeft() != prev.isRightToLeft()) {
436                         if (isRightToLeft()) {
437                                 os << "\\R{";
438                                 count += 3;
439                         } else {
440                                 os << "\\L{";
441                                 count += 3;
442                         }
443                 } else if (!language()->babel().empty()) {
444                         string const tmp =
445                                 subst(lyxrc.language_command_local,
446                                       "$$lang", language()->babel());
447                         os << from_ascii(tmp);
448                         count += tmp.length();
449                 } else {
450                         os << '{';
451                         count += 1;
452                 }
453         }
454
455         if (language()->encoding()->package() == Encoding::CJK) {
456                 pair<bool, int> const c = switchEncoding(os, bparams,
457                                 runparams, *(runparams.encoding),
458                                 *(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.getFromLyXName("ascii");
627                 pair<bool, int> const c = switchEncoding(os, bparams,
628                                 runparams, *(runparams.encoding),
629                                 *ascii);
630                 BOOST_ASSERT(c.first);
631                 count += c.second;
632                 runparams.encoding = ascii;
633                 open_encoding_ = false;
634         }
635
636         if (closeLanguage &&
637                         language() != base.language() && language() != next.language()) {
638                 os << '}';
639                 ++count;
640         }
641
642         return count;
643 }
644
645
646 std::string Font::toString(bool const toggle) const
647 {
648         string lang = "ignore";
649         if (language())
650                 lang = language()->lang();
651
652         ostringstream os;
653         os << "family " << bits_.family() << '\n'
654            << "series " << bits_.series() << '\n'
655            << "shape " << bits_.shape() << '\n'
656            << "size " << bits_.size() << '\n'
657            << "emph " << bits_.emph() << '\n'
658            << "underbar " << bits_.underbar() << '\n'
659            << "noun " << bits_.noun() << '\n'
660            << "number " << bits_.number() << '\n'
661            << "color " << bits_.color() << '\n'
662            << "language " << lang << '\n'
663            << "toggleall " << convert<string>(toggle);
664         return os.str();
665 }
666
667
668 bool Font::fromString(string const & data, bool & toggle)
669 {
670         istringstream is(data);
671         Lexer lex(0,0);
672         lex.setStream(is);
673
674         int nset = 0;
675         while (lex.isOK()) {
676                 string token;
677                 if (lex.next())
678                         token = lex.getString();
679
680                 if (token.empty() || !lex.next())
681                         break;
682
683                 if (token == "family") {
684                         int const next = lex.getInteger();
685                         bits_.setFamily(FontFamily(next));
686
687                 } else if (token == "series") {
688                         int const next = lex.getInteger();
689                         bits_.setSeries(FontSeries(next));
690
691                 } else if (token == "shape") {
692                         int const next = lex.getInteger();
693                         bits_.setShape(FontShape(next));
694
695                 } else if (token == "size") {
696                         int const next = lex.getInteger();
697                         bits_.setSize(FontSize(next));
698
699                 } else if (token == "emph" || token == "underbar" ||
700                            token == "noun" || token == "number") {
701
702                         int const next = lex.getInteger();
703                         FontState const misc = FontState(next);
704
705                         if (token == "emph")
706                                 bits_.setEmph(misc);
707                         else if (token == "underbar")
708                                 bits_.setUnderbar(misc);
709                         else if (token == "noun")
710                                 bits_.setNoun(misc);
711                         else if (token == "number")
712                                 bits_.setNumber(misc);
713
714                 } else if (token == "color") {
715                         int const next = lex.getInteger();
716                         bits_.setColor(ColorCode(next));
717
718                 /**
719                 } else if (token == "background") {
720                         int const next = lex.getInteger();
721                         bits_.setBackground(ColorCode(next));
722                 */
723
724                 } else if (token == "language") {
725                         string const next = lex.getString();
726                         if (next == "ignore")
727                                 setLanguage(ignore_language);
728                         else
729                                 setLanguage(languages.getLanguage(next));
730
731                 } else if (token == "toggleall") {
732                         toggle = lex.getBool();
733
734                 } else {
735                         // Unrecognised token
736                         break;
737                 }
738
739                 ++nset;
740         }
741         return (nset > 0);
742 }
743
744
745 void Font::validate(LaTeXFeatures & features) const
746 {
747         BufferParams const & bparams = features.bufferParams();
748         Language const * doc_language = bparams.language;
749
750         if (bits_.noun() == FONT_ON) {
751                 LYXERR(Debug::LATEX, "font.noun: " << bits_.noun());
752                 features.require("noun");
753                 LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText(0)));
754         }
755         switch (bits_.color()) {
756                 case Color_none:
757                 case Color_inherit:
758                 case Color_ignore:
759                         // probably we should put here all interface colors used for
760                         // font displaying! For now I just add this ones I know of (Jug)
761                 case Color_latex:
762                 case Color_note:
763                         break;
764                 default:
765                         features.require("color");
766                         LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText(0)));
767         }
768
769         // FIXME: Do something for background and soul package?
770
771         if (lang_->babel() != doc_language->babel() &&
772                 lang_ != ignore_language &&
773                 lang_ != latex_language)
774         {
775                 features.useLanguage(lang_);
776                 LYXERR(Debug::LATEX, "Found language " << lang_->lang());
777         }
778 }
779
780
781 ostream & operator<<(ostream & os, FontState fms)
782 {
783         return os << int(fms);
784 }
785
786
787 ostream & operator<<(std::ostream & os, FontInfo const & f)
788 {
789         return os << "font:"
790                 << " family " << f.family()
791                 << " series " << f.series()
792                 << " shape " << f.shape()
793                 << " size " << f.size()
794                 << " color " << f.color()
795                 // FIXME: uncomment this when we support background.
796                 //<< " background " << f.background()
797                 << " emph " << f.emph()
798                 << " underbar " << f.underbar()
799                 << " noun " << f.noun()
800                 << " number " << f.number();
801 }
802
803
804 std::ostream & operator<<(std::ostream & os, Font const & font)
805 {
806         return os << font.bits_
807                 << " lang: " << (font.lang_ ? font.lang_->lang() : 0);
808 }
809
810
811 } // namespace lyx