From cc5ff21005cf9a131487fcc470598c835c34c1e9 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Tue, 6 Sep 2016 11:52:27 +0200 Subject: [PATCH 1/2] Add line numbers to pdf (fixes #2300) --- openslides/core/static/js/core/site.js | 67 ++++++++++++++++---- openslides/motions/static/js/motions/site.js | 47 ++++++++++---- 2 files changed, 86 insertions(+), 28 deletions(-) diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index a264914fd..88c600baa 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -49,7 +49,7 @@ angular.module('OpenSlidesApp.core.site', [ { fontSize: 6, width: '30%', - text: gettextCatalog.getString('As of') + date.toLocaleDateString() + " " + date.toLocaleTimeString(), + text: gettextCatalog.getString('As of') + " " + date.toLocaleDateString() + " " + date.toLocaleTimeString(), alignment: 'right' }] }; @@ -78,9 +78,9 @@ angular.module('OpenSlidesApp.core.site', [ pageSize: 'A4', pageMargins: [80, 90, 80, 60], defaultStyle: { - font: defaultFont + font: defaultFont, + fontSize: 10 }, - fontSize: 8, header: header, footer: footer, content: content, @@ -152,7 +152,7 @@ angular.module('OpenSlidesApp.core.site', [ * @function * @param {object} html - html */ - convertHTML = function(html) { + convertHTML = function(html, scope) { var elementStyles = { "b": ["font-weight:bold"], "strong": ["font-weight:bold"], @@ -338,21 +338,59 @@ angular.module('OpenSlidesApp.core.site', [ alreadyConverted.push(st); break; case "span": - parseChildren(alreadyConverted, element, currentParagraph, styles); + if (scope.lineNumberMode == "inline") { + var lineNumberInline = element.getAttribute("data-line-number"), + lineNumberObjInline = { + text: lineNumberInline, + color: "gray", + fontSize: 5 + }; + currentParagraph.text.push(lineNumberObjInline); + parseChildren(alreadyConverted, element, currentParagraph, styles); + } else if (scope.lineNumberMode == "outside") { + var lineNumberOutline = element.getAttribute("data-line-number"), + lineNumberObject = { + width: 20, + text: lineNumberOutline, + color: "gray" + }, + col = { + columns: [ + lineNumberObject, + ] + }; + currentParagraph = create("text"); + col.columns.push(currentParagraph); + parseChildren(col.columns[0], element, currentParagraph, styles); + alreadyConverted.push(col); + } else { + parseChildren(alreadyConverted, element, currentParagraph, styles); + } break; case "br": - currentParagraph = create("text"); - alreadyConverted.push(currentParagraph); + //in case of inline-line-numbers and the os-line-break class ignore the break + if (!(scope.lineNumberMode == "inline" && element.getAttribute("class") == "os-line-break")) { + currentParagraph = create("text"); + alreadyConverted.push(currentParagraph); + } break; case "li": case "div": + currentParagraph = create("text"); + var stackDiv = create("stack"); + stackDiv.stack.push(currentParagraph); + ComputeStyle(stackDiv, styles); + parseChildren(stackDiv.stack, element, currentParagraph); + alreadyConverted.push(stackDiv); + break; case "p": currentParagraph = create("text"); - var stack = create("stack"); - stack.stack.push(currentParagraph); - ComputeStyle(stack, styles); - parseChildren(stack.stack, element, currentParagraph); - alreadyConverted.push(stack); + currentParagraph.margin = [0,5]; + var stackP = create("stack"); + stackP.stack.push(currentParagraph); + ComputeStyle(stackP, styles); + parseChildren(stackP.stack, element, currentParagraph); + alreadyConverted.push(stackP); break; case "img": alreadyConverted.push({ @@ -373,8 +411,9 @@ angular.module('OpenSlidesApp.core.site', [ break; default: var temporary = create("text", element.textContent.replace(/\n/g, "")); - if (styles) + if (styles) { ComputeStyle(temporary, styles); + } currentParagraph.text.push(temporary); break; } @@ -390,7 +429,7 @@ angular.module('OpenSlidesApp.core.site', [ var html = $(htmlText.replace(/\t/g, "").replace(/\n/g, "")); var emptyParagraph = create("text"); slice(html).forEach(function(element) { - ParseElement(converted, element, emptyParagraph); + ParseElement(converted, element); }); }, content = []; diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index a33436746..11fdf5dfe 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -17,7 +17,17 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid * @param {object} $scope - Current $scope */ var textContent = function(motion, $scope) { - return converter.convertHTML(motion.getText($scope.version)); + if ($scope.lineNumberMode == "inline" || $scope.lineNumberMode == "outside") { + /* in order to distinguish between the line-number-types we need to pass the scope + * to the convertHTML function. + * We should avoid this, since this completly breaks compatibilty for every + * other project that might want to use this HTML to PDF parser. + * https://github.com/OpenSlides/OpenSlides/issues/2361 + */ + return converter.convertHTML($scope.lineBrokenText, $scope); + } else { + return converter.convertHTML(motion.getText($scope.version), $scope); + } }, /** * Generate text of reason @@ -26,7 +36,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid * @param {object} $scope - Current $scope */ reasonContent = function(motion, $scope) { - return converter.convertHTML(motion.getReason($scope.version)); + return converter.convertHTML(motion.getReason($scope.version), $scope); }, /** * Generate header text of motion @@ -162,15 +172,25 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid * @param {object} User - Current user */ getContent = function(motion, $scope, User) { - return [ - motionHeader(motion, $scope), - signment(motion, $scope, User), - polls(motion, $scope), - titleSection(motion, $scope), - textContent(motion, $scope), - reason(motion, $scope), - reasonContent(motion, $scope) - ]; + if (reasonContent(motion, $scope).length === 0 ) { + return [ + motionHeader(motion, $scope), + signment(motion, $scope, User), + polls(motion, $scope), + titleSection(motion, $scope), + textContent(motion, $scope), + ]; + } else { + return [ + motionHeader(motion, $scope), + signment(motion, $scope, User), + polls(motion, $scope), + titleSection(motion, $scope), + textContent(motion, $scope), + reason(motion, $scope), + reasonContent(motion, $scope) + ]; + } }; return { getContent: getContent @@ -840,9 +860,8 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid } $scope.amendments = Motion.filter({parent_id: motion.id}); - $scope.makePDF = function(){ - var content = motion.getText($scope.version) + motion.getReason($scope.version), - id = motion.identifier, + $scope.makePDF = function() { + var id = motion.identifier, slice = Function.prototype.call.bind([].slice), map = Function.prototype.call.bind([].map), image_sources = map($(content).find("img"), function(element) { From 875b7b2ddd3203c551b93a765fa3123f450cb3fd Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Tue, 20 Sep 2016 16:57:57 +0200 Subject: [PATCH 2/2] Reduced font-size of outline numbers. --- openslides/core/static/js/core/site.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index 88c600baa..4e37f11c5 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -352,7 +352,9 @@ angular.module('OpenSlidesApp.core.site', [ lineNumberObject = { width: 20, text: lineNumberOutline, - color: "gray" + color: "gray", + fontSize: 8, + margin: [0, 2, 0, 0] }, col = { columns: [