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
43 /** The value INHERIT_* means that the font attribute is
44 inherited from the layout. In the case of layout fonts, the
45 attribute is inherited from the default font.
46 The value IGNORE_* is used with LyXFont::update() when the
47 attribute should not be changed.
51 ROMAN_FAMILY, // fontstruct rely on this to be 0
67 MEDIUM_SERIES, // fontstruct rely on this to be 0
79 UP_SHAPE, // fontstruct rely on this to be 0
95 SIZE_TINY, // fontstruct rely on this to be 0
124 /// Used for emph, underbar, noun and latex toggles
125 enum FONT_MISC_STATE {
138 /// Trick to overload constructor and make it megafast
157 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
158 LyXFont(LyXFont const & x);
160 /// Shortcut initialization
161 LyXFont(LyXFont::FONT_INIT1);
162 /// Shortcut initialization
163 LyXFont(LyXFont::FONT_INIT2);
164 /// Shortcut initialization
165 LyXFont(LyXFont::FONT_INIT3);
166 /// Shortcut initialization
167 LyXFont(LyXFont::FONT_INIT1, Language const * l);
168 /// Shortcut initialization
169 LyXFont(LyXFont::FONT_INIT2, Language const * l);
170 /// Shortcut initialization
171 LyXFont(LyXFont::FONT_INIT3, Language const * l);
173 /// LyXFont x, y; x = y;
174 LyXFont & operator=(LyXFont const & x);
176 /// Decreases font size by one
179 /// Increases font size by one
183 FONT_FAMILY family() const;
186 FONT_SERIES series() const;
189 FONT_SHAPE shape() const;
192 FONT_SIZE size() const;
195 FONT_MISC_STATE emph() const;
198 FONT_MISC_STATE underbar() const;
201 FONT_MISC_STATE noun() const;
204 FONT_MISC_STATE latex() const;
207 LColor::color color() const;
210 Language const * language() const;
213 bool isRightToLeft() const;
216 bool isVisibleRightToLeft() const;
219 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
221 LyXFont & setSeries(LyXFont::FONT_SERIES s);
223 LyXFont & setShape(LyXFont::FONT_SHAPE s);
225 LyXFont & setSize(LyXFont::FONT_SIZE s);
227 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
229 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
231 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
233 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
235 LyXFont & setColor(LColor::color c);
237 LyXFont & setLanguage(Language const * l);
239 /// Set family after LyX text format
240 LyXFont & setLyXFamily(string const &);
242 /// Set series after LyX text format
243 LyXFont & setLyXSeries(string const &);
245 /// Set shape after LyX text format
246 LyXFont & setLyXShape(string const &);
248 /// Set size after LyX text format
249 LyXFont & setLyXSize(string const &);
251 /// Returns misc flag after LyX text format
252 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
254 /// Sets color after LyX text format
255 LyXFont & setLyXColor(string const &);
257 /// Sets size after GUI name
258 LyXFont & setGUISize(string const &);
260 /// Returns size of font in LaTeX text notation
261 string latexSize() const;
263 /** Updates font settings according to request. If an
264 attribute is IGNORE, the attribute is left as it is. */
266 * When toggleall = true, all properties that matches the font in use
267 * will have the effect that the properties is reset to the
268 * default. If we have a text that is TYPEWRITER_FAMILY, and is
269 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
270 * a INHERIT_FAMILY was asked for. This is necessary for the
271 * toggle-user-defined-style button on the toolbar.
273 void update(LyXFont const & newfont,
274 Language const * default_lang,
275 bool toggleall = false);
277 /** Reduce font to fall back to template where possible.
278 Equal fields are reduced to INHERIT */
279 void reduce(LyXFont const & tmplt);
281 /// Realize font from a template (INHERIT are realized)
282 LyXFont & realize(LyXFont const & tmplt);
284 /// Is a given font fully resolved?
285 bool resolved() const;
287 /// Read a font specification from LyXLex. Used for layout files.
288 LyXFont & lyxRead(LyXLex &);
290 /// Writes the changes from this font to orgfont in .lyx format in file
291 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
293 /** Writes the head of the LaTeX needed to change to this font.
294 Writes to string, the head of the LaTeX needed to change
295 to this font. Returns number of chars written. Base is the
296 font state active now.
298 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
299 LyXFont const & prev) const;
301 /** Writes tha tail of the LaTeX needed to chagne to this font.
302 Returns number of chars written. Base is the font state we want
305 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
306 LyXFont const & next) const;
308 /// Build GUI description of font state
309 string stateText() const;
312 LColor::color realColor() const;
316 bool operator==(LyXFont const & font1, LyXFont const & font2) {
317 return font1.bits == font2.bits &&
318 font1.lang == font2.lang;
323 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
324 return font1.bits != font2.bits ||
325 font1.lang != font2.lang;
328 /// compares two fonts, ignoring the setting of the Latex part.
329 bool equalExceptLatex(LyXFont const &) const;
331 /// Converts logical attributes to concrete shape attribute
332 LyXFont::FONT_SHAPE realShape() const;
337 bool operator==(FontBits const & fb1) const;
339 bool operator!=(FontBits const & fb1) const;
351 FONT_MISC_STATE emph;
353 FONT_MISC_STATE underbar;
355 FONT_MISC_STATE noun;
357 FONT_MISC_STATE latex;
362 Language const * lang;
365 static FontBits sane;
368 static FontBits inherit;
371 static FontBits ignore;
373 /// Updates a misc setting according to request
374 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
375 LyXFont::FONT_MISC_STATE org);
379 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
386 lang = default_language;
391 LyXFont::LyXFont(LyXFont const & x)
399 LyXFont::LyXFont(LyXFont::FONT_INIT1)
402 lang = default_language;
407 LyXFont::LyXFont(LyXFont::FONT_INIT2)
410 lang = ignore_language;
415 LyXFont::LyXFont(LyXFont::FONT_INIT3)
418 lang = default_language;
421 LyXFont::LyXFont(LyXFont::FONT_INIT1, Language const * l)
429 LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
437 LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
444 LyXFont & LyXFont::operator=(LyXFont const & x)
453 LyXFont::FONT_FAMILY LyXFont::family() const
460 LyXFont::FONT_SERIES LyXFont::series() const
467 LyXFont::FONT_SHAPE LyXFont::shape() const
474 LyXFont::FONT_SIZE LyXFont::size() const
481 LyXFont::FONT_MISC_STATE LyXFont::emph() const
488 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
490 return bits.underbar;
495 LyXFont::FONT_MISC_STATE LyXFont::noun() const
502 LyXFont::FONT_MISC_STATE LyXFont::latex() const
509 LColor::color LyXFont::color() const
516 Language const * LyXFont::language() const
523 bool LyXFont::isRightToLeft() const
525 return lang->RightToLeft;
530 bool LyXFont::isVisibleRightToLeft() const
532 return (lang->RightToLeft && latex() != ON);
537 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
545 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
553 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
561 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
569 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
577 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
585 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
592 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
600 LyXFont & LyXFont::setColor(LColor::color c)
608 LyXFont & LyXFont::setLanguage(Language const * l)