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))
123#ifdef MAC_OS_X_VERSION_10_9
126bool GetPostscriptName(CTFontDescriptorRef fontDescriptor, std::vector<char> &
name)
129 assert(fontDescriptor != 0 &&
"GetPostscriptName, parameter 'fontDescriptor' is null");
135 if (
const CFIndex cfLen = CFStringGetLength(cfFamilyName.Get())) {
136 name.resize(cfLen + 1);
137 if (CFStringGetCString(cfFamilyName.Get(), &
name[0],
name.size(), kCFStringEncodingMacRoman))
147void GetWeightAndSlant(CTFontDescriptorRef fontDescriptor,
X11::XLFDName &newXLFD)
152 if (CFNumberRef symbolTraits = (CFNumberRef)CFDictionaryGetValue(traits.Get(), kCTFontSymbolicTrait)) {
154 CFNumberGetValue(symbolTraits, kCFNumberIntType, &val);
155 if (val & kCTFontItalicTrait)
160 if (val & kCTFontBoldTrait)
185void GetPixelSize(CTFontDescriptorRef fontDescriptor,
X11::XLFDName &newXLFD)
190 if(CFNumberIsFloatType(
size.Get())) {
192 CFNumberGetValue(
size.Get(), kCFNumberDoubleType, &val);
195 CFNumberGetValue(
size.Get(), kCFNumberIntType, &pixelSize);
203void CreateXLFDString(
const X11::XLFDName &xlfd, std::string &xlfdString)
205 xlfdString =
"-CoreText-";
209 xlfdString +=
"-bold";
211 xlfdString +=
"-normal";
218 xlfdString +=
"-*-*";
221 std::ostringstream
out;
224 xlfdString +=
out.str();
228 xlfdString +=
"-*-*-*-*-*-*-*-";
235 : fSymbolFontRegistered(false)
249#ifdef MAC_OS_X_VERSION_10_9
252 const CFScopeGuard<CFStringRef> fontName(CFStringCreateWithCString(kCFAllocatorDefault, psName.c_str(), kCFStringEncodingMacRoman));
254 const CFScopeGuard<CFStringRef> fontName(CFStringCreateWithCString(kCFAllocatorDefault, xlfd.
fFamilyName.c_str(), kCFStringEncodingMacRoman));
257 const CFStrongReference<CTFontRef> baseFont(CTFontCreateWithName(fontName.Get(), xlfd.
fPixelSize, 0),
false);
259 if (!baseFont.Get()) {
260 ::Error(
"FontCache::LoadFont",
"CTFontCreateWithName failed for %s", xlfd.
fFamilyName.c_str());
264 CTFontSymbolicTraits symbolicTraits = CTFontSymbolicTraits();
267 symbolicTraits |= kCTFontBoldTrait;
269 symbolicTraits |= kCTFontItalicTrait;
271 if (symbolicTraits) {
272 const CFStrongReference<CTFontRef> font(CTFontCreateCopyWithSymbolicTraits(baseFont.Get(), xlfd.
fPixelSize, 0, symbolicTraits, symbolicTraits),
false);
290 CTFontRef fontRef = (CTFontRef)font;
293 assert(fontIter !=
fLoadedFonts.end() &&
"Attempt to unload font, not created by font manager");
301 typedef std::vector<char>::size_type size_type;
313 if (!collectionGuard.
Get())
318 ::Error(
"FontCache::ListFonts",
"CTFontCollectionCreateMatchingFontDescriptors failed %s", xlfd.
fFamilyName.c_str());
322 std::vector<char> xlfdData;
324 std::vector<char> familyName;
326 std::string xlfdString;
328 const CFIndex nFonts = CFArrayGetCount(
fonts.Get());
329 for (CFIndex i = 0; i < nFonts && count < maxNames; ++i) {
330 CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(
fonts.Get(), i);
332 if (!GetFamilyName(font, familyName))
343 if (newXLFD.
fFamilyName.find(
'-') != std::string::npos)
346 GetWeightAndSlant(font, newXLFD);
355 GetPixelSize(font, newXLFD);
361#ifdef MAC_OS_X_VERSION_10_9
366 std::vector<char> postscriptName;
367 if (GetPostscriptName(font, postscriptName)) {
375 CreateXLFDString(newXLFD, xlfdString);
377 xlfdData.insert(xlfdData.end(), xlfdString.begin(), xlfdString.end());
378 xlfdData.push_back(0);
383 if (xlfdData.size()) {
388 std::vector<char *> &list =
fFontLists.back().fList;
390 list.push_back(&
data[0]);
391 for (size_type i = 1,
e =
data.size(); i <
e; ++i) {
392 if (!
data[i] && i + 1 <
e)
393 list.push_back(&
data[i + 1]);
407 for (std::list<FontList>::iterator it =
fFontLists.begin(), eIt =
fFontLists.end(); it != eIt; ++it) {
408 if (fontList == &it->fList[0]) {
414 assert(0 &&
"FreeFontNames, unknown fontList");
423 typedef std::vector<CGSize>::size_type size_type;
425 CTFontRef fontRef = (CTFontRef)font;
430 nChars = std::strlen(
text);
432 std::vector<UniChar> unichars(
text,
text + nChars);
435 std::vector<CGGlyph> glyphs(unichars.size());
436 CTFontGetGlyphsForCharacters(fontRef, &unichars[0], &glyphs[0], unichars.size());
439 std::vector<CGSize> glyphAdvances(glyphs.size());
442 CGFloat textWidth = 0.;
443 for (size_type i = 0,
e = glyphAdvances.size(); i <
e; ++i)
444 textWidth += std::ceil(glyphAdvances[i].
width);
453 CTFontRef fontRef = (CTFontRef)font;
458 maxAscent =
int(CTFontGetAscent(fontRef) + 0.5) + 2;
459 maxDescent =
int(CTFontGetDescent(fontRef) + 0.5);
460 }
catch (
const std::exception &) {
471 if (fontIndex >
nPadFonts || !fontIndex) {
472 ::Warning(
"FontCache::SelectFont",
"Font with index %d was requested", fontIndex);
477 if (fontIndex == 11 || fontIndex == 14)
483 if (it ==
fFonts[fontIndex].end()) {
486 const CTFontGuard_t font(CTFontCreateWithName(fixedFontNames[fontIndex], fixedSize, 0),
false);
488 ::Error(
"FontCache::SelectFont",
"CTFontCreateWithName failed for font %d", fontIndex);
492 fFonts[fontIndex][fixedSize] = font;
494 }
catch (
const std::exception &) {
505 assert(fontIndex == 11 || fontIndex == 14 &&
"SelectSymbolFont, parameter fontIndex has invalid value");
510 if (it ==
fFonts[fontIndex].end()) {
517 if (!fontFileName || fontFileName[0] == 0) {
518 ::Error(
"FontCache::SelectSymbolFont",
"symbol.ttf file not found");
525 ::Error(
"FontCache::SelectSymbolFont",
"CFStringCreateWithCString failed");
530 if (!fontURL.
Get()) {
531 ::Error(
"FontCache::SelectSymbolFont",
"CFURLCreateWithFileSystemPath failed");
540 ::Error(
"FontCache::SelectSymbolFont",
"CTFontManagerRegisterFontsForURL failed");
549 ::Error(
"FontCache::SelectSymbolFont",
"CTFontManagerCreateFontDescriptorsFromURL failed");
553 CTFontDescriptorRef fontDesc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(arr.
Get(), 0);
555 const CGAffineTransform shearMatrix = {1., 0., 0.26794, 1., 0., 0.};
556 const CTFontGuard_t font(CTFontCreateWithFontDescriptorAndOptions(fontDesc, fixedSize,
557 fontIndex == 11 ? &CGAffineTransformIdentity :
558 &shearMatrix, kCTFontOptionsDefault),
false);
560 ::Error(
"FontCache::SelectSymbolFont",
"CTFontCreateWithFontDescriptor failed");
564 fFonts[fontIndex][fixedSize] = font;
566 }
catch (
const std::exception &) {
578 assert(
fSelectedFont != 0 &&
"GetTextBounds: no font was selected");
584 }
catch (
const std::exception &) {
592 assert(
fSelectedFont != 0 &&
"GetTextBounds: no font was selected");
598 }
catch (
const std::exception &) {
606 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
613 assert(
text != 0 &&
"GetAscent, parameter 'text' is null");
614 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
618 Int_t ascent = 0, descent = 0;
621 }
catch (
const std::exception &) {
629 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
633 Int_t ascent = 0, descent = 0;
636 }
catch (
const std::exception &) {
644 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
651 assert(
text != 0 &&
"GetDescent, parameter 'text' is null");
652 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
656 Int_t ascent = 0, descent = 0;
659 }
catch (
const std::exception &) {
667 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
671 Int_t ascent = 0, descent = 0;
674 }
catch (
const std::exception &) {
682 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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.