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
19class TTF;
20
21class TTFhandle {
22 friend class TTF;
23
24 private:
25
26 struct GlyphStruct;
27 struct FontStruct;
28
29 Bool_t fKerning = kTRUE; ///< use kerning (true by default)
30 Bool_t fSmoothing = kTRUE; ///< use anti-aliasing (true when >8 planes, false otherwise)
31 Bool_t fHinting = kFALSE; ///< use hinting (false by default)
32
33 FontStruct *fFont = nullptr; ///< selected font
34 long fRotationXX = 0, fRotationXY = 0; ///< rotation matrix members
35 std::vector<GlyphStruct> fGlyphs; ///< glyphs
36 Int_t fAscent = 0; ///< string ascent, used to compute Y alignment
37 long xMin = 0, yMin = 0, xMax = 0, yMax = 0; ///< boundaries
38 Int_t fTBlankW = 0; ///< trailing blanks width
39 Int_t fWidth = 0; ///< string width, used to compute X alignment
40
43
44 Int_t SelectFontHandle(Int_t arg, const char *name = nullptr);
45
46 /// Thread-local wrapper to the FreeType library
47 struct FT_Library_Wrapper;
48 static thread_local FT_Library_Wrapper fFT_Library;
49
50 void FillTTFGlypths(void *vect);
51
52 public:
53 TTFhandle();
54 virtual ~TTFhandle();
55
56 void SetSmoothing(Bool_t state) { fSmoothing = state; }
57 void SetHinting(Bool_t state) { fHinting = state; }
58 void SetKerning(Bool_t state) { fKerning = state; }
60 Int_t SetTextFont(const char *fontname, Int_t italic = 0);
63
64 Bool_t GetSmoothing() const { return fSmoothing; }
65 Bool_t GetHinting() const { return fHinting; }
66 Bool_t GetKerning() const { return fKerning; }
67 void* GetFontFace() const;
68
69 void PrepareString(const char *string);
70 void PrepareString(const wchar_t *string);
71 void LayoutGlyphs();
72
73 Int_t GetGlyphsWidth() const;
74 Int_t GetGlyphsHeight() const;
75
76 Int_t GetAscent() const { return fAscent; }
78 Int_t GetWidth() const { return fWidth; }
79 long GetBoxXMin() const { return xMin; }
80 long GetBoxXMax() const { return xMax; }
81 long GetBoxYMin() const { return yMin; }
82 long GetBoxYMax() const { return yMax; }
83
84 UInt_t GetNumGlyphs() const;
87 void CleanupGlyphs();
88
89 void GetTextExtent(UInt_t &w, UInt_t &h, const char *text);
90 void GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text);
91 void GetTextAdvance(UInt_t &a, const char *text);
92
94
95 static Bool_t Init();
96
97 ClassDef(TTFhandle, 0) // Dynamic interface to TTF
98
99};
100
101#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
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
#define ClassDef(name, id)
Definition Rtypes.h:344
Option_t Option_t SetTextSize
Option_t Option_t fontnumber
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:55
Dynamic handle to work with freetype 2 library.
Definition TTFhandle.h:21
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:34
Bool_t fKerning
use kerning (true by default)
Definition TTFhandle.h:29
void * GetFontFace() const
Return current font index.
virtual ~TTFhandle()
Definition TTFhandle.cxx:95
long xMax
Definition TTFhandle.h:37
Int_t GetWidth() const
Definition TTFhandle.h:78
Int_t fAscent
string ascent, used to compute Y alignment
Definition TTFhandle.h:36
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:33
long GetBoxYMax() const
Definition TTFhandle.h:82
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()
UInt_t GetNumGlyphs() const
return number of glyphs
long GetBoxYMin() const
Definition TTFhandle.h:81
void SetHinting(Bool_t state)
Definition TTFhandle.h:57
long xMin
Definition TTFhandle.h:37
Bool_t GetHinting() const
Definition TTFhandle.h:65
Int_t GetAscent() const
Definition TTFhandle.h:76
Int_t GetGlyphsHeight() const
Returns height of all glyphs.
std::vector< GlyphStruct > fGlyphs
glyphs
Definition TTFhandle.h:35
long fRotationXY
rotation matrix members
Definition TTFhandle.h:34
long yMin
Definition TTFhandle.h:37
long GetBoxXMax() const
Definition TTFhandle.h:80
Int_t fTBlankW
trailing blanks width
Definition TTFhandle.h:38
Int_t GetTrailingBlanksWidth() const
Definition TTFhandle.h:77
void SetKerning(Bool_t state)
Definition TTFhandle.h:58
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:48
Bool_t fHinting
use hinting (false by default)
Definition TTFhandle.h:31
void CleanupGlyphs()
Remove temporary data created by LayoutGlyphs.
long GetBoxXMin() const
Definition TTFhandle.h:79
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Bool_t GetKerning() const
Definition TTFhandle.h:66
void ComputeTrailingBlanksWidth(Int_t n)
Compute the trailing blanks width.
void GetTextAdvance(UInt_t &a, const char *text)
Get advance (a) when text is horizontal.
Bool_t fSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
Definition TTFhandle.h:30
Int_t fWidth
string width, used to compute X alignment
Definition TTFhandle.h:39
void FillTTFGlypths(void *vect)
Fill vector from TTF class Only for backward compatibility of old API.
Bool_t GetSmoothing() const
Definition TTFhandle.h:64
void SetSmoothing(Bool_t state)
Definition TTFhandle.h:56
long yMax
boundaries
Definition TTFhandle.h:37
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:59