2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 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 /// Used for emph, underbar, noun and latex toggles
123 enum FONT_MISC_STATE {
166 /// Trick to overload constructor and make it megafast
185 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
186 LyXFont(LyXFont const & x);
188 /// Shortcut initialization
189 LyXFont(LyXFont::FONT_INIT1);
190 /// Shortcut initialization
191 LyXFont(LyXFont::FONT_INIT2);
192 /// Shortcut initialization
193 LyXFont(LyXFont::FONT_INIT3);
195 /// LyXFont x, y; x = y;
196 LyXFont& operator=(LyXFont const & x);
198 /// Decreases font size by one
201 /// Increases font size by one
205 FONT_FAMILY family() const;
208 FONT_SERIES series() const;
211 FONT_SHAPE shape() const;
214 FONT_SIZE size() const;
217 FONT_MISC_STATE emph() const;
220 FONT_MISC_STATE underbar() const;
223 FONT_MISC_STATE noun() const;
226 FONT_MISC_STATE latex() const;
229 FONT_COLOR color() const;
232 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
234 LyXFont & setSeries(LyXFont::FONT_SERIES s);
236 LyXFont & setShape(LyXFont::FONT_SHAPE s);
238 LyXFont & setSize(LyXFont::FONT_SIZE s);
240 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
242 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
244 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
246 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
248 LyXFont & setColor(LyXFont::FONT_COLOR c);
250 /// Set family after LyX text format
251 LyXFont & setLyXFamily(string const &);
253 /// Set series after LyX text format
254 LyXFont & setLyXSeries(string const &);
256 /// Set shape after LyX text format
257 LyXFont & setLyXShape(string const &);
259 /// Set size after LyX text format
260 LyXFont & setLyXSize(string const &);
262 /// Returns misc flag after LyX text format
263 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
265 /// Sets color after LyX text format
266 LyXFont & setLyXColor(string const &);
268 /// Sets size after GUI name
269 LyXFont & setGUISize(string const &);
271 /// Returns size of font in LaTeX text notation
272 string latexSize() const;
274 /** Updates font settings according to request. If an
275 attribute is IGNORE, the attribute is left as it is. */
277 * When toggleall = true, all properties that matches the font in use
278 * will have the effect that the properties is reset to the
279 * default. If we have a text that is TYPEWRITER_FAMILY, and is
280 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
281 * a INHERIT_FAMILY was asked for. This is necessary for the
282 * toggle-user-defined-style button on the toolbar.
284 void update(LyXFont const & newfont, bool toggleall = false);
286 /** Reduce font to fall back to template where possible.
287 Equal fields are reduced to INHERIT */
288 void reduce(LyXFont const & tmplt);
290 /// Realize font from a template (INHERIT are realized)
291 LyXFont & realize(LyXFont const & tmplt);
293 /// Is a given font fully resolved?
294 bool resolved() const;
296 /// Read a font specification from LyXLex. Used for layout files.
297 LyXFont & lyxRead(LyXLex&);
299 /// Writes the changes from this font to orgfont in .lyx format in file
300 void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
302 /** Writes the head of the LaTeX needed to change to this font.
303 Writes to string, the head of the LaTeX needed to change
304 to this font. Returns number of chars written. Base is the
305 font state active now.
307 int latexWriteStartChanges(string &, LyXFont const & base) const;
309 /** Writes tha tail of the LaTeX needed to chagne to this font.
310 Returns number of chars written. Base is the font state we want
313 int latexWriteEndChanges(string &, LyXFont const & base) const;
315 /// Build GUI description of font state
316 string stateText() const;
319 int maxAscent() const;
322 int maxDescent() const;
325 int ascent(char c) const;
328 int descent(char c) const;
331 int width(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;
353 bool operator==(LyXFont const & font1, LyXFont const & font2) {
354 return font1.bits == font2.bits;
359 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
360 return font1.bits != font2.bits;
363 /// compares two fonts, ignoring the setting of the Latex part.
364 bool equalExceptLatex(LyXFont const &) const;
367 /// This have to be at least 32 bits, but 64 or more does not hurt
368 typedef unsigned int ui32;
370 /** Representation: bit table
372 11 1111 111 122 222 222 2233
373 Bit 012 34 567 8901 2345 678 901 234 567 8901
374 FFF SS SSS SSSS CCCC EEE UUU NNN LLL
375 aaa ee hhh iiii oooo mmm nnn ooo aaa
376 mmm rr aaa zzzz llll ppp ddd uuu ttt
378 Some might think this is a dirty representation, but it gives
379 us at least 25% speed-up, so why not?
422 enum { sane = ui32(ROMAN_FAMILY) << Fam_Pos
423 | ui32(MEDIUM_SERIES) << Ser_Pos
424 | ui32(UP_SHAPE) << Sha_Pos
425 | ui32(SIZE_NORMAL) << Siz_Pos
426 | ui32(NONE) << Col_Pos
427 | ui32(OFF) << Emp_Pos
428 | ui32(OFF) << Und_Pos
429 | ui32(OFF) << Nou_Pos
430 | ui32(OFF) << Lat_Pos};
433 enum{ inherit = ui32(INHERIT_FAMILY) << Fam_Pos
434 | ui32(INHERIT_SERIES) << Ser_Pos
435 | ui32(INHERIT_SHAPE) << Sha_Pos
436 | ui32(INHERIT_SIZE) << Siz_Pos
437 | ui32(INHERIT_COLOR) << Col_Pos
438 | ui32(INHERIT) << Emp_Pos
439 | ui32(INHERIT) << Und_Pos
440 | ui32(INHERIT) << Nou_Pos
441 | ui32(INHERIT) << Lat_Pos};
444 enum{ ignore = ui32(IGNORE_FAMILY) << Fam_Pos
445 | ui32(IGNORE_SERIES) << Ser_Pos
446 | ui32(IGNORE_SHAPE) << Sha_Pos
447 | ui32(IGNORE_SIZE) << Siz_Pos
448 | ui32(IGNORE_COLOR) << Col_Pos
449 | ui32(IGNORE) << Emp_Pos
450 | ui32(IGNORE) << Und_Pos
451 | ui32(IGNORE) << Nou_Pos
452 | ui32(IGNORE) << Lat_Pos};
454 /// Updates a misc setting according to request
455 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
456 LyXFont::FONT_MISC_STATE org);
458 /// Converts logical attributes to concrete shape attribute
459 LyXFont::FONT_SHAPE realShape() const;
462 XFontStruct* getXFontstruct() const;
465 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
467 inline LyXFont::LyXFont()
473 inline LyXFont::LyXFont(LyXFont const & x)
479 inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
485 inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
491 inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
497 inline LyXFont & LyXFont::operator=(LyXFont const & x)
504 // You don't have to understand the stuff below :-)
505 // It works, and it's bloody fast. (Asger)
506 inline LyXFont::FONT_FAMILY LyXFont::family() const
508 return LyXFont::FONT_FAMILY((bits >> Fam_Pos) & Fam_Mask);
512 inline LyXFont::FONT_SERIES LyXFont::series() const
514 return LyXFont::FONT_SERIES((bits >> Ser_Pos) & Ser_Mask);
518 inline LyXFont::FONT_SHAPE LyXFont::shape() const
520 return LyXFont::FONT_SHAPE((bits >> Sha_Pos) & Sha_Mask);
524 inline LyXFont::FONT_SIZE LyXFont::size() const
526 return LyXFont::FONT_SIZE((bits >> Siz_Pos) & Siz_Mask);
530 inline LyXFont::FONT_MISC_STATE LyXFont::emph() const
532 return LyXFont::FONT_MISC_STATE((bits >> Emp_Pos) & Misc_Mask);
536 inline LyXFont::FONT_MISC_STATE LyXFont::underbar() const
538 return LyXFont::FONT_MISC_STATE((bits >> Und_Pos) & Misc_Mask);
542 inline LyXFont::FONT_MISC_STATE LyXFont::noun() const
544 return LyXFont::FONT_MISC_STATE((bits >> Nou_Pos) & Misc_Mask);
548 inline LyXFont::FONT_MISC_STATE LyXFont::latex() const
550 return LyXFont::FONT_MISC_STATE((bits >> Lat_Pos) & Misc_Mask);
554 inline LyXFont::FONT_COLOR LyXFont::color() const
556 return LyXFont::FONT_COLOR((bits >> Col_Pos) & Col_Mask);
560 inline LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
562 bits &= ~(Fam_Mask << Fam_Pos);
563 bits |= ui32(f) << Fam_Pos;
568 inline LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
570 bits &= ~(Ser_Mask << Ser_Pos);
571 bits |= ui32(s) << Ser_Pos;
576 inline LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
578 bits &= ~(Sha_Mask << Sha_Pos);
579 bits |= ui32(s) << Sha_Pos;
584 inline LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
586 bits &= ~(Siz_Mask << Siz_Pos);
587 bits |= ui32(s) << Siz_Pos;
592 inline LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
594 bits &= ~(Misc_Mask << Emp_Pos);
595 bits |= ui32(e) << Emp_Pos;
600 inline LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
602 bits &= ~(Misc_Mask << Und_Pos);
603 bits |= ui32(u) << Und_Pos;
608 inline LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
610 bits &= ~(Misc_Mask << Nou_Pos);
611 bits |= ui32(n) << Nou_Pos;
615 inline LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
617 bits &= ~(Misc_Mask << Lat_Pos);
618 bits |= ui32(l) << Lat_Pos;
623 inline LyXFont & LyXFont::setColor(LyXFont::FONT_COLOR c)
625 bits &= ~(Col_Mask << Col_Pos);
626 bits |= ui32(c) << Col_Pos;