![]() |
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,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (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 * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXFont.h,v 1.77 2009/01/06 13:07:24 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXFONT_H 00024 #define FXFONT_H 00025 00026 #ifndef FXID_H 00027 #include "FXId.h" 00028 #endif 00029 00030 namespace FX { 00031 00032 00033 /// Font character set encoding 00034 enum FXFontEncoding { 00035 FONTENCODING_DEFAULT, /// Don't care character encoding 00036 00037 FONTENCODING_ISO_8859_1 = 1, /// West European (Latin1) 00038 FONTENCODING_ISO_8859_2 = 2, /// Central and East European (Latin2) 00039 FONTENCODING_ISO_8859_3 = 3, /// Esperanto (Latin3) 00040 FONTENCODING_ISO_8859_4 = 4, 00041 FONTENCODING_ISO_8859_5 = 5, /// Cyrillic (almost obsolete) 00042 FONTENCODING_ISO_8859_6 = 6, /// Arabic 00043 FONTENCODING_ISO_8859_7 = 7, /// Greek 00044 FONTENCODING_ISO_8859_8 = 8, /// Hebrew 00045 FONTENCODING_ISO_8859_9 = 9, /// Turkish (Latin5) 00046 FONTENCODING_ISO_8859_10 = 10, 00047 FONTENCODING_ISO_8859_11 = 11, /// Thai 00048 FONTENCODING_ISO_8859_13 = 13, /// Baltic 00049 FONTENCODING_ISO_8859_14 = 14, 00050 FONTENCODING_ISO_8859_15 = 15, 00051 FONTENCODING_ISO_8859_16 = 16, 00052 FONTENCODING_KOI8 = 17, 00053 FONTENCODING_KOI8_R = 18, /// Russian 00054 FONTENCODING_KOI8_U = 19, /// Ukrainian 00055 FONTENCODING_KOI8_UNIFIED = 20, 00056 00057 FONTENCODING_CP437 = 437, /// IBM-PC code page 00058 FONTENCODING_CP850 = 850, /// IBMPC Multilingual 00059 FONTENCODING_CP851 = 851, /// IBM-PC Greek 00060 FONTENCODING_CP852 = 852, /// IBM-PC Latin2 00061 FONTENCODING_CP855 = 855, /// IBM-PC Cyrillic 00062 FONTENCODING_CP856 = 856, /// IBM-PC Hebrew 00063 FONTENCODING_CP857 = 857, /// IBM-PC Turkish 00064 FONTENCODING_CP860 = 860, /// IBM-PC Portugese 00065 FONTENCODING_CP861 = 861, /// IBM-PC Iceland 00066 FONTENCODING_CP862 = 862, /// IBM-PC Israel 00067 FONTENCODING_CP863 = 863, /// IBM-PC Canadian/French 00068 FONTENCODING_CP864 = 864, /// IBM-PC Arabic 00069 FONTENCODING_CP865 = 865, /// IBM-PC Nordic 00070 FONTENCODING_CP866 = 866, /// IBM-PC Cyrillic #2 00071 FONTENCODING_CP869 = 869, /// IBM-PC Greek #2 00072 FONTENCODING_CP870 = 870, /// Latin-2 Multilingual 00073 00074 FONTENCODING_CP1250 = 1250, /// Windows Central European 00075 FONTENCODING_CP1251 = 1251, /// Windows Russian 00076 FONTENCODING_CP1252 = 1252, /// Windows Latin1 00077 FONTENCODING_CP1253 = 1253, /// Windows Greek 00078 FONTENCODING_CP1254 = 1254, /// Windows Turkish 00079 FONTENCODING_CP1255 = 1255, /// Windows Hebrew 00080 FONTENCODING_CP1256 = 1256, /// Windows Arabic 00081 FONTENCODING_CP1257 = 1257, /// Windows Baltic 00082 FONTENCODING_CP1258 = 1258, /// Windows Vietnam 00083 FONTENCODING_CP874 = 874, /// Windows Thai 00084 00085 FONTENCODING_UNICODE = 9999, 00086 00087 FONTENCODING_LATIN1 = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 00088 FONTENCODING_LATIN2 = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 00089 FONTENCODING_LATIN3 = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 00090 FONTENCODING_LATIN4 = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 00091 FONTENCODING_LATIN5 = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 00092 FONTENCODING_LATIN6 = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 00093 FONTENCODING_LATIN7 = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 00094 FONTENCODING_LATIN8 = FONTENCODING_ISO_8859_14, /// Latin 8 (Celtic) 00095 FONTENCODING_LATIN9 = FONTENCODING_ISO_8859_15, /// Latin 9 AKA Latin 0 00096 FONTENCODING_LATIN10 = FONTENCODING_ISO_8859_16, /// Latin 10 00097 00098 FONTENCODING_USASCII = FONTENCODING_ISO_8859_1, /// Latin 1 00099 FONTENCODING_WESTEUROPE = FONTENCODING_ISO_8859_1, /// Latin 1 (West European) 00100 FONTENCODING_EASTEUROPE = FONTENCODING_ISO_8859_2, /// Latin 2 (East European) 00101 FONTENCODING_SOUTHEUROPE = FONTENCODING_ISO_8859_3, /// Latin 3 (South European) 00102 FONTENCODING_NORTHEUROPE = FONTENCODING_ISO_8859_4, /// Latin 4 (North European) 00103 FONTENCODING_CYRILLIC = FONTENCODING_ISO_8859_5, /// Cyrillic 00104 FONTENCODING_RUSSIAN = FONTENCODING_KOI8, /// Cyrillic 00105 FONTENCODING_ARABIC = FONTENCODING_ISO_8859_6, /// Arabic 00106 FONTENCODING_GREEK = FONTENCODING_ISO_8859_7, /// Greek 00107 FONTENCODING_HEBREW = FONTENCODING_ISO_8859_8, /// Hebrew 00108 FONTENCODING_TURKISH = FONTENCODING_ISO_8859_9, /// Latin 5 (Turkish) 00109 FONTENCODING_NORDIC = FONTENCODING_ISO_8859_10, /// Latin 6 (Nordic) 00110 FONTENCODING_THAI = FONTENCODING_ISO_8859_11, /// Thai 00111 FONTENCODING_BALTIC = FONTENCODING_ISO_8859_13, /// Latin 7 (Baltic Rim) 00112 FONTENCODING_CELTIC = FONTENCODING_ISO_8859_14 /// Latin 8 (Celtic) 00113 }; 00114 00115 00116 /// Font style 00117 struct FXFontDesc { 00118 FXchar face[116]; /// Face name 00119 FXushort size; /// Size in deci-points (one point is 1/72 inch) 00120 FXushort weight; /// Weight [light, normal, bold, ...] 00121 FXushort slant; /// Slant [normal, italic, oblique, ...] 00122 FXushort setwidth; /// Set width [normal, condensed, expanded, ...] 00123 FXushort encoding; /// Encoding of character set 00124 FXushort flags; /// Flags 00125 }; 00126 00127 00128 class FXDC; 00129 class FXDCWindow; 00130 00131 00132 /// Font class 00133 class FXAPI FXFont : public FXId { 00134 friend class FXDCWindow; 00135 FXDECLARE(FXFont) 00136 protected: 00137 FXString wantedName; // Desired font font name 00138 FXString actualName; // Matched font font name 00139 FXushort wantedSize; // Font size (points*10) 00140 FXushort actualSize; // Actual size that was matched 00141 FXushort wantedWeight; // Font weight 00142 FXushort actualWeight; // Font weight 00143 FXushort wantedSlant; // Font slant 00144 FXushort actualSlant; // Font slant 00145 FXushort wantedSetwidth; // Relative setwidth 00146 FXushort actualSetwidth; // Relative setwidth 00147 FXushort wantedEncoding; // Character set encoding 00148 FXushort actualEncoding; // Character set encoding 00149 FXushort hints; // Matching hint flags 00150 FXushort flags; // Actual flags 00151 FXshort angle; // Angle 00152 void *font; // Info about the font 00153 private: 00154 #ifdef WIN32 00155 FXID dc; 00156 #endif 00157 protected: 00158 FXFont(); 00159 void* match(const FXString& wantfamily,const FXString& wantforge,FXuint wantsize,FXuint wantweight,FXuint wantslant,FXuint wantsetwidth,FXuint wantencoding,FXuint wanthints,FXint res); 00160 private: 00161 FXFont(const FXFont&); 00162 FXFont &operator=(const FXFont&); 00163 public: 00164 00165 /// Font pitch hints 00166 enum { 00167 Fixed = 1, /// Fixed pitch, mono-spaced 00168 Variable = 2 /// Variable pitch, proportional spacing 00169 }; 00170 00171 /// Font style hints 00172 enum { 00173 Decorative = 4, /// Fancy fonts 00174 Modern = 8, /// Monospace typewriter font 00175 Roman = 16, /// Variable width times-like font, serif 00176 Script = 32, /// Script or cursive 00177 Swiss = 64, /// Helvetica/swiss type font, sans-serif 00178 System = 128, /// System font 00179 X11 = 256, /// Raw X11 font string 00180 Scalable = 512, /// Scalable fonts 00181 Polymorphic = 1024, /// Polymorphic fonts, e.g. parametric weight, slant, etc. 00182 Rotatable = 2048 /// Rotatable fonts 00183 }; 00184 00185 /// Font slant options 00186 enum { 00187 ReverseOblique = 1, /// Reversed oblique 00188 ReverseItalic = 2, /// Reversed italic 00189 Straight = 5, /// Straight, not slanted 00190 Italic = 8, /// Italics 00191 Oblique = 9 /// Oblique slant 00192 }; 00193 00194 /// Font weight options 00195 enum { 00196 Thin = 10, /// Thin 00197 ExtraLight = 20, /// Extra light 00198 Light = 30, /// Light 00199 Normal = 40, /// Normal or regular weight 00200 Medium = 50, /// Medium bold face 00201 DemiBold = 60, /// Demi bold face 00202 Bold = 70, /// Bold face 00203 ExtraBold = 80, /// Extra 00204 Black = 90 /// Black 00205 }; 00206 00207 /// Condensed or expanded options 00208 enum { 00209 UltraCondensed = 50, /// Ultra condensed printing 00210 ExtraCondensed = 63, /// Extra condensed 00211 Condensed = 75, /// Condensed 00212 SemiCondensed = 87, /// Semi-condensed 00213 NonExpanded = 100, /// Regular printing 00214 SemiExpanded = 113, /// Semi expanded 00215 Expanded = 125, /// Expanded 00216 ExtraExpanded = 150, /// Extra expanded 00217 UltraExpanded = 200 /// Ultra expanded 00218 }; 00219 00220 public: 00221 00222 /** 00223 * Construct a font with given font description of the form: 00224 * 00225 * fontname [ "[" foundry "]" ] ["," size ["," weight ["," slant ["," setwidth ["," encoding ["," hints]]]]]] 00226 * 00227 * For example: 00228 * 00229 * "helvetica [bitstream],120,bold,italic,normal,iso8859-1,0" 00230 * 00231 * Typically, at least the font name, and size must be given for 00232 * normal font matching. As a special case, raw X11 fonts can also be 00233 * passed, for example: 00234 * 00235 * "9x15bold" 00236 * 00237 * Note: use of the raw X11 fonts is stronly discouraged. 00238 */ 00239 FXFont(FXApp* a,const FXString& string); 00240 00241 /** 00242 * Construct a font with given name, size in points, weight, slant, character set 00243 * encoding, setwidth, and hints. 00244 * The font name may be comprised of a family name and optional foundry name enclosed in 00245 * square brackets, for example, "helvetica [bitstream]". 00246 */ 00247 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); 00248 00249 /// Construct font from font description 00250 FXFont(FXApp* a,const FXFontDesc& fontdesc); 00251 00252 /// Create the font 00253 virtual void create(); 00254 00255 /// Detach the font 00256 virtual void detach(); 00257 00258 /// Destroy the font 00259 virtual void destroy(); 00260 00261 /// Return family part of name 00262 FXString getFamily() const; 00263 00264 /// Return foundry part of name 00265 FXString getFoundry() const; 00266 00267 /// Get font family name 00268 const FXString& getName() const { return wantedName; } 00269 00270 /// Get actual family name 00271 const FXString& getActualName() const { return actualName; } 00272 00273 /// Get size in deci-points 00274 FXuint getSize() const { return wantedSize; } 00275 00276 /// Get actual size in deci-points 00277 FXuint getActualSize() const { return actualSize; } 00278 00279 /// Get font weight 00280 FXuint getWeight() const { return wantedWeight; } 00281 00282 /// Get actual font weight 00283 FXuint getActualWeight() const { return actualWeight; } 00284 00285 /// Get slant 00286 FXuint getSlant() const { return wantedSlant; } 00287 00288 /// Get actual slant 00289 FXuint getActualSlant() const { return actualSlant; } 00290 00291 /// Get character set encoding 00292 FXuint getEncoding() const { return wantedEncoding; } 00293 00294 /// Get actual encoding 00295 FXuint getActualEncoding() const { return actualEncoding; } 00296 00297 /// Get setwidth 00298 FXuint getSetWidth() const { return wantedSetwidth; } 00299 00300 /// Get actual setwidth 00301 FXuint getActualSetWidth() const { return actualSetwidth; } 00302 00303 /// Get hints 00304 FXuint getHints() const { return hints; } 00305 00306 /// Get flags 00307 FXuint getFlags() const { return flags; } 00308 00309 /// Change font description 00310 virtual void setFontDesc(const FXFontDesc& fontdesc); 00311 00312 /// Get font description 00313 FXFontDesc getFontDesc() const; 00314 00315 /// Get actual font description 00316 FXFontDesc getActualFontDesc() const; 00317 00318 /// Return angle 00319 FXint getAngle() const { return angle; } 00320 00321 /// Set to new angle, in degrees*64 relative to positive x axis 00322 virtual void setAngle(FXint ang); 00323 00324 /** 00325 * Return the font description as a string suitable for 00326 * parsing with setFont(), see above. 00327 */ 00328 FXString getFont() const; 00329 00330 /** 00331 * Change the font to the specified font description string. 00332 */ 00333 virtual void setFont(const FXString& string); 00334 00335 /// Find out if the font is monotype or proportional 00336 virtual FXbool isFontMono() const; 00337 00338 /// See if font has glyph for ch 00339 virtual FXbool hasChar(FXwchar ch) const; 00340 00341 /// Get first character glyph in font 00342 virtual FXwchar getMinChar() const; 00343 00344 /// Get last character glyph in font 00345 virtual FXwchar getMaxChar() const; 00346 00347 /// Left bearing 00348 virtual FXint leftBearing(FXwchar ch) const; 00349 00350 /// Right bearing 00351 virtual FXint rightBearing(FXwchar ch) const; 00352 00353 /// Width of widest character in font 00354 virtual FXint getFontWidth() const; 00355 00356 /// Height of highest character in font 00357 virtual FXint getFontHeight() const; 00358 00359 /// Ascent from baseline 00360 virtual FXint getFontAscent() const; 00361 00362 /// Descent from baseline 00363 virtual FXint getFontDescent() const; 00364 00365 /// Get font leading [that is lead-ing as in Pb!] 00366 virtual FXint getFontLeading() const; 00367 00368 /// Get font line spacing 00369 virtual FXint getFontSpacing() const; 00370 00371 /// Calculate width of single wide character in this font 00372 virtual FXint getCharWidth(const FXwchar ch) const; 00373 00374 /// Calculate width of given text in this font 00375 virtual FXint getTextWidth(const FXString& string) const; 00376 00377 /// Calculate width of given text in this font 00378 virtual FXint getTextWidth(const FXchar* string,FXuint length) const; 00379 00380 /// Calculate height of given text in this font 00381 virtual FXint getTextHeight(const FXString& string) const; 00382 00383 /// Calculate height of given text in this font 00384 virtual FXint getTextHeight(const FXchar *string,FXuint length) const; 00385 00386 /** 00387 * List all fonts matching hints. If listFonts() returns true then 00388 * fonts points to a newly-allocated array of length numfonts. It 00389 * is the caller's responsibility to free this array using FXFREE(). 00390 */ 00391 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); 00392 00393 /// Save font data into stream 00394 virtual void save(FXStream& store) const; 00395 00396 /// Load font data from stream 00397 virtual void load(FXStream& store); 00398 00399 /// Destroy font 00400 virtual ~FXFont(); 00401 }; 00402 00403 00404 } 00405 00406 #endif
![]() |