Skip to content

Commit

Permalink
fix: available Font Family Regression (#2731)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdkopen committed Apr 29, 2024
1 parent 6bf9d99 commit ee126d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
19 changes: 18 additions & 1 deletion packages/examples/src/fontFamilyFallback/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ const styles = StyleSheet.create({
},
regular: {
fontFamily: ['Roboto', 'NotoSansArabic'],
fontSize: '14',
fontWeight: 900,
},
default: {
fontFamily: ['Courier-Bold', 'NotoSansArabic'],
fontSize: '14',
},
});

Font.register({
Expand All @@ -43,7 +48,19 @@ Font.register({
const MyDoc = () => {
return (
<Page style={styles.body}>
<Text style={styles.regular}>Test امتحان</Text>
<Text style={{ fontFamily: 'Courier', marginBottom: '10px' }}>
This font is default Courier
</Text>
<Text style={{ fontSize: 10 }}>
The following is partially Roboto and Noto Sans Arabic
</Text>
<Text style={[styles.regular, { marginBottom: '10px' }]}>
Roboto / امتحان
</Text>
<Text style={{ fontSize: 10 }}>
The following is partially Courier-Bold and Noto Sans Arabic
</Text>
<Text style={styles.default}>Courier-Bold / امتحان</Text>
</Page>
);
};
Expand Down
13 changes: 4 additions & 9 deletions packages/layout/src/text/fontSubstitution.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ const fontSubstitution =
for (let i = 0; i < runs.length; i += 1) {
const run = runs[i];

const defaultFont =
typeof run.attributes.font === 'string'
? getOrCreateFont(run.attributes.font)
: run.attributes.font;
const defaultFont = run.attributes.font.map((font) =>
typeof font === 'string' ? getOrCreateFont(font) : font,
);

if (string.length === 0) {
res.push({ start: 0, end: 0, attributes: { font: defaultFont } });
Expand All @@ -67,11 +66,7 @@ const fontSubstitution =
const char = chars[j];
const codePoint = char.codePointAt();
// If the default font does not have a glyph and the fallback font does, we use it
const font = pickFontFromFontStack(
codePoint,
run.attributes.font,
lastFont,
);
const font = pickFontFromFontStack(codePoint, defaultFont, lastFont);
const fontSize = getFontSize(run);

// If anything that would impact res has changed, update it
Expand Down

1 comment on commit ee126d6

@TomasSalas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will you be able to upload this change, do I need it urgently?

Please sign in to comment.