Skip to content

Commit feb45fe

Browse files
committed
Fix new vector font - accidentally committed one with too few points
Graphics.fillPoly now uses 4 bit fixed point internally
1 parent 8ff3977 commit feb45fe

File tree

7 files changed

+249
-230
lines changed

7 files changed

+249
-230
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
Pixl.js: fix self-test/terminal print - write to screen immediately after newline unless in IRQ
4242
Fix issue with iteration over arrays with negative entries (these should be converted to Strings)
4343
Linux: improve command-line, allow recursive test directory and more than one test (eg wildcard + shell expansion)
44+
Added new vector fonts supporting most of ISO8859-1
45+
Graphics.fillPoly now uses 4 bit fixed point internally
4446

4547
2v05 : Add Array.includes
4648
Fix (Number.toFixed) rounding, eg (1234.505).toFixed(2)

libs/graphics/graphics.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ void graphicsToDeviceCoordinates(const JsGraphics *gfx, int *x, int *y) {
204204
if (gfx->data.flags & JSGRAPHICSFLAGS_INVERT_Y) *y = (int)(gfx->data.height - (*y+1));
205205
}
206206

207+
// If graphics is flipped or rotated then the coordinates need modifying
208+
void graphicsToDeviceCoordinates16x(const JsGraphics *gfx, int *x, int *y) {
209+
if (gfx->data.flags & JSGRAPHICSFLAGS_SWAP_XY) {
210+
int t = *x;
211+
*x = *y;
212+
*y = t;
213+
}
214+
if (gfx->data.flags & JSGRAPHICSFLAGS_INVERT_X) *x = (int)((gfx->data.width-1)*16 - *x);
215+
if (gfx->data.flags & JSGRAPHICSFLAGS_INVERT_Y) *y = (int)((gfx->data.height-1)*16 - *y);
216+
}
217+
207218
unsigned short graphicsGetWidth(const JsGraphics *gfx) {
208219
return (gfx->data.flags & JSGRAPHICSFLAGS_SWAP_XY) ? gfx->data.height : gfx->data.width;
209220
}
@@ -409,7 +420,7 @@ void graphicsDrawLine(JsGraphics *gfx, int x1, int y1, int x2, int y2) {
409420
}
410421

411422

412-
423+
// Fill poly - each member of vertices is 1/16th pixel
413424
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
414425
typedef struct {
415426
short x,y;
@@ -423,11 +434,11 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
423434
// convert into device coordinates...
424435
int vx = v[i].x;
425436
int vy = v[i].y;
426-
graphicsToDeviceCoordinates(gfx, &vx, &vy);
437+
graphicsToDeviceCoordinates16x(gfx, &vx, &vy);
427438
v[i].x = (short)vx;
428439
v[i].y = (short)vy;
429440
// work out min and max
430-
short y = v[i].y;
441+
short y = v[i].y>>4;
431442
if (y<miny) miny=y;
432443
if (y>maxy) maxy=y;
433444
}
@@ -442,16 +453,15 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
442453
const int MAX_CROSSES = 64;
443454

444455
// for each scanline
445-
for (y=miny;y<=maxy;y++) {
456+
for (y=miny<<4;y<=maxy<<4;y+=16) {
446457
short cross[MAX_CROSSES];
447458
bool slopes[MAX_CROSSES];
448459
int crosscnt = 0;
449460
// work out all the times lines cross the scanline
450461
j = points-1;
451462
for (i=0;i<points;i++) {
452-
if ((y==miny && (v[i].y==y || v[j].y==y)) || // special-case top line
453-
(v[i].y<y && v[j].y>=y) ||
454-
(v[j].y<y && v[i].y>=y)) {
463+
if ((v[i].y<=y && v[j].y>=y) ||
464+
(v[j].y<=y && v[i].y>=y)) {
455465
if (crosscnt < MAX_CROSSES) {
456466
int l = v[j].y - v[i].y;
457467
if (l) { // don't do horiz lines - rely on the ends of the lines that join onto them
@@ -482,7 +492,8 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
482492
for (i=0;i<crosscnt;i++) {
483493
if (s==0) x=cross[i];
484494
if (slopes[i]) s++; else s--;
485-
if (!s || i==crosscnt-1) graphicsFillRectDevice(gfx,x,y,cross[i],y,gfx->data.fgColor);
495+
if (!s || i==crosscnt-1)
496+
graphicsFillRectDevice(gfx,x>>4,y>>4,cross[i]>>4,y>>4,gfx->data.fgColor);
486497
if (jspIsInterrupted()) break;
487498
}
488499
}

libs/graphics/graphics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void graphicsDrawRect(JsGraphics *gfx, int x1, int y1, int x2, int y2);
132132
void graphicsDrawEllipse(JsGraphics *gfx, int x, int y, int x2, int y2);
133133
void graphicsFillEllipse(JsGraphics *gfx, int x, int y, int x2, int y2);
134134
void graphicsDrawLine(JsGraphics *gfx, int x1, int y1, int x2, int y2);
135-
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices); // may overwrite vertices...
135+
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices); // each pixel is 1/16th a pixel may overwrite vertices...
136136
#ifndef NO_VECTOR_FONT
137137
unsigned int graphicsFillVectorChar(JsGraphics *gfx, int x1, int y1, int size, char ch); ///< prints character, returns width
138138
unsigned int graphicsVectorCharWidth(JsGraphics *gfx, unsigned int size, char ch); ///< returns the width of a character

libs/graphics/jswrap_graphics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ JsVar *jswrap_graphics_fillPoly(JsVar *parent, JsVar *poly) {
16531653
JsvIterator it;
16541654
jsvIteratorNew(&it, poly, JSIF_EVERY_ARRAY_ELEMENT);
16551655
while (jsvIteratorHasElement(&it) && idx<maxVerts) {
1656-
verts[idx++] = (short)jsvIteratorGetIntegerValue(&it);
1656+
verts[idx++] = (short)(0.5 + jsvIteratorGetFloatValue(&it)*16);
16571657
jsvIteratorNext(&it);
16581658
}
16591659
jsvIteratorFree(&it);

0 commit comments

Comments
 (0)