13 #include "RConfigure.h" 28 # include <FTGL/ftgl.h> 31 # include "FTGLExtrdFont.h" 32 # include "FTGLOutlineFont.h" 33 # include "FTGLPolygonFont.h" 34 # include "FTGLTextureFont.h" 35 # include "FTGLPixmapFont.h" 36 # include "FTGLBitmapFont.h" 53 fFont(0), fManager(0), fDepth(0),
54 fSize(0), fFile(0), fMode(
kUndef),
117 return fFont->Ascender();
125 return -
fFont->Descender();
133 return fFont->LineHeight();
142 const char* txt)
const 145 const_cast<FTFont*
>(
fFont)->
BBox(txt, dum, lly, dum, dum, ury, dum);
148 line_height = ury - lly;
159 const_cast<FTFont*
>(
fFont)->
BBox(txt, llx, lly, llz, urx, ury, urz);
170 const_cast<FTFont*
>(
fFont)->
BBox(txt, llx, lly, llz, urx, ury, urz);
184 Float_t llx = 0.f, lly = 0.f, llz = 0.f, urx = 0.f, ury = 0.f, urz = 0.f;
185 BBox(txt, llx, lly, llz, urx, ury, urz);
196 const Double_t dx = urx - llx, dy = ury - lly;
204 if (
gVirtualX->InheritsFrom(
"TGCocoa")) {
263 glTranslated(x, y, 0.);
264 glRotated(angle, 0., 0., 1.);
265 glTranslated(xc, yc, 0.);
266 glTranslated(-0.5 * dx, -0.5 * dy, 0.);
318 glTranslatef(x, y, z);
321 Float_t llx, lly, llz, urx, ury, urz;
322 BBox(txt, llx, lly, llz, urx, ury, urz);
352 glBitmap(0, 0, 0, 0, x, y, 0);
356 glTranslatef(x, y, 0);
371 glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
372 glEnable(GL_ALPHA_TEST);
373 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
374 glAlphaFunc(GL_GEQUAL, 0.0625);
377 glPushAttrib(GL_POLYGON_BIT | GL_ENABLE_BIT);
378 glEnable(GL_TEXTURE_2D);
379 glDisable(GL_CULL_FACE);
380 glEnable(GL_ALPHA_TEST);
381 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
382 glAlphaFunc(GL_GEQUAL, 0.0625);
387 glPushAttrib(GL_POLYGON_BIT | GL_ENABLE_BIT);
388 glEnable(GL_NORMALIZE);
389 glDisable(GL_CULL_FACE);
392 Warning(
"TGLFont::PreRender",
"Font mode undefined.");
393 glPushAttrib(GL_LIGHTING_BIT);
398 glEnable(GL_LIGHTING);
400 glDisable(GL_LIGHTING);
432 while (it != fFontMap.end()) {
433 delete it->first.GetFont();
444 if (fgStaticInitDone ==
kFALSE) InitStatics();
446 Int_t size = GetFontSize(sizeIn);
451 if (it == fFontMap.end())
455 ttpath =
gEnv->
GetValue(
"Root.TTGLFontPath", TTFFONTDIR );
457 ttpath =
gEnv->
GetValue(
"Root.TTGLFontPath",
"$(ROOTSYS)/fonts");
461 char *fp =
gSystem->
Which(ttpath, fileID < fgExtendedFontStart ?
472 ftfont =
new FTGLBitmapFont(file);
475 ftfont =
new FTGLPixmapFont(file);
478 ftfont =
new FTGLOutlineFont(file);
481 ftfont =
new FTGLPolygonFont(file);
484 ftfont =
new FTGLExtrdFont(file);
485 ftfont->Depth(0.2*size);
488 ftfont =
new FTGLTextureFont(file);
491 Error(
"TGLFontManager::RegisterFont",
"invalid FTGL type");
495 ftfont->FaceSize(size);
496 const TGLFont &mf = fFontMap.insert(std::make_pair(
TGLFont(size, fileID, mode, ftfont, 0), 1)).first->first;
501 if (it->first.GetTrashCount() > 0) {
502 fFontTrash.remove(&(it->first));
503 it->first.SetTrashCount(0);
527 if (cnt < farr->GetEntries())
528 RegisterFont(size, cnt, mode, out);
530 Error(
"TGLFontManager::RegisterFont",
"unknown font name %s", name);
541 if (it != fFontMap.end())
546 assert(it->first.GetTrashCount() == 0);
547 it->first.IncTrashCount();
548 fFontTrash.push_back(&it->first);
558 if (fgStaticInitDone ==
kFALSE) InitStatics();
559 return &fgFontFileArray;
567 if (fgStaticInitDone ==
kFALSE) InitStatics();
568 return &fgFontSizeArray;
575 if (fgStaticInitDone ==
kFALSE) InitStatics();
577 assert(fgExtendedFontStart > 0 &&
"GetExtendedFontStartIndex, invalid index");
579 return fgExtendedFontStart;
587 if (fgStaticInitDone ==
kFALSE) InitStatics();
592 if (idx < 0) idx = 0;
593 return fgFontSizeArray[idx];
601 if (ds < min) ds = min;
602 if (ds > max) ds = max;
603 return GetFontSize(ds);
611 if (fgStaticInitDone ==
kFALSE) InitStatics();
613 Int_t fontIndex =
id / 10;
615 if (fontIndex > fgFontFileArray.GetEntries() || !fontIndex)
629 fgFontFileArray.Add(
new TObjString(
"timesi"));
630 fgFontFileArray.Add(
new TObjString(
"timesbd"));
631 fgFontFileArray.Add(
new TObjString(
"timesbi"));
634 fgFontFileArray.Add(
new TObjString(
"ariali"));
635 fgFontFileArray.Add(
new TObjString(
"arialbd"));
636 fgFontFileArray.Add(
new TObjString(
"arialbi"));
640 fgFontFileArray.Add(
new TObjString(
"courbd"));
641 fgFontFileArray.Add(
new TObjString(
"courbi"));
643 fgFontFileArray.Add(
new TObjString(
"symbol"));
645 fgFontFileArray.Add(
new TObjString(
"wingding"));
646 fgFontFileArray.Add(
new TObjString(
"symbol"));
648 fgExtendedFontStart = fgFontFileArray.GetEntries();
651 fgFontFileArray.Add(
new TObjString(
"FreeSerifItalic.otf"));
652 fgFontFileArray.Add(
new TObjString(
"FreeSerifBold.otf"));
653 fgFontFileArray.Add(
new TObjString(
"FreeSerifBoldItalic.otf"));
655 fgFontFileArray.Add(
new TObjString(
"FreeSans.otf"));
656 fgFontFileArray.Add(
new TObjString(
"FreeSansOblique.otf"));
657 fgFontFileArray.Add(
new TObjString(
"FreeSansBold.otf"));
658 fgFontFileArray.Add(
new TObjString(
"FreeSansBoldOblique.otf"));
660 fgFontFileArray.Add(
new TObjString(
"FreeMono.otf"));
661 fgFontFileArray.Add(
new TObjString(
"FreeMonoOblique.otf"));
662 fgFontFileArray.Add(
new TObjString(
"FreeMonoBold.otf"));
663 fgFontFileArray.Add(
new TObjString(
"FreeMonoBoldOblique.otf"));
665 fgFontFileArray.Add(
new TObjString(
"symbol.ttf"));
666 fgFontFileArray.Add(
new TObjString(
"FreeSerif.otf"));
667 fgFontFileArray.Add(
new TObjString(
"wingding.ttf"));
668 fgFontFileArray.Add(
new TObjString(
"symbol.ttf"));
670 fgFontFileArray.Add(
new TObjString(
"STIXGeneral.otf"));
671 fgFontFileArray.Add(
new TObjString(
"STIXGeneralItalic.otf"));
672 fgFontFileArray.Add(
new TObjString(
"STIXGeneralBol.otf"));
673 fgFontFileArray.Add(
new TObjString(
"STIXGeneralBolIta.otf"));
675 fgFontFileArray.Add(
new TObjString(
"STIXSiz1Sym.otf"));
676 fgFontFileArray.Add(
new TObjString(
"STIXSiz1SymBol.otf"));
677 fgFontFileArray.Add(
new TObjString(
"STIXSiz2Sym.otf"));
678 fgFontFileArray.Add(
new TObjString(
"STIXSiz2SymBol.otf"));
680 fgFontFileArray.Add(
new TObjString(
"STIXSiz3Sym.otf"));
681 fgFontFileArray.Add(
new TObjString(
"STIXSiz3SymBol.otf"));
682 fgFontFileArray.Add(
new TObjString(
"STIXSiz4Sym.otf"));
683 fgFontFileArray.Add(
new TObjString(
"STIXSiz4SymBol.otf"));
685 fgFontFileArray.Add(
new TObjString(
"STIXSiz5Sym.otf"));
686 fgFontFileArray.Add(
new TObjString(
"DroidSansFallback.ttf"));
687 fgFontFileArray.Add(
new TObjString(
"DroidSansFallback.ttf"));
688 fgFontFileArray.Add(
new TObjString(
"DroidSansFallback.ttf"));
690 for (
Int_t i = 10; i <= 20; i+=2)
691 fgFontSizeArray.push_back(i);
692 for (
Int_t i = 24; i <= 64; i+=4)
693 fgFontSizeArray.push_back(i);
694 for (
Int_t i = 72; i <= 128; i+=8)
695 fgFontSizeArray.push_back(i);
697 fgStaticInitDone =
kTRUE;
706 while (it != fFontTrash.end())
708 if ((*it)->IncTrashCount() > 10000)
711 assert(mi != fFontMap.end());
713 delete (*it)->GetFont();
716 fFontTrash.erase(li);
Float_t GetAscent() const
Get font's ascent.
virtual void PreRender(Bool_t autoLight=kTRUE, Bool_t lightOn=kFALSE) const
Set-up GL state before FTFont rendering.
void Render(const char *txt, Double_t x, Double_t y, Double_t angle, Double_t mgn) const
static const char * GetFontNameFromId(Int_t)
Get font name from TAttAxis font id.
Collectable string class.
void BBox(const char *txt, Float_t &llx, Float_t &lly, Float_t &llz, Float_t &urx, Float_t &ury, Float_t &urz) const
Get bounding box.
void ReleaseFont(TGLFont &font)
Release font with given attributes.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
void CopyAttributes(const TGLFont &o)
Assignment operator.
static void InitStatics()
Create a list of available font files and allowed font sizes.
void RegisterFont(Int_t size, Int_t file, TGLFont::EMode mode, TGLFont &out)
Provide font with given size, file and FTGL class.
static TObjArray fgFontFileArray
std::vector< Int_t > FontSizeVec_t
static Int_t GetFontSize(Int_t ds)
Get availabe font size.
std::list< const TGLFont * >::iterator FontList_i
void Error(const char *location, const char *msgfmt,...)
Float_t GetDescent() const
Get font's descent. The returned value is positive.
R__EXTERN TSystem * gSystem
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
static Int_t fgExtendedFontStart
void Warning(const char *location, const char *msgfmt,...)
Float_t GetLineHeight() const
Get font's line-height.
void RenderHelper(const Char *txt, Double_t x, Double_t y, Double_t angle, Double_t) const
mgn is simply ignored, because ROOT's TVirtualX TGX11 are complete mess with painting attributes...
std::map< TGLFont, Int_t >::iterator FontMap_i
void SetManager(TGLFontManager *mng)
const FTFont * GetFont() const
TGLFontManager * fManager
static Bool_t fgStaticInitDone
virtual ~TGLFontManager()
Destructor.
you should not use this method at all Int_t Int_t z
virtual void PostRender() const
Reset GL state after FTFont rendering.
A FreeType GL font manager.
static FontSizeVec_t * GetFontSizeArray()
Get valid font size vector.
static FontSizeVec_t fgFontSizeArray
static TObjArray * GetFontFileArray()
Get id to file name map.
A wrapper class for FTFont.
static Int_t GetExtendedFontStartIndex()
void ClearFontTrash()
Delete FTFFont objects registered for destruction.
virtual ~TGLFont()
Destructor.
void MeasureBaseLineParams(Float_t &ascent, Float_t &descent, Float_t &line_height, const char *txt="Xj") const
Measure font's base-line parameters from the passed text.
Int_t CeilNint(Double_t x)
Long64_t BinarySearch(Long64_t n, const T *array, T value)
const char * Data() const