Merge pull request #2376 from tsiegleauq/issue2300-pdf-line-numbers
Add line numbers to pdf (fixes #2300)
This commit is contained in:
commit
96b4fb9fd9
@ -53,7 +53,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'
|
||||
}]
|
||||
};
|
||||
@ -82,9 +82,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,
|
||||
@ -156,7 +156,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"],
|
||||
@ -342,21 +342,61 @@ angular.module('OpenSlidesApp.core.site', [
|
||||
alreadyConverted.push(st);
|
||||
break;
|
||||
case "span":
|
||||
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",
|
||||
fontSize: 8,
|
||||
margin: [0, 2, 0, 0]
|
||||
},
|
||||
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":
|
||||
//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":
|
||||
// TODO: need a proper way to calculate the space
|
||||
@ -399,8 +439,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;
|
||||
}
|
||||
@ -416,7 +457,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 = [];
|
||||
|
@ -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,6 +172,15 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid
|
||||
* @param {object} User - Current user
|
||||
*/
|
||||
getContent = function(motion, $scope, User) {
|
||||
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),
|
||||
@ -171,6 +190,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions', 'OpenSlid
|
||||
reason(motion, $scope),
|
||||
reasonContent(motion, $scope)
|
||||
];
|
||||
}
|
||||
};
|
||||
return {
|
||||
getContent: getContent
|
||||
@ -1068,9 +1088,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) {
|
||||
|
Loading…
Reference in New Issue
Block a user