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
162 LyXFont(LyXFont::FONT_INIT1);
163 /// Shortcut initialization
165 LyXFont(LyXFont::FONT_INIT2);
166 /// Shortcut initialization
168 LyXFont(LyXFont::FONT_INIT3);
169 /// Shortcut initialization
170 LyXFont(LyXFont::FONT_INIT1, Language const * l);
171 /// Shortcut initialization
172 LyXFont(LyXFont::FONT_INIT2, Language const * l);
173 /// Shortcut initialization
174 LyXFont(LyXFont::FONT_INIT3, Language const * l);
176 /// LyXFont x, y; x = y;
177 LyXFont & operator=(LyXFont const & x);
179 /// Decreases font size by one
182 /// Increases font size by one
186 FONT_FAMILY family() const;
189 FONT_SERIES series() const;
192 FONT_SHAPE shape() const;
195 FONT_SIZE size() const;
198 FONT_MISC_STATE emph() const;
201 FONT_MISC_STATE underbar() const;
204 FONT_MISC_STATE noun() const;
207 FONT_MISC_STATE latex() const;
210 LColor::color color() const;
213 Language const * language() const;
216 bool isRightToLeft() const;
219 bool isVisibleRightToLeft() const;
222 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
224 LyXFont & setSeries(LyXFont::FONT_SERIES s);
226 LyXFont & setShape(LyXFont::FONT_SHAPE s);
228 LyXFont & setSize(LyXFont::FONT_SIZE s);
230 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
232 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
234 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
236 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
238 LyXFont & setColor(LColor::color c);
240 LyXFont & setLanguage(Language const * l);
242 /// Set family after LyX text format
243 LyXFont & setLyXFamily(string const &);
245 /// Set series after LyX text format
246 LyXFont & setLyXSeries(string const &);
248 /// Set shape after LyX text format
249 LyXFont & setLyXShape(string const &);
251 /// Set size after LyX text format
252 LyXFont & setLyXSize(string const &);
254 /// Returns misc flag after LyX text format
255 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
257 /// Sets color after LyX text format
258 LyXFont & setLyXColor(string const &);
260 /// Sets size after GUI name
261 LyXFont & setGUISize(string const &);
263 /// Returns size of font in LaTeX text notation
264 string latexSize() const;
266 /** Updates font settings according to request. If an
267 attribute is IGNORE, the attribute is left as it is. */
269 * When toggleall = true, all properties that matches the font in use
270 * will have the effect that the properties is reset to the
271 * default. If we have a text that is TYPEWRITER_FAMILY, and is
272 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
273 * a INHERIT_FAMILY was asked for. This is necessary for the
274 * toggle-user-defined-style button on the toolbar.
276 void update(LyXFont const & newfont,
277 Language const * default_lang,
278 bool toggleall = false);
280 /** Reduce font to fall back to template where possible.
281 Equal fields are reduced to INHERIT */
282 void reduce(LyXFont const & tmplt);
284 /// Realize font from a template (INHERIT are realized)
285 LyXFont & realize(LyXFont const & tmplt);
287 /// Is a given font fully resolved?
288 bool resolved() const;
290 /// Read a font specification from LyXLex. Used for layout files.
291 LyXFont & lyxRead(LyXLex &);
293 /// Writes the changes from this font to orgfont in .lyx format in file
294 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
296 /** Writes the head of the LaTeX needed to change to this font.
297 Writes to string, the head of the LaTeX needed to change
298 to this font. Returns number of chars written. Base is the
299 font state active now.
301 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
302 LyXFont const & prev) const;
304 /** Writes tha tail of the LaTeX needed to chagne to this font.
305 Returns number of chars written. Base is the font state we want
308 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
309 LyXFont const & next) const;
311 /// Build GUI description of font state
312 string stateText() const;
315 LColor::color realColor() const;
319 bool operator==(LyXFont const & font1, LyXFont const & font2) {
320 return font1.bits == font2.bits &&
321 font1.lang == font2.lang;
326 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
327 return font1.bits != font2.bits ||
328 font1.lang != font2.lang;
331 /// compares two fonts, ignoring the setting of the Latex part.
332 bool equalExceptLatex(LyXFont const &) const;
334 /// Converts logical attributes to concrete shape attribute
335 LyXFont::FONT_SHAPE realShape() const;
340 bool operator==(FontBits const & fb1) const;
342 bool operator!=(FontBits const & fb1) const;
354 FONT_MISC_STATE emph;
356 FONT_MISC_STATE underbar;
358 FONT_MISC_STATE noun;
360 FONT_MISC_STATE latex;
365 Language const * lang;
368 static FontBits sane;
371 static FontBits inherit;
374 static FontBits ignore;
376 /// Updates a misc setting according to request
377 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
378 LyXFont::FONT_MISC_STATE org);
382 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
389 lang = default_language;
394 LyXFont::LyXFont(LyXFont const & x)
402 LyXFont::LyXFont(LyXFont::FONT_INIT1)
405 lang = default_language;
410 LyXFont::LyXFont(LyXFont::FONT_INIT2)
413 lang = ignore_language;
418 LyXFont::LyXFont(LyXFont::FONT_INIT3)
421 lang = default_language;
424 LyXFont::LyXFont(LyXFont::FONT_INIT1, Language const * l)
432 LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
440 LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
448 LyXFont & LyXFont::operator=(LyXFont const & x)
457 LyXFont::FONT_FAMILY LyXFont::family() const
464 LyXFont::FONT_SERIES LyXFont::series() const
471 LyXFont::FONT_SHAPE LyXFont::shape() const
478 LyXFont::FONT_SIZE LyXFont::size() const
485 LyXFont::FONT_MISC_STATE LyXFont::emph() const
492 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
494 return bits.underbar;
499 LyXFont::FONT_MISC_STATE LyXFont::noun() const
506 LyXFont::FONT_MISC_STATE LyXFont::latex() const
513 LColor::color LyXFont::color() const
520 Language const * LyXFont::language() const
527 bool LyXFont::isRightToLeft() const
529 return lang->RightToLeft;
534 bool LyXFont::isVisibleRightToLeft() const
536 return (lang->RightToLeft && latex() != ON);
541 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
549 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
557 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
565 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
573 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
581 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
589 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
596 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
604 LyXFont & LyXFont::setColor(LColor::color c)
612 LyXFont & LyXFont::setLanguage(Language const * l)