Skip to content

Commit eaafa0c

Browse files
authored
Update glyphEditor.html to support reducing width/height, shift all (#384)
1 parent 41505aa commit eaafa0c

File tree

1 file changed

+81
-26
lines changed

1 file changed

+81
-26
lines changed

resources/glyphEditor.html

+81-26
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,23 @@
124124
<tr>
125125
<td>Height:</td><td><input placeholder="Font height" type="number" id="height" value="13" max="64"/></td>
126126
</tr>
127+
<tr>
128+
<td>NewWidth:</td><td><input placeholder="New Font width" type="number" id="newwidth" value="0"/></td>
129+
</tr>
130+
<tr>
131+
<td>NewHeight:</td><td><input placeholder="New Font height" type="number" id="newheight" value="0" max="64"/></td>
132+
</tr>
127133
<tr>
128134
<td colspan="3"> </td> <!--slightly improves layout-->
129135
</tr>
130136
<tr>
131137
<td colspan="2">
132138
<button id="create">Create</button>
133-
<button id="shiftUp">Shift all up</button>
139+
<br/>Shift all
140+
<button id="shiftUp">Up</button>
141+
<button id="shiftDown">Down</button>
142+
<button id="shiftLeft">Left</button>
143+
<button id="shiftRight">Right</button><br/>
134144
<button id="generate">Generate</button>
135145
<button id="savetoFile">Save To File</button>
136146
</td>
@@ -294,6 +304,16 @@
294304
// generates the jump table and font data
295305
generate() {
296306
// this.width -= 3; // hack to narrow an existing font
307+
var newheight = parseInt(document.getElementById('newheight').value);
308+
if(newheight){
309+
this.height = newheight;
310+
this.bytesForHeight = (1 + ((this.height - 1) >> 3));
311+
}
312+
var newwidth = parseInt(document.getElementById('newwidth').value);
313+
if(newwidth){
314+
this.width = newwidth;
315+
}
316+
297317
Font.emptyOutput();
298318
let chars = this.fontContainer.getElementsByTagName('table');
299319
let firstCharCode = parseInt(document.getElementById('code').value);
@@ -319,7 +339,9 @@
319339
// Browse each row starting from the bottom one, going up, and accumulate pixels in
320340
// a string: this rotates the glyph
321341
// Beware, row 0 is table headers.
322-
for(let r = rows.length-1; r >=1 ; r--) {
342+
//for(let r = rows.length-1; r >=1 ; r--) {
343+
344+
for(let r = this.height; r >=1 ; r--) {
323345
let pixelState = rows[r].children[col].className;
324346
bits += (pixelState === 'on' ? '1': '0');
325347
}
@@ -410,6 +432,28 @@
410432
}
411433
});
412434

435+
document.getElementById('shiftDown').addEventListener('click', function() {
436+
var chars = document.getElementById("chars");
437+
var tables = chars.getElementsByTagName("table");
438+
for(var i=0; i< tables.length; i++) {
439+
shiftDown(tables[i]);
440+
}
441+
});
442+
document.getElementById('shiftLeft').addEventListener('click', function() {
443+
var chars = document.getElementById("chars");
444+
var tables = chars.getElementsByTagName("table");
445+
for(var i=0; i< tables.length; i++) {
446+
shiftLeft(tables[i]);
447+
}
448+
});
449+
document.getElementById('shiftRight').addEventListener('click', function() {
450+
var chars = document.getElementById("chars");
451+
var tables = chars.getElementsByTagName("table");
452+
for(var i=0; i< tables.length; i++) {
453+
shiftRight(tables[i]);
454+
}
455+
});
456+
413457
document.getElementById('generate').addEventListener('click', function() {
414458
font.generate();
415459
});
@@ -454,38 +498,18 @@
454498

455499
// Shift pixels to the left
456500
case 'left':
457-
pixels = currentContainer.getElementsByTagName('td');
458-
for(p = 0; p < pixels.length; p++) {
459-
if((p + 1) % font.width) {
460-
pixels[p].className = pixels[p + 1].className;
461-
} else {
462-
pixels[p].className = '';
463-
}
464-
}
501+
shiftLeft(currentContainer);
465502
break;
466503

467504
// Shift pixels to the right
468505
case 'right':
469-
pixels = currentContainer.getElementsByTagName('td');
470-
for(p = pixels.length-1; p >=0 ; p--) {
471-
if(p % font.width) {
472-
pixels[p].className = pixels[p - 1].className;
473-
} else {
474-
pixels[p].className = '';
475-
}
476-
}
506+
shiftRight(currentContainer);
477507
break;
478508

479509
// Shift pixels down
480510
case 'down':
481-
pixels = currentContainer.getElementsByTagName('td');
482-
for(p = pixels.length-1; p >=0 ; p--) {
483-
if(p >= font.width) {
484-
pixels[p].className = pixels[p - font.width].className;
485-
} else {
486-
pixels[p].className = '';
487-
}
488-
} break;
511+
shiftDown(currentContainer);
512+
break;
489513

490514
// Shift pixels up
491515
case 'up':
@@ -532,6 +556,37 @@
532556
}
533557
}
534558
}
559+
function shiftDown(container) {
560+
var pixels = container.getElementsByTagName('td');
561+
for(p = pixels.length-1; p >=0 ; p--) {
562+
if(p >= font.width) {
563+
pixels[p].className = pixels[p - font.width].className;
564+
} else {
565+
pixels[p].className = '';
566+
}
567+
}
568+
}
569+
function shiftLeft(container) {
570+
var pixels = container.getElementsByTagName('td');
571+
for(p = 0; p < pixels.length; p++) {
572+
if((p + 1) % font.width) {
573+
pixels[p].className = pixels[p + 1].className;
574+
} else {
575+
pixels[p].className = '';
576+
}
577+
}
578+
}
579+
580+
function shiftRight(container) {
581+
var pixels = container.getElementsByTagName('td');
582+
for(p = pixels.length-1; p >=0 ; p--) {
583+
if(p % font.width) {
584+
pixels[p].className = pixels[p - 1].className;
585+
} else {
586+
pixels[p].className = '';
587+
}
588+
}
589+
}
535590

536591
document.getElementById('chars').addEventListener('mouseover', function(e) {
537592
let target = e.target;

0 commit comments

Comments
 (0)