Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * F o n t O b j e c t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2004 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXFont.h,v 1.43 2004/03/10 23:19:41 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXFONT_H 00025 #define FXFONT_H 00026 00027 #ifndef FXID_H 00028 #include "FXId.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 /// Font style hints which influence the matcher 00035 enum FXFontHint { 00036 FONTPITCH_DEFAULT = 0, /// Default pitch 00037 FONTPITCH_FIXED = 1, /// Fixed pitch, mono-spaced 00038 FONTPITCH_VARIABLE = 2, /// Variable pitch, proportional spacing 00039 FONTHINT_DONTCARE = 0, /// Don't care which font 00040 FONTHINT_DECORATIVE = 4, /// Fancy fonts 00041 FONTHINT_MODERN = 8, /// Monospace typewriter font 00042 FONTHINT_ROMAN = 16, /// Variable width times-like font, serif 00043 FONTHINT_SCRIPT = 32, /// Script or cursive 00044 FONTHINT_SWISS = 64, /// Helvetica/swiss type font, sans-serif 00045 FONTHINT_SYSTEM = 128, /// System font 00046 FONTHINT_X11 = 256, /// X11 Font string 00047 FONTHINT_SCALABLE = 512, /// Scalable fonts 00048 FONTHINT_POLYMORPHIC = 1024 /// Polymorphic fonts 00049 }; 00050 00051 00052 /// Font slant 00053 enum FXFontSlant { 00054 FONTSLANT_DONTCARE = 0, /// Don't care about slant 00055 FONTSLANT_REGULAR = 1, /// Regular straight up 00056 FONTSLANT_ITALIC = 2, /// Italics 00057 FONTSLANT_OBLIQUE = 3, /// Oblique slant 00058 FONTSLANT_REVERSE_ITALIC = 4, /// Reversed italic 00059 FONTSLANT_REVERSE_OBLIQUE = 5 /// Reversed oblique 00060 }; 00061 00062 00063 /// Font character set encoding 00064 enum FXFontEncoding { 00065 FONTENCODING_DEFAULT, /// Don't care character encoding 00066 00067 FONTENCODING_ISO_8859_1 = 1, /// West European (Latin1) 00068 FONTENCODING_ISO_8859_2 = 2, /// Central and East European (Latin2) 00069 FONTENCODING_ISO_8859_3 = 3, /// Esperanto (Latin3) 00070 FONTENCODING_ISO_8859_4 = 4, 00071 FONTENCODING_ISO_8859_5 = 5, /// Cyrillic (almost obsolete) 00072 FONTENCODING_ISO_8859_6 = 6, /// Arabic 00073 FONTENCODING_ISO_8859_7 = 7, /// Greek 00074 FONTENCODING_ISO_8859_8 = 8, /// Hebrew 00075 FONTENCODING_ISO_8859_9 = 9, /// Turkish (Latin5) 00076 FONTENCODING_ISO_8859_10 = 10, 00077 FONTENCODING_ISO_8859_11 = 11, /// Thai 00078 FONTENCODING_ISO_8859_13 = 13, /// Baltic 00079 FONTENCODING_ISO_8859_14 = 14, 00080 FONTENCODING_ISO_8859_15 = 15, 00081 FONTENCODING_ISO_8859_16 = 16, 00082 FONTENCODING_KOI8 = 17, 00083 FONTENCODING_KOI8_R = 18, /// Russian 00084 FONTENCODING_KOI8_U = 19, /// Ukrainian 00085 FONTENCODING_KOI8_UNIFIED = 20, 00086 00087 FONTENCODING_CP437 = 437, /// IBM-PC code page 00088 FONTENCODING_CP850 = 850, /// IBMPC Multilingual 00089 FONTENCODING_CP851 = 851, /// IBM-PC Greek 00090 FONTENCODING_CP852 = 852, /// IBM-PC Latin2 00091 FONTENCODING_CP855 = 855, /// IBM-PC Cyrillic 00092 FONTENCODING_CP856 = 856, /// IBM-PC Hebrew 00093 FONTENCODING_CP857 = 857, /// IBM-PC Turkish 00094 FONTENCODING_CP860 = 860, /// IBM-PC Portugese 00095 FONTENCODING_CP861 = 861, /// IBM-PC Iceland 00096 FONTENCODING_CP862 = 862, /// IBM-PC Israel 00097 FONTENCODING_CP863 = 863, /// IBM-PC Canadian/French 00098 FONTENCODING_CP864 = 864, /// IBM-PC Arabic 00099 FONTENCODING_CP865 = 865, /// IBM-PC Nordic 00100 FONTENCODING_CP866 = 866, /// IBM-PC Cyrillic #2 00101 FONTENCODING_CP869 = 869, /// IBM-PC Greek #2 00102 FONTENCODING_CP870 = 870, /// Latin-2 Multilingual 00103 00104 FONTENCODING_CP1250 = 1250, /// Windows Central European 00105 FONTENCODING_CP1251 = 1251, /// Windows Russian 00106 FONTENCODING_CP1252 = 1252, /// Windows Latin1 00107 FONTENCODING_CP1253 = 1253, /// Windows Greek 00108 FONTENCODING_CP1254 = 1254, /// Windows Turkish 00109 FONTENCODING_CP1255 = 1255, /// Windows Hebrew 00110 FONTENCODING_CP1256 = 1256, /// Windows Arabic 00111 FONTENCODING_CP1257 = 1257, /// Windows Baltic 00112 FONTENCODING_CP1258 = 1258, /// Windows Vietnam 00113 FONTENCODING_CP874 = 874, /// Windows Thai 00114 00115 FONTENCODING_LATIN1 = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 00116 FONTENCODING_LATIN2 = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 00117 FONTENCODING_LATIN3 = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 00118 FONTENCODING_LATIN4 = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 00119 FONTENCODING_LATIN5 = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 00120 FONTENCODING_LATIN6 = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 00121 FONTENCODING_LATIN7 = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 00122 FONTENCODING_LATIN8 = FONTENCODING_ISO_8859_14, /// Latin 8 (Celtic) 00123 FONTENCODING_LATIN9 = FONTENCODING_ISO_8859_15, /// Latin 9 AKA Latin 0 00124 FONTENCODING_LATIN10 = FONTENCODING_ISO_8859_16, /// Latin 10 00125 00126 FONTENCODING_USASCII = FONTENCODING_ISO_8859_1, /// Latin 1 00127 FONTENCODING_WESTEUROPE = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 00128 FONTENCODING_EASTEUROPE = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 00129 FONTENCODING_SOUTHEUROPE = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 00130 FONTENCODING_NORTHEUROPE = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 00131 FONTENCODING_CYRILLIC = FONTENCODING_ISO_8859_5, /// Cyrillic 00132 FONTENCODING_RUSSIAN = FONTENCODING_KOI8, /// Cyrillic 00133 FONTENCODING_ARABIC = FONTENCODING_ISO_8859_6, /// Arabic 00134 FONTENCODING_GREEK = FONTENCODING_ISO_8859_7, /// Greek 00135 FONTENCODING_HEBREW = FONTENCODING_ISO_8859_8, /// Hebrew 00136 FONTENCODING_TURKISH = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 00137 FONTENCODING_NORDIC = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 00138 FONTENCODING_THAI = FONTENCODING_ISO_8859_11, /// Thai 00139 FONTENCODING_BALTIC = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 00140 FONTENCODING_CELTIC = FONTENCODING_ISO_8859_14 /// Latin 8 (Celtic) 00141 }; 00142 00143 00144 /// Font weight 00145 enum FXFontWeight { 00146 FONTWEIGHT_DONTCARE = 0, /// Don't care about weight 00147 FONTWEIGHT_THIN = 100, /// Thin 00148 FONTWEIGHT_EXTRALIGHT = 200, /// Extra light 00149 FONTWEIGHT_LIGHT = 300, /// Light 00150 FONTWEIGHT_NORMAL = 400, /// Normal or regular weight 00151 FONTWEIGHT_REGULAR = 400, /// Normal or regular weight 00152 FONTWEIGHT_MEDIUM = 500, /// Medium bold face 00153 FONTWEIGHT_DEMIBOLD = 600, /// Demi bold face 00154 FONTWEIGHT_BOLD = 700, /// Bold face 00155 FONTWEIGHT_EXTRABOLD = 800, /// Extra 00156 FONTWEIGHT_HEAVY = 900, /// Heavy 00157 FONTWEIGHT_BLACK = 900 /// Black 00158 }; 00159 00160 00161 /// Font relative setwidth 00162 enum FXFontSetWidth { 00163 FONTSETWIDTH_DONTCARE = 0, /// Don't care about set width 00164 FONTSETWIDTH_ULTRACONDENSED = 10, /// Ultra condensed printing 00165 FONTSETWIDTH_EXTRACONDENSED = 20, /// Extra condensed 00166 FONTSETWIDTH_CONDENSED = 30, /// Condensed 00167 FONTSETWIDTH_NARROW = 30, /// Narrow 00168 FONTSETWIDTH_COMPRESSED = 30, /// Compressed 00169 FONTSETWIDTH_SEMICONDENSED = 40, /// Semi-condensed 00170 FONTSETWIDTH_MEDIUM = 50, /// Medium printing 00171 FONTSETWIDTH_NORMAL = 50, /// Normal printing 00172 FONTSETWIDTH_REGULAR = 50, /// Regulat printing 00173 FONTSETWIDTH_SEMIEXPANDED = 60, /// Semi expanded 00174 FONTSETWIDTH_EXPANDED = 70, /// Expanded 00175 FONTSETWIDTH_WIDE = 80, /// Wide 00176 FONTSETWIDTH_EXTRAEXPANDED = 80, /// Extra expanded 00177 FONTSETWIDTH_ULTRAEXPANDED = 90 /// Ultra expanded 00178 }; 00179 00180 00181 /// Font style 00182 struct FXFontDesc { 00183 FXchar face[104]; /// Face name 00184 FXuint size; /// Size in deci-points 00185 FXuint weight; /// Weight [light, normal, bold, ...] 00186 FXuint slant; /// Slant [normal, italic, oblique, ...] 00187 FXuint setwidth; /// Set width [normal, condensed, expanded, ...] 00188 FXuint encoding; /// Encoding of character set 00189 FXuint flags; /// Flags 00190 }; 00191 00192 00193 /// Font class 00194 class FXAPI FXFont : public FXId { 00195 friend class FXDCWindow; 00196 FXDECLARE(FXFont) 00197 protected: 00198 FXString wantedName; // Desired font font name 00199 FXString actualName; // Matched font font name 00200 FXuint wantedSize; // Font size (points*10) 00201 FXuint actualSize; // Actual size that was matched 00202 FXuint wantedWeight; // Font weight 00203 FXuint actualWeight; // Font weight 00204 FXuint wantedSlant; // Font slant 00205 FXuint actualSlant; // Font slant 00206 FXuint wantedSetwidth; // Relative setwidth 00207 FXuint actualSetwidth; // Relative setwidth 00208 FXuint wantedEncoding; // Character set encoding 00209 FXuint actualEncoding; // Character set encoding 00210 FXuint hints; // Matching hints 00211 void *font; // Info about the font 00212 private: 00213 #ifdef WIN32 00214 FXID dc; // Dummy 00215 #endif 00216 protected: 00217 FXFont(); 00218 #ifndef WIN32 00219 char* findbestfont(char* fontname); 00220 char* findmatch(char* fontname,const char* forge,const char* family); 00221 #endif 00222 private: 00223 FXFont(const FXFont&); 00224 FXFont &operator=(const FXFont&); 00225 public: 00226 00227 /** 00228 * Construct a font with given font description of the form: 00229 * 00230 * fontname [ "[" foundry "]" ] ["," size ["," weight ["," slant ["," setwidth ["," encoding ["," hints]]]]]] 00231 * 00232 * For example: 00233 * 00234 * "helvetica [bitstream],12,bold,i,normal,iso8859-1,0" 00235 * 00236 * Typically, at least the font name, and size must be given for 00237 * normal font matching. As a special case, raw X11 fonts can also be 00238 * passed, for example: 00239 * 00240 * "9x15bold" 00241 * 00242 * Finally, an old FOX 1.0 style font string may be passed as well: 00243 * 00244 * "[helvetica] 90 700 1 1 0 0" 00245 * 00246 */ 00247 FXFont(FXApp* a,const FXString& string); 00248 00249 /** 00250 * Construct a font with given name, size in points, weight, slant, character set 00251 * encoding, setwidth, and hints. 00252 * The font name may be comprised of a family name and optional foundry name enclosed in 00253 * square brackets, for example, "helvetica [bitstream]". 00254 */ 00255 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); 00256 00257 /// Construct font from font description 00258 FXFont(FXApp* a,const FXFontDesc& fontdesc); 00259 00260 /// Create the font 00261 virtual void create(); 00262 00263 /// Detach the font 00264 virtual void detach(); 00265 00266 /// Destroy the font 00267 virtual void destroy(); 00268 00269 /// Get font family name 00270 FXString getName() const { return wantedName; } 00271 00272 /// Get actual family name 00273 FXString getActualName() const { return actualName; } 00274 00275 /// Get size in deci-points 00276 FXuint getSize() const { return wantedSize; } 00277 00278 /// Get actual size in deci-points 00279 FXuint getActualSize() const { return actualSize; } 00280 00281 /// Get font weight 00282 FXuint getWeight() const { return wantedWeight; } 00283 00284 /// Get actual font weight 00285 FXuint getActualWeight() const { return actualWeight; } 00286 00287 /// Get slant 00288 FXuint getSlant() const { return wantedSlant; } 00289 00290 /// Get actual slant 00291 FXuint getActualSlant() const { return actualSlant; } 00292 00293 /// Get character set encoding 00294 FXuint getEncoding() const { return wantedEncoding; } 00295 00296 /// Get actual encoding 00297 FXuint getActualEncoding() const { return actualEncoding; } 00298 00299 /// Get setwidth 00300 FXuint getSetWidth() const { return wantedSetwidth; } 00301 00302 /// Get actual setwidth 00303 FXuint getActualSetWidth() const { return actualSetwidth; } 00304 00305 /// Get hints 00306 FXuint getHints() const { return hints; } 00307 00308 /// Change font description 00309 void setFontDesc(const FXFontDesc& fontdesc); 00310 00311 /// Get font description 00312 void getFontDesc(FXFontDesc& fontdesc) const; 00313 00314 /** 00315 * Change the font to the specified font description string. 00316 */ 00317 FXbool setFont(const FXString& string); 00318 00319 /** 00320 * Return the font description as a string suitable for 00321 * parsing with setFont(), see above. 00322 */ 00323 FXString getFont() const; 00324 00325 /// Find out if the font is monotype or proportional 00326 FXbool isFontMono() const; 00327 00328 /// See if font has glyph for ch 00329 FXbool hasChar(FXint ch) const; 00330 00331 /// Get first character glyph in font 00332 FXint getMinChar() const; 00333 00334 /// Get last character glyph in font 00335 FXint getMaxChar() const; 00336 00337 /// Left bearing 00338 FXint leftBearing(FXchar ch) const; 00339 00340 /// Right bearing 00341 FXint rightBearing(FXchar ch) const; 00342 00343 /// Width of widest character in font 00344 FXint getFontWidth() const; 00345 00346 /// Height of highest character in font 00347 FXint getFontHeight() const; 00348 00349 /// Ascent from baseline 00350 FXint getFontAscent() const; 00351 00352 /// Descent from baseline 00353 FXint getFontDescent() const; 00354 00355 /// Get font leading [that is lead-ing as in Pb!] 00356 FXint getFontLeading() const; 00357 00358 /// Get font line spacing 00359 FXint getFontSpacing() const; 00360 00361 /// Calculate width of given text in this font 00362 FXint getTextWidth(const FXchar *text,FXuint n) const; 00363 00364 /// Calculate width of given text in this font 00365 FXint getTextWidth(const FXString& text) const; 00366 00367 /// Calculate height of given text in this font 00368 FXint getTextHeight(const FXchar *text,FXuint n) const; 00369 00370 /// Calculate height of given text in this font 00371 FXint getTextHeight(const FXString& text) const; 00372 00373 /** 00374 * List all fonts matching hints. If listFonts() returns TRUE then 00375 * fonts points to a newly-allocated array of length numfonts. It 00376 * is the caller's responsibility to free this array using FXFREE(). 00377 */ 00378 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); 00379 00380 /// Save font data into stream 00381 virtual void save(FXStream& store) const; 00382 00383 /// Load font data from stream 00384 virtual void load(FXStream& store); 00385 00386 /// Destroy font 00387 virtual ~FXFont(); 00388 }; 00389 00390 00391 00392 /// DEPRECATED: Parse font description from a string 00393 extern FXAPI FXbool fxparsefontdesc(FXFontDesc& fontdesc,const FXchar* string); 00394 00395 /// DEPRECATED: Unparse font description into a string 00396 extern FXAPI FXbool fxunparsefontdesc(FXchar *string,const FXFontDesc& fontdesc); 00397 00398 } 00399 00400 #endif
Copyright © 1997-2004 Jeroen van der Zijp |