coretext: Support variable application fonts
Named instances of variable application fonts are exposed automatically through CTFontManagerCreateFontDescriptorsFromData() (and also for the URL equivalent). The main change here is just to call this instead of the overload which only returns the first font. Note that this also updates the test: This is because the conversion from CoreText normalized weight values to TTF values is not 100%. In the CoreText code, we map Heavy (0.56) to ExtraBold, but ExtraBold gets converted to 0.6, which is closer to the CoreText value for Black (0.62). To avoid hitting this inconsistency, the QtExtraBold has been changed to Black weight instead, which resolves to the same on all platforms. Task-number: QTBUG-108624 Change-Id: Ied6d42e9e3e1ba8b7102936c5be3d285b3d9e07f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
1aba24a2ed
commit
a890df0283
@ -714,13 +714,20 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData
|
||||
|
||||
if (!fontData.isEmpty()) {
|
||||
QCFType<CFDataRef> fontDataReference = fontData.toRawCFData();
|
||||
if (QCFType<CTFontDescriptorRef> descriptor = CTFontManagerCreateFontDescriptorFromData(fontDataReference)) {
|
||||
// There's no way to get the data back out of a font descriptor created with
|
||||
// CTFontManagerCreateFontDescriptorFromData, so we attach the data manually.
|
||||
NSDictionary *attributes = @{ kQtFontDataAttribute : [NSValue valueWithPointer:new QByteArray(fontData)] };
|
||||
descriptor = CTFontDescriptorCreateCopyWithAttributes(descriptor, (CFDictionaryRef)attributes);
|
||||
if (QCFType<CFArrayRef> descriptors = CTFontManagerCreateFontDescriptorsFromData(fontDataReference)) {
|
||||
CFMutableArrayRef array = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
||||
CFArrayAppendValue(array, descriptor);
|
||||
const int count = CFArrayGetCount(descriptors);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
CTFontDescriptorRef descriptor = CTFontDescriptorRef(CFArrayGetValueAtIndex(descriptors, i));
|
||||
|
||||
// There's no way to get the data back out of a font descriptor created with
|
||||
// CTFontManagerCreateFontDescriptorFromData, so we attach the data manually.
|
||||
NSDictionary *attributes = @{ kQtFontDataAttribute : [NSValue valueWithPointer:new QByteArray(fontData)] };
|
||||
descriptor = CTFontDescriptorCreateCopyWithAttributes(descriptor, (CFDictionaryRef)attributes);
|
||||
CFArrayAppendValue(array, descriptor);
|
||||
}
|
||||
|
||||
fonts = array;
|
||||
}
|
||||
} else {
|
||||
@ -980,5 +987,10 @@ QList<int> QCoreTextFontDatabase::standardSizes() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool QCoreTextFontDatabase::supportsVariableApplicationFonts() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
QFont defaultFont() const override;
|
||||
bool fontsAlwaysScalable() const override;
|
||||
QList<int> standardSizes() const override;
|
||||
bool supportsVariableApplicationFonts() const override;
|
||||
|
||||
// For iOS and macOS platform themes
|
||||
QFont *themeFont(QPlatformTheme::Font) const;
|
||||
|
@ -534,9 +534,9 @@ void tst_QFontDatabase::variableFont()
|
||||
|
||||
{
|
||||
QFont font(family);
|
||||
font.setWeight(QFont::ExtraBold);
|
||||
font.setWeight(QFont::Black);
|
||||
QCOMPARE(QFontInfo(font).styleName(), u"QtExtraBold"_s);
|
||||
QCOMPARE(QFontInfo(font).weight(), QFont::ExtraBold);
|
||||
QCOMPARE(QFontInfo(font).weight(), int(QFont::Black));
|
||||
}
|
||||
|
||||
{
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user