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