Allow custom font directory via environment variables when running as server
This commit is contained in:
parent
51ad974ba5
commit
724f11cfcb
|
@ -10258,13 +10258,15 @@
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const opentype = require('opentype.js');
|
const opentype = require('opentype.js');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const FONTDIR = process.env.FONTDIR || './fonts/';
|
||||||
const FONTS = new Map();
|
const FONTS = new Map();
|
||||||
|
|
||||||
function loadFont(path) {
|
function loadFont(relativePath) {
|
||||||
// Must be synchronous so that measurements are ready once startup completes
|
// Must be synchronous so that measurements are ready once startup completes
|
||||||
/* eslint-disable no-sync */
|
/* eslint-disable no-sync */
|
||||||
const data = fs.readFileSync(path);
|
const data = fs.readFileSync(path.join(FONTDIR, relativePath));
|
||||||
/* eslint-enable no-sync */
|
/* eslint-enable no-sync */
|
||||||
return opentype.parse(data.buffer);
|
return opentype.parse(data.buffer);
|
||||||
}
|
}
|
||||||
|
@ -10282,19 +10284,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
addFont('sans-serif', {
|
addFont('sans-serif', {
|
||||||
'': 'fonts/liberation-fonts/LiberationSans-Regular.ttf',
|
'': 'liberation-fonts/LiberationSans-Regular.ttf',
|
||||||
'bold': 'fonts/liberation-fonts/LiberationSans-Bold.ttf',
|
'bold': 'liberation-fonts/LiberationSans-Bold.ttf',
|
||||||
'bold-italic': 'fonts/liberation-fonts/LiberationSans-BoldItalic.ttf',
|
'bold-italic': 'liberation-fonts/LiberationSans-BoldItalic.ttf',
|
||||||
'italic': 'fonts/liberation-fonts/LiberationSans-Italic.ttf',
|
'italic': 'liberation-fonts/LiberationSans-Italic.ttf',
|
||||||
});
|
});
|
||||||
addFont('monospace', {
|
addFont('monospace', {
|
||||||
'': 'fonts/liberation-fonts/LiberationMono-Regular.ttf',
|
'': 'liberation-fonts/LiberationMono-Regular.ttf',
|
||||||
'bold': 'fonts/liberation-fonts/LiberationMono-Bold.ttf',
|
'bold': 'liberation-fonts/LiberationMono-Bold.ttf',
|
||||||
'bold-italic': 'fonts/liberation-fonts/LiberationMono-BoldItalic.ttf',
|
'bold-italic': 'liberation-fonts/LiberationMono-BoldItalic.ttf',
|
||||||
'italic': 'fonts/liberation-fonts/LiberationMono-Italic.ttf',
|
'italic': 'liberation-fonts/LiberationMono-Italic.ttf',
|
||||||
});
|
});
|
||||||
addFont('handlee', {
|
addFont('handlee', {
|
||||||
'': 'fonts/handlee/Handlee.ttf',
|
'': 'handlee/Handlee.ttf',
|
||||||
});
|
});
|
||||||
|
|
||||||
const DEFAULT_FONT = 'sans-serif';
|
const DEFAULT_FONT = 'sans-serif';
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const opentype = require('opentype.js');
|
const opentype = require('opentype.js');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const FONTDIR = process.env.FONTDIR || './fonts/';
|
||||||
const FONTS = new Map();
|
const FONTS = new Map();
|
||||||
|
|
||||||
function loadFont(path) {
|
function loadFont(relativePath) {
|
||||||
// Must be synchronous so that measurements are ready once startup completes
|
// Must be synchronous so that measurements are ready once startup completes
|
||||||
/* eslint-disable no-sync */
|
/* eslint-disable no-sync */
|
||||||
const data = fs.readFileSync(path);
|
const data = fs.readFileSync(path.join(FONTDIR, relativePath));
|
||||||
/* eslint-enable no-sync */
|
/* eslint-enable no-sync */
|
||||||
return opentype.parse(data.buffer);
|
return opentype.parse(data.buffer);
|
||||||
}
|
}
|
||||||
|
@ -24,19 +26,19 @@ function addFont(name, variants) {
|
||||||
}
|
}
|
||||||
|
|
||||||
addFont('sans-serif', {
|
addFont('sans-serif', {
|
||||||
'': 'fonts/liberation-fonts/LiberationSans-Regular.ttf',
|
'': 'liberation-fonts/LiberationSans-Regular.ttf',
|
||||||
'bold': 'fonts/liberation-fonts/LiberationSans-Bold.ttf',
|
'bold': 'liberation-fonts/LiberationSans-Bold.ttf',
|
||||||
'bold-italic': 'fonts/liberation-fonts/LiberationSans-BoldItalic.ttf',
|
'bold-italic': 'liberation-fonts/LiberationSans-BoldItalic.ttf',
|
||||||
'italic': 'fonts/liberation-fonts/LiberationSans-Italic.ttf',
|
'italic': 'liberation-fonts/LiberationSans-Italic.ttf',
|
||||||
});
|
});
|
||||||
addFont('monospace', {
|
addFont('monospace', {
|
||||||
'': 'fonts/liberation-fonts/LiberationMono-Regular.ttf',
|
'': 'liberation-fonts/LiberationMono-Regular.ttf',
|
||||||
'bold': 'fonts/liberation-fonts/LiberationMono-Bold.ttf',
|
'bold': 'liberation-fonts/LiberationMono-Bold.ttf',
|
||||||
'bold-italic': 'fonts/liberation-fonts/LiberationMono-BoldItalic.ttf',
|
'bold-italic': 'liberation-fonts/LiberationMono-BoldItalic.ttf',
|
||||||
'italic': 'fonts/liberation-fonts/LiberationMono-Italic.ttf',
|
'italic': 'liberation-fonts/LiberationMono-Italic.ttf',
|
||||||
});
|
});
|
||||||
addFont('handlee', {
|
addFont('handlee', {
|
||||||
'': 'fonts/handlee/Handlee.ttf',
|
'': 'handlee/Handlee.ttf',
|
||||||
});
|
});
|
||||||
|
|
||||||
const DEFAULT_FONT = 'sans-serif';
|
const DEFAULT_FONT = 'sans-serif';
|
||||||
|
|
|
@ -158,7 +158,7 @@ module.exports = {
|
||||||
'no-octal-escape': ['error'],
|
'no-octal-escape': ['error'],
|
||||||
'no-param-reassign': ['error'],
|
'no-param-reassign': ['error'],
|
||||||
'no-path-concat': ['error'],
|
'no-path-concat': ['error'],
|
||||||
'no-process-env': ['error'],
|
'no-process-env': ['off'],
|
||||||
'no-process-exit': ['error'],
|
'no-process-exit': ['error'],
|
||||||
'no-proto': ['error'],
|
'no-proto': ['error'],
|
||||||
'no-prototype-builtins': ['error'],
|
'no-prototype-builtins': ['error'],
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
/* eslint-disable no-process-env */ // Configuration section
|
|
||||||
const manual = Boolean(process.env.MANUAL);
|
const manual = Boolean(process.env.MANUAL);
|
||||||
/* eslint-enable no-process-env */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Firefox is supported, but tests will fail until version 60 is out
|
* Firefox is supported, but tests will fail until version 60 is out
|
||||||
|
|
Loading…
Reference in New Issue