4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author Angus Leeming
12 * Full author contact details are available in file CREDITS.
19 #include "support/docstream.h"
33 /** The value INHERIT_* means that the font attribute is
34 inherited from the layout. In the case of layout fonts, the
35 attribute is inherited from the default font.
36 The value IGNORE_* is used with LyXFont::update() when the
37 attribute should not be changed.
41 ROMAN_FAMILY, // fontstruct rely on this to be 0
71 NUM_FAMILIES = INHERIT_FAMILY
77 MEDIUM_SERIES, // fontstruct rely on this to be 0
89 UP_SHAPE, // fontstruct rely on this to be 0
105 SIZE_TINY, // fontstruct rely on this to be 0
134 /// Used for emph, underbar, noun and latex toggles
135 enum FONT_MISC_STATE {
148 /// Trick to overload constructor and make it megafast
173 /** We store the LColor::color value as an int to get LColor.h out
174 * of the header file.
178 FONT_MISC_STATE emph;
180 FONT_MISC_STATE underbar;
182 FONT_MISC_STATE noun;
184 FONT_MISC_STATE number;
189 /// Shortcut initialization
191 LyXFont(LyXFont::FONT_INIT1);
192 /// Shortcut initialization
194 LyXFont(LyXFont::FONT_INIT2);
195 /// Shortcut initialization
197 LyXFont(LyXFont::FONT_INIT3);
198 /// Shortcut initialization
199 LyXFont(LyXFont::FONT_INIT1, Language const * l);
200 /// Shortcut initialization
201 LyXFont(LyXFont::FONT_INIT2, Language const * l);
202 /// Shortcut initialization
203 LyXFont(LyXFont::FONT_INIT3, Language const * l);
205 /// Decreases font size by one
207 /// Increases font size by one
210 FONT_FAMILY family() const { return bits.family; }
212 FONT_SERIES series() const { return bits.series; }
214 FONT_SHAPE shape() const { return bits.shape; }
216 FONT_SIZE size() const { return bits.size; }
218 FONT_MISC_STATE emph() const { return bits.emph; }
220 FONT_MISC_STATE underbar() const { return bits.underbar; }
222 FONT_MISC_STATE noun() const { return bits.noun; }
224 FONT_MISC_STATE number() const { return bits.number; }
226 LColor_color color() const;
228 Language const * language() const { return lang; }
230 bool isRightToLeft() const;
232 bool isVisibleRightToLeft() const;
234 bool isSymbolFont() const;
237 void setFamily(LyXFont::FONT_FAMILY f);
238 void setSeries(LyXFont::FONT_SERIES s);
239 void setShape(LyXFont::FONT_SHAPE s);
240 void setSize(LyXFont::FONT_SIZE s);
241 void setEmph(LyXFont::FONT_MISC_STATE e);
242 void setUnderbar(LyXFont::FONT_MISC_STATE u);
243 void setNoun(LyXFont::FONT_MISC_STATE n);
244 void setNumber(LyXFont::FONT_MISC_STATE n);
245 void setColor(LColor_color c);
246 void setLanguage(Language const * l);
248 /// Set family after LyX text format
249 LyXFont & setLyXFamily(std::string const &);
251 /// Set series after LyX text format
252 LyXFont & setLyXSeries(std::string const &);
254 /// Set shape after LyX text format
255 LyXFont & setLyXShape(std::string const &);
257 /// Set size after LyX text format
258 LyXFont & setLyXSize(std::string const &);
260 /// Returns misc flag after LyX text format
261 LyXFont::FONT_MISC_STATE setLyXMisc(std::string const &);
263 /// Sets color after LyX text format
264 LyXFont & setLyXColor(std::string const &);
266 /// Returns size of font in LaTeX text notation
267 std::string const latexSize() const;
269 /** Updates font settings according to request.
270 If an attribute is IGNORE, the attribute is left as it is.
271 When toggleall = true, all properties that matches the font in use
272 will have the effect that the properties is reset to the
273 default. If we have a text that is TYPEWRITER_FAMILY, and is
274 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
275 a INHERIT_FAMILY was asked for. This is necessary for the
276 toggle-user-defined-style button on the toolbar.
278 void update(LyXFont const & newfont,
279 Language const * default_lang,
280 bool toggleall = false);
282 /** Reduce font to fall back to template where possible.
283 Equal fields are reduced to INHERIT */
284 void reduce(LyXFont const & tmplt);
286 /// Realize font from a template (INHERIT are realized)
287 LyXFont & realize(LyXFont const & tmplt);
288 /// Is a given font fully resolved?
289 bool resolved() const;
291 /// Read a font specification from LyXLex. Used for layout files.
292 LyXFont & lyxRead(LyXLex &);
294 /// Writes the changes from this font to orgfont in .lyx format in file
295 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
297 /** Writes the head of the LaTeX needed to change to this font.
298 Writes to string, the head of the LaTeX needed to change
299 to this font. Returns number of chars written. Base is the
300 font state active now.
302 int latexWriteStartChanges(odocstream &, LyXFont const & base,
303 LyXFont const & prev) const;
305 /** Writes the tail of the LaTeX needed to change to this font.
306 Returns number of chars written. Base is the font state we want
309 int latexWriteEndChanges(odocstream &, LyXFont const & base,
310 LyXFont const & next) const;
312 /// Build GUI description of font state
313 std::string const stateText(BufferParams * params) const;
316 LColor_color realColor() const;
320 bool operator==(LyXFont const & font1, LyXFont const & font2);
323 std::ostream & operator<<(std::ostream & os, LyXFont const & font);
325 /// Converts logical attributes to concrete shape attribute
326 // Try hard to inline this as it shows up with 4.6 % in the profiler.
327 LyXFont::FONT_SHAPE realShape() const {
329 return SMALLCAPS_SHAPE;
331 return (bits.shape == UP_SHAPE) ? ITALIC_SHAPE : UP_SHAPE;
336 /** Compaq cxx 6.5 requires that the definition be public so that
337 it can compile operator==()
343 Language const * lang;
345 static FontBits sane;
347 static FontBits inherit;
349 static FontBits ignore;
350 /// Updates a misc setting according to request
351 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
352 LyXFont::FONT_MISC_STATE org);
356 /** \c LyXFont_size is a wrapper for LyXFont::FONT_SIZE.
357 * It can be forward-declared and passed as a function argument without
358 * having to expose lyxfont.h.
363 LyXFont_size(LyXFont::FONT_SIZE val) : val_(val) {}
365 operator LyXFont::FONT_SIZE() const { return val_; }
368 LyXFont::FONT_SIZE val_;
374 bool LyXFont::isSymbolFont() const
377 case LyXFont::SYMBOL_FAMILY:
378 case LyXFont::CMSY_FAMILY:
379 case LyXFont::CMM_FAMILY:
380 case LyXFont::CMEX_FAMILY:
381 case LyXFont::MSA_FAMILY:
382 case LyXFont::MSB_FAMILY:
383 case LyXFont::WASY_FAMILY:
384 case LyXFont::ESINT_FAMILY:
392 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
394 bool operator==(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs);
397 bool operator!=(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs)
399 return !(lhs == rhs);
404 bool operator==(LyXFont const & font1, LyXFont const & font2)
406 return font1.bits == font2.bits && font1.lang == font2.lang;
411 bool operator!=(LyXFont const & font1, LyXFont const & font2)
413 return !(font1 == font2);