Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
import { DEFAULT_SERIF_FONT, DEFAULT_SANS_SERIF_FONT } from '../shared/lib/constants';
|
|
const capsizeFontsMetrics = require('next/dist/server/capsize-font-metrics.json');
|
|
function formatName(str) {
|
|
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
}).replace(/\s+/g, '');
|
|
}
|
|
function formatOverrideValue(val) {
|
|
return Math.abs(val * 100).toFixed(2);
|
|
}
|
|
export function calculateSizeAdjustValues(fontName) {
|
|
const fontKey = formatName(fontName);
|
|
const fontMetrics = capsizeFontsMetrics[fontKey];
|
|
let { category, ascent, descent, lineGap, unitsPerEm, xWidthAvg } = fontMetrics;
|
|
const mainFontAvgWidth = xWidthAvg / unitsPerEm;
|
|
const fallbackFont = category === 'serif' ? DEFAULT_SERIF_FONT : DEFAULT_SANS_SERIF_FONT;
|
|
const fallbackFontName = formatName(fallbackFont.name);
|
|
const fallbackFontMetrics = capsizeFontsMetrics[fallbackFontName];
|
|
const fallbackFontAvgWidth = fallbackFontMetrics.xWidthAvg / fallbackFontMetrics.unitsPerEm;
|
|
let sizeAdjust = xWidthAvg ? mainFontAvgWidth / fallbackFontAvgWidth : 1;
|
|
ascent = formatOverrideValue(ascent / (unitsPerEm * sizeAdjust));
|
|
descent = formatOverrideValue(descent / (unitsPerEm * sizeAdjust));
|
|
lineGap = formatOverrideValue(lineGap / (unitsPerEm * sizeAdjust));
|
|
return {
|
|
ascent,
|
|
descent,
|
|
lineGap,
|
|
fallbackFont: fallbackFont.name,
|
|
sizeAdjust: formatOverrideValue(sizeAdjust)
|
|
};
|
|
}
|
|
|
|
//# sourceMappingURL=font-utils.js.map
|