19 #include "RConfigure.h"
21 # include <ft2build.h>
22 # include FT_FREETYPE_H
73 Error(
"TTF::Init",
"error initializing FreeType");
107 if (!
fgFace[fgCurFontIdx])
return 0;
109 for (i = 0; i <
n; i++) {
110 if (!
fgFace[fgCurFontIdx])
continue;
112 platform = charmap->platform_id;
113 encoding = charmap->encoding_id;
114 if ((platform == 3 && encoding == 1) ||
115 (platform == 0 && encoding == 0) ||
116 (platform == 1 && encoding == 0 &&
117 !strcmp(
fgFontName[fgCurFontIdx],
"wingding.ttf")) ||
118 (platform == 1 && encoding == 0 &&
119 !strcmp(
fgFontName[fgCurFontIdx],
"symbol.ttf")))
123 Error(
"TTF::CharToUnicode",
"error in FT_Set_CharMap");
124 return FT_Get_Char_Index(
fgFace[fgCurFontIdx], (FT_ULong)code);
128 return FT_Get_Char_Index(
fgFace[fgCurFontIdx], (FT_ULong)code);
188 FT_UInt prev_index = 0;
193 load_flags = FT_LOAD_DEFAULT;
194 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
206 fgHinting ? ft_kerning_default : ft_kerning_unfitted,
210 prev_index = glyph->
fIndex;
224 if (FT_Get_Glyph (
fgFace[fgCurFontIdx]->glyph, &glyph->
fImage))
227 glyph->
fPos = origin;
238 FT_Glyph_Get_CBox(glyph->
fImage, ft_glyph_bbox_pixels, &bbox);
251 const unsigned char *p = (
const unsigned char*)
string;
277 FT_UInt load_flags = FT_LOAD_DEFAULT;
278 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
289 const wchar_t *p = string;
315 FT_UInt load_flags = FT_LOAD_DEFAULT;
316 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
344 #if defined(FREETYPE_PATCH) && \
345 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
381 if (!fontname || !fontname[0]) {
383 "no font name specified, using default font %s",
fgFontName[0]);
409 Error(
"TTF::SetTextFont",
"too many fonts opened (increase kTTMaxFont = %d)",
428 Error(
"TTF::SetTextFont",
"font file %s not found in path", fontname);
440 if (FT_New_Face(
fgLibrary, ttfont, 0, &tface)) {
441 Error(
"TTF::SetTextFont",
"error loading font %s", ttfont);
443 if (tface) FT_Done_Face(tface);
464 slantMat.xx = (1 << 16);
465 slantMat.xy = ((1 << 16) >> 2);
467 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",
"FreeSans.otf" },
507 {
"Root.TTFont.5",
"FreeSansOblique.otf" },
508 {
"Root.TTFont.6",
"FreeSansBold.otf" },
509 {
"Root.TTFont.7",
"FreeSansBoldOblique.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;
539 int fontid = fontnumber / 10;
540 if (fontid < 0 || fontid > 31) fontid = 0;
562 if (fontid==15) italic = 1;
566 if (ret == 0 && fontid != 12) fontset = thisset;
575 if (textsize < 0)
return;
578 Error(
"TTF::SetTextSize",
"current font index out of bounds");
585 Error(
"TTF::SetTextSize",
"error in FT_Set_Char_Size");
592 FT_Library_Version(
fgLibrary, &major, &minor, &patch);
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
ClassImp(TTF) TTF
Cleanup TTF environment.
static void Init()
Initialise the TrueType fonts interface.
static FT_Matrix * fgRotMatrix
static Bool_t IsInitialized()
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)
static FT_CharMap fgCharMap[kTTMaxFonts]
static TTF::TTGlyph fgGlyphs[kMaxGlyphs]
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 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 void SetSmoothing(Bool_t state)
Set smoothing (anti-aliasing) flag.
static Int_t fgCurFontIdx
static FT_Library fgLibrary
R__EXTERN TSystem * gSystem
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
static Bool_t GetKerning()
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]
char * StrDup(const char *str)
Duplicate the string str.
static Int_t fgSymbItaFontIdx
static Bool_t fgSmoothing
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]
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()
static const FT_BBox & GetBox()
static Bool_t GetSmoothing()