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;
216 FT_Done_Glyph(glyph->
fImage);
228 glyph->
fPos = origin;
239 FT_Glyph_Get_CBox(glyph->
fImage, ft_glyph_bbox_pixels, &bbox);
252 const unsigned char *p = (
const unsigned char*)
string;
278 FT_UInt load_flags = FT_LOAD_DEFAULT;
279 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
290 const wchar_t *p = string;
316 FT_UInt load_flags = FT_LOAD_DEFAULT;
317 if (!
fgHinting) load_flags |= FT_LOAD_NO_HINTING;
345#if defined(FREETYPE_PATCH) && \
346 (FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH == 2)
382 if (!fontname || !fontname[0]) {
384 "no font name specified, using default font %s",
fgFontName[0]);
410 Error(
"TTF::SetTextFont",
"too many fonts opened (increase kTTMaxFont = %d)",
423 Error(
"TTF::SetTextFont",
"font file %s not found in path", fontname);
435 if (FT_New_Face(
fgLibrary, ttfont, 0, &tface)) {
436 Error(
"TTF::SetTextFont",
"error loading font %s", ttfont);
438 if (tface) FT_Done_Face(tface);
459 slantMat.xx = (1 << 16);
460 slantMat.xy = ((1 << 16) >> 2);
462 slantMat.yy = (1 << 16);
496 static const char *fonttable[][2] = {
497 {
"Root.TTFont.0",
"FreeSansBold.otf" },
498 {
"Root.TTFont.1",
"FreeSerifItalic.otf" },
499 {
"Root.TTFont.2",
"FreeSerifBold.otf" },
500 {
"Root.TTFont.3",
"FreeSerifBoldItalic.otf" },
501 {
"Root.TTFont.4",
"FreeSans.otf" },
502 {
"Root.TTFont.5",
"FreeSansOblique.otf" },
503 {
"Root.TTFont.6",
"FreeSansBold.otf" },
504 {
"Root.TTFont.7",
"FreeSansBoldOblique.otf" },
505 {
"Root.TTFont.8",
"FreeMono.otf" },
506 {
"Root.TTFont.9",
"FreeMonoOblique.otf" },
507 {
"Root.TTFont.10",
"FreeMonoBold.otf" },
508 {
"Root.TTFont.11",
"FreeMonoBoldOblique.otf" },
509 {
"Root.TTFont.12",
"symbol.ttf" },
510 {
"Root.TTFont.13",
"FreeSerif.otf" },
511 {
"Root.TTFont.14",
"wingding.ttf" },
512 {
"Root.TTFont.15",
"symbol.ttf" },
513 {
"Root.TTFont.STIXGen",
"STIXGeneral.otf" },
514 {
"Root.TTFont.STIXGenIt",
"STIXGeneralItalic.otf" },
515 {
"Root.TTFont.STIXGenBd",
"STIXGeneralBol.otf" },
516 {
"Root.TTFont.STIXGenBdIt",
"STIXGeneralBolIta.otf" },
517 {
"Root.TTFont.STIXSiz1Sym",
"STIXSiz1Sym.otf" },
518 {
"Root.TTFont.STIXSiz1SymBd",
"STIXSiz1SymBol.otf" },
519 {
"Root.TTFont.STIXSiz2Sym",
"STIXSiz2Sym.otf" },
520 {
"Root.TTFont.STIXSiz2SymBd",
"STIXSiz2SymBol.otf" },
521 {
"Root.TTFont.STIXSiz3Sym",
"STIXSiz3Sym.otf" },
522 {
"Root.TTFont.STIXSiz3SymBd",
"STIXSiz3SymBol.otf" },
523 {
"Root.TTFont.STIXSiz4Sym",
"STIXSiz4Sym.otf" },
524 {
"Root.TTFont.STIXSiz4SymBd",
"STIXSiz4SymBol.otf" },
525 {
"Root.TTFont.STIXSiz5Sym",
"STIXSiz5Sym.otf" },
526 {
"Root.TTFont.ME",
"DroidSansFallback.ttf" },
527 {
"Root.TTFont.CJKMing",
"DroidSansFallback.ttf" },
528 {
"Root.TTFont.CJKGothic",
"DroidSansFallback.ttf" }
531 static int fontset = -1;
532 int thisset = fontset;
534 int fontid = fontnumber / 10;
535 if (fontid < 0 || fontid > 31) fontid = 0;
552 if (fontid==15) italic = 1;
556 if (ret == 0 && fontid != 12) fontset = thisset;
565 if (textsize < 0)
return;
568 Error(
"TTF::SetTextSize",
"current font index out of bounds");
575 Error(
"TTF::SetTextSize",
"error in FT_Set_Char_Size");
582 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)