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