00001
00002
00003
00004 #ifndef _GDCFONT_H_
00005 #define _GDCFONT_H_
00006
00007 #include "string.h"
00008 #include "GRect.h"
00009 #include "GProperties.h"
00010
00012
00013
00014 #ifndef WIN32
00015
00016
00017 #define FW_DONTCARE 0
00018 #define FW_THIN 100
00019 #define FW_EXTRALIGHT 200
00020 #define FW_ULTRALIGHT 200
00021 #define FW_LIGHT 300
00022
00023 #define FW_NORMAL 400
00024 #define FW_REGULAR 400
00025 #define FW_MEDIUM 500
00026 #define FW_SEMIBOLD 600
00027 #define FW_DEMIBOLD 600
00028
00029 #define FW_BOLD 700
00030 #define FW_EXTRABOLD 800
00031 #define FW_ULTRABOLD 800
00032 #define FW_HEAVY 900
00033 #define FW_BLACK 900
00034
00035
00037 #define DEFAULT_QUALITY 0
00038
00039 #define ANTIALIASED_QUALITY 1
00040
00041 #define NONANTIALIASED_QUALITY 2
00042
00043 #elif defined WIN32
00044
00045 #define WESTEUROPE_CHARSET BALTIC_CHARSET // ??? don't know
00046
00047 #endif
00048
00049
00050 #if defined WIN32
00051
00052 typedef HFONT OsFont;
00053 #define PrevOsChar(Ptr) Ptr--
00054 #define NextOsChar(Ptr) Ptr++
00055
00056 #elif defined BEOS
00057
00058 typedef BFont *OsFont;
00059 #define PrevOsChar(Ptr) LgiPrevUtf8((char*&)Ptr)
00060 #define NextOsChar(Ptr) LgiNextUtf8((char*&)Ptr)
00061
00062 #elif defined LINUX
00063
00064 #include "LgiOsClasses.h"
00065 #define PrevOsChar(Ptr) Ptr--
00066 #define NextOsChar(Ptr) Ptr++
00067
00068 #endif
00069
00070 #define MAX_UNICODE 0xffff // maximum unicode char I can handle
00071 #define _HasUnicodeGlyph(map, u) ( (map[(u)>>3] & (1 << ((u) & 7))) != 0 )
00072
00074
00075
00077 LgiFunc inline char16 LgiUtf8To32(uint8 *&i, int &Len);
00079 LgiFunc inline void LgiUtf32To8(uint32 c, uint8 *&i, int &Len);
00081 LgiFunc inline uint32 LgiUtf16To32(char16 *&i, int &Len);
00083 LgiFunc inline void LgiUtf32To16(uint32 c, char16 *&i, int &Len);
00085 LgiFunc inline void LgiNextUtf8(char *&Ptr);
00087 LgiFunc inline void LgiPrevUtf8(char *&Ptr);
00088
00090
00091 class GFontType;
00092 class GDisplayString;
00093
00095 class LgiClass GTypeFace
00096 {
00097 protected:
00098 class GTypeFacePrivate *d;
00099
00100
00101 virtual void _OnPropChange(bool c) {}
00102
00103 public:
00104 GTypeFace();
00105 virtual ~GTypeFace();
00106
00108 void Face(char *s);
00110 void PointSize(int i);
00112 void TabSize(int i);
00114 void Quality(int i);
00116 void Fore(COLOUR c);
00121 void Back(COLOUR c);
00123 void SetWeight(int Weight);
00125 void Bold(bool i) { SetWeight(i ? FW_BOLD : FW_NORMAL); }
00127 void Italic(bool i);
00129 void Underline(bool i);
00131 void Transparent(bool i);
00133 void SubGlyphs(bool i);
00134
00136 char *Face();
00138 int PointSize();
00140 int TabSize();
00142 int Quality();
00144 COLOUR Fore();
00146 COLOUR Back();
00148 int GetWeight();
00150 bool Bold() { return GetWeight() >= FW_BOLD; }
00152 bool Italic();
00154 bool Underline();
00156 bool Transparent();
00158 bool SubGlyphs();
00160 double Ascent();
00162 double Descent();
00163
00164
00165
00166
00167
00168
00169
00170
00173 virtual void Colour(COLOUR Fore, COLOUR Back = 0xFFFFFFFF);
00174 };
00175
00214 class LgiClass GFont :
00215 public GTypeFace
00216 {
00217 friend class GFontSystem;
00218 friend class GDisplayString;
00219
00220 class GFontPrivate *d;
00221
00222
00223 bool IsValid();
00224 void _OnPropChange(bool Change);
00225 char16 *_ToUnicode(char *In, int &Len);
00226 bool GetOwnerUnderline();
00227 uchar *GetGlyphMap();
00228
00230 void _Measure
00231 (
00233 int &x,
00235 int &y,
00237 OsChar *Str,
00239 int Len
00240 );
00243 int _CharAt
00244 (
00246 int x,
00248 OsChar *Str,
00250 int Len
00251 );
00253 void _Draw
00254 (
00256 GSurface *pDC,
00258 int x,
00260 int y,
00262 OsChar *Str,
00264 int Len,
00266 GRect *r
00267 );
00268
00269 public:
00271 GFont
00272 (
00274 char *face = 0,
00276 int point = -1
00277 );
00279 GFont(OsFont Handle);
00281 GFont(GFontType &Type);
00283 GFont(GFont &Fnt);
00284 ~GFont();
00285
00287 bool Create
00288 (
00290 char *Face = 0,
00292 int PtSize = -1,
00295 int Param = 0
00296 );
00298 bool Create(GFontType *Type, int Param = 0);
00300 OsFont Handle();
00302 GFont &operator =(GFont &f);
00304 int GetHeight();
00306 int GetParam();
00307
00309 void Text
00310 (
00312 GSurface *pDC,
00314 int x,
00316 int y,
00318 char *Str,
00320 int Len = -1,
00322 GRect *r = 0,
00324 int TabOrigin = 0
00325 );
00327 void Size
00328 (
00330 int *x,
00332 int *y,
00334 char *Str,
00336 int Len = -1,
00338 int Flags = 0
00339 );
00341 int X(char *Str, int Len = -1);
00343 int Y(char *Str, int Len = -1);
00345 int CharAt
00346 (
00348 int x,
00350 char *Str,
00352 int Len = -1,
00354 int TabOffset = 0
00355 );
00356
00358 void TextW
00359 (
00361 GSurface *pDC,
00363 int x,
00365 int y,
00367 char16 *Str,
00369 int Len = -1,
00371 GRect *r = 0,
00373 int TabOrigin = 0
00374 );
00376 void SizeW
00377 (
00379 int *x,
00381 int *y,
00383 char16 *Str,
00385 int Len = -1,
00387 int Flags = 0
00388 );
00390 int XW(char16 *Str, int Len = -1);
00392 int YW(char16 *Str, int Len = -1);
00394 int CharAtW
00395 (
00397 int x,
00399 char16 *Str,
00401 int Len = -1,
00403 int TabOffset = 0
00404 );
00405 };
00406
00408 class LgiClass GFontType
00409 {
00410 friend class GFont;
00411 friend class GTypeFace;
00412
00413 protected:
00414 #if defined WIN32
00415 LOGFONT Info;
00416 #else
00417 GTypeFace Info;
00418 #endif
00419
00420 public:
00421 GFontType(char *face = 0, int pointsize = 0);
00422 virtual ~GFontType();
00423
00424 #ifdef WIN32
00425 LOGFONT *Handle() { return &Info; }
00426 #else
00427 GTypeFace *Handle() { return &Info; }
00428 #endif
00429
00431 char *GetFace();
00432
00434 void SetFace(char *Face);
00435
00437 int GetPointSize();
00438
00440 void SetPointSize(int PointSize);
00441
00443 bool DoUI(GView *Parent);
00444
00446 bool GetDescription(char *Str);
00447
00449 bool Serialize(ObjProperties *Options, char *OptName, bool Write);
00450
00452 bool GetConfigFont(char *Tag);
00453
00455 bool GetSystemFont(char *Which);
00456
00458 bool GetFromRef(OsFont Handle);
00459
00461 virtual GFont *Create(int Param = 0);
00462 };
00463
00465 enum GCharSetType
00466 {
00467 CpNone,
00468 CpMapped,
00469 CpUtf8,
00470 CpWide,
00471 CpIconv,
00472 CpWindowsDb
00473 };
00474
00476 class LgiClass GCharset
00477 {
00478 public:
00480 char *Charset;
00482 char *Description;
00484 short *UnicodeMap;
00486 char *IconvName;
00488 char *AlternateNames;
00490 GCharSetType Type;
00491
00493 GCharset(char *cp = 0, char *des = 0, short *map = 0, char *alt = 0);
00494
00496 bool IsUnicode();
00498 char *GetIconvName();
00500 bool IsAvailable();
00501 };
00502
00517 class LgiClass GDisplayString
00518 {
00519 OsChar *Str;
00520 GFont *Font;
00521 int x, y, len, TabOrigin;
00522 int Blocks;
00523 class CharInfo *Info;
00524 uint8 Flags;
00525
00526 void Layout();
00527
00528 public:
00530 GDisplayString
00531 (
00533 GFont *f,
00535 char *s,
00537 int l = -1,
00538 int tabOrigin = 0
00539 );
00541 GDisplayString
00542 (
00544 GFont *f,
00546 char16 *s,
00548 int l = -1,
00549 int tabOrigin = 0
00550 );
00551 virtual ~GDisplayString();
00552
00555 bool ShowVisibleTab();
00558 void ShowVisibleTab(bool i);
00559 GFont *GetFont() { return Font; };
00560
00562 void TruncateWithDots
00563 (
00565 int Width
00566 );
00568 bool IsTruncated();
00569
00571 int Length();
00573 void Length(int NewLen);
00574
00576 operator OsChar*() { return Str; }
00577
00579 int X();
00581 int Y();
00583 void Size(int *x, int *y);
00585 int CharAt(int x);
00586
00588 void Draw
00589 (
00591 GSurface *pDC,
00593 int x,
00595 int y,
00597 GRect *r = 0
00598 );
00599 };
00600
00602 class LgiClass GCharsetSystem
00603 {
00604
00605 GHashTable *Charsets;
00606
00607 public:
00608 GCharsetSystem();
00609 ~GCharsetSystem();
00610
00611
00612 GCharset *GetCsInfo(char *Cp);
00613 GCharset *GetCsList();
00614 };
00615
00617 LgiFunc GCharset *LgiGetCsInfo(char *Cs);
00620 LgiFunc GCharset *LgiGetCsList();
00621
00623 class LgiClass GFontSystem
00624 {
00625 friend class GApp;
00626 friend class GDisplayString;
00627
00628 static GFontSystem *Me;
00629
00630 private:
00631
00632 List<char> AllFonts;
00633 List<char> SubFonts;
00634
00635
00636 uchar Lut[MAX_UNICODE+1];
00637 GFont *Font[256];
00638 class GFontSystemPrivate *d;
00639
00640 public:
00642 static GFontSystem *Inst();
00643
00644
00645 GFontSystem();
00646 ~GFontSystem();
00647
00649 bool EnumerateFonts(List<char> &Fonts);
00650
00652 bool GetGlyphSubSupport();
00654 bool GetDefaultGlyphSub();
00656 void SetDefaultGlyphSub(bool i);
00658 GFont *GetGlyph
00659 (
00661 int u,
00663 GFont *UserFont
00664 );
00668 GFont *GetBestFont(char *Str);
00669 };
00670
00671 #endif