]> git.lyx.org Git - lyx.git/blob - src/Font.cpp
Remove question marks from Windows dialogs
[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 (bits_.number() == FONT_ON && prev.fontInfo().number() != FONT_ON
347                 && (language()->lang() == "hebrew"
348                         || language()->lang() == "farsi" 
349                         || language()->lang() == "arabic_arabi")) {
350                 os << "{\\beginL ";
351                 count += 9;
352         }
353
354         FontInfo f = bits_;
355         f.reduce(base.bits_);
356
357         if (f.family() != INHERIT_FAMILY) {
358                 os << '\\'
359                    << LaTeXFamilyNames[f.family()]
360                    << '{';
361                 count += strlen(LaTeXFamilyNames[f.family()]) + 2;
362                 env = true; //We have opened a new environment
363         }
364         if (f.series() != INHERIT_SERIES) {
365                 os << '\\'
366                    << LaTeXSeriesNames[f.series()]
367                    << '{';
368                 count += strlen(LaTeXSeriesNames[f.series()]) + 2;
369                 env = true; //We have opened a new environment
370         }
371         if (f.shape() != INHERIT_SHAPE) {
372                 os << '\\'
373                    << LaTeXShapeNames[f.shape()]
374                    << '{';
375                 count += strlen(LaTeXShapeNames[f.shape()]) + 2;
376                 env = true; //We have opened a new environment
377         }
378         if (f.color() != Color_inherit && f.color() != Color_ignore) {
379                 os << "\\textcolor{"
380                    << from_ascii(lcolor.getLaTeXName(f.color()))
381                    << "}{";
382                 count += lcolor.getLaTeXName(f.color()).length() + 13;
383                 env = true; //We have opened a new environment
384         }
385         // FIXME: uncomment this when we support background.
386         /*
387         if (f.background() != Color_inherit && f.background() != Color_ignore) {
388                 os << "\\textcolor{"
389                    << from_ascii(lcolor.getLaTeXName(f.background()))
390                    << "}{";
391                 count += lcolor.getLaTeXName(f.background()).length() + 13;
392                 env = true; //We have opened a new environment
393         }
394         */
395         if (f.emph() == FONT_ON) {
396                 os << "\\emph{";
397                 count += 6;
398                 env = true; //We have opened a new environment
399         }
400         // \noun{} is a LyX special macro
401         if (f.noun() == FONT_ON) {
402                 os << "\\noun{";
403                 count += 6;
404                 env = true; //We have opened a new environment
405         }
406         if (f.size() != FONT_SIZE_INHERIT) {
407                 // If we didn't open an environment above, we open one here
408                 if (!env) {
409                         os << '{';
410                         ++count;
411                 }
412                 os << '\\'
413                    << LaTeXSizeNames[f.size()]
414                    << "{}";
415                 count += strlen(LaTeXSizeNames[f.size()]) + 3;
416         }
417         // The ulem commands need to be on the deepest nesting level
418         // because ulem puts every nested group or macro in a box,
419         // which prevents linebreaks (#8424, #8733)
420         if (f.underbar() == FONT_ON) {
421                 os << "\\uline{";
422                 count += 10;
423                 ++runparams.inulemcmd;
424         }
425         if (f.strikeout() == FONT_ON) {
426                 os << "\\sout{";
427                 count += 9;
428                 ++runparams.inulemcmd;
429         }
430         if (f.uuline() == FONT_ON) {
431                 os << "\\uuline{";
432                 count += 11;
433                 ++runparams.inulemcmd;
434         }
435         if (f.uwave() == FONT_ON) {
436                 os << "\\uwave{";
437                 count += 10;
438                 ++runparams.inulemcmd;
439         }
440         return count;
441 }
442
443
444 /// Writes ending block of LaTeX needed to close use of this font
445 // Returns number of chars written
446 // This one corresponds to latexWriteStartChanges(). (Asger)
447 int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
448                                   OutputParams const & runparams,
449                                   Font const & base,
450                                   Font const & next,
451                                   bool const & closeLanguage) const
452 {
453         int count = 0;
454         bool env = false;
455
456         // reduce the current font to changes against the base
457         // font (of the layout). We use a temporary for this to
458         // avoid changing this font instance, as that would break
459         FontInfo f = bits_;
460         f.reduce(base.bits_);
461
462         if (f.family() != INHERIT_FAMILY) {
463                 os << '}';
464                 ++count;
465                 env = true; // Size change need not bother about closing env.
466         }
467         if (f.series() != INHERIT_SERIES) {
468                 os << '}';
469                 ++count;
470                 env = true; // Size change need not bother about closing env.
471         }
472         if (f.shape() != INHERIT_SHAPE) {
473                 os << '}';
474                 ++count;
475                 env = true; // Size change need not bother about closing env.
476         }
477         if (f.color() != Color_inherit && f.color() != Color_ignore) {
478                 os << '}';
479                 ++count;
480                 env = true; // Size change need not bother about closing env.
481         }
482         if (f.emph() == FONT_ON) {
483                 os << '}';
484                 ++count;
485                 env = true; // Size change need not bother about closing env.
486         }
487         if (f.noun() == FONT_ON) {
488                 os << '}';
489                 ++count;
490                 env = true; // Size change need not bother about closing env.
491         }
492         if (f.size() != FONT_SIZE_INHERIT) {
493                 // We only have to close if only size changed
494                 if (!env) {
495                         os << '}';
496                         ++count;
497                 }
498         }
499         if (f.underbar() == FONT_ON) {
500                 os << '}';
501                 ++count;
502                 --runparams.inulemcmd;
503         }
504         if (f.strikeout() == FONT_ON) {
505                 os << '}';
506                 ++count;
507                 --runparams.inulemcmd;
508         }
509         if (f.uuline() == FONT_ON) {
510                 os << '}';
511                 ++count;
512                 --runparams.inulemcmd;
513         }
514         if (f.uwave() == FONT_ON) {
515                 os << '}';
516                 ++count;
517                 --runparams.inulemcmd;
518         }
519
520         // If the current language is Hebrew, Arabic, or Farsi
521         // the numbers are written Left-to-Right. ArabTeX package
522         // reorders the number automatically but the packages used
523         // for Hebrew and Farsi (Arabi) do not.
524         if (bits_.number() == FONT_ON && next.fontInfo().number() != FONT_ON
525                 && (language()->lang() == "hebrew"
526                         || language()->lang() == "farsi"
527                         || language()->lang() == "arabic_arabi")) {
528                 os << "\\endL}";
529                 count += 6;
530         }
531
532         if (open_encoding_) {
533                 // We need to close the encoding even if it does not change
534                 // to do correct environment nesting
535                 Encoding const * const ascii = encodings.fromLyXName("ascii");
536                 pair<bool, int> const c = switchEncoding(os.os(), bparams,
537                                 runparams, *ascii);
538                 LATTEST(c.first);
539                 count += c.second;
540                 runparams.encoding = ascii;
541                 open_encoding_ = false;
542         }
543
544         if (closeLanguage
545             && language() != base.language() && language() != next.language()
546             && language()->encoding()->package() != Encoding::CJK) {
547                 os << '}';
548                 ++count;
549                 if (runparams.use_polyglossia)
550                         popPolyglossiaLang();
551         }
552
553         return count;
554 }
555
556
557 string Font::toString(bool const toggle) const
558 {
559         string const lang = (language() == reset_language)
560                 ? "reset" : language()->lang();
561
562         ostringstream os;
563         os << "family " << bits_.family() << '\n'
564            << "series " << bits_.series() << '\n'
565            << "shape " << bits_.shape() << '\n'
566            << "size " << bits_.size() << '\n'
567            << "emph " << bits_.emph() << '\n'
568            << "underbar " << bits_.underbar() << '\n'
569            << "strikeout " << bits_.strikeout() << '\n'
570            << "uuline " << bits_.uuline() << '\n'
571            << "uwave " << bits_.uwave() << '\n'
572            << "noun " << bits_.noun() << '\n'
573            << "number " << bits_.number() << '\n'
574            << "color " << bits_.color() << '\n'
575            << "language " << lang << '\n'
576            << "toggleall " << convert<string>(toggle);
577         return os.str();
578 }
579
580
581 bool Font::fromString(string const & data, bool & toggle)
582 {
583         istringstream is(data);
584         Lexer lex;
585         lex.setStream(is);
586
587         int nset = 0;
588         while (lex.isOK()) {
589                 string token;
590                 if (lex.next())
591                         token = lex.getString();
592
593                 if (token.empty() || !lex.next())
594                         break;
595
596                 if (token == "family") {
597                         int const next = lex.getInteger();
598                         bits_.setFamily(FontFamily(next));
599
600                 } else if (token == "series") {
601                         int const next = lex.getInteger();
602                         bits_.setSeries(FontSeries(next));
603
604                 } else if (token == "shape") {
605                         int const next = lex.getInteger();
606                         bits_.setShape(FontShape(next));
607
608                 } else if (token == "size") {
609                         int const next = lex.getInteger();
610                         bits_.setSize(FontSize(next));
611
612                 } else if (token == "emph" || token == "underbar" ||
613                            token == "noun" || token == "number" ||
614                            token == "uuline" || token == "uwave" ||
615                            token == "strikeout") {
616
617                         int const next = lex.getInteger();
618                         FontState const misc = FontState(next);
619
620                         if (token == "emph")
621                                 bits_.setEmph(misc);
622                         else if (token == "underbar")
623                                 bits_.setUnderbar(misc);
624                         else if (token == "strikeout")
625                                 bits_.setStrikeout(misc);
626                         else if (token == "uuline")
627                                 bits_.setUuline(misc);
628                         else if (token == "uwave")
629                                 bits_.setUwave(misc);
630                         else if (token == "noun")
631                                 bits_.setNoun(misc);
632                         else if (token == "number")
633                                 bits_.setNumber(misc);
634
635                 } else if (token == "color") {
636                         int const next = lex.getInteger();
637                         bits_.setColor(ColorCode(next));
638
639                 /**
640                 } else if (token == "background") {
641                         int const next = lex.getInteger();
642                         bits_.setBackground(ColorCode(next));
643                 */
644
645                 } else if (token == "language") {
646                         string const next = lex.getString();
647                         setLanguage(languages.getLanguage(next));
648
649                 } else if (token == "toggleall") {
650                         toggle = lex.getBool();
651
652                 } else {
653                         // Unrecognised token
654                         break;
655                 }
656
657                 ++nset;
658         }
659         return (nset > 0);
660 }
661
662
663 void Font::validate(LaTeXFeatures & features) const
664 {
665         BufferParams const & bparams = features.bufferParams();
666         Language const * doc_language = bparams.language;
667
668         if (bits_.noun() == FONT_ON) {
669                 LYXERR(Debug::LATEX, "font.noun: " << bits_.noun());
670                 features.require("noun");
671                 LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText(0)));
672         }
673         if (bits_.underbar() == FONT_ON) {
674                 LYXERR(Debug::LATEX, "font.underline: " << bits_.underbar());
675                 features.require("ulem");
676                 LYXERR(Debug::LATEX, "Underline enabled. Font: " << to_utf8(stateText(0)));
677         }
678         if (bits_.strikeout() == FONT_ON) {
679                 LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
680                 features.require("ulem");
681                 LYXERR(Debug::LATEX, "Strikeout enabled. Font: " << to_utf8(stateText(0)));
682         }
683         if (bits_.uuline() == FONT_ON) {
684                 LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline());
685                 features.require("ulem");
686                 LYXERR(Debug::LATEX, "Double underline enabled. Font: " << to_utf8(stateText(0)));
687         }
688         if (bits_.uwave() == FONT_ON) {
689                 LYXERR(Debug::LATEX, "font.uwave: " << bits_.uwave());
690                 features.require("ulem");
691                 LYXERR(Debug::LATEX, "Wavy underline enabled. Font: " << to_utf8(stateText(0)));
692         }
693         switch (bits_.color()) {
694                 case Color_none:
695                 case Color_inherit:
696                 case Color_ignore:
697                         // probably we should put here all interface colors used for
698                         // font displaying! For now I just add this ones I know of (Jug)
699                 case Color_latex:
700                 case Color_notelabel:
701                         break;
702                 case Color_brown:
703                 case Color_darkgray:
704                 case Color_gray:
705                 case Color_lightgray:
706                 case Color_lime:
707                 case Color_olive:
708                 case Color_orange:
709                 case Color_pink:
710                 case Color_purple:
711                 case Color_teal:
712                 case Color_violet:
713                         features.require("xcolor");
714                         break;
715                 default:
716                         features.require("color");
717                         LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText(0)));
718         }
719
720         // FIXME: Do something for background and soul package?
721
722         if (((features.usePolyglossia() && lang_->polyglossia() != doc_language->polyglossia())
723              || (features.useBabel() && lang_->babel() != doc_language->babel())
724              || (doc_language->encoding()->package() == Encoding::CJK && lang_ != doc_language))
725             && lang_ != ignore_language
726             && lang_ != latex_language)
727         {
728                 features.useLanguage(lang_);
729                 LYXERR(Debug::LATEX, "Found language " << lang_->lang());
730         }
731 }
732
733
734 ostream & operator<<(ostream & os, FontState fms)
735 {
736         return os << int(fms);
737 }
738
739
740 ostream & operator<<(ostream & os, FontInfo const & f)
741 {
742         return os << "font:"
743                 << " family " << f.family()
744                 << " series " << f.series()
745                 << " shape " << f.shape()
746                 << " size " << f.size()
747                 << " color " << f.color()
748                 // FIXME: uncomment this when we support background.
749                 //<< " background " << f.background()
750                 << " emph " << f.emph()
751                 << " underbar " << f.underbar()
752                 << " strikeout " << f.strikeout()
753                 << " uuline " << f.uuline()
754                 << " uwave " << f.uwave()
755                 << " noun " << f.noun()
756                 << " number " << f.number();
757 }
758
759
760 ostream & operator<<(ostream & os, Font const & font)
761 {
762         return os << font.bits_
763                 << " lang: " << (font.lang_ ? font.lang_->lang() : 0);
764 }
765
766
767 } // namespace lyx