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