Skip to content

Commit 03b8298

Browse files
authored
feat(textkit): expect font array (diegomura#3104)
1 parent 9e173c4 commit 03b8298

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

src/svg/layoutText.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import layoutEngine, {
1010
textDecoration,
1111
fromFragments,
1212
Fragment,
13-
Font,
1413
} from '@react-pdf/textkit';
1514

1615
import transformText from '../text/transformText';
@@ -64,14 +63,11 @@ const getFragments = (fontStore: FontStore, instance) => {
6463
// Fallback font
6564
fontFamilies.push('Helvetica');
6665

67-
// TODO: Fix multiple fonts passed
6866
const font = fontFamilies.map((fontFamilyName) => {
69-
if (typeof fontFamilyName !== 'string') return fontFamilyName;
70-
7167
const opts = { fontFamily: fontFamilyName, fontWeight, fontStyle };
7268
const obj = fontStore.getFont(opts);
73-
return obj ? obj.data : fontFamilyName;
74-
}) as Font[];
69+
return obj?.data;
70+
});
7571

7672
const attributes = {
7773
font,
@@ -98,7 +94,6 @@ const getFragments = (fontStore: FontStore, instance) => {
9894
if (isTextInstance(child)) {
9995
fragments.push({
10096
string: transformText(child.value, textTransform),
101-
// @ts-expect-error custom font substitution engine deals with multiple fonts. unify with textkit
10297
attributes,
10398
});
10499
} else if (child) {

src/text/getAttributedString.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as P from '@react-pdf/primitives';
2-
import { Font, Fragment, fromFragments } from '@react-pdf/textkit';
2+
import { Fragment, fromFragments } from '@react-pdf/textkit';
33
import FontStore from '@react-pdf/font';
44

55
import { embedEmojis } from './emoji';
@@ -65,14 +65,11 @@ const getFragments = (
6565
// Fallback font
6666
fontFamilies.push('Helvetica');
6767

68-
// TODO: Fix multiple fonts passed
6968
const font = fontFamilies.map((fontFamilyName) => {
70-
if (typeof fontFamilyName !== 'string') return fontFamilyName;
71-
7269
const opts = { fontFamily: fontFamilyName, fontWeight, fontStyle };
7370
const obj = fontStore.getFont(opts);
74-
return obj ? obj.data : fontFamilyName;
75-
}) as Font[];
71+
return obj?.data;
72+
});
7673

7774
// Don't pass main background color to textkit. Will be rendered by the render package instead
7875
const backgroundColor = level === 0 ? null : instance.style.backgroundColor;
@@ -111,7 +108,6 @@ const getFragments = (
111108
if (isImage(child)) {
112109
fragments.push({
113110
string: String.fromCharCode(0xfffc),
114-
// @ts-expect-error custom font substitution engine deals with multiple fonts. unify with textkit
115111
attributes: {
116112
...attributes,
117113
attachment: {
@@ -124,7 +120,6 @@ const getFragments = (
124120
} else if (isTextInstance(child)) {
125121
fragments.push({
126122
string: transformText(child.value, textTransform),
127-
// @ts-expect-error custom font substitution engine deals with multiple fonts. unify with textkit
128123
attributes,
129124
});
130125
} else if (child) {

src/text/ignoreChars.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const buildSubsetForFont = (font: Font) =>
1919

2020
const ignoreChars = (fragments: Fragment[]): Fragment[] =>
2121
fragments.map((fragment) => {
22-
const charSubset = buildSubsetForFont(fragment.attributes.font);
22+
const charSubset = buildSubsetForFont(fragment.attributes.font[0]);
2323
const subsetRegex = new RegExp(charSubset.join('|'));
2424

2525
return {

0 commit comments

Comments
 (0)