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
68 NUM_FAMILIES = INHERIT_FAMILY
74 MEDIUM_SERIES, // fontstruct rely on this to be 0
86 UP_SHAPE, // fontstruct rely on this to be 0
102 SIZE_TINY, // fontstruct rely on this to be 0
131 /// Used for emph, underbar, noun and latex toggles
132 enum FONT_MISC_STATE {
145 /// Trick to overload constructor and make it megafast
164 /// Shortcut initialization
166 LyXFont(LyXFont::FONT_INIT1);
167 /// Shortcut initialization
169 LyXFont(LyXFont::FONT_INIT2);
170 /// Shortcut initialization
172 LyXFont(LyXFont::FONT_INIT3);
173 /// Shortcut initialization
174 LyXFont(LyXFont::FONT_INIT1, Language const * l);
175 /// Shortcut initialization
176 LyXFont(LyXFont::FONT_INIT2, Language const * l);
177 /// Shortcut initialization
178 LyXFont(LyXFont::FONT_INIT3, Language const * l);
180 /// Decreases font size by one
183 /// Increases font size by one
187 FONT_FAMILY family() const;
190 FONT_SERIES series() const;
193 FONT_SHAPE shape() const;
196 FONT_SIZE size() const;
199 FONT_MISC_STATE emph() const;
202 FONT_MISC_STATE underbar() const;
205 FONT_MISC_STATE noun() const;
208 FONT_MISC_STATE number() const;
211 LColor::color color() const;
214 Language const * language() const;
217 bool isRightToLeft() const;
220 bool isVisibleRightToLeft() const;
223 bool isSymbolFont() const;
226 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
228 LyXFont & setSeries(LyXFont::FONT_SERIES s);
230 LyXFont & setShape(LyXFont::FONT_SHAPE s);
232 LyXFont & setSize(LyXFont::FONT_SIZE s);
234 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
236 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
238 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
240 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
242 LyXFont & setColor(LColor::color c);
244 LyXFont & setLanguage(Language const * l);
246 /// Set family after LyX text format
247 LyXFont & setLyXFamily(string const &);
249 /// Set series after LyX text format
250 LyXFont & setLyXSeries(string const &);
252 /// Set shape after LyX text format
253 LyXFont & setLyXShape(string const &);
255 /// Set size after LyX text format
256 LyXFont & setLyXSize(string const &);
258 /// Returns misc flag after LyX text format
259 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
261 /// Sets color after LyX text format
262 LyXFont & setLyXColor(string const &);
264 /// Returns size of font in LaTeX text notation
265 string const latexSize() const;
267 /** Updates font settings according to request.
268 If an attribute is IGNORE, the attribute is left as it is.
269 When toggleall = true, all properties that matches the font in use
270 will have the effect that the properties is reset to the
271 default. If we have a text that is TYPEWRITER_FAMILY, and is
272 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
273 a INHERIT_FAMILY was asked for. This is necessary for the
274 toggle-user-defined-style button on the toolbar.
276 void update(LyXFont const & newfont,
277 Language const * default_lang,
278 bool toggleall = false);
280 /** Reduce font to fall back to template where possible.
281 Equal fields are reduced to INHERIT */
282 void reduce(LyXFont const & tmplt);
284 /// Realize font from a template (INHERIT are realized)
285 #ifndef INHERIT_LANGUAGE
286 LyXFont & realize(LyXFont const & tmplt);
288 LyXFont & realize(LyXFont const & tmplt, Language const * language);
290 /// Is a given font fully resolved?
291 bool resolved() const;
293 /// Read a font specification from LyXLex. Used for layout files.
294 LyXFont & lyxRead(LyXLex &);
296 /// Writes the changes from this font to orgfont in .lyx format in file
297 #ifndef INHERIT_LANGUAGE
298 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
300 void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
301 std::ostream &) const;
304 /** Writes the head of the LaTeX needed to change to this font.
305 Writes to string, the head of the LaTeX needed to change
306 to this font. Returns number of chars written. Base is the
307 font state active now.
309 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
310 LyXFont const & prev) const;
312 /** Writes tha tail of the LaTeX needed to chagne to this font.
313 Returns number of chars written. Base is the font state we want
316 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
317 LyXFont const & next) const;
319 /// Build GUI description of font state
320 string const stateText(BufferParams * params) const;
323 LColor::color realColor() const;
327 bool operator==(LyXFont const & font1, LyXFont const & font2);
329 /// Converts logical attributes to concrete shape attribute
330 LyXFont::FONT_SHAPE realShape() const;
332 /** Compaq cxx 6.5 requires that the definition be public so that
333 it can compile operator==()
347 FONT_MISC_STATE emph;
349 FONT_MISC_STATE underbar;
351 FONT_MISC_STATE noun;
353 FONT_MISC_STATE number;
361 Language const * lang;
364 static FontBits sane;
367 static FontBits inherit;
370 static FontBits ignore;
372 /// Updates a misc setting according to request
373 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
374 LyXFont::FONT_MISC_STATE org);
379 LyXFont::FONT_SHAPE LyXFont::shape() const
386 LyXFont::FONT_FAMILY LyXFont::family() const
393 LyXFont::FONT_SERIES LyXFont::series() const
400 LyXFont::FONT_SIZE LyXFont::size() const
407 LyXFont::FONT_MISC_STATE LyXFont::emph() const
414 LyXFont::FONT_MISC_STATE LyXFont::noun() const
421 bool LyXFont::isSymbolFont() const
424 case LyXFont::SYMBOL_FAMILY:
425 case LyXFont::CMSY_FAMILY:
426 case LyXFont::CMM_FAMILY:
427 case LyXFont::CMEX_FAMILY:
428 case LyXFont::MSA_FAMILY:
429 case LyXFont::MSB_FAMILY:
430 case LyXFont::WASY_FAMILY:
438 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
440 bool operator==(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs);
443 bool operator!=(LyXFont::FontBits const & lhs, LyXFont::FontBits const & rhs)
445 return !(lhs == rhs);
450 bool operator==(LyXFont const & font1, LyXFont const & font2)
452 return font1.bits == font2.bits &&
453 font1.lang == font2.lang;
458 bool operator!=(LyXFont const & font1, LyXFont const & font2)
460 return !(font1 == font2);