Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTF.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Olivier Couet 01/10/2002
3// Author: Sergey Linev 29/04/2026
4
5/*************************************************************************
6 * Copyright (C) 1995-2026, 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
14/** \class TTFhandle
15\ingroup BasicGraphics
16
17Dynamic handle to work with freetype 2 library.
18in ROOT7 TTFhandle will be renamed into TTF class
19*/
20
21
22#include <ft2build.h>
23#include FT_FREETYPE_H
24#include FT_GLYPH_H
25#include "TROOT.h"
26#include "TTF.h"
27#include "TSystem.h"
28#include "TEnv.h"
29#include "TMath.h"
30#include "TError.h"
31
32// to scale fonts to the same size as the old TT version
33const Float_t kScale = 0.93376068;
34
37
38/// Free all resources of this glyph.
43
45 std::string name;
46 FT_Face face = nullptr;
47 FT_CharMap charmap = nullptr;
48 bool is_symbol() const
49 {
50 return (name == "wingding.ttf") || (name.find("symbol.ttf") == 0);
51 }
52};
53
54////////////////////////////////////////////////////////////////////////////////
55/// Thread-local wrapper to the freetype library.
56/// The library gets initialised on demand when Get() is called.
57/// It auto-destructs when the thread exits.
59 FT_Library _library = nullptr;
60 FT_Library_Wrapper() = default;
65
66 FT_Library Get()
67 {
68 if (!_library && FT_Init_FreeType(&_library) != 0) {
69 Error("TTF.cxx", "error initializing FreeType");
70 _library = nullptr;
71 }
72 return _library;
73 }
74
76 {
77 if (_library)
78 FT_Done_FreeType(_library);
79 }
80};
81
83
84////////////////////////////////////////////////////////////////////////////////
85
87{
88 // Ensure that there's a freetype library in our thread
89 fFT_Library.Get();
90}
91
92////////////////////////////////////////////////////////////////////////////////
93
98
99////////////////////////////////////////////////////////////////////////////////
100/// Map char to unicode. Returns 0 in case no mapping exists.
101
103{
104 FT_Face face = fFont ? fFont->face : nullptr;
105 if (!face)
106 return 0;
107
108 if (!fFont->charmap) {
109 Int_t n = face->num_charmaps;
110 for (Int_t i = 0; i < n; i++) {
111 FT_CharMap charmap = face->charmaps[i];
112 auto platform = charmap->platform_id;
113 auto encoding = charmap->encoding_id;
114 if ((platform == 3 && encoding == 1) ||
115 (platform == 0 && encoding == 0) ||
116 (platform == 1 && encoding == 0 && fFont->is_symbol()))
117 {
118 fFont->charmap = charmap;
119 if (FT_Set_Charmap(face, charmap))
120 Error("TTF::CharToUnicode", "error in FT_Set_CharMap");
121 break;
122 }
123 }
124 }
125 return FT_Get_Char_Index(face, (FT_ULong)code);
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Compute the trailing blanks width. It is use to compute the text width in GetTextExtent
130/// `n` is the number of trailing blanks in a string.
131
133{
134 fTBlankW = 0;
135 if (n && fFont) {
136 FT_Face face = fFont->face;
137 char space = ' ';
139 if (!fgHinting) load_flags |= FT_LOAD_NO_HINTING;
140 FT_Load_Char(face, space, load_flags);
141
142 FT_GlyphSlot slot = face->glyph;
143 FT_Pos advance_x = slot->advance.x;
145
146 fTBlankW = advance_x_pixels * n;
147 }
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Get width (w) and height (h) when text is horizontal.
152
154{
157 LayoutGlyphs();
158 Int_t Xoff = 0; if (fCBox.xMin < 0) Xoff = -fCBox.xMin;
159 Int_t Yoff = 0; if (fCBox.yMin < 0) Yoff = -fCBox.yMin;
160 w = fCBox.xMax + Xoff + GetTrailingBlanksWidth();
161 h = fCBox.yMax + Yoff;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Get advance (a) when text is horizontal.
167
169{
172 LayoutGlyphs();
173 a = GetWidth() >> 6;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Get width (w) and height (h) when text is horizontal.
179
181{
184 LayoutGlyphs();
185 Int_t Xoff = 0; if (fCBox.xMin < 0) Xoff = -fCBox.xMin;
186 Int_t Yoff = 0; if (fCBox.yMin < 0) Yoff = -fCBox.yMin;
187 w = fCBox.xMax + Xoff + GetTrailingBlanksWidth();
188 h = fCBox.yMax + Yoff;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
194/// Perform the Glyphs transformation.
195/// Compute the string control box.
196/// If required take the "kerning" into account.
197/// SetRotation and PrepareString should have been called before.
198
200{
201 FT_Vector origin;
204
205 fAscent = 0;
206 fWidth = 0;
207
209 if (!fgHinting)
211
212 fCBox.xMin = fCBox.yMin = 32000;
213 fCBox.xMax = fCBox.yMax = -32000;
214
215 FT_Face face = fFont ? fFont->face : nullptr;
216 if (!face)
217 return;
218
219 for (auto &glyph : fGlyphs) {
220
221 // compute glyph origin
222 if (fKerning) {
223 if (prev_index) {
224 FT_Vector kern;
225 FT_Get_Kerning(face, prev_index, glyph.fIndex,
227 &kern);
228 fWidth += kern.x;
229 }
230 prev_index = glyph.fIndex;
231 }
232
233 origin.x = fWidth;
234 origin.y = 0;
235
236 // clear existing image if there is one
237 if (glyph.fImage) {
238 FT_Done_Glyph(glyph.fImage);
239 glyph.fImage = nullptr;
240 }
241
242 // load the glyph image (in its native format)
243 if (FT_Load_Glyph(face, glyph.fIndex, load_flags))
244 continue;
245
246 // extract the glyph image
247 if (FT_Get_Glyph(face->glyph, &glyph.fImage))
248 continue;
249
250 glyph.fPos = origin;
251 fWidth += face->glyph->advance.x;
252 fAscent = TMath::Max((Int_t)(face->glyph->metrics.horiBearingY), fAscent);
253
254 // transform the glyphs
255 FT_Vector_Transform(&glyph.fPos, fRotMatrix.get());
256 if (FT_Glyph_Transform(glyph.fImage, fRotMatrix.get(), &glyph.fPos))
257 continue;
258
259 // compute the string control box
260 FT_BBox bbox;
262 if (bbox.xMin < fCBox.xMin) fCBox.xMin = bbox.xMin;
263 if (bbox.yMin < fCBox.yMin) fCBox.yMin = bbox.yMin;
264 if (bbox.xMax > fCBox.xMax) fCBox.xMax = bbox.xMax;
265 if (bbox.yMax > fCBox.yMax) fCBox.yMax = bbox.yMax;
266 }
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Return bitmap for specified glyph
271
273{
274 if (n >= fGlyphs.size())
275 return nullptr;
276
277 if (FT_Glyph_To_Bitmap(&fGlyphs[n].fImage, smooth || GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono, nullptr, 1))
278 return nullptr;
279
280 return (FT_BitmapGlyph) fGlyphs[n].fImage;
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Remove temporary data created by LayoutGlyphs
285
287{
288 fGlyphs.clear();
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Put the characters in "string" in the "glyphs" array.
293
294void TTFhandle::PrepareString(const char *string)
295{
297
298 const unsigned char *p = (const unsigned char*) string;
299
300 Int_t NbTBlank = 0; // number of trailing blanks
301
302 while (*p) {
304 if (index != 0)
305 fGlyphs.emplace_back(index);
306 if (*p == ' ')
307 NbTBlank++;
308 else
309 NbTBlank = 0;
310 p++;
311 }
312
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Put the characters in "string" in the "glyphs" array.
318
319void TTFhandle::PrepareString(const wchar_t *string)
320{
322
323 FT_Face face = fFont ? fFont->face : nullptr;
324 if (!face)
325 return;
326
327 const wchar_t *p = string;
328
329 Int_t NbTBlank = 0; // number of trailing blanks
330
331 while (*p) {
333 if (index != 0)
334 fGlyphs.emplace_back(index);
335 if (*p == ' ')
336 NbTBlank++;
337 else
338 NbTBlank = 0;
339 p++;
340 }
341
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Return current font index
347
349{
350 return fFont ? fFont->face : nullptr;
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Set the rotation matrix used to rotate the font outlines.
355
357{
358 Float_t rangle = angle * TMath::Pi() / 180.; // Angle in radian
359#if defined(FREETYPE_PATCH) && \
360 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
363#else
364 Float_t sin = TMath::Sin(-rangle);
365 Float_t cos = TMath::Cos(-rangle);
366#endif
367
368 if (!fRotMatrix)
369 fRotMatrix = std::make_unique<FT_Matrix>();
370
371 fRotMatrix->xx = (FT_Fixed) (cos * (1<<16));
372 fRotMatrix->xy = (FT_Fixed) (sin * (1<<16));
373 fRotMatrix->yx = -fRotMatrix->xy;
374 fRotMatrix->yy = fRotMatrix->xx;
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Return thread_local instance of TTFontHandle for speified font
379
381{
382 thread_local std::map<std::string, TTFontHandle> _fonts;
383
384 fFont = nullptr;
385
386 if (arg == 111) {
387 // select any existing font, fallback solution for some errors in SetTextFont
388 if (!_fonts.empty())
389 fFont = &(_fonts.begin()->second);
390 Warning("TTFhandle::SetTextFont", "%s, using %s", name, fFont ? fFont->name.c_str() : "<nothing>");
391 return fFont ? 0 : 1;
392 }
393
394 if (arg >= 0) {
395 auto iter = _fonts.find(name);
396 if (iter != _fonts.end()) {
397 fFont = &iter->second;
398 return 0;
399 }
400 if (arg == 0)
401 return 1;
402 _fonts[name] = { name, nullptr, nullptr };
403 fFont = &_fonts[name];
404 return 0;
405 }
406
407 for (auto &font : _fonts) {
408 if (font.second.face) {
409 FT_Done_Face(font.second.face);
410 font.second.face = nullptr;
411 }
412 }
413 _fonts.clear();
414 return 0;
415}
416
417
418////////////////////////////////////////////////////////////////////////////////
419/// Set text font to specified name.
420/// - font : font name
421/// - italic : the fonts should be slanted. Used for symbol font.
422///
423/// Set text font to specified name. This function returns 0 if
424/// the specified font is found, 1 if not.
425
427{
428 fFont = nullptr;
429
430 if (!fontname || !*fontname)
431 return SelectFontHandle(111, "no font name specified");
432
433 const char *basename = gSystem->BaseName(fontname);
434
435 if (SelectFontHandle(1, TString::Format("%s%s", basename, italic ? ".italic" : ""))) {
436 Fatal("SetTextFont", "Fail to create font handle for font %s", basename);
437 return 1;
438 }
439
440 // font face exists and initialized
441 if (fFont->face)
442 return 0;
443
444 auto lib = fFT_Library.Get();
445 if (!lib) {
446 Error("SetTextFont", "no free type library initialized");
447 return 1;
448 }
449
450 // try to load font (font must be in Root.TTFontPath resource)
451 const char *ttpath = gEnv->GetValue("Root.TTFontPath", TROOT::GetTTFFontDir());
452
455
456 if (!ttfont)
457 return SelectFontHandle(111, TString::Format("font file %s not found in path %s", fontname, ttpath));
458
459 if (FT_New_Face(lib, ttfont, 0, &fFont->face))
460 return SelectFontHandle(111, TString::Format("error loading font %s", ttfont));
461
462 if (italic) {
464 slantMat.xx = (1 << 16);
465 slantMat.xy = ((1 << 16) >> 2);
466 slantMat.yx = 0;
467 slantMat.yy = (1 << 16);
468 FT_Set_Transform(fFont->face, &slantMat, nullptr);
469 }
470
471 return 0;
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Set specified font.
476/// List of the currently supported fonts (screen and PostScript)
477///
478/// | Font number | TTF Names | PostScript/PDF Names |
479/// |-------------|---------------------------|-------------------------------|
480/// | 1 | Free Serif Italic | Times-Italic |
481/// | 2 | Free Serif Bold | Times-Bold |
482/// | 3 | Free Serif Bold Italic | Times-BoldItalic |
483/// | 4 | Tex Gyre Regular | Helvetica |
484/// | 5 | Tex Gyre Italic | Helvetica-Oblique |
485/// | 6 | Tex Gyre Bold | Helvetica-Bold |
486/// | 7 | Tex Gyre Bold Italic | Helvetica-BoldOblique |
487/// | 8 | Free Mono | Courier |
488/// | 9 | Free Mono Oblique | Courier-Oblique |
489/// | 10 | Free Mono Bold | Courier-Bold |
490/// | 11 | Free Mono Bold Oblique | Courier-BoldOblique |
491/// | 12 | Symbol | Symbol |
492/// | 13 | Free Serif | Times-Roman |
493/// | 14 | Wingdings | ZapfDingbats |
494
496{
497 // Added by cholm for use of DFSG - fonts - based on Kevins fix.
498 // Table of Microsoft and (for non-MSFT operating systems) backup
499 // FreeFont TTF fonts.
500 static const char *fonttable[][2] = {
501 { "Root.TTFont.0", "FreeSansBold.otf" },
502 { "Root.TTFont.1", "FreeSerifItalic.otf" },
503 { "Root.TTFont.2", "FreeSerifBold.otf" },
504 { "Root.TTFont.3", "FreeSerifBoldItalic.otf" },
505 { "Root.TTFont.4", "texgyreheros-regular.otf" },
506 { "Root.TTFont.5", "texgyreheros-italic.otf" },
507 { "Root.TTFont.6", "texgyreheros-bold.otf" },
508 { "Root.TTFont.7", "texgyreheros-bolditalic.otf" },
509 { "Root.TTFont.8", "FreeMono.otf" },
510 { "Root.TTFont.9", "FreeMonoOblique.otf" },
511 { "Root.TTFont.10", "FreeMonoBold.otf" },
512 { "Root.TTFont.11", "FreeMonoBoldOblique.otf" },
513 { "Root.TTFont.12", "symbol.ttf" },
514 { "Root.TTFont.13", "FreeSerif.otf" },
515 { "Root.TTFont.14", "wingding.ttf" },
516 { "Root.TTFont.15", "symbol.ttf" },
517 { "Root.TTFont.STIXGen", "STIXGeneral.otf" },
518 { "Root.TTFont.STIXGenIt", "STIXGeneralItalic.otf" },
519 { "Root.TTFont.STIXGenBd", "STIXGeneralBol.otf" },
520 { "Root.TTFont.STIXGenBdIt", "STIXGeneralBolIta.otf" },
521 { "Root.TTFont.STIXSiz1Sym", "STIXSiz1Sym.otf" },
522 { "Root.TTFont.STIXSiz1SymBd", "STIXSiz1SymBol.otf" },
523 { "Root.TTFont.STIXSiz2Sym", "STIXSiz2Sym.otf" },
524 { "Root.TTFont.STIXSiz2SymBd", "STIXSiz2SymBol.otf" },
525 { "Root.TTFont.STIXSiz3Sym", "STIXSiz3Sym.otf" },
526 { "Root.TTFont.STIXSiz3SymBd", "STIXSiz3SymBol.otf" },
527 { "Root.TTFont.STIXSiz4Sym", "STIXSiz4Sym.otf" },
528 { "Root.TTFont.STIXSiz4SymBd", "STIXSiz4SymBol.otf" },
529 { "Root.TTFont.STIXSiz5Sym", "STIXSiz5Sym.otf" },
530 { "Root.TTFont.ME", "DroidSansFallback.ttf" },
531 { "Root.TTFont.CJKMing", "DroidSansFallback.ttf" },
532 { "Root.TTFont.CJKGothic", "DroidSansFallback.ttf" }
533 };
534
535 static int fontset = -1;
536 int thisset = fontset;
537
538 int fontid = fontnumber / 10;
539 if (fontid < 0 || fontid > 31) fontid = 0;
540
541 if (thisset == -1) {
542 // try to load font (font must be in Root.TTFontPath resource)
543 // to see which fontset we have available
544 const char *ttpath = gEnv->GetValue("Root.TTFontPath",
548 thisset = ttfont ? 0 : 1;
549 }
550 Int_t italic = fontid == 15 ? 1 : 0;
552
553 // Do not define font set is we're loading the symbol.ttf - it's
554 // the same in both cases.
555 if (ret == 0 && fontid != 12)
557}
558
559////////////////////////////////////////////////////////////////////////////////
560/// Set current text size.
561
563{
564 if (textsize < 0)
565 return kFALSE;
566
567 if (!fFont || !fFont->face) {
568 Error("TTFhandle::SetTextSize", "current font not selected");
569 return kFALSE;
570 }
571
572 Int_t tsize = (Int_t)(textsize*kScale+0.5) << 6;
573 FT_Error err = FT_Set_Char_Size(fFont->face, tsize, tsize, 72, 72);
574
575 if (err)
576 Error("TTFhandle::SetTextSize", "error in FT_Set_Char_Size: 0x%x (input size %f, calc. size 0x%x)", err, textsize, tsize);
577
578 return !err;
579}
580
581////////////////////////////////////////////////////////////////////////////////
582
584{
585 FT_Library_Version(fFT_Library.Get(), &major, &minor, &patch);
586}
587
588
589////////////////////////////////////////////////////////////////////////////////
590
592{
593 return fFT_Library.Get() != nullptr;
594}
595
596
597////////////////////////////////////////////////////////////////////////////////
598
600{
601 return fgHinting;
602}
603
604////////////////////////////////////////////////////////////////////////////////
605
607{
608 return fgSmoothing;
609}
610
611////////////////////////////////////////////////////////////////////////////////
612
614{
615 fgHinting = state;
616}
617
618////////////////////////////////////////////////////////////////////////////////
619
621{
622 fgSmoothing = state;
623}
624
625
626/** \class TTF
627\ingroup BasicGraphics
628
629Interface to the freetype 2 library.
630Implements old static API.
631Unitl ROOT7 just redirects to static TTFhandle instance,
632then TTFhandle will be renamed into TTF class
633*/
634
635thread_local TTF gCleanupTTF; // Allows to call "Cleanup" at the end of the session
636thread_local std::unique_ptr<TTFhandle> fgHandle; // static handle, destroyed automatically
637
638////////////////////////////////////////////////////////////////////////////////
639/// Cleanup TTF environment.
640
642
643////////////////////////////////////////////////////////////////////////////////
644/// Init TTF environment.
645
647{
648 if (!fgHandle) {
649 fgHandle = std::make_unique<TTFhandle>();
650 fgHandle->SetTextFont(62);
651 }
652}
653
654////////////////////////////////////////////////////////////////////////////////
655
660
661////////////////////////////////////////////////////////////////////////////////
662
664{
665 return fgHandle ? fgHandle->GetKerning() : kFALSE;
666}
667
668////////////////////////////////////////////////////////////////////////////////
669
674
675////////////////////////////////////////////////////////////////////////////////
676
678{
679 return fgHandle.get() != nullptr;
680}
681
682////////////////////////////////////////////////////////////////////////////////
683
685{
686 return fgHandle ? fgHandle->GetWidth() : 0;
687}
688
689////////////////////////////////////////////////////////////////////////////////
690
692{
693 return fgHandle ? fgHandle->GetAscent() : 0;
694}
695
696////////////////////////////////////////////////////////////////////////////////
697
699{
700 return fgHandle ? fgHandle->GetNumGlyphs() : 0;
701}
702
703////////////////////////////////////////////////////////////////////////////////
704
706{
707 return fgHandle ? fgHandle->GetRotMatrix() : nullptr;
708}
709
710////////////////////////////////////////////////////////////////////////////////
711
713{
714 return fgHandle ? fgHandle->GetTrailingBlanksWidth() : 0;
715}
716
717////////////////////////////////////////////////////////////////////////////////
718
719const FT_BBox &TTF::GetBox()
720{
721 static FT_BBox dummy;
722 return fgHandle ? fgHandle->GetBox() : dummy;
723}
724
725////////////////////////////////////////////////////////////////////////////////
726
728{
729 return fgHandle ? fgHandle->GetGlyphs() : nullptr;
730}
731
732////////////////////////////////////////////////////////////////////////////////
733/// Map char to unicode. Returns 0 in case no mapping exists.
734
736{
737 Init();
738 return fgHandle->CharToUnicode(code);
739}
740
741////////////////////////////////////////////////////////////////////////////////
742/// Set the rotation matrix used to rotate the font outlines.
743
745{
746 Init();
747 fgHandle->SetRotationMatrix(angle);
748}
749
750////////////////////////////////////////////////////////////////////////////////
751/// Set hinting flag.
752
754{
756}
757
758////////////////////////////////////////////////////////////////////////////////
759/// Set kerning flag.
760
762{
763 Init();
764 fgHandle->SetKerning(state);
765}
766
767////////////////////////////////////////////////////////////////////////////////
768/// Set smoothing (anti-aliasing) flag.
769
771{
773}
774
775////////////////////////////////////////////////////////////////////////////////
776/// Set text font to specified name.
777/// - font : font name
778/// - italic : the fonts should be slanted. Used for symbol font.
779
781{
782 Init();
783 return fgHandle->SetTextFont(fontname, italic);
784}
785
786////////////////////////////////////////////////////////////////////////////////
787/// Set specified font.
788
790{
791 Init();
792 fgHandle->SetTextFont(fontnumber);
793}
794
795////////////////////////////////////////////////////////////////////////////////
796
798{
799 Init();
800 fgHandle->SetTextSize(textsize);
801}
802
803////////////////////////////////////////////////////////////////////////////////
804/// Put the characters in "string" in the "glyphs" array.
805
806void TTF::PrepareString(const char *string)
807{
808 Init();
809 fgHandle->PrepareString(string);
810}
811
812////////////////////////////////////////////////////////////////////////////////
813/// Put the characters in "string" in the "glyphs" array.
814
815void TTF::PrepareString(const wchar_t *string)
816{
817 Init();
818 fgHandle->PrepareString(string);
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
823
825{
826 if (fgHandle)
827 fgHandle->LayoutGlyphs();
828}
829
830////////////////////////////////////////////////////////////////////////////////
831/// Compute the trailing blanks width. It is use to compute the text width in GetTextExtent
832/// `n` is the number of trailing blanks in a string.
833
835{
836 if (fgHandle)
837 fgHandle->ComputeTrailingBlanksWidth(n);
838}
839
840////////////////////////////////////////////////////////////////////////////////
841/// Remove temporary data created by LayoutGlyphs
842
844{
845 if (fgHandle)
846 fgHandle->CleanupGlyphs();
847}
848
849////////////////////////////////////////////////////////////////////////////////
850/// Get width (w) and height (h) when text is horizontal.
851
852void TTF::GetTextExtent(UInt_t &w, UInt_t &h, const char *text)
853{
854 Init();
855 fgHandle->GetTextExtent(w, h, text);
856}
857
858////////////////////////////////////////////////////////////////////////////////
859/// Get advance (a) when text is horizontal.
860
861void TTF::GetTextAdvance(UInt_t &a, const char *text)
862{
863 Init();
864 fgHandle->GetTextAdvance(a, text);
865}
866
867////////////////////////////////////////////////////////////////////////////////
868/// Get width (w) and height (h) when text is horizontal.
869
870void TTF::GetTextExtent(UInt_t &w, UInt_t &h, const wchar_t *text)
871{
872 Init();
873 fgHandle->GetTextExtent(w, h, text);
874}
875
876////////////////////////////////////////////////////////////////////////////////
877
879{
880 Init();
881 fgHandle->Version(major, minor, patch);
882}
#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
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
short Font_t
Font number (short)
Definition RtypesCore.h:96
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const Float_t kScale
Definition TASImage.cxx:135
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition TError.cxx:267
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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 TPoint TPoint const char text
char name[80]
Definition TGX11.cxx:148
@ kReadPermission
Definition TSystem.h:55
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
const Float_t kScale
Definition TTF.cxx:33
thread_local TTF gCleanupTTF
Definition TTF.cxx:635
thread_local std::unique_ptr< TTFhandle > fgHandle
Definition TTF.cxx:636
const_iterator begin() const
const_iterator end() const
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
Definition TROOT.cxx:3507
Basic string class.
Definition TString.h:138
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2459
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1553
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:948
TTF helper class containing glyphs description.
Definition TTF.h:65
FT_Glyph fImage
glyph image
Definition TTF.h:69
~TTGlyph()
Free all resources of this glyph.
Definition TTF.cxx:39
Interface to the freetype 2 library.
Definition TTF.h:55
static void SetKerning(Bool_t state)
Set kerning flag.
Definition TTF.cxx:761
static Bool_t IsInitialized()
Definition TTF.cxx:677
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Definition TTF.cxx:806
static void GetTextExtent(UInt_t &w, UInt_t &h, const char *text)
Get width (w) and height (h) when text is horizontal.
Definition TTF.cxx:852
static Bool_t GetKerning()
Definition TTF.cxx:663
static void Version(Int_t &major, Int_t &minor, Int_t &patch)
Definition TTF.cxx:878
static Int_t GetTrailingBlanksWidth()
Definition TTF.cxx:712
static void SetHinting(Bool_t state)
Set hinting flag.
Definition TTF.cxx:753
static void Init()
Init TTF environment.
Definition TTF.cxx:646
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition TTF.cxx:824
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
Definition TTF.cxx:770
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition TTF.cxx:744
static void CleanupGlyphs()
Remove temporary data created by LayoutGlyphs.
Definition TTF.cxx:843
static void SetTextFont(Font_t fontnumber)
Set specified font.
Definition TTF.cxx:789
static Short_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
Definition TTF.cxx:735
static Int_t GetAscent()
Definition TTF.cxx:691
static TTGlyph * GetGlyphs()
Definition TTF.cxx:727
static Int_t GetNumGlyphs()
Definition TTF.cxx:698
static void ComputeTrailingBlanksWidth(Int_t n)
Compute the trailing blanks width.
Definition TTF.cxx:834
virtual ~TTF()
Cleanup TTF environment.
Definition TTF.cxx:641
static Int_t GetWidth()
Definition TTF.cxx:684
static const FT_BBox & GetBox()
Definition TTF.cxx:719
static void GetTextAdvance(UInt_t &a, const char *text)
Get advance (a) when text is horizontal.
Definition TTF.cxx:861
static Bool_t GetHinting()
Definition TTF.cxx:656
static Bool_t GetSmoothing()
Definition TTF.cxx:670
static void SetTextSize(Float_t textsize)
Definition TTF.cxx:797
static FT_Matrix * GetRotMatrix()
Definition TTF.cxx:705
void GetTextExtent(UInt_t &w, UInt_t &h, const char *text)
Get width (w) and height (h) when text is horizontal.
Definition TTF.cxx:153
virtual ~TTFhandle()
Definition TTF.cxx:94
Int_t SelectFontHandle(Int_t arg, const char *name=nullptr)
Return thread_local instance of TTFontHandle for speified font.
Definition TTF.cxx:380
Bool_t SetTextSize(Float_t textsize)
Set current text size.
Definition TTF.cxx:562
void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Definition TTF.cxx:356
void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
Definition TTF.cxx:294
UInt_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
Definition TTF.cxx:102
FT_BitmapGlyph GetGlyphBitmap(UInt_t n, Bool_t smooth=kFALSE)
Return bitmap for specified glyph.
Definition TTF.cxx:272
static Bool_t Init()
Definition TTF.cxx:591
static void SetHinting(Bool_t state)
Definition TTF.cxx:613
void SetTextFont(Font_t fontnumber)
Set specified font.
Definition TTF.cxx:495
static Bool_t fgHinting
use hinting (false by default)
Definition TTF.h:133
void Version(Int_t &major, Int_t &minor, Int_t &patch)
Definition TTF.cxx:583
FT_Face GetFontFace() const
Return current font index.
Definition TTF.cxx:348
static thread_local FT_Library_Wrapper fFT_Library
Definition TTF.h:143
void CleanupGlyphs()
Remove temporary data created by LayoutGlyphs.
Definition TTF.cxx:286
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
Definition TTF.cxx:199
TTFhandle()
Definition TTF.cxx:86
static Bool_t GetSmoothing()
Definition TTF.cxx:606
void ComputeTrailingBlanksWidth(Int_t n)
Compute the trailing blanks width.
Definition TTF.cxx:132
void GetTextAdvance(UInt_t &a, const char *text)
Get advance (a) when text is horizontal.
Definition TTF.cxx:168
static Bool_t fgSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
Definition TTF.h:134
static Bool_t GetHinting()
Definition TTF.cxx:599
static void SetSmoothing(Bool_t state)
Definition TTF.cxx:620
const Int_t n
Definition legend1.C:16
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:249
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:607
constexpr Double_t Pi()
Definition TMath.h:40
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:601
Thread-local wrapper to the freetype library.
Definition TTF.cxx:58
FT_Library_Wrapper & operator=(FT_Library_Wrapper const &)=delete
FT_Library_Wrapper & operator=(FT_Library_Wrapper &&)=delete
FT_Library_Wrapper(FT_Library_Wrapper &&)=delete
FT_Library_Wrapper(FT_Library_Wrapper const &)=delete
std::string name
Definition TTF.cxx:45
bool is_symbol() const
Definition TTF.cxx:48