From b6bdd70d2ea2def70b52b10c7a98c52f7d9b95c8 Mon Sep 17 00:00:00 2001 From: Johannes Weskamm Date: Fri, 24 Mar 2023 15:32:11 +0100 Subject: [PATCH] address review comments --- data/styles/point_styledLabel_static.ts | 4 +--- src/OlStyleParser.spec.ts | 2 +- src/OlStyleParser.ts | 15 ++++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/data/styles/point_styledLabel_static.ts b/data/styles/point_styledLabel_static.ts index 0242e06d..d70a5d9f 100644 --- a/data/styles/point_styledLabel_static.ts +++ b/data/styles/point_styledLabel_static.ts @@ -14,9 +14,7 @@ const pointStyledLabel: Style = { offset: [0, 5], haloColor: '#000000', haloWidth: 5, - rotate: 45, - fontStyle: 'normal', - fontWeight: 'normal' + rotate: 45 }] } ] diff --git a/src/OlStyleParser.spec.ts b/src/OlStyleParser.spec.ts index 4089d73b..9f9894b6 100644 --- a/src/OlStyleParser.spec.ts +++ b/src/OlStyleParser.spec.ts @@ -368,7 +368,7 @@ describe('OlStyleParser implements StyleParser', () => { const fontFamily = [ ['arial', 'sans-serif'], ['Georgia', 'serif'], - ['Neue Helvetica', 'Helvetica', 'sans-serif'] + ['"Neue Helvetica"', 'Helvetica', 'sans-serif'] ]; const font1 = `bold 5px ${fontFamily[0].join(', ')}`; const font2 = `italic bold 12px/30px ${fontFamily[1].join(', ')}`; diff --git a/src/OlStyleParser.ts b/src/OlStyleParser.ts index 5dc07fe4..483dd307 100644 --- a/src/OlStyleParser.ts +++ b/src/OlStyleParser.ts @@ -407,22 +407,23 @@ export class OlStyleParser implements StyleParser { const label = Array.isArray(text) ? text[0] : text; let fontSize: number = Infinity; let fontFamily: string[]|undefined = undefined; - let fontWeight: 'normal' | 'bold' = 'normal'; - let fontStyle: 'normal' | 'italic' | 'oblique' = 'normal'; + let fontWeight: 'normal' | 'bold' | undefined = undefined; + let fontStyle: 'normal' | 'italic' | 'oblique' | undefined = undefined; if (font) { const fontObj = parseFont(font); if (fontObj['font-weight']) { - fontWeight = fontObj['font-weight'] as 'normal' | 'bold'; + fontWeight = fontObj['font-weight']; } if (fontObj['font-size']) { fontSize = parseInt(fontObj['font-size'], 10); } if (fontObj['font-family']) { - fontFamily = fontObj['font-family']; + const fontFamilies = fontObj['font-family']; + fontFamily = fontFamilies?.map((f: string) => f.includes(' ') ? '"' + f + '"' : f); } if (fontObj['font-style']) { - fontStyle = fontObj['font-style'] as 'normal' | 'italic' | 'oblique'; + fontStyle = fontObj['font-style']; } } @@ -433,8 +434,8 @@ export class OlStyleParser implements StyleParser { color: olFillStyle ? OlStyleUtil.getHexColor(olFillStyle.getColor() as string) : undefined, size: isFinite(fontSize) ? fontSize : undefined, font: fontFamily, - fontWeight, - fontStyle, + fontWeight: fontWeight || undefined, + fontStyle: fontStyle || undefined, offset: (offsetX !== undefined) && (offsetY !== undefined) ? [offsetX, offsetY] : [0, 0], haloColor: olStrokeStyle && olStrokeStyle.getColor() ? OlStyleUtil.getHexColor(olStrokeStyle.getColor() as string) : undefined,