diff --git a/client/src/app/core/ui-services/html-to-pdf.service.ts b/client/src/app/core/ui-services/html-to-pdf.service.ts index 310e7e1ff..0b29ce71b 100644 --- a/client/src/app/core/ui-services/html-to-pdf.service.ts +++ b/client/src/app/core/ui-services/html-to-pdf.service.ts @@ -46,6 +46,11 @@ export class HtmlToPdfService { */ private P_MARGIN_BOTTOM = 4.0; + /** + * Space above H + */ + private H_MARGIN_TOP = 10.0; + /** * Conversion of HTML tags into pdfmake directives */ @@ -84,14 +89,44 @@ export class HtmlToPdfService { */ public constructor() {} + /** + * Determine the ideal top margin for a given node + * + * @param nodeName the node to parse + * @returns the margin tip as number + */ + private getMarginTop(nodeName: string): number { + switch (nodeName) { + case 'h1': + case 'h2': + case 'h3': + case 'h4': + case 'h5': + case 'h6': { + return this.H_MARGIN_TOP; + } + default: { + return 0; + } + } + } + /** * Determine the ideal margin for a given node * - * @param nodeName the parsing node + * @param nodeName the node to parse * @returns the margin bottom as number */ private getMarginBottom(nodeName: string): number { switch (nodeName) { + case 'h1': + case 'h2': + case 'h3': + case 'h4': + case 'h5': + case 'h6': { + return this.P_MARGIN_BOTTOM; + } case 'li': { return this.LI_MARGIN_BOTTOM; } @@ -126,6 +161,7 @@ export class HtmlToPdfService { const parsedElement = this.parseElement(child); docDef.push(parsedElement); } + return docDef; } @@ -198,20 +234,28 @@ export class HtmlToPdfService { } newParagraph.margin = [0, 0, 0, 0]; + + // determine the "normal" top and button margins + newParagraph.margin[1] = this.getMarginTop(nodeName); + newParagraph.margin[3] = this.getMarginBottom(nodeName); + if (this.lineNumberingMode === LineNumberingMode.Outside) { // that is usually the case for inserted change which should appear // under a set of line numbers with correct alignment if (classes.includes('insert')) { newParagraph.margin[0] = 20; - newParagraph.margin[1] = this.P_MARGIN_BOTTOM; newParagraph.margin[3] = this.P_MARGIN_BOTTOM; } } + // stop enumeration if the list was inserted if (classes.includes('os-split-before')) { newParagraph.listType = 'none'; - } else if (this.isInsideAList(element)) { - newParagraph.margin[3] = this.getMarginBottom(nodeName); + } + + // if the list ends (usually due to a new insert cr) prevent margins + if (classes.includes('os-split-after')) { + newParagraph.margin[3] = 0; } newParagraph.lineHeight = this.LINE_HEIGHT; @@ -266,10 +310,14 @@ export class HtmlToPdfService { break; } case 'br': { - newParagraph = this.create('text'); - // yep thats all - newParagraph.text = '\n'; - newParagraph.lineHeight = this.LINE_HEIGHT; + if (this.lineNumberingMode === LineNumberingMode.None && classes.includes('os-line-break')) { + break; + } else { + newParagraph = this.create('text'); + // yep thats all + newParagraph.text = '\n'; + newParagraph.lineHeight = this.LINE_HEIGHT; + } break; } case 'ul': @@ -302,15 +350,11 @@ export class HtmlToPdfService { margin: [0, 0, 0, 0] }; - // For correction factor for "change reco" elements in lists, cause - // they open a new OL-List and have additional distance - if ( - element.classList.contains('os-split-before') && - element.classList.contains('os-split-after') - ) { - listCol.margin = [0, -this.LI_MARGIN_BOTTOM, 0, -this.LI_MARGIN_BOTTOM]; - } else if (!element.classList.contains('os-split-before')) { - listCol.margin = [0, 5, 0, 0]; + // This has the effect that changed complex lists will look good with line numbers, + // but simple lists will be too close. The information in the HTML is highly redundant and + // there is currently no clear way to determine what to do with the lists. + if (classes.includes('os-split-after')) { + listCol.margin[3] = -this.LI_MARGIN_BOTTOM; } for (const line of lines) { diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index 82b34eaef..93768140b 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -1205,9 +1205,12 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { * Click handler for the pdf button */ public onDownloadPdf(): void { - const exportCr = this.motion.isStatuteAmendment() ? ChangeRecoMode.Diff : this.crMode; // TODO: apparently statue amendments never have line numbers and are always in crMode - this.pdfExport.exportSingleMotion(this.motion, this.lnMode, exportCr); + if (this.motion.isStatuteAmendment()) { + this.pdfExport.exportSingleMotion(this.motion, LineNumberingMode.None, ChangeRecoMode.Diff); + } else { + this.pdfExport.exportSingleMotion(this.motion, this.lnMode, this.crMode); + } } /**