Add scaling text size

- Closes #2
This commit is contained in:
Pk11 2022-10-04 08:57:41 -05:00
parent 95639581db
commit 0f0d8e39ed
2 changed files with 25 additions and 10 deletions

View File

@ -53,6 +53,8 @@ show_version: true
<br> <br>
Background image: Background image:
<input class="form-control" id="bgImage" placeholder="https://example.test/background.png" onchange="setBg(this.value)"> <input class="form-control" id="bgImage" placeholder="https://example.test/background.png" onchange="setBg(this.value)">
Scale:
<input class="form-control" id="previewScale" type="number" min="1" max="8" value="1" onchange="setScale(this.value)">
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<h3>Palette colors:</h3> <h3>Palette colors:</h3>

View File

@ -3,7 +3,7 @@ let maxChar = 0;
let palette = [[0xFF, 0xFF, 0xFF, 0x00], [0x92, 0x92, 0x92, 0xFF], [0x43, 0x43, 0x43, 0xFF], [0x00, 0x00, 0x00, 0xFF]]; let palette = [[0xFF, 0xFF, 0xFF, 0x00], [0x92, 0x92, 0x92, 0xFF], [0x43, 0x43, 0x43, 0xFF], [0x00, 0x00, 0x00, 0xFF]];
let paletteHTML = ["", "#929292", "#434343", "#000000"]; let paletteHTML = ["", "#929292", "#434343", "#000000"];
let data, fontU8, fileName; let data, fontU8, fileName;
let brushColor = 0, realColor = 0, extraKerning = 0; let brushColor = 0, realColor = 0, extraKerning = 0, scale = 1;
var onkeydown, onkeyup; var onkeydown, onkeyup;
@ -217,7 +217,7 @@ function updateBitmap() {
x = 0; x = 0;
continue; continue;
} }
let imgData = ctx.createImageData(tileWidth, tileHeight); let imgData = ctx.createImageData(tileWidth * scale, tileHeight * scale);
let t = getCharIndex(c); let t = getCharIndex(c);
let charImg = new Array(tileHeight * tileWidth); let charImg = new Array(tileHeight * tileWidth);
@ -227,19 +227,27 @@ function updateBitmap() {
} }
} }
for(let i = 0; i < imgData.data.length / 4; i++) { for(let y = 0; y < tileHeight; y++) {
imgData.data[i * 4] = palette[charImg[i]][0]; for(let x = 0; x < tileWidth; x++) {
imgData.data[i * 4 + 1] = palette[charImg[i]][1]; let sPos = y * tileWidth + x;
imgData.data[i * 4 + 2] = palette[charImg[i]][2]; for(let i = 0; i < scale; i++) {
imgData.data[i * 4 + 3] = palette[charImg[i]][3]; let dPos = (y * scale + i) * (tileWidth * scale) + x * scale;
for(let j = 0; j < scale; j++) {
imgData.data[(dPos + j) * 4] = palette[charImg[sPos]][0];
imgData.data[(dPos + j) * 4 + 1] = palette[charImg[sPos]][1];
imgData.data[(dPos + j) * 4 + 2] = palette[charImg[sPos]][2];
imgData.data[(dPos + j) * 4 + 3] = palette[charImg[sPos]][3];
}
}
}
} }
let width = (bytesPerWidth == 3 ? fontWidths[t][2] : fontWidths[t][0] + fontWidths[t][1]) + extraKerning; let width = ((bytesPerWidth == 3 ? fontWidths[t][2] : fontWidths[t][0] + fontWidths[t][1]) + extraKerning) * scale;
if(x + width > canvas.width) { if(x + width > canvas.width) {
y += tileHeight; y += tileHeight * scale;
x = 0; x = 0;
} }
ctx.putImageData(imgData, x + fontWidths[t][0], y); ctx.putImageData(imgData, x + fontWidths[t][0] * scale, y);
x += width; x += width;
} }
} }
@ -1314,3 +1322,8 @@ function setBg(value) {
document.getElementById("bgColor").style.backgroundColor = "" document.getElementById("bgColor").style.backgroundColor = ""
} }
} }
function setScale(value) {
scale = value | 0;
updateBitmap();
}