pdfkit/tests/unit/font.spec.js
Jakub Valenta 63972499c0 lib/font/embedded: Don't put '@' in font tag
Otherwise Adobe Illustrator says "This document uses fonts that are
currently not available on your computer".
2021-03-24 15:25:51 -03:00

56 lines
1.4 KiB
JavaScript

import PDFFontFactory from '../../lib/font_factory';
import PDFDocument from '../../lib/document';
describe('EmbeddedFont', () => {
test('no fontLayoutCache option', () => {
const document = new PDFDocument();
const font = PDFFontFactory.open(
document,
'tests/fonts/Roboto-Regular.ttf'
);
const runSpy = jest.spyOn(font, 'layoutRun');
font.layout('test');
font.layout('test');
font.layout('test');
font.layout('test');
expect(runSpy).toBeCalledTimes(1);
});
test('fontLayoutCache = false', () => {
const document = new PDFDocument({ fontLayoutCache: false });
const font = PDFFontFactory.open(
document,
'tests/fonts/Roboto-Regular.ttf'
);
const runSpy = jest.spyOn(font, 'layoutRun');
font.layout('test');
font.layout('test');
font.layout('test');
font.layout('test');
expect(runSpy).toBeCalledTimes(4);
});
describe('emebed', () => {
test('sets BaseName based on font id and postscript name', () => {
const document = new PDFDocument();
const font = PDFFontFactory.open(
document,
'tests/fonts/Roboto-Regular.ttf',
undefined,
'F1099'
);
const dictionary = {
end: () => {},
};
font.dictionary = dictionary;
font.embed();
expect(dictionary.data.BaseFont).toBe('BAJJZZ+Roboto-Regular');
});
});
});