ROOT  6.06/09
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 //////////////////////////////////////////////////////////////////////////
18 // //
19 // TTF //
20 // //
21 // Interface to the Freetype 2 library. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #ifndef ROOT_Rtypes
26 #include "Rtypes.h"
27 #endif
28 
29 /// @cond DOXYGEN_IGNORE
30 // Forward declare for the headers:
31 // # include <ft2build.h>
32 // # include FT_FREETYPE_H
33 // # include FT_GLYPH_H
34 extern "C" {
35  struct FT_LibraryRec_;
36  struct FT_FaceRec_;
37  struct FT_CharMapRec_;
38  struct FT_GlyphRec_;
39  struct FT_Matrix_;
40  struct FT_Bitmap_;
41  typedef struct FT_LibraryRec_* FT_Library;
42  typedef struct FT_FaceRec_* FT_Face;
43  typedef struct FT_CharMapRec_* FT_CharMap;
44  typedef struct FT_GlyphRec_* FT_Glyph;
45  typedef struct FT_Matrix_ FT_Matrix;
46  typedef struct FT_Bitmap_ FT_Bitmap; // Forward declared for TGX11TTF.h's benefit
47  typedef signed long FT_Pos;
48  #ifndef FT_FREETYPE_H
49  struct FT_Vector_ { FT_Pos x, y; };
50  struct FT_BBox_ { FT_Pos xMin, yMin, xMax, yMax; };
51  #endif
52  typedef struct FT_Vector_ FT_Vector;
53  typedef struct FT_BBox_ FT_BBox;
54 }
55 /// @endcond
56 
57 
58 class TGX11TTF;
59 class TGWin32;
60 class TMathTextRenderer;
61 
62 
63 class TTF {
64 
65 friend class TGX11TTF;
66 friend class TGWin32;
67 friend class TMathTextRenderer;
68 
69 public:
70 
71 /** \class TTGlyph
72 TTF helper class containing glyphs description.
73 */
74 
75  class TTGlyph {
76  public:
77  UInt_t fIndex; // glyph index in face
78  FT_Vector fPos; // position of glyph origin
79  FT_Glyph fImage; // glyph image
80  };
81 
82 protected:
83  enum { kTTMaxFonts = 32, kMaxGlyphs = 1024 };
84 
85  static Int_t fgAscent; // string ascent, used to compute Y alignment
86  static FT_BBox fgCBox; // string control box
87  static FT_CharMap fgCharMap[kTTMaxFonts]; // font character map
88  static Int_t fgCurFontIdx; // current font index
89  static Int_t fgSymbItaFontIdx; // Symbol italic font index
90  static Int_t fgFontCount; // number of fonts loaded
91  static char *fgFontName[kTTMaxFonts]; // font name
92  static FT_Face fgFace[kTTMaxFonts]; // font face
93  static TTF::TTGlyph fgGlyphs[kMaxGlyphs]; // glyphs
94  static Bool_t fgHinting; // use hinting (true by default)
95  static Bool_t fgInit; // true if the Init has been called
96  static Bool_t fgKerning; // use kerning (true by default)
97  static FT_Library fgLibrary; // FreeType font library
98  static Int_t fgNumGlyphs; // number of glyphs in the string
99  static FT_Matrix *fgRotMatrix; // rotation matrix
100  static Bool_t fgSmoothing; // use anti-aliasing (true when >8 planes, false otherwise)
101  static Int_t fgTBlankW; // trailing blanks width
102  static Int_t fgWidth; // string width, used to compute X alignment
103 
104 public:
105  static Short_t CharToUnicode(UInt_t code);
106  static void LayoutGlyphs();
107  static void PrepareString(const char *string);
108  static void PrepareString(const wchar_t *string);
109  static void SetRotationMatrix(Float_t angle);
110 
111 public:
112  TTF() { }
113  virtual ~TTF();
114 
115  static void Init();
116  static void Cleanup();
117  static Int_t GetAscent();
118  static const FT_BBox &GetBox();
119  static TTGlyph *GetGlyphs();
120  static Bool_t GetHinting();
121  static Bool_t GetKerning();
122  static Int_t GetNumGlyphs();
123  static FT_Matrix *GetRotMatrix();
124  static Bool_t GetSmoothing();
125  static Int_t GetWidth();
126  static void SetHinting(Bool_t state);
127  static void SetKerning(Bool_t state);
128  static void SetSmoothing(Bool_t state);
129  static void GetTextExtent(UInt_t &w, UInt_t &h, char *text);
130  static void GetTextExtent(UInt_t &w, UInt_t &h, wchar_t *text);
131  static void GetTextAdvance(UInt_t &a, char *text);
132  static void SetTextFont(Font_t fontnumber);
133  static Int_t SetTextFont(const char *fontname, Int_t italic=0);
134  static void SetTextSize(Float_t textsize);
135  static Bool_t IsInitialized();
136  static void Version(Int_t &major, Int_t &minor, Int_t &patch);
137 
138  ClassDef(TTF,0) //Interface to TTF font handling
139 };
140 
141 #endif
static void Init()
Initialise the TrueType fonts interface.
Definition: TTF.cxx:67
FT_Vector fPos
Definition: TTF.h:78
static FT_Matrix * fgRotMatrix
Definition: TTF.h:99
float Float_t
Definition: RtypesCore.h:53
static Int_t fgFontCount
Definition: TTF.h:90
static Bool_t IsInitialized()
Definition: TTF.cxx:618
FT_Glyph fImage
Definition: TTF.h:79
TH1 * h
Definition: legend2.C:5
static void Cleanup()
Cleanup. Is called by the gCleanupTTF destructor.
Definition: TTF.cxx:84
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Interface to the freetype 2 library.
Definition: TTF.h:63
TArc * a
Definition: textangle.C:12
This class is the basic interface to the Win32 graphics system.
Definition: TGWin32.h:80
static void Version(Int_t &major, Int_t &minor, Int_t &patch)
Definition: TTF.cxx:590
UInt_t fIndex
Definition: TTF.h:77
short Font_t
Definition: RtypesCore.h:75
Interface to low level X11 (Xlib).
Definition: TGX11TTF.h:45
static FT_CharMap fgCharMap[kTTMaxFonts]
Definition: TTF.h:87
static Int_t fgAscent
Definition: TTF.h:85
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
Definition: TTF.h:93
Double_t x[n]
Definition: legend1.C:17
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition: TTF.cxx:183
#define ClassDef(name, id)
Definition: Rtypes.h:254
static Bool_t GetHinting()
Definition: TTF.cxx:597
static void SetTextFont(Font_t fontnumber)
Set specified font.
Definition: TTF.cxx:496
static void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Get width (w) and height (h) when text is horizontal.
Definition: TTF.cxx:134
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Definition: TTF.cxx:249
TTF()
Definition: TTF.h:112
static FT_BBox fgCBox
Definition: TTF.h:86
static void GetTextAdvance(UInt_t &a, char *text)
Get advance (a) when text is horizontal.
Definition: TTF.cxx:150
static TTGlyph * GetGlyphs()
Definition: TTF.cxx:660
static Int_t fgTBlankW
Definition: TTF.h:101
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
Definition: TTF.cxx:364
virtual ~TTF()
static Int_t fgCurFontIdx
Definition: TTF.h:88
static Int_t GetWidth()
Definition: TTF.cxx:625
static FT_Library fgLibrary
Definition: TTF.h:97
static Bool_t GetKerning()
Definition: TTF.cxx:604
static Bool_t fgKerning
Definition: TTF.h:96
static Bool_t fgInit
Definition: TTF.h:95
static FT_Matrix * GetRotMatrix()
Definition: TTF.cxx:646
unsigned int UInt_t
Definition: RtypesCore.h:42
TTF helper class containing glyphs description.
Definition: TTF.h:75
short Short_t
Definition: RtypesCore.h:35
static void SetHinting(Bool_t state)
Set hinting flag.
Definition: TTF.cxx:325
static void SetKerning(Bool_t state)
Set kerning flag.
Definition: TTF.cxx:333
static char * fgFontName[kTTMaxFonts]
Definition: TTF.h:91
friend class TMathTextRenderer
Definition: TTF.h:67
static Bool_t fgHinting
Definition: TTF.h:94
static Int_t fgSymbItaFontIdx
Definition: TTF.h:89
static Int_t GetAscent()
Definition: TTF.cxx:632
TText * text
Double_t y[n]
Definition: legend1.C:17
static Bool_t fgSmoothing
Definition: TTF.h:100
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition: TTF.cxx:341
static FT_Face fgFace[kTTMaxFonts]
Definition: TTF.h:92
static Int_t fgNumGlyphs
Definition: TTF.h:98
static void SetTextSize(Float_t textsize)
Set current text size.
Definition: TTF.cxx:572
static Short_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
Definition: TTF.cxx:101
static Int_t GetNumGlyphs()
Definition: TTF.cxx:639
static Int_t fgWidth
Definition: TTF.h:102
static const FT_BBox & GetBox()
Definition: TTF.cxx:653
static Bool_t GetSmoothing()
Definition: TTF.cxx:611