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