00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TGFont
00013 #define ROOT_TGFont
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef ROOT_TNamed
00026 #include "TNamed.h"
00027 #endif
00028 #ifndef ROOT_TGObject
00029 #include "TGObject.h"
00030 #endif
00031 #ifndef ROOT_TRefCnt
00032 #include "TRefCnt.h"
00033 #endif
00034
00035 class THashTable;
00036 class TObjString;
00037 class TGFont;
00038
00039
00040
00041 enum ETextLayoutFlags {
00042 kTextWholeWords = BIT(0),
00043 kTextAtLeastOne = BIT(1),
00044 kTextPartialOK = BIT(2),
00045 kTextIgnoreTabs = BIT(3),
00046 kTextIgnoreNewlines = BIT(4)
00047 };
00048
00049 enum EFontWeight {
00050 kFontWeightNormal = 0,
00051 kFontWeightMedium = 0,
00052 kFontWeightBold = 1,
00053 kFontWeightLight = 2,
00054 kFontWeightDemibold = 3,
00055 kFontWeightBlack = 4,
00056 kFontWeightUnknown = -1
00057 };
00058
00059 enum EFontSlant {
00060 kFontSlantRoman = 0,
00061 kFontSlantItalic = 1,
00062 kFontSlantOblique = 2,
00063 kFontSlantUnknown = -1
00064 };
00065
00066
00067 struct FontMetrics_t {
00068 Int_t fAscent;
00069 Int_t fDescent;
00070 Int_t fLinespace;
00071 Int_t fMaxWidth;
00072 Bool_t fFixed;
00073 };
00074
00075
00076 struct FontAttributes_t {
00077
00078 const char *fFamily;
00079 Int_t fPointsize;
00080 Int_t fWeight;
00081 Int_t fSlant;
00082 Int_t fUnderline;
00083 Int_t fOverstrike;
00084
00085 FontAttributes_t():
00086 fFamily (0),
00087 fPointsize (0),
00088 fWeight (kFontWeightNormal),
00089 fSlant (kFontSlantRoman),
00090 fUnderline (0),
00091 fOverstrike(0) { }
00092
00093 FontAttributes_t(const FontAttributes_t& f):
00094 fFamily (f.fFamily),
00095 fPointsize (f.fPointsize),
00096 fWeight (f.fWeight),
00097 fSlant (f.fSlant),
00098 fUnderline (f.fUnderline),
00099 fOverstrike(f.fOverstrike) { }
00100
00101 FontAttributes_t& operator=(const FontAttributes_t& f)
00102 {
00103 fFamily = f.fFamily;
00104 fPointsize = f.fPointsize;
00105 fWeight = f.fWeight;
00106 fSlant = f.fSlant;
00107 fUnderline = f.fUnderline;
00108 fOverstrike = f.fOverstrike;
00109 return *this;
00110 }
00111
00112 };
00113
00114
00115
00116 struct LayoutChunk_t;
00117
00118
00119 class TGTextLayout : public TObject {
00120
00121 friend class TGFont;
00122
00123 protected:
00124 const TGFont *fFont;
00125 const char *fString;
00126 Int_t fWidth;
00127 Int_t fNumChunks;
00128 LayoutChunk_t *fChunks;
00129
00130 TGTextLayout(const TGTextLayout &tlayout);
00131 void operator=(const TGTextLayout &tlayout);
00132
00133 public:
00134 TGTextLayout(): fFont(NULL), fString(""), fWidth(0), fNumChunks(0), fChunks(NULL) {}
00135 virtual ~TGTextLayout();
00136
00137 void DrawText(Drawable_t dst, GContext_t gc, Int_t x, Int_t y,
00138 Int_t firstChar, Int_t lastChar) const;
00139 void UnderlineChar(Drawable_t dst, GContext_t gc,
00140 Int_t x, Int_t y, Int_t underline) const;
00141 Int_t PointToChar(Int_t x, Int_t y) const;
00142 Int_t CharBbox(Int_t index, Int_t *x, Int_t *y, Int_t *w, Int_t *h) const;
00143 Int_t DistanceToText(Int_t x, Int_t y) const;
00144 Int_t IntersectText(Int_t x, Int_t y, Int_t w, Int_t h) const;
00145 void ToPostscript(TString *dst) const;
00146
00147 ClassDef(TGTextLayout,0)
00148 };
00149
00150
00151
00152
00153 class TGFont : public TNamed, public TRefCnt {
00154
00155 friend class TGFontPool;
00156 friend class TGTextLayout;
00157
00158 private:
00159 FontStruct_t fFontStruct;
00160 FontH_t fFontH;
00161 FontMetrics_t fFM;
00162 FontAttributes_t fFA;
00163 TObjString *fNamedHash;
00164 Int_t fTabWidth;
00165 Int_t fUnderlinePos;
00166
00167 Int_t fUnderlineHeight;
00168
00169 char fTypes[256];
00170
00171 Int_t fWidths[256];
00172 Int_t fBarHeight;
00173
00174
00175 protected:
00176 TGFont(const char *name)
00177 : TNamed(name,""), TRefCnt(), fFontStruct(0), fFontH(0), fFM(),
00178 fFA(), fNamedHash(0), fTabWidth(0), fUnderlinePos(0), fUnderlineHeight(0), fBarHeight(0)
00179 {
00180 SetRefCount(1);
00181 for (Int_t i=0; i<256; i++) {
00182 fWidths[i] = 0;
00183 fTypes[i] = ' ';
00184 }
00185 }
00186
00187 TGFont(const TGFont &font);
00188 void operator=(const TGFont &font);
00189
00190 LayoutChunk_t *NewChunk(TGTextLayout *layout, int *maxPtr,
00191 const char *start, int numChars,
00192 int curX, int newX, int y) const;
00193 public:
00194 virtual ~TGFont();
00195
00196 FontH_t GetFontHandle() const { return fFontH; }
00197 FontStruct_t GetFontStruct() const { return fFontStruct; }
00198 FontStruct_t operator()() const;
00199 void GetFontMetrics(FontMetrics_t *m) const;
00200 FontAttributes_t GetFontAttributes() const { return fFA; }
00201
00202 Int_t PostscriptFontName(TString *dst) const;
00203 Int_t TextWidth(const char *string, Int_t numChars = -1) const;
00204 Int_t XTextWidth(const char *string, Int_t numChars = -1) const;
00205 Int_t TextHeight() const { return fFM.fLinespace; }
00206 void UnderlineChars(Drawable_t dst, GContext_t gc,
00207 const char *string, Int_t x, Int_t y,
00208 Int_t firstChar, Int_t lastChar) const;
00209 TGTextLayout *ComputeTextLayout(const char *string, Int_t numChars,
00210 Int_t wrapLength, Int_t justify, Int_t flags,
00211 UInt_t *width, UInt_t *height) const;
00212 Int_t MeasureChars(const char *source, Int_t numChars, Int_t maxLength,
00213 Int_t flags, Int_t *length) const;
00214 void DrawCharsExp(Drawable_t dst, GContext_t gc, const char *source,
00215 Int_t numChars, Int_t x, Int_t y) const;
00216 void DrawChars(Drawable_t dst, GContext_t gc, const char *source,
00217 Int_t numChars, Int_t x, Int_t y) const;
00218
00219 void Print(Option_t *option="") const;
00220 virtual void SavePrimitive(ostream &out, Option_t * = "");
00221
00222 ClassDef(TGFont,0)
00223 };
00224
00225
00226 struct FontStateMap_t;
00227 struct XLFDAttributes_t;
00228
00229
00230 class TGFontPool : public TGObject {
00231
00232 private:
00233 THashTable *fList;
00234 THashTable *fUidTable;
00235 THashTable *fNamedTable;
00236
00237 TGFontPool(const TGFontPool& fp);
00238 TGFontPool& operator=(const TGFontPool& fp);
00239
00240 protected:
00241 const char *GetUid(const char *string);
00242 Bool_t ParseXLFD(const char *string, XLFDAttributes_t *xa);
00243 TGFont *GetFontFromAttributes(FontAttributes_t *fa, TGFont *fontPtr);
00244 int FindStateNum(const FontStateMap_t *map, const char *strKey);
00245 const char *FindStateString(const FontStateMap_t *map, int numKey);
00246 Bool_t FieldSpecified(const char *field);
00247 TGFont *GetNativeFont(const char *name, Bool_t fixedDefault = kTRUE);
00248 TGFont *MakeFont(TGFont *font, FontStruct_t fontStruct, const char *fontName);
00249
00250 public:
00251 TGFontPool(TGClient *client);
00252 virtual ~TGFontPool();
00253
00254 TGFont *GetFont(const char *font, Bool_t fixedDefault = kTRUE);
00255 TGFont *GetFont(const TGFont *font);
00256 TGFont *GetFont(FontStruct_t font);
00257 TGFont *GetFont(const char *family, Int_t ptsize, Int_t weight, Int_t slant);
00258
00259 void FreeFont(const TGFont *font);
00260
00261 TGFont *FindFont(FontStruct_t font) const;
00262 TGFont *FindFontByHandle(FontH_t font) const;
00263
00264 char **GetAttributeInfo(const FontAttributes_t *fa);
00265 void FreeAttributeInfo(char **info);
00266 char **GetFontFamilies();
00267 void FreeFontFamilies(char **f);
00268 Bool_t ParseFontName(const char *string, FontAttributes_t *fa);
00269 const char *NameOfFont(TGFont *font);
00270
00271 void Print(Option_t *option="") const;
00272
00273 ClassDef(TGFontPool,0)
00274 };
00275
00276 #endif