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");
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;
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);
void Error(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
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 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.
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)