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 number() const;
193 LColor::color color() const;
196 Language const * language() const;
199 bool isRightToLeft() const;
202 bool isVisibleRightToLeft() const;
205 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
207 LyXFont & setSeries(LyXFont::FONT_SERIES s);
209 LyXFont & setShape(LyXFont::FONT_SHAPE s);
211 LyXFont & setSize(LyXFont::FONT_SIZE s);
213 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
215 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
217 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
219 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
221 LyXFont & setColor(LColor::color c);
223 LyXFont & setLanguage(Language const * l);
225 /// Set family after LyX text format
226 LyXFont & setLyXFamily(string const &);
228 /// Set series after LyX text format
229 LyXFont & setLyXSeries(string const &);
231 /// Set shape after LyX text format
232 LyXFont & setLyXShape(string const &);
234 /// Set size after LyX text format
235 LyXFont & setLyXSize(string const &);
237 /// Returns misc flag after LyX text format
238 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
240 /// Sets color after LyX text format
241 LyXFont & setLyXColor(string const &);
243 /// Returns size of font in LaTeX text notation
244 string const latexSize() const;
246 /** Updates font settings according to request.
247 If an attribute is IGNORE, the attribute is left as it is.
248 When toggleall = true, all properties that matches the font in use
249 will have the effect that the properties is reset to the
250 default. If we have a text that is TYPEWRITER_FAMILY, and is
251 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
252 a INHERIT_FAMILY was asked for. This is necessary for the
253 toggle-user-defined-style button on the toolbar.
255 void update(LyXFont const & newfont, bool toggleall = false);
257 /** Reduce font to fall back to template where possible.
258 Equal fields are reduced to INHERIT */
259 void reduce(LyXFont const & tmplt);
261 /// Realize font from a template (INHERIT are realized)
262 LyXFont & realize(LyXFont const & tmplt, Language const * language);
264 /// Is a given font fully resolved?
265 bool resolved() const;
267 /// Read a font specification from LyXLex. Used for layout files.
268 LyXFont & lyxRead(LyXLex &);
270 /// Writes the changes from this font to orgfont in .lyx format in file
271 void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
272 std::ostream &) const;
274 /** Writes the head of the LaTeX needed to change to this font.
275 Writes to string, the head of the LaTeX needed to change
276 to this font. Returns number of chars written. Base is the
277 font state active now.
279 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
280 LyXFont const & prev) const;
282 /** Writes tha tail of the LaTeX needed to chagne to this font.
283 Returns number of chars written. Base is the font state we want
286 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
287 LyXFont const & next) const;
289 /// Build GUI description of font state
290 string const stateText(BufferParams * params) const;
293 LColor::color realColor() const;
297 bool operator==(LyXFont const & font1, LyXFont const & font2);
299 /// Converts logical attributes to concrete shape attribute
300 LyXFont::FONT_SHAPE realShape() const;
305 bool operator==(FontBits const & fb1) const;
307 bool operator!=(FontBits const & fb1) const;
319 FONT_MISC_STATE emph;
321 FONT_MISC_STATE underbar;
323 FONT_MISC_STATE noun;
325 FONT_MISC_STATE number;
332 Language const * lang;
335 static FontBits sane;
338 static FontBits inherit;
341 static FontBits ignore;
343 /// Updates a misc setting according to request
344 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
345 LyXFont::FONT_MISC_STATE org);
350 LyXFont::FONT_SHAPE LyXFont::shape() const
358 : bits(sane), lang(default_language)
363 LyXFont::FONT_FAMILY LyXFont::family() const
370 LyXFont::FONT_SERIES LyXFont::series() const
377 LyXFont::FONT_SIZE LyXFont::size() const
384 LyXFont::FONT_MISC_STATE LyXFont::emph() const
391 LyXFont::FONT_MISC_STATE LyXFont::noun() const
398 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
402 bool operator==(LyXFont const & font1, LyXFont const & font2)
404 return font1.bits == font2.bits &&
405 font1.lang == font2.lang;
410 bool operator!=(LyXFont const & font1, LyXFont const & font2)
412 return !(font1 == font2);