Skip to content

Commit

Permalink
fix: svg text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Sep 22, 2024
1 parent 4bafab8 commit 76de911
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions packages/layout/src/svg/layoutText.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ const getFragments = (fontStore, instance) => {

const _textDecoration = instance.props.textDecoration;

const obj = fontStore
? fontStore.getFont({ fontFamily, fontWeight, fontStyle })
: null;
const font = obj ? obj.data : fontFamily;
const fontFamilies =
typeof fontFamily === 'string' ? [fontFamily] : [...(fontFamily || [])];

const font = fontFamilies.map((fontFamilyName) => {
if (typeof fontFamilyName !== 'string') return fontFamilyName;

const opts = { fontFamily: fontFamilyName, fontWeight, fontStyle };
const obj = fontStore ? fontStore.getFont(opts) : null;
return obj ? obj.data : fontFamilyName;
});

const attributes = {
font,
Expand Down
2 changes: 2 additions & 0 deletions packages/layout/src/text/fontSubstitution.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const fontSubstitution =
for (let i = 0; i < runs.length; i += 1) {
const run = runs[i];

console.log(run);

const defaultFont = run.attributes.font.map((font) =>
typeof font === 'string' ? getOrCreateFont(font) : font,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/tests/svg.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Font.register({
});

describe('Svg', () => {
test('should render Tspan component', async () => {
test.only('should render Tspan component', async () => {
const image = await renderToImage(
<Document>
<Page
Expand Down

0 comments on commit 76de911

Please sign in to comment.