diff --git a/doric-Qt/example/app/qml.qrc b/doric-Qt/example/app/qml.qrc index 8347b124..e83c096e 100644 --- a/doric-Qt/example/app/qml.qrc +++ b/doric-Qt/example/app/qml.qrc @@ -3,6 +3,10 @@ main.qml test-layout.qml qtquickcontrols2.conf + ../../../doric-demo/bundle/iconfont.ttf + + + ./resources/assets_iconfont.ttf ../../../doric-demo/bundle/src/Counter.js diff --git a/doric-Qt/example/app/resources/assets_iconfont.ttf b/doric-Qt/example/app/resources/assets_iconfont.ttf new file mode 100644 index 00000000..6ea00a93 Binary files /dev/null and b/doric-Qt/example/app/resources/assets_iconfont.ttf differ diff --git a/doric-Qt/example/doric/resources/text.qml b/doric-Qt/example/doric/resources/text.qml index 6290c455..af97dfa7 100644 --- a/doric-Qt/example/doric/resources/text.qml +++ b/doric-Qt/example/doric/resources/text.qml @@ -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: { diff --git a/doric-Qt/example/doric/shader/DoricTextNode.cpp b/doric-Qt/example/doric/shader/DoricTextNode.cpp index 870bf417..69f6584b 100644 --- a/doric-Qt/example/doric/shader/DoricTextNode.cpp +++ b/doric-Qt/example/doric/shader/DoricTextNode.cpp @@ -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())));