1 /******************************************************************************** 2 * * 3 * F o n t O b j e c t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2005 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.47 2005/01/16 16:06:06 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 style hints which influence the matcher 35 enum FXFontHint { 36 FONTPITCH_DEFAULT = 0, /// Default pitch 37 FONTPITCH_FIXED = 1, /// Fixed pitch, mono-spaced 38 FONTPITCH_VARIABLE = 2, /// Variable pitch, proportional spacing 39 FONTHINT_DONTCARE = 0, /// Don't care which font 40 FONTHINT_DECORATIVE = 4, /// Fancy fonts 41 FONTHINT_MODERN = 8, /// Monospace typewriter font 42 FONTHINT_ROMAN = 16, /// Variable width times-like font, serif 43 FONTHINT_SCRIPT = 32, /// Script or cursive 44 FONTHINT_SWISS = 64, /// Helvetica/swiss type font, sans-serif 45 FONTHINT_SYSTEM = 128, /// System font 46 FONTHINT_X11 = 256, /// X11 Font string 47 FONTHINT_SCALABLE = 512, /// Scalable fonts 48 FONTHINT_POLYMORPHIC = 1024 /// Polymorphic fonts 49 }; 50 51 52 /// Font slant 53 enum FXFontSlant { 54 FONTSLANT_DONTCARE = 0, /// Don't care about slant 55 FONTSLANT_REGULAR = 1, /// Regular straight up 56 FONTSLANT_ITALIC = 2, /// Italics 57 FONTSLANT_OBLIQUE = 3, /// Oblique slant 58 FONTSLANT_REVERSE_ITALIC = 4, /// Reversed italic 59 FONTSLANT_REVERSE_OBLIQUE = 5 /// Reversed oblique 60 }; 61 62 63 /// Font character set encoding 64 enum FXFontEncoding { 65 FONTENCODING_DEFAULT, /// Don't care character encoding 66 67 FONTENCODING_ISO_8859_1 = 1, /// West European (Latin1) 68 FONTENCODING_ISO_8859_2 = 2, /// Central and East European (Latin2) 69 FONTENCODING_ISO_8859_3 = 3, /// Esperanto (Latin3) 70 FONTENCODING_ISO_8859_4 = 4, 71 FONTENCODING_ISO_8859_5 = 5, /// Cyrillic (almost obsolete) 72 FONTENCODING_ISO_8859_6 = 6, /// Arabic 73 FONTENCODING_ISO_8859_7 = 7, /// Greek 74 FONTENCODING_ISO_8859_8 = 8, /// Hebrew 75 FONTENCODING_ISO_8859_9 = 9, /// Turkish (Latin5) 76 FONTENCODING_ISO_8859_10 = 10, 77 FONTENCODING_ISO_8859_11 = 11, /// Thai 78 FONTENCODING_ISO_8859_13 = 13, /// Baltic 79 FONTENCODING_ISO_8859_14 = 14, 80 FONTENCODING_ISO_8859_15 = 15, 81 FONTENCODING_ISO_8859_16 = 16, 82 FONTENCODING_KOI8 = 17, 83 FONTENCODING_KOI8_R = 18, /// Russian 84 FONTENCODING_KOI8_U = 19, /// Ukrainian 85 FONTENCODING_KOI8_UNIFIED = 20, 86 87 FONTENCODING_CP437 = 437, /// IBM-PC code page 88 FONTENCODING_CP850 = 850, /// IBMPC Multilingual 89 FONTENCODING_CP851 = 851, /// IBM-PC Greek 90 FONTENCODING_CP852 = 852, /// IBM-PC Latin2 91 FONTENCODING_CP855 = 855, /// IBM-PC Cyrillic 92 FONTENCODING_CP856 = 856, /// IBM-PC Hebrew 93 FONTENCODING_CP857 = 857, /// IBM-PC Turkish 94 FONTENCODING_CP860 = 860, /// IBM-PC Portugese 95 FONTENCODING_CP861 = 861, /// IBM-PC Iceland 96 FONTENCODING_CP862 = 862, /// IBM-PC Israel 97 FONTENCODING_CP863 = 863, /// IBM-PC Canadian/French 98 FONTENCODING_CP864 = 864, /// IBM-PC Arabic 99 FONTENCODING_CP865 = 865, /// IBM-PC Nordic 100 FONTENCODING_CP866 = 866, /// IBM-PC Cyrillic #2 101 FONTENCODING_CP869 = 869, /// IBM-PC Greek #2 102 FONTENCODING_CP870 = 870, /// Latin-2 Multilingual 103 104 FONTENCODING_CP1250 = 1250, /// Windows Central European 105 FONTENCODING_CP1251 = 1251, /// Windows Russian 106 FONTENCODING_CP1252 = 1252, /// Windows Latin1 107 FONTENCODING_CP1253 = 1253, /// Windows Greek 108 FONTENCODING_CP1254 = 1254, /// Windows Turkish 109 FONTENCODING_CP1255 = 1255, /// Windows Hebrew 110 FONTENCODING_CP1256 = 1256, /// Windows Arabic 111 FONTENCODING_CP1257 = 1257, /// Windows Baltic 112 FONTENCODING_CP1258 = 1258, /// Windows Vietnam 113 FONTENCODING_CP874 = 874, /// Windows Thai 114 115 FONTENCODING_LATIN1 = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 116 FONTENCODING_LATIN2 = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 117 FONTENCODING_LATIN3 = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 118 FONTENCODING_LATIN4 = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 119 FONTENCODING_LATIN5 = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 120 FONTENCODING_LATIN6 = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 121 FONTENCODING_LATIN7 = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 122 FONTENCODING_LATIN8 = FONTENCODING_ISO_8859_14, /// Latin 8 (Celtic) 123 FONTENCODING_LATIN9 = FONTENCODING_ISO_8859_15, /// Latin 9 AKA Latin 0 124 FONTENCODING_LATIN10 = FONTENCODING_ISO_8859_16, /// Latin 10 125 126 FONTENCODING_USASCII = FONTENCODING_ISO_8859_1, /// Latin 1 127 FONTENCODING_WESTEUROPE = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 128 FONTENCODING_EASTEUROPE = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 129 FONTENCODING_SOUTHEUROPE = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 130 FONTENCODING_NORTHEUROPE = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 131 FONTENCODING_CYRILLIC = FONTENCODING_ISO_8859_5, /// Cyrillic 132 FONTENCODING_RUSSIAN = FONTENCODING_KOI8, /// Cyrillic 133 FONTENCODING_ARABIC = FONTENCODING_ISO_8859_6, /// Arabic 134 FONTENCODING_GREEK = FONTENCODING_ISO_8859_7, /// Greek 135 FONTENCODING_HEBREW = FONTENCODING_ISO_8859_8, /// Hebrew 136 FONTENCODING_TURKISH = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 137 FONTENCODING_NORDIC = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 138 FONTENCODING_THAI = FONTENCODING_ISO_8859_11, /// Thai 139 FONTENCODING_BALTIC = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 140 FONTENCODING_CELTIC = FONTENCODING_ISO_8859_14 /// Latin 8 (Celtic) 141 }; 142 143 144 /// Font weight 145 enum FXFontWeight { 146 FONTWEIGHT_DONTCARE = 0, /// Don't care about weight 147 FONTWEIGHT_THIN = 100, /// Thin 148 FONTWEIGHT_EXTRALIGHT = 200, /// Extra light 149 FONTWEIGHT_LIGHT = 300, /// Light 150 FONTWEIGHT_NORMAL = 400, /// Normal or regular weight 151 FONTWEIGHT_REGULAR = 400, /// Normal or regular weight 152 FONTWEIGHT_MEDIUM = 500, /// Medium bold face 153 FONTWEIGHT_DEMIBOLD = 600, /// Demi bold face 154 FONTWEIGHT_BOLD = 700, /// Bold face 155 FONTWEIGHT_EXTRABOLD = 800, /// Extra 156 FONTWEIGHT_HEAVY = 900, /// Heavy 157 FONTWEIGHT_BLACK = 900 /// Black 158 }; 159 160 161 /// Font relative setwidth 162 enum FXFontSetWidth { 163 FONTSETWIDTH_DONTCARE = 0, /// Don't care about set width 164 FONTSETWIDTH_ULTRACONDENSED = 10, /// Ultra condensed printing 165 FONTSETWIDTH_EXTRACONDENSED = 20, /// Extra condensed 166 FONTSETWIDTH_CONDENSED = 30, /// Condensed 167 FONTSETWIDTH_NARROW = 30, /// Narrow 168 FONTSETWIDTH_COMPRESSED = 30, /// Compressed 169 FONTSETWIDTH_SEMICONDENSED = 40, /// Semi-condensed 170 FONTSETWIDTH_MEDIUM = 50, /// Medium printing 171 FONTSETWIDTH_NORMAL = 50, /// Normal printing 172 FONTSETWIDTH_REGULAR = 50, /// Regulat printing 173 FONTSETWIDTH_SEMIEXPANDED = 60, /// Semi expanded 174 FONTSETWIDTH_EXPANDED = 70, /// Expanded 175 FONTSETWIDTH_WIDE = 80, /// Wide 176 FONTSETWIDTH_EXTRAEXPANDED = 80, /// Extra expanded 177 FONTSETWIDTH_ULTRAEXPANDED = 90 /// Ultra expanded 178 }; 179 180 181 /// Font style 182 struct FXFontDesc { 183 FXchar face[104]; /// Face name 184 FXuint size; /// Size in deci-points 185 FXuint weight; /// Weight [light, normal, bold, ...] 186 FXuint slant; /// Slant [normal, italic, oblique, ...] 187 FXuint setwidth; /// Set width [normal, condensed, expanded, ...] 188 FXuint encoding; /// Encoding of character set 189 FXuint flags; /// Flags 190 }; 191 192 193 /// Font class 194 class FXAPI FXFont : public FXId { 195 friend class FXDCWindow; 196 FXDECLARE(FXFont) 197 protected: 198 FXString wantedName; // Desired font font name 199 FXString actualName; // Matched font font name 200 FXuint wantedSize; // Font size (points*10) 201 FXuint actualSize; // Actual size that was matched 202 FXuint wantedWeight; // Font weight 203 FXuint actualWeight; // Font weight 204 FXuint wantedSlant; // Font slant 205 FXuint actualSlant; // Font slant 206 FXuint wantedSetwidth; // Relative setwidth 207 FXuint actualSetwidth; // Relative setwidth 208 FXuint wantedEncoding; // Character set encoding 209 FXuint actualEncoding; // Character set encoding 210 FXuint hints; // Matching hints 211 void *font; // Info about the font 212 private: 213 #ifdef WIN32 214 FXID dc; // Dummy 215 #endif 216 protected: 217 FXFont(); 218 #ifndef WIN32 219 const char* findbestfont(char* fontname); 220 char* findmatch(char* fontname,const char* forge,const char* family); 221 #endif 222 private: 223 FXFont(const FXFont&); 224 FXFont &operator=(const FXFont&); 225 public: 226 227 /** 228 * Construct a font with given font description of the form: 229 * 230 * fontname [ "[" foundry "]" ] ["," size ["," weight ["," slant ["," setwidth ["," encoding ["," hints]]]]]] 231 * 232 * For example: 233 * 234 * "helvetica [bitstream],120,bold,i,normal,iso8859-1,0" 235 * 236 * Typically, at least the font name, and size must be given for 237 * normal font matching. As a special case, raw X11 fonts can also be 238 * passed, for example: 239 * 240 * "9x15bold" 241 * 242 * Finally, an old FOX 1.0 style font string may be passed as well: 243 * 244 * "[helvetica] 90 700 1 1 0 0" 245 * 246 */ 247 FXFont(FXApp* a,const FXString& string); 248 249 /** 250 * Construct a font with given name, size in points, weight, slant, character set 251 * encoding, setwidth, and hints. 252 * The font name may be comprised of a family name and optional foundry name enclosed in 253 * square brackets, for example, "helvetica [bitstream]". 254 */ 255 FXFont(FXApp* a,const FXString& face,FXuint sz,FXuint wt=FONTWEIGHT_NORMAL,FXuint sl=FONTSLANT_REGULAR,FXuint enc=FONTENCODING_DEFAULT,FXuint setw=FONTSETWIDTH_DONTCARE,FXuint h=0); 256 257 /// Construct font from font description 258 FXFont(FXApp* a,const FXFontDesc& fontdesc); 259 260 /// Create the font 261 virtual void create(); 262 263 /// Detach the font 264 virtual void detach(); 265 266 /// Destroy the font 267 virtual void destroy(); 268 269 /// Get font family name getName()270 const FXString& getName() const { return wantedName; } 271 272 /// Get actual family name getActualName()273 const FXString& getActualName() const { return actualName; } 274 275 /// Get size in deci-points getSize()276 FXuint getSize() const { return wantedSize; } 277 278 /// Get actual size in deci-points getActualSize()279 FXuint getActualSize() const { return actualSize; } 280 281 /// Get font weight getWeight()282 FXuint getWeight() const { return wantedWeight; } 283 284 /// Get actual font weight getActualWeight()285 FXuint getActualWeight() const { return actualWeight; } 286 287 /// Get slant getSlant()288 FXuint getSlant() const { return wantedSlant; } 289 290 /// Get actual slant getActualSlant()291 FXuint getActualSlant() const { return actualSlant; } 292 293 /// Get character set encoding getEncoding()294 FXuint getEncoding() const { return wantedEncoding; } 295 296 /// Get actual encoding getActualEncoding()297 FXuint getActualEncoding() const { return actualEncoding; } 298 299 /// Get setwidth getSetWidth()300 FXuint getSetWidth() const { return wantedSetwidth; } 301 302 /// Get actual setwidth getActualSetWidth()303 FXuint getActualSetWidth() const { return actualSetwidth; } 304 305 /// Get hints getHints()306 FXuint getHints() const { return hints; } 307 308 /// Change font description 309 void setFontDesc(const FXFontDesc& fontdesc); 310 311 /// Get font description 312 void getFontDesc(FXFontDesc& fontdesc) const; 313 314 /** 315 * Change the font to the specified font description string. 316 */ 317 FXbool setFont(const FXString& string); 318 319 /** 320 * Return the font description as a string suitable for 321 * parsing with setFont(), see above. 322 */ 323 FXString getFont() const; 324 325 /// Find out if the font is monotype or proportional 326 FXbool isFontMono() const; 327 328 /// See if font has glyph for ch 329 FXbool hasChar(FXint ch) const; 330 331 /// Get first character glyph in font 332 FXint getMinChar() const; 333 334 /// Get last character glyph in font 335 FXint getMaxChar() const; 336 337 /// Left bearing 338 FXint leftBearing(FXchar ch) const; 339 340 /// Right bearing 341 FXint rightBearing(FXchar ch) const; 342 343 /// Width of widest character in font 344 FXint getFontWidth() const; 345 346 /// Height of highest character in font 347 FXint getFontHeight() const; 348 349 /// Ascent from baseline 350 FXint getFontAscent() const; 351 352 /// Descent from baseline 353 FXint getFontDescent() const; 354 355 /// Get font leading [that is lead-ing as in Pb!] 356 FXint getFontLeading() const; 357 358 /// Get font line spacing 359 FXint getFontSpacing() const; 360 361 /// Calculate width of given text in this font 362 FXint getTextWidth(const FXchar *text,FXuint n) const; 363 364 /// Calculate width of given text in this font 365 FXint getTextWidth(const FXString& text) const; 366 367 /// Calculate height of given text in this font 368 FXint getTextHeight(const FXchar *text,FXuint n) const; 369 370 /// Calculate height of given text in this font 371 FXint getTextHeight(const FXString& text) const; 372 373 /** 374 * List all fonts matching hints. If listFonts() returns TRUE then 375 * fonts points to a newly-allocated array of length numfonts. It 376 * is the caller's responsibility to free this array using FXFREE(). 377 */ 378 static FXbool listFonts(FXFontDesc*& fonts,FXuint& numfonts,const FXString& face,FXuint wt=FONTWEIGHT_DONTCARE,FXuint sl=FONTSLANT_DONTCARE,FXuint sw=FONTSETWIDTH_DONTCARE,FXuint en=FONTENCODING_DEFAULT,FXuint h=0); 379 380 /// Save font data into stream 381 virtual void save(FXStream& store) const; 382 383 /// Load font data from stream 384 virtual void load(FXStream& store); 385 386 /// Destroy font 387 virtual ~FXFont(); 388 }; 389 390 391 392 /// DEPRECATED: Parse font description from a string 393 extern FXAPI FXbool fxparsefontdesc(FXFontDesc& fontdesc,const FXchar* string); 394 395 /// DEPRECATED: Unparse font description into a string 396 extern FXAPI FXbool fxunparsefontdesc(FXchar *string,const FXFontDesc& fontdesc); 397 398 } 399 400 #endif 401