Skip to content

Commit

Permalink
feat: support default system fonts for Windows, Macos and web
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent e026e67 commit 4474dff
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 59 deletions.
58 changes: 1 addition & 57 deletions packages/render-html/src/TRenderEngineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import useTRenderEngine from './hooks/useTRenderEngine';
import { TransientRenderEngineConfig } from './shared-types';
import RenderRegistryProvider from './context/RenderRegistryProvider';
import defaultSystemFonts from './defaultSystemFonts';

const defaultTRenderEngine = {} as any;

Expand Down Expand Up @@ -52,63 +53,6 @@ export const defaultFallbackFonts = {
serif: Platform.select({ ios: 'Times New Roman', default: 'serif' })
};

/**
* Default system fonts based on current platform. If you are using Expo, use
* `Constants.systemFonts` instead.
*/
export const defaultSystemFonts = Platform.select({
default: [],
ios: [
'San Francisco',
'Arial',
'ArialHebrew',
'Avenir',
'Baskerville',
'Bodoni 72',
'Bradley Hand',
'Chalkboard SE',
'Cochin',
'Copperplate',
'Courier',
'Courier New',
'Damascus',
'Didot',
'Futura',
'Geeza Pro',
'Georgia',
'Gill Sans',
'Helvetica',
'Helvetica Neue',
'Hiragino Sans',
'Hoefler Text',
'Iowan Old Style',
'Kailasa',
'Khmer Sangam MN',
'Marker Felt',
'Menlo',
'Mishafi',
'Noteworthy',
'Optima',
'Palatino',
'Papyrus',
'Savoye LET',
'Symbol',
'Thonburi',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Zapf Dingbats',
'Zapfino'
],
android: [
'Roboto',
'notoserif',
'sans-serif-light',
'sans-serif-thin',
'sans-serif-medium'
]
});

