51 return (
name ==
"wingding.ttf") || (
name.find(
"symbol.ttf") == 0);
70 Error(
"TTF.cxx",
"error initializing FreeType");
110 Int_t n = face->num_charmaps;
111 for (
Int_t i = 0; i <
n; i++) {
112 FT_CharMap charmap = face->charmaps[i];
113 auto platform = charmap->platform_id;
114 auto encoding = charmap->encoding_id;
115 if ((platform == 3 && encoding == 1) ||
116 (platform == 0 && encoding == 0) ||
120 if (FT_Set_Charmap(face, charmap))
121 Error(
"TTF::CharToUnicode",
"error in FT_Set_CharMap");
126 return FT_Get_Char_Index(face, (FT_ULong)code);
139 FT_UInt load_flags = FT_LOAD_DEFAULT;
140 if (!
fHinting) load_flags |= FT_LOAD_NO_HINTING;
141 FT_Load_Char(face, space, load_flags);
143 FT_GlyphSlot slot = face->glyph;
144 FT_Pos advance_x = slot->advance.x;
145 Int_t advance_x_pixels = advance_x >> 6;
200 FT_UInt prev_index = 0;
205 load_flags = FT_LOAD_DEFAULT;
207 load_flags |= FT_LOAD_NO_HINTING;
222 FT_Get_Kerning(face, prev_index, glyph.fIndex,
223 fHinting ? ft_kerning_default : ft_kerning_unfitted,
227 prev_index = glyph.fIndex;
235 FT_Done_Glyph(glyph.fImage);
236 glyph.fImage =
nullptr;
240 if (FT_Load_Glyph(face, glyph.fIndex, load_flags))
244 if (FT_Get_Glyph(face->glyph, &glyph.fImage))
248 fWidth += face->glyph->advance.x;
252 FT_Matrix
m, *matrix_arg =
nullptr;
261 FT_Vector_Transform(&glyph.fPos, matrix_arg);
262 if (FT_Glyph_Transform(glyph.fImage, matrix_arg, &glyph.fPos))
267 FT_Glyph_Get_CBox(glyph.fImage, ft_glyph_bbox_pixels, &bbox);
268 if (bbox.xMin <
xMin)
xMin = bbox.xMin;
269 if (bbox.yMin <
yMin)
yMin = bbox.yMin;
270 if (bbox.xMax >
xMax)
xMax = bbox.xMax;
271 if (bbox.yMax >
yMax)
yMax = bbox.yMax;
290 auto &vect = *((std::vector<TTF::TTGlyph> *)
data);
292 for (std::size_t i = 0; i <
fGlyphs.size(); ++i) {
296 tgt.fIndex =
src.fIndex;
298 tgt.fImage =
src.fImage;
310 Int_t txalh = align / 10;
311 Int_t txalv = align % 10;
313 FT_Vector alignVector;
316 case 2: alignVector.x =
GetWidth() / 2;
break;
317 case 3: alignVector.x =
GetWidth();
break;
318 default: alignVector.x = 0;
break;
322 case 2: alignVector.y =
GetAscent() / 2;
break;
323 case 3: alignVector.y =
GetAscent();
break;
324 default: alignVector.y = 0;
break;
327 FT_Matrix
m, *matrix_arg =
nullptr;
336 FT_Vector_Transform(&alignVector, matrix_arg);
344 if (
w <= 0 ||
h <= 0)
347 Int_t x1 = px - Xoff - (alignVector.x >> 6);
348 Int_t y1 = py + Yoff + (alignVector.y >> 6) -
h;
351 if (
x1 + w <= 0 || x1 >= pad_width ||
y1 + h <= 0 || y1 >= pad_height)
355 if ((
w > 10 * pad_width) || (
h > 10 * pad_height))
390 if (FT_Glyph_To_Bitmap(&
fGlyphs[
n].fImage,
GetSmoothing() ? ft_render_mode_normal : ft_render_mode_mono,
nullptr, 1))
394 if (!glyph || (glyph->format != FT_GLYPH_FORMAT_BITMAP))
398 FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
400 auto &bmp = bitmap_glyph->bitmap;
405 offy =
yMax - bitmap_glyph->top;
429 const unsigned char *
p = (
const unsigned char*)
string;
458 const wchar_t *
p = string;
494#if defined(FREETYPE_PATCH) && \
495 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
517 thread_local std::map<std::string, FontStruct> _fonts;
524 fFont = &(_fonts.begin()->second);
526 return fFont ? 0 : 1;
530 auto iter = _fonts.find(
name);
531 if (iter != _fonts.end()) {
532 fFont = &iter->second;
537 _fonts[
name] = {
name,
nullptr,
nullptr };
542 for (
auto &font : _fonts) {
543 if (font.second.face) {
544 FT_Done_Face(font.second.face);
545 font.second.face =
nullptr;
571 Fatal(
"SetTextFont",
"Fail to create font handle for font %s", basename);
581 Error(
"SetTextFont",
"no free type library initialized");
594 if (FT_New_Face(lib, ttfont, 0, &
fFont->
face))
599 slantMat.xx = (1 << 16);
600 slantMat.xy = ((1 << 16) >> 2);
602 slantMat.yy = (1 << 16);
603 FT_Set_Transform(
fFont->
face, &slantMat,
nullptr);
635 static const char *fonttable[][2] = {
636 {
"Root.TTFont.0",
"FreeSansBold.otf" },
637 {
"Root.TTFont.1",
"FreeSerifItalic.otf" },
638 {
"Root.TTFont.2",
"FreeSerifBold.otf" },
639 {
"Root.TTFont.3",
"FreeSerifBoldItalic.otf" },
640 {
"Root.TTFont.4",
"texgyreheros-regular.otf" },
641 {
"Root.TTFont.5",
"texgyreheros-italic.otf" },
642 {
"Root.TTFont.6",
"texgyreheros-bold.otf" },
643 {
"Root.TTFont.7",
"texgyreheros-bolditalic.otf" },
644 {
"Root.TTFont.8",
"FreeMono.otf" },
645 {
"Root.TTFont.9",
"FreeMonoOblique.otf" },
646 {
"Root.TTFont.10",
"FreeMonoBold.otf" },
647 {
"Root.TTFont.11",
"FreeMonoBoldOblique.otf" },
648 {
"Root.TTFont.12",
"symbol.ttf" },
649 {
"Root.TTFont.13",
"FreeSerif.otf" },
650 {
"Root.TTFont.14",
"wingding.ttf" },
651 {
"Root.TTFont.15",
"symbol.ttf" },
652 {
"Root.TTFont.STIXGen",
"STIXGeneral.otf" },
653 {
"Root.TTFont.STIXGenIt",
"STIXGeneralItalic.otf" },
654 {
"Root.TTFont.STIXGenBd",
"STIXGeneralBol.otf" },
655 {
"Root.TTFont.STIXGenBdIt",
"STIXGeneralBolIta.otf" },
656 {
"Root.TTFont.STIXSiz1Sym",
"STIXSiz1Sym.otf" },
657 {
"Root.TTFont.STIXSiz1SymBd",
"STIXSiz1SymBol.otf" },
658 {
"Root.TTFont.STIXSiz2Sym",
"STIXSiz2Sym.otf" },
659 {
"Root.TTFont.STIXSiz2SymBd",
"STIXSiz2SymBol.otf" },
660 {
"Root.TTFont.STIXSiz3Sym",
"STIXSiz3Sym.otf" },
661 {
"Root.TTFont.STIXSiz3SymBd",
"STIXSiz3SymBol.otf" },
662 {
"Root.TTFont.STIXSiz4Sym",
"STIXSiz4Sym.otf" },
663 {
"Root.TTFont.STIXSiz4SymBd",
"STIXSiz4SymBol.otf" },
664 {
"Root.TTFont.STIXSiz5Sym",
"STIXSiz5Sym.otf" },
665 {
"Root.TTFont.ME",
"DroidSansFallback.ttf" },
666 {
"Root.TTFont.CJKMing",
"DroidSansFallback.ttf" },
667 {
"Root.TTFont.CJKGothic",
"DroidSansFallback.ttf" }
670 static int fontset = -1;
671 int thisset = fontset;
674 if (fontid < 0 || fontid > 31) fontid = 0;
683 thisset = ttfont ? 0 : 1;
685 Int_t italic = fontid == 15 ? 1 : 0;
690 if (ret == 0 && fontid != 12)
703 Error(
"TTFhandle::SetTextSize",
"current font not selected");
708 FT_Error err = FT_Set_Char_Size(
fFont->
face, tsize, tsize, 72, 72);
711 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 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.
Bool_t fKerning
use kerning (true by default)
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.
UInt_t GetNumGlyphs() const
return number of glyphs
Int_t GetGlyphsHeight() const
Returns height of all glyphs.
std::vector< GlyphStruct > fGlyphs
glyphs
long fRotationXY
rotation matrix members
void SetTextFont(Font_t fontnumber)
Set specified font.
Int_t fTBlankW
trailing blanks width
Int_t GetTrailingBlanksWidth() const
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
Bool_t fHinting
use hinting (false by default)
void CleanupGlyphs()
Remove temporary data created by LayoutGlyphs.
void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
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.
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
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)