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 * ====================================================== */
19 #include FORMS_H_LOCATION
22 #include "direction.h"
25 // It might happen that locale.h defines ON and OFF. This is not good
26 // for us, since we use these names below. But of course this is due
27 // to some old compilers. Than is broken when it comes to C++ scoping.
28 #include "gettext.h" // so that we are sure tht it won't be included
44 /** The value INHERIT_* means that the font attribute is
45 inherited from the layout. In the case of layout fonts, the
46 attribute is inherited from the default font.
47 The value IGNORE_* is used with LyXFont::update() when the
48 attribute should not be changed.
52 ROMAN_FAMILY, // fontstruct rely on this to be 0
68 MEDIUM_SERIES, // fontstruct rely on this to be 0
80 UP_SHAPE, // fontstruct rely on this to be 0
96 SIZE_TINY, // fontstruct rely on this to be 0
125 enum FONT_DIRECTION {
138 /// Used for emph, underbar, noun and latex toggles
139 enum FONT_MISC_STATE {
152 /// Trick to overload constructor and make it megafast
171 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
172 LyXFont(LyXFont const & x);
174 /// Shortcut initialization
175 LyXFont(LyXFont::FONT_INIT1);
176 /// Shortcut initialization
177 LyXFont(LyXFont::FONT_INIT2);
178 /// Shortcut initialization
179 LyXFont(LyXFont::FONT_INIT3);
181 /// LyXFont x, y; x = y;
182 LyXFont & operator=(LyXFont const & x);
184 /// Decreases font size by one
187 /// Increases font size by one
191 FONT_FAMILY family() const;
194 FONT_SERIES series() const;
197 FONT_SHAPE shape() const;
200 FONT_SIZE size() const;
203 FONT_MISC_STATE emph() const;
206 FONT_MISC_STATE underbar() const;
209 FONT_MISC_STATE noun() const;
212 FONT_MISC_STATE latex() const;
215 LColor::color color() const;
218 FONT_DIRECTION direction() const;
221 LyXDirection getFontDirection() const;
224 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
226 LyXFont & setSeries(LyXFont::FONT_SERIES s);
228 LyXFont & setShape(LyXFont::FONT_SHAPE s);
230 LyXFont & setSize(LyXFont::FONT_SIZE s);
232 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
234 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
236 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
238 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
240 LyXFont & setColor(LColor::color c);
242 LyXFont & setDirection(LyXFont::FONT_DIRECTION d);
244 /// Set family after LyX text format
245 LyXFont & setLyXFamily(string const &);
247 /// Set series after LyX text format
248 LyXFont & setLyXSeries(string const &);
250 /// Set shape after LyX text format
251 LyXFont & setLyXShape(string const &);
253 /// Set size after LyX text format
254 LyXFont & setLyXSize(string const &);
256 /// Returns misc flag after LyX text format
257 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
259 /// Sets color after LyX text format
260 LyXFont & setLyXColor(string const &);
262 /// Sets size after GUI name
263 LyXFont & setGUISize(string const &);
265 /// Returns size of font in LaTeX text notation
266 string latexSize() const;
268 /** Updates font settings according to request. If an
269 attribute is IGNORE, the attribute is left as it is. */
271 * When toggleall = true, all properties that matches the font in use
272 * will have the effect that the properties is reset to the
273 * default. If we have a text that is TYPEWRITER_FAMILY, and is
274 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
275 * a INHERIT_FAMILY was asked for. This is necessary for the
276 * toggle-user-defined-style button on the toolbar.
278 void update(LyXFont const & newfont, bool toggleall = false);
280 /** Reduce font to fall back to template where possible.
281 Equal fields are reduced to INHERIT */
282 void reduce(LyXFont const & tmplt);
284 /// Realize font from a template (INHERIT are realized)
285 LyXFont & realize(LyXFont const & tmplt);
287 /// Is a given font fully resolved?
288 bool resolved() const;
290 /// Read a font specification from LyXLex. Used for layout files.
291 LyXFont & lyxRead(LyXLex &);
293 /// Writes the changes from this font to orgfont in .lyx format in file
294 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;
304 /** Writes tha tail of the LaTeX needed to chagne to this font.
305 Returns number of chars written. Base is the font state we want
308 int latexWriteEndChanges(ostream &, LyXFont const & base,
309 LyXFont const & next) const;
311 /// Build GUI description of font state
312 string stateText() const;
315 int maxAscent() const;
318 int maxDescent() const;
321 int ascent(char c) const;
324 int descent(char c) const;
327 int width(char c) const;
330 int lbearing(char c) const;
333 int rbearing(char c) const;
336 int textWidth(char const *s, int n) const;
339 int stringWidth(string const & s) const;
342 int signedStringWidth(string const & s) const;
344 /// Draws text and returns width of text
345 int drawText(char const *, int n, Pixmap, int baseline, int x) const;
348 int drawString(string const &, Pixmap pm, int baseline, int x) const;
351 LColor::color realColor() const;
354 XID getFontID() const {
355 return getXFontstruct()->fid;
360 bool operator==(LyXFont const & font1, LyXFont const & font2) {
361 return font1.bits == font2.bits;
366 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
367 return font1.bits != font2.bits;
370 /// compares two fonts, ignoring the setting of the Latex part.
371 bool equalExceptLatex(LyXFont const &) const;
376 bool operator==(FontBits const & fb1) const {
377 return fb1.family == family &&
378 fb1.series == series &&
379 fb1.shape == shape &&
381 fb1.color == color &&
383 fb1.underbar == underbar &&
385 fb1.latex == latex &&
386 fb1.direction == direction;
388 bool operator!=(FontBits const & fb1) const {
389 return !(fb1 == *this);
397 FONT_MISC_STATE emph;
398 FONT_MISC_STATE underbar;
399 FONT_MISC_STATE noun;
400 FONT_MISC_STATE latex;
401 FONT_DIRECTION direction;
407 static FontBits sane;
410 static FontBits inherit;
413 static FontBits ignore;
415 /// Updates a misc setting according to request
416 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
417 LyXFont::FONT_MISC_STATE org);
419 /// Converts logical attributes to concrete shape attribute
420 LyXFont::FONT_SHAPE realShape() const;
423 XFontStruct * getXFontstruct() const;
426 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
436 LyXFont::LyXFont(LyXFont const & x)
443 LyXFont::LyXFont(LyXFont::FONT_INIT1)
450 LyXFont::LyXFont(LyXFont::FONT_INIT2)
457 LyXFont::LyXFont(LyXFont::FONT_INIT3)
464 LyXFont & LyXFont::operator=(LyXFont const & x)
472 LyXFont::FONT_FAMILY LyXFont::family() const
479 LyXFont::FONT_SERIES LyXFont::series() const
486 LyXFont::FONT_SHAPE LyXFont::shape() const
493 LyXFont::FONT_SIZE LyXFont::size() const
500 LyXFont::FONT_MISC_STATE LyXFont::emph() const
507 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
509 return bits.underbar;
514 LyXFont::FONT_MISC_STATE LyXFont::noun() const
521 LyXFont::FONT_MISC_STATE LyXFont::latex() const
528 LColor::color LyXFont::color() const
535 LyXFont::FONT_DIRECTION LyXFont::direction() const
537 return bits.direction;
541 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
549 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
557 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
565 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
573 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
581 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
589 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
596 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
604 LyXFont & LyXFont::setColor(LColor::color c)
612 LyXFont & LyXFont::setDirection(LyXFont::FONT_DIRECTION d)