Browse Source

fix drawing on upload

pull/939/head
cho 5 years ago
parent
commit
2467236253
  1. 27
      app/widgets/Draw/draw.js
  2. 2
      app/widgets/Snap/snap.js
  3. 16
      app/widgets/Upload/upload.js

27
app/widgets/Draw/draw.js

@ -278,7 +278,7 @@ var Draw = {
stopDrawing: function(e) {
// print to actual canvas
if (Draw.drawingData.length)
Draw.smoothenLine(Draw.drawingData[Draw.drawingData.length -1], Draw.ctx)
Draw.smoothenLine(Draw.drawingData[Draw.drawingData.length -1], Draw.ctx, 1)
// cleanup screen
const rect = Draw.screen.getBoundingClientRect();
Draw.sctx.clearRect(0, 0, rect.width, rect.height);
@ -325,13 +325,14 @@ var Draw = {
finalctx.lineWidth = Draw.drawingData[i].width * Draw.ratio;
finalctx.strokeStyle = Draw.drawingData[i].color;
Draw.smoothenLine(Draw.drawingData[i], finalctx);
Draw.smoothenLine(Draw.drawingData[i], finalctx, Draw.ratio);
finalctx.beginPath();
}
},
smoothenLine(line, ctx) {
smoothenLine(line, ctx, ratio) {
let j = 0;
// keep only half of the points
const sample = line.points.filter((point, index) => index % 2 == 0)
while (sample.length < 4) {
@ -341,8 +342,8 @@ var Draw = {
if (sample.length >= 4) {
// move to 1st point of the line
ctx.moveTo(
sample[j].x * Draw.ratio,
sample[j].y * Draw.ratio
sample[j].x * ratio,
sample[j].y * ratio
);
for (j = 1; j < sample.length - 2; j++) {
// define controle point as the mean point between current point and next point
@ -351,17 +352,17 @@ var Draw = {
// draw a curve between
ctx.quadraticCurveTo(
sample[j].x * Draw.ratio,
sample[j].y * Draw.ratio,
c * Draw.ratio,
d * Draw.ratio
sample[j].x * ratio,
sample[j].y * ratio,
c * ratio,
d * ratio
);
}
ctx.quadraticCurveTo(
sample[j].x * Draw.ratio,
sample[j].y * Draw.ratio,
sample[j + 1].x * Draw.ratio,
sample[j + 1].y * Draw.ratio
sample[j].x * ratio,
sample[j].y * ratio,
sample[j + 1].x * ratio,
sample[j + 1].y * ratio
);
}
ctx.stroke();

2
app/widgets/Snap/snap.js

@ -24,7 +24,7 @@ var Snap = {
Snap.video.play();
// We try to use ImageCapture
if (ImageCapture) {
if (typeof(ImageCapture) != 'undefined') {
const track = stream.getVideoTracks()[0];
Snap.imageCapture = new ImageCapture(track);
}

16
app/widgets/Upload/upload.js

@ -77,18 +77,17 @@ var Upload = {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (ev) {
reader.addEventListener('load', function (ev) {
MovimUtils.getOrientation(file, function(orientation) {
Upload.compress(ev.target.result, file, orientation);
});
};
});
};
},
compress : function(src, file, orientation) {
var image = new Image();
image.onload = function()
{
image.addEventListener('load', function() {
if (file.size > SMALL_PICTURE_LIMIT) {
var limit = 1920;
var width = image.naturalWidth;
@ -144,8 +143,7 @@ var Upload = {
} else {
Upload.prepare(file);
}
}
});
image.src = src;
},
@ -166,7 +164,11 @@ var Upload = {
if (Upload.file.type.match(/image.*/)) {
preview.src = URL.createObjectURL(Upload.file);
toDraw.addEventListener('click', e => {
Draw.init(Upload.canvas);
if (Upload.canvas) {
Draw.init(Upload.canvas);
} else {
Draw.init(preview);
}
Dialog_ajaxClear();
Upload.abort();
});

Loading…
Cancel
Save