Skip to content

Fix font #2199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/core/util/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function getAlignPoint(size, horizontalAlignment, verticalAlignment) {
}

//export it for plugin develop
export const DEFAULT_FONT = 'monospace';
export const DEFAULT_FONT = 'sans-serif';
export const DEFAULT_TEXTSIZE = 14;

/**
Expand All @@ -243,10 +243,25 @@ export function getFont(style) {
return (style['textStyle'] && style['textStyle'] !== 'normal' ? style['textStyle'] + ' ' : '') +
(style['textWeight'] && style['textWeight'] !== 'normal' ? style['textWeight'] + ' ' : '') +
textSize + 'px ' +
(style['textFaceName'] ? style['textFaceName'] : DEFAULT_FONT);
(style['textFaceName'] && formatFontFamily(style['textFaceName']) || DEFAULT_FONT);
}
}

function formatFontFamily(font) {
const fonts = font.split(',');
for (let i = 0; i < fonts.length; i++) {
if (fonts[i].trim) {
fonts[i] = fonts[i].trim();
}
// quote font name with space
// e.g. "Gill Sans Extrabold", sans-serif
if (fonts[i].indexOf(' ') > 0 && fonts[i][0] !== '"' && fonts[i][0] !== '\'') {
fonts[i] = '"' + fonts[i] + '"';
}
}
return fonts.join(',');
}

/**
* Split a text to multiple rows according to the style.
* @param {String} text - text to split
Expand Down
2 changes: 1 addition & 1 deletion src/ui/UIMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class UIMarker extends Handlerable(UIComponent) {

onAdd() {
if (this._owner && !this._owner.isMap) {
throw new Error('UIMarker Can only be added to the map, but owner is:', this._owner.getJSONType());
throw new Error('UIMarker Can only be added to the map, but owner is:', this._owner.getJSONType && this._owner.getJSONType());
}
this.show();
return this;
Expand Down