Skip to content

Commit

Permalink
[cff] properly skip blend arguments when no variations are set up by …
Browse files Browse the repository at this point in the history
…the user (#123)
  • Loading branch information
benoitkugler authored Dec 11, 2023
1 parent 0d88ef8 commit 26d810d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
13 changes: 6 additions & 7 deletions opentype/api/font/cff/charstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,11 @@ type cff2CharstringHandler struct {

func (cff2CharstringHandler) Context() ps.Context { return ps.Type2Charstring }

// returns true if variations are activated
func (met *cff2CharstringHandler) isVar() bool {
return len(met.coords) != 0 && len(met.vars.ItemVariationDatas) != 0
}

func (met *cff2CharstringHandler) setVSIndex(index int) error {
if !met.isVar() {
// if the font has variations, always build the scalar
// slice, even if no variations are activated by the user:
// the blend operator needs to know how many args to skip.
if len(met.vars.ItemVariationDatas) == 0 {
return nil
}

Expand Down Expand Up @@ -221,7 +219,8 @@ func (met *cff2CharstringHandler) blend(state *ps.Machine) error {
return errors.New("missing arguments for blend operator")
}

if met.isVar() {
// actually apply the deltas only if the user has activated variations
if len(met.coords) != 0 {
args := state.ArgStack.Vals[state.ArgStack.Top-n*(k+1) : state.ArgStack.Top]
// the first n values are the 'default' arguments
for i := int32(0); i < n; i++ {
Expand Down
19 changes: 19 additions & 0 deletions opentype/api/font/cff/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,22 @@ func TestParseCFF2(t *testing.T) {
tu.AssertNoErr(t, err)
}
}

func TestIssue122(t *testing.T) {
b, err := td.Files.ReadFile("common/NotoSansCJKjp-VF.otf")
tu.AssertNoErr(t, err)

ft, err := loader.NewLoader(bytes.NewReader(b))
tu.AssertNoErr(t, err)

table, err := ft.RawTable(loader.MustNewTag("CFF2"))
tu.AssertNoErr(t, err)

out, err := ParseCFF2(table)
tu.AssertNoErr(t, err)

// check that the correct number of segments are
// computed, even if the user has not activated variations
segments, _, _ := out.LoadGlyph(38, nil)
tu.Assert(t, len(segments) == 12)
}

0 comments on commit 26d810d

Please sign in to comment.