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