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 * ====================================================== */
25 // It might happen that locale.h defines ON and OFF. This is not good
26 // for us, since we use these names below. But of course this is due
27 // to some old compilers. Than is broken when it comes to C++ scoping.
28 #include "gettext.h" // so that we are sure tht it won't be included
44 /** The value INHERIT_* means that the font attribute is
45 inherited from the layout. In the case of layout fonts, the
46 attribute is inherited from the default font.
47 The value IGNORE_* is used with LyXFont::update() when the
48 attribute should not be changed.
52 ROMAN_FAMILY, // fontstruct rely on this to be 0
68 MEDIUM_SERIES, // fontstruct rely on this to be 0
80 UP_SHAPE, // fontstruct rely on this to be 0
96 SIZE_TINY, // fontstruct rely on this to be 0
125 /// Used for emph, underbar, noun and latex toggles
126 enum FONT_MISC_STATE {
139 /// Trick to overload constructor and make it megafast
158 /// Shortcut initialization
160 LyXFont(LyXFont::FONT_INIT1);
161 /// Shortcut initialization
163 LyXFont(LyXFont::FONT_INIT2);
164 /// Shortcut initialization
166 LyXFont(LyXFont::FONT_INIT3);
167 /// Shortcut initialization
168 LyXFont(LyXFont::FONT_INIT1, Language const * l);
169 /// Shortcut initialization
170 LyXFont(LyXFont::FONT_INIT2, Language const * l);
171 /// Shortcut initialization
172 LyXFont(LyXFont::FONT_INIT3, Language const * l);
174 /// Decreases font size by one
177 /// Increases font size by one
181 FONT_FAMILY family() const;
184 FONT_SERIES series() const;
187 FONT_SHAPE shape() const;
190 FONT_SIZE size() const;
193 FONT_MISC_STATE emph() const;
196 FONT_MISC_STATE underbar() const;
199 FONT_MISC_STATE noun() const;
202 FONT_MISC_STATE latex() const;
205 FONT_MISC_STATE number() const;
208 LColor::color color() const;
211 Language const * language() const;
214 bool isRightToLeft() const;
217 bool isVisibleRightToLeft() const;
220 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
222 LyXFont & setSeries(LyXFont::FONT_SERIES s);
224 LyXFont & setShape(LyXFont::FONT_SHAPE s);
226 LyXFont & setSize(LyXFont::FONT_SIZE s);
228 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
230 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
232 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
234 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
236 LyXFont & setNumber(LyXFont::FONT_MISC_STATE n);
238 LyXFont & setColor(LColor::color c);
240 LyXFont & setLanguage(Language const * l);
242 /// Set family after LyX text format
243 LyXFont & setLyXFamily(string const &);
245 /// Set series after LyX text format
246 LyXFont & setLyXSeries(string const &);
248 /// Set shape after LyX text format
249 LyXFont & setLyXShape(string const &);
251 /// Set size after LyX text format
252 LyXFont & setLyXSize(string const &);
254 /// Returns misc flag after LyX text format
255 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
257 /// Sets color after LyX text format
258 LyXFont & setLyXColor(string const &);
260 /// Returns size of font in LaTeX text notation
261 string const latexSize() const;
263 /** Updates font settings according to request.
264 If an attribute is IGNORE, the attribute is left as it is.
265 When toggleall = true, all properties that matches the font in use
266 will have the effect that the properties is reset to the
267 default. If we have a text that is TYPEWRITER_FAMILY, and is
268 update()'ed with TYPEWRITER_FAMILY, the operation will be as if
269 a INHERIT_FAMILY was asked for. This is necessary for the
270 toggle-user-defined-style button on the toolbar.
272 void update(LyXFont const & newfont,
273 Language const * default_lang,
274 bool toggleall = false);
276 /** Reduce font to fall back to template where possible.
277 Equal fields are reduced to INHERIT */
278 void reduce(LyXFont const & tmplt);
280 /// Realize font from a template (INHERIT are realized)
281 LyXFont & realize(LyXFont const & tmplt);
283 /// Is a given font fully resolved?
284 bool resolved() const;
286 /// Read a font specification from LyXLex. Used for layout files.
287 LyXFont & lyxRead(LyXLex &);
289 /// Writes the changes from this font to orgfont in .lyx format in file
290 void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
292 /** Writes the head of the LaTeX needed to change to this font.
293 Writes to string, the head of the LaTeX needed to change
294 to this font. Returns number of chars written. Base is the
295 font state active now.
297 int latexWriteStartChanges(std::ostream &, LyXFont const & base,
298 LyXFont const & prev) const;
300 /** Writes tha tail of the LaTeX needed to chagne to this font.
301 Returns number of chars written. Base is the font state we want
304 int latexWriteEndChanges(std::ostream &, LyXFont const & base,
305 LyXFont const & next) const;
307 /// Build GUI description of font state
308 string const stateText(BufferParams * params) const;
311 LColor::color realColor() const;
315 bool operator==(LyXFont const & font1, LyXFont const & font2);
317 /// compares two fonts, ignoring the setting of the Latex part.
318 bool equalExceptLatex(LyXFont const &) const;
320 /// Converts logical attributes to concrete shape attribute
321 LyXFont::FONT_SHAPE realShape() const;
326 bool operator==(FontBits const & fb1) const;
328 bool operator!=(FontBits const & fb1) const;
340 FONT_MISC_STATE emph;
342 FONT_MISC_STATE underbar;
344 FONT_MISC_STATE noun;
346 FONT_MISC_STATE latex;
348 FONT_MISC_STATE number;
355 Language const * lang;
358 static FontBits sane;
361 static FontBits inherit;
364 static FontBits ignore;
366 /// Updates a misc setting according to request
367 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
368 LyXFont::FONT_MISC_STATE org);
372 std::ostream & operator<<(std::ostream &, LyXFont::FONT_MISC_STATE);
376 bool operator==(LyXFont const & font1, LyXFont const & font2)
378 return font1.bits == font2.bits &&
379 font1.lang == font2.lang;
384 bool operator!=(LyXFont const & font1, LyXFont const & font2)
386 return !(font1 == font2);