Loading custom fonts on iOS
-
Hope it is going to be implemented in Qt 5.2.1;-)
-
Yeah, would be great :)
...but for now solution given by dbrian works like a charm, thanks for that.
P.S. i haven't used resource file, just plain ttf and it worked without using font loader, i've just listed all available font families by
@
QFontDatabase db;
foreach (const QString &family, db.families()) {
qDebug() << family;
}
@...and picked my custom font's family name
Cheers
-
Will give it a try in the evening
-
Tried it.
In the .pro file I added:
@
ios: {
fonts.files = ../../src/qml/fonts/SourceCodePro-Regular.ttf
fonts.path = .fonts
QMAKE_BUNDLE_DATA += fonts
}
@On the iOS device or simulator QFontDatabase db.families() contains an entry "Source Code Pro" and the .ttf file got copied to the corresponding application sandbox sub directory .fonts
But the console logs as you described
@
This plugin does not support application fonts
qrc:///qml/main.qml:12:5: QML FontLoader: Cannot load font: "qrc:///qml/fonts/SourceCodePro-Regular.ttf"
@main.qml lists
@
FontLoader { id: sourceCodeProFont; source: "fonts/SourceCodePro-Regular.ttf" }
@main.qml has been launched via qrc
@
view->setSource(QUrl("qrc:///qml/main.qml"));
@My Info.plist contains
@
<key>UIAppFonts</key>
<array>
<string>.fonts/SourceCodePro-Regular.ttf</string>
</array>
@Therefore, it seems as if one can not load a custom font!?
It would help to be able to have a .qml in the qrc system but define a file url as source of FontLoader instead of a qrc url in the .qml
-
Hi Jamil,
please try to remove FontLoader from qml completely, in my case that was a problem.If your font is present in QFontDatabase, just use font's family name while defining item in qml, i.e.:@
Text {
anchors.centerIn: ......
text: ......
color: "#ffffffff"
font.family: "Source Code Pro"
font.pointSize: 20
}
@Cheers
-
For the sake of completeness, it seems like FontLoader is fully implemented for iOS as of the current "Qt 5.3 beta":http://blog.qt.digia.com/blog/2014/03/25/qt-5-3-beta-released/, so there are no more hacks required. ;)
Cheers,
Alex