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
00015
00016
00017 #ifndef WIN32
00018
00019
00020 #define FW_DONTCARE 0
00021 #define FW_THIN 100
00022 #define FW_EXTRALIGHT 200
00023 #define FW_ULTRALIGHT 200
00024 #define FW_LIGHT 300
00026 #define FW_NORMAL 400
00027 #define FW_REGULAR 400
00028 #define FW_MEDIUM 500
00029 #define FW_SEMIBOLD 600
00030 #define FW_DEMIBOLD 600
00032 #define FW_BOLD 700
00033 #define FW_EXTRABOLD 800
00034 #define FW_ULTRABOLD 800
00035 #define FW_HEAVY 900
00036 #define FW_BLACK 900
00037
00038
00040 #define DEFAULT_QUALITY 0
00042 #define ANTIALIASED_QUALITY 1
00044 #define NONANTIALIASED_QUALITY 2
00045
00046 #elif defined WIN32
00047
00048 #define WESTEUROPE_CHARSET BALTIC_CHARSET // ??? don't know
00049
00050 #endif
00051
00052
00053 #if defined __GTK_H__
00054
00055 #include "LgiOsClasses.h"
00056 #define PrevOsChar(Ptr) Ptr--
00057 #define NextOsChar(Ptr) Ptr++
00058
00059 #elif defined(WIN32)
00060
00061 typedef HFONT OsFont;
00062 #define PrevOsChar(Ptr) Ptr--
00063 #define NextOsChar(Ptr) Ptr++
00064
00065 #elif defined(BEOS)
00066
00067 typedef BFont *OsFont;
00068 #define PrevOsChar(Ptr) LgiPrevUtf8((char*&)Ptr)
00069 #define NextOsChar(Ptr) LgiNextUtf8((char*&)Ptr)
00070
00071 #endif
00072
00073 #define MAX_UNICODE 0xffff // maximum unicode char I can handle
00074 #define _HasUnicodeGlyph(map, u) ( (map[(u)>>3] & (1 << ((u) & 7))) != 0 )
00075
00077
00078 class GFontType;
00079 class GDisplayString;
00080
00082 class LgiClass GTypeFace
00083 {
00084 protected:
00085 class GTypeFacePrivate *d;
00086
00087
00088 virtual void _OnPropChange(bool c) {}
00089
00090 public:
00091 GTypeFace();
00092 virtual ~GTypeFace();
00093
00095 void Face(char *s);
00097 void PointSize(int i);
00099 void TabSize(int i);
00101 void Quality(int i);
00103 void Fore(COLOUR c);
00108 void Back(COLOUR c);
00110 void SetWeight(int Weight);
00112 void Bold(bool i) { SetWeight(i ? FW_BOLD : FW_NORMAL); }
00114 void Italic(bool i);
00116 void Underline(bool i);
00118 void Transparent(bool i);
00120 void SubGlyphs(bool i);
00121
00123 char *Face();
00125 int PointSize();
00127 int TabSize();
00129 int Quality();
00131 COLOUR Fore();
00133 COLOUR Back();
00135 int GetWeight();
00137 bool Bold() { return GetWeight() >= FW_BOLD; }
00139 bool Italic();
00141 bool Underline();
00143 bool Transparent();
00145 bool SubGlyphs();
00147 double Ascent();
00149 double Descent();
00150
00152 bool operator ==(GTypeFace &t);
00153
00156 virtual void Colour(COLOUR Fore, COLOUR Back = 0xFFFFFFFF);
00157
00159 virtual void Colour32(COLOUR Fore32, COLOUR Back32 = 0xFFFFFFFF);
00160 };
00161
00163 class LgiClass GFont :
00164 public GTypeFace
00165 {
00166 friend class GFontSystem;
00167
00168 class GFontPrivate *d;
00169
00170
00171 bool IsValid();
00172 void _OnPropChange(bool Change);
00173 char16 *_ToUnicode(char *In, int &Len);
00174 bool GetOwnerUnderline();
00175
00176 #if WIN32NATIVE
00177 friend class GDisplayString;
00178
00179 void _Measure(int &x, int &y, OsChar *Str, int Len);
00180 int _CharAt(int x, OsChar *Str, int Len);
00181 void _Draw(GSurface *pDC, int x, int y, OsChar *Str, int Len, GRect *r);
00182 #endif
00183
00184 public:
00186 GFont
00187 (
00189 char *face = 0,
00191 int point = -1
00192 );
00194 GFont(OsFont Handle);
00196 GFont(GFontType &Type);
00198 GFont(GFont &Fnt);
00199 ~GFont();
00200
00202 bool Create
00203 (
00205 char *Face = 0,
00207 int PtSize = -1,
00210 int Param = 0
00211 );
00213 bool Create(GFontType *Type, int Param = 0);
00215 bool Destroy();
00217 OsFont Handle();
00219 GFont &operator =(GFont &f);
00221 int GetHeight();
00223 int GetParam();
00225 uchar *GetGlyphMap();
00227 double GetAscent();
00229 double GetDescent();
00230 };
00231
00233 class LgiClass GFontType
00234 {
00235 friend class GFont;
00236 friend class GTypeFace;
00237
00238 protected:
00239 #if defined WIN32
00240 LOGFONT Info;
00241 #else
00242 GTypeFace Info;
00243 #endif
00244
00245 public:
00246 GFontType(char *face = 0, int pointsize = 0);
00247 virtual ~GFontType();
00248
00249 #ifdef WIN32
00250 LOGFONT *Handle() { return &Info; }
00251 #else
00252 GTypeFace *Handle() { return &Info; }
00253 #endif
00254
00256 char *GetFace();
00257
00259 void SetFace(char *Face);
00260
00262 int GetPointSize();
00263
00265 void SetPointSize(int PointSize);
00266
00268 bool DoUI(GView *Parent);
00269
00271 bool GetDescription(char *Str);
00272
00274
00276 bool Serialize(GDom *Options, char *OptName, bool Write);
00277
00279 bool GetConfigFont(char *Tag);
00280
00282 bool GetSystemFont(char *Which);
00283
00285 bool GetFromRef(OsFont Handle);
00286
00288 virtual GFont *Create(int Param = 0);
00289 };
00290
00292 enum GCharSetType
00293 {
00294 CpNone,
00295 CpMapped,
00296 CpUtf8,
00297 CpWide,
00298 CpIconv,
00299 CpWindowsDb
00300 };
00301
00303 class LgiClass GCharset
00304 {
00305 public:
00307 char *Charset;
00309 char *Description;
00311 short *UnicodeMap;
00313 char *IconvName;
00315 char *AlternateNames;
00317 GCharSetType Type;
00318
00320 GCharset(char *cp = 0, char *des = 0, short *map = 0, char *alt = 0);
00321
00323 bool IsUnicode();
00325 char *GetIconvName();
00327 bool IsAvailable();
00328 };
00329
00330 #include "GDisplayString.h"
00331
00333 class LgiClass GCharsetSystem
00334 {
00335 struct GCharsetSystemPriv *d;
00336
00337 public:
00338 GCharsetSystem();
00339 ~GCharsetSystem();
00340
00341
00342 GCharset *GetCsInfo(char *Cp);
00343 GCharset *GetCsList();
00344 };
00345
00347 LgiFunc GCharset *LgiGetCsInfo(char *Cs);
00350 LgiFunc GCharset *LgiGetCsList();
00352 LgiFunc char *LgiDetectCharset
00353 (
00355 char *Utf8,
00357 int Len = -1,
00359 List<char> *Prefs = 0
00360 );
00361
00362 #if defined(LGI_STATIC)
00363 #undef HAS_ICONV
00364 #endif
00365
00366 #if HAS_ICONV
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 #ifdef __MINGW32__
00381 #include "../iconv.h"
00382 #else
00383 #include "iconv.h"
00384 #endif
00385
00386 #ifdef WIN32
00387 typedef const char IconvChar;
00388 #else
00389 typedef char IconvChar;
00390 #endif
00391 #endif
00392
00394 class LgiClass GFontSystem : public GLibrary
00395 {
00396 friend class GApp;
00397 friend class GDisplayString;
00398
00399 static GFontSystem *Me;
00400
00401 private:
00402
00403 List<char> AllFonts;
00404 List<char> SubFonts;
00405
00406
00407 uchar Lut[MAX_UNICODE+1];
00408 GFont *Font[256];
00409 class GFontSystemPrivate *d;
00410
00411 public:
00413 static GFontSystem *Inst();
00414
00415
00416 GFontSystem();
00417 ~GFontSystem();
00418
00420 bool EnumerateFonts(List<char> &Fonts);
00421
00423 bool GetGlyphSubSupport();
00425 bool GetDefaultGlyphSub();
00427 void SetDefaultGlyphSub(bool i);
00429 GFont *GetGlyph
00430 (
00432 int u,
00434 GFont *UserFont
00435 );
00439 GFont *GetBestFont(char *Str);
00440
00441 #ifdef __GTK_H__
00442
00443
00444 Gtk::PangoFontMap *GetFontMap();
00445 Gtk::PangoContext *GetContext();
00446
00447 #endif
00448
00449 #if HAS_ICONV
00450 #ifdef WIN32
00451
00452 DynFunc2(iconv_t, libiconv_open, const char*, tocode, const char*, fromcode);
00453 DynFunc5( size_t,
00454 libiconv,
00455 iconv_t, cd,
00456 IconvChar**, inbuf,
00457 size_t*, inbytesleft,
00458 char**, outbuf,
00459 size_t*, outbytesleft);
00460 DynFunc1(int, libiconv_close, iconv_t, cd);
00461
00462 #else
00463
00464
00465 iconv_t libiconv_open(const char *tocode, const char *fromcode)
00466 {
00467 return ::iconv_open(tocode, fromcode);
00468 }
00469
00470 size_t libiconv(iconv_t cd, IconvChar** inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
00471 {
00472 return ::iconv(cd,
00473 #ifdef LINUX
00474 (char**)
00475 #else
00476 (const char**)
00477 #endif
00478 inbuf, inbytesleft, outbuf, outbytesleft);
00479 }
00480
00481 int libiconv_close(iconv_t cd)
00482 {
00483 return ::iconv_close(cd);
00484 }
00485
00486 bool IsLoaded()
00487 {
00488 return true;
00489 }
00490
00491 #endif
00492 #endif // HAS_ICONV
00493 };
00494
00495 #ifdef LINUX
00496 extern bool _GetSystemFont(char *FontType, char *Font, int FontBufSize, int &PointSize);
00497 #endif
00498
00499
00500 #endif