|
|
@ -123,6 +123,17 @@ module.exports.woff2ServerPlugin = (options = {}) => {
|
|
|
|
"./assets/NotoEmoji-Regular-2048.ttf",
|
|
|
|
"./assets/NotoEmoji-Regular-2048.ttf",
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const liberationPath = path.resolve(
|
|
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
|
|
"./assets/LiberationSans-Regular.ttf",
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// need to use the same em size as built-in fonts, otherwise pyftmerge throws (modified manually with font forge)
|
|
|
|
|
|
|
|
const liberationPath_2048 = path.resolve(
|
|
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
|
|
"./assets/LiberationSans-Regular-2048.ttf",
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const xiaolaiFont = Font.create(fs.readFileSync(xiaolaiPath), {
|
|
|
|
const xiaolaiFont = Font.create(fs.readFileSync(xiaolaiPath), {
|
|
|
|
type: "ttf",
|
|
|
|
type: "ttf",
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -130,6 +141,10 @@ module.exports.woff2ServerPlugin = (options = {}) => {
|
|
|
|
type: "ttf",
|
|
|
|
type: "ttf",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const liberationFont = Font.create(fs.readFileSync(liberationPath), {
|
|
|
|
|
|
|
|
type: "ttf",
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const sortedFonts = Array.from(fonts.entries()).sort(
|
|
|
|
const sortedFonts = Array.from(fonts.entries()).sort(
|
|
|
|
([family1], [family2]) => (family1 > family2 ? 1 : -1),
|
|
|
|
([family1], [family2]) => (family1 > family2 ? 1 : -1),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -141,13 +156,6 @@ module.exports.woff2ServerPlugin = (options = {}) => {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fallbackFontsPaths = [];
|
|
|
|
|
|
|
|
const shouldIncludeXiaolaiFallback = family.includes("Excalifont");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldIncludeXiaolaiFallback) {
|
|
|
|
|
|
|
|
fallbackFontsPaths.push(xiaolaiPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const baseFont = Regular[0];
|
|
|
|
const baseFont = Regular[0];
|
|
|
|
const tempPaths = Regular.map((_, index) =>
|
|
|
|
const tempPaths = Regular.map((_, index) =>
|
|
|
|
path.resolve(outputDir, `temp_${family}_${index}.ttf`),
|
|
|
|
path.resolve(outputDir, `temp_${family}_${index}.ttf`),
|
|
|
@ -165,10 +173,18 @@ module.exports.woff2ServerPlugin = (options = {}) => {
|
|
|
|
|
|
|
|
|
|
|
|
const mergedFontPath = path.resolve(outputDir, `${family}.ttf`);
|
|
|
|
const mergedFontPath = path.resolve(outputDir, `${family}.ttf`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fallbackFontsPaths = [];
|
|
|
|
|
|
|
|
const shouldIncludeXiaolaiFallback = family.includes("Excalifont");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldIncludeXiaolaiFallback) {
|
|
|
|
|
|
|
|
fallbackFontsPaths.push(xiaolaiPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add liberation as fallback to all fonts, so that unknown characters are rendered similarly to how browser renders them (Helvetica, Arial, etc.)
|
|
|
|
if (baseFont.data.head.unitsPerEm === 2048) {
|
|
|
|
if (baseFont.data.head.unitsPerEm === 2048) {
|
|
|
|
fallbackFontsPaths.push(emojiPath_2048);
|
|
|
|
fallbackFontsPaths.push(emojiPath_2048, liberationPath_2048);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
fallbackFontsPaths.push(emojiPath);
|
|
|
|
fallbackFontsPaths.push(emojiPath, liberationPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// drop Vertical related metrics, otherwise it does not allow us to merge the fonts
|
|
|
|
// drop Vertical related metrics, otherwise it does not allow us to merge the fonts
|
|
|
@ -196,10 +212,12 @@ module.exports.woff2ServerPlugin = (options = {}) => {
|
|
|
|
const base = baseFont.data.name[field];
|
|
|
|
const base = baseFont.data.name[field];
|
|
|
|
const xiaolai = xiaolaiFont.data.name[field];
|
|
|
|
const xiaolai = xiaolaiFont.data.name[field];
|
|
|
|
const emoji = emojiFont.data.name[field];
|
|
|
|
const emoji = emojiFont.data.name[field];
|
|
|
|
|
|
|
|
const liberation = liberationFont.data.name[field];
|
|
|
|
|
|
|
|
// liberation font
|
|
|
|
|
|
|
|
|
|
|
|
return shouldIncludeXiaolaiFallback
|
|
|
|
return shouldIncludeXiaolaiFallback
|
|
|
|
? `${base} & ${xiaolai} & ${emoji}`
|
|
|
|
? `${base} & ${xiaolai} & ${emoji} & ${liberation}`
|
|
|
|
: `${base} & ${emoji}`;
|
|
|
|
: `${base} & ${emoji} & ${liberation}`;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mergedFont.set({
|
|
|
|
mergedFont.set({
|
|
|
|