Logo ROOT  
Reference Guide
TTF.h
Go to the documentation of this file.
1 // @(#)root/graf:$Id$
2 // Author: Olivier Couet 01/10/02
3 // Author: Fons Rademakers 21/11/98
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TTF
14 #define ROOT_TTF
15 
16 
17 #include "Rtypes.h"
18 
19 /// @cond DOXYGEN_IGNORE
20 // Forward declare for the headers:
21 // # include <ft2build.h>
22 // # include FT_FREETYPE_H
23 // # include FT_GLYPH_H
24 extern "C" {
25  struct FT_LibraryRec_;
26  struct FT_FaceRec_;
27  struct FT_CharMapRec_;
28  struct FT_GlyphRec_;
29  struct FT_Matrix_;
30  struct FT_Bitmap_;
31  typedef struct FT_LibraryRec_* FT_Library;
32  typedef struct FT_FaceRec_* FT_Face;
33  typedef struct FT_CharMapRec_* FT_CharMap;
34  typedef struct FT_GlyphRec_* FT_Glyph;
35  typedef struct FT_Matrix_ FT_Matrix;
36  typedef struct FT_Bitmap_ FT_Bitmap; // Forward declared for TGX11TTF.h's benefit
37  typedef signed long FT_Pos;
38  #ifndef FT_FREETYPE_H
39  struct FT_Vector_ { FT_Pos x, y; };
40  struct FT_BBox_ { FT_Pos xMin, yMin, xMax, yMax; };
41  #endif
42  typedef struct FT_Vector_ FT_Vector;
43  typedef struct FT_BBox_ FT_BBox;
44 }
45 /// @endcond
46 
47 
48 class TGX11TTF;
49 class TGWin32;
50 class TMathTextRenderer;
51 
52 
53 class TTF {
54 
55 friend class TGX11TTF;
56 friend class TGWin32;
57 friend class TMathTextRenderer;
58 
59 public:
60 
61 /** \class TTGlyph
62 TTF helper class containing glyphs description.
63 */
64 
65  class TTGlyph {
66  public:
67  UInt_t fIndex{0}; ///< glyph index in face
68  FT_Vector fPos; ///< position of glyph origin
69  FT_Glyph fImage{nullptr}; ///< glyph image
70  };
71 
72 protected:
73  enum { kTTMaxFonts = 32, kMaxGlyphs = 1024 };
74 
75  static Int_t fgAscent; ///< string ascent, used to compute Y alignment
76  static FT_BBox fgCBox; ///< string control box
77  static FT_CharMap fgCharMap[kTTMaxFonts]; ///< font character map
78  static Int_t fgCurFontIdx; ///< current font index
79  static Int_t fgSymbItaFontIdx; ///< Symbol italic font index
80  static Int_t fgFontCount; ///< number of fonts loaded
81  static char *fgFontName[kTTMaxFonts]; ///< font name
82  static FT_Face fgFace[kTTMaxFonts]; ///< font face
83  static TTF::TTGlyph fgGlyphs[kMaxGlyphs]; ///< glyphs
84  static Bool_t fgHinting; ///< use hinting (true by default)
85  static Bool_t fgInit; ///< true if the Init has been called
86  static Bool_t fgKerning; ///< use kerning (true by default)
87  static FT_Library fgLibrary; ///< FreeType font library
88  static Int_t fgNumGlyphs; ///< number of glyphs in the string
89  static FT_Matrix *fgRotMatrix; ///< rotation matrix
90  static Bool_t fgSmoothing; ///< use anti-aliasing (true when >8 planes, false otherwise)
91  static Int_t fgTBlankW; ///< trailing blanks width
92  static Int_t fgWidth; ///< string width, used to compute X alignment
93 
94 public:
95  static Short_t CharToUnicode(UInt_t code);
96  static void LayoutGlyphs();
97  static void PrepareString(const char *string);
98  static void PrepareString(const wchar_t *string);
99  static void SetRotationMatrix(Float_t angle);
100 
101 public:
102  TTF() { }
103  virtual ~TTF();
104 
105  static void Init();
106  static void Cleanup();
107  static Int_t GetAscent();
108  static const FT_BBox &GetBox();
109  static TTGlyph *GetGlyphs();
110  static Bool_t GetHinting();
111  static Bool_t GetKerning();
112  static Int_t GetNumGlyphs();
113  static FT_Matrix *GetRotMatrix();
114  static Bool_t GetSmoothing();
115  static Int_t GetWidth();
116  static void SetHinting(Bool_t state);
117  static void SetKerning(Bool_t state);
118  static void SetSmoothing(Bool_t state);
119  static void GetTextExtent(UInt_t &w, UInt_t &h, char *text);
120  static void GetTextExtent(UInt_t &w, UInt_t &h, wchar_t *text);
121  static void GetTextAdvance(UInt_t &a, char *text);
122  static void SetTextFont(Font_t fontnumber);
123  static Int_t SetTextFont(const char *fontname, Int_t italic=0);
124  static void SetTextSize(Float_t textsize);
125  static Bool_t IsInitialized();
126  static void Version(Int_t &major, Int_t &minor, Int_t &patch);
127 
128  ClassDef(TTF,0) //Interface to TTF font handling
129 };
130 
131 #endif
TTF::fgCharMap
static FT_CharMap fgCharMap[kTTMaxFonts]
font character map
Definition: TTF.h:77
TTF::CharToUnicode
static Short_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
Definition: TTF.cxx:99
TTF::GetWidth
static Int_t GetWidth()
Definition: TTF.cxx:615
TTF::TTGlyph
Definition: TTF.h:65
TTF::fgKerning
static Bool_t fgKerning
use kerning (true by default)
Definition: TTF.h:86
TTF::fgInit
static Bool_t fgInit
true if the Init has been called
Definition: TTF.h:85
TTF::LayoutGlyphs
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition: TTF.cxx:181
TTF::Init
static void Init()
Initialise the TrueType fonts interface.
Definition: TTF.cxx:65
TTF::Cleanup
static void Cleanup()
Cleanup. Is called by the gCleanupTTF destructor.
Definition: TTF.cxx:82
TTF::TTGlyph::fImage
FT_Glyph fImage
glyph image
Definition: TTF.h:69
TTF::fgSmoothing
static Bool_t fgSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
Definition: TTF.h:90
TTF::GetTextExtent
static void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Get width (w) and height (h) when text is horizontal.
Definition: TTF.cxx:132
TTF::fgFontName
static char * fgFontName[kTTMaxFonts]
font name
Definition: TTF.h:81
TTF::SetSmoothing
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
Definition: TTF.cxx:365
TGWin32
Definition: TGWin32.h:64
TTF::Version
static void Version(Int_t &major, Int_t &minor, Int_t &patch)
Definition: TTF.cxx:580
TTF::SetTextSize
static void SetTextSize(Float_t textsize)
Set current text size.
Definition: TTF.cxx:562
TTF::fgCurFontIdx
static Int_t fgCurFontIdx
current font index
Definition: TTF.h:78
TTF::fgSymbItaFontIdx
static Int_t fgSymbItaFontIdx
Symbol italic font index.
Definition: TTF.h:79
Float_t
float Float_t
Definition: RtypesCore.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TTF::SetTextFont
static void SetTextFont(Font_t fontnumber)
Set specified font.
Definition: TTF.cxx:491
Font_t
short Font_t
Definition: RtypesCore.h:79
TTF::~TTF
virtual ~TTF()
Cleanup TTF environment.
Definition: TTF.cxx:57
x
Double_t x[n]
Definition: legend1.C:17
TTF
Definition: TTF.h:53
TTF::SetHinting
static void SetHinting(Bool_t state)
Set hinting flag.
Definition: TTF.cxx:326
TTF::GetRotMatrix
static FT_Matrix * GetRotMatrix()
Definition: TTF.cxx:636
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TTF::TTGlyph::fPos
FT_Vector fPos
position of glyph origin
Definition: TTF.h:68
TTF::GetTextAdvance
static void GetTextAdvance(UInt_t &a, char *text)
Get advance (a) when text is horizontal.
Definition: TTF.cxx:148
TTF::GetSmoothing
static Bool_t GetSmoothing()
Definition: TTF.cxx:601
text
TText * text
Definition: entrylist_figure1.C:10
bool
TTF::fgGlyphs
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
glyphs
Definition: TTF.h:83
TTF::fgLibrary
static FT_Library fgLibrary
FreeType font library.
Definition: TTF.h:87
TTF::TTGlyph::fIndex
UInt_t fIndex
glyph index in face
Definition: TTF.h:67
TTF::fgRotMatrix
static FT_Matrix * fgRotMatrix
rotation matrix
Definition: TTF.h:89
TTF::fgWidth
static Int_t fgWidth
string width, used to compute X alignment
Definition: TTF.h:92
TTF::fgFontCount
static Int_t fgFontCount
number of fonts loaded
Definition: TTF.h:80
h
#define h(i)
Definition: RSha256.hxx:124
a
auto * a
Definition: textangle.C:12
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
y
Double_t y[n]
Definition: legend1.C:17
TTF::fgNumGlyphs
static Int_t fgNumGlyphs
number of glyphs in the string
Definition: TTF.h:88
Short_t
short Short_t
Definition: RtypesCore.h:39
TTF::GetAscent
static Int_t GetAscent()
Definition: TTF.cxx:622
TTF::kMaxGlyphs
@ kMaxGlyphs
Definition: TTF.h:73
unsigned int
TTF::GetGlyphs
static TTGlyph * GetGlyphs()
Definition: TTF.cxx:650
TTF::GetHinting
static Bool_t GetHinting()
Definition: TTF.cxx:587
TTF::TMathTextRenderer
friend class TMathTextRenderer
Definition: TTF.h:57
TTF::kTTMaxFonts
@ kTTMaxFonts
Definition: TTF.h:73
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TTF::fgHinting
static Bool_t fgHinting
use hinting (true by default)
Definition: TTF.h:84
TGX11TTF
Definition: TGX11TTF.h:27
TTF::TTF
TTF()
Definition: TTF.h:102
TTF::IsInitialized
static Bool_t IsInitialized()
Definition: TTF.cxx:608
TTF::fgCBox
static FT_BBox fgCBox
string control box
Definition: TTF.h:76
TTF::fgAscent
static Int_t fgAscent
string ascent, used to compute Y alignment
Definition: TTF.h:75
TTF::GetNumGlyphs
static Int_t GetNumGlyphs()
Definition: TTF.cxx:629
TTF::PrepareString
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Definition: TTF.cxx:250
TTF::SetRotationMatrix
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition: TTF.cxx:342
TTF::GetBox
static const FT_BBox & GetBox()
Definition: TTF.cxx:643
TTF::GetKerning
static Bool_t GetKerning()
Definition: TTF.cxx:594
Rtypes.h
TTF::fgFace
static FT_Face fgFace[kTTMaxFonts]
font face
Definition: TTF.h:82
TTF::fgTBlankW
static Int_t fgTBlankW
trailing blanks width
Definition: TTF.h:91
int
TTF::SetKerning
static void SetKerning(Bool_t state)
Set kerning flag.
Definition: TTF.cxx:334