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.
31 /** The value INHERIT_* means that the font attribute is
32 inherited from the layout. In the case of layout fonts, the
33 attribute is inherited from the default font.
34 The value IGNORE_* is used with LyXFont::update() when the
35 attribute should not be changed.
39 ROMAN_FAMILY, // fontstruct rely on this to be 0
67 NUM_FAMILIES = INHERIT_FAMILY
73 MEDIUM_SERIES, // fontstruct rely on this to be 0
85 UP_SHAPE, // fontstruct rely on this to be 0
101 SIZE_TINY, // fontstruct rely on this to be 0
130 /// Used for emph, underbar, noun and latex toggles
131 enum FONT_MISC_STATE {
144 /// Trick to overload constructor and make it megafast
169 /** We store the LColor::color value as an int to get LColor.h out
170 * of the header file.
174 FONT_MISC_STATE emph;
176 FONT_MISC_STATE underbar;
178 FONT_MISC_STATE noun;
180 FONT_MISC_STATE number;
185 /// Shortcut initialization
187 LyXFont(LyXFont::FONT_INIT1);
188 /// Shortcut initialization
190 LyXFont(LyXFont::FONT_INIT2);
191 /// Shortcut initialization
193 LyXFont(LyXFont::FONT_INIT3);
194 /// Shortcut initialization
195 LyXFont(LyXFont::FONT_INIT1, Language const * l);
196 /// Shortcut initialization
197 LyXFont(LyXFont::FONT_INIT2, Language const * l);
198 /// Shortcut initialization
199 LyXFont(LyXFont::FONT_INIT3, Language const * l);
201 /// Decreases font size by one
203 /// Increases font size by one
206 FONT_FAMILY family() const { return bits.family; }
208 FONT_SERIES series() const { return bits.series; }
210 FONT_SHAPE shape() const { return bits.shape; }
212 FONT_SIZE size() const { return bits.size; }
214 FONT_MISC_STATE emph() const { return bits.emph; }
216 FONT_MISC_STATE underbar() const { return bits.underbar; }
218 FONT_MISC_STATE noun() const { return bits.noun; }
220 FONT_MISC_STATE number() const { return bits.number; }
222 LColor_color color() const;
224 Language const * language() const { return lang; }
226 bool isRightToLeft() const;
228 bool isVisibleRightToLeft() const;
230 bool isSymbolFont() const;
233 void setFamily(LyXFont::FONT_FAMILY f);
234 void setSeries(LyXFont::FONT_SERIES s);
235 void setShape(LyXFont::FONT_SHAPE s);
236 void setSize(LyXFont::FONT_SIZE s);
237 void setEmph(LyXFont::FONT_MISC_STATE e);
238 void setUnderbar(LyXFont::FONT_MISC_STATE u);
239 void setNoun(LyXFont::FONT_MISC_STATE n);
240 void setNumber(LyXFont::FONT_MISC_STATE n);
241 void setColor(LColor_color c);
242 void setLanguage(Language const * l);
244 /// Set family after LyX text format
245 LyXFont & setLyXFamily(std::string const &);
247 /// Set series after LyX text format
248 LyXFont & setLyXSeries(std::string const &);
250 /// Set shape after LyX text format
251 LyXFont & setLyXShape(std::string const &);
253 /// Set size after LyX text format
254 LyXFont & setLyXSize(std::string const &);
256 /// Returns misc flag after LyX text format
257 LyXFont::FONT_MISC_STATE setLyXMisc(std::string const &);
259 /// Sets color after LyX text format
260 LyXFont & setLyXColor(std::string const &);
262 /// Returns size of font in LaTeX text notation
263 std::string const latexSize() const;
265 /** Updates font settings according to request.
266 If an attribute is IGNORE, the attribute is left as it is.
267 When toggleall = true, all properties that matches the font in use
268 will have the effect that the properties is reset to the
269 default. If we have a text that is TYPEWRITER_FAMILY, and is
270 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
271 a INHERIT_FAMILY was asked for. This is necessary for the
272 toggle-user-defined-style button on the toolbar.
274 void update(LyXFont const & newfont,
275 Language const * default_lang,
276 bool toggleall = false);
278 /** Reduce font to fall back to template where possible.
279 Equal fields are reduced to INHERIT */
280 void reduce(LyXFont const & tmplt);
282 /// Realize font from a template (INHERIT are realized)
283 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 the tail of the LaTeX needed to change 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 std::string const stateText(BufferParams * params) const;
312 LColor_color realColor() const;
316 bool operator==(LyXFont const & font1, LyXFont const & font2);
319 std::ostream & operator<<(std::ostream & os, LyXFont const & font);
321 /// Converts logical attributes to concrete shape attribute
322 // Try hard to inline this as it shows up with 4.6 % in the profiler.
323 LyXFont::FONT_SHAPE realShape() const {
325 return SMALLCAPS_SHAPE;
327 return (bits.shape == UP_SHAPE) ? ITALIC_SHAPE : UP_SHAPE;
332 /** Compaq cxx 6.5 requires that the definition be public so that
333 it can compile operator==()
339 Language const * lang;
341 static FontBits sane;
343 static FontBits inherit;
345 static FontBits ignore;
346 /// Updates a misc setting according to request
347 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
348 LyXFont::FONT_MISC_STATE org);
352 /** \c LyXFont_size is a wrapper for LyXFont::FONT_SIZE.
353 * It can be forward-declared and passed as a function argument without
354 * having to expose lyxfont.h.
359 LyXFont_size(LyXFont::FONT_SIZE val) : val_(val) {}
361 operator LyXFont::FONT_SIZE() const { return val_; }
364 LyXFont::FONT_SIZE val_;
370 bool LyXFont::isSymbolFont() const
373 case LyXFont::SYMBOL_FAMILY:
374 case LyXFont::CMSY_FAMILY:
375 case LyXFont::CMM_FAMILY:
376 case LyXFont::CMEX_FAMILY:
377 case LyXFont::MSA_FAMILY:
378 case LyXFont::MSB_FAMILY:
379 case LyXFont::WASY_FAMILY:
387 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
389 bool operator==(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs);
392 bool operator!=(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs)
394 return !(lhs == rhs);
399 bool operator==(LyXFont const & font1, LyXFont const & font2)
401 return font1.bits == font2.bits && font1.lang == font2.lang;
406 bool operator!=(LyXFont const & font1, LyXFont const & font2)
408 return !(font1 == font2);