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 * ====================================================== */
28 /** The value INHERIT_* means that the font attribute is
29 inherited from the layout. In the case of layout fonts, the
30 attribute is inherited from the default font.
31 The value IGNORE_* is used with LyXFont::update() when the
32 attribute should not be changed.
36 ROMAN_FAMILY, // fontstruct rely on this to be 0
64 NUM_FAMILIES = INHERIT_FAMILY
70 MEDIUM_SERIES, // fontstruct rely on this to be 0
82 UP_SHAPE, // fontstruct rely on this to be 0
98 SIZE_TINY, // fontstruct rely on this to be 0
127 /// Used for emph, underbar, noun and latex toggles
128 enum FONT_MISC_STATE {
141 /// Trick to overload constructor and make it megafast
160 /// Shortcut initialization
162 LyXFont(LyXFont::FONT_INIT1);
163 /// Shortcut initialization
165 LyXFont(LyXFont::FONT_INIT2);
166 /// Shortcut initialization
168 LyXFont(LyXFont::FONT_INIT3);
169 /// Shortcut initialization
170 LyXFont(LyXFont::FONT_INIT1, Language const * l);
171 /// Shortcut initialization
172 LyXFont(LyXFont::FONT_INIT2, Language const * l);
173 /// Shortcut initialization
174 LyXFont(LyXFont::FONT_INIT3, Language const * l);
176 /// Decreases font size by one
179 /// Increases font size by one
183 FONT_FAMILY family() const;
186 FONT_SERIES series() const;
189 FONT_SHAPE shape() const;
192 FONT_SIZE size() const;
195 FONT_MISC_STATE emph() const;
198 FONT_MISC_STATE underbar() const;
201 FONT_MISC_STATE noun() const;
204 FONT_MISC_STATE number() const;
207 LColor::color color() const;
210 Language const * language() const;
213 bool isRightToLeft() const;
216 bool isVisibleRightToLeft() const;
219 bool isSymbolFont() const;
222 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
224 LyXFont & setSeries(LyXFont::FONT_SERIES s);
226 LyXFont & setShape(LyXFont::FONT_SHAPE s);
228 LyXFont & setSize(LyXFont::FONT_SIZE s);
230 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
232 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
234 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
236 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
238 LyXFont & setColor(LColor::color c);
240 LyXFont & setLanguage(Language const * l);
242 /// Set family after LyX text format
243 LyXFont & setLyXFamily(string const &);
245 /// Set series after LyX text format
246 LyXFont & setLyXSeries(string const &);
248 /// Set shape after LyX text format
249 LyXFont & setLyXShape(string const &);
251 /// Set size after LyX text format
252 LyXFont & setLyXSize(string const &);
254 /// Returns misc flag after LyX text format
255 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
257 /// Sets color after LyX text format
258 LyXFont & setLyXColor(string const &);
260 /// Returns size of font in LaTeX text notation
261 string const latexSize() const;
263 /** Updates font settings according to request.
264 If an attribute is IGNORE, the attribute is left as it is.
265 When toggleall = true, all properties that matches the font in use
266 will have the effect that the properties is reset to the
267 default. If we have a text that is TYPEWRITER_FAMILY, and is
268 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
269 a INHERIT_FAMILY was asked for. This is necessary for the
270 toggle-user-defined-style button on the toolbar.
272 void update(LyXFont const & newfont,
273 Language const * default_lang,
274 bool toggleall = false);
276 /** Reduce font to fall back to template where possible.
277 Equal fields are reduced to INHERIT */
278 void reduce(LyXFont const & tmplt);
280 /// Realize font from a template (INHERIT are realized)
281 LyXFont & realize(LyXFont const & tmplt);
282 /// Is a given font fully resolved?
283 bool resolved() const;
285 /// Read a font specification from LyXLex. Used for layout files.
286 LyXFont & lyxRead(LyXLex &);
288 /// Writes the changes from this font to orgfont in .lyx format in file
289 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
291 /** Writes the head of the LaTeX needed to change to this font.
292 Writes to string, the head of the LaTeX needed to change
293 to this font. Returns number of chars written. Base is the
294 font state active now.
296 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
297 LyXFont const & prev) const;
299 /** Writes tha tail of the LaTeX needed to chagne to this font.
300 Returns number of chars written. Base is the font state we want
303 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
304 LyXFont const & next) const;
306 /// Build GUI description of font state
307 string const stateText(BufferParams * params) const;
310 LColor::color realColor() const;
314 bool operator==(LyXFont const & font1, LyXFont const & font2);
316 /// Converts logical attributes to concrete shape attribute
317 LyXFont::FONT_SHAPE realShape() const;
319 /** Compaq cxx 6.5 requires that the definition be public so that
320 it can compile operator==()
334 FONT_MISC_STATE emph;
336 FONT_MISC_STATE underbar;
338 FONT_MISC_STATE noun;
340 FONT_MISC_STATE number;
348 Language const * lang;
351 static FontBits sane;
354 static FontBits inherit;
357 static FontBits ignore;
359 /// Updates a misc setting according to request
360 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
361 LyXFont::FONT_MISC_STATE org);
366 LyXFont::FONT_SHAPE LyXFont::shape() const
373 LyXFont::FONT_FAMILY LyXFont::family() const
380 LyXFont::FONT_SERIES LyXFont::series() const
387 LyXFont::FONT_SIZE LyXFont::size() const
394 LyXFont::FONT_MISC_STATE LyXFont::emph() const
401 LyXFont::FONT_MISC_STATE LyXFont::noun() const
408 bool LyXFont::isSymbolFont() const
411 case LyXFont::SYMBOL_FAMILY:
412 case LyXFont::CMSY_FAMILY:
413 case LyXFont::CMM_FAMILY:
414 case LyXFont::CMEX_FAMILY:
415 case LyXFont::MSA_FAMILY:
416 case LyXFont::MSB_FAMILY:
417 case LyXFont::WASY_FAMILY:
425 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
427 bool operator==(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs);
430 bool operator!=(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs)
432 return !(lhs == rhs);
437 bool operator==(LyXFont const & font1, LyXFont const & font2)
439 return font1.bits == font2.bits &&
440 font1.lang == font2.lang;
445 bool operator!=(LyXFont const & font1, LyXFont const & font2)
447 return !(font1 == font2);