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