add icon font support (except for res)

This commit is contained in:
王劲鹏 2021-05-26 15:47:44 +08:00 committed by osborn
parent 08d767bed0
commit 1d4667b347
4 changed files with 33 additions and 0 deletions

View File

@ -3,6 +3,10 @@
<file>main.qml</file>
<file>test-layout.qml</file>
<file>qtquickcontrols2.conf</file>
<file alias="iconfont.ttf">../../../doric-demo/bundle/iconfont.ttf</file>
</qresource>
<qresource prefix="/fonts">
<file alias="assets_iconfont.ttf">./resources/assets_iconfont.ttf</file>
</qresource>
<qresource prefix="/doric/bundles">
<file alias="Counter.js">../../../doric-demo/bundle/src/Counter.js</file>

Binary file not shown.

View File

@ -6,6 +6,8 @@ import "util.mjs" as Util
import "gravity.mjs" as Gravity
TextArea {
FontLoader { id: webFont }
property var wrapper
property var uuid: Util.uuidv4()
@ -21,6 +23,13 @@ TextArea {
property int textAlignment: 0
property var fontSource: ""
onFontSourceChanged: {
webFont.source = fontSource
font.family = webFont.name
}
property var fontStyle: ""
onFontStyleChanged: {

View File

@ -50,6 +50,26 @@ void DoricTextNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
view->setProperty("lineCount", prop.toInt());
} else if (name == "fontStyle") {
view->setProperty("fontStyle", prop.toString());
} else if (name == "font") {
QString font = prop.toString();
QString fontPath = "";
QString fontName = font;
if (font.contains("/")) {
int separatorIndex = font.lastIndexOf("/");
fontPath = QStringRef(&font, 0, separatorIndex + 1).toString();
fontName = QStringRef(&font, separatorIndex + 1,
font.length() - separatorIndex - 1)
.toString();
}
if (fontName.endsWith(".ttf")) {
fontName = fontName.replace(".ttf", "");
}
QString path = "qrc:/" + fontPath + fontName + ".ttf";
view->setProperty("fontSource", path);
} else if (name == "shadow") {
view->setProperty("shadowColor", QVariant::fromValue(DoricUtils::doricColor(
prop["color"].toInt())));