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 Font::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 Color::color value as an int to get Color.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
190 explicit Font(Font::FONT_INIT1);
191 /// Shortcut initialization
192 explicit Font(Font::FONT_INIT2);
193 /// Shortcut initialization
194 explicit Font(Font::FONT_INIT3);
195 /// Shortcut initialization
196 Font(Font::FONT_INIT1, Language const * l);
197 /// Shortcut initialization
198 Font(Font::FONT_INIT2, Language const * l);
199 /// Shortcut initialization
200 Font(Font::FONT_INIT3, Language const * l);
202 /// Decreases font size by one
204 /// Increases font size by one
207 FONT_FAMILY family() const { return bits.family; }
209 FONT_SERIES series() const { return bits.series; }
211 FONT_SHAPE shape() const { return bits.shape; }
213 FONT_SIZE size() const { return bits.size; }
215 FONT_MISC_STATE emph() const { return bits.emph; }
217 FONT_MISC_STATE underbar() const { return bits.underbar; }
219 FONT_MISC_STATE noun() const { return bits.noun; }
221 FONT_MISC_STATE number() const { return bits.number; }
223 Color_color color() const;
225 Language const * language() const { return lang; }
227 bool isRightToLeft() const;
229 bool isVisibleRightToLeft() const;
231 bool isSymbolFont() const;
234 void setFamily(Font::FONT_FAMILY f);
235 void setSeries(Font::FONT_SERIES s);
236 void setShape(Font::FONT_SHAPE s);
237 void setSize(Font::FONT_SIZE s);
238 void setEmph(Font::FONT_MISC_STATE e);
239 void setUnderbar(Font::FONT_MISC_STATE u);
240 void setNoun(Font::FONT_MISC_STATE n);
241 void setNumber(Font::FONT_MISC_STATE n);
242 void setColor(Color_color c);
243 void setLanguage(Language const * l);
245 /// Set family after LyX text format
246 Font & setLyXFamily(std::string const &);
248 /// Set series after LyX text format
249 Font & setLyXSeries(std::string const &);
251 /// Set shape after LyX text format
252 Font & setLyXShape(std::string const &);
254 /// Set size after LyX text format
255 Font & setLyXSize(std::string const &);
257 /// Returns misc flag after LyX text format
258 Font::FONT_MISC_STATE setLyXMisc(std::string const &);
260 /// Sets color after LyX text format
261 Font & setLyXColor(std::string const &);
263 /// Returns size of font in LaTeX text notation
264 std::string const latexSize() const;
266 /** Updates font settings according to request.
267 If an attribute is IGNORE, the attribute is left as it is.
268 When toggleall = true, all properties that matches the font in use
269 will have the effect that the properties is reset to the
270 default. If we have a text that is TYPEWRITER_FAMILY, and is
271 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
272 a INHERIT_FAMILY was asked for. This is necessary for the
273 toggle-user-defined-style button on the toolbar.
275 void update(Font const & newfont,
276 Language const * default_lang,
277 bool toggleall = false);
279 /** Reduce font to fall back to template where possible.
280 Equal fields are reduced to INHERIT */
281 void reduce(Font const & tmplt);
283 /// Realize font from a template (INHERIT are realized)
284 Font & realize(Font const & tmplt);
285 /// Is a given font fully resolved?
286 bool resolved() const;
288 /// Read a font specification from Lexer. Used for layout files.
289 Font & lyxRead(Lexer &);
291 /// Writes the changes from this font to orgfont in .lyx format in file
292 void lyxWriteChanges(Font const & orgfont, std::ostream &) const;
294 /** Writes the head of the LaTeX needed to change to this font.
295 Writes to string, the head of the LaTeX needed to change
296 to this font. Returns number of chars written. Base is the
297 font state active now.
299 int latexWriteStartChanges(odocstream &, Font const & base,
300 Font const & prev) const;
302 /** Writes the tail of the LaTeX needed to change to this font.
303 Returns number of chars written. Base is the font state we want
306 int latexWriteEndChanges(odocstream &, Font const & base,
307 Font const & next) const;
310 /// Build GUI description of font state
311 docstring const stateText(BufferParams * params) const;
314 Color_color realColor() const;
318 bool operator==(Font const & font1, Font const & font2);
321 std::ostream & operator<<(std::ostream & os, Font const & font);
323 /// Converts logical attributes to concrete shape attribute
324 // Try hard to inline this as it shows up with 4.6 % in the profiler.
325 inline Font::FONT_SHAPE realShape() const {
327 return SMALLCAPS_SHAPE;
329 return (bits.shape == UP_SHAPE) ? ITALIC_SHAPE : UP_SHAPE;
334 /** Compaq cxx 6.5 requires that the definition be public so that
335 it can compile operator==()
341 Language const * lang;
343 static FontBits sane;
345 static FontBits inherit;
347 static FontBits ignore;
348 /// Updates a misc setting according to request
349 Font::FONT_MISC_STATE setMisc(Font::FONT_MISC_STATE newfont,
350 Font::FONT_MISC_STATE org);
354 /** \c Font_size is a wrapper for Font::FONT_SIZE.
355 * It can be forward-declared and passed as a function argument without
356 * having to expose Font.h.
361 Font_size(Font::FONT_SIZE val) : val_(val) {}
363 operator Font::FONT_SIZE() const { return val_; }
366 Font::FONT_SIZE val_;
372 bool Font::isSymbolFont() const
375 case Font::SYMBOL_FAMILY:
376 case Font::CMSY_FAMILY:
377 case Font::CMM_FAMILY:
378 case Font::CMEX_FAMILY:
379 case Font::MSA_FAMILY:
380 case Font::MSB_FAMILY:
381 case Font::WASY_FAMILY:
382 case Font::ESINT_FAMILY:
390 std::ostream & operator<<(std::ostream &, Font::FONT_MISC_STATE);
392 bool operator==(Font::FontBits const & lhs, Font::FontBits const & rhs);
395 bool operator!=(Font::FontBits const & lhs, Font::FontBits const & rhs)
397 return !(lhs == rhs);
402 bool operator==(Font const & font1, Font const & font2)
404 return font1.bits == font2.bits && font1.lang == font2.lang;
409 bool operator!=(Font const & font1, Font const & font2)
411 return !(font1 == font2);