#include "TGFont.h"
#include "TGClient.h"
#include "THashTable.h"
#include "TVirtualX.h"
#include "Riostream.h"
#include "TROOT.h"
ClassImp(TGFont)
TGFont::~TGFont()
{
if (fFontStruct)
gVirtualX->DeleteFont(fFontStruct);
}
void TGFont::GetFontMetrics(FontMetrics_t *m) const
{
if (!m) {
Error("GetFontMetrics", "argument may not be 0");
return;
}
*m = fFM;
}
FontStruct_t TGFont::operator()() const
{
return fFontStruct;
}
void TGFont::Print(Option_t *) const
{
Printf("TGFont: %s, %s, ref cnt = %u", fName.Data(),
fFM.fFixed ? "fixed" : "prop", References());
}
ClassImp(TGFontPool)
TGFontPool::TGFontPool(TGClient *client)
{
fClient = client;
fList = new THashTable(50);
fList->SetOwner();
}
TGFontPool::~TGFontPool()
{
delete fList;
}
TGFont *TGFontPool::GetFont(const char *font, Bool_t fixedDefault)
{
if (!font || !*font) {
Error("GetFont", "argument may not be 0 or empty");
return 0;
}
TGFont *f = (TGFont*) fList->FindObject(font);
if (f) {
f->AddReference();
return f;
}
FontStruct_t fs = fClient->GetFontByName(font, fixedDefault);
if (fs) {
f = new TGFont(font);
f->fFontStruct = fs;
f->fFontH = gVirtualX->GetFontHandle(fs);
gVirtualX->GetFontProperties(fs, f->fFM.fAscent, f->fFM.fDescent);
f->fFM.fLinespace = f->fFM.fAscent + f->fFM.fDescent;
f->fFM.fMaxWidth = gVirtualX->TextWidth(fs, "w", 1);
f->fFM.fFixed = (f->fFM.fMaxWidth == gVirtualX->TextWidth(fs, "i", 1)) ? kTRUE : kFALSE;
fList->Add(f);
}
return f;
}
TGFont *TGFontPool::GetFont(const TGFont *font)
{
TGFont *f = (TGFont*) fList->FindObject(font);
if (f) {
f->AddReference();
return f;
}
return 0;
}
TGFont *TGFontPool::GetFont(FontStruct_t fs)
{
TGFont *f = FindFont(fs);
if (f) {
f->AddReference();
return f;
}
static int i = 0;
f = new TGFont(Form("unknown-%d", i));
f->fFontStruct = fs;
f->fFontH = gVirtualX->GetFontHandle(fs);
gVirtualX->GetFontProperties(fs, f->fFM.fAscent, f->fFM.fDescent);
f->fFM.fLinespace = f->fFM.fAscent + f->fFM.fDescent;
f->fFM.fMaxWidth = gVirtualX->TextWidth(fs, "w", 1);
f->fFM.fFixed = (f->fFM.fMaxWidth == gVirtualX->TextWidth(fs, "i", 1)) ? kTRUE : kFALSE;
fList->Add(f);
i++;
return f;
}
void TGFontPool::FreeFont(const TGFont *font)
{
TGFont *f = (TGFont*) fList->FindObject(font);
if (f) {
if (f->RemoveReference() == 0) {
fList->Remove(f);
delete font;
}
}
}
TGFont *TGFontPool::FindFont(FontStruct_t font) const
{
TIter next(fList);
while (TGFont *f = (TGFont*) next())
if (f->fFontStruct == font)
return f;
return 0;
}
TGFont *TGFontPool::FindFontByHandle(FontH_t font) const
{
TIter next(fList);
while (TGFont *f = (TGFont*) next())
if (f->fFontH == font)
return f;
return 0;
}
void TGFontPool::Print(Option_t *) const
{
fList->Print();
}
void TGFont::SavePrimitive(ostream &out, Option_t * )
{
char quote = '"';
if (gROOT->ClassSaved(TGFont::Class())) {
out << endl;
} else {
out << endl;
out << " TGFont *ufont; // will reflect user font changes" << endl;
}
out << " ufont = gClient->GetFont(" << quote << GetName() << quote << ");" << endl;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.