]> git.lyx.org Git - lyx.git/blob - src/Font.cpp
de.po
[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" };
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                         tmp += "{";
234                         os << from_ascii(tmp);
235                         count += tmp.length();
236                         pushLanguageName(language()->polyglossia(), true);
237                 } else if (language()->encoding()->package() != Encoding::CJK) {
238                         os << '{';
239                         count += 1;
240                 }
241         } else if (language()->babel() != base.language()->babel() &&
242             language() != prev.language()) {
243                 if (language()->lang() == "farsi") {
244                         os << "\\textFR{";
245                         count += 8;
246                 } else if (!isRightToLeft() &&
247                             base.language()->lang() == "farsi") {
248                         os << "\\textLR{";
249                         count += 8;
250                 } else if (language()->lang() == "arabic_arabi") {
251                         os << "\\textAR{";
252                         count += 8;
253                 } else if (!isRightToLeft() &&
254                                 base.language()->lang() == "arabic_arabi") {
255                         os << "\\textLR{";
256                         count += 8;
257                 // currently the remaining RTL languages are arabic_arabtex and hebrew
258                 } else if (isRightToLeft() != prev.isRightToLeft()) {
259                         if (isRightToLeft()) {
260                                 os << "\\R{";
261                                 count += 3;
262                         } else {
263                                 os << "\\L{";
264                                 count += 3;
265                         }
266                 } else if (!language()->babel().empty()) {
267                         string const tmp =
268                                 subst(lyxrc.language_command_local,
269                                       "$$lang", language()->babel());
270                         os << from_ascii(tmp);
271                         count += tmp.length();
272                         if (!lyxrc.language_command_end.empty())
273                                 pushLanguageName(language()->babel(), true);
274                 } else if (language()->encoding()->package() != Encoding::CJK) {
275                         os << '{';
276                         count += 1;
277                 }
278         }
279
280         if (language()->encoding()->package() == Encoding::CJK) {
281                 pair<bool, int> const c = switchEncoding(os, bparams,
282                                 runparams, *(language()->encoding()));
283                 if (c.first) {
284                         open_encoding_ = true;
285                         count += c.second;
286                         runparams.encoding = language()->encoding();
287                 }
288         }
289
290         FontInfo f = bits_;
291         f.reduce(base.bits_);
292         FontInfo p = bits_;
293         p.reduce(prev.bits_);
294
295         if (f.family() != INHERIT_FAMILY) {
296                 os << '\\'
297                    << LaTeXFamilyNames[f.family()]
298                    << '{';
299                 count += strlen(LaTeXFamilyNames[f.family()]) + 2;
300                 env = true; //We have opened a new environment
301         }
302         if (f.series() != INHERIT_SERIES) {
303                 os << '\\'
304                    << LaTeXSeriesNames[f.series()]
305                    << '{';
306                 count += strlen(LaTeXSeriesNames[f.series()]) + 2;
307                 env = true; //We have opened a new environment
308         }
309         if (f.shape() != INHERIT_SHAPE) {
310                 os << '\\'
311                    << LaTeXShapeNames[f.shape()]
312                    << '{';
313                 count += strlen(LaTeXShapeNames[f.shape()]) + 2;
314                 env = true; //We have opened a new environment
315         }
316         if (f.color() != Color_inherit && f.color() != Color_ignore) {
317                 if (f.color() == Color_none && p.color() != Color_none) {
318                         // Color none: Close previous color, if any
319                         os << '}';
320                         ++count;
321                 } else if (f.color() != Color_none) {
322                         os << "\\textcolor{"
323                            << from_ascii(lcolor.getLaTeXName(f.color()))
324                            << "}{";
325                         count += lcolor.getLaTeXName(f.color()).length() + 13;
326                 }
327                 env = true; //We have opened a new environment
328         }
329         // FIXME: uncomment this when we support background.
330         /*
331         if (f.background() != Color_inherit && f.background() != Color_ignore) {
332                 os << "\\textcolor{"
333                    << from_ascii(lcolor.getLaTeXName(f.background()))
334                    << "}{";
335                 count += lcolor.getLaTeXName(f.background()).length() + 13;
336                 env = true; //We have opened a new environment
337         }
338         */
339         // If the current language is Hebrew, Arabic, or Farsi
340         // the numbers are written Left-to-Right. ArabTeX package
341         // and bidi (polyglossia) reorder the number automatically
342         // but the packages used for Hebrew and Farsi (Arabi) do not.
343         if (!runparams.use_polyglossia
344             && !runparams.pass_thru
345             && bits_.number() == FONT_ON
346             && prev.fontInfo().number() != FONT_ON
347             && (language()->lang() == "hebrew"
348                 || language()->lang() == "farsi"
349                 || language()->lang() == "arabic_arabi")) {
350                 os << "{\\beginL ";
351                 count += 9;
352         }
353         if (f.emph() == FONT_ON) {
354                 os << "\\emph{";
355                 count += 6;
356                 env = true; //We have opened a new environment
357         }
358         // \noun{} is a LyX special macro
359         if (f.noun() == FONT_ON) {
360                 os << "\\noun{";
361                 count += 6;
362                 env = true; //We have opened a new environment
363         }
364         if (f.size() != FONT_SIZE_INHERIT) {
365                 // If we didn't open an environment above, we open one here
366                 if (!env) {
367                         os << '{';
368                         ++count;
369                 }
370                 os << '\\'
371                    << LaTeXSizeNames[f.size()]
372                    << "{}";
373                 count += strlen(LaTeXSizeNames[f.size()]) + 3;
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) const
422 {
423         int count = 0;
424         bool env = false;
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                 env = true; // Size change need not bother about closing env.
436         }
437         if (f.series() != INHERIT_SERIES) {
438                 os << '}';
439                 ++count;
440                 env = true; // Size change need not bother about closing env.
441         }
442         if (f.shape() != INHERIT_SHAPE) {
443                 os << '}';
444                 ++count;
445                 env = true; // Size change need not bother about closing env.
446         }
447         if (f.color() != Color_inherit && f.color() != Color_ignore && f.color() != Color_none) {
448                 os << '}';
449                 ++count;
450                 env = true; // Size change need not bother about closing env.
451         }
452         if (f.emph() == FONT_ON) {
453                 os << '}';
454                 ++count;
455                 env = true; // Size change need not bother about closing env.
456         }
457         if (f.noun() == FONT_ON) {
458                 os << '}';
459                 ++count;
460                 env = true; // Size change need not bother about closing env.
461         }
462         if (f.size() != FONT_SIZE_INHERIT) {
463                 // We only have to close if only size changed
464                 if (!env) {
465                         if (needPar && !closeLanguage) {
466                                 os << "\\par";
467                                 count += 4;
468                                 needPar = false;
469                         }
470                         os << '}';
471                         ++count;
472                 }
473         }
474         if (f.underbar() == FONT_ON) {
475                 os << '}';
476                 ++count;
477                 --runparams.inulemcmd;
478         }
479         if (f.strikeout() == FONT_ON) {
480                 os << '}';
481                 ++count;
482                 --runparams.inulemcmd;
483         }
484         if (f.xout() == FONT_ON) {
485                 os << '}';
486                 ++count;
487                 --runparams.inulemcmd;
488         }
489         if (f.uuline() == FONT_ON) {
490                 os << '}';
491                 ++count;
492                 --runparams.inulemcmd;
493         }
494         if (f.uwave() == FONT_ON) {
495                 os << '}';
496                 ++count;
497                 --runparams.inulemcmd;
498         }
499
500         // If the current language is Hebrew, Arabic, or Farsi
501         // the numbers are written Left-to-Right. ArabTeX package
502         // and bidi (polyglossia) reorder the number automatically
503         // but the packages used for Hebrew and Farsi (Arabi) do not.
504         if (!runparams.use_polyglossia
505             && !runparams.pass_thru
506             && bits_.number() == FONT_ON
507             && next.fontInfo().number() != FONT_ON
508             && (language()->lang() == "hebrew"
509                 || language()->lang() == "farsi"
510                 || language()->lang() == "arabic_arabi")) {
511                 os << "\\endL}";
512                 count += 6;
513         }
514
515         if (open_encoding_) {
516                 // We need to close the encoding even if it does not change
517                 // to do correct environment nesting
518                 Encoding const * const ascii = encodings.fromLyXName("ascii");
519                 pair<bool, int> const c = switchEncoding(os.os(), bparams,
520                                 runparams, *ascii);
521                 LATTEST(c.first);
522                 count += c.second;
523                 runparams.encoding = ascii;
524                 open_encoding_ = false;
525         }
526
527         if (closeLanguage
528             && language() != base.language() && language() != next.language()
529             && language()->encoding()->package() != Encoding::CJK) {
530                 os << '}';
531                 ++count;
532                 bool const using_begin_end =
533                         runparams.use_polyglossia ||
534                                 !lyxrc.language_command_end.empty();
535                 if (using_begin_end)
536                         popLanguageName();
537         }
538
539         return count;
540 }
541
542
543 string Font::toString(bool const toggle) const
544 {
545         string const lang = (language() == reset_language)
546                 ? "reset" : language()->lang();
547
548         ostringstream os;
549         os << "family " << bits_.family() << '\n'
550            << "series " << bits_.series() << '\n'
551            << "shape " << bits_.shape() << '\n'
552            << "size " << bits_.size() << '\n'
553            << "emph " << bits_.emph() << '\n'
554            << "underbar " << bits_.underbar() << '\n'
555            << "strikeout " << bits_.strikeout() << '\n'
556            << "xout " << bits_.xout() << '\n'
557            << "uuline " << bits_.uuline() << '\n'
558            << "uwave " << bits_.uwave() << '\n'
559            << "noun " << bits_.noun() << '\n'
560            << "number " << bits_.number() << '\n'
561            << "nospellcheck " << bits_.nospellcheck() << '\n'
562            << "color " << bits_.color() << '\n'
563            << "language " << lang << '\n'
564            << "toggleall " << convert<string>(toggle);
565         return os.str();
566 }
567
568
569 bool Font::fromString(string const & data, bool & toggle)
570 {
571         istringstream is(data);
572         Lexer lex;
573         lex.setStream(is);
574
575         int nset = 0;
576         while (lex.isOK()) {
577                 string token;
578                 if (lex.next())
579                         token = lex.getString();
580
581                 if (token.empty() || !lex.next())
582                         break;
583
584                 if (token == "family") {
585                         int const next = lex.getInteger();
586                         bits_.setFamily(FontFamily(next));
587
588                 } else if (token == "series") {
589                         int const next = lex.getInteger();
590                         bits_.setSeries(FontSeries(next));
591
592                 } else if (token == "shape") {
593                         int const next = lex.getInteger();
594                         bits_.setShape(FontShape(next));
595
596                 } else if (token == "size") {
597                         int const next = lex.getInteger();
598                         bits_.setSize(FontSize(next));
599                 // FIXME: shall style be handled there? Probably not.
600                 } else if (token == "emph" || token == "underbar"
601                         || token == "noun" || token == "number"
602                         || token == "uuline" || token == "uwave"
603                         || token == "strikeout" || token == "xout"
604                         || token == "nospellcheck") {
605
606                         int const next = lex.getInteger();
607                         FontState const misc = FontState(next);
608
609                         if (token == "emph")
610                                 bits_.setEmph(misc);
611                         else if (token == "underbar")
612                                 bits_.setUnderbar(misc);
613                         else if (token == "strikeout")
614                                 bits_.setStrikeout(misc);
615                         else if (token == "xout")
616                                 bits_.setXout(misc);
617                         else if (token == "uuline")
618                                 bits_.setUuline(misc);
619                         else if (token == "uwave")
620                                 bits_.setUwave(misc);
621                         else if (token == "noun")
622                                 bits_.setNoun(misc);
623                         else if (token == "number")
624                                 bits_.setNumber(misc);
625                         else if (token == "nospellcheck")
626                                 bits_.setNoSpellcheck(misc);
627
628                 } else if (token == "color") {
629                         int const next = lex.getInteger();
630                         bits_.setColor(ColorCode(next));
631
632                 /**
633                 } else if (token == "background") {
634                         int const next = lex.getInteger();
635                         bits_.setBackground(ColorCode(next));
636                 */
637
638                 } else if (token == "language") {
639                         string const next = lex.getString();
640                         setLanguage(languages.getLanguage(next));
641
642                 } else if (token == "toggleall") {
643                         toggle = lex.getBool();
644
645                 } else {
646                         // Unrecognised token
647                         break;
648                 }
649
650                 ++nset;
651         }
652         return (nset > 0);
653 }
654
655
656 void Font::validate(LaTeXFeatures & features) const
657 {
658         BufferParams const & bparams = features.bufferParams();
659         Language const * doc_language = bparams.language;
660
661         if (bits_.noun() == FONT_ON) {
662                 LYXERR(Debug::LATEX, "font.noun: " << bits_.noun());
663                 features.require("noun");
664                 LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText()));
665         }
666         if (bits_.underbar() == FONT_ON) {
667                 LYXERR(Debug::LATEX, "font.underline: " << bits_.underbar());
668                 features.require("ulem");
669                 LYXERR(Debug::LATEX, "Underline enabled. Font: " << to_utf8(stateText()));
670         }
671         if (bits_.strikeout() == FONT_ON) {
672                 LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
673                 features.require("ulem");
674                 LYXERR(Debug::LATEX, "Strike out enabled. Font: " << to_utf8(stateText()));
675         }
676         if (bits_.xout() == FONT_ON) {
677                 LYXERR(Debug::LATEX, "font.xout: " << bits_.xout());
678                 features.require("ulem");
679                 LYXERR(Debug::LATEX, "Cross out enabled. Font: " << to_utf8(stateText()));
680         }
681         if (bits_.uuline() == FONT_ON) {
682                 LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline());
683                 features.require("ulem");
684                 LYXERR(Debug::LATEX, "Double underline enabled. Font: " << to_utf8(stateText()));
685         }
686         if (bits_.uwave() == FONT_ON) {
687                 LYXERR(Debug::LATEX, "font.uwave: " << bits_.uwave());
688                 features.require("ulem");
689                 LYXERR(Debug::LATEX, "Wavy underline enabled. Font: " << to_utf8(stateText()));
690         }
691         switch (bits_.color()) {
692                 case Color_none:
693                 case Color_inherit:
694                 case Color_ignore:
695                         // probably we should put here all interface colors used for
696                         // font displaying! For now I just add this ones I know of (Jug)
697                 case Color_latex:
698                 case Color_notelabel:
699                         break;
700                 case Color_brown:
701                 case Color_darkgray:
702                 case Color_gray:
703                 case Color_lightgray:
704                 case Color_lime:
705                 case Color_olive:
706                 case Color_orange:
707                 case Color_pink:
708                 case Color_purple:
709                 case Color_teal:
710                 case Color_violet:
711                         features.require("xcolor");
712                         break;
713                 default:
714                         features.require("color");
715                         LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText()));
716         }
717
718         // FIXME: Do something for background and soul package?
719
720         if (((features.usePolyglossia() && lang_->polyglossia() != doc_language->polyglossia())
721              || (features.useBabel() && lang_->babel() != doc_language->babel())
722              || (doc_language->encoding()->package() == Encoding::CJK && lang_ != doc_language))
723             && lang_ != ignore_language
724             && lang_ != latex_language)
725         {
726                 features.useLanguage(lang_);
727                 LYXERR(Debug::LATEX, "Found language " << lang_->lang());
728         }
729 }
730
731
732 ostream & operator<<(ostream & os, FontState fms)
733 {
734         return os << int(fms);
735 }
736
737
738 ostream & operator<<(ostream & os, FontInfo const & f)
739 {
740         return os << "font:"
741                 << " family " << f.family()
742                 << " series " << f.series()
743                 << " shape " << f.shape()
744                 << " size " << f.size()
745                 << " style " << f.style()
746                 << " color " << f.color()
747                 // FIXME: uncomment this when we support background.
748                 //<< " background " << f.background()
749                 << " emph " << f.emph()
750                 << " underbar " << f.underbar()
751                 << " strikeout " << f.strikeout()
752                 << " xout " << f.xout()
753                 << " uuline " << f.uuline()
754                 << " uwave " << f.uwave()
755                 << " noun " << f.noun()
756                 << " number " << f.number()
757                 << " nospellcheck " << f.nospellcheck();
758 }
759
760
761 ostream & operator<<(ostream & os, Font const & font)
762 {
763         return os << font.bits_
764                 << " lang: " << (font.lang_ ? font.lang_->lang() : 0);
765 }
766
767
768 } // namespace lyx