Add fallback font and missing libs for .png generation

If Verdana.ttf can't be loaded, the font file pointed by the
FALLBACK_FONT_PATH environment variable will be loaded.

This fixes width computation errors that can occur with non-latin
characters when running with Docker.
This commit is contained in:
Christophe Bliard
2017-08-08 10:33:26 +02:00
committed by Paul Melnikow
parent c7b782b014
commit cafb66bd93
2 changed files with 9 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
FROM node:6.9.2-alpine
RUN apk add --update gettext
RUN apk add --no-cache gettext imagemagick librsvg ttf-dejavu
ENV FALLBACK_FONT_PATH /usr/share/fonts/ttf-dejavu/DejaVuSans.ttf
RUN mkdir -p /usr/src/app
RUN mkdir /usr/src/app/private
@@ -9,7 +10,8 @@ WORKDIR /usr/src/app
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
COPY package.json /usr/src/app/
RUN npm install
RUN npm install && \
rm -rf /tmp/npm-* /root/.npm
COPY . /usr/src/app
CMD envsubst < secret.tpl.json > ./private/secret.json && npm start

View File

@@ -16,7 +16,11 @@ function loadFont(path, callback) {
}
}
loadFont(path.join(__dirname, '..', 'Verdana.ttf'));
loadFont(path.join(__dirname, '..', 'Verdana.ttf'), function (err) {
if (err && process.env.FALLBACK_FONT_PATH) {
loadFont(process.env.FALLBACK_FONT_PATH);
}
});
doc = doc.fontSize(11);
function measure(str) {