Fix roboto mono font
This commit is contained in:
parent
c97baa6fdf
commit
ba0618de0d
@ -133,11 +133,12 @@ class AddTextToImage extends Operation {
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error loading image. (${err})`);
|
||||
}
|
||||
try {
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage("Adding text to image...");
|
||||
|
||||
const fontsMap = {};
|
||||
if (isWorkerEnvironment())
|
||||
self.sendStatusMessage("Adding text to image...");
|
||||
|
||||
const fontsMap = {};
|
||||
try {
|
||||
const fonts = [
|
||||
import(
|
||||
/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.fnt"
|
||||
@ -159,7 +160,6 @@ class AddTextToImage extends Operation {
|
||||
fontsMap["Roboto Mono"] = fonts[2];
|
||||
fontsMap["Roboto Slab"] = fonts[3];
|
||||
});
|
||||
|
||||
// Make Webpack load the png font images
|
||||
await Promise.all([
|
||||
import(
|
||||
@ -175,11 +175,16 @@ class AddTextToImage extends Operation {
|
||||
/* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoBlack72White.png"
|
||||
),
|
||||
]);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error preparing fonts. (${err})`);
|
||||
}
|
||||
|
||||
let jimpFont;
|
||||
try {
|
||||
const font = fontsMap[fontFace];
|
||||
|
||||
// LoadFont needs an absolute url, so append the font name to self.docURL
|
||||
const jimpFont = await loadFont(self.docURL + "/" + font.default);
|
||||
jimpFont = await loadFont(self.docURL + "/" + font.default);
|
||||
|
||||
jimpFont.pages.forEach(function (page) {
|
||||
if (page.bitmap) {
|
||||
@ -210,7 +215,11 @@ class AddTextToImage extends Operation {
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error loading font. (${err})`);
|
||||
}
|
||||
|
||||
try {
|
||||
// Create a temporary image to hold the rendered text
|
||||
const textImage = new Jimp({
|
||||
width: measureText(jimpFont, text),
|
||||
@ -271,7 +280,11 @@ class AddTextToImage extends Operation {
|
||||
x: xPos,
|
||||
y: yPos,
|
||||
});
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error adding text to image. (${err})`);
|
||||
}
|
||||
|
||||
try {
|
||||
let imageBuffer;
|
||||
if (image.mime === "image/gif") {
|
||||
imageBuffer = await image.getBuffer(JimpMime.png);
|
||||
@ -280,7 +293,7 @@ class AddTextToImage extends Operation {
|
||||
}
|
||||
return imageBuffer.buffer;
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error adding text to image. (${err})`);
|
||||
throw new OperationError(`Error exporting image. (${err})`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -104,6 +104,7 @@
|
||||
<char id="126" x="454" y="319" width="42" height="16" xoffset="1" yoffset="47" xadvance="44" page="0" chnl="0" />
|
||||
<char id="127" x="0" y="0" width="45" height="99" xoffset="-1" yoffset="-2" xadvance="43" page="0" chnl="0" />
|
||||
</chars>
|
||||
<kernings count="0">
|
||||
<kernings count="1">
|
||||
<kerning first="0" second="0" amount="0" />
|
||||
</kernings>
|
||||
</font>
|
||||
|
||||
@ -34,7 +34,10 @@ module.exports = {
|
||||
testOp(browser, "AES Encrypt", "test input", "e42eb8fbfb7a98fff061cd2c1a794d92", [{"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Raw", "Hex"]);
|
||||
testOp(browser, "AND", "test input", "4$04 $044", [{ "option": "Hex", "string": "34" }]);
|
||||
testOp(browser, "Add line numbers", "test input", "1 test input");
|
||||
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16], []]);
|
||||
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16, "Roboto"], []]);
|
||||
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16, "Roboto Black"], []]);
|
||||
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16, "Roboto Mono"], []]);
|
||||
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16, "Roboto Slab"], []]);
|
||||
testOp(browser, ["From Hex", "Dither Image", "SHA2"], Images.PNG_HEX, "cbf587a78915cfb14546ba83080b13e5054800802488dd0cb786b8951e7dc0b48f055260917bd0ccfc075e422b9d6aff112948562653995d74e70f0b66367ac3", [[], [], []]);
|
||||
testOp(browser, ["From Hex", "Generate Image", "SHA2"], Images.PNG_HEX, "2c451762a6c9192fd31dc80765eab3f447be70ea51f6fdb6911ade4d89d4a98bd0a1ff00b08d76aac472faeceb54b66092e3f3be7bbf899bf3e55ca9c96a56aa", [[], [], []]);
|
||||
testOp(browser, ["From Hex", "Image Hue/Saturation/Lightness", "SHA2"], Images.PNG_HEX, "522dfc0bbef00e05c5d6861a002039fa2952e4bbb7fe8d21d0d538ef6f9d65da82065929b4150dc5b8b49460ee6c9bef7f660b86f8d4e7442a07c61c0a152a4b", [[], [50, 50, 50], []]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user