More reliable text/stack defintion in cr pdf

Motion pdfs with line numbers, CR/Amendment and bullet points with
multiple changes have a better chance to produce expected results
This commit is contained in:
Sean 2020-09-17 18:11:45 +02:00
parent 909a7539c5
commit 6007799f1d

View File

@ -32,11 +32,6 @@ export class HtmlToPdfService {
*/ */
private lineNumberingMode: LineNumberingMode; private lineNumberingMode: LineNumberingMode;
/**
* Space between list elements
*/
private LI_MARGIN_BOTTOM = 8;
/** /**
* Normal line height for paragraphs * Normal line height for paragraphs
*/ */
@ -192,6 +187,8 @@ export class HtmlToPdfService {
*/ */
public parseElement(element: Element, styles?: string[]): any { public parseElement(element: Element, styles?: string[]): any {
const nodeName = element.nodeName.toLowerCase(); const nodeName = element.nodeName.toLowerCase();
const childNodes = Array.from(element.childNodes) as Element[];
const directChildIsCrNode = childNodes.some(child => this.isCrElement(child));
let classes = []; let classes = [];
let newParagraph: any; let newParagraph: any;
@ -237,7 +234,12 @@ export class HtmlToPdfService {
case 'div': { case 'div': {
const children = this.parseChildren(element, styles); const children = this.parseChildren(element, styles);
if (this.lineNumberingMode === LineNumberingMode.Outside && !classes.includes('insert')) { if (
this.lineNumberingMode === LineNumberingMode.Outside &&
!classes.includes('insert') &&
!(nodeName === 'li' && directChildIsCrNode)
) {
//
newParagraph = this.create('stack'); newParagraph = this.create('stack');
newParagraph.stack = children; newParagraph.stack = children;
} else { } else {
@ -367,7 +369,7 @@ export class HtmlToPdfService {
// if this is a "fake list" lower put it close to the element above // if this is a "fake list" lower put it close to the element above
if (this.isFakeList(element)) { if (this.isFakeList(element)) {
listCol.margin[3] = -this.LI_MARGIN_BOTTOM; listCol.margin[3] = -this.P_MARGIN_BOTTOM;
} }
for (const line of lines) { for (const line of lines) {
@ -501,7 +503,7 @@ export class HtmlToPdfService {
children[i].remove(); children[i].remove();
} }
if (children[i].childNodes.length > 0) { if (children[i]?.childNodes.length > 0) {
const cleanChildren = this.cleanLineNumbers(children[i] as Element); const cleanChildren = this.cleanLineNumbers(children[i] as Element);
elementCopy.replaceChild(cleanChildren, children[i]); elementCopy.replaceChild(cleanChildren, children[i]);
} }
@ -689,6 +691,16 @@ export class HtmlToPdfService {
return styleObject; return styleObject;
} }
/**
* Detect if the given element is a cr exclusive node
* @param child
*/
private isCrElement(element: Element): boolean {
const nodeName = element.nodeName.toLowerCase();
const crNodeNames = ['ins', 'del'];
return crNodeNames.includes(nodeName);
}
/** /**
* Returns the color in a hex format (e.g. #12ff00). * Returns the color in a hex format (e.g. #12ff00).
* Also tries to convert RGB colors into hex values * Also tries to convert RGB colors into hex values