mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
Graphics: Fix text bounding box calculation when just the top line of a character would be visible
This commit is contained in:
parent
d1f2ed061f
commit
ef4553d55d
@ -38,6 +38,7 @@
|
||||
Bangle.js2: Ensure NRF.setTxPower works for all connections and advertising
|
||||
If a process.on("uncaughtException" handler creates an exception, make sure we report it as Uncaught
|
||||
Bangle.js: If home button held and JS is still executing, force a break (like Ctrl-C)
|
||||
Graphics: Fix text bounding box calculation when just the top line of a character would be visible
|
||||
|
||||
2v12 : nRF52840: Flow control XOFF is now sent at only 3/8th full - delays in BLE mean we can sometimes fill our 1k input buffer otherwise
|
||||
__FILE__ is now set correctly for apps (fixes 2v11 regression)
|
||||
|
||||
@ -2244,7 +2244,7 @@ JsVar *jswrap_graphics_drawString(JsVar *parent, JsVar *var, int x, int y, bool
|
||||
if (info.font == JSGRAPHICS_FONTSIZE_VECTOR) {
|
||||
#ifndef NO_VECTOR_FONT
|
||||
int w = (int)graphicsVectorCharWidth(&gfx, info.scalex, ch);
|
||||
if (x>minX-w && x<maxX && y>minY-fontHeight && y<maxY) {
|
||||
if (x>minX-w && x<maxX && y>minY-fontHeight && y<=maxY) {
|
||||
if (solidBackground)
|
||||
graphicsFillRect(&gfx,x,y,x+w-1,y+fontHeight-1, gfx.data.bgColor);
|
||||
graphicsFillVectorChar(&gfx, x, y, info.scalex, info.scaley, ch);
|
||||
@ -2252,12 +2252,12 @@ JsVar *jswrap_graphics_drawString(JsVar *parent, JsVar *var, int x, int y, bool
|
||||
x+=w;
|
||||
#endif
|
||||
} else if (info.font == JSGRAPHICS_FONTSIZE_4X6) {
|
||||
if (x>minX-4*info.scalex && x<maxX && y>minY-fontHeight && y<maxY)
|
||||
if (x>minX-4*info.scalex && x<maxX && y>minY-fontHeight && y<=maxY)
|
||||
graphicsDrawChar4x6(&gfx, x, y, ch, info.scalex, info.scaley, solidBackground);
|
||||
x+=4*info.scalex;
|
||||
#ifdef USE_FONT_6X8
|
||||
} else if (info.font == JSGRAPHICS_FONTSIZE_6X8) {
|
||||
if (x>minX-6*info.scalex && x<maxX && y>minY-fontHeight && y<maxY)
|
||||
if (x>minX-6*info.scalex && x<maxX && y>minY-fontHeight && y<=maxY)
|
||||
graphicsDrawChar6x8(&gfx, x, y, ch, info.scalex, info.scaley, solidBackground);
|
||||
x+=6*info.scalex;
|
||||
#endif
|
||||
@ -2280,7 +2280,7 @@ JsVar *jswrap_graphics_drawString(JsVar *parent, JsVar *var, int x, int y, bool
|
||||
width = (int)jsvGetInteger(customWidth);
|
||||
bmpOffset = width*(ch-info.customFirstChar);
|
||||
}
|
||||
if (ch>=info.customFirstChar && (x>minX-width*info.scalex) && (x<maxX) && (y>minY-fontHeight) && y<maxY) {
|
||||
if (ch>=info.customFirstChar && (x>minX-width*info.scalex) && (x<maxX) && (y>minY-fontHeight) && y<=maxY) {
|
||||
int ch = fontHeight/info.scaley;
|
||||
bmpOffset *= ch * customBPP;
|
||||
// now render character
|
||||
|
||||
42
tests/test_graphics_drawStringClipRect.js
Normal file
42
tests/test_graphics_drawStringClipRect.js
Normal file
@ -0,0 +1,42 @@
|
||||
var g = Graphics.createArrayBuffer(8,8,8);
|
||||
g.dump = _=>{
|
||||
var s = "";
|
||||
var b = new Uint8Array(g.buffer);
|
||||
var n = 0;
|
||||
for (var y=0;y<g.getHeight();y++) {
|
||||
s+="\n";
|
||||
for (var x=0;x<g.getWidth();x++)
|
||||
s+=".#"[b[n++]?1:0];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
g.print = _=>{
|
||||
print("`"+g.dump()+"`");
|
||||
}
|
||||
var ok = true;
|
||||
function SHOULD_BE(a) {
|
||||
var b = g.dump();
|
||||
if (a!=b) {
|
||||
console.log("GOT :"+b+"\nSHOULD BE:"+a+"\n================");
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
// left align
|
||||
g.clear(1);
|
||||
g.setClipRect(0,0, g.getWidth()-1, 0);
|
||||
g.drawString("T", 0, 0);
|
||||
// font visibility should mean that the top line of T is drawn
|
||||
|
||||
SHOULD_BE(`
|
||||
###.....
|
||||
........
|
||||
........
|
||||
........
|
||||
........
|
||||
........
|
||||
........
|
||||
........`);
|
||||
|
||||
|
||||
result = ok;
|
||||
Loading…
x
Reference in New Issue
Block a user