44 CFSTR(
"TimesNewRomanPS-ItalicMT"),
45 CFSTR(
"TimesNewRomanPS-BoldMT"),
46 CFSTR(
"TimesNewRomanPS-BoldItalicMT"),
48 CFSTR(
"Helvetica-Oblique"),
49 CFSTR(
"Helvetica-Bold"),
50 CFSTR(
"Helvetica-BoldOblique"),
52 CFSTR(
"Courier-Oblique"),
53 CFSTR(
"Courier-Bold"),
54 CFSTR(
"Courier-BoldOblique"),
56 CFSTR(
"TimesNewRomanPSMT"),
58 CFSTR(
"Symbol-Italic")
62CTFontCollectionRef CreateFontCollection(
const X11::XLFDName &)
64 CTFontCollectionRef ctCollection = CTFontCollectionCreateFromAvailableFonts(0);
66 ::Error(
"CreateFontCollection",
"CTFontCollectionCreateFromAvailableFonts failed");
106bool GetFamilyName(CTFontDescriptorRef fontDescriptor, std::vector<char> &
name)
109 assert(fontDescriptor != 0 &&
"GetFamilyName, parameter 'fontDescriptor' is null");
114 if (
const CFIndex cfLen = CFStringGetLength(cfFamilyName.Get())) {
115 name.resize(cfLen + 1);
116 if (CFStringGetCString(cfFamilyName.Get(), &
name[0],
name.size(), kCFStringEncodingMacRoman))
124void GetWeightAndSlant(CTFontDescriptorRef fontDescriptor,
X11::XLFDName &newXLFD)
129 if (CFNumberRef symbolTraits = (CFNumberRef)CFDictionaryGetValue(traits.Get(), kCTFontSymbolicTrait)) {
131 CFNumberGetValue(symbolTraits, kCFNumberIntType, &val);
132 if (val & kCTFontItalicTrait)
137 if (val & kCTFontBoldTrait)
162void GetPixelSize(CTFontDescriptorRef fontDescriptor,
X11::XLFDName &newXLFD)
167 if(CFNumberIsFloatType(
size.Get())) {
169 CFNumberGetValue(
size.Get(), kCFNumberDoubleType, &val);
172 CFNumberGetValue(
size.Get(), kCFNumberIntType, &pixelSize);
180void CreateXLFDString(
const X11::XLFDName &xlfd, std::string &xlfdString)
182 xlfdString =
"-CoreText-";
186 xlfdString +=
"-bold";
188 xlfdString +=
"-normal";
195 xlfdString +=
"-*-*";
198 std::ostringstream
out;
201 xlfdString +=
out.str();
205 xlfdString +=
"-*-*-*-*-*-*-*-";
212 : fSymbolFontRegistered(false)
226#ifdef MAC_OS_X_VERSION_10_9
229 const CFScopeGuard<CFStringRef> fontName(CFStringCreateWithCString(kCFAllocatorDefault, psName.c_str(), kCFStringEncodingMacRoman));
231 const CFScopeGuard<CFStringRef> fontName(CFStringCreateWithCString(kCFAllocatorDefault, xlfd.
fFamilyName.c_str(), kCFStringEncodingMacRoman));
234 const CFStrongReference<CTFontRef> baseFont(CTFontCreateWithName(fontName.Get(), xlfd.
fPixelSize, 0),
false);
236 if (!baseFont.Get()) {
237 ::Error(
"FontCache::LoadFont",
"CTFontCreateWithName failed for %s", xlfd.
fFamilyName.c_str());
241 CTFontSymbolicTraits symbolicTraits = CTFontSymbolicTraits();
244 symbolicTraits |= kCTFontBoldTrait;
246 symbolicTraits |= kCTFontItalicTrait;
248 if (symbolicTraits) {
249 const CFStrongReference<CTFontRef> font(CTFontCreateCopyWithSymbolicTraits(baseFont.Get(), xlfd.
fPixelSize, 0, symbolicTraits, symbolicTraits),
false);
267 CTFontRef fontRef = (CTFontRef)font;
270 assert(fontIter !=
fLoadedFonts.end() &&
"Attempt to unload font, not created by font manager");
278 typedef std::vector<char>::size_type size_type;
290 if (!collectionGuard.
Get())
295 ::Error(
"FontCache::ListFonts",
"CTFontCollectionCreateMatchingFontDescriptors failed %s", xlfd.
fFamilyName.c_str());
299 std::vector<char> xlfdData;
301 std::vector<char> familyName;
303 std::string xlfdString;
305 const CFIndex nFonts = CFArrayGetCount(
fonts.Get());
306 for (CFIndex i = 0; i < nFonts && count < maxNames; ++i) {
307 CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(
fonts.Get(), i);
309 if (!GetFamilyName(font, familyName))
320 if (newXLFD.
fFamilyName.find(
'-') != std::string::npos)
323 GetWeightAndSlant(font, newXLFD);
332 GetPixelSize(font, newXLFD);
339 CreateXLFDString(newXLFD, xlfdString);
341 xlfdData.insert(xlfdData.end(), xlfdString.begin(), xlfdString.end());
342 xlfdData.push_back(0);
347 if (xlfdData.size()) {
352 std::vector<char *> &list =
fFontLists.back().fList;
354 list.push_back(&
data[0]);
355 for (size_type i = 1,
e =
data.size(); i <
e; ++i) {
356 if (!
data[i] && i + 1 <
e)
357 list.push_back(&
data[i + 1]);
371 for (std::list<FontList>::iterator it =
fFontLists.begin(), eIt =
fFontLists.end(); it != eIt; ++it) {
372 if (fontList == &it->fList[0]) {
378 assert(0 &&
"FreeFontNames, unknown fontList");
387 typedef std::vector<CGSize>::size_type size_type;
389 CTFontRef fontRef = (CTFontRef)font;
394 nChars = std::strlen(
text);
396 std::vector<UniChar> unichars(
text,
text + nChars);
399 std::vector<CGGlyph> glyphs(unichars.size());
400 CTFontGetGlyphsForCharacters(fontRef, &unichars[0], &glyphs[0], unichars.size());
403 std::vector<CGSize> glyphAdvances(glyphs.size());
406 CGFloat textWidth = 0.;
407 for (size_type i = 0,
e = glyphAdvances.size(); i <
e; ++i)
408 textWidth += std::ceil(glyphAdvances[i].
width);
417 CTFontRef fontRef = (CTFontRef)font;
422 maxAscent =
int(CTFontGetAscent(fontRef) + 0.5) + 2;
423 maxDescent =
int(CTFontGetDescent(fontRef) + 0.5);
424 }
catch (
const std::exception &) {
435 if (fontIndex >
nPadFonts || !fontIndex) {
436 ::Warning(
"FontCache::SelectFont",
"Font with index %d was requested", fontIndex);
441 if (fontIndex == 11 || fontIndex == 14)
447 if (it ==
fFonts[fontIndex].end()) {
450 const CTFontGuard_t font(CTFontCreateWithName(fixedFontNames[fontIndex], fixedSize, 0),
false);
452 ::Error(
"FontCache::SelectFont",
"CTFontCreateWithName failed for font %d", fontIndex);
456 fFonts[fontIndex][fixedSize] = font;
458 }
catch (
const std::exception &) {
469 assert(fontIndex == 11 || fontIndex == 14 &&
"SelectSymbolFont, parameter fontIndex has invalid value");
474 if (it ==
fFonts[fontIndex].end()) {
481 if (!fontFileName || fontFileName[0] == 0) {
482 ::Error(
"FontCache::SelectSymbolFont",
"symbol.ttf file not found");
489 ::Error(
"FontCache::SelectSymbolFont",
"CFStringCreateWithCString failed");
494 if (!fontURL.
Get()) {
495 ::Error(
"FontCache::SelectSymbolFont",
"CFURLCreateWithFileSystemPath failed");
504 ::Error(
"FontCache::SelectSymbolFont",
"CTFontManagerRegisterFontsForURL failed");
513 ::Error(
"FontCache::SelectSymbolFont",
"CTFontManagerCreateFontDescriptorsFromURL failed");
517 CTFontDescriptorRef fontDesc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(arr.
Get(), 0);
519 const CGAffineTransform shearMatrix = {1., 0., 0.26794, 1., 0., 0.};
520 const CTFontGuard_t font(CTFontCreateWithFontDescriptorAndOptions(fontDesc, fixedSize,
521 fontIndex == 11 ? &CGAffineTransformIdentity :
522 &shearMatrix, kCTFontOptionsDefault),
false);
524 ::Error(
"FontCache::SelectSymbolFont",
"CTFontCreateWithFontDescriptor failed");
528 fFonts[fontIndex][fixedSize] = font;
530 }
catch (
const std::exception &) {
542 assert(
fSelectedFont != 0 &&
"GetTextBounds: no font was selected");
548 }
catch (
const std::exception &) {
556 assert(
fSelectedFont != 0 &&
"GetTextBounds: no font was selected");
562 }
catch (
const std::exception &) {
570 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
577 assert(
text != 0 &&
"GetAscent, parameter 'text' is null");
578 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
582 Int_t ascent = 0, descent = 0;
585 }
catch (
const std::exception &) {
593 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
597 Int_t ascent = 0, descent = 0;
600 }
catch (
const std::exception &) {
608 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
615 assert(
text != 0 &&
"GetDescent, parameter 'text' is null");
616 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
620 Int_t ascent = 0, descent = 0;
623 }
catch (
const std::exception &) {
631 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
635 Int_t ascent = 0, descent = 0;
638 }
catch (
const std::exception &) {
646 assert(
fSelectedFont != 0 &&
"GetLeading, no font was selected");
Handle_t FontStruct_t
Pointer to font structure.
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char text
R__EXTERN TSystem * gSystem
void FreeFontNames(char **fontList)
double GetLeading() const
void GetFontProperties(FontStruct_t font, int &maxAscent, int &maxDescent)
std::map< CTFontRef, CTFontGuard_t >::iterator font_iterator
char ** ListFonts(const X11::XLFDName &xlfd, int maxNames, int &count)
unsigned GetTextWidth(FontStruct_t font, const char *text, int nChars)
CTFontRef SelectSymbolFont(Float_t fontSize, unsigned fontIndex)
PSNameMap_t fXLFDtoPostscriptNames
double GetDescent() const
std::list< FontList > fFontLists
void GetTextBounds(UInt_t &w, UInt_t &h, const char *text) const
std::map< CTFontRef, CTFontGuard_t > fLoadedFonts
FontStruct_t LoadFont(const X11::XLFDName &xlfd)
void UnloadFont(FontStruct_t font)
CTFontRef SelectFont(Font_t fontIndex, Float_t fontSize)
bool fSymbolFontRegistered
FontMap_t::iterator font_map_iterator
FontMap_t fFonts[nPadFonts]
void GetBounds(UInt_t &w, UInt_t &h) const
void GetAscentDescent(Int_t &asc, Int_t &desc) const
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 char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
const CTFontOrientation horizontalFontOrientation
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...