Warning, file /include/root/TGFont.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGFont
0013 #define ROOT_TGFont
0014
0015
0016 #include "TNamed.h"
0017 #include "TGObject.h"
0018 #include "TRefCnt.h"
0019
0020 class THashTable;
0021 class TObjString;
0022 class TGFont;
0023
0024
0025
0026 enum ETextLayoutFlags {
0027 kTextWholeWords = BIT(0),
0028 kTextAtLeastOne = BIT(1),
0029 kTextPartialOK = BIT(2),
0030 kTextIgnoreTabs = BIT(3),
0031 kTextIgnoreNewlines = BIT(4)
0032 };
0033
0034 enum EFontWeight {
0035 kFontWeightNormal = 0,
0036 kFontWeightMedium = 0,
0037 kFontWeightBold = 1,
0038 kFontWeightLight = 2,
0039 kFontWeightDemibold = 3,
0040 kFontWeightBlack = 4,
0041 kFontWeightUnknown = -1
0042 };
0043
0044 enum EFontSlant {
0045 kFontSlantRoman = 0,
0046 kFontSlantItalic = 1,
0047 kFontSlantOblique = 2,
0048 kFontSlantUnknown = -1
0049 };
0050
0051
0052 struct FontMetrics_t {
0053 Int_t fAscent;
0054 Int_t fDescent;
0055 Int_t fLinespace;
0056 Int_t fMaxWidth;
0057 Bool_t fFixed;
0058 };
0059
0060
0061 struct FontAttributes_t {
0062
0063 const char *fFamily;
0064 Int_t fPointsize;
0065 Int_t fWeight;
0066 Int_t fSlant;
0067 Int_t fUnderline;
0068 Int_t fOverstrike;
0069
0070 FontAttributes_t():
0071 fFamily (nullptr),
0072 fPointsize (0),
0073 fWeight (kFontWeightNormal),
0074 fSlant (kFontSlantRoman),
0075 fUnderline (0),
0076 fOverstrike(0) { }
0077
0078 FontAttributes_t(const FontAttributes_t& f):
0079 fFamily (f.fFamily),
0080 fPointsize (f.fPointsize),
0081 fWeight (f.fWeight),
0082 fSlant (f.fSlant),
0083 fUnderline (f.fUnderline),
0084 fOverstrike(f.fOverstrike) { }
0085
0086 FontAttributes_t& operator=(const FontAttributes_t& f)
0087 {
0088 if (this != &f) {
0089 fFamily = f.fFamily;
0090 fPointsize = f.fPointsize;
0091 fWeight = f.fWeight;
0092 fSlant = f.fSlant;
0093 fUnderline = f.fUnderline;
0094 fOverstrike = f.fOverstrike;
0095 }
0096 return *this;
0097 }
0098
0099 };
0100
0101
0102
0103 struct LayoutChunk_t;
0104
0105
0106 class TGTextLayout : public TObject {
0107
0108 friend class TGFont;
0109
0110 protected:
0111 const TGFont *fFont;
0112 const char *fString;
0113 Int_t fWidth;
0114 Int_t fNumChunks;
0115 LayoutChunk_t *fChunks;
0116
0117 TGTextLayout(const TGTextLayout &tlayout) = delete;
0118 void operator=(const TGTextLayout &tlayout) = delete;
0119
0120 public:
0121 TGTextLayout(): fFont(nullptr), fString(""), fWidth(0), fNumChunks(0), fChunks(nullptr) {}
0122 ~TGTextLayout() override;
0123
0124 void DrawText(Drawable_t dst, GContext_t gc, Int_t x, Int_t y,
0125 Int_t firstChar, Int_t lastChar) const;
0126 void UnderlineChar(Drawable_t dst, GContext_t gc,
0127 Int_t x, Int_t y, Int_t underline) const;
0128 Int_t PointToChar(Int_t x, Int_t y) const;
0129 Int_t CharBbox(Int_t index, Int_t *x, Int_t *y, Int_t *w, Int_t *h) const;
0130 Int_t DistanceToText(Int_t x, Int_t y) const;
0131 Int_t IntersectText(Int_t x, Int_t y, Int_t w, Int_t h) const;
0132 void ToPostscript(TString *dst) const;
0133
0134 ClassDefOverride(TGTextLayout,0)
0135 };
0136
0137
0138
0139
0140 class TGFont : public TNamed, public TRefCnt {
0141
0142 friend class TGFontPool;
0143 friend class TGTextLayout;
0144
0145 private:
0146 FontStruct_t fFontStruct;
0147 FontH_t fFontH;
0148 FontMetrics_t fFM;
0149 FontAttributes_t fFA;
0150 TObjString *fNamedHash;
0151 Int_t fTabWidth;
0152 Int_t fUnderlinePos;
0153
0154 Int_t fUnderlineHeight;
0155
0156 char fTypes[256];
0157
0158 Int_t fWidths[256];
0159 Int_t fBarHeight;
0160
0161
0162 protected:
0163 TGFont(const char *name)
0164 : TNamed(name,""), TRefCnt(), fFontStruct(0), fFontH(0), fFM(),
0165 fFA(), fNamedHash(nullptr), fTabWidth(0), fUnderlinePos(0), fUnderlineHeight(0), fBarHeight(0)
0166 {
0167 SetRefCount(1);
0168 for (Int_t i=0; i<256; i++) {
0169 fWidths[i] = 0;
0170 fTypes[i] = ' ';
0171 }
0172 }
0173
0174 TGFont(const TGFont &) = delete;
0175 void operator=(const TGFont &) = delete;
0176
0177 LayoutChunk_t *NewChunk(TGTextLayout *layout, int *maxPtr,
0178 const char *start, int numChars,
0179 int curX, int newX, int y) const;
0180 public:
0181 ~TGFont() override;
0182
0183 FontH_t GetFontHandle() const { return fFontH; }
0184 FontStruct_t GetFontStruct() const { return fFontStruct; }
0185 FontStruct_t operator()() const;
0186 void GetFontMetrics(FontMetrics_t *m) const;
0187 FontAttributes_t GetFontAttributes() const { return fFA; }
0188
0189 Int_t PostscriptFontName(TString *dst) const;
0190 Int_t TextWidth(const char *string, Int_t numChars = -1) const;
0191 Int_t XTextWidth(const char *string, Int_t numChars = -1) const;
0192 Int_t TextHeight() const { return fFM.fLinespace; }
0193 void UnderlineChars(Drawable_t dst, GContext_t gc,
0194 const char *string, Int_t x, Int_t y,
0195 Int_t firstChar, Int_t lastChar) const;
0196 TGTextLayout *ComputeTextLayout(const char *string, Int_t numChars,
0197 Int_t wrapLength, Int_t justify, Int_t flags,
0198 UInt_t *width, UInt_t *height) const;
0199 Int_t MeasureChars(const char *source, Int_t numChars, Int_t maxLength,
0200 Int_t flags, Int_t *length) const;
0201 void DrawCharsExp(Drawable_t dst, GContext_t gc, const char *source,
0202 Int_t numChars, Int_t x, Int_t y) const;
0203 void DrawChars(Drawable_t dst, GContext_t gc, const char *source,
0204 Int_t numChars, Int_t x, Int_t y) const;
0205
0206 void Print(Option_t *option="") const override;
0207 void SavePrimitive(std::ostream &out, Option_t * = "") override;
0208
0209 ClassDefOverride(TGFont,0)
0210 };
0211
0212
0213 struct FontStateMap_t;
0214 struct XLFDAttributes_t;
0215
0216
0217 class TGFontPool : public TGObject {
0218
0219 private:
0220 THashTable *fList;
0221 THashTable *fUidTable;
0222 THashTable *fNamedTable;
0223
0224 TGFontPool(const TGFontPool& fp) = delete;
0225 TGFontPool& operator=(const TGFontPool& fp) = delete;
0226
0227 protected:
0228 const char *GetUid(const char *string);
0229 Bool_t ParseXLFD(const char *string, XLFDAttributes_t *xa);
0230 TGFont *GetFontFromAttributes(FontAttributes_t *fa, TGFont *fontPtr);
0231 int FindStateNum(const FontStateMap_t *map, const char *strKey);
0232 const char *FindStateString(const FontStateMap_t *map, int numKey);
0233 Bool_t FieldSpecified(const char *field);
0234 TGFont *GetNativeFont(const char *name, Bool_t fixedDefault = kTRUE);
0235 TGFont *MakeFont(TGFont *font, FontStruct_t fontStruct, const char *fontName);
0236
0237 public:
0238 TGFontPool(TGClient *client);
0239 ~TGFontPool() override;
0240
0241 TGFont *GetFont(const char *font, Bool_t fixedDefault = kTRUE);
0242 TGFont *GetFont(const TGFont *font);
0243 TGFont *GetFont(FontStruct_t font);
0244 TGFont *GetFont(const char *family, Int_t ptsize, Int_t weight, Int_t slant);
0245
0246 void FreeFont(const TGFont *font);
0247
0248 TGFont *FindFont(FontStruct_t font) const;
0249 TGFont *FindFontByHandle(FontH_t font) const;
0250
0251 char **GetAttributeInfo(const FontAttributes_t *fa);
0252 void FreeAttributeInfo(char **info);
0253 char **GetFontFamilies();
0254 void FreeFontFamilies(char **f);
0255 Bool_t ParseFontName(const char *string, FontAttributes_t *fa);
0256 const char *NameOfFont(TGFont *font);
0257
0258 void Print(Option_t *option="") const override;
0259
0260 ClassDefOverride(TGFontPool,0)
0261 };
0262
0263 #endif