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 * ====================================================== */
19 #include FORMS_H_LOCATION
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 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
159 LyXFont(LyXFont const & x);
161 /// Shortcut initialization
162 LyXFont(LyXFont::FONT_INIT1);
163 /// Shortcut initialization
164 LyXFont(LyXFont::FONT_INIT2);
165 /// 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 /// LyXFont x, y; x = y;
175 LyXFont & operator=(LyXFont const & x);
177 /// Decreases font size by one
180 /// Increases font size by one
184 FONT_FAMILY family() const;
187 FONT_SERIES series() const;
190 FONT_SHAPE shape() const;
193 FONT_SIZE size() const;
196 FONT_MISC_STATE emph() const;
199 FONT_MISC_STATE underbar() const;
202 FONT_MISC_STATE noun() const;
205 FONT_MISC_STATE latex() 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 & setColor(LColor::color c);
238 LyXFont & setLanguage(Language const * l);
240 /// Set family after LyX text format
241 LyXFont & setLyXFamily(string const &);
243 /// Set series after LyX text format
244 LyXFont & setLyXSeries(string const &);
246 /// Set shape after LyX text format
247 LyXFont & setLyXShape(string const &);
249 /// Set size after LyX text format
250 LyXFont & setLyXSize(string const &);
252 /// Returns misc flag after LyX text format
253 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
255 /// Sets color after LyX text format
256 LyXFont & setLyXColor(string const &);
258 /// Sets size after GUI name
259 LyXFont & setGUISize(string const &);
261 /// Returns size of font in LaTeX text notation
262 string latexSize() const;
264 /** Updates font settings according to request. If an
265 attribute is IGNORE, the attribute is left as it is. */
267 * When toggleall = true, all properties that matches the font in use
268 * will have the effect that the properties is reset to the
269 * default. If we have a text that is TYPEWRITER_FAMILY, and is
270 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
271 * a INHERIT_FAMILY was asked for. This is necessary for the
272 * toggle-user-defined-style button on the toolbar.
274 void update(LyXFont const & newfont,
275 Language const * default_lang,
276 bool toggleall = false);
278 /** Reduce font to fall back to template where possible.
279 Equal fields are reduced to INHERIT */
280 void reduce(LyXFont const & tmplt);
282 /// Realize font from a template (INHERIT are realized)
283 LyXFont & realize(LyXFont const & tmplt);
285 /// Is a given font fully resolved?
286 bool resolved() const;
288 /// Read a font specification from LyXLex. Used for layout files.
289 LyXFont & lyxRead(LyXLex &);
291 /// Writes the changes from this font to orgfont in .lyx format in file
292 void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
294 /** Writes the head of the LaTeX needed to change to this font.
295 Writes to string, the head of the LaTeX needed to change
296 to this font. Returns number of chars written. Base is the
297 font state active now.
299 int latexWriteStartChanges(ostream &, LyXFont const & base,
300 LyXFont const & prev) const;
302 /** Writes tha tail of the LaTeX needed to chagne to this font.
303 Returns number of chars written. Base is the font state we want
306 int latexWriteEndChanges(ostream &, LyXFont const & base,
307 LyXFont const & next) const;
309 /// Build GUI description of font state
310 string stateText() const;
313 int maxAscent() const;
316 int maxDescent() const;
319 int ascent(char c) const;
322 int descent(char c) const;
325 int width(char c) const;
328 int lbearing(char c) const;
331 int rbearing(char c) const;
334 int textWidth(char const *s, int n) const;
337 int stringWidth(string const & s) const;
340 int signedStringWidth(string const & s) const;
342 /// Draws text and returns width of text
343 int drawText(char const *, int n, Pixmap, int baseline, int x) const;
346 int drawString(string const &, Pixmap pm, int baseline, int x) const;
349 LColor::color realColor() const;
352 XID getFontID() const {
353 return getXFontstruct()->fid;
358 bool operator==(LyXFont const & font1, LyXFont const & font2) {
359 return font1.bits == font2.bits &&
360 font1.lang == font2.lang;
365 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
366 return font1.bits != font2.bits ||
367 font1.lang != font2.lang;
370 /// compares two fonts, ignoring the setting of the Latex part.
371 bool equalExceptLatex(LyXFont const &) const;
376 bool operator==(FontBits const & fb1) const {
377 return fb1.family == family &&
378 fb1.series == series &&
379 fb1.shape == shape &&
381 fb1.color == color &&
383 fb1.underbar == underbar &&
387 bool operator!=(FontBits const & fb1) const {
388 return !(fb1 == *this);
396 FONT_MISC_STATE emph;
397 FONT_MISC_STATE underbar;
398 FONT_MISC_STATE noun;
399 FONT_MISC_STATE latex;
403 Language const * lang;
406 static FontBits sane;
409 static FontBits inherit;
412 static FontBits ignore;
414 /// Updates a misc setting according to request
415 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
416 LyXFont::FONT_MISC_STATE org);
418 /// Converts logical attributes to concrete shape attribute
419 LyXFont::FONT_SHAPE realShape() const;
422 XFontStruct * getXFontstruct() const;
425 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
431 lang = default_language;
436 LyXFont::LyXFont(LyXFont const & x)
444 LyXFont::LyXFont(LyXFont::FONT_INIT1)
447 lang = default_language;
452 LyXFont::LyXFont(LyXFont::FONT_INIT2)
455 lang = ignore_language;
460 LyXFont::LyXFont(LyXFont::FONT_INIT3)
463 lang = default_language;
466 LyXFont::LyXFont(LyXFont::FONT_INIT1, Language const * l)
474 LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
482 LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
489 LyXFont & LyXFont::operator=(LyXFont const & x)
498 LyXFont::FONT_FAMILY LyXFont::family() const
505 LyXFont::FONT_SERIES LyXFont::series() const
512 LyXFont::FONT_SHAPE LyXFont::shape() const
519 LyXFont::FONT_SIZE LyXFont::size() const
526 LyXFont::FONT_MISC_STATE LyXFont::emph() const
533 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
535 return bits.underbar;
540 LyXFont::FONT_MISC_STATE LyXFont::noun() const
547 LyXFont::FONT_MISC_STATE LyXFont::latex() const
554 LColor::color LyXFont::color() const
561 Language const * LyXFont::language() const
568 bool LyXFont::isRightToLeft() const
570 return lang->RightToLeft;
575 bool LyXFont::isVisibleRightToLeft() const
577 return (lang->RightToLeft && latex() != ON);
582 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
590 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
598 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
606 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
614 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
622 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
630 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
637 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
645 LyXFont & LyXFont::setColor(LColor::color c)
653 LyXFont & LyXFont::setLanguage(Language const * l)