diff --git a/src/modules/olMap/services/Mfp3Encoder.js b/src/modules/olMap/services/Mfp3Encoder.js index 39362fc433..25067c7d79 100644 --- a/src/modules/olMap/services/Mfp3Encoder.js +++ b/src/modules/olMap/services/Mfp3Encoder.js @@ -726,13 +726,14 @@ export class BvvMfp3Encoder { if (textStyle.getFont()) { const fontValues = textStyle.getFont().split(' '); + const scale = textStyle.getScale() ?? 1; const [weight, size, ...fontFamilyValues] = fontValues; // hint: the fontFamily value relates to all installed font on the server. // If the application use any custom fonts over css-styles which are used // for labels on the map, these fonts must be available as TrueTypeFonts // on the MapFishPrint server encoded.fontFamily = fontFamilyValues.join(' '); - encoded.fontSize = BvvMfp3Encoder.adjustDistance(parseInt(size), dpi); + encoded.fontSize = scale * BvvMfp3Encoder.adjustDistance(parseInt(size), dpi); encoded.fontWeight = weight; } diff --git a/test/modules/olMap/formats/Mfp3Encoder.test.js b/test/modules/olMap/formats/Mfp3Encoder.test.js index bc78780839..b2207d2816 100644 --- a/test/modules/olMap/formats/Mfp3Encoder.test.js +++ b/test/modules/olMap/formats/Mfp3Encoder.test.js @@ -1507,6 +1507,47 @@ describe('BvvMfp3Encoder', () => { }); }); + it('writes a point feature with feature style (text) and scaled font size', () => { + const featureWithScale1 = new Feature({ geometry: new Point([30, 30]) }); + const featureWithScale2 = new Feature({ geometry: new Point([40, 40]) }); + const stylesScaled1 = getTextStyle(); + const stylesScaled2 = getTextStyle(); + stylesScaled1[0].getText().setScale(1); + stylesScaled1[0].getImage().setScale(1); + stylesScaled2[0].getText().setScale(2); + stylesScaled2[0].getImage().setScale(2); + featureWithScale1.setStyle(stylesScaled1); + featureWithScale2.setStyle(stylesScaled2); + const vectorSource = new VectorSource({ wrapX: false, features: [featureWithScale1, featureWithScale2] }); + const vectorLayer = new VectorLayer({ id: 'foo', source: vectorSource, style: null }); + const groupOpacity = 1; + spyOn(vectorLayer, 'getExtent').and.callFake(() => [20, 20, 50, 50]); + const geoResourceMock = getGeoResourceMock(); + spyOn(geoResourceServiceMock, 'byId').and.callFake(() => geoResourceMock); + const encoder = setup(); + encoder._pageExtent = [20, 20, 50, 50]; + const actualSpec = encoder._encodeVector(vectorLayer, groupOpacity); + + expect(actualSpec).toEqual({ + opacity: 1, + type: 'geojson', + name: 'foo', + geoJson: { + features: jasmine.any(Array), + type: 'FeatureCollection' + }, + style: { + version: '2', + '[_gx_style = 0]': { + symbolizers: [jasmine.objectContaining({ type: 'text', fontSize: 16.666666666666668 })] + }, + '[_gx_style = 1]': { + symbolizers: [jasmine.objectContaining({ type: 'text', fontSize: 33.333333333333336 })] + } + } + }); + }); + it('writes a point feature with feature style (text) and alignment (bottom)', () => { const featureWithStyle = new Feature({ geometry: new Point([30, 30]) }); featureWithStyle.setStyle(getTextStyle('left', 'bottom')); @@ -1608,6 +1649,54 @@ describe('BvvMfp3Encoder', () => { }); }); + it('writes a point feature with feature style (text & symbol) with two symbolizers and scaling', () => { + const featureWithScale1 = new Feature({ geometry: new Point([30, 30]) }); + const featureWithScale2 = new Feature({ geometry: new Point([40, 40]) }); + const stylesScaled1 = getTextAndImageStyle('left', 'top'); + const stylesScaled2 = getTextAndImageStyle('left', 'top'); + stylesScaled1[0].getText().setScale(1); + stylesScaled1[0].getImage().setScale(1); + stylesScaled2[0].getText().setScale(2); + stylesScaled2[0].getImage().setScale(2); + featureWithScale1.setStyle(stylesScaled1); + featureWithScale2.setStyle(stylesScaled2); + + const vectorSource = new VectorSource({ wrapX: false, features: [featureWithScale1, featureWithScale2] }); + const vectorLayer = new VectorLayer({ id: 'foo', source: vectorSource, style: null }); + const groupOpacity = 1; + spyOn(vectorLayer, 'getExtent').and.callFake(() => [20, 20, 50, 50]); + const geoResourceMock = getGeoResourceMock(); + spyOn(geoResourceServiceMock, 'byId').and.callFake(() => geoResourceMock); + const encoder = setup(); + encoder._pageExtent = [20, 20, 50, 50]; + const actualSpec = encoder._encodeVector(vectorLayer, groupOpacity); + + expect(actualSpec).toEqual({ + opacity: 1, + type: 'geojson', + name: 'foo', + geoJson: { + features: jasmine.any(Array), + type: 'FeatureCollection' + }, + style: { + version: '2', + '[_gx_style = 0]': { + symbolizers: [ + jasmine.objectContaining({ type: 'point', graphicHeight: 70 }), + jasmine.objectContaining({ type: 'text', fontSize: 16.666666666666668 }) + ] + }, + '[_gx_style = 1]': { + symbolizers: [ + jasmine.objectContaining({ type: 'point', graphicHeight: 140 }), + jasmine.objectContaining({ type: 'text', fontSize: 33.333333333333336 }) + ] + } + } + }); + }); + it('writes a point feature with feature style function', () => { const featureWithStyle = new Feature({ geometry: new Point([30, 30]) }); featureWithStyle.setStyle(() => getStyle());