Skip to content

Commit

Permalink
refactor: Print defaults visible in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner committed Feb 13, 2024
1 parent 91def9c commit b496a56
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const TEXT_STYLING_OPTIONS = {
textSizes: [
'9px',
'10px',
'13px',
'12px',
'16px',
'18px',
'24px',
Expand All @@ -46,5 +46,7 @@ export const TEXT_STYLING_OPTIONS = {
'46px',
'48px',
'72px',
'84px',
'96px',
],
};
16 changes: 3 additions & 13 deletions projects/hslayers/components/print/print-imprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class HsPrintImprintService {
*/
private imprintToSvg(imprintObj: ImprintObj): string {
const styles = this.getStyles(imprintObj.textStyle);
const height = imprintObj.height ?? 50;
const width = imprintObj.width ?? 150;
const height = imprintObj.height;
const width = imprintObj.width;
const svgSource = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}px' height='${height}px'>
<foreignObject width='100%' height='100%'>
<div xmlns='http://www.w3.org/1999/xhtml' style="${styles}">
Expand All @@ -70,17 +70,7 @@ export class HsPrintImprintService {
} else {
tmpStyle += 'text-align:center;';
}
if (!textStyle.textSize) {
textStyle.textSize = '12px';
}
if (!textStyle.fontFamily) {
textStyle.fontFamily = 'Times New Roman';
}
if (textStyle.textColor) {
tmpStyle += `color: ${textStyle.textColor};`;
} else {
tmpStyle += `color:black;`;
}

if (textStyle.bcColor) {
tmpStyle += `background-color: ${textStyle.bcColor};`;
}
Expand Down
4 changes: 2 additions & 2 deletions projects/hslayers/components/print/print-legend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class HsPrintLegendService extends PrintLegendParams {
async drawLegendCanvas(legendObj: LegendObj): Promise<HTMLCanvasElement> {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
this.legendWidth = legendObj.width || 200; //Needs to have some default width if none is set
this.legendWidth = legendObj.width;
const legendImages = await this.getLegendImages();
if (legendImages?.length > 0) {
const canvasHeight = legendImages
Expand Down Expand Up @@ -122,7 +122,7 @@ export class HsPrintLegendService extends PrintLegendParams {
legendObj: LegendObj,
): void {
const ctx = canvas.getContext('2d');
ctx.fillStyle = legendObj.bcColor || 'white';
ctx.fillStyle = legendObj.bcColor;
ctx.rect(0, 0, canvas.width, canvas.height);
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
Expand Down
6 changes: 0 additions & 6 deletions projects/hslayers/components/print/print-title.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ export class HsPrintTitleService {
ctx: CanvasRenderingContext2D,
textStyle: TextStyle,
): void {
if (!textStyle.textSize) {
textStyle.textSize = '30px';
}
if (!textStyle.fontFamily) {
textStyle.fontFamily = 'Times New Roman';
}
ctx.font = textStyle.fontStyle.concat(
' ',
textStyle.textSize,
Expand Down
46 changes: 23 additions & 23 deletions projects/hslayers/components/print/print.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,43 @@ export class HsPrintComponent extends HsPanelBaseComponent implements OnInit {
titleObj: {
text: '',
textStyle: {
textColor: '',
textSize: '',
fontFamily: '',
fontStyle: '',
textDraw: null,
posX: null,
posY: null,
textColor: 'black',
textSize: '30px',
fontFamily: 'Times New Roman',
fontStyle: 'normal',
textDraw: 'fill',
posX: 'center',
posY: 'top',
},
},
scaleObj: {
include: false,
scaleType: null,
scaleType: 'scaleline',
scaleBarText: null,
scaleBarSteps: null,
scaleUnits: null,
scaleBarSteps: 4,
scaleUnits: 'metric',
},
legendObj: {
include: false,
width: null,
bcColor: '',
posX: null,
posY: null,
width: 200,
bcColor: 'white',
posX: 'right',
posY: 'bottom',
},
imprintObj: {
include: false,
author: '',
abstract: '',
width: null,
height: null,
width: 100,
height: 50,
textStyle: {
textColor: '',
bcColor: '',
textSize: '',
fontFamily: '',
fontStyle: '',
posX: null,
posY: null,
textColor: 'black',
bcColor: 'transparent',
textSize: '12px',
fontFamily: 'Times New Roman',
fontStyle: 'normal',
posX: 'center',
posY: 'bottom',
},
},
};
Expand Down
10 changes: 5 additions & 5 deletions projects/hslayers/components/print/print.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class HsPrintService {
composition,
tCanvas,
print.titleObj.textStyle.posX,
print.titleObj.textStyle.posY ?? 'top',
print.titleObj.textStyle.posY,
);
ctx.drawImage(tCanvas, textPos[0], textPos[1]);
}
Expand All @@ -122,8 +122,8 @@ export class HsPrintService {
const legendPos = this.getChildPosition(
composition,
lCanvas,
print.legendObj.posX ?? 'right',
print.legendObj.posY ?? 'bottom',
print.legendObj.posX,
print.legendObj.posY,
);
ctx.drawImage(lCanvas, legendPos[0], legendPos[1]);
}
Expand All @@ -139,8 +139,8 @@ export class HsPrintService {
const imprintPos = this.getChildPosition(
composition,
iCanvas,
print.imprintObj.textStyle.posX ?? 'center',
print.imprintObj.textStyle.posY ?? 'bottom',
print.imprintObj.textStyle.posX,
print.imprintObj.textStyle.posY,
);
ctx.drawImage(iCanvas, imprintPos[0], imprintPos[1]);
}
Expand Down

0 comments on commit b496a56

Please sign in to comment.