|
| 1 | +/* eslint react/prop-types: 0 */ |
| 2 | +/* eslint react/jsx-sort-props: 0 */ |
| 3 | + |
| 4 | +import { Document, Font, Page, StyleSheet, Text } from '@react-pdf/renderer'; |
| 5 | +import React from 'react'; |
| 6 | + |
| 7 | +import RobotoFont from '../../../public/Roboto-Regular.ttf'; |
| 8 | +import RubikFont from '../../../public/Rubik-Regular.ttf'; |
| 9 | + |
| 10 | +const styles = StyleSheet.create({ |
| 11 | + body: { |
| 12 | + paddingTop: 35, |
| 13 | + paddingBottom: 45, |
| 14 | + paddingHorizontal: 35, |
| 15 | + position: 'relative', |
| 16 | + fontSize: 14, |
| 17 | + }, |
| 18 | + headline: { |
| 19 | + fontFamily: 'Roboto', |
| 20 | + fontSize: 24, |
| 21 | + paddingVertical: 12, |
| 22 | + }, |
| 23 | + rubik: { |
| 24 | + fontFamily: 'Rubik', |
| 25 | + }, |
| 26 | + roboto: { |
| 27 | + fontFamily: 'Roboto', |
| 28 | + }, |
| 29 | + tabular: { |
| 30 | + fontFeatureSettings: ['tnum'], |
| 31 | + }, |
| 32 | + smallCapitals: { |
| 33 | + fontFeatureSettings: ['smcp'], |
| 34 | + }, |
| 35 | + disableCommonLigatures: { |
| 36 | + fontFeatureSettings: { liga: 0 }, |
| 37 | + }, |
| 38 | +}); |
| 39 | + |
| 40 | +Font.register({ |
| 41 | + family: 'Rubik', |
| 42 | + fonts: [{ src: RubikFont, fontWeight: 400 }], |
| 43 | +}); |
| 44 | +Font.register({ |
| 45 | + family: 'Roboto', |
| 46 | + fonts: [{ src: RobotoFont, fontWeight: 400 }], |
| 47 | +}); |
| 48 | + |
| 49 | +const MyDoc = () => { |
| 50 | + const longNumberExample = "012'345'678'901"; |
| 51 | + const commonLigaturesExample = 'A firefighter from Sheffield'; |
| 52 | + return ( |
| 53 | + <Page style={styles.body}> |
| 54 | + <Text style={styles.headline}>Rubik</Text> |
| 55 | + <Text style={styles.rubik}>{longNumberExample} – Default features</Text> |
| 56 | + <Text style={[styles.rubik, styles.tabular]}> |
| 57 | + {longNumberExample} – Tabular numbers |
| 58 | + </Text> |
| 59 | + <Text style={styles.headline}>Roboto</Text> |
| 60 | + <Text style={styles.roboto}> |
| 61 | + {commonLigaturesExample} – Default features |
| 62 | + </Text> |
| 63 | + <Text style={[styles.roboto, styles.disableCommonLigatures]}> |
| 64 | + {commonLigaturesExample} – Common ligatures off |
| 65 | + </Text> |
| 66 | + <Text style={[styles.roboto, styles.smallCapitals]}> |
| 67 | + {commonLigaturesExample} – Small capitals |
| 68 | + </Text> |
| 69 | + </Page> |
| 70 | + ); |
| 71 | +}; |
| 72 | + |
| 73 | +const FontFeatureSettings = () => { |
| 74 | + return ( |
| 75 | + <Document> |
| 76 | + <MyDoc /> |
| 77 | + </Document> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +export default { |
| 82 | + id: 'font-feature-settings', |
| 83 | + name: 'Font Feature Settings', |
| 84 | + description: '', |
| 85 | + Document: FontFeatureSettings, |
| 86 | +}; |
0 commit comments