CFF hflex and hflex1: second curve doesn't return to the starting y
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, computer-graphics
Research direction
Start in src/glyph/CFFGlyph.js and inspect the hflex and hflex1 operator handling, using the Type 2 charstring spec cited in the issue to confirm the endpoint rules. Compare the affected glyph path commands with fontTools' RecordingPen output for a reproducing CFF OTF. Done when both operators return to their starting y and the resulting paths match the reference.
Written by the indexing model from the issue text.
Description
In src/glyph/CFFGlyph.js (still on master, and in 2.0.4), the hflex (12 34) and hflex1 (12 36) operators leave the second curve at the raised y. The Type 2 charstring spec (Adobe TN #5177) says both end at the y they started from. Every point after the flex is shifted by the flex's dy, which shows up as steps or misplaced contours when drawing the path.
hflex dx1 dx2 dy2 dx3 dx4 dx5 dx6: the second curve is (dx4, 0) (dx5, -dy2) (dx6, 0), so c5y should drop back to the start. Currently:
c5y = c4y; // should be: c5y = y;
c6y = c5y;
hflex1 dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6: dy6 is implied so the curve ends at the starting y. Currently:
c5y = c4y + stack.shift();
c6x = c5x + stack.shift();
c6y = c5y; // should be: c6y = y;
(y is still the start point here because it's only updated after c6y.)
Repro: any CFF OTF whose charstrings use hflex/hflex1. Compare font.glyphForCodePoint(cp).path.commands with fontTools' RecordingPen output for the same glyph. In one font, a glyph whose contour should close at (415, -10) ends at (415, 0) in fontkit (hflex with dy2 = 10). In another, an hflex1 glyph's last point comes out at y 147 where fontTools gives 171. With the two one-line changes above, fontkit matches fontTools.
flex (12 35) and flex1 (12 37) look correct.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 254
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 22
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from foliojs/fontkit
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
Vertical phantom points have the wrong signPossibly taken @lehni claimed this 11 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
foliojs/fontkit#382 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
foliojs/fontkit#368 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Maintainers usually reply within 1 day
Similar issues
-
agentic-workflows
Difficulty 1/5 Under an hour Newbie friendliness 85/100
githubnext/gh-cao#20316 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
rookslog/zlibrary-mcp#408 ·
Maintainers usually reply within 1 day
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mastra-ai/mastra#29641 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 83/100
quarkiverse/quarkiverse#464 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day