42 #include <private/qt_mac_p.h> 48 #include <private/qfontengine_coretext_p.h> 49 #include <private/qfontengine_mac_p.h> 56 #ifndef QT_MAC_USE_COCOA 60 if (ATSFontGetTable(atsFont,
MAKE_TAG(
'O',
'S',
'/',
'2'), 0, 0, 0, &length) != noErr)
64 || ATSFontGetTable(atsFont,
MAKE_TAG(
'O',
'S',
'/',
'2'), 0, length, os2Table.
data(), &length) != noErr)
78 ATSFontGetName(atsFont, kATSOptionFlagsDefault, &name);
79 qDebug() << systems.count() <<
"writing systems for" <<
QString(name);
80 qDebug() <<
"first char" <<
hex << unicodeRange[0];
81 for (
int i = 0; i < systems.count(); ++i)
84 for (
int i = 0; i < systems.count(); ++i)
135 #if defined(QT_MAC_USE_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 143 QString foundry_name =
"CoreText";
144 const int numFonts = CFArrayGetCount(fonts);
145 for(
int i = 0; i < numFonts; ++i) {
146 CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fonts, i);
147 QCFString family_name = (
CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL);
148 QCFString style_name = (
CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL);
152 CFIndex length = CFArrayGetCount(languages);
157 if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang))
165 QString styleName = style_name;
166 if(
QCFType<CFDictionaryRef> styles = (CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute)) {
167 if(CFNumberRef weight = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontWeightTrait)) {
168 Q_ASSERT(CFNumberIsFloatType(weight));
170 if(CFNumberGetValue(weight, kCFNumberDoubleType, &d)) {
175 if(CFNumberRef italic = (CFNumberRef)CFDictionaryGetValue(styles, kCTFontSlantTrait)) {
176 Q_ASSERT(CFNumberIsFloatType(italic));
178 if(CFNumberGetValue(italic, kCFNumberDoubleType, &d)) {
188 if(
QCFType<CFNumberRef> size = (CFNumberRef)CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute)) {
191 if(CFNumberIsFloatType(size)) {
193 CFNumberGetValue(size, kCFNumberDoubleType, &d);
196 CFNumberGetValue(size, kCFNumberIntType, &pixel_size);
208 #ifndef QT_MAC_USE_COCOA 210 if (!FMCreateFontIterator(0, 0, kFMUseGlobalScopeOption, &it)) {
213 if (FMGetNextFont(&it, &fmFont) != noErr)
216 FMFontFamily fmFamily;
222 ATSFontRef atsFont = FMGetATSFontRefFromFont(fmFont);
224 if (!FMGetFontFamilyInstanceFromFont(fmFont, &fmFamily, &fmStyle)) {
227 if(ATSUFONDtoFontID(fmFamily, 0, &fontID) != noErr)
231 if (fmStyle & ::italic)
233 if (fmStyle & ::bold)
236 ATSFontFamilyRef familyRef = FMGetATSFontFamilyRefFromFontFamily(fmFamily);
238 ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &cfFamilyName);
239 familyName = cfFamilyName;
242 ATSFontGetName(atsFont, kATSOptionFlagsDefault, &cfFontName);
243 familyName = cfFontName;
248 if (ATSFontGetTable(atsFont,
MAKE_TAG(
'h',
'e',
'a',
'd'), 44, 4, &data, &len) == noErr)
265 FMDisposeFontIterator(&it);
279 const char *stylehint = 0;
285 stylehint =
"Times New Roman";
288 stylehint =
"Courier New";
292 stylehint =
"Courier New";
300 return (weight - 50) / 100.0;
305 #if defined(QT_MAC_USE_COCOA) 308 ATSFontFamilyRef familyRef = 0;
309 ATSFontRef fontRef = 0;
325 for (
int i = 0; i < family_list.
size(); ++i) {
326 for (
int k = 0; k < db->
count; ++k) {
328 #if defined(QT_MAC_USE_COCOA) 332 (
const void**)&kCTFontFamilyNameAttribute,
333 (
const void**)&familyName, 1,
334 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)));
335 CFRelease(familyName);
338 fontName = CTFontCopyFullName(ctFont);
352 #ifdef QT_MAC_USE_COCOA 358 if (ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr)
370 qWarning(
"QFont: Must construct a QApplication before a QFont");
407 #if defined(QT_MAC_USE_COCOA) 414 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
415 CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, expectedFamily);
416 CFDictionaryAddValue(attributes, kCTFontStyleNameAttribute, expectedStyle);
422 QCFString familyName = CTFontCopyFamilyName(ctFont);
424 if (CFEqual(expectedFamily, familyName)) {
442 ATSFontContainerRef handle;
446 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) 452 ATSFontActivateFromFileReference(&ref, kATSFontContextLocal, kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle);
461 e = ATSFontActivateFromFileSpecification(&spec, kATSFontContextLocal, kATSFontFormatUnspecified,
462 0, kATSOptionFlagsDefault, &handle);
467 kATSFontFormatUnspecified, 0, kATSOptionFlagsDefault, &handle);
475 ItemCount fontCount = 0;
476 e = ATSFontFindFromContainer(handle, kATSOptionFlagsDefault, 0, 0, &fontCount);
481 e = ATSFontFindFromContainer(handle, kATSOptionFlagsDefault, fontCount, containedFonts.
data(), &fontCount);
486 #if defined(QT_MAC_USE_COCOA) 493 for(
int i = 0; i < containedFonts.
size(); ++i) {
495 ATSFontGetPostScriptName(containedFonts[i], kATSOptionFlagsDefault, &fontPostScriptName);
497 QCFString familyName = (
CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
501 for(
int i = 0; i < containedFonts.
size(); ++i) {
503 ATSFontGetName(containedFonts[i], kATSOptionFlagsDefault, &family);
520 0, kATSOptionFlagsDefault);
552 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
553 CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, expectedFamily);
557 CFSetAddValue(mandatoryAttributes, kCTFontFamilyNameAttribute);
564 QCFString familyName = (
CFStringRef) CTFontDescriptorCopyLocalizedAttribute(matched, kCTFontFamilyNameAttribute, NULL);
static bool removeAllApplicationFonts()
Removes all application-local fonts previously added using addApplicationFont() and addApplicationFon...
const struct __CFString * CFStringRef
OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
QFont font(const QString &family, const QString &style, int pointSize) const
Returns a QFont object that has family family, style style and point size pointSize.
#define QT_END_NAMESPACE
This macro expands to.
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
static const char * styleHint(const QFontDef &request)
#define it(className, varName)
The QByteArray class provides an array of bytes.
static float weightToFloat(unsigned int weight)
static CFStringRef toCFStringRef(const QString &str)
void insertEngine(const Key &key, QFontEngine *engine)
int qt_mac_pixelsize(const QFontDef &def, int dpi)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool ref()
Atomically increments the value of this QAtomicInt.
quint32 qFromBigEndian< quint32 >(const uchar *src)
The QString class provides a Unicode character string.
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
static const char * languageForWritingSystem[]
static QFontCache * instance()
OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
static QFont font()
Returns the default application font.
#define MAKE_TAG(ch1, ch2, ch3, ch4)
Q_CORE_EXPORT void qDebug(const char *,...)
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QStringList familyList(const QFontDef &req)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QFontEngine * loadFromDatabase(QFontDef &req, const QFontPrivate *d)
void insertEngineData(const Key &key, QFontEngineData *engineData)
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
static void initWritingSystems(QtFontFamily *family, ATSFontRef atsFont)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static bool supportsThreadedFontRendering()
Returns true if font rendering is supported outside the GUI thread, false otherwise.
static void initializeDb()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
static QString resolveFontFamilyAlias(const QString &family)
void clear()
Removes all items from the list.
static bool removeApplicationFont(int id)
Removes the previously loaded application font identified by id.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QtFontFamily * family(const QString &f, bool=false)
quint16 qFromBigEndian< quint16 >(const uchar *src)
const char * constData() const
Returns a pointer to the data stored in the byte array.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
int compare(const QString &s) const
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
int size() const
Returns the number of items in the list.
int size() const
Returns the number of bytes in this byte array.
QString defaultFamily() const
Returns the family name that corresponds to the current style hint.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
int qt_mac_pointsize(const QFontDef &def, int dpi)
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef)
QFontEngineData * findEngineData(const Key &key) const
QFontEngine * findEngine(const Key &key)
QVector< ApplicationFont > applicationFonts
QtFontFoundry * foundry(const QString &f, bool=false)
static QString writingSystemName(WritingSystem writingSystem)
Returns the names the writingSystem (e.g.
static void load(const QString &=QString(), int=-1)
const struct __CFArray * CFArrayRef
QFontEngineData * engineData
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Q_DECL_CONSTEXPR int qRound(qreal d)
QFontEngine * engine(int at) const
QList< QFontDatabase::WritingSystem > qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2])