Skip to content

Commit

Permalink
Merge pull request #468 from yne/fix-quadratic
Browse files Browse the repository at this point in the history
  • Loading branch information
fdb authored Sep 22, 2021
2 parents 88f7c17 + c4b84d0 commit ad8a567
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tables/cff.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,14 +1169,15 @@ function glyphToOps(glyph) {
const _23 = 2 / 3;

// We're going to create a new command so we don't change the original path.
// Since all coordinates are relative, we round() them ASAP to avoid propagating errors.
cmd = {
type: 'C',
x: cmd.x,
y: cmd.y,
x1: _13 * x + _23 * cmd.x1,
y1: _13 * y + _23 * cmd.y1,
x2: _13 * cmd.x + _23 * cmd.x1,
y2: _13 * cmd.y + _23 * cmd.y1
x1: Math.round(_13 * x + _23 * cmd.x1),
y1: Math.round(_13 * y + _23 * cmd.y1),
x2: Math.round(_13 * cmd.x + _23 * cmd.x1),
y2: Math.round(_13 * cmd.y + _23 * cmd.y1)
};
}

Expand Down
44 changes: 44 additions & 0 deletions test/tables/cff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import assert from 'assert';
import { hex } from '../testutil';
import Glyph from '../../src/glyph';
import glyphset from '../../src/glyphset';
import Path from '../../src/path';
import cff from '../../src/tables/cff';

describe('tables/cff.js', function () {
const data =
'01 00 04 01 00 01 01 01 03 70 73 00 01 01 01 32 ' +
'F8 1B 00 F8 1C 02 F8 1C 03 F8 1D 04 1D 00 00 00 ' +
'55 0F 1D 00 00 00 58 11 8B 1D 00 00 00 80 12 1E ' +
'0A 12 5F 1E 0F 1E 0F 1E 0A 12 5F 1E 0F 1E 0F 0C ' +
'07 00 04 01 01 02 04 06 0B 30 66 6E 77 6E 62 75 ' +
'6D 70 73 00 00 00 01 8A 00 02 01 01 03 23 9B 0E ' +
'9B 8B 8B 15 8C 8D 8B 8B 8C 89 08 89 8B 15 8C 8D ' +
'8B 8B 8C 89 08 89 8B 15 8C 8D 8B 8B 8C 89 08 0E';

it('can make a cff tag table', function () {
const options = {
unitsPerEm: 8,
version: '0',
fullName: 'fn',
postScriptName: 'ps',
familyName: 'fn',
weightName: 'wn',
fontBBox: [0, 0, 0, 0],
};
const path = new Path();
path.moveTo(0, 0);
path.quadraticCurveTo(1, 3, 2, 0);
path.moveTo(0, 0);
path.quadraticCurveTo(1, 3, 2, 0);
path.moveTo(0, 0);
path.quadraticCurveTo(1, 3, 2, 0);
const bumpsGlyph = new Glyph({ name: 'bumps', path, advanceWidth: 16 });
const nodefGlyph = new Glyph({ name: 'nodef', path: new Path(), advanceWidth: 16 });
const glyphSetFont = { unitsPerEm: 8 };
const glyphs = new glyphset.GlyphSet(glyphSetFont, [nodefGlyph, bumpsGlyph]);

assert.deepEqual(data, hex(cff.make(glyphs, options).encode()));
});

});

0 comments on commit ad8a567

Please sign in to comment.