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, bool toggleall = false);
267 /** Reduce font to fall back to template where possible.
268 Equal fields are reduced to INHERIT */
269 void reduce(LyXFont const & tmplt);
271 /// Realize font from a template (INHERIT are realized)
272 LyXFont & realize(LyXFont const & tmplt, Language const * language);
274 /// Is a given font fully resolved?
275 bool resolved() const;
277 /// Read a font specification from LyXLex. Used for layout files.
278 LyXFont & lyxRead(LyXLex &);
280 /// Writes the changes from this font to orgfont in .lyx format in file
281 void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
282 std::ostream &) const;
284 /** Writes the head of the LaTeX needed to change to this font.
285 Writes to string, the head of the LaTeX needed to change
286 to this font. Returns number of chars written. Base is the
287 font state active now.
289 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
290 LyXFont const & prev) const;
292 /** Writes tha tail of the LaTeX needed to chagne to this font.
293 Returns number of chars written. Base is the font state we want
296 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
297 LyXFont const & next) const;
299 /// Build GUI description of font state
300 string const stateText(BufferParams * params) const;
303 LColor::color realColor() const;
307 bool operator==(LyXFont const & font1, LyXFont const & font2);
309 /// compares two fonts, ignoring the setting of the Latex part.
310 bool equalExceptLatex(LyXFont const &) const;
312 /// Converts logical attributes to concrete shape attribute
313 LyXFont::FONT_SHAPE realShape() const;
318 bool operator==(FontBits const & fb1) const;
320 bool operator!=(FontBits const & fb1) const;
332 FONT_MISC_STATE emph;
334 FONT_MISC_STATE underbar;
336 FONT_MISC_STATE noun;
339 FONT_MISC_STATE latex;
342 FONT_MISC_STATE number;
349 Language const * lang;
352 static FontBits sane;
355 static FontBits inherit;
358 static FontBits ignore;
360 /// Updates a misc setting according to request
361 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
362 LyXFont::FONT_MISC_STATE org);
367 LyXFont::FONT_SHAPE LyXFont::shape() const
375 : bits(sane), lang(default_language)
380 LyXFont::FONT_FAMILY LyXFont::family() const
387 LyXFont::FONT_SERIES LyXFont::series() const
394 LyXFont::FONT_SIZE LyXFont::size() const
401 LyXFont::FONT_MISC_STATE LyXFont::emph() const
408 LyXFont::FONT_MISC_STATE LyXFont::noun() const
415 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
419 bool operator==(LyXFont const & font1, LyXFont const & font2)
421 return font1.bits == font2.bits &&
422 font1.lang == font2.lang;
427 bool operator!=(LyXFont const & font1, LyXFont const & font2)
429 return !(font1 == font2);