2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 1995 Matthias Ettrich
9 *======================================================*/
17 #include FORMS_H_LOCATION
20 // It might happen that locale.h defines ON and OFF. This is not good
21 // for us, since we use these names below. But of course this is due
22 // to some old compilers. Than is broken when it comes to C++ scoping.
23 #include "gettext.h" // so that we are sure tht it won't be included
38 /** The value INHERIT_* means that the font attribute is
39 inherited from the layout. In the case of layout fonts, the
40 attribute is inherited from the default font.
41 The value IGNORE_* is used with LyXFont::update() when the
42 attribute should not be changed.
46 ROMAN_FAMILY, // fontstruct rely on this to be 0
62 MEDIUM_SERIES, // fontstruct rely on this to be 0
74 UP_SHAPE, // fontstruct rely on this to be 0
90 SIZE_TINY, // fontstruct rely on this to be 0
119 /// Used for emph, underbar, noun and latex toggles
120 enum FONT_MISC_STATE {
163 /// Trick to overload constructor and make it megafast
182 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
183 LyXFont(LyXFont const & x);
185 /// Shortcut initialization
186 LyXFont(LyXFont::FONT_INIT1);
187 /// Shortcut initialization
188 LyXFont(LyXFont::FONT_INIT2);
189 /// Shortcut initialization
190 LyXFont(LyXFont::FONT_INIT3);
192 /// LyXFont x,y; x=y;
193 LyXFont& operator=(LyXFont const & x);
195 /// Decreases font size by one
198 /// Increases font size by one
202 FONT_FAMILY family() const;
205 FONT_SERIES series() const;
208 FONT_SHAPE shape() const;
211 FONT_SIZE size() const;
214 FONT_MISC_STATE emph() const;
217 FONT_MISC_STATE underbar() const;
220 FONT_MISC_STATE noun() const;
223 FONT_MISC_STATE latex() const;
226 FONT_COLOR color() const;
229 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
231 LyXFont & setSeries(LyXFont::FONT_SERIES s);
233 LyXFont & setShape(LyXFont::FONT_SHAPE s);
235 LyXFont & setSize(LyXFont::FONT_SIZE s);
237 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
239 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
241 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
243 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
245 LyXFont & setColor(LyXFont::FONT_COLOR c);
247 /// Set family after LyX text format
248 LyXFont & setLyXFamily(LString const &);
250 /// Set series after LyX text format
251 LyXFont & setLyXSeries(LString const &);
253 /// Set shape after LyX text format
254 LyXFont & setLyXShape(LString const &);
256 /// Set size after LyX text format
257 LyXFont & setLyXSize(LString const &);
259 /// Returns misc flag after LyX text format
260 LyXFont::FONT_MISC_STATE setLyXMisc(LString const &);
262 /// Sets color after LyX text format
263 LyXFont & setLyXColor(LString const &);
265 /// Sets size after GUI name
266 LyXFont & setGUISize(LString const &);
268 /// Returns size of font in LaTeX text notation
269 LString latexSize() const;
271 /** Updates font settings according to request. If an
272 attribute is IGNORE, the attribute is left as it is. */
274 * When toggleall=true, all properties that matches the font in use
275 * will have the effect that the properties is reset to the
276 * default. If we have a text that is TYPEWRITER_FAMILY, and is
277 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
278 * a INHERIT_FAMILY was asked for. This is necessary for the
279 * toggle-user-defined-style button on the toolbar.
281 void update(LyXFont const & newfont, bool toggleall=false);
283 /** Reduce font to fall back to template where possible.
284 Equal fields are reduced to INHERIT */
285 void reduce(LyXFont const & tmplt);
287 /// Realize font from a template (INHERIT are realized)
288 LyXFont & realize(LyXFont const & tmplt);
290 /// Is a given font fully resolved?
291 bool resolved() const;
293 /// Read a font specification from LyXLex. Used for layout files.
294 LyXFont & lyxRead(LyXLex&);
296 /// Writes the changes from this font to orgfont in .lyx format in file
297 void lyxWriteChanges(LyXFont const & orgfont, FILE *) const;
299 /** Writes the head of the LaTeX needed to change to this font.
300 Writes to file, the head of the LaTeX needed to change to this font.
301 Returns number of chars written. Base is the font state active now.
303 int latexWriteStartChanges(FILE *, LyXFont const & base) const;
305 /** Writes to LString, the head of the LaTeX needed to change
306 to this font. Returns number of chars written. Base is the
307 font state active now.
309 int latexWriteStartChanges(LString &, LyXFont const & base) const;
311 /** Writes the tail of the LaTeX needd to change to this font.
312 Returns number of chars written. Base is the font state we want
315 int latexWriteEndChanges(FILE *, LyXFont const & base) const;
317 /** Writes tha tail of the LaTeX needed to chagne to this font.
318 Returns number of chars written. Base is the font state we want
321 int latexWriteEndChanges(LString &, LyXFont const & base) const;
323 /// Build GUI description of font state
324 LString stateText() const;
327 int maxAscent() const;
330 int maxDescent() const;
333 int ascent(char c) const;
336 int descent(char c) const;
339 int width(char c) const;
342 int textWidth(char const *s, int n) const;
345 int stringWidth(LString const & s) const;
348 int signedStringWidth(LString const & s) const;
350 /// Draws text and returns width of text
351 int drawText(char const*, int n, Pixmap, int baseline, int x) const;
354 int drawString(LString const &, Pixmap pm, int baseline, int x) const;
361 bool operator==(LyXFont const & font1, LyXFont const & font2) {
362 return font1.bits == font2.bits;
367 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
368 return font1.bits != font2.bits;
371 /// compares two fonts, ignoring the setting of the Latex part.
372 bool equalExceptLatex(LyXFont const &) const;
375 /// This have to be at least 32 bits, but 64 or more does not hurt
376 typedef unsigned int ui32;
378 /** Representation: bit table
380 11 1111 111 122 222 222 2233
381 Bit 012 34 567 8901 2345 678 901 234 567 8901
382 FFF SS SSS SSSS CCCC EEE UUU NNN LLL
383 aaa ee hhh iiii oooo mmm nnn ooo aaa
384 mmm rr aaa zzzz llll ppp ddd uuu ttt
386 Some might think this is a dirty representation, but it gives
387 us at least 25% speed-up, so why not?
430 enum { sane = ui32(ROMAN_FAMILY) << Fam_Pos
431 | ui32(MEDIUM_SERIES) << Ser_Pos
432 | ui32(UP_SHAPE) << Sha_Pos
433 | ui32(SIZE_NORMAL) << Siz_Pos
434 | ui32(NONE) << Col_Pos
435 | ui32(OFF) << Emp_Pos
436 | ui32(OFF) << Und_Pos
437 | ui32(OFF) << Nou_Pos
438 | ui32(OFF) << Lat_Pos};
441 enum{ inherit = ui32(INHERIT_FAMILY) << Fam_Pos
442 | ui32(INHERIT_SERIES) << Ser_Pos
443 | ui32(INHERIT_SHAPE) << Sha_Pos
444 | ui32(INHERIT_SIZE) << Siz_Pos
445 | ui32(INHERIT_COLOR) << Col_Pos
446 | ui32(INHERIT) << Emp_Pos
447 | ui32(INHERIT) << Und_Pos
448 | ui32(INHERIT) << Nou_Pos
449 | ui32(INHERIT) << Lat_Pos};
452 enum{ ignore = ui32(IGNORE_FAMILY) << Fam_Pos
453 | ui32(IGNORE_SERIES) << Ser_Pos
454 | ui32(IGNORE_SHAPE) << Sha_Pos
455 | ui32(IGNORE_SIZE) << Siz_Pos
456 | ui32(IGNORE_COLOR) << Col_Pos
457 | ui32(IGNORE) << Emp_Pos
458 | ui32(IGNORE) << Und_Pos
459 | ui32(IGNORE) << Nou_Pos
460 | ui32(IGNORE) << Lat_Pos};
462 /// Updates a misc setting according to request
463 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
464 LyXFont::FONT_MISC_STATE org);
466 /// Converts logical attributes to concrete shape attribute
467 LyXFont::FONT_SHAPE realShape() const;
470 XFontStruct* getXFontstruct() const;
474 inline LyXFont::LyXFont()
480 inline LyXFont::LyXFont(LyXFont const & x)
486 inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
492 inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
498 inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
504 inline LyXFont & LyXFont::operator=(LyXFont const & x)
511 // You don't have to understand the stuff below :-)
512 // It works, and it's bloody fast. (Asger)
513 inline LyXFont::FONT_FAMILY LyXFont::family() const
515 return LyXFont::FONT_FAMILY((bits >> Fam_Pos) & Fam_Mask);
519 inline LyXFont::FONT_SERIES LyXFont::series() const
521 return LyXFont::FONT_SERIES((bits >> Ser_Pos) & Ser_Mask);
525 inline LyXFont::FONT_SHAPE LyXFont::shape() const
527 return LyXFont::FONT_SHAPE((bits >> Sha_Pos) & Sha_Mask);
531 inline LyXFont::FONT_SIZE LyXFont::size() const
533 return LyXFont::FONT_SIZE((bits >> Siz_Pos) & Siz_Mask);
537 inline LyXFont::FONT_MISC_STATE LyXFont::emph() const
539 return LyXFont::FONT_MISC_STATE((bits >> Emp_Pos) & Misc_Mask);
543 inline LyXFont::FONT_MISC_STATE LyXFont::underbar() const
545 return LyXFont::FONT_MISC_STATE((bits >> Und_Pos) & Misc_Mask);
549 inline LyXFont::FONT_MISC_STATE LyXFont::noun() const
551 return LyXFont::FONT_MISC_STATE((bits >> Nou_Pos) & Misc_Mask);
555 inline LyXFont::FONT_MISC_STATE LyXFont::latex() const
557 return LyXFont::FONT_MISC_STATE((bits >> Lat_Pos) & Misc_Mask);
561 inline LyXFont::FONT_COLOR LyXFont::color() const
563 return LyXFont::FONT_COLOR((bits >> Col_Pos) & Col_Mask);
567 inline LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
569 bits &= ~(Fam_Mask << Fam_Pos);
570 bits |= ui32(f) << Fam_Pos;
575 inline LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
577 bits &= ~(Ser_Mask << Ser_Pos);
578 bits |= ui32(s) << Ser_Pos;
583 inline LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
585 bits &= ~(Sha_Mask << Sha_Pos);
586 bits |= ui32(s) << Sha_Pos;
591 inline LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
593 bits &= ~(Siz_Mask << Siz_Pos);
594 bits |= ui32(s) << Siz_Pos;
599 inline LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
601 bits &= ~(Misc_Mask << Emp_Pos);
602 bits |= ui32(e) << Emp_Pos;
607 inline LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
609 bits &= ~(Misc_Mask << Und_Pos);
610 bits |= ui32(u) << Und_Pos;
615 inline LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
617 bits &= ~(Misc_Mask << Nou_Pos);
618 bits |= ui32(n) << Nou_Pos;
622 inline LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
624 bits &= ~(Misc_Mask << Lat_Pos);
625 bits |= ui32(l) << Lat_Pos;
630 inline LyXFont & LyXFont::setColor(LyXFont::FONT_COLOR c)
632 bits &= ~(Col_Mask << Col_Pos);
633 bits |= ui32(c) << Col_Pos;