Skip to content

Commit 7519984

Browse files
authored
change default font to sans-serif and fix textFaceName with space but without quotation marks (#2199)
1 parent d740531 commit 7519984

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/core/util/strings.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function getAlignPoint(size, horizontalAlignment, verticalAlignment) {
223223
}
224224

225225
//export it for plugin develop
226-
export const DEFAULT_FONT = 'monospace';
226+
export const DEFAULT_FONT = 'sans-serif';
227227
export const DEFAULT_TEXTSIZE = 14;
228228

229229
/**
@@ -243,10 +243,25 @@ export function getFont(style) {
243243
return (style['textStyle'] && style['textStyle'] !== 'normal' ? style['textStyle'] + ' ' : '') +
244244
(style['textWeight'] && style['textWeight'] !== 'normal' ? style['textWeight'] + ' ' : '') +
245245
textSize + 'px ' +
246-
(style['textFaceName'] ? style['textFaceName'] : DEFAULT_FONT);
246+
(style['textFaceName'] && formatFontFamily(style['textFaceName']) || DEFAULT_FONT);
247247
}
248248
}
249249

250+
function formatFontFamily(font) {
251+
const fonts = font.split(',');
252+
for (let i = 0; i < fonts.length; i++) {
253+
if (fonts[i].trim) {
254+
fonts[i] = fonts[i].trim();
255+
}
256+
// quote font name with space
257+
// e.g. "Gill Sans Extrabold", sans-serif
258+
if (fonts[i].indexOf(' ') > 0 && fonts[i][0] !== '"' && fonts[i][0] !== '\'') {
259+
fonts[i] = '"' + fonts[i] + '"';
260+
}
261+
}
262+
return fonts.join(',');
263+
}
264+
250265
/**
251266
* Split a text to multiple rows according to the style.
252267
* @param {String} text - text to split

src/ui/UIMarker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class UIMarker extends Handlerable(UIComponent) {
326326

327327
onAdd() {
328328
if (this._owner && !this._owner.isMap) {
329-
throw new Error('UIMarker Can only be added to the map, but owner is:', this._owner.getJSONType());
329+
throw new Error('UIMarker Can only be added to the map, but owner is:', this._owner.getJSONType && this._owner.getJSONType());
330330
}
331331
this.show();
332332
return this;

0 commit comments

Comments
 (0)