Skip to content

Commit

Permalink
fix: fix minRightSideBearing, maxComponentElements calc
Browse files Browse the repository at this point in the history
  • Loading branch information
kekee000 committed Aug 30, 2023
1 parent a0c11df commit d333655
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fonteditor-core",
"version": "2.2.0",
"version": "2.2.1",
"description": "fonts (ttf, woff, woff2, eot, svg, otf) parse, write, transform, glyph adjust.",
"keywords": [
"sfnt",
Expand Down
25 changes: 13 additions & 12 deletions src/ttf/table/OS2.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ export default table.create(
});
}
});

maxComponentElements++;
maxComponentElements = Math.max(maxComponentElements, glyf.glyfs.length);
maxCompositePoints = Math.max(maxCompositePoints, compositePoints);
maxCompositeContours = Math.max(maxCompositeContours, compositeContours);
}
Expand All @@ -198,30 +197,32 @@ export default table.create(
}

// 统计边界信息
if (glyf.xMin < xMin) {
if (null != glyf.xMin && glyf.xMin < xMin) {
xMin = glyf.xMin;
}

if (glyf.yMin < yMin) {
if (null != glyf.yMin && glyf.yMin < yMin) {
yMin = glyf.yMin;
}

if (glyf.xMax > xMax) {
if (null != glyf.xMax && glyf.xMax > xMax) {
xMax = glyf.xMax;
}

if (glyf.yMax > yMax) {
if (null != glyf.yMax && glyf.yMax > yMax) {
yMax = glyf.yMax;
}

advanceWidthMax = Math.max(advanceWidthMax, glyf.advanceWidth);
minLeftSideBearing = Math.min(minLeftSideBearing, glyf.leftSideBearing);
minRightSideBearing = Math.min(minRightSideBearing, glyf.advanceWidth - glyf.xMax);
xMaxExtent = Math.max(xMaxExtent, glyf.xMax);

xAvgCharWidth += glyf.advanceWidth;

glyfNotEmpty++;
if (null != glyf.xMax) {
minRightSideBearing = Math.min(minRightSideBearing, glyf.advanceWidth - glyf.xMax);
xMaxExtent = Math.max(xMaxExtent, glyf.xMax);
}
if (null != glyf.advanceWidth) {
xAvgCharWidth += glyf.advanceWidth;
glyfNotEmpty++;
}

let unicodes = glyf.unicode;

Expand Down
14 changes: 14 additions & 0 deletions test/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const Font = require('../').Font;

const buffer = fs.readFileSync('/System/Library/Fonts/NewYork.ttf');
const font = Font.create(buffer, {
type: 'ttf'
});
console.log(font.get()['OS/2']);

const font1 = Font.create(font.write({type: 'ttf'}), {
type: 'ttf'
});

console.log(font1.get()['OS/2']);

0 comments on commit d333655

Please sign in to comment.