Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXFont.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * F o n t O b j e c t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXFont.h,v 1.66 2006/01/22 17:58:02 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXFONT_H
25 #define FXFONT_H
26 
27 #ifndef FXID_H
28 #include "FXId.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// Font character set encoding
35 enum FXFontEncoding {
36  FONTENCODING_DEFAULT, /// Don't care character encoding
37 
38  FONTENCODING_ISO_8859_1 = 1, /// West European (Latin1)
39  FONTENCODING_ISO_8859_2 = 2, /// Central and East European (Latin2)
40  FONTENCODING_ISO_8859_3 = 3, /// Esperanto (Latin3)
42  FONTENCODING_ISO_8859_5 = 5, /// Cyrillic (almost obsolete)
43  FONTENCODING_ISO_8859_6 = 6, /// Arabic
44  FONTENCODING_ISO_8859_7 = 7, /// Greek
45  FONTENCODING_ISO_8859_8 = 8, /// Hebrew
46  FONTENCODING_ISO_8859_9 = 9, /// Turkish (Latin5)
48  FONTENCODING_ISO_8859_11 = 11, /// Thai
49  FONTENCODING_ISO_8859_13 = 13, /// Baltic
54  FONTENCODING_KOI8_R = 18, /// Russian
55  FONTENCODING_KOI8_U = 19, /// Ukrainian
57 
58  FONTENCODING_CP437 = 437, /// IBM-PC code page
59  FONTENCODING_CP850 = 850, /// IBMPC Multilingual
60  FONTENCODING_CP851 = 851, /// IBM-PC Greek
61  FONTENCODING_CP852 = 852, /// IBM-PC Latin2
62  FONTENCODING_CP855 = 855, /// IBM-PC Cyrillic
63  FONTENCODING_CP856 = 856, /// IBM-PC Hebrew
64  FONTENCODING_CP857 = 857, /// IBM-PC Turkish
65  FONTENCODING_CP860 = 860, /// IBM-PC Portugese
66  FONTENCODING_CP861 = 861, /// IBM-PC Iceland
67  FONTENCODING_CP862 = 862, /// IBM-PC Israel
68  FONTENCODING_CP863 = 863, /// IBM-PC Canadian/French
69  FONTENCODING_CP864 = 864, /// IBM-PC Arabic
70  FONTENCODING_CP865 = 865, /// IBM-PC Nordic
71  FONTENCODING_CP866 = 866, /// IBM-PC Cyrillic #2
72  FONTENCODING_CP869 = 869, /// IBM-PC Greek #2
73  FONTENCODING_CP870 = 870, /// Latin-2 Multilingual
74 
75  FONTENCODING_CP1250 = 1250, /// Windows Central European
76  FONTENCODING_CP1251 = 1251, /// Windows Russian
77  FONTENCODING_CP1252 = 1252, /// Windows Latin1
78  FONTENCODING_CP1253 = 1253, /// Windows Greek
79  FONTENCODING_CP1254 = 1254, /// Windows Turkish
80  FONTENCODING_CP1255 = 1255, /// Windows Hebrew
81  FONTENCODING_CP1256 = 1256, /// Windows Arabic
82  FONTENCODING_CP1257 = 1257, /// Windows Baltic
83  FONTENCODING_CP1258 = 1258, /// Windows Vietnam
84  FONTENCODING_CP874 = 874, /// Windows Thai
85 
87 
88  FONTENCODING_LATIN1 = FONTENCODING_ISO_8859_1, /// Latin 1 (West European)
89  FONTENCODING_LATIN2 = FONTENCODING_ISO_8859_2, /// Latin 2 (East European)
90  FONTENCODING_LATIN3 = FONTENCODING_ISO_8859_3, /// Latin 3 (South European)
91  FONTENCODING_LATIN4 = FONTENCODING_ISO_8859_4, /// Latin 4 (North European)
94  FONTENCODING_LATIN7 = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim)
96  FONTENCODING_LATIN9 = FONTENCODING_ISO_8859_15, /// Latin 9 AKA Latin 0
98 
100  FONTENCODING_WESTEUROPE = FONTENCODING_ISO_8859_1, /// Latin 1 (West European)
101  FONTENCODING_EASTEUROPE = FONTENCODING_ISO_8859_2, /// Latin 2 (East European)
102  FONTENCODING_SOUTHEUROPE = FONTENCODING_ISO_8859_3, /// Latin 3 (South European)
103  FONTENCODING_NORTHEUROPE = FONTENCODING_ISO_8859_4, /// Latin 4 (North European)
112  FONTENCODING_BALTIC = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim)
114  };
117 /// Font style
118 struct FXFontDesc {
119  FXchar face[116]; /// Face name
120  FXushort size; /// Size in deci-points
121  FXushort weight; /// Weight [light, normal, bold, ...]
122  FXushort slant; /// Slant [normal, italic, oblique, ...]
123  FXushort setwidth; /// Set width [normal, condensed, expanded, ...]
124  FXushort encoding; /// Encoding of character set
125  FXushort flags; /// Flags
126  };
129 class FXDC;
130 class FXDCWindow;
131 
132 
133 /// Font class
134 class FXAPI FXFont : public FXId {
135  friend class FXDCWindow;
137 protected:
138  FXString wantedName; // Desired font font name
139  FXString actualName; // Matched font font name
140  FXushort wantedSize; // Font size (points*10)
141  FXushort actualSize; // Actual size that was matched
142  FXushort wantedWeight; // Font weight
143  FXushort actualWeight; // Font weight
144  FXushort wantedSlant; // Font slant
145  FXushort actualSlant; // Font slant
146  FXushort wantedSetwidth; // Relative setwidth
147  FXushort actualSetwidth; // Relative setwidth
148  FXushort wantedEncoding; // Character set encoding
149  FXushort actualEncoding; // Character set encoding
150  FXushort hints; // Matching hint flags
151  FXushort flags; // Actual flags
152  FXshort angle; // Angle
153  void *font; // Info about the font
154 private:
155 #ifdef WIN32
156  FXID dc;
157 #endif
158 protected:
160  void* match(const FXString& wantfamily,const FXString& wantforge,FXuint wantsize,FXuint wantweight,FXuint wantslant,FXuint wantsetwidth,FXuint wantencoding,FXuint wanthints,FXint res);
161 private:
162  FXFont(const FXFont&);
163  FXFont &operator=(const FXFont&);
164 public:
165 
166  /// Font pitch hints
167  enum {
168  Fixed = 1, /// Fixed pitch, mono-spaced
169  Variable = 2 /// Variable pitch, proportional spacing
170  };
172  /// Font style hints
173  enum {
174  Decorative = 4, /// Fancy fonts
175  Modern = 8, /// Monospace typewriter font
176  Roman = 16, /// Variable width times-like font, serif
177  Script = 32, /// Script or cursive
178  Swiss = 64, /// Helvetica/swiss type font, sans-serif
179  System = 128, /// System font
180  X11 = 256, /// Raw X11 font string
181  Scalable = 512, /// Scalable fonts
182  Polymorphic = 1024, /// Polymorphic fonts, e.g. parametric weight, slant, etc.
183  Rotatable = 2048 /// Rotatable fonts
184  };
186  /// Font slant options
187  enum {
188  ReverseOblique = 1, /// Reversed oblique
189  ReverseItalic = 2, /// Reversed italic
190  Straight = 5, /// Straight, not slanted
191  Italic = 8, /// Italics
192  Oblique = 9 /// Oblique slant
193  };
195  /// Font weight options
196  enum {
197  Thin = 10, /// Thin
198  ExtraLight = 20, /// Extra light
199  Light = 30, /// Light
200  Normal = 40, /// Normal or regular weight
201  Medium = 50, /// Medium bold face
202  DemiBold = 60, /// Demi bold face
203  Bold = 70, /// Bold face
204  ExtraBold = 80, /// Extra
205  Black = 90 /// Black
206  };
207 
208  /// Condensed or expanded options
209  enum {
210  UltraCondensed = 50, /// Ultra condensed printing
211  ExtraCondensed = 63, /// Extra condensed
212  Condensed = 75, /// Condensed
213  SemiCondensed = 87, /// Semi-condensed
214  NonExpanded = 100, /// Regular printing
215  SemiExpanded = 113, /// Semi expanded
216  Expanded = 125, /// Expanded
217  ExtraExpanded = 150, /// Extra expanded
218  UltraExpanded = 200 /// Ultra expanded
219  };
220 
221 public:
222 
223  /**
224  * Construct a font with given font description of the form:
225  *
226  * fontname [ "[" foundry "]" ] ["," size ["," weight ["," slant ["," setwidth ["," encoding ["," hints]]]]]]
227  *
228  * For example:
229  *
230  * "helvetica [bitstream],120,bold,italic,normal,iso8859-1,0"
231  *
232  * Typically, at least the font name, and size must be given for
233  * normal font matching. As a special case, raw X11 fonts can also be
234  * passed, for example:
235  *
236  * "9x15bold"
237  *
238  * Note: use of the raw X11 fonts is stronly discouraged.
239  */
240  FXFont(FXApp* a,const FXString& string);
241 
242  /**
243  * Construct a font with given name, size in points, weight, slant, character set
244  * encoding, setwidth, and hints.
245  * The font name may be comprised of a family name and optional foundry name enclosed in
246  * square brackets, for example, "helvetica [bitstream]".
247  */
248  FXFont(FXApp* a,const FXString& face,FXuint size,FXuint weight=FXFont::Normal,FXuint slant=FXFont::Straight,FXuint encoding=FONTENCODING_DEFAULT,FXuint setwidth=FXFont::NonExpanded,FXuint h=0);
249 
250  /// Construct font from font description
251  FXFont(FXApp* a,const FXFontDesc& fontdesc);
252 
253  /// Create the font
254  virtual void create();
255 
256  /// Detach the font
257  virtual void detach();
258 
259  /// Destroy the font
260  virtual void destroy();
261 
262  /// Return family part of name
263  FXString getFamily() const;
264 
265  /// Return foundry part of name
266  FXString getFoundry() const;
267 
268  /// Get font family name
269  const FXString& getName() const { return wantedName; }
270 
271  /// Get actual family name
272  const FXString& getActualName() const { return actualName; }
273 
274  /// Get size in deci-points
275  FXuint getSize() const { return wantedSize; }
276 
277  /// Get actual size in deci-points
278  FXuint getActualSize() const { return actualSize; }
279 
280  /// Get font weight
281  FXuint getWeight() const { return wantedWeight; }
282 
283  /// Get actual font weight
284  FXuint getActualWeight() const { return actualWeight; }
285 
286  /// Get slant
287  FXuint getSlant() const { return wantedSlant; }
288 
289  /// Get actual slant
290  FXuint getActualSlant() const { return actualSlant; }
291 
292  /// Get character set encoding
293  FXuint getEncoding() const { return wantedEncoding; }
294 
295  /// Get actual encoding
296  FXuint getActualEncoding() const { return actualEncoding; }
297 
298  /// Get setwidth
299  FXuint getSetWidth() const { return wantedSetwidth; }
300 
301  /// Get actual setwidth
302  FXuint getActualSetWidth() const { return actualSetwidth; }
303 
304  /// Get hints
305  FXuint getHints() const { return hints; }
306 
307  /// Get flags
308  FXuint getFlags() const { return flags; }
309 
310  /// Get font description
311  void getFontDesc(FXFontDesc& fontdesc) const;
312 
313  /// Change font description
314  virtual void setFontDesc(const FXFontDesc& fontdesc);
315 
316  /// Return angle
317  FXint getAngle() const { return angle; }
318 
319  /// Set to new angle, in degrees*64 relative to positive x axis
320  virtual void setAngle(FXint ang);
321 
322  /**
323  * Return the font description as a string suitable for
324  * parsing with setFont(), see above.
325  */
326  FXString getFont() const;
327 
328  /**
329  * Change the font to the specified font description string.
330  */
331  virtual void setFont(const FXString& string);
332 
333  /// Find out if the font is monotype or proportional
334  virtual FXbool isFontMono() const;
335 
336  /// See if font has glyph for ch
337  virtual FXbool hasChar(FXwchar ch) const;
338 
339  /// Get first character glyph in font
340  virtual FXwchar getMinChar() const;
341 
342  /// Get last character glyph in font
343  virtual FXwchar getMaxChar() const;
344 
345  /// Left bearing
346  virtual FXint leftBearing(FXwchar ch) const;
347 
348  /// Right bearing
349  virtual FXint rightBearing(FXwchar ch) const;
350 
351  /// Width of widest character in font
352  virtual FXint getFontWidth() const;
353 
354  /// Height of highest character in font
355  virtual FXint getFontHeight() const;
356 
357  /// Ascent from baseline
358  virtual FXint getFontAscent() const;
359 
360  /// Descent from baseline
361  virtual FXint getFontDescent() const;
362 
363  /// Get font leading [that is lead-ing as in Pb!]
364  virtual FXint getFontLeading() const;
365 
366  /// Get font line spacing
367  virtual FXint getFontSpacing() const;
368 
369  /// Calculate width of single wide character in this font
370  virtual FXint getCharWidth(const FXwchar ch) const;
371 
372  /// Calculate width of given text in this font
373  virtual FXint getTextWidth(const FXString& string) const;
374 
375  /// Calculate width of given text in this font
376  virtual FXint getTextWidth(const FXchar* string,FXuint length) const;
377 
378  /// Calculate height of given text in this font
379  virtual FXint getTextHeight(const FXString& string) const;
380 
381  /// Calculate height of given text in this font
382  virtual FXint getTextHeight(const FXchar *string,FXuint length) const;
383 
384  /**
385  * List all fonts matching hints. If listFonts() returns TRUE then
386  * fonts points to a newly-allocated array of length numfonts. It
387  * is the caller's responsibility to free this array using FXFREE().
388  */
389  static FXbool listFonts(FXFontDesc*& fonts,FXuint& numfonts,const FXString& face,FXuint wt=0,FXuint sl=0,FXuint sw=0,FXuint en=0,FXuint h=0);
390 
391  /// Save font data into stream
392  virtual void save(FXStream& store) const;
393 
394  /// Load font data from stream
395  virtual void load(FXStream& store);
396 
397  /// Destroy font
398  virtual ~FXFont();
399  };
400 
401 
402 }
403 
404 #endif
IBM-PC Latin2.
Definition: FXFont.h:64
Normal or regular weight.
Definition: FXFont.h:181
Esperanto (Latin3)
Definition: FXFont.h:43
unsigned long FXID
Definition: fxdefs.h:435
unsigned short FXushort
Definition: fxdefs.h:387
FXushort size
Face name.
Definition: FXFont.h:124
Windows Thai.
Definition: FXFont.h:87
Don't care character encoding.
Definition: FXFont.h:39
Straight, not slanted.
Definition: FXFont.h:171
Latin 5 (Turkish)
Definition: FXFont.h:112
char FXchar
Definition: fxdefs.h:380
Ukrainian.
Definition: FXFont.h:58
IBM-PC Greek.
Definition: FXFont.h:63
Windows Baltic.
Definition: FXFont.h:85
Greek.
Definition: FXFont.h:110
short FXshort
Definition: fxdefs.h:388
Cyrillic.
Definition: FXFont.h:107
West European (Latin1)
Definition: FXFont.h:41
Windows Turkish.
Definition: FXFont.h:82
unsigned int FXuint
Definition: fxdefs.h:389
Latin 3 (South European)
Definition: FXFont.h:105
Central and East European (Latin2)
Definition: FXFont.h:42
Greek.
Definition: FXFont.h:47
Hebrew.
Definition: FXFont.h:48
Latin 2 (East European)
Definition: FXFont.h:92
Definition: FXFont.h:89
Russian.
Definition: FXFont.h:57
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:386
Windows Arabic.
Definition: FXFont.h:84
Application Object.
Definition: FXApp.h:158
Thai.
Definition: FXFont.h:114
Definition: FXFont.h:50
Definition: FXFont.h:56
IBM-PC Iceland.
Definition: FXFont.h:69
Latin 6 (Nordic)
Definition: FXFont.h:113
IBMPC Multilingual.
Definition: FXFont.h:62
Latin 10.
Definition: FXFont.h:100
Definition: FXFont.h:59
IBM-PC Greek #2.
Definition: FXFont.h:75
Abstract Device Context.
Definition: FXDC.h:191
Windows Central European.
Definition: FXFont.h:78
Font style.
Definition: FXFont.h:122
Windows Hebrew.
Definition: FXFont.h:83
Latin-2 Multilingual.
Definition: FXFont.h:76
IBM-PC Portugese.
Definition: FXFont.h:68
bool match(const FXString &pattern, const FXString &file, FXuint flags=(FILEMATCH_NOESCAPE|FILEMATCH_FILE_NAME))
Perform wildcard match of a filename against a wildcard pattern.
Baltic.
Definition: FXFont.h:52
Turkish (Latin5)
Definition: FXFont.h:49
Encapsulates server side resource.
Definition: FXId.h:37
wchar_t FXwchar
Definition: fxdefs.h:404
FXushort flags
Encoding of character set.
Definition: FXFont.h:129
Definition: FXFont.h:54
Latin 7 (Baltic Rim)
Definition: FXFont.h:115
IBM-PC Cyrillic.
Definition: FXFont.h:65
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
Windows Russian.
Definition: FXFont.h:79
FXushort encoding
Set width [normal, condensed, expanded, ...].
Definition: FXFont.h:128
Definition: FXFont.h:55
IBM-PC Israel.
Definition: FXFont.h:70
Windows Latin1.
Definition: FXFont.h:80
Regular printing.
Definition: FXFont.h:195
IBM-PC Nordic.
Definition: FXFont.h:73
IBM-PC code page.
Definition: FXFont.h:61
Latin 5 (Turkish)
Definition: FXFont.h:95
Latin 6 (Nordic)
Definition: FXFont.h:96
FXushort setwidth
Slant [normal, italic, oblique, ...].
Definition: FXFont.h:127
Latin 1 (West European)
Definition: FXFont.h:91
IBM-PC Hebrew.
Definition: FXFont.h:66
Thai.
Definition: FXFont.h:51
IBM-PC Cyrillic #2.
Definition: FXFont.h:74
Windows Vietnam.
Definition: FXFont.h:86
IBM-PC Turkish.
Definition: FXFont.h:67
Latin 1 (West European)
Definition: FXFont.h:103
Definition: FXFont.h:53
Cyrillic (almost obsolete)
Definition: FXFont.h:45
IBM-PC Canadian/French.
Definition: FXFont.h:71
Latin 4 (North European)
Definition: FXFont.h:94
Latin 3 (South European)
Definition: FXFont.h:93
Window Device Context.
Definition: FXDCWindow.h:52
FXchar face[116]
Definition: FXFont.h:123
FXFontEncoding
Font character set encoding.
Definition: FXFont.h:38
IBM-PC Arabic.
Definition: FXFont.h:72
FXushort weight
Size in deci-points.
Definition: FXFont.h:125
Definition: FXFont.h:44
Latin 7 (Baltic Rim)
Definition: FXFont.h:97
Latin 1.
Definition: FXFont.h:102
Latin 8 (Celtic)
Definition: FXFont.h:116
Latin 2 (East European)
Definition: FXFont.h:104
FXushort slant
Weight [light, normal, bold, ...].
Definition: FXFont.h:126
Windows Greek.
Definition: FXFont.h:81
Font class.
Definition: FXFont.h:142
Latin 4 (North European)
Definition: FXFont.h:106
Arabic.
Definition: FXFont.h:109
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Latin 8 (Celtic)
Definition: FXFont.h:98
Arabic.
Definition: FXFont.h:46
Cyrillic.
Definition: FXFont.h:108
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33
Latin 9 AKA Latin 0.
Definition: FXFont.h:99
Hebrew.
Definition: FXFont.h:111

Copyright © 1997-2005 Jeroen van der Zijp