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,
256 Language const * default_lang,
257 bool toggleall = false);
259 /** Reduce font to fall back to template where possible.
260 Equal fields are reduced to INHERIT */
261 void reduce(LyXFont const & tmplt);
263 /// Realize font from a template (INHERIT are realized)
264 #ifndef INHERIT_LANGUAGE
265 LyXFont & realize(LyXFont const & tmplt);
267 LyXFont & realize(LyXFont const & tmplt, Language const * language);
269 /// Is a given font fully resolved?
270 bool resolved() const;
272 /// Read a font specification from LyXLex. Used for layout files.
273 LyXFont & lyxRead(LyXLex &);
275 /// Writes the changes from this font to orgfont in .lyx format in file
276 #ifndef INHERIT_LANGUAGE
277 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
279 void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
280 std::ostream &) const;
283 /** Writes the head of the LaTeX needed to change to this font.
284 Writes to string, the head of the LaTeX needed to change
285 to this font. Returns number of chars written. Base is the
286 font state active now.
288 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
289 LyXFont const & prev) const;
291 /** Writes tha tail of the LaTeX needed to chagne to this font.
292 Returns number of chars written. Base is the font state we want
295 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
296 LyXFont const & next) const;
298 /// Build GUI description of font state
299 string const stateText(BufferParams * params) const;
302 LColor::color realColor() const;
306 bool operator==(LyXFont const & font1, LyXFont const & font2);
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 number;
341 Language const * lang;
344 static FontBits sane;
347 static FontBits inherit;
350 static FontBits ignore;
352 /// Updates a misc setting according to request
353 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
354 LyXFont::FONT_MISC_STATE org);
359 LyXFont::FONT_SHAPE LyXFont::shape() const
367 : bits(sane), lang(default_language)
372 LyXFont::FONT_FAMILY LyXFont::family() const
379 LyXFont::FONT_SERIES LyXFont::series() const
386 LyXFont::FONT_SIZE LyXFont::size() const
393 LyXFont::FONT_MISC_STATE LyXFont::emph() const
400 LyXFont::FONT_MISC_STATE LyXFont::noun() const
407 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
411 bool operator==(LyXFont const & font1, LyXFont const & font2)
413 return font1.bits == font2.bits &&
414 font1.lang == font2.lang;
419 bool operator!=(LyXFont const & font1, LyXFont const & font2)
421 return !(font1 == font2);