Logo ROOT  
Reference Guide
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 
20 class FTFont;
21 class TGLFontManager;
22 
23 class TGLFont
24 {
25 public:
26  enum EMode
27  {
28  kUndef = -1,
31  }; // Font-types of FTGL.
32 
35 
36 private:
37  TGLFont& operator=(const TGLFont& o); // Not implemented.
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 
47 protected:
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 
52  mutable Int_t fTrashCount;
53 public:
54  TGLFont();
55  TGLFont(Int_t size, Int_t font, EMode mode, FTFont *f=0, TGLFontManager *mng=0);
56  TGLFont(const TGLFont& o); // Not implemented.
57  virtual ~TGLFont();
58 
59  void CopyAttributes(const TGLFont &o);
60 
61  Int_t GetSize() const { return fSize;}
62  Int_t GetFile() const { return fFile;}
63  EMode GetMode() const { return fMode;}
64 
65  Int_t GetTrashCount() const { return fTrashCount; }
66  void SetTrashCount(Int_t c) const { fTrashCount = c; }
67  Int_t IncTrashCount() const { return ++fTrashCount; }
68 
69  void SetFont(FTFont *f) { fFont =f;}
70  const FTFont* GetFont() const { return fFont; }
71  void SetManager(TGLFontManager *mng) { fManager = mng; }
72  const TGLFontManager* GetManager() const { return fManager; }
73 
74  Float_t GetDepth() const { return fDepth; }
75  void SetDepth(Float_t d) { fDepth = d; }
76 
77  // FTGL wrapper functions
78  Float_t GetAscent() const;
79  Float_t GetDescent() const;
80  Float_t GetLineHeight() const;
81  void MeasureBaseLineParams(Float_t& ascent, Float_t& descent, Float_t& line_height,
82  const char* txt="Xj") const;
83 
84  void BBox(const char* txt,
85  Float_t& llx, Float_t& lly, Float_t& llz,
86  Float_t& urx, Float_t& ury, Float_t& urz) const;
87  void BBox(const wchar_t* txt,
88  Float_t& llx, Float_t& lly, Float_t& llz,
89  Float_t& urx, Float_t& ury, Float_t& urz) const;
90 
91  void Render(const char* txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const;
92  void Render(const wchar_t* txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const;
93  void Render(const TString &txt) const;
94  void Render(const TString &txt, Float_t x, Float_t y, Float_t z, ETextAlignH_e alignH, ETextAlignV_e alignV) const;
95 
96  // helper gl draw functions
97  virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const;
98  virtual void PostRender() const;
99 
100  Bool_t operator< (const TGLFont& o) const
101  {
102  if (fSize == o.fSize)
103  {
104  if(fFile == o.fFile)
105  {
106  return fMode < o.fMode;
107  }
108  return fFile < o.fFile;
109  }
110  return fSize < o.fSize;
111  }
112 
113  ClassDef(TGLFont, 0); // A wrapper class for FTFont.
114 };
115 
116 /******************************************************************************/
117 /******************************************************************************/
118 
120 {
121 public:
122  typedef std::vector<Int_t> FontSizeVec_t;
123 
124 private:
125  TGLFontManager(const TGLFontManager&); // Not implemented
126  TGLFontManager& operator=(const TGLFontManager&); // Not implemented
127 
128 protected:
129  typedef std::map<TGLFont, Int_t> FontMap_t;
130  typedef std::map<TGLFont, Int_t>::iterator FontMap_i;
131 
132  typedef std::list<const TGLFont*> FontList_t;
133  typedef std::list<const TGLFont*>::iterator FontList_i;
134  typedef std::list<const TGLFont*>::const_iterator FontList_ci;
135 
136  FontMap_t fFontMap; // map of created fonts
137  FontList_t fFontTrash; // fonts to purge
138 
139  static TObjArray fgFontFileArray; // map font-id to ttf-font-file
140  // Default fonts - for gl/eve, "extended" - for gl-pad
142 
143  static FontSizeVec_t fgFontSizeArray; // map of valid font-size
144  static Bool_t fgStaticInitDone; // global initialization flag
145  static void InitStatics();
146 
147 public:
149  virtual ~TGLFontManager();
150 
151  void RegisterFont(Int_t size, Int_t file, TGLFont::EMode mode, TGLFont& out);
152  void RegisterFont(Int_t size, const char* name, TGLFont::EMode mode, TGLFont& out);
153  void ReleaseFont(TGLFont& font);
154 
155  static TObjArray* GetFontFileArray();
157 
159  static Int_t GetFontSize(Int_t ds);
160  static Int_t GetFontSize(Int_t ds, Int_t min, Int_t max);
161  static const char* GetFontNameFromId(Int_t);
162 
163  void ClearFontTrash();
164 
165  ClassDef(TGLFontManager, 0); // A FreeType GL font manager.
166 };
167 
168 #endif
169 
TGLFontManager::fgExtendedFontStart
static Int_t fgExtendedFontStart
Definition: TGLFontManager.h:141
c
#define c(i)
Definition: RSha256.hxx:101
TGLFontManager::~TGLFontManager
virtual ~TGLFontManager()
Destructor.
Definition: TGLFontManager.cxx:429
TGLFontManager
A FreeType GL font manager.
Definition: TGLFontManager.h:120
TGLFont
A wrapper class for FTFont.
Definition: TGLFontManager.h:24
TGLFont::GetSize
Int_t GetSize() const
Definition: TGLFontManager.h:61
TGLFont::kPolygon
@ kPolygon
Definition: TGLFontManager.h:30
TGLFont::ETextAlignV_e
ETextAlignV_e
Definition: TGLFontManager.h:34
TGLFontManager::FontList_t
std::list< const TGLFont * > FontList_t
Definition: TGLFontManager.h:132
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGLFontManager::fgStaticInitDone
static Bool_t fgStaticInitDone
Definition: TGLFontManager.h:144
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
f
#define f(i)
Definition: RSha256.hxx:104
TGLFontManager::fFontTrash
FontList_t fFontTrash
Definition: TGLFontManager.h:137
TGLFont::TGLFont
TGLFont()
Constructor.
Definition: TGLFontManager.cxx:52
TGLFont::operator<
Bool_t operator<(const TGLFont &o) const
Definition: TGLFontManager.h:100
TGLFont::SetTrashCount
void SetTrashCount(Int_t c) const
Definition: TGLFontManager.h:66
TGLFontManager::FontMap_i
std::map< TGLFont, Int_t >::iterator FontMap_i
Definition: TGLFontManager.h:130
TGLFont::kCenterV
@ kCenterV
Definition: TGLFontManager.h:34
TGLFont::EMode
EMode
Definition: TGLFontManager.h:27
TGLFontManager::fgFontSizeArray
static FontSizeVec_t fgFontSizeArray
Definition: TGLFontManager.h:143
TGLFont::kCenterH
@ kCenterH
Definition: TGLFontManager.h:33
TGLFontManager::FontSizeVec_t
std::vector< Int_t > FontSizeVec_t
Definition: TGLFontManager.h:122
TGLFont::BBox
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.
Definition: TGLFontManager.cxx:154
TGLFont::ETextAlignH_e
ETextAlignH_e
Definition: TGLFontManager.h:33
extract_docstrings.ds
ds
Definition: extract_docstrings.py:40
TGLFont::IncTrashCount
Int_t IncTrashCount() const
Definition: TGLFontManager.h:67
Float_t
float Float_t
Definition: RtypesCore.h:57
TGLFont::fDepth
Float_t fDepth
Definition: TGLFontManager.h:42
TGLFont::GetManager
const TGLFontManager * GetManager() const
Definition: TGLFontManager.h:72
Int_t
int Int_t
Definition: RtypesCore.h:45
TGLFont::GetAscent
Float_t GetAscent() const
Get font's ascent.
Definition: TGLFontManager.cxx:115
TGLFont::GetDepth
Float_t GetDepth() const
Definition: TGLFontManager.h:74
x
Double_t x[n]
Definition: legend1.C:17
TGLFontManager::GetFontSizeArray
static FontSizeVec_t * GetFontSizeArray()
Get valid font size vector.
Definition: TGLFontManager.cxx:561
TGLFont::MeasureBaseLineParams
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.
Definition: TGLFontManager.cxx:141
TGLFont::SetManager
void SetManager(TGLFontManager *mng)
Definition: TGLFontManager.h:71
TGLFont::kTexture
@ kTexture
Definition: TGLFontManager.h:30
TGLFont::kOutline
@ kOutline
Definition: TGLFontManager.h:30
TGLFontManager::GetFontNameFromId
static const char * GetFontNameFromId(Int_t)
Get font name from TAttAxis font id.
Definition: TGLFontManager.cxx:605
TGLFont::kBitmap
@ kBitmap
Definition: TGLFontManager.h:29
TString
Basic string class.
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGLFont::fFile
Int_t fFile
Definition: TGLFontManager.h:49
TGLFont::RenderHelper
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.
Definition: TGLFontManager.cxx:178
TGLFont::kPixmap
@ kPixmap
Definition: TGLFontManager.h:29
bool
TGLFont::GetDescent
Float_t GetDescent() const
Get font's descent. The returned value is positive.
Definition: TGLFontManager.cxx:123
TGLFontManager::TGLFontManager
TGLFontManager(const TGLFontManager &)
TGLFont::fManager
TGLFontManager * fManager
Definition: TGLFontManager.h:40
TGLFont::PreRender
virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const
Set-up GL state before FTFont rendering.
Definition: TGLFontManager.cxx:365
TGLFont::Render
void Render(const char *txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const
Definition: TGLFontManager.cxx:283
TGLFontManager::FontMap_t
std::map< TGLFont, Int_t > FontMap_t
Definition: TGLFontManager.h:129
TGLFontManager::ClearFontTrash
void ClearFontTrash()
Delete FTFFont objects registered for destruction.
Definition: TGLFontManager.cxx:699
TGLFontManager::ReleaseFont
void ReleaseFont(TGLFont &font)
Release font with given attributes.
Definition: TGLFontManager.cxx:533
TGLFontManager::operator=
TGLFontManager & operator=(const TGLFontManager &)
TGLFont::GetFont
const FTFont * GetFont() const
Definition: TGLFontManager.h:70
TGLFont::fSize
Int_t fSize
Definition: TGLFontManager.h:48
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGLFont::SetFont
void SetFont(FTFont *f)
Definition: TGLFontManager.h:69
TGLFontManager::GetFontFileArray
static TObjArray * GetFontFileArray()
Get id to file name map.
Definition: TGLFontManager.cxx:552
TGLFont::fTrashCount
Int_t fTrashCount
Definition: TGLFontManager.h:52
TGLFontManager::GetExtendedFontStartIndex
static Int_t GetExtendedFontStartIndex()
Definition: TGLFontManager.cxx:569
TGLFontManager::GetFontSize
static Int_t GetFontSize(Int_t ds)
Get availabe font size.
Definition: TGLFontManager.cxx:581
y
Double_t y[n]
Definition: legend1.C:17
TGLFont::kUndef
@ kUndef
Definition: TGLFontManager.h:28
TGLFontManager::fFontMap
FontMap_t fFontMap
Definition: TGLFontManager.h:136
TGLFont::kExtrude
@ kExtrude
Definition: TGLFontManager.h:30
TGLFontManager::TGLFontManager
TGLFontManager()
Definition: TGLFontManager.h:148
TGLFontManager::fgFontFileArray
static TObjArray fgFontFileArray
Definition: TGLFontManager.h:139
TGLFont::kBottom
@ kBottom
Definition: TGLFontManager.h:34
TGLFontManager::FontList_ci
std::list< const TGLFont * >::const_iterator FontList_ci
Definition: TGLFontManager.h:134
TGLFont::kTop
@ kTop
Definition: TGLFontManager.h:34
TGLFont::GetTrashCount
Int_t GetTrashCount() const
Definition: TGLFontManager.h:65
TGLFont::kRight
@ kRight
Definition: TGLFontManager.h:33
Double_t
double Double_t
Definition: RtypesCore.h:59
TGLFont::SetDepth
void SetDepth(Float_t d)
Definition: TGLFontManager.h:75
TGLFont::fFont
FTFont * fFont
Definition: TGLFontManager.h:39
TGLFontManager::InitStatics
static void InitStatics()
Create a list of available font files and allowed font sizes.
Definition: TGLFontManager.cxx:623
TObjArray.h
TGLFont::operator=
TGLFont & operator=(const TGLFont &o)
TGLFont::kLeft
@ kLeft
Definition: TGLFontManager.h:33
file
Definition: file.py:1
TGLFont::~TGLFont
virtual ~TGLFont()
Destructor.
Definition: TGLFontManager.cxx:87
TGLFontManager::RegisterFont
void RegisterFont(Int_t size, Int_t file, TGLFont::EMode mode, TGLFont &out)
Provide font with given size, file and FTGL class.
Definition: TGLFontManager.cxx:442
TGLFontManager::FontList_i
std::list< const TGLFont * >::iterator FontList_i
Definition: TGLFontManager.h:133
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGLFont::fMode
EMode fMode
Definition: TGLFontManager.h:50
TGLFont::GetFile
Int_t GetFile() const
Definition: TGLFontManager.h:62
name
char name[80]
Definition: TGX11.cxx:110
d
#define d(i)
Definition: RSha256.hxx:102
TGLFont::CopyAttributes
void CopyAttributes(const TGLFont &o)
Assignment operator.
Definition: TGLFontManager.cxx:95
sqlio::Char
const char * Char
Definition: TSQLStructure.cxx:70
TGLFont::GetMode
EMode GetMode() const
Definition: TGLFontManager.h:63
TGLFont::GetLineHeight
Float_t GetLineHeight() const
Get font's line-height.
Definition: TGLFontManager.cxx:131
TGLFont::PostRender
virtual void PostRender() const
Reset GL state after FTFont rendering.
Definition: TGLFontManager.cxx:406
int