glyphs2font icon indicating copy to clipboard operation
glyphs2font copied to clipboard

Support for QML ttf

Open danhauck opened this issue 5 years ago • 0 comments

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

danhauck avatar Jul 26 '19 13:07 danhauck