18 # include <ft2build.h> 19 # include FT_FREETYPE_H 71 Error(
"TTF::Init",
"error initializing FreeType");
105 if (!
fgFace[fgCurFontIdx])
return 0;
107 for (i = 0; i <
n; i++) {
108 if (!
fgFace[fgCurFontIdx])
continue;
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 &&
115 !strcmp(
fgFontName[fgCurFontIdx],
"wingding.ttf")) ||
116 (platform == 1 && encoding == 0 &&
117 !strcmp(
fgFontName[fgCurFontIdx],
"symbol.ttf")))
121 Error(
"TTF::CharToUnicode",
"error in FT_Set_CharMap");
122 return FT_Get_Char_Index(
fgFace[fgCurFontIdx], (FT_ULong)code);
126 return FT_Get_Char_Index(
fgFace[fgCurFontIdx], (FT_ULong)code);
186 FT_UInt prev_index = 0;
191 load_flags = FT_LOAD_DEFAULT;
192 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
204 fgHinting ? ft_kerning_default : ft_kerning_unfitted,
208 prev_index = glyph->
fIndex;
222 if (FT_Get_Glyph (
fgFace[fgCurFontIdx]->glyph, &glyph->
fImage))
225 glyph->
fPos = origin;
236 FT_Glyph_Get_CBox(glyph->
fImage, ft_glyph_bbox_pixels, &bbox);
249 const unsigned char *p = (
const unsigned char*)
string;
275 FT_UInt load_flags = FT_LOAD_DEFAULT;
276 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
287 const wchar_t *p = string;
313 FT_UInt load_flags = FT_LOAD_DEFAULT;
314 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
342 #if defined(FREETYPE_PATCH) && \ 343 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2) 379 if (!fontname || !fontname[0]) {
381 "no font name specified, using default font %s",
fgFontName[0]);
407 Error(
"TTF::SetTextFont",
"too many fonts opened (increase kTTMaxFont = %d)",
420 Error(
"TTF::SetTextFont",
"font file %s not found in path", fontname);
432 if (FT_New_Face(
fgLibrary, ttfont, 0, &tface)) {
433 Error(
"TTF::SetTextFont",
"error loading font %s", ttfont);
435 if (tface) FT_Done_Face(tface);
456 slantMat.xx = (1 << 16);
457 slantMat.xy = ((1 << 16) >> 2);
459 slantMat.yy = (1 << 16);
493 static const char *fonttable[][2] = {
494 {
"Root.TTFont.0",
"FreeSansBold.otf" },
495 {
"Root.TTFont.1",
"FreeSerifItalic.otf" },
496 {
"Root.TTFont.2",
"FreeSerifBold.otf" },
497 {
"Root.TTFont.3",
"FreeSerifBoldItalic.otf" },
498 {
"Root.TTFont.4",
"FreeSans.otf" },
499 {
"Root.TTFont.5",
"FreeSansOblique.otf" },
500 {
"Root.TTFont.6",
"FreeSansBold.otf" },
501 {
"Root.TTFont.7",
"FreeSansBoldOblique.otf" },
502 {
"Root.TTFont.8",
"FreeMono.otf" },
503 {
"Root.TTFont.9",
"FreeMonoOblique.otf" },
504 {
"Root.TTFont.10",
"FreeMonoBold.otf" },
505 {
"Root.TTFont.11",
"FreeMonoBoldOblique.otf" },
506 {
"Root.TTFont.12",
"symbol.ttf" },
507 {
"Root.TTFont.13",
"FreeSerif.otf" },
508 {
"Root.TTFont.14",
"wingding.ttf" },
509 {
"Root.TTFont.15",
"symbol.ttf" },
510 {
"Root.TTFont.STIXGen",
"STIXGeneral.otf" },
511 {
"Root.TTFont.STIXGenIt",
"STIXGeneralItalic.otf" },
512 {
"Root.TTFont.STIXGenBd",
"STIXGeneralBol.otf" },
513 {
"Root.TTFont.STIXGenBdIt",
"STIXGeneralBolIta.otf" },
514 {
"Root.TTFont.STIXSiz1Sym",
"STIXSiz1Sym.otf" },
515 {
"Root.TTFont.STIXSiz1SymBd",
"STIXSiz1SymBol.otf" },
516 {
"Root.TTFont.STIXSiz2Sym",
"STIXSiz2Sym.otf" },
517 {
"Root.TTFont.STIXSiz2SymBd",
"STIXSiz2SymBol.otf" },
518 {
"Root.TTFont.STIXSiz3Sym",
"STIXSiz3Sym.otf" },
519 {
"Root.TTFont.STIXSiz3SymBd",
"STIXSiz3SymBol.otf" },
520 {
"Root.TTFont.STIXSiz4Sym",
"STIXSiz4Sym.otf" },
521 {
"Root.TTFont.STIXSiz4SymBd",
"STIXSiz4SymBol.otf" },
522 {
"Root.TTFont.STIXSiz5Sym",
"STIXSiz5Sym.otf" },
523 {
"Root.TTFont.ME",
"DroidSansFallback.ttf" },
524 {
"Root.TTFont.CJKMing",
"DroidSansFallback.ttf" },
525 {
"Root.TTFont.CJKGothic",
"DroidSansFallback.ttf" }
528 static int fontset = -1;
529 int thisset = fontset;
531 int fontid = fontnumber / 10;
532 if (fontid < 0 || fontid > 31) fontid = 0;
549 if (fontid==15) italic = 1;
553 if (ret == 0 && fontid != 12) fontset = thisset;
562 if (textsize < 0)
return;
565 Error(
"TTF::SetTextSize",
"current font index out of bounds");
572 Error(
"TTF::SetTextSize",
"error in FT_Set_Char_Size");
579 FT_Library_Version(
fgLibrary, &major, &minor, &patch);
virtual ~TTF()
Cleanup TTF environment.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
static void Init()
Initialise the TrueType fonts interface.
static const TString & GetTTFFontDir()
Get the fonts directory in the installation. Static utility function.
FT_Vector fPos
position of glyph origin
static FT_Matrix * fgRotMatrix
rotation matrix
static Int_t fgFontCount
number of fonts loaded
static Bool_t IsInitialized()
FT_Glyph fImage
glyph image
static void Cleanup()
Cleanup. Is called by the gCleanupTTF destructor.
Interface to the freetype 2 library.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
static void Version(Int_t &major, Int_t &minor, Int_t &patch)
UInt_t fIndex
glyph index in face
static FT_CharMap fgCharMap[kTTMaxFonts]
font character map
static Int_t fgAscent
string ascent, used to compute Y alignment
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
glyphs
static void LayoutGlyphs()
Compute the glyphs positions, fgAscent and fgWidth (needed for alignment).
static Bool_t GetHinting()
static void SetTextFont(Font_t fontnumber)
Set specified font.
static void GetTextExtent(UInt_t &w, UInt_t &h, char *text)
Get width (w) and height (h) when text is horizontal.
static void PrepareString(const char *string)
Put the characters in "string" in the "glyphs" array.
static FT_BBox fgCBox
string control box
static void GetTextAdvance(UInt_t &a, char *text)
Get advance (a) when text is horizontal.
static TTGlyph * GetGlyphs()
void Error(const char *location, const char *msgfmt,...)
static Int_t fgTBlankW
trailing blanks width
static void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
static Int_t fgCurFontIdx
current font index
static FT_Library fgLibrary
FreeType font library.
R__EXTERN TSystem * gSystem
static Bool_t GetKerning()
static Bool_t fgKerning
use kerning (true by default)
static Bool_t fgInit
true if the Init has been called
static FT_Matrix * GetRotMatrix()
TTF helper class containing glyphs description.
static void SetHinting(Bool_t state)
Set hinting flag.
void Warning(const char *location, const char *msgfmt,...)
static void SetKerning(Bool_t state)
Set kerning flag.
static char * fgFontName[kTTMaxFonts]
font name
char * StrDup(const char *str)
Duplicate the string str.
static Bool_t fgHinting
use hinting (true by default)
static Int_t fgSymbItaFontIdx
Symbol italic font index.
static Bool_t fgSmoothing
use anti-aliasing (true when >8 planes, false otherwise)
static void SetRotationMatrix(Float_t angle)
Set the rotation matrix used to rotate the font outlines.
Short_t Max(Short_t a, Short_t b)
static FT_Face fgFace[kTTMaxFonts]
font face
static Int_t fgNumGlyphs
number of glyphs in the string
static void SetTextSize(Float_t textsize)
Set current text size.
static Short_t CharToUnicode(UInt_t code)
Map char to unicode. Returns 0 in case no mapping exists.
static Int_t GetNumGlyphs()
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
static Int_t fgWidth
string width, used to compute X alignment
static const FT_BBox & GetBox()
static Bool_t GetSmoothing()