Skip to content

Commit a1fddc7

Browse files
committed
♻️ Rename font name parameter in font config
This parameter is used to specify a custom font _family_ name. Since the affected API is not yet released, this change is not considered a breaking change.
1 parent b850a85 commit a1fddc7

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/api/PdfMaker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { DocumentDefinition } from './document.ts';
99
import type { FontStyle, FontWeight } from './text.ts';
1010

1111
export type FontConfig = {
12-
name?: string;
12+
family?: string;
1313
style?: FontStyle;
1414
weight?: FontWeight;
1515
};

src/font-store.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,12 @@ describe('FontStore', () => {
230230
it('registers font with custom config', async () => {
231231
store = new FontStore();
232232

233-
store.registerFont(robotoRegular, { name: 'Custom Name', weight: 'bold' });
234-
store.registerFont(robotoLightItalic, { name: 'Custom Name', weight: 400, style: 'normal' });
233+
store.registerFont(robotoRegular, { family: 'Custom Name', weight: 'bold' });
234+
store.registerFont(robotoLightItalic, {
235+
family: 'Custom Name',
236+
weight: 400,
237+
style: 'normal',
238+
});
235239

236240
const selected1 = await store.selectFont({ fontFamily: 'Custom Name' });
237241
const selected2 = await store.selectFont({ fontFamily: 'Custom Name', fontWeight: 'bold' });

src/font-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class FontStore {
1717

1818
registerFont(data: Uint8Array, config?: FontConfig): void {
1919
const fkFont = fontkit.create(data);
20-
const family = config?.name ?? fkFont.familyName ?? 'Unknown';
20+
const family = config?.family ?? fkFont.familyName ?? 'Unknown';
2121
const style = config?.style ?? extractStyle(fkFont);
2222
const weight = weightToNumber(config?.weight ?? extractWeight(fkFont));
2323
this.#fontDefs.push({ family, style, weight, data, fkFont });

0 commit comments

Comments
 (0)