00001
00002
00003
00004 #ifndef _GDCFONT_H_
00005 #define _GDCFONT_H_
00006
00007 #include "string.h"
00008 #include "GRect.h"
00009
00010 #include "LgiOsClasses.h"
00011 #include "GLibrary.h"
00012 #include "GLibraryUtils.h"
00013 #include "GColour.h"
00014
00016
00017
00018 #ifndef WIN32
00019
00020
00021 #define FW_DONTCARE 0
00022 #define FW_THIN 100
00023 #define FW_EXTRALIGHT 200
00024 #define FW_ULTRALIGHT 200
00025 #define FW_LIGHT 300
00027 #define FW_NORMAL 400
00028 #define FW_REGULAR 400
00029 #define FW_MEDIUM 500
00030 #define FW_SEMIBOLD 600
00031 #define FW_DEMIBOLD 600
00033 #define FW_BOLD 700
00034 #define FW_EXTRABOLD 800
00035 #define FW_ULTRABOLD 800
00036 #define FW_HEAVY 900
00037 #define FW_BLACK 900
00038
00039
00041 #define DEFAULT_QUALITY 0
00043 #define ANTIALIASED_QUALITY 1
00045 #define NONANTIALIASED_QUALITY 2
00046
00047 #elif defined WIN32
00048
00049 #define WESTEUROPE_CHARSET BALTIC_CHARSET // ??? don't know
00050
00051 #endif
00052
00053
00054 #if defined __GTK_H__
00055
00056 #include "LgiOsClasses.h"
00057 #define PrevOsChar(Ptr) Ptr--
00058 #define NextOsChar(Ptr) Ptr++
00059
00060 #elif defined(WIN32)
00061
00062 typedef HFONT OsFont;
00063 #define PrevOsChar(Ptr) Ptr--
00064 #define NextOsChar(Ptr) Ptr++
00065
00066 #elif defined(BEOS)
00067
00068 typedef BFont *OsFont;
00069 #define PrevOsChar(Ptr) LgiPrevUtf8((char*&)Ptr)
00070 #define NextOsChar(Ptr) LgiNextUtf8((char*&)Ptr)
00071
00072 #endif
00073
00074 #define MAX_UNICODE 0xffff // maximum unicode char I can handle
00075 #define _HasUnicodeGlyph(map, u) ( (map[(u)>>3] & (1 << ((u) & 7))) != 0 )
00076
00078
00079 class GFontType;
00080 class GDisplayString;
00081
00083 class LgiClass GTypeFace
00084 {
00085 protected:
00086 class GTypeFacePrivate *d;
00087
00088
00089 virtual void _OnPropChange(bool c) {}
00090
00091 public:
00092 GTypeFace();
00093 virtual ~GTypeFace();
00094
00096 void Face(const char *s);
00098 void PointSize(int i);
00100 void TabSize(int i);
00102 void Quality(int i);
00104 void Fore(COLOUR c);
00105 void Fore(GColour c);
00110 void Back(COLOUR c);
00111 void Back(GColour c);
00113 void SetWeight(int Weight);
00115 void Bold(bool i) { SetWeight(i ? FW_BOLD : FW_NORMAL); }
00117 void Italic(bool i);
00119 void Underline(bool i);
00121 void Transparent(bool i);
00123 void SubGlyphs(bool i);
00124
00126 char *Face();
00128 int PointSize();
00130 int TabSize();
00132 int Quality();
00134 GColour Fore();
00136 GColour Back();
00138 int GetWeight();
00140 bool Bold() { return GetWeight() >= FW_BOLD; }
00142 bool Italic();
00144 bool Underline();
00146 bool Transparent();
00148 bool SubGlyphs();
00150 double Ascent();
00152 double Descent();
00153
00155 bool operator ==(GTypeFace &t);
00156
00159 virtual void Colour(COLOUR Fore, COLOUR Back = 0xFFFFFFFF);
00160
00162 virtual void Colour(GColour Fore, GColour Back);
00163 };
00164
00166 class LgiClass GFont :
00167 public GTypeFace
00168 {
00169 friend class GFontSystem;
00170
00171 class GFontPrivate *d;
00172
00173
00174 bool IsValid();
00175 void _OnPropChange(bool Change);
00176 char16 *_ToUnicode(char *In, int &Len);
00177 bool GetOwnerUnderline();
00178
00179 #if WIN32NATIVE
00180 friend class GDisplayString;
00181
00182 void _Measure(int &x, int &y, OsChar *Str, int Len);
00183 int _CharAt(int x, OsChar *Str, int Len);
00184 void _Draw(GSurface *pDC, int x, int y, OsChar *Str, int Len, GRect *r);
00185 #endif
00186
00187 public:
00189 GFont
00190 (
00192 char *face = 0,
00194 int point = -1
00195 );
00197 GFont(OsFont Handle);
00199 GFont(GFontType &Type);
00201 GFont(GFont &Fnt);
00202 ~GFont();
00203
00205 bool Create
00206 (
00208 const char *Face = 0,
00210 int PtSize = -1,
00213 int Param = 0
00214 );
00216 bool Create(GFontType *Type, int Param = 0);
00218 bool Destroy();
00220 OsFont Handle();
00222 GFont &operator =(GFont &f);
00224 int GetHeight();
00226 int GetParam();
00228 uchar *GetGlyphMap();
00230 double GetAscent();
00232 double GetDescent();
00233 };
00234
00236 class LgiClass GFontType
00237 {
00238 friend class GFont;
00239 friend class GTypeFace;
00240
00241 protected:
00242 #if defined WIN32
00243 LOGFONT Info;
00244 #else
00245 GTypeFace Info;
00246 #endif
00247
00248 public:
00249 GFontType(const char *face = 0, int pointsize = 0);
00250 virtual ~GFontType();
00251
00252 #ifdef WIN32
00253 LOGFONT *Handle() { return &Info; }
00254 #else
00255 GTypeFace *Handle() { return &Info; }
00256 #endif
00257
00259 char *GetFace();
00260
00262 void SetFace(const char *Face);
00263
00265 int GetPointSize();
00266
00268 void SetPointSize(int PointSize);
00269
00271 bool DoUI(GView *Parent);
00272
00274 bool GetDescription(char *Str);
00275
00277
00279 bool Serialize(GDom *Options, const char *OptName, bool Write);
00280
00282 bool GetConfigFont(const char *Tag);
00283
00285 bool GetSystemFont(const char *Which);
00286
00288 bool GetFromRef(OsFont Handle);
00289
00291 virtual GFont *Create(int Param = 0);
00292 };
00293
00295 enum GCharSetType
00296 {
00297 CpNone,
00298 CpMapped,
00299 CpUtf8,
00300 CpWide,
00301 CpIconv,
00302 CpWindowsDb
00303 };
00304
00306 class LgiClass GCharset
00307 {
00308 public:
00310 const char *Charset;
00312 const char *Description;
00314 short *UnicodeMap;
00316 const char *IconvName;
00318 const char *AlternateNames;
00320 GCharSetType Type;
00321
00323 GCharset(const char *cp = 0, const char *des = 0, short *map = 0, const char *alt = 0);
00324
00326 bool IsUnicode();
00328 const char *GetIconvName();
00330 bool IsAvailable();
00331 };
00332
00333 #include "GDisplayString.h"
00334
00336 class LgiClass GCharsetSystem
00337 {
00338 struct GCharsetSystemPriv *d;
00339
00340 public:
00341 GCharsetSystem();
00342 ~GCharsetSystem();
00343
00344
00345 GCharset *GetCsInfo(const char *Cp);
00346 GCharset *GetCsList();
00347 };
00348
00350 LgiFunc GCharset *LgiGetCsInfo(const char *Cs);
00353 LgiFunc GCharset *LgiGetCsList();
00355 LgiFunc const char *LgiDetectCharset
00356 (
00358 const char *Utf8,
00360 int Len = -1,
00362 List<char> *Prefs = 0
00363 );
00364
00365 #if defined(LGI_STATIC)
00366 #undef HAS_ICONV
00367 #endif
00368
00369 #if HAS_ICONV
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 #ifdef __MINGW32__
00384 #include "../iconv.h"
00385 #else
00386 #include "iconv.h"
00387 #endif
00388
00389 #if defined(WIN32)
00390 typedef const char IconvChar;
00391 #else
00392 typedef char IconvChar;
00393 #endif
00394 #endif
00395
00397 class LgiClass GFontSystem : public GLibrary
00398 {
00399 friend class GApp;
00400 friend class GDisplayString;
00401
00402 static GFontSystem *Me;
00403
00404 private:
00405
00406 List<const char> AllFonts;
00407 List<const char> SubFonts;
00408
00409
00410 uchar Lut[MAX_UNICODE+1];
00411 GFont *Font[256];
00412 class GFontSystemPrivate *d;
00413
00414 public:
00416 static GFontSystem *Inst();
00417
00418
00419 GFontSystem();
00420 ~GFontSystem();
00421
00423 bool EnumerateFonts(List<const char> &Fonts);
00424
00426 bool GetGlyphSubSupport();
00428 bool GetDefaultGlyphSub();
00430 void SetDefaultGlyphSub(bool i);
00432 GFont *GetGlyph
00433 (
00435 int u,
00437 GFont *UserFont
00438 );
00442 GFont *GetBestFont(char *Str);
00443
00444 #ifdef __GTK_H__
00445
00446
00447 Gtk::PangoFontMap *GetFontMap();
00448 Gtk::PangoContext *GetContext();
00449
00450 #endif
00451
00452 #if HAS_ICONV
00453 #ifdef WIN32
00454
00455 DynFunc2(iconv_t, libiconv_open, const char*, tocode, const char*, fromcode);
00456 DynFunc5( size_t,
00457 libiconv,
00458 iconv_t, cd,
00459 IconvChar**, inbuf,
00460 size_t*, inbytesleft,
00461 char**, outbuf,
00462 size_t*, outbytesleft);
00463 DynFunc1(int, libiconv_close, iconv_t, cd);
00464
00465 #elif !defined(MAC)
00466
00467
00468 iconv_t libiconv_open(const char *tocode, const char *fromcode)
00469 {
00470 return ::iconv_open(tocode, fromcode);
00471 }
00472
00473 size_t libiconv(iconv_t cd, IconvChar** inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
00474 {
00475 return ::iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
00476 }
00477
00478 int libiconv_close(iconv_t cd)
00479 {
00480 return ::iconv_close(cd);
00481 }
00482
00483 bool IsLoaded()
00484 {
00485 return true;
00486 }
00487
00488 #endif
00489 #endif // HAS_ICONV
00490 };
00491
00492 #ifdef LINUX
00493 extern bool _GetSystemFont(char *FontType, char *Font, int FontBufSize, int &PointSize);
00494 #endif
00495
00496
00497 #endif