2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
32 /** The value INHERIT_* means that the font attribute is
33 inherited from the layout. In the case of layout fonts, the
34 attribute is inherited from the default font.
35 The value IGNORE_* is used with LyXFont::update() when the
36 attribute should not be changed.
40 ROMAN_FAMILY, // fontstruct rely on this to be 0
56 MEDIUM_SERIES, // fontstruct rely on this to be 0
68 UP_SHAPE, // fontstruct rely on this to be 0
84 SIZE_TINY, // fontstruct rely on this to be 0
113 /// Used for emph, underbar, noun and latex toggles
114 enum FONT_MISC_STATE {
127 /// Trick to overload constructor and make it megafast
146 /// Shortcut initialization
148 LyXFont(LyXFont::FONT_INIT1);
149 /// Shortcut initialization
151 LyXFont(LyXFont::FONT_INIT2);
152 /// Shortcut initialization
154 LyXFont(LyXFont::FONT_INIT3);
155 /// Shortcut initialization
156 LyXFont(LyXFont::FONT_INIT1, Language const * l);
157 /// Shortcut initialization
158 LyXFont(LyXFont::FONT_INIT2, Language const * l);
159 /// Shortcut initialization
160 LyXFont(LyXFont::FONT_INIT3, Language const * l);
162 /// Decreases font size by one
165 /// Increases font size by one
169 FONT_FAMILY family() const;
172 FONT_SERIES series() const;
175 FONT_SHAPE shape() const;
178 FONT_SIZE size() const;
181 FONT_MISC_STATE emph() const;
184 FONT_MISC_STATE underbar() const;
187 FONT_MISC_STATE noun() const;
190 FONT_MISC_STATE latex() const;
193 FONT_MISC_STATE number() const;
196 LColor::color color() const;
199 Language const * language() const;
202 bool isRightToLeft() const;
205 bool isVisibleRightToLeft() const;
208 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
210 LyXFont & setSeries(LyXFont::FONT_SERIES s);
212 LyXFont & setShape(LyXFont::FONT_SHAPE s);
214 LyXFont & setSize(LyXFont::FONT_SIZE s);
216 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
218 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
220 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
222 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
224 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
226 LyXFont & setColor(LColor::color c);
228 LyXFont & setLanguage(Language const * l);
230 /// Set family after LyX text format
231 LyXFont & setLyXFamily(string const &);
233 /// Set series after LyX text format
234 LyXFont & setLyXSeries(string const &);
236 /// Set shape after LyX text format
237 LyXFont & setLyXShape(string const &);
239 /// Set size after LyX text format
240 LyXFont & setLyXSize(string const &);
242 /// Returns misc flag after LyX text format
243 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
245 /// Sets color after LyX text format
246 LyXFont & setLyXColor(string const &);
248 /// Returns size of font in LaTeX text notation
249 string const latexSize() const;
251 /** Updates font settings according to request.
252 If an attribute is IGNORE, the attribute is left as it is.
253 When toggleall = true, all properties that matches the font in use
254 will have the effect that the properties is reset to the
255 default. If we have a text that is TYPEWRITER_FAMILY, and is
256 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
257 a INHERIT_FAMILY was asked for. This is necessary for the
258 toggle-user-defined-style button on the toolbar.
260 void update(LyXFont const & newfont,
261 Language const * default_lang,
262 bool toggleall = false);
264 /** Reduce font to fall back to template where possible.
265 Equal fields are reduced to INHERIT */
266 void reduce(LyXFont const & tmplt);
268 /// Realize font from a template (INHERIT are realized)
269 LyXFont & realize(LyXFont const & tmplt);
271 /// Is a given font fully resolved?
272 bool resolved() const;
274 /// Read a font specification from LyXLex. Used for layout files.
275 LyXFont & lyxRead(LyXLex &);
277 /// Writes the changes from this font to orgfont in .lyx format in file
278 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
280 /** Writes the head of the LaTeX needed to change to this font.
281 Writes to string, the head of the LaTeX needed to change
282 to this font. Returns number of chars written. Base is the
283 font state active now.
285 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
286 LyXFont const & prev) const;
288 /** Writes tha tail of the LaTeX needed to chagne to this font.
289 Returns number of chars written. Base is the font state we want
292 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
293 LyXFont const & next) const;
295 /// Build GUI description of font state
296 string const stateText(BufferParams * params) const;
299 LColor::color realColor() const;
303 bool operator==(LyXFont const & font1, LyXFont const & font2);
305 /// compares two fonts, ignoring the setting of the Latex part.
306 bool equalExceptLatex(LyXFont const &) const;
308 /// Converts logical attributes to concrete shape attribute
309 LyXFont::FONT_SHAPE realShape() const;
314 bool operator==(FontBits const & fb1) const;
316 bool operator!=(FontBits const & fb1) const;
328 FONT_MISC_STATE emph;
330 FONT_MISC_STATE underbar;
332 FONT_MISC_STATE noun;
334 FONT_MISC_STATE latex;
336 FONT_MISC_STATE number;
343 Language const * lang;
346 static FontBits sane;
349 static FontBits inherit;
352 static FontBits ignore;
354 /// Updates a misc setting according to request
355 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
356 LyXFont::FONT_MISC_STATE org);
361 LyXFont::FONT_SHAPE LyXFont::shape() const
369 : bits(sane), lang(default_language)
374 LyXFont::FONT_FAMILY LyXFont::family() const
381 LyXFont::FONT_SERIES LyXFont::series() const
388 LyXFont::FONT_SIZE LyXFont::size() const
395 LyXFont::FONT_MISC_STATE LyXFont::emph() const
402 LyXFont::FONT_MISC_STATE LyXFont::noun() const
409 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
413 bool operator==(LyXFont const & font1, LyXFont const & font2)
415 return font1.bits == font2.bits &&
416 font1.lang == font2.lang;
421 bool operator!=(LyXFont const & font1, LyXFont const & font2)
423 return !(font1 == font2);