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 * ====================================================== */
34 /** The value INHERIT_* means that the font attribute is
35 inherited from the layout. In the case of layout fonts, the
36 attribute is inherited from the default font.
37 The value IGNORE_* is used with LyXFont::update() when the
38 attribute should not be changed.
42 ROMAN_FAMILY, // fontstruct rely on this to be 0
58 MEDIUM_SERIES, // fontstruct rely on this to be 0
70 UP_SHAPE, // fontstruct rely on this to be 0
86 SIZE_TINY, // fontstruct rely on this to be 0
115 /// Used for emph, underbar, noun and latex toggles
116 enum FONT_MISC_STATE {
129 /// Trick to overload constructor and make it megafast
148 /// Shortcut initialization
150 LyXFont(LyXFont::FONT_INIT1);
151 /// Shortcut initialization
153 LyXFont(LyXFont::FONT_INIT2);
154 /// Shortcut initialization
156 LyXFont(LyXFont::FONT_INIT3);
157 /// Shortcut initialization
158 LyXFont(LyXFont::FONT_INIT1, Language const * l);
159 /// Shortcut initialization
160 LyXFont(LyXFont::FONT_INIT2, Language const * l);
161 /// Shortcut initialization
162 LyXFont(LyXFont::FONT_INIT3, Language const * l);
164 /// Decreases font size by one
167 /// Increases font size by one
171 FONT_FAMILY family() const;
174 FONT_SERIES series() const;
177 FONT_SHAPE shape() const;
180 FONT_SIZE size() const;
183 FONT_MISC_STATE emph() const;
186 FONT_MISC_STATE underbar() const;
189 FONT_MISC_STATE noun() const;
193 FONT_MISC_STATE latex() const;
196 FONT_MISC_STATE number() const;
199 LColor::color color() const;
202 Language const * language() const;
205 bool isRightToLeft() const;
208 bool isVisibleRightToLeft() const;
211 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
213 LyXFont & setSeries(LyXFont::FONT_SERIES s);
215 LyXFont & setShape(LyXFont::FONT_SHAPE s);
217 LyXFont & setSize(LyXFont::FONT_SIZE s);
219 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
221 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
223 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
226 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
229 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
231 LyXFont & setColor(LColor::color c);
233 LyXFont & setLanguage(Language const * l);
235 /// Set family after LyX text format
236 LyXFont & setLyXFamily(string const &);
238 /// Set series after LyX text format
239 LyXFont & setLyXSeries(string const &);
241 /// Set shape after LyX text format
242 LyXFont & setLyXShape(string const &);
244 /// Set size after LyX text format
245 LyXFont & setLyXSize(string const &);
247 /// Returns misc flag after LyX text format
248 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
250 /// Sets color after LyX text format
251 LyXFont & setLyXColor(string const &);
253 /// Returns size of font in LaTeX text notation
254 string const latexSize() const;
256 /** Updates font settings according to request.
257 If an attribute is IGNORE, the attribute is left as it is.
258 When toggleall = true, all properties that matches the font in use
259 will have the effect that the properties is reset to the
260 default. If we have a text that is TYPEWRITER_FAMILY, and is
261 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
262 a INHERIT_FAMILY was asked for. This is necessary for the
263 toggle-user-defined-style button on the toolbar.
265 void update(LyXFont const & newfont,
266 Language const * default_lang,
267 bool toggleall = false);
269 /** Reduce font to fall back to template where possible.
270 Equal fields are reduced to INHERIT */
271 void reduce(LyXFont const & tmplt);
273 /// Realize font from a template (INHERIT are realized)
274 LyXFont & realize(LyXFont const & tmplt);
276 /// Is a given font fully resolved?
277 bool resolved() const;
279 /// Read a font specification from LyXLex. Used for layout files.
280 LyXFont & lyxRead(LyXLex &);
282 /// Writes the changes from this font to orgfont in .lyx format in file
283 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
285 /** Writes the head of the LaTeX needed to change to this font.
286 Writes to string, the head of the LaTeX needed to change
287 to this font. Returns number of chars written. Base is the
288 font state active now.
290 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
291 LyXFont const & prev) const;
293 /** Writes tha tail of the LaTeX needed to chagne to this font.
294 Returns number of chars written. Base is the font state we want
297 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
298 LyXFont const & next) const;
300 /// Build GUI description of font state
301 string const stateText(BufferParams * params) const;
304 LColor::color realColor() const;
308 bool operator==(LyXFont const & font1, LyXFont const & font2);
310 /// compares two fonts, ignoring the setting of the Latex part.
311 bool equalExceptLatex(LyXFont const &) const;
313 /// Converts logical attributes to concrete shape attribute
314 LyXFont::FONT_SHAPE realShape() const;
319 bool operator==(FontBits const & fb1) const;
321 bool operator!=(FontBits const & fb1) const;
333 FONT_MISC_STATE emph;
335 FONT_MISC_STATE underbar;
337 FONT_MISC_STATE noun;
340 FONT_MISC_STATE latex;
343 FONT_MISC_STATE number;
350 Language const * lang;
353 static FontBits sane;
356 static FontBits inherit;
359 static FontBits ignore;
361 /// Updates a misc setting according to request
362 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
363 LyXFont::FONT_MISC_STATE org);
368 LyXFont::FONT_SHAPE LyXFont::shape() const
376 : bits(sane), lang(default_language)
381 LyXFont::FONT_FAMILY LyXFont::family() const
388 LyXFont::FONT_SERIES LyXFont::series() const
395 LyXFont::FONT_SIZE LyXFont::size() const
402 LyXFont::FONT_MISC_STATE LyXFont::emph() const
409 LyXFont::FONT_MISC_STATE LyXFont::noun() const
416 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
420 bool operator==(LyXFont const & font1, LyXFont const & font2)
422 return font1.bits == font2.bits &&
423 font1.lang == font2.lang;
428 bool operator!=(LyXFont const & font1, LyXFont const & font2)
430 return !(font1 == font2);