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
38 #define USE_OSTREAM_ONLY 1
45 /** The value INHERIT_* means that the font attribute is
46 inherited from the layout. In the case of layout fonts, the
47 attribute is inherited from the default font.
48 The value IGNORE_* is used with LyXFont::update() when the
49 attribute should not be changed.
53 ROMAN_FAMILY, // fontstruct rely on this to be 0
69 MEDIUM_SERIES, // fontstruct rely on this to be 0
81 UP_SHAPE, // fontstruct rely on this to be 0
97 SIZE_TINY, // fontstruct rely on this to be 0
126 enum FONT_DIRECTION {
139 /// Used for emph, underbar, noun and latex toggles
140 enum FONT_MISC_STATE {
153 /// Trick to overload constructor and make it megafast
172 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
173 LyXFont(LyXFont const & x);
175 /// Shortcut initialization
176 LyXFont(LyXFont::FONT_INIT1);
177 /// Shortcut initialization
178 LyXFont(LyXFont::FONT_INIT2);
179 /// Shortcut initialization
180 LyXFont(LyXFont::FONT_INIT3);
182 /// LyXFont x, y; x = y;
183 LyXFont & operator=(LyXFont const & x);
185 /// Decreases font size by one
188 /// Increases font size by one
192 FONT_FAMILY family() const;
195 FONT_SERIES series() const;
198 FONT_SHAPE shape() const;
201 FONT_SIZE size() const;
204 FONT_MISC_STATE emph() const;
207 FONT_MISC_STATE underbar() const;
210 FONT_MISC_STATE noun() const;
213 FONT_MISC_STATE latex() const;
216 LColor::color color() const;
219 FONT_DIRECTION direction() const;
222 LyXDirection getFontDirection() const;
225 LyXFont & setFamily(LyXFont::FONT_FAMILY f);
227 LyXFont & setSeries(LyXFont::FONT_SERIES s);
229 LyXFont & setShape(LyXFont::FONT_SHAPE s);
231 LyXFont & setSize(LyXFont::FONT_SIZE s);
233 LyXFont & setEmph(LyXFont::FONT_MISC_STATE e);
235 LyXFont & setUnderbar(LyXFont::FONT_MISC_STATE u);
237 LyXFont & setNoun(LyXFont::FONT_MISC_STATE n);
239 LyXFont & setLatex(LyXFont::FONT_MISC_STATE l);
241 LyXFont & setColor(LColor::color c);
243 LyXFont & setDirection(LyXFont::FONT_DIRECTION d);
245 /// Set family after LyX text format
246 LyXFont & setLyXFamily(string const &);
248 /// Set series after LyX text format
249 LyXFont & setLyXSeries(string const &);
251 /// Set shape after LyX text format
252 LyXFont & setLyXShape(string const &);
254 /// Set size after LyX text format
255 LyXFont & setLyXSize(string const &);
257 /// Returns misc flag after LyX text format
258 LyXFont::FONT_MISC_STATE setLyXMisc(string const &);
260 /// Sets color after LyX text format
261 LyXFont & setLyXColor(string const &);
263 /// Sets size after GUI name
264 LyXFont & setGUISize(string const &);
266 /// Returns size of font in LaTeX text notation
267 string latexSize() const;
269 /** Updates font settings according to request. If an
270 attribute is IGNORE, the attribute is left as it is. */
272 * When toggleall = true, all properties that matches the font in use
273 * will have the effect that the properties is reset to the
274 * default. If we have a text that is TYPEWRITER_FAMILY, and is
275 * update()'ed with TYPEWRITER_FAMILY, the operation will be as if
276 * a INHERIT_FAMILY was asked for. This is necessary for the
277 * toggle-user-defined-style button on the toolbar.
279 void update(LyXFont const & newfont, 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;
298 #ifdef USE_OSTREAM_ONLY
299 /** Writes the head of the LaTeX needed to change to this font.
300 Writes to string, the head of the LaTeX needed to change
301 to this font. Returns number of chars written. Base is the
302 font state active now.
304 int latexWriteStartChanges(ostream &, LyXFont const & base,
305 LyXFont const & prev) const;
306 /** Writes tha tail of the LaTeX needed to chagne to this font.
307 Returns number of chars written. Base is the font state we want
310 int latexWriteEndChanges(ostream &, LyXFont const & base,
311 LyXFont const & next) const;
313 /** Writes the head of the LaTeX needed to change to this font.
314 Writes to string, the head of the LaTeX needed to change
315 to this font. Returns number of chars written. Base is the
316 font state active now.
318 int latexWriteStartChanges(string &, LyXFont const & base,
319 LyXFont const & prev) const;
320 /** Writes tha tail of the LaTeX needed to chagne to this font.
321 Returns number of chars written. Base is the font state we want
324 int latexWriteEndChanges(string &, LyXFont const & base,
325 LyXFont const & next) const;
327 /// Build GUI description of font state
328 string stateText() const;
331 int maxAscent() const;
334 int maxDescent() const;
337 int ascent(char c) const;
340 int descent(char c) const;
343 int width(char c) const;
346 int lbearing(char c) const;
349 int rbearing(char c) const;
352 int textWidth(char const *s, int n) const;
355 int stringWidth(string const & s) const;
358 int signedStringWidth(string const & s) const;
360 /// Draws text and returns width of text
361 int drawText(char const *, int n, Pixmap, int baseline, int x) const;
364 int drawString(string const &, Pixmap pm, int baseline, int x) const;
367 LColor::color realColor() const;
370 XID getFontID() const {
371 return getXFontstruct()->fid;
376 bool operator==(LyXFont const & font1, LyXFont const & font2) {
377 return font1.bits == font2.bits;
382 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
383 return font1.bits != font2.bits;
386 /// compares two fonts, ignoring the setting of the Latex part.
387 bool equalExceptLatex(LyXFont const &) const;
392 bool operator==(FontBits const & fb1) const {
393 return fb1.family == family &&
394 fb1.series == series &&
395 fb1.shape == shape &&
397 fb1.color == color &&
399 fb1.underbar == underbar &&
401 fb1.latex == latex &&
402 fb1.direction == direction;
404 bool operator!=(FontBits const & fb1) const {
405 return !(fb1 == *this);
413 FONT_MISC_STATE emph;
414 FONT_MISC_STATE underbar;
415 FONT_MISC_STATE noun;
416 FONT_MISC_STATE latex;
417 FONT_DIRECTION direction;
423 static FontBits sane;
426 static FontBits inherit;
429 static FontBits ignore;
431 /// Updates a misc setting according to request
432 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
433 LyXFont::FONT_MISC_STATE org);
435 /// Converts logical attributes to concrete shape attribute
436 LyXFont::FONT_SHAPE realShape() const;
439 XFontStruct * getXFontstruct() const;
442 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
452 LyXFont::LyXFont(LyXFont const & x)
459 LyXFont::LyXFont(LyXFont::FONT_INIT1)
466 LyXFont::LyXFont(LyXFont::FONT_INIT2)
473 LyXFont::LyXFont(LyXFont::FONT_INIT3)
480 LyXFont & LyXFont::operator=(LyXFont const & x)
488 LyXFont::FONT_FAMILY LyXFont::family() const
495 LyXFont::FONT_SERIES LyXFont::series() const
502 LyXFont::FONT_SHAPE LyXFont::shape() const
509 LyXFont::FONT_SIZE LyXFont::size() const
516 LyXFont::FONT_MISC_STATE LyXFont::emph() const
523 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
525 return bits.underbar;
530 LyXFont::FONT_MISC_STATE LyXFont::noun() const
537 LyXFont::FONT_MISC_STATE LyXFont::latex() const
544 LColor::color LyXFont::color() const
551 LyXFont::FONT_DIRECTION LyXFont::direction() const
553 return bits.direction;
557 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
565 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
573 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
581 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
589 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
597 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
605 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
612 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
620 LyXFont & LyXFont::setColor(LColor::color c)
628 LyXFont & LyXFont::setDirection(LyXFont::FONT_DIRECTION d)