File indexing completed on 2026-09-19 09:37:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGLFontManager
0013 #define ROOT_TGLFontManager
0014
0015 #include "TObjArray.h"
0016 #include <list>
0017 #include <vector>
0018 #include <map>
0019
0020 class FTFont;
0021 class TGLFontManager;
0022
0023 class TGLFont
0024 {
0025 public:
0026 enum EMode
0027 {
0028 kUndef = -1,
0029 kBitmap, kPixmap,
0030 kTexture, kOutline, kPolygon, kExtrude
0031 };
0032
0033 enum ETextAlignH_e { kLeft, kRight, kCenterH };
0034 enum ETextAlignV_e { kBottom, kTop, kCenterV };
0035
0036 private:
0037 TGLFont& operator=(const TGLFont&) = delete;
0038
0039 FTFont *fFont;
0040 TGLFontManager *fManager;
0041
0042 Float_t fDepth;
0043
0044 template<class Char>
0045 void RenderHelper(const Char *txt, Double_t x, Double_t y, Double_t angle, Double_t ) const;
0046
0047 protected:
0048 Int_t fSize;
0049 Int_t fFile;
0050 EMode fMode;
0051 UInt_t fTextAlign = 0;
0052
0053 mutable Int_t fTrashCount;
0054 public:
0055 TGLFont();
0056 TGLFont(Int_t size, Int_t font, EMode mode, FTFont *f = nullptr, TGLFontManager *mng = nullptr);
0057 TGLFont(const TGLFont &o);
0058 virtual ~TGLFont();
0059
0060 void CopyAttributes(const TGLFont &o);
0061
0062 Int_t GetSize() const { return fSize;}
0063 Int_t GetFile() const { return fFile;}
0064 EMode GetMode() const { return fMode;}
0065
0066 Int_t GetTrashCount() const { return fTrashCount; }
0067 void SetTrashCount(Int_t c) const { fTrashCount = c; }
0068 Int_t IncTrashCount() const { return ++fTrashCount; }
0069
0070 void SetFont(FTFont *f) { fFont =f;}
0071 const FTFont* GetFont() const { return fFont; }
0072 void SetManager(TGLFontManager *mng) { fManager = mng; }
0073 const TGLFontManager* GetManager() const { return fManager; }
0074
0075 Float_t GetDepth() const { return fDepth; }
0076 void SetDepth(Float_t d) { fDepth = d; }
0077
0078 void SetTextAlign(UInt_t align) { fTextAlign = align; }
0079
0080
0081 Float_t GetAscent() const;
0082 Float_t GetDescent() const;
0083 Float_t GetLineHeight() const;
0084 void MeasureBaseLineParams(Float_t& ascent, Float_t& descent, Float_t& line_height,
0085 const char* txt="Xj") const;
0086
0087 void BBox(const char* txt,
0088 Float_t& llx, Float_t& lly, Float_t& llz,
0089 Float_t& urx, Float_t& ury, Float_t& urz) const;
0090 void BBox(const wchar_t* txt,
0091 Float_t& llx, Float_t& lly, Float_t& llz,
0092 Float_t& urx, Float_t& ury, Float_t& urz) const;
0093
0094 void Render(const char* txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const;
0095 void Render(const wchar_t* txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const;
0096 void Render(const TString &txt) const;
0097 void Render(const TString &txt, Float_t x, Float_t y, Float_t z, ETextAlignH_e alignH, ETextAlignV_e alignV) const;
0098
0099
0100 virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const;
0101 virtual void PostRender() const;
0102
0103 Bool_t operator< (const TGLFont& o) const
0104 {
0105 if (fSize == o.fSize)
0106 {
0107 if(fFile == o.fFile)
0108 {
0109 return fMode < o.fMode;
0110 }
0111 return fFile < o.fFile;
0112 }
0113 return fSize < o.fSize;
0114 }
0115
0116 ClassDef(TGLFont, 0);
0117 };
0118
0119
0120
0121
0122 class TGLFontManager
0123 {
0124 public:
0125 typedef std::vector<Int_t> FontSizeVec_t;
0126
0127 private:
0128 TGLFontManager(const TGLFontManager&) = delete;
0129 TGLFontManager& operator=(const TGLFontManager&) = delete;
0130
0131 protected:
0132 typedef std::map<TGLFont, Int_t> FontMap_t;
0133 typedef std::map<TGLFont, Int_t>::iterator FontMap_i;
0134
0135 typedef std::list<const TGLFont*> FontList_t;
0136 typedef std::list<const TGLFont*>::iterator FontList_i;
0137 typedef std::list<const TGLFont*>::const_iterator FontList_ci;
0138
0139 FontMap_t fFontMap;
0140 FontList_t fFontTrash;
0141
0142 static TObjArray fgFontFileArray;
0143
0144 static Int_t fgExtendedFontStart;
0145
0146 static FontSizeVec_t fgFontSizeArray;
0147 static Bool_t fgStaticInitDone;
0148 static void InitStatics();
0149
0150 public:
0151 TGLFontManager() : fFontMap(), fFontTrash() {}
0152 virtual ~TGLFontManager();
0153
0154 void RegisterFont(Int_t size, Int_t file, TGLFont::EMode mode, TGLFont& out);
0155 void RegisterFont(Int_t size, const char* name, TGLFont::EMode mode, TGLFont& out);
0156 void ReleaseFont(TGLFont& font);
0157
0158 static TObjArray* GetFontFileArray();
0159 static FontSizeVec_t* GetFontSizeArray();
0160
0161 static Int_t GetExtendedFontStartIndex();
0162 static Int_t GetFontSize(Int_t ds);
0163 static Int_t GetFontSize(Int_t ds, Int_t min, Int_t max);
0164 static const char* GetFontNameFromId(Int_t);
0165
0166 void ClearFontTrash();
0167
0168 ClassDef(TGLFontManager, 0);
0169 };
0170
0171 #endif
0172