Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTFhandle.cxx
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
13/** \class TTFhandle
14\ingroup BasicGraphics
15
16Dynamic handle to work with freetype 2 library.
17in ROOT7 TTFhandle will completely replace TTF class
18*/
19
20
21#include <ft2build.h>
22#include FT_FREETYPE_H
23#include FT_GLYPH_H
24
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// smoothing is enabled by default while all recent devices support enough colors for antialiasing
33
34std::atomic<Bool_t> TTFhandle::gSmoothingPrefer = kTRUE;
35std::atomic<Bool_t> TTFhandle::gHintingPrefer = kFALSE;
36std::atomic<Bool_t> TTFhandle::fKerningPrefer = kTRUE;
37
38
39// to scale fonts to the same size as the old TT version
40const Float_t kScale = 0.93376068;
41
43public:
44 UInt_t fIndex{0}; ///< glyph index in face
45 FT_Vector fPos; ///< position of glyph origin
46 FT_Glyph fImage{nullptr}; ///< glyph image
47 GlyphStruct(UInt_t indx = 0) : fIndex(indx) {}
48 ~GlyphStruct() { FT_Done_Glyph(fImage); }
49};
50
51
53 std::string name;
54 FT_Face face = nullptr;
55 FT_CharMap charmap = nullptr;
56 bool is_symbol() const
57 {
58 return (name == "wingding.ttf") || (name.find("symbol.ttf") == 0);
59 }
60};
61
62////////////////////////////////////////////////////////////////////////////////
63/// Thread-local wrapper to the freetype library.
64/// The library gets initialised on demand when Get() is called.
65/// It auto-destructs when the thread exits.
67 FT_Library _library = nullptr;
68 FT_Library_Wrapper() = default;
73
74 FT_Library Get()
75 {
76 if (!_library && FT_Init_FreeType(&_library) != 0) {
77 Error("TTF.cxx", "error initializing FreeType");
78 _library = nullptr;
79 }
80 return _library;
81 }
82
84 {
85 if (_library)
86 FT_Done_FreeType(_library);
87 }
88};
89
91
92////////////////////////////////////////////////////////////////////////////////
93
95{
96 // Ensure that there's a freetype library in our thread
98}
99
100////////////////////////////////////////////////////////////////////////////////
101
106
107////////////////////////////////////////////////////////////////////////////////
108/// Map char to unicode. Returns 0 in case no mapping exists.
109
111{
112 FT_Face face = fFont ? fFont->face : nullptr;
113 if (!face)
114 return 0;
115
116 if (!fFont->charmap) {
117 Int_t n = face->num_charmaps;
118 for (Int_t i = 0; i < n; i++) {
119 FT_CharMap charmap = face->charmaps[i];
120 auto platform = charmap->platform_id;
121 auto encoding = charmap->encoding_id;
122 if ((platform == 3 && encoding == 1) ||
123 (platform == 0 && encoding == 0) ||
124 (platform == 1 && encoding == 0 && fFont->is_symbol()))
125 {
126 fFont->charmap = charmap;
127 if (FT_Set_Charmap(face, charmap))
128 Error("TTF::CharToUnicode", "error in FT_Set_CharMap");
129 break;
130 }
131 }
132 }
133 return FT_Get_Char_Index(face, (FT_ULong)code);
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Compute the trailing blanks width. It is use to compute the text width in GetTextExtent
138/// `n` is the number of trailing blanks in a string.
139
141{
142 fTBlankW = 0;
143 if (n && fFont) {
144 FT_Face face = fFont->face;
145 char space = ' ';
146 FT_UInt load_flags = FT_LOAD_DEFAULT;
147 if (!GetHinting()) load_flags |= FT_LOAD_NO_HINTING;
148 FT_Load_Char(face, space, load_flags);
149
150 FT_GlyphSlot slot = face->glyph;
151 FT_Pos advance_x = slot->advance.x;
152 Int_t advance_x_pixels = advance_x >> 6;
153
154 fTBlankW = advance_x_pixels * n;
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Get width (w) and height (h) when text is horizontal.
160
170
171////////////////////////////////////////////////////////////////////////////////
172/// Get advance (a) when text is horizontal.
173
175{
178 LayoutGlyphs();
179 a = GetWidth() >> 6;
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Get width (w) and height (h) when text is horizontal.
185
195
196////////////////////////////////////////////////////////////////////////////////
197/// Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
198/// Perform the Glyphs transformation.
199/// Compute the string control box.
200/// If required take the "kerning" into account.
201/// SetRotation and PrepareString should have been called before.
202
204{
205 // fix smoothing, kerning and hinting
206 // do not depend from this point from global values
207 if (fSmoothing.IsUndef())
209 if (fHinting.IsUndef())
211 if (fKerning.IsUndef())
213
214 FT_Vector origin;
215 FT_UInt load_flags;
216 FT_UInt prev_index = 0;
217
218 fAscent = 0;
219 fWidth = 0;
220
221 load_flags = FT_LOAD_DEFAULT;
222 if (!GetHinting())
223 load_flags |= FT_LOAD_NO_HINTING;
224
225 xMin = yMin = 32000;
226 xMax = yMax = -32000;
227
228 FT_Face face = fFont ? fFont->face : nullptr;
229 if (!face)
230 return;
231
232 for (auto &glyph : fGlyphs) {
233
234 // compute glyph origin
235 if (GetKerning()) {
236 if (prev_index) {
237 FT_Vector kern;
238 FT_Get_Kerning(face, prev_index, glyph.fIndex,
239 GetHinting() ? ft_kerning_default : ft_kerning_unfitted,
240 &kern);
241 fWidth += kern.x;
242 }
243 prev_index = glyph.fIndex;
244 }
245
246 origin.x = fWidth;
247 origin.y = 0;
248
249 // clear existing image if there is one
250 if (glyph.fImage) {
251 FT_Done_Glyph(glyph.fImage);
252 glyph.fImage = nullptr;
253 }
254
255 // load the glyph image (in its native format)
256 if (FT_Load_Glyph(face, glyph.fIndex, load_flags))
257 continue;
258
259 // extract the glyph image
260 if (FT_Get_Glyph(face->glyph, &glyph.fImage))
261 continue;
262
263 glyph.fPos = origin;
264 fWidth += face->glyph->advance.x;
265 fAscent = TMath::Max((Int_t)(face->glyph->metrics.horiBearingY), fAscent);
266
267 // transform the glyphs
268 FT_Matrix m, *matrix_arg = nullptr;
269
270 if (fRotationXX || fRotationXY) {
271 m.xx = m.yy = fRotationXX;
272 m.xy = fRotationXY;
273 m.yx = -fRotationXY;
274 matrix_arg = &m;
275 }
276
277 FT_Vector_Transform(&glyph.fPos, matrix_arg);
278 if (FT_Glyph_Transform(glyph.fImage, matrix_arg, &glyph.fPos))
279 continue;
280
281 // compute the string control box
282 FT_BBox bbox;
283 FT_Glyph_Get_CBox(glyph.fImage, ft_glyph_bbox_pixels, &bbox);
284 if (bbox.xMin < xMin) xMin = bbox.xMin;
285 if (bbox.yMin < yMin) yMin = bbox.yMin;
286 if (bbox.xMax > xMax) xMax = bbox.xMax;
287 if (bbox.yMax > yMax) yMax = bbox.yMax;
288 }
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// return number of glyphs
293
295{
296 return fGlyphs.size();
297}
298
299
300////////////////////////////////////////////////////////////////////////////////
301/// Fill vector from TTF class
302/// Only for backward compatibility of old API
303
305{
306 auto &vect = *((std::vector<TTF::TTGlyph> *) data);
307 vect.resize(fGlyphs.size());
308 for (std::size_t i = 0; i < fGlyphs.size(); ++i) {
309 auto &tgt = vect[i];
310 auto &src = fGlyphs[i];
311
312 tgt.fIndex = src.fIndex;
313 tgt.fPos = src.fPos;
314 tgt.fImage = src.fImage;
315 }
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Apply align and configured rotation matrix to text position
320/// px and py will be shifted to the place where glyph drawing can be started
321/// Method returns false when glyphs not need to be drawn
322/// while position is outside of specified pad dimentsions
323
324Bool_t TTFhandle::ApplyAlignRotate(Int_t &px, Int_t &py, Int_t align, Int_t pad_width, Int_t pad_height)
325{
326 Int_t txalh = align / 10;
327 Int_t txalv = align % 10;
328
329 FT_Vector alignVector;
330
331 switch (txalh) {
332 case 2: alignVector.x = GetWidth() / 2; break; //center
333 case 3: alignVector.x = GetWidth(); break; //right
334 default: alignVector.x = 0; break; // left
335 }
336
337 switch (txalv) {
338 case 2: alignVector.y = GetAscent() / 2; break; // middle
339 case 3: alignVector.y = GetAscent(); break; //top
340 default: alignVector.y = 0; break; //bottom
341 }
342
343 FT_Matrix m, *matrix_arg = nullptr;
344
345 if (fRotationXX || fRotationXY) {
346 m.xx = m.yy = fRotationXX;
347 m.xy = fRotationXY;
348 m.yx = -fRotationXY;
349 matrix_arg = &m;
350 }
351
352 FT_Vector_Transform(&alignVector, matrix_arg);
353
354 Int_t Xoff = TMath::Max(0, (Int_t) -xMin);
355 Int_t Yoff = TMath::Max(0, (Int_t) -yMin);
358
359 // If w or h is 0, very likely the string is only blank characters
360 if (w <= 0 || h <= 0)
361 return kFALSE;
362
363 Int_t x1 = px - Xoff - (alignVector.x >> 6);
364 Int_t y1 = py + Yoff + (alignVector.y >> 6) - h;
365
366 // If string falls outside window, there is probably no need to draw it.
367 if (x1 + w <= 0 || x1 >= pad_width || y1 + h <= 0 || y1 >= pad_height)
368 return kFALSE;
369
370 // do not draw text, which size is significantly larger than available pad
371 if ((w > 10 * pad_width) || (h > 10 * pad_height))
372 return kFALSE;
373
374 px = x1;
375 py = y1;
376 return kTRUE;
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Returns width of all glyphs
381
383{
384 return xMax + TMath::Max(0, (Int_t) -xMin);
385}
386
387////////////////////////////////////////////////////////////////////////////////
388/// Returns height of all glyphs
389
391{
392 return yMax + TMath::Max(0, (Int_t) -yMin);
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Returns data for glyph bitmap
397/// Instead direct access to FT_BitmapGlyph one can obtain all relevant fields
398/// Thus one do not requires work with TrueType classes directly
399/// Return kFALSE when glyph not exists or if it width is zero
400
402{
403 if (n >= fGlyphs.size())
404 return kFALSE;
405
406 if (FT_Glyph_To_Bitmap(&fGlyphs[n].fImage, GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono, nullptr, 1))
407 return kFALSE;
408
409 auto glyph = fGlyphs[n].fImage;
410 if (!glyph || (glyph->format != FT_GLYPH_FORMAT_BITMAP))
411 return kFALSE;
412
413 // 2. Safe to typecast to FT_BitmapGlyph
414 FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
415
416 auto &bmp = bitmap_glyph->bitmap;
417 if (!bmp.width)
418 return kFALSE;
419
420 offx = TMath::Max(0, (Int_t) -xMin) + bitmap_glyph->left;
421 offy = yMax - bitmap_glyph->top;
422
423 buffer = bmp.buffer;
424 width = bmp.width;
425 rows = bmp.rows;
426 pitch = bmp.pitch;
427 return kTRUE;
428}
429
430////////////////////////////////////////////////////////////////////////////////
431/// Remove temporary data created by LayoutGlyphs
432
434{
435 fGlyphs.clear();
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// Put the characters in "string" in the "glyphs" array.
440
441void TTFhandle::PrepareString(const char *string)
442{
444
445 const unsigned char *p = (const unsigned char*) string;
446
447 Int_t NbTBlank = 0; // number of trailing blanks
448
449 while (*p) {
450 UInt_t index = CharToUnicode((FT_ULong)*p);
451 if (index != 0)
452 fGlyphs.emplace_back(index);
453 if (*p == ' ')
454 NbTBlank++;
455 else
456 NbTBlank = 0;
457 p++;
458 }
459
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// Put the characters in "string" in the "glyphs" array.
465
466void TTFhandle::PrepareString(const wchar_t *string)
467{
469
470 FT_Face face = fFont ? fFont->face : nullptr;
471 if (!face)
472 return;
473
474 const wchar_t *p = string;
475
476 Int_t NbTBlank = 0; // number of trailing blanks
477
478 while (*p) {
479 UInt_t index = FT_Get_Char_Index(face, (FT_ULong) *p);
480 if (index != 0)
481 fGlyphs.emplace_back(index);
482 if (*p == ' ')
483 NbTBlank++;
484 else
485 NbTBlank = 0;
486 p++;
487 }
488
490}
491
492////////////////////////////////////////////////////////////////////////////////
493/// Return current font index
494
496{
497 return fFont ? (void *) fFont->face : nullptr;
498}
499
500////////////////////////////////////////////////////////////////////////////////
501/// Set the rotation matrix used to rotate the font outlines.
502
504{
506 if (!angle)
507 return;
508
509 Float_t rangle = angle * TMath::Pi() / 180.; // Angle in radian
510#if defined(FREETYPE_PATCH) && \
511 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
512 Float_t sin = TMath::Sin(rangle);
513 Float_t cos = TMath::Cos(rangle);
514#else
515 Float_t sin = TMath::Sin(-rangle);
516 Float_t cos = TMath::Cos(-rangle);
517#endif
518
519 fRotationXX = (FT_Fixed) (cos * (1<<16));
520 fRotationXY = (FT_Fixed) (sin * (1<<16));
521
522// fRotMatrix->xx = (FT_Fixed) (cos * (1<<16));
523// fRotMatrix->xy = (FT_Fixed) (sin * (1<<16));
524// fRotMatrix->yx = -fRotMatrix->xy;
525// fRotMatrix->yy = fRotMatrix->xx;
526}
527
528////////////////////////////////////////////////////////////////////////////////
529/// Return thread_local instance of FontStruct for speified font
530
532{
533 thread_local std::map<std::string, FontStruct> _fonts;
534
535 fFont = nullptr;
536
537 if (arg == 111) {
538 // select any existing font, fallback solution for some errors in SetTextFont
539 if (!_fonts.empty())
540 fFont = &(_fonts.begin()->second);
541 Warning("TTFhandle::SetTextFont", "%s, using %s", name, fFont ? fFont->name.c_str() : "<nothing>");
542 return fFont ? 0 : 1;
543 }
544
545 if (arg >= 0) {
546 auto iter = _fonts.find(name);
547 if (iter != _fonts.end()) {
548 fFont = &iter->second;
549 return 0;
550 }
551 if (arg == 0)
552 return 1;
553 _fonts[name] = { name, nullptr, nullptr };
554 fFont = &_fonts[name];
555 return 0;
556 }
557
558 for (auto &font : _fonts) {
559 if (font.second.face) {
560 FT_Done_Face(font.second.face);
561 font.second.face = nullptr;
562 }
563 }
564 _fonts.clear();
565 return 0;
566}
567
568
569////////////////////////////////////////////////////////////////////////////////
570/// Set text font to specified name.
571/// - font : font name
572/// - italic : the fonts should be slanted. Used for symbol font.
573///
574/// Set text font to specified name. This function returns 0 if
575/// the specified font is found, 1 if not.
576
578{
579 fFont = nullptr;
580
581 if (!fontname || !*fontname)
582 return SelectFontHandle(111, "no font name specified");
583
584 const char *basename = gSystem->BaseName(fontname);
585
586 if (SelectFontHandle(1, TString::Format("%s%s", basename, italic ? ".italic" : ""))) {
587 Fatal("SetTextFont", "Fail to create font handle for font %s", basename);
588 return 1;
589 }
590
591 // font face exists and initialized
592 if (fFont->face)
593 return 0;
594
595 auto lib = fFT_Library.Get();
596 if (!lib) {
597 Error("SetTextFont", "no free type library initialized");
598 return 1;
599 }
600
601 // try to load font (font must be in Root.TTFontPath resource)
602 const char *ttpath = gEnv->GetValue("Root.TTFontPath", TROOT::GetTTFFontDir());
603
604 TString fname = fontname;
605 const char *ttfont = gSystem->FindFile(ttpath, fname, kReadPermission);
606
607 if (!ttfont)
608 return SelectFontHandle(111, TString::Format("font file %s not found in path %s", fontname, ttpath));
609
610 if (FT_New_Face(lib, ttfont, 0, &fFont->face))
611 return SelectFontHandle(111, TString::Format("error loading font %s", ttfont));
612
613 if (italic) {
614 FT_Matrix slantMat;
615 slantMat.xx = (1 << 16);
616 slantMat.xy = ((1 << 16) >> 2);
617 slantMat.yx = 0;
618 slantMat.yy = (1 << 16);
619 FT_Set_Transform(fFont->face, &slantMat, nullptr);
620 }
621
622 return 0;
623}
624
625////////////////////////////////////////////////////////////////////////////////
626/// Set specified font.
627/// List of the currently supported fonts (screen and PostScript)
628///
629/// | Font number | TTF Names | PostScript/PDF Names |
630/// |-------------|---------------------------|-------------------------------|
631/// | 1 | Free Serif Italic | Times-Italic |
632/// | 2 | Free Serif Bold | Times-Bold |
633/// | 3 | Free Serif Bold Italic | Times-BoldItalic |
634/// | 4 | Tex Gyre Regular | Helvetica |
635/// | 5 | Tex Gyre Italic | Helvetica-Oblique |
636/// | 6 | Tex Gyre Bold | Helvetica-Bold |
637/// | 7 | Tex Gyre Bold Italic | Helvetica-BoldOblique |
638/// | 8 | Free Mono | Courier |
639/// | 9 | Free Mono Oblique | Courier-Oblique |
640/// | 10 | Free Mono Bold | Courier-Bold |
641/// | 11 | Free Mono Bold Oblique | Courier-BoldOblique |
642/// | 12 | Symbol | Symbol |
643/// | 13 | Free Serif | Times-Roman |
644/// | 14 | Wingdings | ZapfDingbats |
645
647{
648 // Added by cholm for use of DFSG - fonts - based on Kevins fix.
649 // Table of Microsoft and (for non-MSFT operating systems) backup
650 // FreeFont TTF fonts.
651 static const char *fonttable[][2] = {
652 { "Root.TTFont.0", "FreeSansBold.otf" },
653 { "Root.TTFont.1", "FreeSerifItalic.otf" },
654 { "Root.TTFont.2", "FreeSerifBold.otf" },
655 { "Root.TTFont.3", "FreeSerifBoldItalic.otf" },
656 { "Root.TTFont.4", "texgyreheros-regular.otf" },
657 { "Root.TTFont.5", "texgyreheros-italic.otf" },
658 { "Root.TTFont.6", "texgyreheros-bold.otf" },
659 { "Root.TTFont.7", "texgyreheros-bolditalic.otf" },
660 { "Root.TTFont.8", "FreeMono.otf" },
661 { "Root.TTFont.9", "FreeMonoOblique.otf" },
662 { "Root.TTFont.10", "FreeMonoBold.otf" },
663 { "Root.TTFont.11", "FreeMonoBoldOblique.otf" },
664 { "Root.TTFont.12", "symbol.ttf" },
665 { "Root.TTFont.13", "FreeSerif.otf" },
666 { "Root.TTFont.14", "wingding.ttf" },
667 { "Root.TTFont.15", "symbol.ttf" },
668 { "Root.TTFont.STIXGen", "STIXGeneral.otf" },
669 { "Root.TTFont.STIXGenIt", "STIXGeneralItalic.otf" },
670 { "Root.TTFont.STIXGenBd", "STIXGeneralBol.otf" },
671 { "Root.TTFont.STIXGenBdIt", "STIXGeneralBolIta.otf" },
672 { "Root.TTFont.STIXSiz1Sym", "STIXSiz1Sym.otf" },
673 { "Root.TTFont.STIXSiz1SymBd", "STIXSiz1SymBol.otf" },
674 { "Root.TTFont.STIXSiz2Sym", "STIXSiz2Sym.otf" },
675 { "Root.TTFont.STIXSiz2SymBd", "STIXSiz2SymBol.otf" },
676 { "Root.TTFont.STIXSiz3Sym", "STIXSiz3Sym.otf" },
677 { "Root.TTFont.STIXSiz3SymBd", "STIXSiz3SymBol.otf" },
678 { "Root.TTFont.STIXSiz4Sym", "STIXSiz4Sym.otf" },
679 { "Root.TTFont.STIXSiz4SymBd", "STIXSiz4SymBol.otf" },
680 { "Root.TTFont.STIXSiz5Sym", "STIXSiz5Sym.otf" },
681 { "Root.TTFont.ME", "DroidSansFallback.ttf" },
682 { "Root.TTFont.CJKMing", "DroidSansFallback.ttf" },
683 { "Root.TTFont.CJKGothic", "DroidSansFallback.ttf" }
684 };
685
686 static int fontset = -1;
687 int thisset = fontset;
688
689 int fontid = fontnumber / 10;
690 if (fontid < 0 || fontid > 31) fontid = 0;
691
692 if (thisset == -1) {
693 // try to load font (font must be in Root.TTFontPath resource)
694 // to see which fontset we have available
695 const char *ttpath = gEnv->GetValue("Root.TTFontPath",
697 TString fname = gEnv->GetValue(fonttable[fontid][0], fonttable[fontid][1]);
698 const char *ttfont = gSystem->FindFile(ttpath, fname, kReadPermission);
699 thisset = ttfont ? 0 : 1;
700 }
701 Int_t italic = fontid == 15 ? 1 : 0;
702 auto ret = SetTextFont(gEnv->GetValue(fonttable[fontid][thisset], fonttable[fontid][1]), italic);
703
704 // Do not define font set is we're loading the symbol.ttf - it's
705 // the same in both cases.
706 if (ret == 0 && fontid != 12)
707 fontset = thisset;
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Set current text size.
712
714{
715 if (textsize < 0)
716 return kFALSE;
717
718 if (!fFont || !fFont->face) {
719 Error("TTFhandle::SetTextSize", "current font not selected");
720 return kFALSE;
721 }
722
723 Int_t tsize = (Int_t)(textsize*kScale+0.5) << 6;
724 FT_Error err = FT_Set_Char_Size(fFont->face, tsize, tsize, 72, 72);
725
726 if (err)
727 Error("TTFhandle::SetTextSize", "error in FT_Set_Char_Size: 0x%x (input size %f, calc. size 0x%x)", err, textsize, tsize);
728
729 return !err;
730}
731
732////////////////////////////////////////////////////////////////////////////////
733
734void TTFhandle::Version(Int_t &major, Int_t &minor, Int_t &patch)
735{
736 FT_Library_Version(fFT_Library.Get(), &major, &minor, &patch);
737}
738
739
740////////////////////////////////////////////////////////////////////////////////
741
743{
744 return fFT_Library.Get() != nullptr;
745}
746
747////////////////////////////////////////////////////////////////////////////////
748/// Set global flag to switch on/off kerning of TTF text drawing
749/// This flag is used when SetKerning() flag not set before
750
755
756////////////////////////////////////////////////////////////////////////////////
757/// Returns true if kerning of text drawing is enabled by default
758
763
764////////////////////////////////////////////////////////////////////////////////
765/// Set global flag to switch on/off smoothing of TTF text drawing
766/// This flag is used when SetSmoothing() flag not set before
767
772
773////////////////////////////////////////////////////////////////////////////////
774/// Returns true if smoothing of text drawing is enabled by default
775
780
781////////////////////////////////////////////////////////////////////////////////
782/// Set global flag to switch on/off hinting of TTF text drawing
783/// This flag is used when SetHiniting() flag not set before
784
789
790////////////////////////////////////////////////////////////////////////////////
791/// Returns true if hinting of text drawing is enabled by default
792
797
798////////////////////////////////////////////////////////////////////////////////
799/// Returns true if smoothing for this instance is enabled
800/// If SetSmoothing() was not called before - use global value
801/// configured with @ref SetSmoothingPrefer method
802
804{
805 if (fSmoothing.IsUndef())
806 return GetSmoothingPrefer();
807 return fSmoothing.IsOn();
808}
809
810////////////////////////////////////////////////////////////////////////////////
811/// Returns true if hinting for this instance is enabled
812/// If SetHinting() was not called before - use global value
813/// configured with @ref SetHinitingPrefer method
814
816{
817 if (fHinting.IsUndef())
818 return GetHintingPrefer();
819 return fHinting.IsOn();
820}
821
822////////////////////////////////////////////////////////////////////////////////
823/// Returns true if kerning for this instance is enabled
824/// If SetKerning() was not called before - use global value
825/// configured with @ref SetKerningPrefer method
826
828{
829 if (fKerning.IsUndef())
830 return GetKerningPrefer();
831 return fKerning.IsOn();
832}
833
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
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
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
const Float_t kScale
Definition TASImage.cxx:126
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 data
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 TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char x1
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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:142
@ kReadPermission
Definition TSystem.h:55
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
const Float_t kScale
Definition TTFhandle.cxx:40
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:3523
Basic string class.
Definition TString.h:137
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:2460
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1561
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:950
Bool_t IsOn() const
Definition TTFhandle.h:34
Bool_t IsUndef() const
Definition TTFhandle.h:33
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
Bool_t SetTextSize(Float_t textsize)
Set current text size.
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
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
void SetTextFont(Font_t fontnumber)
Set specified font.
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
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
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 TTFhandle.cxx:66
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
bool is_symbol() const
Definition TTFhandle.cxx:56
UInt_t fIndex
glyph index in face
Definition TTFhandle.cxx:44
FT_Glyph fImage
glyph image
Definition TTFhandle.cxx:46
FT_Vector fPos
position of glyph origin
Definition TTFhandle.cxx:45
GlyphStruct(UInt_t indx=0)
Definition TTFhandle.cxx:47
TMarker m
Definition textangle.C:8