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

@ -42,17 +42,33 @@ loadingTask.promise.then(function(pdf) {
menu.classList.remove('d-md-block');
menu.classList.remove('d-none');
}
responsiveDisplay();
if(localStorage.getItem('svgCollections')) {
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;
});
var getHtmlSvg = function(svg, i) {
var inputRadio = document.createElement('input');
inputRadio.type = "radio";
@ -117,10 +133,10 @@ loadingTask.promise.then(function(pdf) {
svgContainer.classList.add('gap-2');
svgContainer.appendChild(inputRadio);
svgContainer.appendChild(svgButton);
return svgContainer;
}
var displaysSVG = function() {
document.getElementById('svg_list').innerHTML = "";
document.getElementById('svg_list_signature').innerHTML = "";
@ -151,11 +167,11 @@ loadingTask.promise.then(function(pdf) {
item.addEventListener('click', function() {
svgCollections.splice(this.dataset.index, 1);
displaysSVG();
localStorage.setItem('svgCollections', JSON.stringify(svgCollections));
storeCollections();
});
});
}
document.querySelectorAll('.btn-add-svg-type').forEach(function(item) {
item.addEventListener('click', function(event) {
document.getElementById('input-svg-type').value = this.dataset.type;
@ -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);
});
}