58 return (
name ==
"wingding.ttf") || (
name.find(
"symbol.ttf") == 0);
77 Error(
"TTF.cxx",
"error initializing FreeType");
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) ||
127 if (FT_Set_Charmap(face, charmap))
128 Error(
"TTF::CharToUnicode",
"error in FT_Set_CharMap");
133 return FT_Get_Char_Index(face, (FT_ULong)code);
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);
150 FT_GlyphSlot slot = face->glyph;
151 FT_Pos advance_x = slot->advance.x;
152 Int_t advance_x_pixels = advance_x >> 6;
216 FT_UInt prev_index = 0;
221 load_flags = FT_LOAD_DEFAULT;
223 load_flags |= FT_LOAD_NO_HINTING;
238 FT_Get_Kerning(face, prev_index, glyph.fIndex,
239 GetHinting() ? ft_kerning_default : ft_kerning_unfitted,
243 prev_index = glyph.fIndex;
251 FT_Done_Glyph(glyph.fImage);
252 glyph.fImage =
nullptr;
256 if (FT_Load_Glyph(face, glyph.fIndex, load_flags))
260 if (FT_Get_Glyph(face->glyph, &glyph.fImage))
264 fWidth += face->glyph->advance.x;
268 FT_Matrix
m, *matrix_arg =
nullptr;
277 FT_Vector_Transform(&glyph.fPos, matrix_arg);
278 if (FT_Glyph_Transform(glyph.fImage, matrix_arg, &glyph.fPos))
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;
306 auto &vect = *((std::vector<TTF::TTGlyph> *)
data);
308 for (std::size_t i = 0; i <
fGlyphs.size(); ++i) {
312 tgt.fIndex =
src.fIndex;
314 tgt.fImage =
src.fImage;
326 Int_t txalh = align / 10;
327 Int_t txalv = align % 10;
329 FT_Vector alignVector;
332 case 2: alignVector.x =
GetWidth() / 2;
break;
333 case 3: alignVector.x =
GetWidth();
break;
334 default: alignVector.x = 0;
break;
338 case 2: alignVector.y =
GetAscent() / 2;
break;
339 case 3: alignVector.y =
GetAscent();
break;
340 default: alignVector.y = 0;
break;
343 FT_Matrix
m, *matrix_arg =
nullptr;
352 FT_Vector_Transform(&alignVector, matrix_arg);
360 if (
w <= 0 ||
h <= 0)
363 Int_t x1 = px - Xoff - (alignVector.x >> 6);
364 Int_t y1 = py + Yoff + (alignVector.y >> 6) -
h;
367 if (
x1 + w <= 0 || x1 >= pad_width ||
y1 + h <= 0 || y1 >= pad_height)
371 if ((
w > 10 * pad_width) || (
h > 10 * pad_height))
406 if (FT_Glyph_To_Bitmap(&
fGlyphs[
n].fImage,
GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono,
nullptr, 1))
410 if (!glyph || (glyph->format != FT_GLYPH_FORMAT_BITMAP))
414 FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
416 auto &bmp = bitmap_glyph->bitmap;
421 offy =
yMax - bitmap_glyph->top;
445 const unsigned char *
p = (
const unsigned char*)
string;
474 const wchar_t *
p = string;
510#if defined(FREETYPE_PATCH) && \
511 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
533 thread_local std::map<std::string, FontStruct> _fonts;
540 fFont = &(_fonts.begin()->second);
542 return fFont ? 0 : 1;
546 auto iter = _fonts.find(
name);
547 if (iter != _fonts.end()) {
548 fFont = &iter->second;
553 _fonts[
name] = {
name,
nullptr,
nullptr };
558 for (
auto &font : _fonts) {
559 if (font.second.face) {
560 FT_Done_Face(font.second.face);
561 font.second.face =
nullptr;
587 Fatal(
"SetTextFont",
"Fail to create font handle for font %s", basename);
597 Error(
"SetTextFont",
"no free type library initialized");
610 if (FT_New_Face(lib, ttfont, 0, &
fFont->
face))
615 slantMat.xx = (1 << 16);
616 slantMat.xy = ((1 << 16) >> 2);
618 slantMat.yy = (1 << 16);
619 FT_Set_Transform(
fFont->
face, &slantMat,
nullptr);
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" }
686 static int fontset = -1;
687 int thisset = fontset;
690 if (fontid < 0 || fontid > 31) fontid = 0;
699 thisset = ttfont ? 0 : 1;
701 Int_t italic = fontid == 15 ? 1 : 0;
706 if (ret == 0 && fontid != 12)
719 Error(
"TTFhandle::SetTextSize",
"current font not selected");
724 FT_Error err = FT_Set_Char_Size(
fFont->
face, tsize, tsize, 72, 72);
727 Error(
"TTFhandle::SetTextSize",
"error in FT_Set_Char_Size: 0x%x (input size %f, calc. size 0x%x)", err,
textsize, tsize);
int Int_t
Signed integer 4 bytes (int)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
float Float_t
Float 4 bytes (float)
short Font_t
Font number (short)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
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 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
R__EXTERN TSystem * gSystem
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
void GetTextExtent(UInt_t &w, UInt_t &h, const char *text)
Get width (w) and height (h) when text is horizontal.
void * GetFontFace() const
Return current font index.
Int_t fAscent
string ascent, used to compute Y alignment
Int_t SelectFontHandle(Int_t arg, const char *name=nullptr)
Return thread_local instance of FontStruct for speified font.
FontStruct * fFont
selected font
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 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)
Bool_t GetHinting() const
Returns true if hinting for this instance is enabled If SetHinting() was not called before - use glob...
Int_t GetGlyphsHeight() const
Returns height of all glyphs.
std::vector< GlyphStruct > fGlyphs
glyphs
static Bool_t GetSmoothingPrefer()
Returns true if smoothing of text drawing is enabled by default.
long fRotationXY
rotation matrix members
Tristate fSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
void SetTextFont(Font_t fontnumber)
Set specified font.
Int_t fTBlankW
trailing blanks width
Int_t GetTrailingBlanksWidth() const
void SetKerning(Bool_t state)
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
void CleanupGlyphs()
Remove temporary data created by LayoutGlyphs.
Tristate fHinting
use hinting (false by default)
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
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)
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
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)
static std::atomic< Bool_t > gSmoothingPrefer
static std::atomic< Bool_t > gHintingPrefer
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...
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Thread-local wrapper to the freetype library.
FT_Library_Wrapper & operator=(FT_Library_Wrapper const &)=delete
FT_Library_Wrapper()=default
FT_Library_Wrapper & operator=(FT_Library_Wrapper &&)=delete
FT_Library_Wrapper(FT_Library_Wrapper &&)=delete
FT_Library_Wrapper(FT_Library_Wrapper const &)=delete
UInt_t fIndex
glyph index in face
FT_Glyph fImage
glyph image
FT_Vector fPos
position of glyph origin
GlyphStruct(UInt_t indx=0)