2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
21 #include FORMS_H_LOCATION
27 // It might happen that locale.h defines ON and OFF. This is not good
28 // for us, since we use these names below. But of course this is due
29 // to some old compilers. Than is broken when it comes to C++ scoping.
30 #include "gettext.h" // so that we are sure tht it won't be included
47 /** The value INHERIT_* means that the font attribute is
48 inherited from the layout. In the case of layout fonts, the
49 attribute is inherited from the default font.
50 The value IGNORE_* is used with LyXFont::update() when the
51 attribute should not be changed.
55 ROMAN_FAMILY, // fontstruct rely on this to be 0
71 MEDIUM_SERIES, // fontstruct rely on this to be 0
83 UP_SHAPE, // fontstruct rely on this to be 0
99 SIZE_TINY, // fontstruct rely on this to be 0
128 /// Used for emph, underbar, noun and latex toggles
129 enum FONT_MISC_STATE {
142 /// Trick to overload constructor and make it megafast
161 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
162 LyXFont(LyXFont const & x);
164 /// Shortcut initialization
165 LyXFont(LyXFont::FONT_INIT1);
166 /// Shortcut initialization
167 LyXFont(LyXFont::FONT_INIT2);
168 /// Shortcut initialization
169 LyXFont(LyXFont::FONT_INIT3);
170 /// Shortcut initialization
171 LyXFont(LyXFont::FONT_INIT1, Language const * l);
172 /// Shortcut initialization
173 LyXFont(LyXFont::FONT_INIT2, Language const * l);
174 /// Shortcut initialization
175 LyXFont(LyXFont::FONT_INIT3, Language const * l);
177 /// LyXFont x, y; x = y;
178 LyXFont & operator=(LyXFont const & x);
180 /// Decreases font size by one
183 /// Increases font size by one
187 FONT_FAMILY family() const;
190 FONT_SERIES series() const;
193 FONT_SHAPE shape() const;
196 FONT_SIZE size() const;
199 FONT_MISC_STATE emph() const;
202 FONT_MISC_STATE underbar() const;
205 FONT_MISC_STATE noun() const;
208 FONT_MISC_STATE latex() const;
211 LColor::color color() const;
214 Language const * language() const;
217 bool isRightToLeft() const;
220 bool isVisibleRightToLeft() const;
223 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
225 LyXFont & setSeries(LyXFont::FONT_SERIES s);
227 LyXFont & setShape(LyXFont::FONT_SHAPE s);
229 LyXFont & setSize(LyXFont::FONT_SIZE s);
231 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
233 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
235 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
237 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
239 LyXFont & setColor(LColor::color c);
241 LyXFont & setLanguage(Language const * l);
243 /// Set family after LyX text format
244 LyXFont & setLyXFamily(string const &);
246 /// Set series after LyX text format
247 LyXFont & setLyXSeries(string const &);
249 /// Set shape after LyX text format
250 LyXFont & setLyXShape(string const &);
252 /// Set size after LyX text format
253 LyXFont & setLyXSize(string const &);
255 /// Returns misc flag after LyX text format
256 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
258 /// Sets color after LyX text format
259 LyXFont & setLyXColor(string const &);
261 /// Sets size after GUI name
262 LyXFont & setGUISize(string const &);
264 /// Returns size of font in LaTeX text notation
265 string latexSize() const;
267 /** Updates font settings according to request. If an
268 attribute is IGNORE, the attribute is left as it is. */
270 * When toggleall = true, all properties that matches the font in use
271 * will have the effect that the properties is reset to the
272 * default. If we have a text that is TYPEWRITER_FAMILY, and is
273 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
274 * a INHERIT_FAMILY was asked for. This is necessary for the
275 * toggle-user-defined-style button on the toolbar.
277 void update(LyXFont const & newfont,
278 Language const * default_lang,
279 bool toggleall = false);
281 /** Reduce font to fall back to template where possible.
282 Equal fields are reduced to INHERIT */
283 void reduce(LyXFont const & tmplt);
285 /// Realize font from a template (INHERIT are realized)
286 LyXFont & realize(LyXFont const & tmplt);
288 /// Is a given font fully resolved?
289 bool resolved() const;
291 /// Read a font specification from LyXLex. Used for layout files.
292 LyXFont & lyxRead(LyXLex &);
294 /// Writes the changes from this font to orgfont in .lyx format in file
295 void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
297 /** Writes the head of the LaTeX needed to change to this font.
298 Writes to string, the head of the LaTeX needed to change
299 to this font. Returns number of chars written. Base is the
300 font state active now.
302 int latexWriteStartChanges(ostream &, LyXFont const & base,
303 LyXFont const & prev) const;
305 /** Writes tha tail of the LaTeX needed to chagne to this font.
306 Returns number of chars written. Base is the font state we want
309 int latexWriteEndChanges(ostream &, LyXFont const & base,
310 LyXFont const & next) const;
312 /// Build GUI description of font state
313 string stateText() const;
316 int maxAscent() const;
319 int maxDescent() const;
322 int ascent(char c) const;
325 int descent(char c) const;
328 int width(char c) const;
331 int lbearing(char c) const;
334 int rbearing(char c) const;
337 int textWidth(char const *s, int n) const;
340 int stringWidth(string const & s) const;
343 int signedStringWidth(string const & s) const;
345 /// Draws text and returns width of text
346 int drawText(char const *, int n, Pixmap, int baseline, int x) const;
349 int drawString(string const &, Pixmap pm, int baseline, int x) const;
352 LColor::color realColor() const;
355 XID getFontID() const {
356 return getXFontstruct()->fid;
361 bool operator==(LyXFont const & font1, LyXFont const & font2) {
362 return font1.bits == font2.bits &&
363 font1.lang == font2.lang;
368 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
369 return font1.bits != font2.bits ||
370 font1.lang != font2.lang;
373 /// compares two fonts, ignoring the setting of the Latex part.
374 bool equalExceptLatex(LyXFont const &) const;
379 bool operator==(FontBits const & fb1) const {
380 return fb1.family == family &&
381 fb1.series == series &&
382 fb1.shape == shape &&
384 fb1.color == color &&
386 fb1.underbar == underbar &&
390 bool operator!=(FontBits const & fb1) const {
391 return !(fb1 == *this);
399 FONT_MISC_STATE emph;
400 FONT_MISC_STATE underbar;
401 FONT_MISC_STATE noun;
402 FONT_MISC_STATE latex;
406 Language const * lang;
409 static FontBits sane;
412 static FontBits inherit;
415 static FontBits ignore;
417 /// Updates a misc setting according to request
418 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
419 LyXFont::FONT_MISC_STATE org);
421 /// Converts logical attributes to concrete shape attribute
422 LyXFont::FONT_SHAPE realShape() const;
425 XFontStruct * getXFontstruct() const;
428 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
434 lang = default_language;
439 LyXFont::LyXFont(LyXFont const & x)
447 LyXFont::LyXFont(LyXFont::FONT_INIT1)
450 lang = default_language;
455 LyXFont::LyXFont(LyXFont::FONT_INIT2)
458 lang = ignore_language;
463 LyXFont::LyXFont(LyXFont::FONT_INIT3)
466 lang = default_language;
469 LyXFont::LyXFont(LyXFont::FONT_INIT1, Language const * l)
477 LyXFont::LyXFont(LyXFont::FONT_INIT2, Language const * l)
485 LyXFont::LyXFont(LyXFont::FONT_INIT3, Language const * l)
492 LyXFont & LyXFont::operator=(LyXFont const & x)
501 LyXFont::FONT_FAMILY LyXFont::family() const
508 LyXFont::FONT_SERIES LyXFont::series() const
515 LyXFont::FONT_SHAPE LyXFont::shape() const
522 LyXFont::FONT_SIZE LyXFont::size() const
529 LyXFont::FONT_MISC_STATE LyXFont::emph() const
536 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
538 return bits.underbar;
543 LyXFont::FONT_MISC_STATE LyXFont::noun() const
550 LyXFont::FONT_MISC_STATE LyXFont::latex() const
557 LColor::color LyXFont::color() const
564 Language const * LyXFont::language() const
571 bool LyXFont::isRightToLeft() const
573 return lang->RightToLeft;
578 bool LyXFont::isVisibleRightToLeft() const
580 return (lang->RightToLeft && latex() != ON);
585 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
593 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
601 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
609 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
617 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
625 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
633 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
640 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
648 LyXFont & LyXFont::setColor(LColor::color c)
656 LyXFont & LyXFont::setLanguage(Language const * l)