mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-16 22:10:32 +00:00
fixed calculate position (#4827)
* fixed calculate position * Re-enabled tests.
This commit is contained in:
parent
5155da9fce
commit
2ce99ee0b7
2 changed files with 30 additions and 37 deletions
|
|
@ -525,13 +525,17 @@
|
|||
y: boundaries.top + boundaries.topOffset + charHeight
|
||||
},
|
||||
upperCanvas = this.canvas.upperCanvasEl,
|
||||
upperCanvasWidth = upperCanvas.clientWidth || upperCanvas.width,
|
||||
upperCanvasHeight = upperCanvas.clientHeight || upperCanvas.height,
|
||||
upperCanvasWidth = upperCanvas.width,
|
||||
upperCanvasHeight = upperCanvas.height,
|
||||
maxWidth = upperCanvasWidth - charHeight,
|
||||
maxHeight = upperCanvasHeight - charHeight;
|
||||
maxHeight = upperCanvasHeight - charHeight,
|
||||
scaleX = upperCanvas.clientWidth / upperCanvasWidth,
|
||||
scaleY = upperCanvas.clientHeight / upperCanvasHeight;
|
||||
|
||||
p = fabric.util.transformPoint(p, m);
|
||||
p = fabric.util.transformPoint(p, this.canvas.viewportTransform);
|
||||
p.x *= scaleX;
|
||||
p.y *= scaleY;
|
||||
if (p.x < 0) {
|
||||
p.x = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -792,46 +792,35 @@
|
|||
});
|
||||
|
||||
QUnit.test('hiddenTextarea does not move DOM', function(assert) {
|
||||
if (fabric.isLikelyNode) {
|
||||
assert.ok(true);
|
||||
return;
|
||||
}
|
||||
|
||||
var el = fabric.document.createElement('div');
|
||||
el.id = 'itext-test-wrapper';
|
||||
el.style.width = '100px';
|
||||
el.style.height = '65px';
|
||||
el.innerHTML = '<canvas id="itext-test-canvas" style="width: 100%; height: 100%;"></canvas>';
|
||||
|
||||
fabric.document.body.appendChild(el);
|
||||
|
||||
var iText = new fabric.IText('Double-click to edit', { fill: '#ffffff', fontSize: 50 });
|
||||
|
||||
var canvas2 = new fabric.Canvas('itext-test-canvas', { width: 2800, height: 1600, renderOnAddRemove: true });
|
||||
canvas2.setDimensions({'max-height': '100%', 'max-width': '100%'}, { cssOnly: true });
|
||||
canvas2.renderAll();
|
||||
|
||||
var iText = new fabric.IText('a', { fill: '#ffffff', fontSize: 50 });
|
||||
var canvas2 = new fabric.Canvas(null, { width: 800, height: 800, renderOnAddRemove: false });
|
||||
canvas2.setDimensions({ width: 100, height: 100 }, { cssOnly: true });
|
||||
iText.set({
|
||||
top: canvas2.height - iText.height,
|
||||
left: canvas2.width - iText.width
|
||||
top: 400,
|
||||
left: 400,
|
||||
});
|
||||
canvas2.add(iText);
|
||||
|
||||
var widthBeforeEdit = fabric.document.documentElement.scrollWidth,
|
||||
heightBeforeEdit = fabric.document.documentElement.scrollHeight;
|
||||
|
||||
Object.defineProperty(canvas2.upperCanvasEl, 'clientWidth', {
|
||||
get: function() { return this._clientWidth; },
|
||||
set: function(value) { return this._clientWidth = value; },
|
||||
});
|
||||
Object.defineProperty(canvas2.upperCanvasEl, 'clientHeight', {
|
||||
get: function() { return this._clientHeight; },
|
||||
set: function(value) { return this._clientHeight = value; },
|
||||
});
|
||||
canvas2.upperCanvasEl._clientWidth = 100;
|
||||
canvas2.upperCanvasEl._clientHeight = 100;
|
||||
iText.enterEditing();
|
||||
|
||||
var widthAfterEdit = fabric.document.documentElement.scrollWidth,
|
||||
heightAfterEdit = fabric.document.documentElement.scrollHeight;
|
||||
|
||||
assert.equal(Math.round(parseInt(iText.hiddenTextarea.style.top)), 57, 'top is scaled with CSS');
|
||||
assert.equal(Math.round(parseInt(iText.hiddenTextarea.style.left)), 50, 'left is scaled with CSS');
|
||||
iText.exitEditing();
|
||||
canvas2.upperCanvasEl._clientWidth = 200;
|
||||
canvas2.upperCanvasEl._clientHeight = 200;
|
||||
iText.enterEditing();
|
||||
assert.equal(Math.round(parseInt(iText.hiddenTextarea.style.top)), 114, 'top is scaled with CSS');
|
||||
assert.equal(Math.round(parseInt(iText.hiddenTextarea.style.left)), 100, 'left is scaled with CSS');
|
||||
iText.exitEditing();
|
||||
|
||||
assert.equal(widthAfterEdit, widthBeforeEdit, 'Adding hiddenTextarea modified DOM width');
|
||||
assert.equal(heightAfterEdit, heightBeforeEdit, 'Adding hiddenTextarea modified DOM height');
|
||||
|
||||
canvas2.dispose();
|
||||
el.parentNode.removeChild(el);
|
||||
});
|
||||
|
||||
// QUnit.test('measuring width of words', function (assert) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue