From c11a41004b3cc6f133aa41426c73cbabbbe9e201 Mon Sep 17 00:00:00 2001 From: htmltiger <1429451+htmltiger@users.noreply.github.com> Date: Sun, 30 Apr 2023 20:56:10 +0100 Subject: [PATCH] Update glyphEditor.html to support reducing width/height, shift all --- resources/glyphEditor.html | 107 ++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 26 deletions(-) diff --git a/resources/glyphEditor.html b/resources/glyphEditor.html index 31fbd90..f7d0651 100644 --- a/resources/glyphEditor.html +++ b/resources/glyphEditor.html @@ -124,13 +124,23 @@ Height: + + NewWidth: + + + NewHeight: + - +
Shift all + + + +
@@ -294,6 +304,16 @@ // generates the jump table and font data generate() { // this.width -= 3; // hack to narrow an existing font + var newheight = parseInt(document.getElementById('newheight').value); + if(newheight){ + this.height = newheight; + this.bytesForHeight = (1 + ((this.height - 1) >> 3)); + } + var newwidth = parseInt(document.getElementById('newwidth').value); + if(newwidth){ + this.width = newwidth; + } + Font.emptyOutput(); let chars = this.fontContainer.getElementsByTagName('table'); let firstCharCode = parseInt(document.getElementById('code').value); @@ -319,7 +339,9 @@ // Browse each row starting from the bottom one, going up, and accumulate pixels in // a string: this rotates the glyph // Beware, row 0 is table headers. - for(let r = rows.length-1; r >=1 ; r--) { + //for(let r = rows.length-1; r >=1 ; r--) { + + for(let r = this.height; r >=1 ; r--) { let pixelState = rows[r].children[col].className; bits += (pixelState === 'on' ? '1': '0'); } @@ -410,6 +432,28 @@ } }); + document.getElementById('shiftDown').addEventListener('click', function() { + var chars = document.getElementById("chars"); + var tables = chars.getElementsByTagName("table"); + for(var i=0; i< tables.length; i++) { + shiftDown(tables[i]); + } + }); + document.getElementById('shiftLeft').addEventListener('click', function() { + var chars = document.getElementById("chars"); + var tables = chars.getElementsByTagName("table"); + for(var i=0; i< tables.length; i++) { + shiftLeft(tables[i]); + } + }); + document.getElementById('shiftRight').addEventListener('click', function() { + var chars = document.getElementById("chars"); + var tables = chars.getElementsByTagName("table"); + for(var i=0; i< tables.length; i++) { + shiftRight(tables[i]); + } + }); + document.getElementById('generate').addEventListener('click', function() { font.generate(); }); @@ -454,38 +498,18 @@ // Shift pixels to the left case 'left': - pixels = currentContainer.getElementsByTagName('td'); - for(p = 0; p < pixels.length; p++) { - if((p + 1) % font.width) { - pixels[p].className = pixels[p + 1].className; - } else { - pixels[p].className = ''; - } - } + shiftLeft(currentContainer); break; // Shift pixels to the right case 'right': - pixels = currentContainer.getElementsByTagName('td'); - for(p = pixels.length-1; p >=0 ; p--) { - if(p % font.width) { - pixels[p].className = pixels[p - 1].className; - } else { - pixels[p].className = ''; - } - } + shiftRight(currentContainer); break; // Shift pixels down case 'down': - pixels = currentContainer.getElementsByTagName('td'); - for(p = pixels.length-1; p >=0 ; p--) { - if(p >= font.width) { - pixels[p].className = pixels[p - font.width].className; - } else { - pixels[p].className = ''; - } - } break; + shiftDown(currentContainer); + break; // Shift pixels up case 'up': @@ -532,6 +556,37 @@ } } } + function shiftDown(container) { + var pixels = container.getElementsByTagName('td'); + for(p = pixels.length-1; p >=0 ; p--) { + if(p >= font.width) { + pixels[p].className = pixels[p - font.width].className; + } else { + pixels[p].className = ''; + } + } + } + function shiftLeft(container) { + var pixels = container.getElementsByTagName('td'); + for(p = 0; p < pixels.length; p++) { + if((p + 1) % font.width) { + pixels[p].className = pixels[p + 1].className; + } else { + pixels[p].className = ''; + } + } + } + + function shiftRight(container) { + var pixels = container.getElementsByTagName('td'); + for(p = pixels.length-1; p >=0 ; p--) { + if(p % font.width) { + pixels[p].className = pixels[p - 1].className; + } else { + pixels[p].className = ''; + } + } + } document.getElementById('chars').addEventListener('mouseover', function(e) { let target = e.target;