Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: available Font Family Regression #2731

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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