Fixed parsing of image sizes

This commit is contained in:
FinnStutzenstein 2018-05-02 13:38:44 +02:00
parent 60ae155d96
commit 06ddd8ee46

View File

@ -948,43 +948,37 @@ angular.module('OpenSlidesApp.core.pdf', [])
alreadyConverted.push(pObjectToPush); alreadyConverted.push(pObjectToPush);
break; break;
case "img": case "img":
var regex = /([\w-]*)\s*:\s*([^;]*)/g; var path = element.getAttribute('src');
var match; //helper variable for the regex var height = images[path].height;
var imageSize={}; var width = images[path].width;
var maxResolution = { var maxWidth = 450;
width: 435, var scale = 100;
height: 830
};
if (element.getAttribute("style")) { var style = element.getAttribute('style');
while ((match = regex.exec(element.getAttribute("style"))) !== null) { if (style) {
imageSize[match[1]] = parseInt(match[2].trim()); var match = style.match(/width:\s*(\d+)\%/);
if (match) {
scale = parseInt(match[1]);
} }
} else {
imageSize = {
height: images[element.getAttribute("src")].height,
width: images[element.getAttribute("src")].width
};
} }
if (imageSize.width > maxResolution.width) { // scale image
var scaleByWidth = maxResolution.width/imageSize.width; width = (width * scale) / 100;
imageSize.width *= scaleByWidth; height = (height * scale) / 100;
imageSize.height *= scaleByWidth;
if (width > maxWidth) {
height = (height * maxWidth) / width;
width = maxWidth;
} }
if (imageSize.height > maxResolution.height) {
var scaleByHeight = maxResolution.height/imageSize.height; // remove trailing / for the virtual file system (there is no root)
imageSize.width *= scaleByHeight;
imageSize.height *= scaleByHeight;
}
var path = element.getAttribute("src");
if (path.indexOf('/') === 0) { if (path.indexOf('/') === 0) {
path = path.substr(1); // remove trailing / path = path.substr(1);
} }
alreadyConverted.push({ alreadyConverted.push({
image: path, image: path,
width: imageSize.width, width: width,
height: imageSize.height height: height,
}); });
break; break;
case "ul": case "ul":