Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXFont.h

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.42 2004/01/21 07:09:58 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          encoding;                 /// Encoding of character set
00188   FXuint          setwidth;                 /// Set width [normal, condensed, expanded, ...]
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  name;                 // Name of the font, e.g. "helvetica [adobe]"
00199   FXuint    size;                 // Font size (points*10)
00200   FXuint    weight;               // Font weight
00201   FXuint    slant;                // Font slant
00202   FXuint    encoding;             // Character set encoding
00203   FXuint    setwidth;             // Relative setwidth
00204   FXuint    hints;                // Matching hints
00205   void     *font;                 // Info about the font
00206 private:
00207 #ifdef WIN32
00208   FXID      dc;                   // Dummy
00209 #endif
00210 protected:
00211   FXFont();
00212 #ifndef WIN32
00213   char* findbestfont(char* fontname) const;
00214   char* findmatch(char* fontname,const char* forge,const char* family) const;
00215 #endif
00216 private:
00217   FXFont(const FXFont&);
00218   FXFont &operator=(const FXFont&);
00219 public:
00220 
00221   /// Construct font from font description
00222   FXFont(FXApp* a,const FXFontDesc& fontdesc);
00223 
00224   /**
00225   * Construct a font with given face name, size in points, weight, slant, character set
00226   * encoding, setwidth, and hints.
00227   * The font name may be suffixed by a foundry name, enclosed in square brackets;
00228   * for example, "times [urw]".
00229   */
00230   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);
00231 
00232   /**
00233   * Construct a font with given font description of the form:
00234   *
00235   *     fontname [ "[" foundry "]" ] ["," size ["," weight ["," slant ["," setwidth ["," encoding ["," hints]]]]]]
00236   *
00237   * For example:
00238   *
00239   *     "helvetica [bitstream],12,bold,i,normal,iso8859-1,0"
00240   *
00241   * Typically, at least the font name, and size must be given for
00242   * normal font matching.  As a special case, raw X11 fonts can also be
00243   * passed, for example:
00244   *
00245   *     "9x15bold"
00246   *
00247   * Finally, an old FOX 1.0 style font string may be passed as well:
00248   *
00249   *     "[helvetica] 90 700 1 1 0 0"
00250   *
00251   */
00252   FXFont(FXApp* a,const FXString& string);
00253 
00254   /// Create the font
00255   virtual void create();
00256 
00257   /// Detach the font
00258   virtual void detach();
00259 
00260   /// Destroy the font
00261   virtual void destroy();
00262 
00263   /// Get face name
00264   FXString getName() const { return name; }
00265 
00266   /// Get size in deci-points
00267   FXuint getSize() const { return size; }
00268 
00269   /// Get font weight
00270   FXuint getWeight() const { return weight; }
00271 
00272   /// Get slant
00273   FXuint getSlant() const { return slant; }
00274 
00275   /// Get character set encoding
00276   FXuint getEncoding() const { return encoding; }
00277 
00278   /// Get setwidth
00279   FXuint getSetWidth() const { return setwidth; }
00280 
00281   /// Get hints
00282   FXuint getHints() const { return hints; }
00283 
00284   /// Get font description
00285   void getFontDesc(FXFontDesc& fontdesc) const;
00286 
00287   /// Change font description
00288   void setFontDesc(const FXFontDesc& fontdesc);
00289 
00290   /**
00291   * Change the font to the specified font description string.
00292   */
00293   FXbool setFont(const FXString& string);
00294 
00295   /**
00296   * Return the font description as a string suitable for
00297   * parsing with setFont(), see above.
00298   */
00299   FXString getFont() const;
00300 
00301   /// Find out if the font is monotype or proportional
00302   FXbool isFontMono() const;
00303 
00304   /// See if font has glyph for ch
00305   FXbool hasChar(FXint ch) const;
00306 
00307   /// Get first character glyph in font
00308   FXint getMinChar() const;
00309 
00310   /// Get last character glyph in font
00311   FXint getMaxChar() const;
00312 
00313   /// Left bearing
00314   FXint leftBearing(FXchar ch) const;
00315 
00316   /// Right bearing
00317   FXint rightBearing(FXchar ch) const;
00318 
00319   /// Width of widest character in font
00320   FXint getFontWidth() const;
00321 
00322   /// Height of highest character in font
00323   FXint getFontHeight() const;
00324 
00325   /// Ascent from baseline
00326   FXint getFontAscent() const;
00327 
00328   /// Descent from baseline
00329   FXint getFontDescent() const;
00330 
00331   /// Get font leading [that is lead-ing as in Pb!]
00332   FXint getFontLeading() const;
00333 
00334   /// Get font line spacing
00335   FXint getFontSpacing() const;
00336 
00337   /// Calculate width of given text in this font
00338   FXint getTextWidth(const FXchar *text,FXuint n) const;
00339 
00340   /// Calculate width of given text in this font
00341   FXint getTextWidth(const FXString& text) const;
00342 
00343   /// Calculate height of given text in this font
00344   FXint getTextHeight(const FXchar *text,FXuint n) const;
00345 
00346   /// Calculate height of given text in this font
00347   FXint getTextHeight(const FXString& text) const;
00348 
00349   /**
00350    * List all fonts matching hints. If listFonts() returns TRUE then
00351    * fonts points to a newly-allocated array of length numfonts. It
00352    * is the caller's responsibility to free this array using FXFREE().
00353    */
00354   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);
00355 
00356   /// Save font data into stream
00357   virtual void save(FXStream& store) const;
00358 
00359   /// Load font data from stream
00360   virtual void load(FXStream& store);
00361 
00362   /// Destroy font
00363   virtual ~FXFont();
00364   };
00365 
00366 
00367 
00368 /// DEPRECATED: Parse font description from a string
00369 extern FXAPI FXbool fxparsefontdesc(FXFontDesc& fontdesc,const FXchar* string);
00370 
00371 /// DEPRECATED: Unparse font description into a string
00372 extern FXAPI FXbool fxunparsefontdesc(FXchar *string,const FXFontDesc& fontdesc);
00373 
00374 }
00375 
00376 #endif

Copyright © 1997-2004 Jeroen van der Zijp