]> git.lyx.org Git - lyx.git/blob - src/Font.cpp
Run codespell on src/frontends
[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 extern char const * GUIMiscNames[5];
53
54 namespace {
55
56 //
57 // Strings used to write LaTeX files
58 //
59 char const * LaTeXFamilyNames[NUM_FAMILIES + 2] =
60 { "textrm", "textsf", "texttt", "error1", "error2", "error3", "error4",
61   "error5", "error6", "error7", "error8", "error9", "error10", "error11",
62   "error12", "error13", "error14" };
63
64 char const * LaTeXSeriesNames[NUM_SERIES + 2] =
65 { "textmd", "textbf", "error4", "error5" };
66
67 char const * LaTeXShapeNames[NUM_SHAPE + 2] =
68 { "textup", "textit", "textsl", "textsc", "error6", "error7" };
69
70 char const * LaTeXSizeNames[NUM_SIZE + 4] =
71 { "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
72   "Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
73
74 } // namespace
75
76
77 Font::Font(FontInfo bits, Language const * l)
78         : bits_(bits), lang_(l), open_encoding_(false)
79 {
80         if (!lang_)
81                 lang_ = default_language;
82 }
83
84
85 bool Font::isRightToLeft() const
86 {
87         return lang_->rightToLeft();
88 }
89
90
91 bool Font::isVisibleRightToLeft() const
92 {
93         return (lang_->rightToLeft() &&
94                 bits_.number() != FONT_ON);
95 }
96
97
98 void Font::setLanguage(Language const * l)
99 {
100         lang_ = l;
101 }
102
103
104 /// Updates font settings according to request
105 void Font::update(Font const & newfont,
106                      Language const * document_language,
107                      bool toggleall)
108 {
109         bits_.update(newfont.fontInfo(), toggleall);
110
111         if (newfont.language() == language() && toggleall)
112                 if (language() == document_language)
113                         setLanguage(default_language);
114                 else
115                         setLanguage(document_language);
116         else if (newfont.language() == reset_language)
117                 setLanguage(document_language);
118         else if (newfont.language() != ignore_language)
119                 setLanguage(newfont.language());
120 }
121
122
123 docstring const Font::stateText(BufferParams * params, bool const terse) const
124 {
125         odocstringstream os;
126         os << bits_.stateText(terse);
127         if ((!params || (language() != params->language))
128             && (!terse || language() != ignore_language)) {
129                 // reset_language is a null pointer!
130                 os << bformat(_("Language: %1$s, "),
131                               (language() == reset_language) ? _("Default")
132                                                              : _(language()->display()));
133         }
134         if (bits_.number() != FONT_OFF)
135                 os << "  " << bformat(_("Number %1$s"),
136                               _(GUIMiscNames[bits_.number()]));
137         return rtrim(os.str(), ", ");
138 }
139
140
141 // Returns size in latex format
142 string const Font::latexSize() const
143 {
144         return LaTeXSizeNames[bits_.size()];
145 }
146
147
148 /// Writes the changes from this font to orgfont in .lyx format in file
149 void Font::lyxWriteChanges(Font const & orgfont,
150                               ostream & os) const
151 {
152         os << "\n";
153         if (orgfont.fontInfo().family() != bits_.family())
154                 os << "\\family " << LyXFamilyNames[bits_.family()] << "\n";
155         if (orgfont.fontInfo().series() != bits_.series())
156                 os << "\\series " << LyXSeriesNames[bits_.series()] << "\n";
157         if (orgfont.fontInfo().shape() != bits_.shape())
158                 os << "\\shape " << LyXShapeNames[bits_.shape()] << "\n";
159         if (orgfont.fontInfo().size() != bits_.size())
160                 os << "\\size " << LyXSizeNames[bits_.size()] << "\n";
161         // FIXME: shall style be handled there? Probably not.
162         if (orgfont.fontInfo().emph() != bits_.emph())
163                 os << "\\emph " << LyXMiscNames[bits_.emph()] << "\n";
164         if (orgfont.fontInfo().number() != bits_.number())
165                 os << "\\numeric " << LyXMiscNames[bits_.number()] << "\n";
166         if (orgfont.fontInfo().nospellcheck() != bits_.nospellcheck())
167                 os << "\\nospellcheck " << LyXMiscNames[bits_.nospellcheck()] << "\n";
168         if (orgfont.fontInfo().underbar() != bits_.underbar()) {
169                 // This is only for backwards compatibility
170                 switch (bits_.underbar()) {
171                 case FONT_OFF:  os << "\\bar no\n"; break;
172                 case FONT_ON:        os << "\\bar under\n"; break;
173                 case FONT_TOGGLE:       lyxerr << "Font::lyxWriteFontChanges: "
174                                         "FONT_TOGGLE should not appear here!"
175                                        << endl;
176                 break;
177                 case FONT_INHERIT:   os << "\\bar default\n"; break;
178                 case FONT_IGNORE:    lyxerr << "Font::lyxWriteFontChanges: "
179                                         "IGNORE should not appear here!"
180                                        << endl;
181                 break;
182                 }
183         }
184         if (orgfont.fontInfo().strikeout() != bits_.strikeout()) {
185                 os << "\\strikeout " << LyXMiscNames[bits_.strikeout()] << "\n";
186         }
187         if (orgfont.fontInfo().xout() != bits_.xout()) {
188                 os << "\\xout " << LyXMiscNames[bits_.xout()] << "\n";
189         }
190         if (orgfont.fontInfo().uuline() != bits_.uuline()) {
191                 os << "\\uuline " << LyXMiscNames[bits_.uuline()] << "\n";
192         }
193         if (orgfont.fontInfo().uwave() != bits_.uwave()) {
194                 os << "\\uwave " << LyXMiscNames[bits_.uwave()] << "\n";
195         }
196         if (orgfont.fontInfo().noun() != bits_.noun()) {
197                 os << "\\noun " << LyXMiscNames[bits_.noun()] << "\n";
198         }
199         if (orgfont.fontInfo().color() != bits_.color())
200                 os << "\\color " << lcolor.getLyXName(bits_.color()) << '\n';
201         // FIXME: uncomment this when we support background.
202         //if (orgfont.fontInfo().background() != bits_.background())
203         //      os << "\\color " << lcolor.getLyXName(bits_.background()) << '\n';
204         if (orgfont.language() != language() &&
205             language() != latex_language) {
206                 if (language())
207                         os << "\\lang " << language()->lang() << "\n";
208                 else
209                         os << "\\lang unknown\n";
210         }
211 }
212
213
214 /// Writes the head of the LaTeX needed to impose this font
215 // Returns number of chars written.
216 int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
217                                     OutputParams const & runparams,
218                                     Font const & base,
219                                     Font const & prev) const
220 {
221         bool env = false;
222
223         int count = 0;
224
225         // polyglossia or babel?
226         if (runparams.use_polyglossia
227             && language()->lang() != base.language()->lang()
228             && language() != prev.language()) {
229                 if (!language()->polyglossia().empty()) {
230                         string tmp = "\\text" + language()->polyglossia();
231                         if (!language()->polyglossiaOpts().empty()) {
232                                 tmp += "[" + language()->polyglossiaOpts() + "]";
233                                 if (runparams.use_hyperref && runparams.moving_arg)
234                                         // We need to strip the command for
235                                         // the pdf string, see #11813
236                                         tmp = "\\texorpdfstring{" + tmp + "}{}";
237                         }
238                         tmp += "{";
239                         os << from_ascii(tmp);
240                         count += tmp.length();
241                         pushLanguageName(language()->polyglossia(), true);
242                 } else if (language()->encoding()->package() != Encoding::CJK) {
243                         os << '{';
244                         count += 1;
245                 }
246         } else if (language()->babel() != base.language()->babel() &&
247             language() != prev.language()) {
248                 if (language()->lang() == "farsi") {
249                         os << "\\textFR{";
250                         count += 8;
251                 } else if (!isRightToLeft() &&
252                             base.language()->lang() == "farsi") {
253                         os << "\\textLR{";
254                         count += 8;
255                 } else if (language()->lang() == "arabic_arabi") {
256                         os << "\\textAR{";
257                         count += 8;
258                 } else if (!isRightToLeft() &&
259                                 base.language()->lang() == "arabic_arabi") {
260                         os << "\\textLR{";
261                         count += 8;
262                 // currently the remaining RTL languages are arabic_arabtex and hebrew
263                 } else if (isRightToLeft() != prev.isRightToLeft()) {
264                         if (isRightToLeft()) {
265                                 os << "\\R{";
266                                 count += 3;
267                         } else {
268                                 os << "\\L{";
269                                 count += 3;
270                         }
271                 } else if (!language()->babel().empty()) {
272                         string const tmp =
273                                 subst(lyxrc.language_command_local,
274                                       "$$lang", language()->babel());
275                         os << from_ascii(tmp);
276                         count += tmp.length();
277                         if (!lyxrc.language_command_end.empty())
278                                 pushLanguageName(language()->babel(), true);
279                 } else if (language()->encoding()->package() != Encoding::CJK) {
280                         os << '{';
281                         count += 1;
282                 }
283         }
284
285         if (language()->encoding()->package() == Encoding::CJK) {
286                 pair<bool, int> const c = switchEncoding(os, bparams,
287                                 runparams, *(language()->encoding()));
288                 if (c.first) {
289                         open_encoding_ = true;
290                         count += c.second;
291                         runparams.encoding = language()->encoding();
292                 }
293         }
294
295         FontInfo f = bits_;
296         f.reduce(base.bits_);
297         FontInfo p = bits_;
298         p.reduce(prev.bits_);
299
300         if (f.family() != INHERIT_FAMILY) {
301                 os << '\\'
302                    << LaTeXFamilyNames[f.family()]
303                    << '{';
304                 count += strlen(LaTeXFamilyNames[f.family()]) + 2;
305                 env = true; //We have opened a new environment
306         }
307         if (f.series() != INHERIT_SERIES) {
308                 os << '\\'
309                    << LaTeXSeriesNames[f.series()]
310                    << '{';
311                 count += strlen(LaTeXSeriesNames[f.series()]) + 2;
312                 env = true; //We have opened a new environment
313         }
314         if (f.shape() != INHERIT_SHAPE) {
315                 os << '\\'
316                    << LaTeXShapeNames[f.shape()]
317                    << '{';
318                 count += strlen(LaTeXShapeNames[f.shape()]) + 2;
319                 env = true; //We have opened a new environment
320         }
321         if (f.color() != Color_inherit && f.color() != Color_ignore) {
322                 if (f.color() == Color_none && p.color() != Color_none) {
323                         // Color none: Close previous color, if any
324                         os << '}';
325                         ++count;
326                 } else if (f.color() != Color_none) {
327                         os << "\\textcolor{"
328                            << from_ascii(lcolor.getLaTeXName(f.color()))
329                            << "}{";
330                         count += lcolor.getLaTeXName(f.color()).length() + 13;
331                 }
332                 env = true; //We have opened a new environment
333         }
334         // FIXME: uncomment this when we support background.
335         /*
336         if (f.background() != Color_inherit && f.background() != Color_ignore) {
337                 os << "\\textcolor{"
338                    << from_ascii(lcolor.getLaTeXName(f.background()))
339                    << "}{";
340                 count += lcolor.getLaTeXName(f.background()).length() + 13;
341                 env = true; //We have opened a new environment
342         }
343         */
344         // If the current language is Hebrew, Arabic, or Farsi
345         // the numbers are written Left-to-Right. ArabTeX package
346         // and bidi (polyglossia with XeTeX) reorder the number automatically
347         // but the packages used for Hebrew and Farsi (Arabi) do not.
348         if (!runparams.useBidiPackage()
349             && !runparams.pass_thru
350             && bits_.number() == FONT_ON
351             && prev.fontInfo().number() != FONT_ON
352             && (language()->lang() == "hebrew"
353                 || language()->lang() == "farsi"
354                 || language()->lang() == "arabic_arabi")) {
355                 if (runparams.use_polyglossia) {
356                         // LuaTeX/luabidi
357                         os << "\\LR{";
358                         count += 5;
359                 } else {
360                         os << "{\\beginL ";
361                         count += 9;
362                 }
363         }
364         if (f.emph() == FONT_ON) {
365                 os << "\\emph{";
366                 count += 6;
367                 env = true; //We have opened a new environment
368         }
369         // \noun{} is a LyX special macro
370         if (f.noun() == FONT_ON) {
371                 os << "\\noun{";
372                 count += 6;
373                 env = true; //We have opened a new environment
374         }
375         if (f.size() != INHERIT_SIZE) {
376                 // If we didn't open an environment above, we open one here
377                 if (!env) {
378                         os << '{';
379                         ++count;
380                 }
381                 os << '\\'
382                    << LaTeXSizeNames[f.size()]
383                    << "{}";
384                 count += strlen(LaTeXSizeNames[f.size()]) + 3;
385         }
386         // The ulem commands need to be on the deepest nesting level
387         // because ulem puts every nested group or macro in a box,
388         // which prevents linebreaks (#8424, #8733)
389         if (f.underbar() == FONT_ON) {
390                 os << "\\uline{";
391                 count += 10;
392                 ++runparams.inulemcmd;
393         }
394         if (f.uuline() == FONT_ON) {
395                 os << "\\uuline{";
396                 count += 11;
397                 ++runparams.inulemcmd;
398         }
399         if (f.strikeout() == FONT_ON) {
400                 os << "\\sout{";
401                 count += 9;
402                 ++runparams.inulemcmd;
403         }
404         if (f.xout() == FONT_ON) {
405                 os << "\\xout{";
406                 count += 9;
407                 ++runparams.inulemcmd;
408         }
409         if (f.uwave() == FONT_ON) {
410                 if (runparams.inulemcmd) {
411                         // needed with nested uwave in xout
412                         // see https://tex.stackexchange.com/a/263042
413                         os << "\\ULdepth=1000pt";
414                         count += 15;
415                 }
416                 os << "\\uwave{";
417                 count += 10;
418                 ++runparams.inulemcmd;
419         }
420         return count;
421 }
422
423
424 /// Writes ending block of LaTeX needed to close use of this font
425 // Returns number of chars written
426 // This one corresponds to latexWriteStartChanges(). (Asger)
427 int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
428                                   OutputParams const & runparams,
429                                   Font const & base,
430                                   Font const & next,
431                                   bool & needPar,
432                                   bool const & closeLanguage) const
433 {
434         int count = 0;
435         bool env = false;
436
437         // reduce the current font to changes against the base
438         // font (of the layout). We use a temporary for this to
439         // avoid changing this font instance, as that would break
440         FontInfo f = bits_;
441         f.reduce(base.bits_);
442
443         if (f.family() != INHERIT_FAMILY) {
444                 os << '}';
445                 ++count;
446                 env = true; // Size change need not bother about closing env.
447         }
448         if (f.series() != INHERIT_SERIES) {
449                 os << '}';
450                 ++count;
451                 env = true; // Size change need not bother about closing env.
452         }
453         if (f.shape() != INHERIT_SHAPE) {
454                 os << '}';
455                 ++count;
456                 env = true; // Size change need not bother about closing env.
457         }
458         if (f.color() != Color_inherit && f.color() != Color_ignore && f.color() != Color_none) {
459                 os << '}';
460                 ++count;
461                 env = true; // Size change need not bother about closing env.
462         }
463         if (f.emph() == FONT_ON) {
464                 os << '}';
465                 ++count;
466                 env = true; // Size change need not bother about closing env.
467         }
468         if (f.noun() == FONT_ON) {
469                 os << '}';
470                 ++count;
471                 env = true; // Size change need not bother about closing env.
472         }
473         if (f.size() != INHERIT_SIZE) {
474                 // We only have to close if only size changed
475                 if (!env) {
476                         if (needPar && !closeLanguage) {
477                                 os << "\\par";
478                                 count += 4;
479                                 needPar = false;
480                         }
481                         os << '}';
482                         ++count;
483                 }
484         }
485         if (f.underbar() == FONT_ON) {
486                 os << '}';
487                 ++count;
488                 --runparams.inulemcmd;
489         }
490         if (f.strikeout() == FONT_ON) {
491                 os << '}';
492                 ++count;
493                 --runparams.inulemcmd;
494         }
495         if (f.xout() == FONT_ON) {
496                 os << '}';
497                 ++count;
498                 --runparams.inulemcmd;
499         }
500         if (f.uuline() == FONT_ON) {
501                 os << '}';
502                 ++count;
503                 --runparams.inulemcmd;
504         }
505         if (f.uwave() == FONT_ON) {
506                 os << '}';
507                 ++count;
508                 --runparams.inulemcmd;
509         }
510
511         // If the current language is Hebrew, Arabic, or Farsi
512         // the numbers are written Left-to-Right. ArabTeX package
513         // and bidi (polyglossia with XeTeX) reorder the number automatically
514         // but the packages used for Hebrew and Farsi (Arabi) do not.
515         if (!runparams.useBidiPackage()
516             && !runparams.pass_thru
517             && bits_.number() == FONT_ON
518             && next.fontInfo().number() != FONT_ON
519             && (language()->lang() == "hebrew"
520                 || language()->lang() == "farsi"
521                 || language()->lang() == "arabic_arabi")) {
522                 if (runparams.use_polyglossia) {
523                         // LuaTeX/luabidi
524                         os << "}";
525                         count += 1;
526                 } else {
527                         os << "\\endL}";
528                         count += 6;
529                 }
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                 bool const using_begin_end =
550                         runparams.use_polyglossia ||
551                                 !lyxrc.language_command_end.empty();
552                 if (using_begin_end)
553                         popLanguageName();
554         }
555
556         return count;
557 }
558
559
560 string Font::toString(bool const toggle) const
561 {
562         string const lang = (language() == reset_language)
563                 ? "reset" : language()->lang();
564
565         ostringstream os;
566         os << "family " << bits_.family() << '\n'
567            << "series " << bits_.series() << '\n'
568            << "shape " << bits_.shape() << '\n'
569            << "size " << bits_.size() << '\n'
570            << "emph " << bits_.emph() << '\n'
571            << "underbar " << bits_.underbar() << '\n'
572            << "strikeout " << bits_.strikeout() << '\n'
573            << "xout " << bits_.xout() << '\n'
574            << "uuline " << bits_.uuline() << '\n'
575            << "uwave " << bits_.uwave() << '\n'
576            << "noun " << bits_.noun() << '\n'
577            << "number " << bits_.number() << '\n'
578            << "nospellcheck " << bits_.nospellcheck() << '\n'
579            << "color " << bits_.color() << '\n'
580            << "language " << lang << '\n'
581            << "toggleall " << convert<string>(toggle);
582         return os.str();
583 }
584
585
586 bool Font::fromString(string const & data, bool & toggle)
587 {
588         istringstream is(data);
589         Lexer lex;
590         lex.setStream(is);
591
592         int nset = 0;
593         while (lex.isOK()) {
594                 string token;
595                 if (lex.next())
596                         token = lex.getString();
597
598                 if (token.empty() || !lex.next())
599                         break;
600
601                 if (token == "family") {
602                         int const next = lex.getInteger();
603                         bits_.setFamily(FontFamily(next));
604
605                 } else if (token == "series") {
606                         int const next = lex.getInteger();
607                         bits_.setSeries(FontSeries(next));
608
609                 } else if (token == "shape") {
610                         int const next = lex.getInteger();
611                         bits_.setShape(FontShape(next));
612
613                 } else if (token == "size") {
614                         int const next = lex.getInteger();
615                         bits_.setSize(FontSize(next));
616                 // FIXME: shall style be handled there? Probably not.
617                 } else if (token == "emph" || token == "underbar"
618                         || token == "noun" || token == "number"
619                         || token == "uuline" || token == "uwave"
620                         || token == "strikeout" || token == "xout"
621                         || token == "nospellcheck") {
622
623                         int const next = lex.getInteger();
624                         FontState const misc = FontState(next);
625
626                         if (token == "emph")
627                                 bits_.setEmph(misc);
628                         else if (token == "underbar")
629                                 bits_.setUnderbar(misc);
630                         else if (token == "strikeout")
631                                 bits_.setStrikeout(misc);
632                         else if (token == "xout")
633                                 bits_.setXout(misc);
634                         else if (token == "uuline")
635                                 bits_.setUuline(misc);
636                         else if (token == "uwave")
637                                 bits_.setUwave(misc);
638                         else if (token == "noun")
639                                 bits_.setNoun(misc);
640                         else if (token == "number")
641                                 bits_.setNumber(misc);
642                         else if (token == "nospellcheck")
643                                 bits_.setNoSpellcheck(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()));
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()));
687         }
688         if (bits_.strikeout() == FONT_ON) {
689                 LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
690                 features.require("ulem");
691                 LYXERR(Debug::LATEX, "Strike out enabled. Font: " << to_utf8(stateText()));
692         }
693         if (bits_.xout() == FONT_ON) {
694                 LYXERR(Debug::LATEX, "font.xout: " << bits_.xout());
695                 features.require("ulem");
696                 LYXERR(Debug::LATEX, "Cross out enabled. Font: " << to_utf8(stateText()));
697         }
698         if (bits_.uuline() == FONT_ON) {
699                 LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline());
700                 features.require("ulem");
701                 LYXERR(Debug::LATEX, "Double underline enabled. Font: " << to_utf8(stateText()));
702         }
703         if (bits_.uwave() == FONT_ON) {
704                 LYXERR(Debug::LATEX, "font.uwave: " << bits_.uwave());
705                 features.require("ulem");
706                 LYXERR(Debug::LATEX, "Wavy underline enabled. Font: " << to_utf8(stateText()));
707         }
708         switch (bits_.color()) {
709                 case Color_none:
710                 case Color_inherit:
711                 case Color_ignore:
712                         // probably we should put here all interface colors used for
713                         // font displaying! For now I just add this ones I know of (Jug)
714                 case Color_latex:
715                 case Color_notelabel:
716                         break;
717                 case Color_brown:
718                 case Color_darkgray:
719                 case Color_gray:
720                 case Color_lightgray:
721                 case Color_lime:
722                 case Color_olive:
723                 case Color_orange:
724                 case Color_pink:
725                 case Color_purple:
726                 case Color_teal:
727                 case Color_violet:
728                         features.require("xcolor");
729                         break;
730                 default:
731                         features.require("color");
732                         LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText()));
733         }
734
735         // FIXME: Do something for background and soul package?
736
737         if (((features.usePolyglossia() && lang_->polyglossia() != doc_language->polyglossia())
738              || (features.useBabel() && lang_->babel() != doc_language->babel())
739              || (doc_language->encoding()->package() == Encoding::CJK && lang_ != doc_language))
740             && lang_ != ignore_language
741             && lang_ != latex_language)
742         {
743                 features.useLanguage(lang_);
744                 LYXERR(Debug::LATEX, "Found language " << lang_->lang());
745         }
746 }
747
748
749 ostream & operator<<(ostream & os, FontState fms)
750 {
751         return os << int(fms);
752 }
753
754
755 ostream & operator<<(ostream & os, FontInfo const & f)
756 {
757         return os << "font:"
758                 << " family " << f.family()
759                 << " series " << f.series()
760                 << " shape " << f.shape()
761                 << " size " << f.size()
762                 << " style " << f.style()
763                 << " color " << f.color()
764                 // FIXME: uncomment this when we support background.
765                 //<< " background " << f.background()
766                 << " emph " << f.emph()
767                 << " underbar " << f.underbar()
768                 << " strikeout " << f.strikeout()
769                 << " xout " << f.xout()
770                 << " uuline " << f.uuline()
771                 << " uwave " << f.uwave()
772                 << " noun " << f.noun()
773                 << " number " << f.number()
774                 << " nospellcheck " << f.nospellcheck();
775 }
776
777
778 ostream & operator<<(ostream & os, Font const & font)
779 {
780         return os << font.bits_
781                 << " lang: " << (font.lang_ ? font.lang_->lang() : nullptr);
782 }
783
784
785 } // namespace lyx