EDIT. Sorry, this is not supposed to be in its own thread. I only get two posting options. Quick Reply (which I don't want) or New Post.
Can anyone help? I'm trying to convert some code from JScript to Spider Monkey and this one is giving me a headache..
String.prototype.calc_width = function (font_str) {
var font = JSON.parse(font_str);
return utils.CalcTextWidth(this, font.Name, font.Size, font.Weight || 400);
}
It gives me... CalcTextWidth failed: Value is not a JS object
It's not contained in a function. In fact, it's the first lines in the code.
So I changed it to this and I get the same error...
let _bmp = gdi.CreateImage(1, 1);
let _gr = _bmp.GetGraphics();
String.prototype.calc_width = function (font) {
return _gr.CalcTextWidth(this, font);
}
This works...
let _bmp = gdi.CreateImage(1, 1);
let _gr = _bmp.GetGraphics();
String.prototype.calc_width = function (font) {
return _gr.CalcTextWidth(this, font);
}
var font = gdi.Font("Segoe UI", 16); // or could be window.GetFontCUI / window.GetFontDUI
var width = "XXXX".calc_width(font);
console.log(width);