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()) {
387 std::vector<char> &data =
fFontLists.back().fStringData;
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");
420 typedef std::vector<CGSize>::size_type size_type;
422 CTFontRef fontRef = (CTFontRef)font;
427 nChars = std::strlen(
text);
429 std::vector<UniChar> unichars(
text,
text + nChars);
432 std::vector<CGGlyph> glyphs(unichars.size());
433 CTFontGetGlyphsForCharacters(fontRef, &unichars[0], &glyphs[0], unichars.size());
436 std::vector<CGSize> glyphAdvances(glyphs.size());
439 CGFloat textWidth = 0.;
440 for (size_type i = 0,
e = glyphAdvances.size(); i <
e; ++i)
450 CTFontRef fontRef = (CTFontRef)font;
455 maxAscent = int(CTFontGetAscent(fontRef) + 0.5) + 2;
456 maxDescent = int(CTFontGetDescent(fontRef) + 0.5);
457 }
catch (
const std::exception &) {
468 if (fontIndex >
nPadFonts || !fontIndex) {
469 ::Warning(
"FontCache::SelectFont",
"Font with index %d was requested", fontIndex);
474 if (fontIndex == 11 || fontIndex == 14)
480 if (it ==
fFonts[fontIndex].end()) {
483 const CTFontGuard_t font(CTFontCreateWithName(fixedFontNames[fontIndex], fixedSize, 0),
false);
485 ::Error(
"FontCache::SelectFont",
"CTFontCreateWithName failed for font %d", fontIndex);
489 fFonts[fontIndex][fixedSize] = font;
491 }
catch (
const std::exception &) {
502 assert(fontIndex == 11 || fontIndex == 14 &&
"SelectSymbolFont, parameter fontIndex has invalid value");
507 if (it ==
fFonts[fontIndex].end()) {
514 if (!fontFileName || fontFileName[0] == 0) {
515 ::Error(
"FontCache::SelectSymbolFont",
"symbol.ttf file not found");
522 ::Error(
"FontCache::SelectSymbolFont",
"CFStringCreateWithCString failed");
527 if (!fontURL.
Get()) {
528 ::Error(
"FontCache::SelectSymbolFont",
"CFURLCreateWithFileSystemPath failed");
537 ::Error(
"FontCache::SelectSymbolFont",
"CTFontManagerRegisterFontsForURL failed");
546 ::Error(
"FontCache::SelectSymbolFont",
"CTFontManagerCreateFontDescriptorsFromURL failed");
550 CTFontDescriptorRef fontDesc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(arr.
Get(), 0);
552 const CGAffineTransform shearMatrix = {1., 0., 0.26794, 1., 0., 0.};
553 const CTFontGuard_t font(CTFontCreateWithFontDescriptorAndOptions(fontDesc, fixedSize,
554 fontIndex == 11 ? &CGAffineTransformIdentity :
555 &shearMatrix, kCTFontOptionsDefault),
false);
557 ::Error(
"FontCache::SelectSymbolFont",
"CTFontCreateWithFontDescriptor failed");
561 fFonts[fontIndex][fixedSize] = font;
563 }
catch (
const std::exception &) {
575 assert(
fSelectedFont != 0 &&
"GetTextBounds: no font was selected");
581 }
catch (
const std::exception &) {
589 assert(
fSelectedFont != 0 &&
"GetTextBounds: no font was selected");
595 }
catch (
const std::exception &) {
603 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
610 assert(
text != 0 &&
"GetAscent, parameter 'text' is null");
611 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
615 Int_t ascent = 0, descent = 0;
618 }
catch (
const std::exception &) {
626 assert(
fSelectedFont != 0 &&
"GetAscent, no font was selected");
630 Int_t ascent = 0, descent = 0;
633 }
catch (
const std::exception &) {
641 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
648 assert(
text != 0 &&
"GetDescent, parameter 'text' is null");
649 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
653 Int_t ascent = 0, descent = 0;
656 }
catch (
const std::exception &) {
664 assert(
fSelectedFont != 0 &&
"GetDescent, no font was selected");
668 Int_t ascent = 0, descent = 0;
671 }
catch (
const std::exception &) {
679 assert(
fSelectedFont != 0 &&
"GetLeading, no font was selected");
include TDocParser_001 C image html pict1_TDocParser_001 png width
void Error(const char *location, const char *msgfmt,...)
void Warning(const char *location, const char *msgfmt,...)
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
Namespace for new ROOT classes and functions.