2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
9 * ====================================================== */
18 #include FORMS_H_LOCATION
21 #include "direction.h"
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 LyXDirection getFontDirection() const;
251 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
253 LyXFont & setSeries(LyXFont::FONT_SERIES s);
255 LyXFont & setShape(LyXFont::FONT_SHAPE s);
257 LyXFont & setSize(LyXFont::FONT_SIZE s);
259 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
261 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
263 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
265 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
267 LyXFont & setColor(LyXFont::FONT_COLOR c);
269 LyXFont & setDirection(LyXFont::FONT_DIRECTION d);
271 /// Set family after LyX text format
272 LyXFont & setLyXFamily(string const &);
274 /// Set series after LyX text format
275 LyXFont & setLyXSeries(string const &);
277 /// Set shape after LyX text format
278 LyXFont & setLyXShape(string const &);
280 /// Set size after LyX text format
281 LyXFont & setLyXSize(string const &);
283 /// Returns misc flag after LyX text format
284 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
286 /// Sets color after LyX text format
287 LyXFont & setLyXColor(string const &);
289 /// Sets size after GUI name
290 LyXFont & setGUISize(string const &);
292 /// Returns size of font in LaTeX text notation
293 string latexSize() const;
295 /** Updates font settings according to request. If an
296 attribute is IGNORE, the attribute is left as it is. */
298 * When toggleall = true, all properties that matches the font in use
299 * will have the effect that the properties is reset to the
300 * default. If we have a text that is TYPEWRITER_FAMILY, and is
301 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
302 * a INHERIT_FAMILY was asked for. This is necessary for the
303 * toggle-user-defined-style button on the toolbar.
305 void update(LyXFont const & newfont, bool toggleall = false);
307 /** Reduce font to fall back to template where possible.
308 Equal fields are reduced to INHERIT */
309 void reduce(LyXFont const & tmplt);
311 /// Realize font from a template (INHERIT are realized)
312 LyXFont & realize(LyXFont const & tmplt);
314 /// Is a given font fully resolved?
315 bool resolved() const;
317 /// Read a font specification from LyXLex. Used for layout files.
318 LyXFont & lyxRead(LyXLex&);
320 /// Writes the changes from this font to orgfont in .lyx format in file
321 void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
323 /** Writes the head of the LaTeX needed to change to this font.
324 Writes to string, the head of the LaTeX needed to change
325 to this font. Returns number of chars written. Base is the
326 font state active now.
328 int latexWriteStartChanges(string &, LyXFont const & base,
329 LyXFont const & prev) const;
331 /** Writes tha tail of the LaTeX needed to chagne to this font.
332 Returns number of chars written. Base is the font state we want
335 int latexWriteEndChanges(string &, LyXFont const & base,
336 LyXFont const & next) const;
338 /// Build GUI description of font state
339 string stateText() const;
342 int maxAscent() const;
345 int maxDescent() const;
348 int ascent(char c) const;
351 int descent(char c) const;
354 int width(char c) const;
357 int lbearing(char c) const;
360 int rbearing(char c) const;
363 int textWidth(char const *s, int n) const;
366 int stringWidth(string const & s) const;
369 int signedStringWidth(string const & s) const;
371 /// Draws text and returns width of text
372 int drawText(char const*, int n, Pixmap, int baseline, int x) const;
375 int drawString(string const &, Pixmap pm, int baseline, int x) const;
382 bool operator==(LyXFont const & font1, LyXFont const & font2) {
383 return font1.bits == font2.bits;
388 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
389 return font1.bits != font2.bits;
392 /// compares two fonts, ignoring the setting of the Latex part.
393 bool equalExceptLatex(LyXFont const &) const;
396 /// This have to be at least 32 bits, but 64 or more does not hurt
397 typedef unsigned int ui32;
399 /** Representation: bit table
401 11 1111 111 122 222 222 2233
402 Bit 012 34 567 8901 2345 678 901 234 567 8901
403 FFF SS SSS SSSS CCCC EEE UUU NNN LLL
404 aaa ee hhh iiii oooo mmm nnn ooo aaa
405 mmm rr aaa zzzz llll ppp ddd uuu ttt
407 Some might think this is a dirty representation, but it gives
408 us at least 25% speed-up, so why not?
455 enum { sane = ui32(ROMAN_FAMILY) << Fam_Pos
456 | ui32(MEDIUM_SERIES) << Ser_Pos
457 | ui32(UP_SHAPE) << Sha_Pos
458 | ui32(SIZE_NORMAL) << Siz_Pos
459 | ui32(NONE) << Col_Pos
460 | ui32(OFF) << Emp_Pos
461 | ui32(OFF) << Und_Pos
462 | ui32(OFF) << Nou_Pos
463 | ui32(OFF) << Lat_Pos
464 | ui32(LTR_DIR) << Dir_Pos};
467 enum{ inherit = ui32(INHERIT_FAMILY) << Fam_Pos
468 | ui32(INHERIT_SERIES) << Ser_Pos
469 | ui32(INHERIT_SHAPE) << Sha_Pos
470 | ui32(INHERIT_SIZE) << Siz_Pos
471 | ui32(INHERIT_COLOR) << Col_Pos
472 | ui32(INHERIT) << Emp_Pos
473 | ui32(INHERIT) << Und_Pos
474 | ui32(INHERIT) << Nou_Pos
475 | ui32(INHERIT) << Lat_Pos
476 | ui32(INHERIT_DIR) << Dir_Pos};
479 enum{ ignore = ui32(IGNORE_FAMILY) << Fam_Pos
480 | ui32(IGNORE_SERIES) << Ser_Pos
481 | ui32(IGNORE_SHAPE) << Sha_Pos
482 | ui32(IGNORE_SIZE) << Siz_Pos
483 | ui32(IGNORE_COLOR) << Col_Pos
484 | ui32(IGNORE) << Emp_Pos
485 | ui32(IGNORE) << Und_Pos
486 | ui32(IGNORE) << Nou_Pos
487 | ui32(IGNORE) << Lat_Pos
488 | ui32(IGNORE_DIR) << Dir_Pos};
490 /// Updates a misc setting according to request
491 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
492 LyXFont::FONT_MISC_STATE org);
494 /// Converts logical attributes to concrete shape attribute
495 LyXFont::FONT_SHAPE realShape() const;
498 XFontStruct* getXFontstruct() const;
501 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
503 inline LyXFont::LyXFont()
509 inline LyXFont::LyXFont(LyXFont const & x)
515 inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
521 inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
527 inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
533 inline LyXFont & LyXFont::operator=(LyXFont const & x)
540 // You don't have to understand the stuff below :-)
541 // It works, and it's bloody fast. (Asger)
542 inline LyXFont::FONT_FAMILY LyXFont::family() const
544 return LyXFont::FONT_FAMILY((bits >> Fam_Pos) & Fam_Mask);
548 inline LyXFont::FONT_SERIES LyXFont::series() const
550 return LyXFont::FONT_SERIES((bits >> Ser_Pos) & Ser_Mask);
554 inline LyXFont::FONT_SHAPE LyXFont::shape() const
556 return LyXFont::FONT_SHAPE((bits >> Sha_Pos) & Sha_Mask);
560 inline LyXFont::FONT_SIZE LyXFont::size() const
562 return LyXFont::FONT_SIZE((bits >> Siz_Pos) & Siz_Mask);
566 inline LyXFont::FONT_MISC_STATE LyXFont::emph() const
568 return LyXFont::FONT_MISC_STATE((bits >> Emp_Pos) & Misc_Mask);
572 inline LyXFont::FONT_MISC_STATE LyXFont::underbar() const
574 return LyXFont::FONT_MISC_STATE((bits >> Und_Pos) & Misc_Mask);
578 inline LyXFont::FONT_MISC_STATE LyXFont::noun() const
580 return LyXFont::FONT_MISC_STATE((bits >> Nou_Pos) & Misc_Mask);
584 inline LyXFont::FONT_MISC_STATE LyXFont::latex() const
586 return LyXFont::FONT_MISC_STATE((bits >> Lat_Pos) & Misc_Mask);
590 inline LyXFont::FONT_COLOR LyXFont::color() const
592 return LyXFont::FONT_COLOR((bits >> Col_Pos) & Col_Mask);
595 inline LyXFont::FONT_DIRECTION LyXFont::direction() const
597 return LyXFont::FONT_DIRECTION((bits >> Dir_Pos) & Dir_Mask);
600 inline LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
602 bits &= ~(Fam_Mask << Fam_Pos);
603 bits |= ui32(f) << Fam_Pos;
608 inline LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
610 bits &= ~(Ser_Mask << Ser_Pos);
611 bits |= ui32(s) << Ser_Pos;
616 inline LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
618 bits &= ~(Sha_Mask << Sha_Pos);
619 bits |= ui32(s) << Sha_Pos;
624 inline LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
626 bits &= ~(Siz_Mask << Siz_Pos);
627 bits |= ui32(s) << Siz_Pos;
632 inline LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
634 bits &= ~(Misc_Mask << Emp_Pos);
635 bits |= ui32(e) << Emp_Pos;
640 inline LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
642 bits &= ~(Misc_Mask << Und_Pos);
643 bits |= ui32(u) << Und_Pos;
648 inline LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
650 bits &= ~(Misc_Mask << Nou_Pos);
651 bits |= ui32(n) << Nou_Pos;
655 inline LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
657 bits &= ~(Misc_Mask << Lat_Pos);
658 bits |= ui32(l) << Lat_Pos;
663 inline LyXFont & LyXFont::setColor(LyXFont::FONT_COLOR c)
665 bits &= ~(Col_Mask << Col_Pos);
666 bits |= ui32(c) << Col_Pos;
670 inline LyXFont & LyXFont::setDirection(LyXFont::FONT_DIRECTION d)
672 bits &= ~(Dir_Mask << Dir_Pos);
673 bits |= ui32(d) << Dir_Pos;