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"
30 /** The value INHERIT_* means that the font attribute is
31 inherited from the layout. In the case of layout fonts, the
32 attribute is inherited from the default font.
33 The value IGNORE_* is used with LyXFont::update() when the
34 attribute should not be changed.
38 ROMAN_FAMILY, // fontstruct rely on this to be 0
66 NUM_FAMILIES = INHERIT_FAMILY
72 MEDIUM_SERIES, // fontstruct rely on this to be 0
84 UP_SHAPE, // fontstruct rely on this to be 0
100 SIZE_TINY, // fontstruct rely on this to be 0
129 /// Used for emph, underbar, noun and latex toggles
130 enum FONT_MISC_STATE {
143 /// Trick to overload constructor and make it megafast
168 /** We store the LColor::color value as an int to get LColor.h out
169 * of the header file.
173 FONT_MISC_STATE emph;
175 FONT_MISC_STATE underbar;
177 FONT_MISC_STATE noun;
179 FONT_MISC_STATE number;
184 /// Shortcut initialization
186 LyXFont(LyXFont::FONT_INIT1);
187 /// Shortcut initialization
189 LyXFont(LyXFont::FONT_INIT2);
190 /// Shortcut initialization
192 LyXFont(LyXFont::FONT_INIT3);
193 /// Shortcut initialization
194 LyXFont(LyXFont::FONT_INIT1, Language const * l);
195 /// Shortcut initialization
196 LyXFont(LyXFont::FONT_INIT2, Language const * l);
197 /// Shortcut initialization
198 LyXFont(LyXFont::FONT_INIT3, Language const * l);
200 /// Decreases font size by one
202 /// Increases font size by one
205 FONT_FAMILY family() const { return bits.family; }
207 FONT_SERIES series() const { return bits.series; }
209 FONT_SHAPE shape() const { return bits.shape; }
211 FONT_SIZE size() const { return bits.size; }
213 FONT_MISC_STATE emph() const { return bits.emph; }
215 FONT_MISC_STATE underbar() const { return bits.underbar; }
217 FONT_MISC_STATE noun() const { return bits.noun; }
219 FONT_MISC_STATE number() const { return bits.number; }
221 LColor_color color() const;
223 Language const * language() const { return lang; }
225 bool isRightToLeft() const;
227 bool isVisibleRightToLeft() const;
229 bool isSymbolFont() const;
232 void setFamily(LyXFont::FONT_FAMILY f);
233 void setSeries(LyXFont::FONT_SERIES s);
234 void setShape(LyXFont::FONT_SHAPE s);
235 void setSize(LyXFont::FONT_SIZE s);
236 void setEmph(LyXFont::FONT_MISC_STATE e);
237 void setUnderbar(LyXFont::FONT_MISC_STATE u);
238 void setNoun(LyXFont::FONT_MISC_STATE n);
239 void setNumber(LyXFont::FONT_MISC_STATE n);
240 void setColor(LColor_color c);
241 void setLanguage(Language const * l);
243 /// Set family after LyX text format
244 LyXFont & setLyXFamily(std::string const &);
246 /// Set series after LyX text format
247 LyXFont & setLyXSeries(std::string const &);
249 /// Set shape after LyX text format
250 LyXFont & setLyXShape(std::string const &);
252 /// Set size after LyX text format
253 LyXFont & setLyXSize(std::string const &);
255 /// Returns misc flag after LyX text format
256 LyXFont::FONT_MISC_STATE setLyXMisc(std::string const &);
258 /// Sets color after LyX text format
259 LyXFont & setLyXColor(std::string const &);
261 /// Returns size of font in LaTeX text notation
262 std::string const latexSize() const;
264 /** Updates font settings according to request.
265 If an 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);
283 /// Is a given font fully resolved?
284 bool resolved() const;
286 /// Read a font specification from LyXLex. Used for layout files.
287 LyXFont & lyxRead(LyXLex &);
289 /// Writes the changes from this font to orgfont in .lyx format in file
290 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
292 /** Writes the head of the LaTeX needed to change to this font.
293 Writes to string, the head of the LaTeX needed to change
294 to this font. Returns number of chars written. Base is the
295 font state active now.
297 int latexWriteStartChanges(lyx::odocstream &, LyXFont const & base,
298 LyXFont const & prev) const;
300 /** Writes the tail of the LaTeX needed to change to this font.
301 Returns number of chars written. Base is the font state we want
304 int latexWriteEndChanges(lyx::odocstream &, LyXFont const & base,
305 LyXFont const & next) const;
307 /// Build GUI description of font state
308 std::string const stateText(BufferParams * params) const;
311 LColor_color realColor() const;
315 bool operator==(LyXFont const & font1, LyXFont const & font2);
318 std::ostream & operator<<(std::ostream & os, LyXFont const & font);
320 /// Converts logical attributes to concrete shape attribute
321 // Try hard to inline this as it shows up with 4.6 % in the profiler.
322 LyXFont::FONT_SHAPE realShape() const {
324 return SMALLCAPS_SHAPE;
326 return (bits.shape == UP_SHAPE) ? ITALIC_SHAPE : UP_SHAPE;
331 /** Compaq cxx 6.5 requires that the definition be public so that
332 it can compile operator==()
338 Language const * lang;
340 static FontBits sane;
342 static FontBits inherit;
344 static FontBits ignore;
345 /// Updates a misc setting according to request
346 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
347 LyXFont::FONT_MISC_STATE org);
351 /** \c LyXFont_size is a wrapper for LyXFont::FONT_SIZE.
352 * It can be forward-declared and passed as a function argument without
353 * having to expose lyxfont.h.
358 LyXFont_size(LyXFont::FONT_SIZE val) : val_(val) {}
360 operator LyXFont::FONT_SIZE() const { return val_; }
363 LyXFont::FONT_SIZE val_;
369 bool LyXFont::isSymbolFont() const
372 case LyXFont::SYMBOL_FAMILY:
373 case LyXFont::CMSY_FAMILY:
374 case LyXFont::CMM_FAMILY:
375 case LyXFont::CMEX_FAMILY:
376 case LyXFont::MSA_FAMILY:
377 case LyXFont::MSB_FAMILY:
378 case LyXFont::WASY_FAMILY:
386 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
388 bool operator==(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs);
391 bool operator!=(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs)
393 return !(lhs == rhs);
398 bool operator==(LyXFont const & font1, LyXFont const & font2)
400 return font1.bits == font2.bits && font1.lang == font2.lang;
405 bool operator!=(LyXFont const & font1, LyXFont const & font2)
407 return !(font1 == font2);