Files
NapCatQQ/.pnpm-store/v3/files/25/1a48ac7ff01eb166b821f52c8b6e0a5f55173d8585e56315ae17e9022d2aa36387be3b764500567fdc117056669c2669c3dca18909a694d6d25d89a90df91d
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

94 lines
2.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file glyf的缩放和平移调整
* @author mengke01(kekee000@gmail.com)
*/
import pathAdjust from '../../graphics/pathAdjust';
import pathCeil from '../../graphics/pathCeil';
import {computePathBox} from '../../graphics/computeBoundingBox';
/**
* 简单字形的缩放和平移调整
*
* @param {Object} g glyf对象
* @param {number} scaleX x缩放比例
* @param {number} scaleY y缩放比例
* @param {number} offsetX x偏移
* @param {number} offsetY y偏移
* @param {boolan} useCeil 是否对字形设置取整,默认取整
*
* @return {Object} 调整后的glyf对象
*/
export default function glyfAdjust(g, scaleX = 1, scaleY = 1, offsetX = 0, offsetY = 0, useCeil = true) {
if (g.contours && g.contours.length) {
if (scaleX !== 1 || scaleY !== 1) {
g.contours.forEach((contour) => {
pathAdjust(contour, scaleX, scaleY);
});
}
if (offsetX !== 0 || offsetY !== 0) {
g.contours.forEach((contour) => {
pathAdjust(contour, 1, 1, offsetX, offsetY);
});
}
if (false !== useCeil) {
g.contours.forEach((contour) => {
pathCeil(contour);
});
}
}
// 重新计算xmin,xmax,ymin,ymax
const advanceWidth = g.advanceWidth;
if (
undefined === g.xMin
|| undefined === g.yMax
|| undefined === g.leftSideBearing
|| undefined === g.advanceWidth
) {
// 有的字形没有形状,需要特殊处理一下
let bound;
if (g.contours && g.contours.length) {
// eslint-disable-next-line no-invalid-this
bound = computePathBox.apply(this, g.contours);
}
else {
bound = {
x: 0,
y: 0,
width: 0,
height: 0
};
}
g.xMin = bound.x;
g.xMax = bound.x + bound.width;
g.yMin = bound.y;
g.yMax = bound.y + bound.height;
g.leftSideBearing = g.xMin;
// 如果设置了advanceWidth就是用默认的,否则为xMax + abs(xMin)
if (undefined !== advanceWidth) {
g.advanceWidth = Math.round(advanceWidth * scaleX + offsetX);
}
else {
g.advanceWidth = g.xMax + Math.abs(g.xMin);
}
}
else {
g.xMin = Math.round(g.xMin * scaleX + offsetX);
g.xMax = Math.round(g.xMax * scaleX + offsetX);
g.yMin = Math.round(g.yMin * scaleY + offsetY);
g.yMax = Math.round(g.yMax * scaleY + offsetY);
g.leftSideBearing = Math.round(g.leftSideBearing * scaleX + offsetX);
g.advanceWidth = Math.round(advanceWidth * scaleX + offsetX);
}
return g;
}