enables pdf image scaling for CKEditor
This commit is contained in:
parent
2833341867
commit
eb259dc5e2
@ -99,7 +99,12 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
ctx.drawImage(img, 0, 0);
|
ctx.drawImage(img, 0, 0);
|
||||||
var dataURL = canvas.toDataURL("image/png");
|
var dataURL = canvas.toDataURL("image/png");
|
||||||
resolve(dataURL);
|
var imageData = {
|
||||||
|
data: dataURL,
|
||||||
|
width: img.width,
|
||||||
|
height: img.height
|
||||||
|
};
|
||||||
|
resolve(imageData);
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
});
|
});
|
||||||
@ -159,7 +164,7 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
|
|
||||||
if (logoHeaderUrl) {
|
if (logoHeaderUrl) {
|
||||||
columns.push({
|
columns.push({
|
||||||
image: imageMap[logoHeaderUrl],
|
image: imageMap[logoHeaderUrl].data,
|
||||||
fit: [180, 40],
|
fit: [180, 40],
|
||||||
width: '20%'
|
width: '20%'
|
||||||
});
|
});
|
||||||
@ -198,7 +203,7 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
|
|
||||||
if (logoFooterUrl) {
|
if (logoFooterUrl) {
|
||||||
columns.push({
|
columns.push({
|
||||||
image: imageMap[logoFooterUrl],
|
image: imageMap[logoFooterUrl].data,
|
||||||
fit: [400,50],
|
fit: [400,50],
|
||||||
width: '80%'
|
width: '80%'
|
||||||
});
|
});
|
||||||
@ -813,31 +818,39 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
alreadyConverted.push(pObjectToPush);
|
alreadyConverted.push(pObjectToPush);
|
||||||
break;
|
break;
|
||||||
case "img":
|
case "img":
|
||||||
// TODO: need a proper way to calculate the space
|
var regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
||||||
// left on the page.
|
var match; //helper variable for the refegex
|
||||||
// This requires further information
|
var imageSize={};
|
||||||
// A4 in 72dpi: 595px x 842px
|
|
||||||
var maxResolution = {
|
var maxResolution = {
|
||||||
width: 435,
|
width: 435,
|
||||||
height: 830
|
height: 830
|
||||||
},
|
};
|
||||||
width = parseInt(element.getAttribute("width")),
|
|
||||||
height = parseInt(element.getAttribute("height"));
|
|
||||||
|
|
||||||
if (width > maxResolution.width) {
|
if (element.getAttribute("style")) {
|
||||||
var scaleByWidth = maxResolution.width/width;
|
while ((match = regex.exec(element.getAttribute("style"))) !== null) {
|
||||||
width *= scaleByWidth;
|
imageSize[match[1]] = parseInt(match[2].trim());
|
||||||
height *= scaleByWidth;
|
|
||||||
}
|
}
|
||||||
if (height > maxResolution.height) {
|
} else {
|
||||||
var scaleByHeight = maxResolution.height/height;
|
imageSize = {
|
||||||
width *= scaleByHeight;
|
height: images[element.getAttribute("src")].height,
|
||||||
height *= scaleByHeight;
|
width: images[element.getAttribute("src")].width
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageSize.width > maxResolution.width) {
|
||||||
|
var scaleByWidth = maxResolution.width/imageSize.width;
|
||||||
|
imageSize.width *= scaleByWidth;
|
||||||
|
imageSize.height *= scaleByWidth;
|
||||||
|
}
|
||||||
|
if (imageSize.height > maxResolution.height) {
|
||||||
|
var scaleByHeight = maxResolution.height/imageSize.height;
|
||||||
|
imageSize.width *= scaleByHeight;
|
||||||
|
imageSize.height *= scaleByHeight;
|
||||||
}
|
}
|
||||||
alreadyConverted.push({
|
alreadyConverted.push({
|
||||||
image: images[element.getAttribute("src")],
|
image: images[element.getAttribute("src")].data,
|
||||||
width: width,
|
width: imageSize.width,
|
||||||
height: height
|
height: imageSize.height
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "ul":
|
case "ul":
|
||||||
|
Loading…
Reference in New Issue
Block a user