diff --git a/src/tables/cff.mjs b/src/tables/cff.mjs index b189c289..7f4d3d0d 100755 --- a/src/tables/cff.mjs +++ b/src/tables/cff.mjs @@ -308,6 +308,17 @@ function interpretDict(dict, meta, strings) { if (m.type === 'SID') { value = getCFFString(strings, value); } + if (m.type === 'delta' && value !== null) { + if (!Array.isArray(value) || value.length % 2 != 0) { + throw new Error(`Read delta data invalid`); + } + // Convert delta array to human readable version + let current = 0; + for(let i = 0; i < value.length; i++) { + value[i] = value[i] + current; + current = value[i] + } + } newDict[m.name] = value; } } @@ -1416,6 +1427,21 @@ function makeDict(meta, attrs, strings) { if (entry.type === 'SID') { value = encodeString(value, strings); } + if (entry.type === 'delta' && value !== null) { + if (!Array.isArray(value) || value.length % 2 != 0) { + throw new Error(`Provided delta data invalid`); + } + // Convert human readable delta array to DICT version + // See https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf + // Private DICT data > Table 6 Operand Types > delta + let current = 0; + for(let i = 0; i < value.length; i++) { + let nextcurrent = value[i]; + value[i] = value[i] - current; + current = nextcurrent; + } + console.log("OUTCOMING", value); + } m[entry.op] = {name: entry.name, type: entry.type, value: value}; } diff --git a/test/tables/cff.spec.mjs b/test/tables/cff.spec.mjs index ab46f19e..b4e4690a 100644 --- a/test/tables/cff.spec.mjs +++ b/test/tables/cff.spec.mjs @@ -93,10 +93,10 @@ describe('tables/cff.mjs', function () { assert.equal(topDict.vstore, 16); assert.equal(topDict.fdSelect, null); - assert.deepEqual(privateDict1.blueValues, [-20, 20, 472, 18, 35, 15, 105, 15, 10, 20, 40, 20]); - assert.deepEqual(privateDict1.otherBlues, [-250, 10]); - assert.deepEqual(privateDict1.familyBlues, [-20, 20, 473, 18, 34, 15, 104, 15, 10, 20, 40, 20]); - assert.deepEqual(privateDict1.familyOtherBlues, [ -249, 10 ]); + assert.deepEqual(privateDict1.blueValues, [-20, 0, 472, 490, 525, 540, 645, 660, 670, 690, 730, 750]); + assert.deepEqual(privateDict1.otherBlues, [-250, -240]); + assert.deepEqual(privateDict1.familyBlues, [-20, 0, 473, 491, 525, 540, 644, 659, 669, 689, 729, 749]); + assert.deepEqual(privateDict1.familyOtherBlues, [ -249, -239 ]); assert.equal(privateDict1.blueScale, 0.0375); assert.equal(privateDict1.blueShift, 7); assert.equal(privateDict1.blueFuzz, 0);