-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add font feature settings support
- Loading branch information
1 parent
ee126d6
commit f33ad19
Showing
8 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@react-pdf/textkit": minor | ||
"@react-pdf/layout": minor | ||
"@react-pdf/types": minor | ||
--- | ||
|
||
Add support for fontFeatureSettings to customise ligatures, tabular number display, and other font features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint react/prop-types: 0 */ | ||
/* eslint react/jsx-sort-props: 0 */ | ||
|
||
import { Document, Font, Page, StyleSheet, Text } from '@react-pdf/renderer'; | ||
import React from 'react'; | ||
|
||
import RobotoFont from '../../public/Roboto-Regular.ttf'; | ||
import RubikFont from '../../public/Rubik-Regular.ttf'; | ||
|
||
const styles = StyleSheet.create({ | ||
body: { | ||
paddingTop: 35, | ||
paddingBottom: 45, | ||
paddingHorizontal: 35, | ||
position: 'relative', | ||
fontSize: 14, | ||
}, | ||
headline: { | ||
fontFamily: 'Roboto', | ||
fontSize: '24', | ||
paddingVertical: 12, | ||
}, | ||
rubik: { | ||
fontFamily: 'Rubik', | ||
}, | ||
roboto: { | ||
fontFamily: 'Roboto', | ||
}, | ||
tabular: { | ||
fontFeatureSettings: ['tnum'], | ||
}, | ||
smallCapitals: { | ||
fontFeatureSettings: ['smcp'], | ||
}, | ||
disableCommonLigatures: { | ||
fontFeatureSettings: { liga: 0 }, | ||
}, | ||
}); | ||
|
||
Font.register({ | ||
family: 'Rubik', | ||
fonts: [{ src: RubikFont, fontWeight: 400 }], | ||
}); | ||
Font.register({ | ||
family: 'Roboto', | ||
fonts: [{ src: RobotoFont, fontWeight: 400 }], | ||
}); | ||
|
||
const MyDoc = () => { | ||
const longNumberExample = "012'345'678'901"; | ||
const commonLigaturesExample = 'A firefighter from Sheffield'; | ||
return ( | ||
<Page style={styles.body}> | ||
<Text style={styles.headline}>Rubik</Text> | ||
<Text style={styles.rubik}>{longNumberExample} – Default features</Text> | ||
<Text style={[styles.rubik, styles.tabular]}> | ||
{longNumberExample} – Tabular numbers | ||
</Text> | ||
<Text style={styles.headline}>Roboto</Text> | ||
<Text style={styles.roboto}> | ||
{commonLigaturesExample} – Default features | ||
</Text> | ||
<Text style={[styles.roboto, styles.disableCommonLigatures]}> | ||
{commonLigaturesExample} – Common ligatures off | ||
</Text> | ||
<Text style={[styles.roboto, styles.smallCapitals]}> | ||
{commonLigaturesExample} – Small capitals | ||
</Text> | ||
</Page> | ||
); | ||
}; | ||
|
||
const App = () => { | ||
return ( | ||
<Document> | ||
<MyDoc /> | ||
</Document> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters