2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
9 * ====================================================== */
18 #include FORMS_H_LOCATION
23 // It might happen that locale.h defines ON and OFF. This is not good
24 // for us, since we use these names below. But of course this is due
25 // to some old compilers. Than is broken when it comes to C++ scoping.
26 #include "gettext.h" // so that we are sure tht it won't be included
41 /** The value INHERIT_* means that the font attribute is
42 inherited from the layout. In the case of layout fonts, the
43 attribute is inherited from the default font.
44 The value IGNORE_* is used with LyXFont::update() when the
45 attribute should not be changed.
49 ROMAN_FAMILY, // fontstruct rely on this to be 0
65 MEDIUM_SERIES, // fontstruct rely on this to be 0
77 UP_SHAPE, // fontstruct rely on this to be 0
93 SIZE_TINY, // fontstruct rely on this to be 0
122 enum FONT_DIRECTION {
135 /// Used for emph, underbar, noun and latex toggles
136 enum FONT_MISC_STATE {
179 /// Trick to overload constructor and make it megafast
198 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
199 LyXFont(LyXFont const & x);
201 /// Shortcut initialization
202 LyXFont(LyXFont::FONT_INIT1);
203 /// Shortcut initialization
204 LyXFont(LyXFont::FONT_INIT2);
205 /// Shortcut initialization
206 LyXFont(LyXFont::FONT_INIT3);
208 /// LyXFont x, y; x = y;
209 LyXFont& operator=(LyXFont const & x);
211 /// Decreases font size by one
214 /// Increases font size by one
218 FONT_FAMILY family() const;
221 FONT_SERIES series() const;
224 FONT_SHAPE shape() const;
227 FONT_SIZE size() const;
230 FONT_MISC_STATE emph() const;
233 FONT_MISC_STATE underbar() const;
236 FONT_MISC_STATE noun() const;
239 FONT_MISC_STATE latex() const;
242 FONT_COLOR color() const;
245 FONT_DIRECTION direction() const;
248 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
250 LyXFont & setSeries(LyXFont::FONT_SERIES s);
252 LyXFont & setShape(LyXFont::FONT_SHAPE s);
254 LyXFont & setSize(LyXFont::FONT_SIZE s);
256 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
258 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
260 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
262 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
264 LyXFont & setColor(LyXFont::FONT_COLOR c);
266 LyXFont & setDirection(LyXFont::FONT_DIRECTION d);
268 /// Set family after LyX text format
269 LyXFont & setLyXFamily(string const &);
271 /// Set series after LyX text format
272 LyXFont & setLyXSeries(string const &);
274 /// Set shape after LyX text format
275 LyXFont & setLyXShape(string const &);
277 /// Set size after LyX text format
278 LyXFont & setLyXSize(string const &);
280 /// Returns misc flag after LyX text format
281 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
283 /// Sets color after LyX text format
284 LyXFont & setLyXColor(string const &);
286 /// Sets size after GUI name
287 LyXFont & setGUISize(string const &);
289 /// Returns size of font in LaTeX text notation
290 string latexSize() const;
292 /** Updates font settings according to request. If an
293 attribute is IGNORE, the attribute is left as it is. */
295 * When toggleall = true, all properties that matches the font in use
296 * will have the effect that the properties is reset to the
297 * default. If we have a text that is TYPEWRITER_FAMILY, and is
298 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
299 * a INHERIT_FAMILY was asked for. This is necessary for the
300 * toggle-user-defined-style button on the toolbar.
302 void update(LyXFont const & newfont, bool toggleall = false);
304 /** Reduce font to fall back to template where possible.
305 Equal fields are reduced to INHERIT */
306 void reduce(LyXFont const & tmplt);
308 /// Realize font from a template (INHERIT are realized)
309 LyXFont & realize(LyXFont const & tmplt);
311 /// Is a given font fully resolved?
312 bool resolved() const;
314 /// Read a font specification from LyXLex. Used for layout files.
315 LyXFont & lyxRead(LyXLex&);
317 /// Writes the changes from this font to orgfont in .lyx format in file
318 void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
320 /** Writes the head of the LaTeX needed to change to this font.
321 Writes to string, the head of the LaTeX needed to change
322 to this font. Returns number of chars written. Base is the
323 font state active now.
325 int latexWriteStartChanges(string &, LyXFont const & base,
326 LyXFont const & prev) const;
328 /** Writes tha tail of the LaTeX needed to chagne to this font.
329 Returns number of chars written. Base is the font state we want
332 int latexWriteEndChanges(string &, LyXFont const & base,
333 LyXFont const & next) const;
335 /// Build GUI description of font state
336 string stateText() const;
339 int maxAscent() const;
342 int maxDescent() const;
345 int ascent(char c) const;
348 int descent(char c) const;
351 int width(char c) const;
354 int lbearing(char c) const;
357 int rbearing(char c) const;
360 int textWidth(char const *s, int n) const;
363 int stringWidth(string const & s) const;
366 int signedStringWidth(string const & s) const;
368 /// Draws text and returns width of text
369 int drawText(char const*, int n, Pixmap, int baseline, int x) const;
372 int drawString(string const &, Pixmap pm, int baseline, int x) const;
379 bool operator==(LyXFont const & font1, LyXFont const & font2) {
380 return font1.bits == font2.bits;
385 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
386 return font1.bits != font2.bits;
389 /// compares two fonts, ignoring the setting of the Latex part.
390 bool equalExceptLatex(LyXFont const &) const;
393 /// This have to be at least 32 bits, but 64 or more does not hurt
394 typedef unsigned int ui32;
396 /** Representation: bit table
398 11 1111 111 122 222 222 2233
399 Bit 012 34 567 8901 2345 678 901 234 567 8901
400 FFF SS SSS SSSS CCCC EEE UUU NNN LLL
401 aaa ee hhh iiii oooo mmm nnn ooo aaa
402 mmm rr aaa zzzz llll ppp ddd uuu ttt
404 Some might think this is a dirty representation, but it gives
405 us at least 25% speed-up, so why not?
452 enum { sane = ui32(ROMAN_FAMILY) << Fam_Pos
453 | ui32(MEDIUM_SERIES) << Ser_Pos
454 | ui32(UP_SHAPE) << Sha_Pos
455 | ui32(SIZE_NORMAL) << Siz_Pos
456 | ui32(NONE) << Col_Pos
457 | ui32(OFF) << Emp_Pos
458 | ui32(OFF) << Und_Pos
459 | ui32(OFF) << Nou_Pos
460 | ui32(OFF) << Lat_Pos
461 | ui32(LTR_DIR) << Dir_Pos};
464 enum{ inherit = ui32(INHERIT_FAMILY) << Fam_Pos
465 | ui32(INHERIT_SERIES) << Ser_Pos
466 | ui32(INHERIT_SHAPE) << Sha_Pos
467 | ui32(INHERIT_SIZE) << Siz_Pos
468 | ui32(INHERIT_COLOR) << Col_Pos
469 | ui32(INHERIT) << Emp_Pos
470 | ui32(INHERIT) << Und_Pos
471 | ui32(INHERIT) << Nou_Pos
472 | ui32(INHERIT) << Lat_Pos
473 | ui32(INHERIT_DIR) << Dir_Pos};
476 enum{ ignore = ui32(IGNORE_FAMILY) << Fam_Pos
477 | ui32(IGNORE_SERIES) << Ser_Pos
478 | ui32(IGNORE_SHAPE) << Sha_Pos
479 | ui32(IGNORE_SIZE) << Siz_Pos
480 | ui32(IGNORE_COLOR) << Col_Pos
481 | ui32(IGNORE) << Emp_Pos
482 | ui32(IGNORE) << Und_Pos
483 | ui32(IGNORE) << Nou_Pos
484 | ui32(IGNORE) << Lat_Pos
485 | ui32(IGNORE_DIR) << Dir_Pos};
487 /// Updates a misc setting according to request
488 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
489 LyXFont::FONT_MISC_STATE org);
491 /// Converts logical attributes to concrete shape attribute
492 LyXFont::FONT_SHAPE realShape() const;
495 XFontStruct* getXFontstruct() const;
498 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
500 inline LyXFont::LyXFont()
506 inline LyXFont::LyXFont(LyXFont const & x)
512 inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
518 inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
524 inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
530 inline LyXFont & LyXFont::operator=(LyXFont const & x)
537 // You don't have to understand the stuff below :-)
538 // It works, and it's bloody fast. (Asger)
539 inline LyXFont::FONT_FAMILY LyXFont::family() const
541 return LyXFont::FONT_FAMILY((bits >> Fam_Pos) & Fam_Mask);
545 inline LyXFont::FONT_SERIES LyXFont::series() const
547 return LyXFont::FONT_SERIES((bits >> Ser_Pos) & Ser_Mask);
551 inline LyXFont::FONT_SHAPE LyXFont::shape() const
553 return LyXFont::FONT_SHAPE((bits >> Sha_Pos) & Sha_Mask);
557 inline LyXFont::FONT_SIZE LyXFont::size() const
559 return LyXFont::FONT_SIZE((bits >> Siz_Pos) & Siz_Mask);
563 inline LyXFont::FONT_MISC_STATE LyXFont::emph() const
565 return LyXFont::FONT_MISC_STATE((bits >> Emp_Pos) & Misc_Mask);
569 inline LyXFont::FONT_MISC_STATE LyXFont::underbar() const
571 return LyXFont::FONT_MISC_STATE((bits >> Und_Pos) & Misc_Mask);
575 inline LyXFont::FONT_MISC_STATE LyXFont::noun() const
577 return LyXFont::FONT_MISC_STATE((bits >> Nou_Pos) & Misc_Mask);
581 inline LyXFont::FONT_MISC_STATE LyXFont::latex() const
583 return LyXFont::FONT_MISC_STATE((bits >> Lat_Pos) & Misc_Mask);
587 inline LyXFont::FONT_COLOR LyXFont::color() const
589 return LyXFont::FONT_COLOR((bits >> Col_Pos) & Col_Mask);
592 inline LyXFont::FONT_DIRECTION LyXFont::direction() const
594 return LyXFont::FONT_DIRECTION((bits >> Dir_Pos) & Dir_Mask);
597 inline LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
599 bits &= ~(Fam_Mask << Fam_Pos);
600 bits |= ui32(f) << Fam_Pos;
605 inline LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
607 bits &= ~(Ser_Mask << Ser_Pos);
608 bits |= ui32(s) << Ser_Pos;
613 inline LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
615 bits &= ~(Sha_Mask << Sha_Pos);
616 bits |= ui32(s) << Sha_Pos;
621 inline LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
623 bits &= ~(Siz_Mask << Siz_Pos);
624 bits |= ui32(s) << Siz_Pos;
629 inline LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
631 bits &= ~(Misc_Mask << Emp_Pos);
632 bits |= ui32(e) << Emp_Pos;
637 inline LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
639 bits &= ~(Misc_Mask << Und_Pos);
640 bits |= ui32(u) << Und_Pos;
645 inline LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
647 bits &= ~(Misc_Mask << Nou_Pos);
648 bits |= ui32(n) << Nou_Pos;
652 inline LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
654 bits &= ~(Misc_Mask << Lat_Pos);
655 bits |= ui32(l) << Lat_Pos;
660 inline LyXFont & LyXFont::setColor(LyXFont::FONT_COLOR c)
662 bits &= ~(Col_Mask << Col_Pos);
663 bits |= ui32(c) << Col_Pos;
667 inline LyXFont & LyXFont::setDirection(LyXFont::FONT_DIRECTION d)
669 bits &= ~(Dir_Mask << Dir_Pos);
670 bits |= ui32(d) << Dir_Pos;