2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
31 /** The value INHERIT_* means that the font attribute is
32 inherited from the layout. In the case of layout fonts, the
33 attribute is inherited from the default font.
34 The value IGNORE_* is used with LyXFont::update() when the
35 attribute should not be changed.
39 ROMAN_FAMILY, // fontstruct rely on this to be 0
55 MEDIUM_SERIES, // fontstruct rely on this to be 0
67 UP_SHAPE, // fontstruct rely on this to be 0
83 SIZE_TINY, // fontstruct rely on this to be 0
112 /// Used for emph, underbar, noun and latex toggles
113 enum FONT_MISC_STATE {
126 /// Trick to overload constructor and make it megafast
145 /// Shortcut initialization
147 LyXFont(LyXFont::FONT_INIT1);
148 /// Shortcut initialization
150 LyXFont(LyXFont::FONT_INIT2);
151 /// Shortcut initialization
153 LyXFont(LyXFont::FONT_INIT3);
154 /// Shortcut initialization
155 LyXFont(LyXFont::FONT_INIT1, Language const * l);
156 /// Shortcut initialization
157 LyXFont(LyXFont::FONT_INIT2, Language const * l);
158 /// Shortcut initialization
159 LyXFont(LyXFont::FONT_INIT3, Language const * l);
161 /// Decreases font size by one
164 /// Increases font size by one
168 FONT_FAMILY family() const;
171 FONT_SERIES series() const;
174 FONT_SHAPE shape() const;
177 FONT_SIZE size() const;
180 FONT_MISC_STATE emph() const;
183 FONT_MISC_STATE underbar() const;
186 FONT_MISC_STATE noun() const;
189 FONT_MISC_STATE latex() const;
192 FONT_MISC_STATE number() const;
195 LColor::color color() const;
198 Language const * language() const;
201 bool isRightToLeft() const;
204 bool isVisibleRightToLeft() const;
207 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
209 LyXFont & setSeries(LyXFont::FONT_SERIES s);
211 LyXFont & setShape(LyXFont::FONT_SHAPE s);
213 LyXFont & setSize(LyXFont::FONT_SIZE s);
215 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
217 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
219 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
221 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
223 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
225 LyXFont & setColor(LColor::color c);
227 LyXFont & setLanguage(Language const * l);
229 /// Set family after LyX text format
230 LyXFont & setLyXFamily(string const &);
232 /// Set series after LyX text format
233 LyXFont & setLyXSeries(string const &);
235 /// Set shape after LyX text format
236 LyXFont & setLyXShape(string const &);
238 /// Set size after LyX text format
239 LyXFont & setLyXSize(string const &);
241 /// Returns misc flag after LyX text format
242 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
244 /// Sets color after LyX text format
245 LyXFont & setLyXColor(string const &);
247 /// Returns size of font in LaTeX text notation
248 string const latexSize() const;
250 /** Updates font settings according to request.
251 If an attribute is IGNORE, the attribute is left as it is.
252 When toggleall = true, all properties that matches the font in use
253 will have the effect that the properties is reset to the
254 default. If we have a text that is TYPEWRITER_FAMILY, and is
255 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
256 a INHERIT_FAMILY was asked for. This is necessary for the
257 toggle-user-defined-style button on the toolbar.
259 void update(LyXFont const & newfont,
260 Language const * default_lang,
261 bool toggleall = false);
263 /** Reduce font to fall back to template where possible.
264 Equal fields are reduced to INHERIT */
265 void reduce(LyXFont const & tmplt);
267 /// Realize font from a template (INHERIT are realized)
268 LyXFont & realize(LyXFont const & tmplt);
270 /// Is a given font fully resolved?
271 bool resolved() const;
273 /// Read a font specification from LyXLex. Used for layout files.
274 LyXFont & lyxRead(LyXLex &);
276 /// Writes the changes from this font to orgfont in .lyx format in file
277 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
279 /** Writes the head of the LaTeX needed to change to this font.
280 Writes to string, the head of the LaTeX needed to change
281 to this font. Returns number of chars written. Base is the
282 font state active now.
284 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
285 LyXFont const & prev) const;
287 /** Writes tha tail of the LaTeX needed to chagne to this font.
288 Returns number of chars written. Base is the font state we want
291 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
292 LyXFont const & next) const;
294 /// Build GUI description of font state
295 string const stateText(BufferParams * params) const;
298 LColor::color realColor() const;
302 bool operator==(LyXFont const & font1, LyXFont const & font2);
304 /// compares two fonts, ignoring the setting of the Latex part.
305 bool equalExceptLatex(LyXFont const &) const;
307 /// Converts logical attributes to concrete shape attribute
308 LyXFont::FONT_SHAPE realShape() const;
313 bool operator==(FontBits const & fb1) const;
315 bool operator!=(FontBits const & fb1) const;
327 FONT_MISC_STATE emph;
329 FONT_MISC_STATE underbar;
331 FONT_MISC_STATE noun;
333 FONT_MISC_STATE latex;
335 FONT_MISC_STATE number;
342 Language const * lang;
345 static FontBits sane;
348 static FontBits inherit;
351 static FontBits ignore;
353 /// Updates a misc setting according to request
354 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
355 LyXFont::FONT_MISC_STATE org);
360 LyXFont::FONT_SHAPE LyXFont::shape() const
367 LyXFont::FONT_MISC_STATE LyXFont::emph() const
374 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
378 bool operator==(LyXFont const & font1, LyXFont const & font2)
380 return font1.bits == font2.bits &&
381 font1.lang == font2.lang;
386 bool operator!=(LyXFont const & font1, LyXFont const & font2)
388 return !(font1 == font2);