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