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
43 /** The value INHERIT_* means that the font attribute is
44 inherited from the layout. In the case of layout fonts, the
45 attribute is inherited from the default font.
46 The value IGNORE_* is used with LyXFont::update() when the
47 attribute should not be changed.
51 ROMAN_FAMILY, // fontstruct rely on this to be 0
67 MEDIUM_SERIES, // fontstruct rely on this to be 0
79 UP_SHAPE, // fontstruct rely on this to be 0
95 SIZE_TINY, // fontstruct rely on this to be 0
124 enum FONT_DIRECTION {
137 /// Used for emph, underbar, noun and latex toggles
138 enum FONT_MISC_STATE {
151 /// Trick to overload constructor and make it megafast
170 /// LyXFont x(LyXFont ...) and LyXFont x = LyXFont ...
171 LyXFont(LyXFont const & x);
173 /// Shortcut initialization
174 LyXFont(LyXFont::FONT_INIT1);
175 /// Shortcut initialization
176 LyXFont(LyXFont::FONT_INIT2);
177 /// Shortcut initialization
178 LyXFont(LyXFont::FONT_INIT3);
180 /// LyXFont x, y; x = y;
181 LyXFont & operator=(LyXFont const & x);
183 /// Decreases font size by one
186 /// Increases font size by one
190 FONT_FAMILY family() const;
193 FONT_SERIES series() const;
196 FONT_SHAPE shape() const;
199 FONT_SIZE size() const;
202 FONT_MISC_STATE emph() const;
205 FONT_MISC_STATE underbar() const;
208 FONT_MISC_STATE noun() const;
211 FONT_MISC_STATE latex() const;
214 LColor::color color() const;
217 FONT_DIRECTION direction() const;
220 LyXDirection getFontDirection() 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 & setDirection(LyXFont::FONT_DIRECTION d);
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, bool toggleall = false);
279 /** Reduce font to fall back to template where possible.
280 Equal fields are reduced to INHERIT */
281 void reduce(LyXFont const & tmplt);
283 /// Realize font from a template (INHERIT are realized)
284 LyXFont & realize(LyXFont const & tmplt);
286 /// Is a given font fully resolved?
287 bool resolved() const;
289 /// Read a font specification from LyXLex. Used for layout files.
290 LyXFont & lyxRead(LyXLex &);
292 /// Writes the changes from this font to orgfont in .lyx format in file
293 void lyxWriteChanges(LyXFont const & orgfont, ostream &) const;
295 /** Writes the head of the LaTeX needed to change to this font.
296 Writes to string, the head of the LaTeX needed to change
297 to this font. Returns number of chars written. Base is the
298 font state active now.
300 int latexWriteStartChanges(string &, LyXFont const & base,
301 LyXFont const & prev) const;
303 /** Writes tha tail of the LaTeX needed to chagne to this font.
304 Returns number of chars written. Base is the font state we want
307 int latexWriteEndChanges(string &, LyXFont const & base,
308 LyXFont const & next) const;
310 /// Build GUI description of font state
311 string stateText() const;
314 int maxAscent() const;
317 int maxDescent() const;
320 int ascent(char c) const;
323 int descent(char c) const;
326 int width(char c) const;
329 int lbearing(char c) const;
332 int rbearing(char c) const;
335 int textWidth(char const *s, int n) const;
338 int stringWidth(string const & s) const;
341 int signedStringWidth(string const & s) const;
343 /// Draws text and returns width of text
344 int drawText(char const *, int n, Pixmap, int baseline, int x) const;
347 int drawString(string const &, Pixmap pm, int baseline, int x) const;
350 LColor::color realColor() const;
353 XID getFontID() const {
354 return getXFontstruct()->fid;
359 bool operator==(LyXFont const & font1, LyXFont const & font2) {
360 return font1.bits == font2.bits;
365 bool operator!=(LyXFont const & font1, LyXFont const & font2) {
366 return font1.bits != font2.bits;
369 /// compares two fonts, ignoring the setting of the Latex part.
370 bool equalExceptLatex(LyXFont const &) const;
375 bool operator==(FontBits const & fb1) const {
376 return fb1.family == family &&
377 fb1.series == series &&
378 fb1.shape == shape &&
380 fb1.color == color &&
382 fb1.underbar == underbar &&
384 fb1.latex == latex &&
385 fb1.direction == direction;
387 bool operator!=(FontBits const & fb1) const {
388 return !(fb1 == *this);
396 FONT_MISC_STATE emph;
397 FONT_MISC_STATE underbar;
398 FONT_MISC_STATE noun;
399 FONT_MISC_STATE latex;
400 FONT_DIRECTION direction;
406 static FontBits sane;
409 static FontBits inherit;
412 static FontBits ignore;
414 /// Updates a misc setting according to request
415 LyXFont::FONT_MISC_STATE setMisc(LyXFont::FONT_MISC_STATE newfont,
416 LyXFont::FONT_MISC_STATE org);
418 /// Converts logical attributes to concrete shape attribute
419 LyXFont::FONT_SHAPE realShape() const;
422 XFontStruct * getXFontstruct() const;
425 ostream & operator<<(ostream &, LyXFont::FONT_MISC_STATE);
427 inline LyXFont::LyXFont()
433 inline LyXFont::LyXFont(LyXFont const & x)
439 inline LyXFont::LyXFont(LyXFont::FONT_INIT1)
445 inline LyXFont::LyXFont(LyXFont::FONT_INIT2)
451 inline LyXFont::LyXFont(LyXFont::FONT_INIT3)
457 inline LyXFont & LyXFont::operator=(LyXFont const & x)
465 LyXFont::FONT_FAMILY LyXFont::family() const
472 LyXFont::FONT_SERIES LyXFont::series() const
479 LyXFont::FONT_SHAPE LyXFont::shape() const
486 LyXFont::FONT_SIZE LyXFont::size() const
493 LyXFont::FONT_MISC_STATE LyXFont::emph() const
500 LyXFont::FONT_MISC_STATE LyXFont::underbar() const
502 return bits.underbar;
507 LyXFont::FONT_MISC_STATE LyXFont::noun() const
514 LyXFont::FONT_MISC_STATE LyXFont::latex() const
521 LColor::color LyXFont::color() const
528 LyXFont::FONT_DIRECTION LyXFont::direction() const
530 return bits.direction;
534 LyXFont & LyXFont::setFamily(LyXFont::FONT_FAMILY f)
542 LyXFont & LyXFont::setSeries(LyXFont::FONT_SERIES s)
550 LyXFont & LyXFont::setShape(LyXFont::FONT_SHAPE s)
558 LyXFont & LyXFont::setSize(LyXFont::FONT_SIZE s)
566 LyXFont & LyXFont::setEmph(LyXFont::FONT_MISC_STATE e)
574 LyXFont & LyXFont::setUnderbar(LyXFont::FONT_MISC_STATE u)
582 LyXFont & LyXFont::setNoun(LyXFont::FONT_MISC_STATE n)
589 LyXFont & LyXFont::setLatex(LyXFont::FONT_MISC_STATE l)
597 LyXFont & LyXFont::setColor(LColor::color c)
605 LyXFont & LyXFont::setDirection(LyXFont::FONT_DIRECTION d)