From fc185e2eeb7594c9e8d0127c56ee3470e023ee68 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 10 Oct 2017 10:13:47 +0200 Subject: [PATCH] Fixing multiline headers in PDF --- openslides/core/static/js/core/pdf.js | 52 ++++++++++++--------- openslides/motions/static/js/motions/pdf.js | 2 +- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/openslides/core/static/js/core/pdf.js b/openslides/core/static/js/core/pdf.js index 7c0fc5761..eb64894da 100644 --- a/openslides/core/static/js/core/pdf.js +++ b/openslides/core/static/js/core/pdf.js @@ -658,30 +658,38 @@ angular.module('OpenSlidesApp.core.pdf', []) case "h4": case "h5": case "h6": - // Special case quick fix to handle the dirty HTML format*/ - // see following issue: https://github.com/OpenSlides/OpenSlides/issues/3025 if (lineNumberMode === "outside" && element.childNodes.length > 0 && element.childNodes[0].getAttribute) { - var HeaderOutsideLineNumber = { - width: 20, - text: element.childNodes[0].getAttribute("data-line-number"), - color: "gray", - fontSize: 8, - margin: [0, 2, 0, 0] - }; - var HeaderOutsideLineNumberText = { - text: element.childNodes[1].textContent, - }; - ComputeStyle(HeaderOutsideLineNumberText, elementStyles[nodeName]); - var HeaderOutsideLineNumberColumns = { - columns: [ - HeaderOutsideLineNumber, - HeaderOutsideLineNumberText - ], - margin: [0, 11, 0, 0] - }; - alreadyConverted.push(HeaderOutsideLineNumberColumns); + // A heading may have multiple lines, so handle line by line separated by line number elements + var outerStack = create("stack"); + var currentCol; + _.forEach(element.childNodes, function (node) { + if (node.getAttribute && node.getAttribute('data-line-number')) { + if (currentCol) { + ComputeStyle(currentCol, elementStyles[nodeName]); + outerStack.stack.push(currentCol); + } + currentCol = { + columns: [ + getLineNumberObject(node.getAttribute('data-line-number')), + ], + margin: [0, 2, 0, 0], + }; + } else if (node.textContent) { + var HeaderText = { + text: node.textContent, + }; + currentCol.columns.push(HeaderText); + } + }); + ComputeStyle(currentCol, elementStyles[nodeName]); + outerStack.stack.push(currentCol); + outerStack.margin = [0, 0, 0, 0]; + if (!/h[1-6]/.test(element.previousSibling.nodeName.toLowerCase())) { + outerStack.margin[1] = 10; + } + alreadyConverted.push(outerStack); } else { currentParagraph = create("text"); currentParagraph.marginBottom = 4; @@ -855,7 +863,7 @@ angular.module('OpenSlidesApp.core.pdf', []) break; case "img": var regex = /([\w-]*)\s*:\s*([^;]*)/g; - var match; //helper variable for the refegex + var match; //helper variable for the regex var imageSize={}; var maxResolution = { width: 435, diff --git a/openslides/motions/static/js/motions/pdf.js b/openslides/motions/static/js/motions/pdf.js index 6c92668ae..0936259e6 100644 --- a/openslides/motions/static/js/motions/pdf.js +++ b/openslides/motions/static/js/motions/pdf.js @@ -300,7 +300,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf']) style: 'heading3', marginTop: 25, }); - reason.push(converter.convertHTML(motion.getReason(motionVersion), lineNumberMode)); + reason.push(converter.convertHTML(motion.getReason(motionVersion), 'none')); } return reason; }