1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

Quand un objet est redimensionné la ratio de sa dimension est conserver

dans l'objet d'origine et dans le local storage
This commit is contained in:
Vincent LAURENT 2021-10-12 00:27:12 +02:00
parent 08465b5d4e
commit 3676b874d3

View File

@ -49,6 +49,22 @@ loadingTask.promise.then(function(pdf) {
svgCollections = JSON.parse(localStorage.getItem('svgCollections'));
}
var storeCollections = function () {
localStorage.setItem('svgCollections', JSON.stringify(svgCollections));
}
var getSvgItem = function(svg) {
for (index in svgCollections) {
svgItem = svgCollections[index];
if(svgItem.svg == svg) {
return svgItem;
}
}
return null;
}
opentype.load('/vendor/fonts/Caveat-Regular.ttf', function(err, font) {
fontCaveat = font;
});
@ -151,7 +167,7 @@ loadingTask.promise.then(function(pdf) {
item.addEventListener('click', function() {
svgCollections.splice(this.dataset.index, 1);
displaysSVG();
localStorage.setItem('svgCollections', JSON.stringify(svgCollections));
storeCollections();
});
});
}
@ -413,10 +429,15 @@ loadingTask.promise.then(function(pdf) {
fabric.loadSVGFromURL(item, function(objects, options) {
var svg = fabric.util.groupSVGElements(objects, options);
svg.svgOrigin = item;
svg.scaleToHeight(100);
if(svg.getScaledWidth() > 200) {
svg.scaleToWidth(200);
}
var svgItem = getSvgItem(item);
if(svgItem && svgItem.scale) {
svg.scaleToWidth(canvas.width * svgItem.scale);
}
svg.top = y - (svg.getScaledHeight() / 2);
svg.left = x - (svg.getScaledWidth() / 2);
canvas.add(svg).renderAll();
@ -606,6 +627,14 @@ loadingTask.promise.then(function(pdf) {
input_selected.checked = false;
input_selected.dispatchEvent(new Event("change"));
});
canvasEdition.on('object:scaled', function(event) {
var item = getSvgItem(event.target.svgOrigin);
if(!item) {
return;
}
item.scale = event.target.width * event.target.scaleX / event.target.canvas.width;
storeCollections();
});
canvasEditions.push(canvasEdition);
});
}