2018-09-04 12:12:41 +02:00
|
|
|
package it.cavallium.warppi.gui.graphicengine.html;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.teavm.jso.browser.Window;
|
|
|
|
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
|
|
|
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
|
|
|
import org.teavm.jso.dom.html.HTMLDocument;
|
|
|
|
|
|
|
|
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
2018-09-22 10:29:40 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.impl.common.RFTFont;
|
2018-09-04 12:12:41 +02:00
|
|
|
|
|
|
|
public class HtmlFont extends RFTFont {
|
|
|
|
|
|
|
|
public HTMLCanvasElement imgEl;
|
|
|
|
public CanvasRenderingContext2D imgElCtx;
|
2018-09-22 11:17:30 +02:00
|
|
|
|
|
|
|
public HtmlFont(final String fontName) throws IOException {
|
2018-09-04 12:12:41 +02:00
|
|
|
super(fontName);
|
2018-09-22 11:17:30 +02:00
|
|
|
final HTMLDocument doc = Window.current().getDocument();
|
2018-09-04 12:12:41 +02:00
|
|
|
imgEl = doc.createElement("canvas").cast();
|
|
|
|
imgEl.setClassName("hidden");
|
|
|
|
doc.getBody().appendChild(imgEl);
|
|
|
|
imgElCtx = imgEl.getContext("2d").cast();
|
2018-09-22 11:17:30 +02:00
|
|
|
imgEl.setWidth(charW);
|
|
|
|
imgEl.setHeight(charH * intervalsTotalSize);
|
2018-09-04 12:12:41 +02:00
|
|
|
|
|
|
|
int currentInt;
|
|
|
|
int currentIntBitPosition;
|
|
|
|
int bitData;
|
|
|
|
imgElCtx.clearRect(0, 0, imgEl.getWidth(), imgEl.getHeight());
|
|
|
|
imgElCtx.setFillStyle("#000");
|
2018-09-22 11:17:30 +02:00
|
|
|
final int minBound = 0, maxBound = intervalsTotalSize - 1;
|
|
|
|
for (int charIndex = minBound; charIndex < maxBound; charIndex++)
|
|
|
|
for (int dy = 0; dy < charH; dy++)
|
2018-09-04 12:12:41 +02:00
|
|
|
for (int dx = 0; dx < charW; dx++) {
|
|
|
|
final int bit = dx + dy * charW;
|
2018-09-22 11:17:30 +02:00
|
|
|
currentInt = (int) (Math.floor(bit) / RFTFont.intBits);
|
|
|
|
currentIntBitPosition = bit - currentInt * RFTFont.intBits;
|
2018-09-04 12:12:41 +02:00
|
|
|
final int charIdx = charIndex * charIntCount + currentInt;
|
|
|
|
if (charIdx >= 0 && charIdx < chars32.length) {
|
2018-09-22 11:17:30 +02:00
|
|
|
bitData = chars32[charIdx] >> currentIntBitPosition & 1;
|
|
|
|
if (bitData == 1)
|
|
|
|
imgElCtx.fillRect(dx, charIndex * charH + dy, 1, 1);
|
2018-09-04 12:12:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-22 11:17:30 +02:00
|
|
|
|
2018-09-04 12:12:41 +02:00
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void use(final GraphicEngine d) {
|
|
|
|
if (d.getRenderer() instanceof HtmlRenderer)
|
2018-09-04 12:12:41 +02:00
|
|
|
((HtmlRenderer) d.getRenderer()).f = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|