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