![]() |
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,2002 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.25 2002/03/12 07:11:30 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 = 0, /// Don't care character encoding 00066 FONTENCODING_ISO_8859_1 = 1, 00067 FONTENCODING_ISO_8859_2 = 2, 00068 FONTENCODING_ISO_8859_3 = 3, 00069 FONTENCODING_ISO_8859_4 = 4, 00070 FONTENCODING_ISO_8859_5 = 5, /// Cyrillic (almost obsolete) 00071 FONTENCODING_ISO_8859_6 = 6, 00072 FONTENCODING_ISO_8859_7 = 7, 00073 FONTENCODING_ISO_8859_8 = 8, 00074 FONTENCODING_ISO_8859_9 = 9, 00075 FONTENCODING_ISO_8859_10 = 10, 00076 FONTENCODING_ISO_8859_11 = 11, 00077 FONTENCODING_ISO_8859_13 = 13, 00078 FONTENCODING_ISO_8859_14 = 14, 00079 FONTENCODING_ISO_8859_15 = 15, 00080 FONTENCODING_ISO_8859_16 = 16, 00081 FONTENCODING_KOI8 = 17, 00082 FONTENCODING_KOI8_R = 18, /// Russian 00083 FONTENCODING_KOI8_U = 19, /// Ukrainian 00084 FONTENCODING_KOI8_UNIFIED = 20, 00085 00086 FONTENCODING_LATIN1 = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 00087 FONTENCODING_LATIN2 = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 00088 FONTENCODING_LATIN3 = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 00089 FONTENCODING_LATIN4 = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 00090 FONTENCODING_LATIN5 = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 00091 FONTENCODING_LATIN6 = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 00092 FONTENCODING_LATIN7 = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 00093 FONTENCODING_LATIN8 = FONTENCODING_ISO_8859_14, /// Latin 8 (Celtic) 00094 FONTENCODING_LATIN9 = FONTENCODING_ISO_8859_15, /// Latin 9 AKA Latin 0 00095 FONTENCODING_LATIN10 = FONTENCODING_ISO_8859_16, /// Latin 10 00096 00097 FONTENCODING_USASCII = FONTENCODING_ISO_8859_1, /// Latin 1 00098 FONTENCODING_WESTEUROPE = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 00099 FONTENCODING_EASTEUROPE = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 00100 FONTENCODING_SOUTHEUROPE = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 00101 FONTENCODING_NORTHEUROPE = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 00102 FONTENCODING_CYRILLIC = FONTENCODING_ISO_8859_5, /// Cyrillic 00103 FONTENCODING_RUSSIAN = FONTENCODING_KOI8, /// Cyrillic 00104 FONTENCODING_ARABIC = FONTENCODING_ISO_8859_6, /// Arabic 00105 FONTENCODING_GREEK = FONTENCODING_ISO_8859_7, /// Greek 00106 FONTENCODING_HEBREW = FONTENCODING_ISO_8859_8, /// Hebrew 00107 FONTENCODING_TURKISH = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 00108 FONTENCODING_NORDIC = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 00109 FONTENCODING_THAI = FONTENCODING_ISO_8859_11, /// Thai 00110 FONTENCODING_BALTIC = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 00111 FONTENCODING_CELTIC = FONTENCODING_ISO_8859_14 /// Latin 8 (Celtic) 00112 }; 00113 00114 00115 /// Font weight 00116 enum FXFontWeight { 00117 FONTWEIGHT_DONTCARE = 0, /// Don't care about weight 00118 FONTWEIGHT_THIN = 100, /// Thin 00119 FONTWEIGHT_EXTRALIGHT = 200, /// Extra light 00120 FONTWEIGHT_LIGHT = 300, /// Light 00121 FONTWEIGHT_NORMAL = 400, /// Normal or regular weight 00122 FONTWEIGHT_REGULAR = 400, /// Normal or regular weight 00123 FONTWEIGHT_MEDIUM = 500, /// Medium bold face 00124 FONTWEIGHT_DEMIBOLD = 600, /// Demi bold face 00125 FONTWEIGHT_BOLD = 700, /// Bold face 00126 FONTWEIGHT_EXTRABOLD = 800, /// Extra 00127 FONTWEIGHT_HEAVY = 900, /// Heavy 00128 FONTWEIGHT_BLACK = 900 /// Black 00129 }; 00130 00131 00132 /// Font relative setwidth 00133 enum FXFontSetWidth { 00134 FONTSETWIDTH_DONTCARE = 0, /// Don't care about set width 00135 FONTSETWIDTH_ULTRACONDENSED = 10, /// Ultra condensed printing 00136 FONTSETWIDTH_EXTRACONDENSED = 20, /// Extra condensed 00137 FONTSETWIDTH_CONDENSED = 30, /// Condensed 00138 FONTSETWIDTH_NARROW = 30, /// Narrow 00139 FONTSETWIDTH_COMPRESSED = 30, /// Compressed 00140 FONTSETWIDTH_SEMICONDENSED = 40, /// Semi-condensed 00141 FONTSETWIDTH_MEDIUM = 50, /// Medium printing 00142 FONTSETWIDTH_NORMAL = 50, /// Normal printing 00143 FONTSETWIDTH_REGULAR = 50, /// Regulat printing 00144 FONTSETWIDTH_SEMIEXPANDED = 60, /// Semi expanded 00145 FONTSETWIDTH_EXPANDED = 70, /// Expanded 00146 FONTSETWIDTH_WIDE = 80, /// Wide 00147 FONTSETWIDTH_EXTRAEXPANDED = 80, /// Extra expanded 00148 FONTSETWIDTH_ULTRAEXPANDED = 90 /// Ultra expanded 00149 }; 00150 00151 00152 /// Font style 00153 struct FXFontDesc { 00154 FXchar face[48]; /// Face name 00155 FXuint size; /// Size in deci-points 00156 FXuint weight; /// Weight [light, normal, bold, ...] 00157 FXuint slant; /// Slant [normal, italic, oblique, ...] 00158 FXuint encoding; /// Encoding of character set 00159 FXuint setwidth; /// Set width [normal, condensed, expanded, ...] 00160 FXuint flags; /// Flags 00161 }; 00162 00163 00164 /// Font class 00165 class FXAPI FXFont : public FXId { 00166 FXDECLARE(FXFont) 00167 protected: 00168 FXString name; // Name of the font 00169 FXuint size; // Font size (points*10) 00170 FXuint weight; // Font weight 00171 FXuint slant; // Font slant 00172 FXuint encoding; // Character set encoding 00173 FXuint setwidth; // Relative setwidth 00174 FXuint hints; // Matching hints 00175 void *font; // Info about the font 00176 private: 00177 #ifdef WIN32 00178 FXID dc; // Dummy 00179 #endif 00180 protected: 00181 FXFont(); 00182 #ifndef WIN32 00183 char* findbestfont(char *fontname) const; 00184 const char* fallbackfont() const; 00185 char* findmatch(char *fontname,const char* family) const; 00186 #endif 00187 private: 00188 FXFont(const FXFont&); 00189 FXFont &operator=(const FXFont&); 00190 public: 00191 00192 /// Construct font from font description 00193 FXFont(FXApp* a,const FXFontDesc& fontdesc); 00194 00195 /// Construct a font with given face name, size in points(pixels), weight, slant, character set encoding, setwidth, and hints 00196 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); 00197 00198 /// Construct a font with given X11 font string 00199 FXFont(FXApp* a,const FXString& nm); 00200 00201 /// Create the font 00202 virtual void create(); 00203 00204 /// Detach the font 00205 virtual void detach(); 00206 00207 /// Destroy the font 00208 virtual void destroy(); 00209 00210 /// Get face name 00211 FXString getName() const { return name; } 00212 00213 /// Get size in deci-points 00214 FXuint getSize() const { return size; } 00215 00216 /// Get font weight 00217 FXuint getWeight() const { return weight; } 00218 00219 /// Get slant 00220 FXuint getSlant() const { return slant; } 00221 00222 /// Get character set encoding 00223 FXuint getEncoding() const { return encoding; } 00224 00225 /// Get setwidth 00226 FXuint getSetWidth() const { return setwidth; } 00227 00228 /// Get hints 00229 FXuint getHints() const { return hints; } 00230 00231 /// Get font description 00232 void getFontDesc(FXFontDesc& fontdesc) const; 00233 00234 /// Change font description 00235 void setFontDesc(const FXFontDesc& fontdesc); 00236 00237 /// Find out if the font is monotype or proportional 00238 FXbool isFontMono() const; 00239 00240 /// See if font has glyph for ch 00241 FXbool hasChar(FXint ch) const; 00242 00243 /// Get first character glyph in font 00244 FXint getMinChar() const; 00245 00246 /// Get last character glyph in font 00247 FXint getMaxChar() const; 00248 00249 /// Left bearing 00250 FXint leftBearing(FXchar ch) const; 00251 00252 /// Right bearing 00253 FXint rightBearing(FXchar ch) const; 00254 00255 /// Width of widest character in font 00256 FXint getFontWidth() const; 00257 00258 /// Height of highest character in font 00259 FXint getFontHeight() const; 00260 00261 /// Ascent from baseline 00262 FXint getFontAscent() const; 00263 00264 /// Descent from baseline 00265 FXint getFontDescent() const; 00266 00267 /// Get font leading [that is lead-ing as in Pb!] 00268 FXint getFontLeading() const; 00269 00270 /// Get font line spacing 00271 FXint getFontSpacing() const; 00272 00273 /// Calculate width of given text in this font 00274 FXint getTextWidth(const FXchar *text,FXuint n) const; 00275 00276 /// Calculate height of given text in this font 00277 FXint getTextHeight(const FXchar *text,FXuint n) const; 00278 00279 /// List all fonts matching hints 00280 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); 00281 00282 /// Save font data into stream 00283 virtual void save(FXStream& store) const; 00284 00285 /// Load font data from stream 00286 virtual void load(FXStream& store); 00287 00288 /// Destroy font 00289 virtual ~FXFont(); 00290 }; 00291 00292 00293 00294 /// Parse font description from a string 00295 extern FXAPI FXbool fxparsefontdesc(FXFontDesc& fontdesc,const FXchar* string); 00296 00297 /// Unparse font description into a string 00298 extern FXAPI FXbool fxunparsefontdesc(FXchar *string,const FXFontDesc& fontdesc); 00299 00300 } 00301 00302 #endif