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 authored and jmacura committed Feb 9, 2024
1 parent 49d449c commit b83b696
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export const TEXT_STYLING_OPTIONS = {
textSizes: [
'9px',
'10px',
'13px',
'12px',
'16px',
'18px',
'24px',
'30px',
'32px',
'40px',
'46px',
'48px',
'64px',
'72px',
'84px',
'96px',
],
};
18 changes: 2 additions & 16 deletions projects/hslayers/src/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,20 +70,6 @@ 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};`;
}
tmpStyle += `font:${textStyle.fontStyle.concat(
' ',
textStyle.textSize,
Expand Down
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/src/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/src/components/print/print.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,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
15 changes: 9 additions & 6 deletions projects/hslayers/src/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,22 +122,25 @@ 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]);
}
}
if (print.imprintObj?.include && print.imprintObj?.author || print.imprintObj?.abstract) {
if (
(print.imprintObj?.include && print.imprintObj?.author) ||
print.imprintObj?.abstract
) {
const iCanvas = await this.hsPrintImprintService.drawImprintCanvas(
print.imprintObj,
);
if (iCanvas) {
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 b83b696

Please sign in to comment.