Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTFhandle.h
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Sergey Linev 25/08/2026
3
4/*************************************************************************
5 * Copyright (C) 1995-2026, 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_TTFhandle
13#define ROOT_TTFhandle
14
15
16#include "Rtypes.h"
17#include <memory>
18#include <atomic>
19
20class TTF;
21
22class TTFhandle {
23 friend class TTF;
24
25 private:
26
27 struct GlyphStruct;
28 struct FontStruct;
29 class Tristate {
30 enum { kUndef, kOff, kOn } fState = kUndef;
31 public:
32 void Set(Bool_t on) { fState = on ? kOn : kOff; }
33 Bool_t IsUndef() const { return fState == kUndef; }
34 Bool_t IsOn() const { return fState == kOn; }
35 };
36
37 Tristate fKerning; ///< use kerning (true by default)
38 Tristate fSmoothing; ///< use anti-aliasing (true when >8 planes, false otherwise)
39 Tristate fHinting; ///< use hinting (false by default)
40
41 FontStruct *fFont = nullptr; ///< selected font
42 long fRotationXX = 0, fRotationXY = 0; ///< rotation matrix members
43 std::vector<GlyphStruct> fGlyphs; ///< glyphs
44 Int_t fAscent = 0; ///< string ascent, used to compute Y alignment
45 long xMin = 0, yMin = 0, xMax = 0, yMax = 0; ///< boundaries
46 Int_t fTBlankW = 0; ///< trailing blanks width
47 Int_t fWidth = 0; ///< string width, used to compute X alignment
48
51
52 Int_t SelectFontHandle(Int_t arg, const char *name = nullptr);
53
54 /// Thread-local wrapper to the FreeType library
55 struct FT_Library_Wrapper;
56 static thread_local FT_Library_Wrapper fFT_Library;
57 static std::atomic<Bool_t> gSmoothingPrefer;
58 static std::atomic<Bool_t> gHintingPrefer;
59 static std::atomic<Bool_t> fKerningPrefer;
60
61 void FillTTFGlypths(void *vect);
62
63 public:
64 TTFhandle();
65 virtual ~TTFhandle();
66
67 void SetSmoothing(Bool_t state) { fSmoothing.Set(state); }
68 void SetHinting(Bool_t state) { fHinting.Set(state); }
69 void SetKerning(Bool_t state) { fKerning.Set(state); }
71 Int_t SetTextFont(const char *fontname, Int_t italic = 0);
74
75 Bool_t GetSmoothing() const;
76 Bool_t GetHinting() const;
77 Bool_t GetKerning() const;
78 void* GetFontFace() const;
79
80 void PrepareString(const char *string);
81 void PrepareString(const wchar_t *string);
82 void LayoutGlyphs();
83
84 Int_t GetGlyphsWidth() const;
85 Int_t GetGlyphsHeight() const;
86
87 Int_t GetAscent() const { return fAscent; }
89 Int_t GetWidth() const { return fWidth; }
90 long GetBoxXMin() const { return xMin; }
91 long GetBoxXMax() const { return xMax; }
92 long GetBoxYMin() const { return yMin; }
93 long GetBoxYMax() const { return yMax; }
94
95 UInt_t GetNumGlyphs() const;
96 Bool_t ApplyAlignRotate(Int_t &px, Int_t &py, Int_t align, Int_t pad_width, Int_t pad_height);
97 Bool_t GetGlyphData(UInt_t n, Int_t &offx, Int_t &offy, UChar_t *&buffer, UInt_t &width, UInt_t &rows, UInt_t &pitch);
98 void CleanupGlyphs();
99
100 void GetTextExtent(UInt_t &w, UInt_t &h, const char *text);
101 void GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text);
102 void GetTextAdvance(UInt_t &a, const char *text);
103
104 void Version(Int_t &major, Int_t &minor, Int_t &patch);
105
106 static Bool_t Init();
107 static void SetKerningPrefer(Bool_t on);
108 static Bool_t GetKerningPrefer();
109 static void SetSmoothingPrefer(Bool_t on);
110 static Bool_t GetSmoothingPrefer();
111 static void SetHintingPrefer(Bool_t on);
112 static Bool_t GetHintingPrefer();
113
114 ClassDef(TTFhandle, 0) // Dynamic interface to TTF
115
116};
117
118#endif
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:53
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:61
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Font_t
Font number (short)
Definition RtypesCore.h:96
#define ClassDef(name, id)
Definition Rtypes.h:343
Option_t Option_t SetTextSize
Option_t Option_t fontnumber
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t SetTextFont
Option_t Option_t textsize
Option_t Option_t TPoint TPoint angle
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char fontname
Option_t Option_t width
Option_t Option_t TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:142
Interface to the freetype 2 library.
Definition TTF.h:60
Bool_t IsOn() const
Definition TTFhandle.h:34
enum TTFhandle::Tristate::@54 fState
void Set(Bool_t on)
Definition TTFhandle.h:32
Bool_t IsUndef() const
Definition TTFhandle.h:33
Dynamic handle to work with freetype 2 library.
Definition TTFhandle.h:22
void GetTextExtent(UInt_t &w, UInt_t &h, const char *text)
Get width (w) and height (h) when text is horizontal.
long fRotationXX
Definition TTFhandle.h:42
void * GetFontFace() const
Return current font index.
virtual ~TTFhandle()
long xMax
Definition TTFhandle.h:45
Int_t GetWidth() const
Definition TTFhandle.h:89
Int_t fAscent
string ascent, used to compute Y alignment
Definition TTFhandle.h:44
Int_t SelectFontHandle(Int_t arg, const char *name=nullptr)
Return thread_local instance of FontStruct for speified font.
FontStruct * fFont
selected font
Definition TTFhandle.h:41
long GetBoxYMax() const
Definition TTFhandle.h:93
void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
UInt_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
static Bool_t Init()
static void SetSmoothingPrefer(Bool_t on)
Set global flag to switch on/off smoothing of TTF text drawing This flag is used when SetSmoothing() ...
UInt_t GetNumGlyphs() const
return number of glyphs
long GetBoxYMin() const
Definition TTFhandle.h:92
void SetHinting(Bool_t state)
Definition TTFhandle.h:68
long xMin
Definition TTFhandle.h:45
Bool_t GetHinting() const
Returns true if hinting for this instance is enabled If SetHinting() was not called before - use glob...
Int_t GetAscent() const
Definition TTFhandle.h:87
Int_t GetGlyphsHeight() const
Returns height of all glyphs.
std::vector< GlyphStruct > fGlyphs
glyphs
Definition TTFhandle.h:43
static Bool_t GetSmoothingPrefer()
Returns true if smoothing of text drawing is enabled by default.
long fRotationXY
rotation matrix members
Definition TTFhandle.h:42
long yMin
Definition TTFhandle.h:45
Tristate fSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
Definition TTFhandle.h:38
long GetBoxXMax() const
Definition TTFhandle.h:91
Int_t fTBlankW
trailing blanks width
Definition TTFhandle.h:46
Int_t GetTrailingBlanksWidth() const
Definition TTFhandle.h:88
void SetKerning(Bool_t state)
Definition TTFhandle.h:69
void Version(Int_t &major, Int_t &minor, Int_t &patch)
Int_t GetGlyphsWidth() const
Returns width of all glyphs.
static thread_local FT_Library_Wrapper fFT_Library
Definition TTFhandle.h:56
void CleanupGlyphs()
Remove temporary data created by LayoutGlyphs.
Tristate fHinting
use hinting (false by default)
Definition TTFhandle.h:39
long GetBoxXMin() const
Definition TTFhandle.h:90
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Bool_t GetKerning() const
Returns true if kerning for this instance is enabled If SetKerning() was not called before - use glob...
static std::atomic< Bool_t > fKerningPrefer
Definition TTFhandle.h:59
static void SetHintingPrefer(Bool_t on)
Set global flag to switch on/off hinting of TTF text drawing This flag is used when SetHiniting() fla...
static void SetKerningPrefer(Bool_t on)
Set global flag to switch on/off kerning of TTF text drawing This flag is used when SetKerning() flag...
static Bool_t GetHintingPrefer()
Returns true if hinting of text drawing is enabled by default.
void ComputeTrailingBlanksWidth(Int_t n)
Compute the trailing blanks width.
Tristate fKerning
use kerning (true by default)
Definition TTFhandle.h:37
void GetTextAdvance(UInt_t &a, const char *text)
Get advance (a) when text is horizontal.
static Bool_t GetKerningPrefer()
Returns true if kerning of text drawing is enabled by default.
Int_t fWidth
string width, used to compute X alignment
Definition TTFhandle.h:47
void FillTTFGlypths(void *vect)
Fill vector from TTF class Only for backward compatibility of old API.
Bool_t GetSmoothing() const
Returns true if smoothing for this instance is enabled If SetSmoothing() was not called before - use ...
void SetSmoothing(Bool_t state)
Definition TTFhandle.h:67
static std::atomic< Bool_t > gSmoothingPrefer
Definition TTFhandle.h:57
static std::atomic< Bool_t > gHintingPrefer
Definition TTFhandle.h:58
long yMax
boundaries
Definition TTFhandle.h:45
Bool_t GetGlyphData(UInt_t n, Int_t &offx, Int_t &offy, UChar_t *&buffer, UInt_t &width, UInt_t &rows, UInt_t &pitch)
Returns data for glyph bitmap Instead direct access to FT_BitmapGlyph one can obtain all relevant fie...
Bool_t ApplyAlignRotate(Int_t &px, Int_t &py, Int_t align, Int_t pad_width, Int_t pad_height)
Apply align and configured rotation matrix to text position px and py will be shifted to the place wh...
const Int_t n
Definition legend1.C:16
Thread-local wrapper to the freetype library.
Definition TTFhandle.cxx:66