Starting from version 1078, the API prefix has been changed from hbs to qg. The original prefix hbs is still supported.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
fontStyle | string | No | Font style.
|
fontWeight | string | No | Font weight.
|
fontSize | number | No | Font size. |
fontFamily | string | Yes | Font family. |
text | string | Yes | Text content. |
success | function | No | Callback function triggered upon a successful API call. |
fail | function | No | Callback function triggered upon a failed API call. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
var height = qg.getTextLineHeight({
"fontStyle": "italic",
"fontWeight": "bold",
"fontSize": "20",
"fontFamily": "Arial",
"text": "test",
"success": function(h){
console.log("getTextLineHeight:" + h)
},
"fail": function(msg){
console.log("getTextLineHeight fail:" + msg)
},
"complete": function(){
console.log("getTextLineHeight complete")
}
}); Parameter | Type | Mandatory | Description |
|---|---|---|---|
familyName | string | No | Font family. |
path | string | Yes | Font file path. The path can be a code package file path or a path specified by qg.env.USER_DATA_PATH + ${File path}. |
If a font is loaded successfully, its font family (of the string type) is returned. Otherwise, null is returned.
var userFilePath = `${qg.env.USER_DATA_PATH}/writer.ttf`; // userFilePath indicates a path on the mobile phone. (Font files can be downloaded from a remote directory to a local path.)
var rpkFilePath = "font/writer.ttf" // Code path
// The font is in the code package (two parameters required).
var font = qg.loadFont("Arial", rpkFilePath)
// The font is stored locally (two parameters required).
var font = qg.loadFont("Arial", userFilePath);
// The font is in the code package (single parameter required).
var font = qg.loadFont(rpkFilePath)
// The font is stored locally (single parameter required).
var font = qg.loadFont(userFilePath);