]> git.lyx.org Git - features.git/blob - src/Font.cpp
Implement variable size bigops
[features.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         int count = 0;
222
223         // polyglossia or babel?
224         if (runparams.use_polyglossia
225             && language()->lang() != base.language()->lang()
226             && language() != prev.language()) {
227                 if (!language()->polyglossia().empty()) {
228                         string tmp = "\\text" + language()->polyglossia();
229                         if (!language()->polyglossiaOpts().empty()) {
230                                 tmp += "[" + language()->polyglossiaOpts() + "]";
231                                 if (runparams.use_hyperref && runparams.moving_arg)
232                                         // We need to strip the command for
233                                         // the pdf string, see #11813
234                                         tmp = "\\texorpdfstring{" + tmp + "}{}";
235                         }
236                         tmp += "{";
237                         os << from_ascii(tmp);
238                         count += tmp.length();
239                         pushLanguageName(language()->polyglossia(), true);
240                 } else if (language()->encoding()->package() != Encoding::CJK) {
241                         os << '{';
242                         count += 1;
243                 }
244         } else if (language()->babel() != base.language()->babel() &&
245             language() != prev.language()) {
246                 if (language()->lang() == "farsi") {
247                         os << "\\textFR{";
248                         count += 8;
249                 } else if (!isRightToLeft() &&
250                             base.language()->lang() == "farsi") {
251                         os << "\\textLR{";
252                         count += 8;
253                 } else if (language()->lang() == "arabic_arabi") {
254                         os << "\\textAR{";
255                         count += 8;
256                 } else if (!isRightToLeft() &&
257                                 base.language()->lang() == "arabic_arabi") {
258                         os << "\\textLR{";
259                         count += 8;
260                 // currently the remaining RTL languages are arabic_arabtex and hebrew
261                 } else if (isRightToLeft() != prev.isRightToLeft()) {
262                         if (isRightToLeft()) {
263                                 os << "\\R{";
264                                 count += 3;
265                         } else {
266                                 os << "\\L{";
267                                 count += 3;
268                         }
269                 } else if (!language()->babel().empty()) {
270                         string const tmp =
271                                 subst(lyxrc.language_command_local,
272                                       "$$lang", language()->babel());
273                         os << from_ascii(tmp);
274                         count += tmp.length();
275                         if (!lyxrc.language_command_end.empty())
276                                 pushLanguageName(language()->babel(), true);
277                 } else if (language()->encoding()->package() != Encoding::CJK) {
278                         os << '{';
279                         count += 1;
280                 }
281         }
282
283         if (language()->encoding()->package() == Encoding::CJK) {
284                 pair<bool, int> const c = switchEncoding(os, bparams,
285                                 runparams, *(language()->encoding()));
286                 if (c.first) {
287                         open_encoding_ = true;
288                         count += c.second;
289                         runparams.encoding = language()->encoding();
290                 }
291         }
292
293         FontInfo f = bits_;
294         f.reduce(base.bits_);
295         FontInfo p = bits_;
296         p.reduce(prev.bits_);
297
298         if (f.size() != INHERIT_SIZE) {
299                 os << '{';
300                 ++count;
301                 os << '\\'
302                    << LaTeXSizeNames[f.size()]
303                    << "{}";
304                 count += strlen(LaTeXSizeNames[f.size()]) + 3;
305         }
306         if (f.family() != INHERIT_FAMILY) {
307                 os << '\\'
308                    << LaTeXFamilyNames[f.family()]
309                    << '{';
310                 count += strlen(LaTeXFamilyNames[f.family()]) + 2;
311         }
312         if (f.series() != INHERIT_SERIES) {
313                 os << '\\'
314                    << LaTeXSeriesNames[f.series()]
315                    << '{';
316                 count += strlen(LaTeXSeriesNames[f.series()]) + 2;
317         }
318         if (f.shape() != INHERIT_SHAPE) {
319                 os << '\\'
320                    << LaTeXShapeNames[f.shape()]
321                    << '{';
322                 count += strlen(LaTeXShapeNames[f.shape()]) + 2;
323         }
324         if (f.color() != Color_inherit && f.color() != Color_ignore) {
325                 if (f.color() == Color_none && p.color() != Color_none) {
326                         // Color none: Close previous color, if any
327                         os << '}';
328                         ++count;
329                 } else if (f.color() != Color_none) {
330                         os << "\\textcolor{"
331                            << from_ascii(lcolor.getLaTeXName(f.color()))
332                            << "}{";
333                         count += lcolor.getLaTeXName(f.color()).length() + 13;
334                 }
335         }
336         // FIXME: uncomment this when we support background.
337         /*
338         if (f.background() != Color_inherit && f.background() != Color_ignore) {
339                 os << "\\textcolor{"
340                    << from_ascii(lcolor.getLaTeXName(f.background()))
341                    << "}{";
342                 count += lcolor.getLaTeXName(f.background()).length() + 13;
343                 env = true; //We have opened a new environment
344         }
345         */
346         // If the current language is Hebrew, Arabic, or Farsi
347         // the numbers are written Left-to-Right. ArabTeX package
348         // and bidi (polyglossia with XeTeX) reorder the number automatically
349         // but the packages used for Hebrew and Farsi (Arabi) do not.
350         if (!runparams.useBidiPackage()
351             && !runparams.pass_thru
352             && bits_.number() == FONT_ON
353             && prev.fontInfo().number() != FONT_ON
354             && (language()->lang() == "hebrew"
355                 || language()->lang() == "farsi"
356                 || language()->lang() == "arabic_arabi")) {
357                 if (runparams.use_polyglossia) {
358                         // LuaTeX/luabidi
359                         os << "\\LR{";
360                         count += 5;
361                 } else {
362                         os << "{\\beginL ";
363                         count += 9;
364                 }
365         }
366         if (f.emph() == FONT_ON) {
367                 os << "\\emph{";
368                 count += 6;
369         }
370         // \noun{} is a LyX special macro
371         if (f.noun() == FONT_ON) {
372                 os << "\\noun{";
373                 count += 6;
374         }
375         // The ulem commands need to be on the deepest nesting level
376         // because ulem puts every nested group or macro in a box,
377         // which prevents linebreaks (#8424, #8733)
378         if (f.underbar() == FONT_ON) {
379                 os << "\\uline{";
380                 count += 10;
381                 ++runparams.inulemcmd;
382         }
383         if (f.uuline() == FONT_ON) {
384                 os << "\\uuline{";
385                 count += 11;
386                 ++runparams.inulemcmd;
387         }
388         if (f.strikeout() == FONT_ON) {
389                 os << "\\sout{";
390                 count += 9;
391                 ++runparams.inulemcmd;
392         }
393         if (f.xout() == FONT_ON) {
394                 os << "\\xout{";
395                 count += 9;
396                 ++runparams.inulemcmd;
397         }
398         if (f.uwave() == FONT_ON) {
399                 if (runparams.inulemcmd) {
400                         // needed with nested uwave in xout
401                         // see https://tex.stackexchange.com/a/263042
402                         os << "\\ULdepth=1000pt";
403                         count += 15;
404                 }
405                 os << "\\uwave{";
406                 count += 10;
407                 ++runparams.inulemcmd;
408         }
409         return count;
410 }
411
412
413 /// Writes ending block of LaTeX needed to close use of this font
414 // Returns number of chars written
415 // This one corresponds to latexWriteStartChanges(). (Asger)
416 int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
417                                   OutputParams const & runparams,
418                                   Font const & base,
419                                   Font const & next,
420                                   bool & needPar,
421                                   bool const & closeLanguage,
422                                   bool const & non_inherit_inset) const
423 {
424         int count = 0;
425
426         // reduce the current font to changes against the base
427         // font (of the layout). We use a temporary for this to
428         // avoid changing this font instance, as that would break
429         FontInfo f = bits_;
430         f.reduce(base.bits_);
431
432         if (f.family() != INHERIT_FAMILY) {
433                 os << '}';
434                 ++count;
435         }
436         if (f.series() != INHERIT_SERIES) {
437                 os << '}';
438                 ++count;
439         }
440         if (f.shape() != INHERIT_SHAPE) {
441                 os << '}';
442                 ++count;
443         }
444         if (f.color() != Color_inherit && f.color() != Color_ignore && f.color() != Color_none) {
445                 os << '}';
446                 ++count;
447         }
448         if (f.emph() == FONT_ON) {
449                 os << '}';
450                 ++count;
451         }
452         if (f.noun() == FONT_ON) {
453                 os << '}';
454                 ++count;
455         }
456         if (f.size() != INHERIT_SIZE) {
457                 // We do not close size group in front of
458                 // insets with InheritFont() false (as opposed
459                 // to all other font properties) (#8384)
460                 if (!non_inherit_inset) {
461                         if (needPar && !closeLanguage) {
462                                 os << "\\par";
463                                 count += 4;
464                                 needPar = false;
465                         }
466                         os << '}';
467                         ++count;
468                 }
469         }
470         if (f.underbar() == FONT_ON) {
471                 os << '}';
472                 ++count;
473                 --runparams.inulemcmd;
474         }
475         if (f.strikeout() == FONT_ON) {
476                 os << '}';
477                 ++count;
478                 --runparams.inulemcmd;
479         }
480         if (f.xout() == FONT_ON) {
481                 os << '}';
482                 ++count;
483                 --runparams.inulemcmd;
484         }
485         if (f.uuline() == FONT_ON) {
486                 os << '}';
487                 ++count;
488                 --runparams.inulemcmd;
489         }
490         if (f.uwave() == FONT_ON) {
491                 os << '}';
492                 ++count;
493                 --runparams.inulemcmd;
494         }
495
496         // If the current language is Hebrew, Arabic, or Farsi
497         // the numbers are written Left-to-Right. ArabTeX package
498         // and bidi (polyglossia with XeTeX) reorder the number automatically
499         // but the packages used for Hebrew and Farsi (Arabi) do not.
500         if (!runparams.useBidiPackage()
501             && !runparams.pass_thru
502             && bits_.number() == FONT_ON
503             && next.fontInfo().number() != FONT_ON
504             && (language()->lang() == "hebrew"
505                 || language()->lang() == "farsi"
506                 || language()->lang() == "arabic_arabi")) {
507                 if (runparams.use_polyglossia) {
508                         // LuaTeX/luabidi
509                         os << "}";
510                         count += 1;
511                 } else {
512                         os << "\\endL}";
513                         count += 6;
514                 }
515         }
516
517         if (open_encoding_) {
518                 // We need to close the encoding even if it does not change
519                 // to do correct environment nesting
520                 Encoding const * const ascii = encodings.fromLyXName("ascii");
521                 pair<bool, int> const c = switchEncoding(os.os(), bparams,
522                                 runparams, *ascii);
523                 LATTEST(c.first);
524                 count += c.second;
525                 runparams.encoding = ascii;
526                 open_encoding_ = false;
527         }
528
529         if (closeLanguage
530             && language() != base.language() && language() != next.language()
531             && (language()->encoding()->package() != Encoding::CJK)) {
532                 os << '}';
533                 ++count;
534                 bool const using_begin_end =
535                         runparams.use_polyglossia ||
536                                 !lyxrc.language_command_end.empty();
537                 if (using_begin_end)
538                         popLanguageName();
539         }
540
541         return count;
542 }
543
544
545 string Font::toString(bool const toggle) const
546 {
547         string const lang = (language() == reset_language)
548                 ? "reset" : language()->lang();
549
550         ostringstream os;
551         os << "family " << bits_.family() << '\n'
552            << "series " << bits_.series() << '\n'
553            << "shape " << bits_.shape() << '\n'
554            << "size " << bits_.size() << '\n'
555            << "emph " << bits_.emph() << '\n'
556            << "underbar " << bits_.underbar() << '\n'
557            << "strikeout " << bits_.strikeout() << '\n'
558            << "xout " << bits_.xout() << '\n'
559            << "uuline " << bits_.uuline() << '\n'
560            << "uwave " << bits_.uwave() << '\n'
561            << "noun " << bits_.noun() << '\n'
562            << "number " << bits_.number() << '\n'
563            << "nospellcheck " << bits_.nospellcheck() << '\n'
564            << "color " << bits_.color() << '\n'
565            << "language " << lang << '\n'
566            << "toggleall " << convert<string>(toggle);
567         return os.str();
568 }
569
570
571 bool Font::fromString(string const & data, bool & toggle)
572 {
573         istringstream is(data);
574         Lexer lex;
575         lex.setStream(is);
576
577         int nset = 0;
578         while (lex.isOK()) {
579                 string token;
580                 if (lex.next())
581                         token = lex.getString();
582
583                 if (token.empty() || !lex.next())
584                         break;
585
586                 if (token == "family") {
587                         int const next = lex.getInteger();
588                         bits_.setFamily(FontFamily(next));
589
590                 } else if (token == "series") {
591                         int const next = lex.getInteger();
592                         bits_.setSeries(FontSeries(next));
593
594                 } else if (token == "shape") {
595                         int const next = lex.getInteger();
596                         bits_.setShape(FontShape(next));
597
598                 } else if (token == "size") {
599                         int const next = lex.getInteger();
600                         bits_.setSize(FontSize(next));
601                 // FIXME: shall style be handled there? Probably not.
602                 } else if (token == "emph" || token == "underbar"
603                         || token == "noun" || token == "number"
604                         || token == "uuline" || token == "uwave"
605                         || token == "strikeout" || token == "xout"
606                         || token == "nospellcheck") {
607
608                         int const next = lex.getInteger();
609                         FontState const misc = FontState(next);
610
611                         if (token == "emph")
612                                 bits_.setEmph(misc);
613                         else if (token == "underbar")
614                                 bits_.setUnderbar(misc);
615                         else if (token == "strikeout")
616                                 bits_.setStrikeout(misc);
617                         else if (token == "xout")
618                                 bits_.setXout(misc);
619                         else if (token == "uuline")
620                                 bits_.setUuline(misc);
621                         else if (token == "uwave")
622                                 bits_.setUwave(misc);
623                         else if (token == "noun")
624                                 bits_.setNoun(misc);
625                         else if (token == "number")
626                                 bits_.setNumber(misc);
627                         else if (token == "nospellcheck")
628                                 bits_.setNoSpellcheck(misc);
629
630                 } else if (token == "color") {
631                         int const next = lex.getInteger();
632                         bits_.setColor(ColorCode(next));
633
634                 /**
635                 } else if (token == "background") {
636                         int const next = lex.getInteger();
637                         bits_.setBackground(ColorCode(next));
638                 */
639
640                 } else if (token == "language") {
641                         string const next = lex.getString();
642                         setLanguage(languages.getLanguage(next));
643
644                 } else if (token == "toggleall") {
645                         toggle = lex.getBool();
646
647                 } else {
648                         // Unrecognised token
649                         break;
650                 }
651
652                 ++nset;
653         }
654         return (nset > 0);
655 }
656
657
658 void Font::validate(LaTeXFeatures & features) const
659 {
660         BufferParams const & bparams = features.bufferParams();
661         Language const * doc_language = bparams.language;
662
663         if (bits_.noun() == FONT_ON) {
664                 LYXERR(Debug::LATEX, "font.noun: " << bits_.noun());
665                 features.require("noun");
666                 LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText()));
667         }
668         if (bits_.underbar() == FONT_ON) {
669                 LYXERR(Debug::LATEX, "font.underline: " << bits_.underbar());
670                 features.require("ulem");
671                 LYXERR(Debug::LATEX, "Underline enabled. Font: " << to_utf8(stateText()));
672         }
673         if (bits_.strikeout() == FONT_ON) {
674                 LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
675                 features.require("ulem");
676                 LYXERR(Debug::LATEX, "Strike out enabled. Font: " << to_utf8(stateText()));
677         }
678         if (bits_.xout() == FONT_ON) {
679                 LYXERR(Debug::LATEX, "font.xout: " << bits_.xout());
680                 features.require("ulem");
681                 LYXERR(Debug::LATEX, "Cross out enabled. Font: " << to_utf8(stateText()));
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()));
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()));
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()));
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                 << " style " << f.style()
748                 << " color " << f.color()
749                 // FIXME: uncomment this when we support background.
750                 //<< " background " << f.background()
751                 << " emph " << f.emph()
752                 << " underbar " << f.underbar()
753                 << " strikeout " << f.strikeout()
754                 << " xout " << f.xout()
755                 << " uuline " << f.uuline()
756                 << " uwave " << f.uwave()
757                 << " noun " << f.noun()
758                 << " number " << f.number()
759                 << " nospellcheck " << f.nospellcheck();
760 }
761
762
763 ostream & operator<<(ostream & os, Font const & font)
764 {
765         return os << font.bits_
766                 << " lang: " << (font.lang_ ? font.lang_->lang() : nullptr);
767 }
768
769
770 } // namespace lyx