Hi all,
I've been looking for a while on internet and this forum, but couldn't find an answer. So I decided to post my question. I hope I didn't duplicate a question with my post.
I'd like to use the dimensions of a text as reference to drawmy objects on a watchface. Unfortunately, the methods dc.getTextDimensions(text, font) and dc.getFontHeight(font) return strange values. Or maybe the rendering of the text is wrong? In any case, here is a small example of my problem:
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_BLACK);
dc.clear();
var text = "1136";
var x=50;
var y=50;
var font = Gfx.FONT_SYSTEM_NUMBER_HOT;
dc.setColor(Gfx.COLOR_WHITE,Gfx.COLOR_BLACK);
dc.drawText(x,y, font, text, Gfx.TEXT_JUSTIFY_LEFT);
var dim = dc.getTextDimensions(text, font);
var h = dc.getFontHeight(font);
System.println(dim + " > "+ h);
dc.setColor(Gfx.COLOR_RED,Gfx.COLOR_RED);
dc.fillCircle(x,y,3);
dc.setColor(Gfx.COLOR_GREEN,Gfx.COLOR_GREEN);
dc.drawRectangle(x, y, dim[0], dim[1]);
}
this snippet of code gives
As you can see, there is a margin above and beneath the baseline of the text. Also there is a space between each number.
I have the same problem when following the tutorial https://www.youtube.com/watch?v=PRQyA4BeqqE
I get this result (code is slightly different, but the idea remains the same):
The font has a height of 180px and according to the System.print, the dimension returned by getTextDimension is effectively 180px (see green rectangle); meaning the text is smaller than 180px. How can this happen?
Does anybody have an idea?
Thanks!
Gautier