export const defaultTRenderEngineProviderProps: TransientRenderEngineConfig = {
htmlParserOptions: {
decodeEntities: true
Expand Down
9 changes: 9 additions & 0 deletions packages/render-html/src/defaultSystemFonts.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const defaultSystemFonts = [
'Roboto',
'notoserif',
'sans-serif-light',
'sans-serif-thin',
'sans-serif-medium'
];

export default defaultSystemFonts;
44 changes: 44 additions & 0 deletions packages/render-html/src/defaultSystemFonts.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const defaultSystemFonts = [
'San Francisco',
'Arial',
'ArialHebrew',
'Avenir',
'Baskerville',
'Bodoni 72',
'Bradley Hand',
'Chalkboard SE',
'Cochin',
'Copperplate',
'Courier',
'Courier New',
'Damascus',
'Didot',
'Futura',
'Geeza Pro',
'Georgia',
'Gill Sans',
'Helvetica',
'Helvetica Neue',
'Hiragino Sans',
'Hoefler Text',
'Iowan Old Style',
'Kailasa',
'Khmer Sangam MN',
'Marker Felt',
'Menlo',
'Mishafi',
'Noteworthy',
'Optima',
'Palatino',
'Papyrus',
'Savoye LET',
'Symbol',
'Thonburi',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Zapf Dingbats',
'Zapfino'
];

export default defaultSystemFonts;
128 changes: 128 additions & 0 deletions packages/render-html/src/defaultSystemFonts.macos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
const defaultSystemFonts = [
'Al Bayan',
'American Typewriter',
'Andalé Mono',
'Apple Casual',
'Apple Chancery',
'Apple Garamond',
'Apple Gothic',
'Apple LiGothic',
'Apple LiSung',
'Apple Myungjo',
'Apple Symbols',
'.AquaKana',
'Arial',
'Arial Hebrew',
'Ayuthaya',
'Baghdad',
'Baskerville',
'Beijing',
'BiauKai',
'Big Caslon',
'Browallia New',
'BrowalliaUPC',
'Brush Script',
'Candara',
'Chalkboard',
'Chalkduster',
'Charcoal',
'Charcoal CY',
'Chicago',
'Cochin',
'Comic Sans',
'Consolas',
'Cooper',
'Copperplate',
'Corsiva Hebrew',
'Courier',
'Courier New',
'DecoType Naskh',
'Devanagari',
'Didot',
'Euphemia UCAS',
'Futura',
'Gadget',
'Geeza Pro',
'Geezah',
'Geneva',
'Geneva CY',
'Georgia',
'Gill Sans',
'Gujarati',
'Gung Seoche',
'Gurmukhi',
'Hangangche',
'HeadlineA',
'Hei',
'Helvetica',
'Helvetica CY',
'Helvetica Neue',
'Herculanum',
'Hiragino Kaku Gothic Pro',
'Hiragino Kaku Gothic ProN',
'Hiragino Kaku Gothic Std',
'Hiragino Kaku Gothic StdN',
'Hiragino Maru Gothic Pro',
'Hiragino Maru Gothic ProN',
'Hiragino Mincho Pro',
'Hiragino Mincho ProN',
'Hoefler Text',
'Inai Mathi',
'Impact',
'Jung Gothic',
'Kai',
'Keyboard',
'Krungthep',
'KufiStandard GK',
'Kuenstler Script',
'LastResort',
'LiHei Pro',
'LiSong Pro',
'Lucida Sans',
'Marker Felt',
'Menlo',
'Monaco',
'Monaco CY',
'Mshtakan',
'Nadeem',
'New Peninim',
'New York',
'NISC GB18030',
'Optima',
'Osaka',
'Palatino',
'Papyrus',
'PC Myungjo',
'Pilgiche',
'Plantagenet Cherokee',
'Raanana',
'Sand',
'Sathu',
'Seoul',
'Shin Myungjo Neue',
'Silom',
'Skia',
'Snell Roundhand',
'ST FangSong',
'ST FangSong 2',
'ST Heiti',
'ST Kaiti',
'ST Song',
'Symbol',
'Tae Graphic',
'Tahoma',
'Taipei',
'Techno',
'Textile',
'Thonburi',
'Times',
'Times CY',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Zapf Chancery',
'Zapf Dingbats',
'Zapfino'
];

export default defaultSystemFonts;
7 changes: 7 additions & 0 deletions packages/render-html/src/defaultSystemFonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Default system fonts based on current platform.
*
* @remarks If you are using Expo, use `Constants.systemFonts` instead.
*/
const defaultSystemFonts = ['Arial', 'Courier New', 'Georgia'];
export default defaultSystemFonts;
63 changes: 63 additions & 0 deletions packages/render-html/src/defaultSystemFonts.windows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const defaultSystemFonts = [
'Arial',
'Arial Black',
'Bahnschrift',
'Calibri',
'Cambria',
'Cambria Math',
'Candara',
'Comic Sans MS',
'Consolas',
'Constantia',
'Corbel',
'Courier New',
'Ebrima',
'Franklin Gothic Medium',
'Gabriola',
'Gadugi',
'Georgia',
'HoloLens MDL2 Assets',
'Impact',
'Ink Free',
'Javanese Text',
'Leelawadee UI',
'Lucida Console',
'Lucida Sans Unicode',
'Malgun Gothic',
'Marlett',
'Microsoft Himalaya',
'Microsoft JhengHei',
'Microsoft New Tai Lue',
'Microsoft PhagsPa',
'Microsoft Sans Serif',
'Microsoft Tai Le',
'Microsoft YaHei',
'Microsoft Yi Baiti',
'MingLiU-ExtB',
'Mongolian Baiti',
'MS Gothic',
'MV Boli',
'Myanmar Text',
'Nirmala UI',
'Palatino Linotype',
'Segoe MDL2 Assets',
'Segoe Print',
'Segoe Script',
'Segoe UI',
'Segoe UI Historic',
'Segoe UI Emoji',
'Segoe UI Symbol',
'SimSun',
'Sitka',
'Sylfaen',
'Symbol',
'Tahoma',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Webdings',
'Wingdings',
'Yu Gothic'
];

export default defaultSystemFonts;
4 changes: 2 additions & 2 deletions packages/render-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export type { TNodeChildrenRendererProps } from './TNodeChildrenRenderer';
export { default as TNodeRenderer } from './TNodeRenderer';
export {
default as TRenderEngineProvider,
defaultFallbackFonts,
defaultSystemFonts
defaultFallbackFonts
} from './TRenderEngineProvider';
export { default as defaultSystemFonts } from './defaultSystemFonts';
export { default as RenderHTMLFragment } from './RenderHTMLFragment';
export { default as useInternalRenderer } from './hooks/useInternalRenderer';
export { default as useNormalizedUrl } from './hooks/useNormalizedUrl';
Expand Down

0 comments on commit 4474dff

Please sign in to comment.