2
0
mirror of https://github.com/gchq/CyberChef synced 2026-02-28 02:23:17 +00:00

Fix Roboto Mono font (#2199)

This commit is contained in:
GCHQ Developer 85297
2026-02-20 16:10:15 +00:00
committed by GitHub
parent 8df8028f43
commit d71dad8568
4 changed files with 26 additions and 15 deletions

View File

@@ -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})`);
}
}

View File

@@ -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>