Skip to content

Commit

Permalink
Merge pull request #29158 from bernhardoj/fix/27626-md-custom-font
Browse files Browse the repository at this point in the history
Fix code block font is not a monospace
  • Loading branch information
puneetlath authored Oct 10, 2023
2 parents 987569f + 8ade452 commit 6d447b1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 47 deletions.
9 changes: 2 additions & 7 deletions src/components/HTMLEngineProvider/BaseHTMLEngineProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import PropTypes from 'prop-types';
import htmlRenderers from './HTMLRenderers';
import * as HTMLEngineUtils from './htmlEngineUtils';
import styles from '../../styles/styles';
import fontFamily from '../../styles/fontFamily';
import convertToLTR from '../../libs/convertToLTR';
import singleFontFamily from '../../styles/fontFamily/singleFontFamily';

const propTypes = {
/** Whether text elements should be selectable */
Expand Down Expand Up @@ -60,18 +60,13 @@ function BaseHTMLEngineProvider(props) {
// We need to memoize this prop to make it referentially stable.
const defaultTextProps = useMemo(() => ({selectable: props.textSelectable, allowFontScaling: false, textBreakStrategy: 'simple'}), [props.textSelectable]);

// We need to pass multiple system-specific fonts for emojis but
// we can't apply multiple fonts at once so we need to pass fallback fonts.
const fallbackFonts = {'ExpensifyNeue-Regular': fontFamily.EXP_NEUE};

return (
<TRenderEngineProvider
customHTMLElementModels={customHTMLElementModels}
baseStyle={styles.webViewStyles.baseFontStyle}
tagsStyles={styles.webViewStyles.tagStyles}
enableCSSInlineProcessing={false}
systemFonts={_.values(fontFamily)}
fallbackFonts={fallbackFonts}
systemFonts={_.values(singleFontFamily)}
domVisitors={{
// eslint-disable-next-line no-param-reassign
onText: (text) => (text.data = convertToLTR(text.data)),
Expand Down
5 changes: 3 additions & 2 deletions src/styles/fontFamily/bold/index.android.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const bold = 'ExpensifyNeue-Bold';
const singleBold = 'ExpensifyNeue-Bold';
const multiBold = 'ExpensifyNeue-Bold';

export default bold;
export {singleBold, multiBold};
5 changes: 3 additions & 2 deletions src/styles/fontFamily/bold/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const bold = 'ExpensifyNeue-Regular';
const singleBold = 'ExpensifyNeue-Regular';
const multiBold = 'ExpensifyNeue-Regular';

export default bold;
export {singleBold, multiBold};
5 changes: 3 additions & 2 deletions src/styles/fontFamily/bold/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const bold = 'ExpensifyNeue-Regular, Segoe UI Emoji, Noto Color Emoji';
const singleBold = 'ExpensifyNeue-Regular';
const multiBold = 'ExpensifyNeue-Regular, Segoe UI Emoji, Noto Color Emoji';

export default bold;
export {singleBold, multiBold};
18 changes: 2 additions & 16 deletions src/styles/fontFamily/index.native.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
import bold from './bold';
import FontFamilyStyles from './types';
import singleFontFamily from './singleFontFamily';

const fontFamily: FontFamilyStyles = {
EXP_NEUE_ITALIC: 'ExpensifyNeue-Italic',
EXP_NEUE_BOLD: bold,
EXP_NEUE: 'ExpensifyNeue-Regular',
EXP_NEW_KANSAS_MEDIUM: 'ExpensifyNewKansas-Medium',
EXP_NEW_KANSAS_MEDIUM_ITALIC: 'ExpensifyNewKansas-MediumItalic',
SYSTEM: 'System',
MONOSPACE: 'ExpensifyMono-Regular',
MONOSPACE_ITALIC: 'ExpensifyMono-Regular',
MONOSPACE_BOLD: 'ExpensifyMono-Bold',
MONOSPACE_BOLD_ITALIC: 'ExpensifyMono-Bold',
};

export default fontFamily;
export default singleFontFamily;
20 changes: 2 additions & 18 deletions src/styles/fontFamily/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import bold from './bold';
import FontFamilyStyles from './types';
import multiFontFamily from './multiFontFamily';

// In windows and ubuntu, we need some extra system fonts for emojis to work properly
// otherwise few of them will appear as black and white
const fontFamily: FontFamilyStyles = {
EXP_NEUE_ITALIC: 'ExpensifyNeue-Italic, Segoe UI Emoji, Noto Color Emoji',
EXP_NEUE_BOLD: bold,
EXP_NEUE: 'ExpensifyNeue-Regular, Segoe UI Emoji, Noto Color Emoji',
EXP_NEW_KANSAS_MEDIUM: 'ExpensifyNewKansas-Medium, Segoe UI Emoji, Noto Color Emoji',
EXP_NEW_KANSAS_MEDIUM_ITALIC: 'ExpensifyNewKansas-MediumItalic, Segoe UI Emoji, Noto Color Emoji',
SYSTEM: 'System',
MONOSPACE: 'ExpensifyMono-Regular, Segoe UI Emoji, Noto Color Emoji',
MONOSPACE_ITALIC: 'ExpensifyMono-Regular, Segoe UI Emoji, Noto Color Emoji',
MONOSPACE_BOLD: 'ExpensifyMono-Bold, Segoe UI Emoji, Noto Color Emoji',
MONOSPACE_BOLD_ITALIC: 'ExpensifyMono-Bold, Segoe UI Emoji, Noto Color Emoji',
};

export default fontFamily;
export default multiFontFamily;
19 changes: 19 additions & 0 deletions src/styles/fontFamily/multiFontFamily.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {multiBold} from './bold';
import FontFamilyStyles from './types';

// In windows and ubuntu, we need some extra system fonts for emojis to work properly
// otherwise few of them will appear as black and white
const fontFamily: FontFamilyStyles = {
EXP_NEUE_ITALIC: 'ExpensifyNeue-Italic, Segoe UI Emoji, Noto Color Emoji',
EXP_NEUE_BOLD: multiBold,
EXP_NEUE: 'ExpensifyNeue-Regular, Segoe UI Emoji, Noto Color Emoji',
EXP_NEW_KANSAS_MEDIUM: 'ExpensifyNewKansas-Medium, Segoe UI Emoji, Noto Color Emoji',
EXP_NEW_KANSAS_MEDIUM_ITALIC: 'ExpensifyNewKansas-MediumItalic, Segoe UI Emoji, Noto Color Emoji',
SYSTEM: 'System',
MONOSPACE: 'ExpensifyMono-Regular, Segoe UI Emoji, Noto Color Emoji',
MONOSPACE_ITALIC: 'ExpensifyMono-Regular, Segoe UI Emoji, Noto Color Emoji',
MONOSPACE_BOLD: 'ExpensifyMono-Bold, Segoe UI Emoji, Noto Color Emoji',
MONOSPACE_BOLD_ITALIC: 'ExpensifyMono-Bold, Segoe UI Emoji, Noto Color Emoji',
};

export default fontFamily;
17 changes: 17 additions & 0 deletions src/styles/fontFamily/singleFontFamily.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {singleBold} from './bold';
import FontFamilyStyles from './types';

const fontFamily: FontFamilyStyles = {
EXP_NEUE_ITALIC: 'ExpensifyNeue-Italic',
EXP_NEUE_BOLD: singleBold,
EXP_NEUE: 'ExpensifyNeue-Regular',
EXP_NEW_KANSAS_MEDIUM: 'ExpensifyNewKansas-Medium',
EXP_NEW_KANSAS_MEDIUM_ITALIC: 'ExpensifyNewKansas-MediumItalic',
SYSTEM: 'System',
MONOSPACE: 'ExpensifyMono-Regular',
MONOSPACE_ITALIC: 'ExpensifyMono-Regular',
MONOSPACE_BOLD: 'ExpensifyMono-Bold',
MONOSPACE_BOLD_ITALIC: 'ExpensifyMono-Bold',
};

export default fontFamily;

0 comments on commit 6d447b1

Please sign in to comment.