Add line-numbering fix
Also enabled li-elements to be rendered in LineNumbering Mode
This commit is contained in:
parent
7dd086eacf
commit
4ce8f2b38f
@ -75,6 +75,23 @@ export class HtmlToPdfService {
|
|||||||
*/
|
*/
|
||||||
public constructor() {}
|
public constructor() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the ideal margin for a given node
|
||||||
|
*
|
||||||
|
* @param nodeName the parsing node
|
||||||
|
* @returns the margin bottom as number
|
||||||
|
*/
|
||||||
|
private getMarginBottom(nodeName: string): number {
|
||||||
|
switch (nodeName) {
|
||||||
|
case 'li': {
|
||||||
|
return this.LI_MARGIN_BOTTOM;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return this.P_MARGIN_BOTTOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an HTML string, converts to HTML using a DOM parser and recursivly parses
|
* Takes an HTML string, converts to HTML using a DOM parser and recursivly parses
|
||||||
* the content into pdfmake compatible doc definition
|
* the content into pdfmake compatible doc definition
|
||||||
@ -154,8 +171,10 @@ export class HtmlToPdfService {
|
|||||||
case 'h4':
|
case 'h4':
|
||||||
case 'h5':
|
case 'h5':
|
||||||
case 'h6':
|
case 'h6':
|
||||||
case 'p': {
|
case 'li':
|
||||||
const children = this.parseChildren(element, newParagraph);
|
case 'p':
|
||||||
|
case 'div': {
|
||||||
|
const children = this.parseChildren(element, styles);
|
||||||
|
|
||||||
if (this.lineNumberingMode === LineNumberingMode.Outside) {
|
if (this.lineNumberingMode === LineNumberingMode.Outside) {
|
||||||
newParagraph = this.create('stack');
|
newParagraph = this.create('stack');
|
||||||
@ -165,15 +184,14 @@ export class HtmlToPdfService {
|
|||||||
newParagraph.text = children;
|
newParagraph.text = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
newParagraph.margin = [0, this.P_MARGIN_BOTTOM];
|
newParagraph.margin = [0, this.getMarginBottom(nodeName)];
|
||||||
newParagraph.lineHeight = this.LINE_HEIGHT;
|
newParagraph.lineHeight = this.LINE_HEIGHT;
|
||||||
|
|
||||||
styles = this.computeStyle(styles);
|
|
||||||
const implicitStyles = this.computeStyle(this.elementStyles[nodeName]);
|
const implicitStyles = this.computeStyle(this.elementStyles[nodeName]);
|
||||||
|
|
||||||
newParagraph = {
|
newParagraph = {
|
||||||
...newParagraph,
|
...newParagraph,
|
||||||
...styles,
|
...this.computeStyle(styles),
|
||||||
...implicitStyles
|
...implicitStyles
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
@ -240,19 +258,6 @@ export class HtmlToPdfService {
|
|||||||
newParagraph.lineHeight = this.LINE_HEIGHT;
|
newParagraph.lineHeight = this.LINE_HEIGHT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'li':
|
|
||||||
case 'div': {
|
|
||||||
newParagraph = this.create('text');
|
|
||||||
newParagraph.lineHeight = this.LI_MARGIN_BOTTOM;
|
|
||||||
newParagraph = {
|
|
||||||
...newParagraph,
|
|
||||||
...this.computeStyle(styles)
|
|
||||||
};
|
|
||||||
|
|
||||||
const children = this.parseChildren(element, styles);
|
|
||||||
newParagraph.text = children;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ul':
|
case 'ul':
|
||||||
case 'ol': {
|
case 'ol': {
|
||||||
newParagraph = this.create(nodeName);
|
newParagraph = this.create(nodeName);
|
||||||
|
@ -1155,7 +1155,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
|
|||||||
public onDownloadPdf(): void {
|
public onDownloadPdf(): void {
|
||||||
const exportCr = this.motion.isStatuteAmendment() ? ChangeRecoMode.Diff : this.crMode;
|
const exportCr = this.motion.isStatuteAmendment() ? ChangeRecoMode.Diff : this.crMode;
|
||||||
// TODO: apparently statue amendments never have line numbers and are always in crMode
|
// TODO: apparently statue amendments never have line numbers and are always in crMode
|
||||||
this.pdfExport.exportSingleMotion(this.motion, LineNumberingMode.None, exportCr);
|
this.pdfExport.exportSingleMotion(this.motion, this.lnMode, exportCr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,7 @@ import { MotionRepositoryService } from 'app/core/repositories/motions/motion-re
|
|||||||
import { StatuteParagraphRepositoryService } from 'app/core/repositories/motions/statute-paragraph-repository.service';
|
import { StatuteParagraphRepositoryService } from 'app/core/repositories/motions/statute-paragraph-repository.service';
|
||||||
import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion';
|
import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion';
|
||||||
import { ViewUnifiedChange } from '../models/view-unified-change';
|
import { ViewUnifiedChange } from '../models/view-unified-change';
|
||||||
|
import { LinenumberingService } from 'app/core/ui-services/linenumbering.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type declaring which strings are valid options for metainfos to be exported into a pdf
|
* Type declaring which strings are valid options for metainfos to be exported into a pdf
|
||||||
@ -41,6 +42,7 @@ export class MotionPdfService {
|
|||||||
* @param configService Read config variables
|
* @param configService Read config variables
|
||||||
* @param htmlToPdfService To convert HTML text into pdfmake doc def
|
* @param htmlToPdfService To convert HTML text into pdfmake doc def
|
||||||
* @param pollService MotionPollService for rendering the polls
|
* @param pollService MotionPollService for rendering the polls
|
||||||
|
* @param linenumberingService Line numbers
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
@ -49,7 +51,8 @@ export class MotionPdfService {
|
|||||||
private changeRecoRepo: ChangeRecommendationRepositoryService,
|
private changeRecoRepo: ChangeRecommendationRepositoryService,
|
||||||
private configService: ConfigService,
|
private configService: ConfigService,
|
||||||
private htmlToPdfService: HtmlToPdfService,
|
private htmlToPdfService: HtmlToPdfService,
|
||||||
private pollService: MotionPollService
|
private pollService: MotionPollService,
|
||||||
|
private linenumberingService: LinenumberingService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -436,6 +439,8 @@ export class MotionPdfService {
|
|||||||
// order of changes applied to the motion
|
// order of changes applied to the motion
|
||||||
changes.sort((a, b) => a.getLineFrom() - b.getLineFrom());
|
changes.sort((a, b) => a.getLineFrom() - b.getLineFrom());
|
||||||
motionText = this.motionRepo.formatMotion(motion.id, crMode, changes, lineLength);
|
motionText = this.motionRepo.formatMotion(motion.id, crMode, changes, lineLength);
|
||||||
|
// reformat motion text to split long HTML elements to easier convert into PDF
|
||||||
|
motionText = this.linenumberingService.splitInlineElementsAtLineBreaks(motionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.htmlToPdfService.convertHtml(motionText, lnMode);
|
return this.htmlToPdfService.convertHtml(motionText, lnMode);
|
||||||
|
Loading…
Reference in New Issue
Block a user