Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for QML ttf #8

Open
danhauck opened this issue Jul 26, 2019 · 0 comments
Open

Support for QML ttf #8

danhauck opened this issue Jul 26, 2019 · 0 comments

Comments

@danhauck
Copy link

danhauck commented Jul 26, 2019

In QML ttf can be inserted by QFontDatabase::addApplicationFont("example-font.ttf"); but only accessed by code (e.g. "\ue002"). So if the following JS is generated

/* Icons for font example */
var icons = {
"success" : "\ue001",
"failure" : "\ue002",
"plus" : "\ue003",
"minus" : "\ue004",
}

in a QML file the js file can be imported by import "example-font-icons.js" as example and later on used example.icons.success

The following code must be inserted in glyphs2font.js:

    /*  generate qmljs  */
    if (cfg.font.qmljs) {
        var qmljs = ""
        qmljs += "/* Icons for font "+cfg.font.name+" */\n" 
        qmljs += "var icons = {\n"
  
        cfg.glyphs.forEach(function (glyph) {
            qmljs +=  "\"" + glyph.name.replace(/-/g,"_") + "\" : \"\\u" + glyph.code.toString(16) + "\",\n"
        })
        qmljs += "}\n"
        fs.writeFileSync(cwdto(cfg.font.qmljs, cfgfile), qmljs, "utf8")
    }

Then by adding qmljs: example-font-icons.js to yml file generator is enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant