19# include FT_FREETYPE_H
71 Error(
"TTF::Init",
"error initializing FreeType");
107 for (i = 0; i <
n; i++) {
110 platform = charmap->platform_id;
111 encoding = charmap->encoding_id;
112 if ((platform == 3 && encoding == 1) ||
113 (platform == 0 && encoding == 0) ||
114 (platform == 1 && encoding == 0 &&
116 (platform == 1 && encoding == 0 &&
121 Error(
"TTF::CharToUnicode",
"error in FT_Set_CharMap");
139 FT_UInt load_flags = FT_LOAD_DEFAULT;
140 if (!
fgHinting) 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;
208 FT_UInt prev_index = 0;
213 load_flags = FT_LOAD_DEFAULT;
214 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
226 fgHinting ? ft_kerning_default : ft_kerning_unfitted,
230 prev_index = glyph->
fIndex;
238 FT_Done_Glyph(glyph->
fImage);
250 glyph->
fPos = origin;
261 FT_Glyph_Get_CBox(glyph->
fImage, ft_glyph_bbox_pixels, &bbox);
274 const unsigned char *
p = (
const unsigned char*)
string;
304 const wchar_t *
p = string;
351#if defined(FREETYPE_PATCH) && \
352 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
390 "no font name specified, using default font %s",
fgFontName[0]);
416 Error(
"TTF::SetTextFont",
"too many fonts opened (increase kTTMaxFont = %d)",
429 Error(
"TTF::SetTextFont",
"font file %s not found in path",
fontname);
439 FT_Face tface = (FT_Face) 0;
441 if (FT_New_Face(
fgLibrary, ttfont, 0, &tface)) {
442 Error(
"TTF::SetTextFont",
"error loading font %s", ttfont);
444 if (tface) FT_Done_Face(tface);
465 slantMat.xx = (1 << 16);
466 slantMat.xy = ((1 << 16) >> 2);
468 slantMat.yy = (1 << 16);
501 static const char *fonttable[][2] = {
502 {
"Root.TTFont.0",
"FreeSansBold.otf" },
503 {
"Root.TTFont.1",
"FreeSerifItalic.otf" },
504 {
"Root.TTFont.2",
"FreeSerifBold.otf" },
505 {
"Root.TTFont.3",
"FreeSerifBoldItalic.otf" },
506 {
"Root.TTFont.4",
"texgyreheros-regular.otf" },
507 {
"Root.TTFont.5",
"texgyreheros-italic.otf" },
508 {
"Root.TTFont.6",
"texgyreheros-bold.otf" },
509 {
"Root.TTFont.7",
"texgyreheros-bolditalic.otf" },
510 {
"Root.TTFont.8",
"FreeMono.otf" },
511 {
"Root.TTFont.9",
"FreeMonoOblique.otf" },
512 {
"Root.TTFont.10",
"FreeMonoBold.otf" },
513 {
"Root.TTFont.11",
"FreeMonoBoldOblique.otf" },
514 {
"Root.TTFont.12",
"symbol.ttf" },
515 {
"Root.TTFont.13",
"FreeSerif.otf" },
516 {
"Root.TTFont.14",
"wingding.ttf" },
517 {
"Root.TTFont.15",
"symbol.ttf" },
518 {
"Root.TTFont.STIXGen",
"STIXGeneral.otf" },
519 {
"Root.TTFont.STIXGenIt",
"STIXGeneralItalic.otf" },
520 {
"Root.TTFont.STIXGenBd",
"STIXGeneralBol.otf" },
521 {
"Root.TTFont.STIXGenBdIt",
"STIXGeneralBolIta.otf" },
522 {
"Root.TTFont.STIXSiz1Sym",
"STIXSiz1Sym.otf" },
523 {
"Root.TTFont.STIXSiz1SymBd",
"STIXSiz1SymBol.otf" },
524 {
"Root.TTFont.STIXSiz2Sym",
"STIXSiz2Sym.otf" },
525 {
"Root.TTFont.STIXSiz2SymBd",
"STIXSiz2SymBol.otf" },
526 {
"Root.TTFont.STIXSiz3Sym",
"STIXSiz3Sym.otf" },
527 {
"Root.TTFont.STIXSiz3SymBd",
"STIXSiz3SymBol.otf" },
528 {
"Root.TTFont.STIXSiz4Sym",
"STIXSiz4Sym.otf" },
529 {
"Root.TTFont.STIXSiz4SymBd",
"STIXSiz4SymBol.otf" },
530 {
"Root.TTFont.STIXSiz5Sym",
"STIXSiz5Sym.otf" },
531 {
"Root.TTFont.ME",
"DroidSansFallback.ttf" },
532 {
"Root.TTFont.CJKMing",
"DroidSansFallback.ttf" },
533 {
"Root.TTFont.CJKGothic",
"DroidSansFallback.ttf" }
536 static int fontset = -1;
537 int thisset = fontset;
540 if (fontid < 0 || fontid > 31) fontid = 0;
557 if (fontid==15) italic = 1;
561 if (ret == 0 && fontid != 12) fontset = thisset;
573 Error(
"TTF::SetTextSize",
"current font index out of bounds");
581 Error(
"TTF::SetTextSize",
"error in FT_Set_Char_Size: 0x%x (input size %f, calc. size 0x%x)", err,
textsize,
589 FT_Library_Version(
fgLibrary, &major, &minor, &patch);
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.
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 * StrDup(const char *str)
Duplicate the string str.
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.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
TTF helper class containing glyphs description.
FT_Vector fPos
position of glyph origin
FT_Glyph fImage
glyph image
UInt_t fIndex
glyph index in face
Interface to the freetype 2 library.
static void SetKerning(Bool_t state)
Set kerning flag.
static Bool_t fgHinting
use hinting (true by default)
static Bool_t IsInitialized()
static void GetTextAdvance(UInt_t &a, char *text)
Get advance (a) when text is horizontal.
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
glyphs
static Bool_t GetKerning()
static Bool_t fgSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
static void Version(Int_t &major, Int_t &minor, Int_t &patch)
static Int_t GetTrailingBlanksWidth()
static void SetHinting(Bool_t state)
Set hinting flag.
static void Init()
Initialise the TrueType fonts interface.
static FT_Face fgFace[kTTMaxFonts]
font face
static FT_CharMap fgCharMap[kTTMaxFonts]
font character map
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
static void SetTextFont(Font_t fontnumber)
Set specified font.
static Short_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
static void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Get width (w) and height (h) when text is horizontal.
static TTGlyph * GetGlyphs()
static Int_t GetNumGlyphs()
static Int_t fgAscent
string ascent, used to compute Y alignment
static Int_t fgWidth
string width, used to compute X alignment
static Bool_t fgInit
true if the Init has been called
static Int_t fgCurFontIdx
current font index
static Int_t fgSymbItaFontIdx
Symbol italic font index.
static void Cleanup()
Cleanup. Is called by the gCleanupTTF destructor.
static void ComputeTrailingBlanksWidth(Int_t n)
Compute the trailing blanks width.
virtual ~TTF()
Cleanup TTF environment.
static const FT_BBox & GetBox()
static char * fgFontName[kTTMaxFonts]
font name
static FT_Library fgLibrary
FreeType font library.
static Int_t fgNumGlyphs
number of glyphs in the string
static FT_Matrix * fgRotMatrix
rotation matrix
static Bool_t fgKerning
use kerning (true by default)
static Int_t fgTBlankW
trailing blanks width
static Bool_t GetHinting()
static Bool_t GetSmoothing()
static Int_t fgFontCount
number of fonts loaded
static void SetTextSize(Float_t textsize)
Set current text size.
static FT_Matrix * GetRotMatrix()
static FT_BBox fgCBox
string control box
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.