Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLFontManager.h
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Alja Mrak-Tadel 2008
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGLFontManager
13#define ROOT_TGLFontManager
14
15#include "TObjArray.h"
16#include <list>
17#include <vector>
18#include <map>
19
20class FTFont;
21class TGLFontManager;
22
24{
25public:
26 enum EMode
27 {
28 kUndef = -1,
31 }; // Font-types of FTGL.
32
35
36private:
37 TGLFont& operator=(const TGLFont&) = delete;
38
39 FTFont *fFont; // FTGL font.
40 TGLFontManager *fManager; // Font manager.
41
42 Float_t fDepth; // depth of extruded fonts, enforced at render time.
43
44 template<class Char>
45 void RenderHelper(const Char *txt, Double_t x, Double_t y, Double_t angle, Double_t /*mgn*/) const;
46
47protected:
48 Int_t fSize; // free-type face size
49 Int_t fFile; // free-type file name
50 EMode fMode; // free-type FTGL class id
51 UInt_t fTextAlign = 0; // set text align
52
54public:
55 TGLFont();
56 TGLFont(Int_t size, Int_t font, EMode mode, FTFont *f = nullptr, TGLFontManager *mng = nullptr);
57 TGLFont(const TGLFont &o);
58 virtual ~TGLFont();
59
60 void CopyAttributes(const TGLFont &o);
61
62 Int_t GetSize() const { return fSize;}
63 Int_t GetFile() const { return fFile;}
64 EMode GetMode() const { return fMode;}
65
66 Int_t GetTrashCount() const { return fTrashCount; }
67 void SetTrashCount(Int_t c) const { fTrashCount = c; }
68 Int_t IncTrashCount() const { return ++fTrashCount; }
69
70 void SetFont(FTFont *f) { fFont =f;}
71 const FTFont* GetFont() const { return fFont; }
73 const TGLFontManager* GetManager() const { return fManager; }
74
75 Float_t GetDepth() const { return fDepth; }
76 void SetDepth(Float_t d) { fDepth = d; }
77
78 void SetTextAlign(UInt_t align) { fTextAlign = align; }
79
80 // FTGL wrapper functions
81 Float_t GetAscent() const;
82 Float_t GetDescent() const;
83 Float_t GetLineHeight() const;
85 const char* txt="Xj") const;
86
87 void BBox(const char* txt,
89 Float_t& urx, Float_t& ury, Float_t& urz) const;
90 void BBox(const wchar_t* txt,
92 Float_t& urx, Float_t& ury, Float_t& urz) const;
93
94 void Render(const char* txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const;
95 void Render(const wchar_t* txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const;
96 void Render(const TString &txt) const;
97 void Render(const TString &txt, Float_t x, Float_t y, Float_t z, ETextAlignH_e alignH, ETextAlignV_e alignV) const;
98
99 // helper gl draw functions
100 virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const;
101 virtual void PostRender() const;
102
103 Bool_t operator< (const TGLFont& o) const
104 {
105 if (fSize == o.fSize)
106 {
107 if(fFile == o.fFile)
108 {
109 return fMode < o.fMode;
110 }
111 return fFile < o.fFile;
112 }
113 return fSize < o.fSize;
114 }
115
116 ClassDef(TGLFont, 0); // A wrapper class for FTFont.
117};
118
119/******************************************************************************/
120/******************************************************************************/
121
123{
124public:
125 typedef std::vector<Int_t> FontSizeVec_t;
126
127private:
130
131protected:
132 typedef std::map<TGLFont, Int_t> FontMap_t;
133 typedef std::map<TGLFont, Int_t>::iterator FontMap_i;
134
135 typedef std::list<const TGLFont*> FontList_t;
136 typedef std::list<const TGLFont*>::iterator FontList_i;
137 typedef std::list<const TGLFont*>::const_iterator FontList_ci;
138
139 FontMap_t fFontMap; // map of created fonts
140 FontList_t fFontTrash; // fonts to purge
141
142 static TObjArray fgFontFileArray; // map font-id to ttf-font-file
143 // Default fonts - for gl/eve, "extended" - for gl-pad
145
146 static FontSizeVec_t fgFontSizeArray; // map of valid font-size
147 static Bool_t fgStaticInitDone; // global initialization flag
148 static void InitStatics();
149
150public:
152 virtual ~TGLFontManager();
153
155 void RegisterFont(Int_t size, const char* name, TGLFont::EMode mode, TGLFont& out);
156 void ReleaseFont(TGLFont& font);
157
158 static TObjArray* GetFontFileArray();
160
162 static Int_t GetFontSize(Int_t ds);
163 static Int_t GetFontSize(Int_t ds, Int_t min, Int_t max);
164 static const char* GetFontNameFromId(Int_t);
165
166 void ClearFontTrash();
167
168 ClassDef(TGLFontManager, 0); // A FreeType GL font manager.
169};
170
171#endif
172
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t mgn
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:148
A FreeType GL font manager.
virtual ~TGLFontManager()
Destructor.
TGLFontManager(const TGLFontManager &)=delete
std::list< constTGLFont * >::const_iterator FontList_ci
static TObjArray fgFontFileArray
void RegisterFont(Int_t size, Int_t file, TGLFont::EMode mode, TGLFont &out)
Provide font with given size, file and FTGL class.
static Int_t GetFontSize(Int_t ds)
Get availabe font size.
ClassDef(TGLFontManager, 0)
static void InitStatics()
Create a list of available font files and allowed font sizes.
static Int_t GetExtendedFontStartIndex()
static Bool_t fgStaticInitDone
static FontSizeVec_t fgFontSizeArray
std::map< TGLFont, Int_t > FontMap_t
static Int_t fgExtendedFontStart
static FontSizeVec_t * GetFontSizeArray()
Get valid font size vector.
std::list< constTGLFont * >::iterator FontList_i
void ClearFontTrash()
Delete FTFFont objects registered for destruction.
std::map< TGLFont, Int_t >::iterator FontMap_i
std::list< const TGLFont * > FontList_t
std::vector< Int_t > FontSizeVec_t
static const char * GetFontNameFromId(Int_t)
Get font name from TAttAxis font id.
static TObjArray * GetFontFileArray()
Get id to file name map.
void ReleaseFont(TGLFont &font)
Release font with given attributes.
TGLFontManager & operator=(const TGLFontManager &)=delete
FontList_t fFontTrash
A wrapper class for FTFont.
void MeasureBaseLineParams(Float_t &ascent, Float_t &descent, Float_t &line_height, const char *txt="Xj") const
Measure font's base-line parameters from the passed text.
Float_t GetDescent() const
Get font's descent. The returned value is positive.
virtual ~TGLFont()
Destructor.
Int_t IncTrashCount() const
Float_t GetAscent() const
Get font's ascent.
EMode GetMode() const
void SetManager(TGLFontManager *mng)
void SetFont(FTFont *f)
void SetTrashCount(Int_t c) const
Float_t GetLineHeight() const
Get font's line-height.
EMode fMode
Int_t GetTrashCount() const
TGLFont & operator=(const TGLFont &)=delete
Int_t GetSize() const
const FTFont * GetFont() const
void RenderHelper(const Char *txt, Double_t x, Double_t y, Double_t angle, Double_t) const
mgn is simply ignored, because ROOT's TVirtualX TGX11 are complete mess with painting attributes.
FTFont * fFont
TGLFontManager * fManager
Int_t GetFile() const
Bool_t operator<(const TGLFont &o) const
UInt_t fTextAlign
void SetTextAlign(UInt_t align)
void BBox(const char *txt, Float_t &llx, Float_t &lly, Float_t &llz, Float_t &urx, Float_t &ury, Float_t &urz) const
Get bounding box.
Int_t fTrashCount
Float_t fDepth
ClassDef(TGLFont, 0)
const TGLFontManager * GetManager() const
void Render(const char *txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const
virtual void PostRender() const
Reset GL state after FTFont rendering.
void SetDepth(Float_t d)
virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const
Set-up GL state before FTFont rendering.
Int_t fSize
Float_t GetDepth() const
TGLFont()
Constructor.
void CopyAttributes(const TGLFont &o)
Assignment operator.
Int_t fFile
An array of TObjects.
Definition TObjArray.h:31
Basic string class.
Definition TString.h:138
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17