2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 1995 Matthias Ettrich
9 *======================================================*/
18 #include FORMS_H_LOCATION
21 // It might happen that locale.h defines ON and OFF. This is not good
22 // for us, since we use these names below. But of course this is due
23 // to some old compilers. Than is broken when it comes to C++ scoping.
24 #include "gettext.h" // so that we are sure tht it won't be included
39 /** The value INHERIT_* means that the font attribute is
40 inherited from the layout. In the case of layout fonts, the
41 attribute is inherited from the default font.
42 The value IGNORE_* is used with LyXFont::update() when the
43 attribute should not be changed.
47 ROMAN_FAMILY, // fontstruct rely on this to be 0
63 MEDIUM_SERIES, // fontstruct rely on this to be 0
75 UP_SHAPE, // fontstruct rely on this to be 0
91 SIZE_TINY, // fontstruct rely on this to be 0
120 /// Used for emph, underbar, noun and latex toggles
121 enum FONT_MISC_STATE {
164 /// Trick to overload constructor and make it megafast
183 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
184 LyXFont(LyXFont const & x);
186 /// Shortcut initialization
187 LyXFont(LyXFont::FONT_INIT1);
188 /// Shortcut initialization
189 LyXFont(LyXFont::FONT_INIT2);
190 /// Shortcut initialization
191 LyXFont(LyXFont::FONT_INIT3);
193 /// LyXFont x,y; x=y;
194 LyXFont& operator=(LyXFont const & x);
196 /// Decreases font size by one
199 /// Increases font size by one
203 FONT_FAMILY family() const;
206 FONT_SERIES series() const;
209 FONT_SHAPE shape() const;
212 FONT_SIZE size() const;
215 FONT_MISC_STATE emph() const;
218 FONT_MISC_STATE underbar() const;
221 FONT_MISC_STATE noun() const;
224 FONT_MISC_STATE latex() const;
227 FONT_COLOR color() const;
230 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
232 LyXFont & setSeries(LyXFont::FONT_SERIES s);
234 LyXFont & setShape(LyXFont::FONT_SHAPE s);
236 LyXFont & setSize(LyXFont::FONT_SIZE s);
238 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
240 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
242 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
244 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
246 LyXFont & setColor(LyXFont::FONT_COLOR c);
248 /// Set family after LyX text format
249 LyXFont & setLyXFamily(string const &);
251 /// Set series after LyX text format
252 LyXFont & setLyXSeries(string const &);
254 /// Set shape after LyX text format
255 LyXFont & setLyXShape(string const &);
257 /// Set size after LyX text format
258 LyXFont & setLyXSize(string const &);
260 /// Returns misc flag after LyX text format
261 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
263 /// Sets color after LyX text format
264 LyXFont & setLyXColor(string const &);
266 /// Sets size after GUI name
267 LyXFont & setGUISize(string const &);
269 /// Returns size of font in LaTeX text notation
270 string latexSize() const;
272 /** Updates font settings according to request. If an
273 attribute is IGNORE, the attribute is left as it is. */
275 * When toggleall=true, all properties that matches the font in use
276 * will have the effect that the properties is reset to the
277 * default. If we have a text that is TYPEWRITER_FAMILY, and is
278 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
279 * a INHERIT_FAMILY was asked for. This is necessary for the
280 * toggle-user-defined-style button on the toolbar.
282 void update(LyXFont const & newfont, bool toggleall=false);
284 /** Reduce font to fall back to template where possible.
285 Equal fields are reduced to INHERIT */
286 void reduce(LyXFont const & tmplt);
288 /// Realize font from a template (INHERIT are realized)
289 LyXFont & realize(LyXFont const & tmplt);
291 /// Is a given font fully resolved?
292 bool resolved() const;
294 /// Read a font specification from LyXLex. Used for layout files.
295 LyXFont & lyxRead(LyXLex&);
297 /// Writes the changes from this font to orgfont in .lyx format in file
298 void lyxWriteChanges(LyXFont const & orgfont, FILE *) const;
300 /** Writes the head of the LaTeX needed to change to this font.
301 Writes to file, the head of the LaTeX needed to change to this font.
302 Returns number of chars written. Base is the font state active now.
304 int latexWriteStartChanges(FILE *, LyXFont const & base) const;
306 /** Writes to string, the head of the LaTeX needed to change
307 to this font. Returns number of chars written. Base is the
308 font state active now.
310 int latexWriteStartChanges(string &, LyXFont const & base) const;
312 /** Writes the tail of the LaTeX needd to change to this font.
313 Returns number of chars written. Base is the font state we want
316 int latexWriteEndChanges(FILE *, LyXFont const & base) const;
318 /** Writes tha tail of the LaTeX needed to chagne to this font.
319 Returns number of chars written. Base is the font state we want
322 int latexWriteEndChanges(string &, LyXFont const & base) const;
324 /// Build GUI description of font state
325 string stateText() const;
328 int maxAscent() const;
331 int maxDescent() const;
334 int ascent(char c) const;
337 int descent(char c) const;
340 int width(char c) const;
343 int textWidth(char const *s, int n) const;
346 int stringWidth(string const & s) const;
349 int signedStringWidth(string const & s) const;
351 /// Draws text and returns width of text
352 int drawText(char const*, int n, Pixmap, int baseline, int x) const;
355 int drawString(string const &, Pixmap pm, int baseline, int x) const;
362 bool operator==(LyXFont const & font1, LyXFont const & font2) {
363 return font1.bits == font2.bits;
368 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
369 return font1.bits != font2.bits;
372 /// compares two fonts, ignoring the setting of the Latex part.
373 bool equalExceptLatex(LyXFont const &) const;
376 /// This have to be at least 32 bits, but 64 or more does not hurt
377 typedef unsigned int ui32;
379 /** Representation: bit table
381 11 1111 111 122 222 222 2233
382 Bit 012 34 567 8901 2345 678 901 234 567 8901
383 FFF SS SSS SSSS CCCC EEE UUU NNN LLL
384 aaa ee hhh iiii oooo mmm nnn ooo aaa
385 mmm rr aaa zzzz llll ppp ddd uuu ttt
387 Some might think this is a dirty representation, but it gives
388 us at least 25% speed-up, so why not?
431 enum { sane = ui32(ROMAN_FAMILY) << Fam_Pos
432 | ui32(MEDIUM_SERIES) << Ser_Pos
433 | ui32(UP_SHAPE) << Sha_Pos
434 | ui32(SIZE_NORMAL) << Siz_Pos
435 | ui32(NONE) << Col_Pos
436 | ui32(OFF) << Emp_Pos
437 | ui32(OFF) << Und_Pos
438 | ui32(OFF) << Nou_Pos
439 | ui32(OFF) << Lat_Pos};
442 enum{ inherit = ui32(INHERIT_FAMILY) << Fam_Pos
443 | ui32(INHERIT_SERIES) << Ser_Pos
444 | ui32(INHERIT_SHAPE) << Sha_Pos
445 | ui32(INHERIT_SIZE) << Siz_Pos
446 | ui32(INHERIT_COLOR) << Col_Pos
447 | ui32(INHERIT) << Emp_Pos
448 | ui32(INHERIT) << Und_Pos
449 | ui32(INHERIT) << Nou_Pos
450 | ui32(INHERIT) << Lat_Pos};
453 enum{ ignore = ui32(IGNORE_FAMILY) << Fam_Pos
454 | ui32(IGNORE_SERIES) << Ser_Pos
455 | ui32(IGNORE_SHAPE) << Sha_Pos
456 | ui32(IGNORE_SIZE) << Siz_Pos
457 | ui32(IGNORE_COLOR) << Col_Pos
458 | ui32(IGNORE) << Emp_Pos
459 | ui32(IGNORE) << Und_Pos
460 | ui32(IGNORE) << Nou_Pos
461 | ui32(IGNORE) << Lat_Pos};
463 /// Updates a misc setting according to request
464 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
465 LyXFont::FONT_MISC_STATE org);
467 /// Converts logical attributes to concrete shape attribute
468 LyXFont::FONT_SHAPE realShape() const;
471 XFontStruct* getXFontstruct() const;
475 inline LyXFont::LyXFont()
481 inline LyXFont::LyXFont(LyXFont const & x)
487 inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
493 inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
499 inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
505 inline LyXFont & LyXFont::operator=(LyXFont const & x)
512 // You don't have to understand the stuff below :-)
513 // It works, and it's bloody fast. (Asger)
514 inline LyXFont::FONT_FAMILY LyXFont::family() const
516 return LyXFont::FONT_FAMILY((bits >> Fam_Pos) & Fam_Mask);
520 inline LyXFont::FONT_SERIES LyXFont::series() const
522 return LyXFont::FONT_SERIES((bits >> Ser_Pos) & Ser_Mask);
526 inline LyXFont::FONT_SHAPE LyXFont::shape() const
528 return LyXFont::FONT_SHAPE((bits >> Sha_Pos) & Sha_Mask);
532 inline LyXFont::FONT_SIZE LyXFont::size() const
534 return LyXFont::FONT_SIZE((bits >> Siz_Pos) & Siz_Mask);
538 inline LyXFont::FONT_MISC_STATE LyXFont::emph() const
540 return LyXFont::FONT_MISC_STATE((bits >> Emp_Pos) & Misc_Mask);
544 inline LyXFont::FONT_MISC_STATE LyXFont::underbar() const
546 return LyXFont::FONT_MISC_STATE((bits >> Und_Pos) & Misc_Mask);
550 inline LyXFont::FONT_MISC_STATE LyXFont::noun() const
552 return LyXFont::FONT_MISC_STATE((bits >> Nou_Pos) & Misc_Mask);
556 inline LyXFont::FONT_MISC_STATE LyXFont::latex() const
558 return LyXFont::FONT_MISC_STATE((bits >> Lat_Pos) & Misc_Mask);
562 inline LyXFont::FONT_COLOR LyXFont::color() const
564 return LyXFont::FONT_COLOR((bits >> Col_Pos) & Col_Mask);
568 inline LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
570 bits &= ~(Fam_Mask << Fam_Pos);
571 bits |= ui32(f) << Fam_Pos;
576 inline LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
578 bits &= ~(Ser_Mask << Ser_Pos);
579 bits |= ui32(s) << Ser_Pos;
584 inline LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
586 bits &= ~(Sha_Mask << Sha_Pos);
587 bits |= ui32(s) << Sha_Pos;
592 inline LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
594 bits &= ~(Siz_Mask << Siz_Pos);
595 bits |= ui32(s) << Siz_Pos;
600 inline LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
602 bits &= ~(Misc_Mask << Emp_Pos);
603 bits |= ui32(e) << Emp_Pos;
608 inline LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
610 bits &= ~(Misc_Mask << Und_Pos);
611 bits |= ui32(u) << Und_Pos;
616 inline LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
618 bits &= ~(Misc_Mask << Nou_Pos);
619 bits |= ui32(n) << Nou_Pos;
623 inline LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
625 bits &= ~(Misc_Mask << Lat_Pos);
626 bits |= ui32(l) << Lat_Pos;
631 inline LyXFont & LyXFont::setColor(LyXFont::FONT_COLOR c)
633 bits &= ~(Col_Mask << Col_Pos);
634 bits |= ui32(c) << Col_Pos;