Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/font/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,15 @@ class EmbeddedFont extends PDFFont {
}

if (this.document.subset && this.document.subset === 1) {
const CIDSet = Buffer.from('FFFFFFFFC0', 'hex');
const maxCID = this.widths.length - 1;
const cidSetBuffer = Buffer.alloc(Math.ceil((maxCID + 1) / 8), 0);
for (let cid = 0; cid <= maxCID; cid++) {
if (this.widths[cid] != null) {
cidSetBuffer[Math.floor(cid / 8)] |= 0x80 >> cid % 8;
}
}
const CIDSetRef = this.document.ref();
CIDSetRef.write(CIDSet);
CIDSetRef.write(cidSetBuffer);
CIDSetRef.end();

descriptor.data.CIDSet = CIDSetRef;
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/pdfa1.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,41 @@ describe('PDF/A-1', () => {

expect(fontDescriptor).toContain('/CIDSet');
});

test('CIDSet correctly identifies all glyphs in the subset', () => {
let options = {
autoFirstPage: false,
compress: false,
pdfVersion: '1.4',
subset: 'PDF/A-1a',
};
let doc = new PDFDocument(options);
const data = logData(doc);
doc.addPage();
doc.registerFont('Roboto', 'tests/fonts/Roboto-Regular.ttf');
doc.font('Roboto');
doc.text('Text');
const widths = doc._font.widths.slice();
doc.end();

const maxCID = widths.length - 1;
const CIDSet = Buffer.alloc(Math.ceil((maxCID + 1) / 8), 0);
for (let cid = 0; cid <= maxCID; cid++) {
if (widths[cid] != null) {
CIDSet[Math.floor(cid / 8)] |= 0x80 >> cid % 8;
}
}

let found = false;
for (let i = 0; i < data.length - 1; i++) {
if (data[i] === 'stream' && data[i + 1] instanceof Buffer) {
if (data[i + 1].equals(CIDSet)) {
found = true;
break;
}
}
}

expect(found).toBe(true);
});
});
Loading