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