2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
25 // It might happen that locale.h defines ON and OFF. This is not good
26 // for us, since we use these names below. But of course this is due
27 // to some old compilers. Than is broken when it comes to C++ scoping.
28 #include "gettext.h" // so that we are sure tht it won't be included
44 /** The value INHERIT_* means that the font attribute is
45 inherited from the layout. In the case of layout fonts, the
46 attribute is inherited from the default font.
47 The value IGNORE_* is used with LyXFont::update() when the
48 attribute should not be changed.
52 ROMAN_FAMILY, // fontstruct rely on this to be 0
68 MEDIUM_SERIES, // fontstruct rely on this to be 0
80 UP_SHAPE, // fontstruct rely on this to be 0
96 SIZE_TINY, // fontstruct rely on this to be 0
125 /// Used for emph, underbar, noun and latex toggles
126 enum FONT_MISC_STATE {
139 /// Trick to overload constructor and make it megafast
158 // LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
159 LyXFont(LyXFont const & x);
161 /// Shortcut initialization
163 LyXFont(LyXFont::FONT_INIT1);
164 /// Shortcut initialization
166 LyXFont(LyXFont::FONT_INIT2);
167 /// Shortcut initialization
169 LyXFont(LyXFont::FONT_INIT3);
170 /// Shortcut initialization
171 LyXFont(LyXFont::FONT_INIT1, Language const * l);
172 /// Shortcut initialization
173 LyXFont(LyXFont::FONT_INIT2, Language const * l);
174 /// Shortcut initialization
175 LyXFont(LyXFont::FONT_INIT3, Language const * l);
177 /// LyXFont x, y; x = y;
178 LyXFont & operator=(LyXFont const & x);
180 /// Decreases font size by one
183 /// Increases font size by one
187 FONT_FAMILY family() const;
190 FONT_SERIES series() const;
193 FONT_SHAPE shape() const;
196 FONT_SIZE size() const;
199 FONT_MISC_STATE emph() const;
202 FONT_MISC_STATE underbar() const;
205 FONT_MISC_STATE noun() const;
208 FONT_MISC_STATE latex() const;
211 FONT_MISC_STATE number() const;
214 LColor::color color() const;
217 Language const * language() const;
220 bool isRightToLeft() const;
223 bool isVisibleRightToLeft() const;
226 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
228 LyXFont & setSeries(LyXFont::FONT_SERIES s);
230 LyXFont & setShape(LyXFont::FONT_SHAPE s);
232 LyXFont & setSize(LyXFont::FONT_SIZE s);
234 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
236 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
238 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
240 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
242 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
244 LyXFont & setColor(LColor::color c);
246 LyXFont & setLanguage(Language const * l);
248 /// Set family after LyX text format
249 LyXFont & setLyXFamily(string const &);
251 /// Set series after LyX text format
252 LyXFont & setLyXSeries(string const &);
254 /// Set shape after LyX text format
255 LyXFont & setLyXShape(string const &);
257 /// Set size after LyX text format
258 LyXFont & setLyXSize(string const &);
260 /// Returns misc flag after LyX text format
261 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
263 /// Sets color after LyX text format
264 LyXFont & setLyXColor(string const &);
267 /// Sets size after GUI name
268 LyXFont & setGUISize(string const &);
271 /// Returns size of font in LaTeX text notation
272 string const latexSize() const;
274 /** Updates font settings according to request.
275 If an attribute is IGNORE, the attribute is left as it is.
276 When toggleall = true, all properties that matches the font in use
277 will have the effect that the properties is reset to the
278 default. If we have a text that is TYPEWRITER_FAMILY, and is
279 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
280 a INHERIT_FAMILY was asked for. This is necessary for the
281 toggle-user-defined-style button on the toolbar.
283 void update(LyXFont const & newfont,
284 Language const * default_lang,
285 bool toggleall = false);
287 /** Reduce font to fall back to template where possible.
288 Equal fields are reduced to INHERIT */
289 void reduce(LyXFont const & tmplt);
291 /// Realize font from a template (INHERIT are realized)
292 LyXFont & realize(LyXFont const & tmplt);
294 /// Is a given font fully resolved?
295 bool resolved() const;
297 /// Read a font specification from LyXLex. Used for layout files.
298 LyXFont & lyxRead(LyXLex &);
300 /// Writes the changes from this font to orgfont in .lyx format in file
301 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
303 /** Writes the head of the LaTeX needed to change to this font.
304 Writes to string, the head of the LaTeX needed to change
305 to this font. Returns number of chars written. Base is the
306 font state active now.
308 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
309 LyXFont const & prev) const;
311 /** Writes tha tail of the LaTeX needed to chagne to this font.
312 Returns number of chars written. Base is the font state we want
315 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
316 LyXFont const & next) const;
318 /// Build GUI description of font state
319 string const stateText(BufferParams * params) const;
322 LColor::color realColor() const;
326 bool operator==(LyXFont const & font1, LyXFont const & font2);
330 bool operator!=(LyXFont const & font1, LyXFont const & font2);
332 /// compares two fonts, ignoring the setting of the Latex part.
333 bool equalExceptLatex(LyXFont const &) const;
335 /// Converts logical attributes to concrete shape attribute
336 LyXFont::FONT_SHAPE realShape() const;
341 bool operator==(FontBits const & fb1) const;
343 bool operator!=(FontBits const & fb1) const;
355 FONT_MISC_STATE emph;
357 FONT_MISC_STATE underbar;
359 FONT_MISC_STATE noun;
361 FONT_MISC_STATE latex;
366 Language const * lang;
368 FONT_MISC_STATE number_;
371 static FontBits sane;
374 static FontBits inherit;
377 static FontBits ignore;
379 /// Updates a misc setting according to request
380 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
381 LyXFont::FONT_MISC_STATE org);
385 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
389 bool operator==(LyXFont const & font1, LyXFont const & font2) {
390 return font1.bits == font2.bits &&
391 font1.lang == font2.lang &&
392 font1.number_ == font2.number_;
397 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
398 return !(font1 == font2);
406 lang = default_language;
412 LyXFont::LyXFont(LyXFont const & x)
421 LyXFont::LyXFont(LyXFont::FONT_INIT1)
424 lang = default_language;
430 LyXFont::LyXFont(LyXFont::FONT_INIT2)
433 lang = ignore_language;
439 LyXFont::LyXFont(LyXFont::FONT_INIT3)
442 lang = default_language;
448 LyXFont::LyXFont(LyXFont::FONT_INIT1, Language const * l)
457 LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
466 LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
475 LyXFont & LyXFont::operator=(LyXFont const & x)
485 LyXFont::FONT_FAMILY LyXFont::family() const
492 LyXFont::FONT_SERIES LyXFont::series() const
499 LyXFont::FONT_SHAPE LyXFont::shape() const
506 LyXFont::FONT_SIZE LyXFont::size() const
513 LyXFont::FONT_MISC_STATE LyXFont::emph() const
520 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
522 return bits.underbar;
527 LyXFont::FONT_MISC_STATE LyXFont::noun() const
534 LyXFont::FONT_MISC_STATE LyXFont::latex() const
541 LColor::color LyXFont::color() const
548 Language const * LyXFont::language() const
555 LyXFont::FONT_MISC_STATE LyXFont::number() const
562 bool LyXFont::isRightToLeft() const
564 return lang->RightToLeft();
569 bool LyXFont::isVisibleRightToLeft() const
571 return (lang->RightToLeft() && latex() != ON && number() != ON);
576 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
584 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
592 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
600 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
608 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
616 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
624 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
631 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
639 LyXFont & LyXFont::setColor(LColor::color c)
647 LyXFont & LyXFont::setLanguage(Language const * l)
655 LyXFont & LyXFont::setNumber(LyXFont::FONT_MISC_STATE n)