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