Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Re: Spider Monkey Panel (foo_spider_monkey_panel) (Read 1045 times) previous topic - next topic - Topic derived from Re: Spider Monkey Pan...
0 Members and 1 Guest are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

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);
}

 

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #1
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);