From 239d56f350d4f7bf8516a204cf82018ca583ded0 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 28 Apr 2017 12:13:20 +0200 Subject: [PATCH] Fixing PDF in IE11 (fixes #3206, fixes #3217) --- CHANGELOG | 1 + openslides/core/static/js/core/pdf.js | 39 +++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f171e4a07..f4ab039a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -45,6 +45,7 @@ Core: General: - Several bugfixes and minor improvements. +- Bugfixes for PDF creation [#3227] Version 2.1.1 (2017-04-05) diff --git a/openslides/core/static/js/core/pdf.js b/openslides/core/static/js/core/pdf.js index 46f47d8fa..d95a47e4c 100644 --- a/openslides/core/static/js/core/pdf.js +++ b/openslides/core/static/js/core/pdf.js @@ -476,6 +476,37 @@ angular.module('OpenSlidesApp.core.pdf', []) } return currentParagraph; }, + /** + * Returns the color in a hex format (e.g. #12ff00). + * Tries to convert the rgb form into this. + * @function + * @param {string} color + */ + parseColor = function (color) { + var hexRegex = new RegExp('^#([0-9a-f]{3}|[0-9a-f]{6})$'); + // e.g. #fff or #ff0048 + var rgbRegex = new RegExp('^rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)$'); + // e.g. rgb(0,255,34) or rgb(22, 0, 0) + + if (hexRegex.test(color)) { + return color; + } else if(rgbRegex.test(color)) { + var decimalColors = rgbRegex.exec(color).slice(1); + for (var i = 0; i < 3; i++) { + var decimalValue = parseInt(decimalColors[i]); + if (decimalValue > 255) { + decimalValue = 255; + } + var hexString = '0' + decimalValue.toString(16); + hexString = hexString.slice(-2); + decimalColors[i] = hexString; + } + return '#' + decimalColors.join(''); + } else { + console.err('Could not parse color "' + color + '"'); + return color; + } + }, /** * Extracts the style from an object * @function @@ -529,7 +560,7 @@ angular.module('OpenSlidesApp.core.pdf', []) } break; case "color": - o.color = value; + o.color = parseColor(value); break; case "background-color": o.background = value; @@ -724,8 +755,12 @@ angular.module('OpenSlidesApp.core.pdf', []) break; } else { currentParagraph = create("text"); + if (lineNumberMode == "none") { + currentParagraph.margin = [0, 0, 0, 0]; + } else { + currentParagraph.margin = [20, 0, 0, 0]; + } currentParagraph.lineHeight = 1.25; - currentParagraph.margin = [20, 0, 0, 0]; alreadyConverted.push(currentParagraph); } break;