HydrogenAudio

Hosted Forums => foobar2000 => 3rd Party Plugins - (fb2k) => Topic started by: Majestyk on 2023-03-20 02:23:43

Title: Re: Spider Monkey Panel (foo_spider_monkey_panel)
Post by: Majestyk on 2023-03-20 02:23:43
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..
Code: [Select]
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...

Code: [Select]
let _bmp = gdi.CreateImage(1, 1);
let _gr = _bmp.GetGraphics();

String.prototype.calc_width = function (font) {
return _gr.CalcTextWidth(this, font);
}
Title: Re: Spider Monkey Panel (foo_spider_monkey_panel)
Post by: marc2k3 on 2023-03-20 11:55:35
This works...

Code: [Select]
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);