From c8fbe1bb037c9e2a4fdd3459ccfac18441134ef0 Mon Sep 17 00:00:00 2001 From: Xavier Grosjean <grosjean@adobe.com> Date: Tue, 24 Oct 2017 08:43:19 +0200 Subject: [PATCH] Fixed up-bound shifting issue when parsing a font, reported by @lorol --- resources/glyphEditor.html | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/resources/glyphEditor.html b/resources/glyphEditor.html index d234be3..62e9d25 100644 --- a/resources/glyphEditor.html +++ b/resources/glyphEditor.html @@ -104,16 +104,16 @@ SOFTWARE. <td width="75%" rowspan="5"> <textarea id="inputText" placeholder="Or paste a char array font definition here"> const char My_Font[] PROGMEM = { - 0xa, // Width: 10 - 0xd, // Height: 13 - 0x1, // First char: 1 - 0x2, // Number of chars: 2 - // Jump table: - 0x0, 0x0, 0x14, 0xa, - 0x0, 0x14, 0x14, 0xa, + 0x0A, // Width: 10 + 0x0D, // Height: 13 + 0x01, // First char: 1 + 0x02, // Number of chars: 2 + // Jump Table: + 0x00, 0x00, 0x13, 0x0A, // 1 + 0x00, 0x13, 0x14, 0x0A, // 2 // Font Data: - 0x80,0x1f,0x80,0x10,0x80,0x1f,0x80,0x10,0x80,0x1f,0x80,0x10,0x80,0x1f,0x80,0x10,0x80,0x1f,0x0,0x6, - 0x0,0x60,0x0,0x5c,0x80,0x43,0x60,0x40,0x98,0x57,0x98,0x57,0x60,0x40,0x80,0x43,0x0,0x5c,0x0,0x60, + 0xF0, 0x03, 0x10, 0x02, 0xF0, 0x03, 0x10, 0x02, 0xF0, 0x03, 0x10, 0x02, 0xF0, 0x03, 0x10, 0x02, 0xF0, 0x03, 0xC0, // 1 + 0x00, 0x0C, 0x80, 0x0B, 0x70, 0x08, 0x0C, 0x08, 0xF3, 0x0A, 0xF3, 0x0A, 0x0C, 0x08, 0x70, 0x08, 0x80, 0x0B, 0x00, 0x0C, // 2 }; </textarea></td> </tr> @@ -155,8 +155,7 @@ const char My_Font[] PROGMEM = { constructor() { this.height = parseInt(document.getElementById('height').value); this.width = parseInt(document.getElementById('width').value); - let firstCharCode = parseInt(document.getElementById('code').value); - this.currentCharCode = firstCharCode; + this.currentCharCode = parseInt(document.getElementById('code').value); this.fontContainer = document.getElementById('chars'); this.bytesForHeight = (1 + ((this.height - 1) >> 3)); // number of bytes needed for this font height document.body.className = "started"; @@ -184,7 +183,7 @@ const char My_Font[] PROGMEM = { // If data is provided, decode it to pixel initialization friendly structure let pixelInit = []; if (charData && charData.length) { - // charData byte count needs to be a multiple of bytesForHeight. End bytes with value 0 may have been stripped + // charData byte count needs to be a multiple of bytesForHeight. End bytes with value 0 may have been trimmed let missingBytes = charData.length % this.bytesForHeight; for(let b = 0; b < missingBytes ; b++) { charData.push(0); @@ -204,8 +203,8 @@ const char My_Font[] PROGMEM = { mask = mask >> 1; } } - pixelRow.splice(this.height +1); - // Font.output('data', pixelRow); + pixelRow.splice(0, pixelRow.length - this.height); + //Font.output('data', pixelRow); pixelInit.push(pixelRow.reverse()); } } @@ -290,17 +289,16 @@ const char My_Font[] PROGMEM = { let pixelState = rows[r].children[col].className; bits += (pixelState === 'on' ? '1': '0'); } - // Need to complete missing bits to have a sizeof byte multiple number of bits for(let b = 0; b < bits2add; b++) { - bits += '0'; + bits = '0' + bits; } // Font.output('data', ` // ${bits}`); // Debugging help: rotated bitmap // read bytes from the end for(let b = bits.length - 1; b >= 7; b -= 8) { - //Font.output('data', ` // ${bits.substring(b-7, b)}`); // Debugging help: rotated bitmap - let byte = parseInt(bits.substring(b-8, b), 2); + //Font.output('data', ` // ${bits.substr(b-7, 8)}`); // Debugging help: rotated bitmap + let byte = parseInt(bits.substr(b-7, 8), 2); if (byte != 0) { notZero = true; } -- GitLab