@imposium-hub/components 1.38.5 → 1.38.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,6 +12,7 @@ interface ITextLayerProps {
|
|
|
12
12
|
|
|
13
13
|
interface ITextLayerState {
|
|
14
14
|
fontLoaded : boolean;
|
|
15
|
+
fontError : boolean;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export default class TextLayer extends React.PureComponent<ITextLayerProps, ITextLayerState> {
|
|
@@ -23,6 +24,7 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
23
24
|
super(props);
|
|
24
25
|
|
|
25
26
|
this.state = {
|
|
27
|
+
fontError: false,
|
|
26
28
|
fontLoaded: false
|
|
27
29
|
};
|
|
28
30
|
|
|
@@ -89,11 +91,15 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
89
91
|
if (font_type === FONT_TYPES.CUSTOM && font_size && custom_font_url) {
|
|
90
92
|
|
|
91
93
|
const fontOrigin = s3Url(custom_font_url, ASSET_DISTRO, ASSET_ORIGIN);
|
|
92
|
-
|
|
94
|
+
let fontLoaded = false;
|
|
93
95
|
// Not sure why you need to pass the size in here, but .check() throws an error without it.
|
|
94
|
-
|
|
96
|
+
try {
|
|
97
|
+
fontLoaded = document.fonts.check(`${font_size}px ${font}`);
|
|
98
|
+
} catch {
|
|
99
|
+
this.errorLoadingFont();
|
|
100
|
+
}
|
|
95
101
|
|
|
96
|
-
if (!
|
|
102
|
+
if (!fontLoaded) {
|
|
97
103
|
this.setState({
|
|
98
104
|
fontLoaded: false
|
|
99
105
|
}, () => {
|
|
@@ -158,7 +164,12 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
158
164
|
}
|
|
159
165
|
|
|
160
166
|
private errorLoadingFont() {
|
|
161
|
-
|
|
167
|
+
|
|
168
|
+
this.setState({
|
|
169
|
+
fontError: true
|
|
170
|
+
}, () => {
|
|
171
|
+
this.fontReady();
|
|
172
|
+
});
|
|
162
173
|
}
|
|
163
174
|
|
|
164
175
|
private fontReady() {
|
|
@@ -187,6 +198,8 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
187
198
|
const {options: {color, background_color, line_height, word_spacing,
|
|
188
199
|
letter_spacing, font_size, font, horizontal_alignment, vertical_alignment, text_wrap}} = this.props;
|
|
189
200
|
|
|
201
|
+
const {fontError} = this.state;
|
|
202
|
+
|
|
190
203
|
const whiteSpace = (text_wrap) ? 'normal' : 'nowrap';
|
|
191
204
|
const lS = (letter_spacing) ? `${letter_spacing}px` : 'normal';
|
|
192
205
|
const wS = (word_spacing) ? `${word_spacing}px` : 'normal';
|
|
@@ -200,7 +213,7 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
200
213
|
letterSpacing: lS,
|
|
201
214
|
fontSize: fS,
|
|
202
215
|
whiteSpace: whiteSpace as any,
|
|
203
|
-
fontFamily: font
|
|
216
|
+
fontFamily: (!fontError) ? font : 'Arial, helvetica, sans-serif'
|
|
204
217
|
};
|
|
205
218
|
|
|
206
219
|
const wrapperStyle = {
|