44 #include <CoreText/CoreText.h> 45 #include <Foundation/Foundation.h> 47 #include <private/qcore_mac_p.h> 48 #include <private/qfontengine_coretext_p.h> 61 const_cast<QCoreTextFontDatabase *>(
this)->populateFontDatabase();
68 if ([style isEqual:
@"sans-serif"])
70 else if ([style isEqual:
@"monospace"])
72 else if ([style isEqual:
@"cursive"])
74 else if ([style isEqual:
@"serif"])
76 else if ([style isEqual:
@"fantasy"])
84 NSArray *map1 = (NSArray *) obj1;
85 NSArray *map2 = (NSArray *) obj2;
86 NSArray *languages = (NSArray *) context;
88 NSString *lang1 = [map1 objectAtIndex: 0];
89 NSString *lang2 = [map2 objectAtIndex: 0];
91 return [languages indexOfObject: lang1] - [languages indexOfObject: lang2];
98 if (psNameToFamily->
contains(name)) {
99 return psNameToFamily->
value(name);
103 QCFString family = CTFontCopyFamilyName(font);
104 (*psNameToFamily)[
name] = family;
114 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]
init];
125 QString foundry_name =
"CoreText";
126 const int numFonts = CFArrayGetCount(fonts);
128 for (
int i = 0; i < numFonts; ++i) {
129 CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i);
131 QCFString family_name = (
CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
136 if (
QCFType<CFDictionaryRef> styles = (CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute)) {
137 if (CFNumberRef weight = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontWeightTrait)) {
138 Q_ASSERT(CFNumberIsFloatType(weight));
140 if (CFNumberGetValue(weight, kCFNumberDoubleType, &d)) {
145 if (CFNumberRef italic = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontSlantTrait)) {
146 Q_ASSERT(CFNumberIsFloatType(italic));
148 if (CFNumberGetValue(italic, kCFNumberDoubleType, &d)) {
156 if (
QCFType<CFNumberRef> size = (CFNumberRef)CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute)) {
157 if (CFNumberIsFloatType(size)) {
159 CFNumberGetValue(size, kCFNumberDoubleType, &d);
162 CFNumberGetValue(size, kCFNumberIntType, &pixelSize);
174 supportedWritingSystems,
178 kCTFontNameAttribute);
183 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
184 NSArray *languages = [defaults stringArrayForKey:
@"AppleLanguages"];
186 NSDictionary *fallbackDict = [NSDictionary dictionaryWithContentsOfFile:
@"/System/Library/Frameworks/CoreText.framework/DefaultFontFallbacks.plist"];
187 for (NSString *style in [fallbackDict
allKeys]) {
188 NSArray *list = [fallbackDict valueForKey: style];
191 for (
id item in list) {
192 if ([item isKindOfClass: [NSArray
class]]) {
193 NSArray *langs = [(NSArray *) item sortedArrayUsingFunction:
languageMapSort 195 for (NSArray *
map in langs)
197 }
else if ([item isKindOfClass: [NSString
class]]) {
212 CTFontSymbolicTraits symbolicTraits = 0;
214 symbolicTraits |= kCTFontBoldTrait;
215 switch (fontDef.
style) {
220 symbolicTraits |= kCTFontItalicTrait;
224 CGAffineTransform transform = CGAffineTransformIdentity;
226 transform = CGAffineTransformMakeScale(
float(fontDef.
stretch) /
float(100), 1);
235 ctFont = CTFontCreateCopyWithSymbolicTraits(baseFont, fontDef.
pixelSize, &transform, symbolicTraits, symbolicTraits);
static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result)
void setSupported(QFontDatabase::WritingSystem, bool supported=true)
Sets the supported state of the writing system given by writingSystem to the value specified by suppo...
const struct __CFString * CFStringRef
#define QT_END_NAMESPACE
This macro expands to.
static NSInteger languageMapSort(id obj1, id obj2, void *context)
static QString toQString(CFStringRef cfstr)
Weight
Qt uses a weighting scale from 0 to 99 similar to, but not the same as, the scales used in Windows or...
The QString class provides a Unicode character string.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
const T value(const Key &key) const
Returns the value associated with the key.
void populateFontDatabase()
This function is called once at startup by Qts internal fontdatabase.
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static float pixelSize(const QFontDef &request, int dpi)
The QStringList class provides a list of strings.
The QSupportedWritingSystems class is used when registering fonts with the internal Qt fontdatabase...
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
const char * styleHint(const QFontDef &request)
Style
This enum describes the different styles of glyphs that are used to display text. ...
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
static QString familyNameFromPostScriptName(QHash< QString, QString > *psNameToFamily, NSString *psName)
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const
Returns a list of alternative fonts for the specified family and style and script using the styleHint...
QHash< QFont::StyleHint, QStringList > fallbackLists
QFontEngine * fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle)
Returns the font engine that can be used to render the font described by the font definition...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QFont::StyleHint styleHintFromNSString(NSString *style)