fix issue with text selection

master
JFH 2021-11-12 17:32:54 +01:00
parent 585bd06212
commit 254f86397b
7 changed files with 14 additions and 64 deletions

View File

@ -37,23 +37,6 @@ const supportsGoodTextCharPos_ = (function () {
} }
}()); }());
// Support for correct bbox sizing on groups with horizontal/vertical lines
const supportsHVLineContainerBBox_ = (function () {
const svgcontent = document.createElementNS(NSSVG, 'svg');
document.documentElement.append(svgcontent);
const path = document.createElementNS(NSSVG, 'path');
path.setAttribute('d', 'M0,0 10,0');
const path2 = document.createElementNS(NSSVG, 'path');
path2.setAttribute('d', 'M5,0 15,0');
const g = document.createElementNS(NSSVG, 'g');
g.append(path, path2);
svgcontent.append(g);
const bbox = g.getBBox();
svgcontent.remove();
// Webkit gives 0, FF gives 10, Opera (correctly) gives 15
return (bbox.width === 15);
}());
// Public API // Public API
/** /**
@ -83,12 +66,6 @@ export const isMac = () => isMac_;
*/ */
export const isTouch = () => isTouch_; export const isTouch = () => isTouch_;
/**
* @function module:browser.supportsHVLineContainerBBox
* @returns {boolean}
*/
export const supportsHVLineContainerBBox = () => supportsHVLineContainerBBox_;
/** /**
* @function module:browser.supportsGoodTextCharPos * @function module:browser.supportsGoodTextCharPos
* @returns {boolean} * @returns {boolean}

View File

@ -11,20 +11,7 @@ const NSSVG = 'http://www.w3.org/2000/svg';
const wAttrs = [ 'x', 'x1', 'cx', 'rx', 'width' ]; const wAttrs = [ 'x', 'x1', 'cx', 'rx', 'width' ];
const hAttrs = [ 'y', 'y1', 'cy', 'ry', 'height' ]; const hAttrs = [ 'y', 'y1', 'cy', 'ry', 'height' ];
const unitAttrs = [ 'r', 'radius', ...wAttrs, ...hAttrs ]; const unitAttrs = [ 'r', 'radius', ...wAttrs, ...hAttrs ];
// unused
/*
const unitNumMap = {
'%': 2,
em: 3,
ex: 4,
px: 5,
cm: 6,
mm: 7,
in: 8,
pt: 9,
pc: 10
};
*/
// Container of elements. // Container of elements.
let elementContainer_; let elementContainer_;

View File

@ -6,7 +6,7 @@
*/ */
import { import {
assignAttributes, cleanupElement, getElem, getRotationAngle, snapToGrid, walkTree, assignAttributes, cleanupElement, getElem, getRotationAngle, snapToGrid, walkTree,
isNullish, preventClickDefault, setHref isNullish, preventClickDefault, setHref, getBBox
} from './utilities.js'; } from './utilities.js';
import { import {
convertAttrs convertAttrs
@ -201,7 +201,7 @@ export const mouseMoveEvent = function (evt) {
// the shape's coordinates // the shape's coordinates
tlist = selected.transform.baseVal; tlist = selected.transform.baseVal;
const hasMatrix = hasMatrixTransform(tlist); const hasMatrix = hasMatrixTransform(tlist);
box = hasMatrix ? eventContext_.getInitBbox() : selected.getBBox(); box = hasMatrix ? eventContext_.getInitBbox() : getBBox(selected);
let left = box.x; let left = box.x;
let top = box.y; let top = box.y;
let { width, height } = box; let { width, height } = box;
@ -478,7 +478,7 @@ export const mouseMoveEvent = function (evt) {
break; break;
} case 'rotate': { } case 'rotate': {
box = selected.getBBox(); box = getBBox(selected);
cx = box.x + box.width / 2; cx = box.x + box.width / 2;
cy = box.y + box.height / 2; cy = box.y + box.height / 2;
const m = getMatrix(selected); const m = getMatrix(selected);
@ -1074,7 +1074,7 @@ export const mouseDownEvent = function (evt) {
// Getting the BBox from the selection box, since we know we // Getting the BBox from the selection box, since we know we
// want to orient around it // want to orient around it
eventContext_.setInitBbox($id('selectedBox0').getBBox()); eventContext_.setInitBbox(getBBox($id('selectedBox0')));
const bb = {}; const bb = {};
for (const [ key, val ] of Object.entries(eventContext_.getInitBbox())) { for (const [ key, val ] of Object.entries(eventContext_.getInitBbox())) {
bb[key] = val / currentZoom; bb[key] = val / currentZoom;

View File

@ -6,7 +6,7 @@
* @copyright 2010 Jeff Schiller * @copyright 2010 Jeff Schiller
*/ */
import { getHref, setHref, getRotationAngle, isNullish } from './utilities.js'; import { getHref, setHref, getRotationAngle, isNullish, getBBox } from './utilities.js';
/** /**
* Group: Undo/Redo history management. * Group: Undo/Redo history management.
@ -330,7 +330,7 @@ export class ChangeElementCommand extends Command {
if (!bChangedTransform) { if (!bChangedTransform) {
const angle = getRotationAngle(this.elem); const angle = getRotationAngle(this.elem);
if (angle) { if (angle) {
const bbox = this.elem.getBBox(); const bbox = getBBox(this.elem);
const cx = bbox.x + bbox.width / 2; const cx = bbox.x + bbox.width / 2;
const cy = bbox.y + bbox.height / 2; const cy = bbox.y + bbox.height / 2;
const rotate = [ 'rotate(', angle, ' ', cx, ',', cy, ')' ].join(''); const rotate = [ 'rotate(', angle, ' ', cx, ',', cy, ')' ].join('');
@ -371,7 +371,7 @@ export class ChangeElementCommand extends Command {
if (!bChangedTransform) { if (!bChangedTransform) {
const angle = getRotationAngle(this.elem); const angle = getRotationAngle(this.elem);
if (angle) { if (angle) {
const bbox = this.elem.getBBox(); const bbox = getBBox(this.elem);
const cx = bbox.x + bbox.width / 2; const cx = bbox.x + bbox.width / 2;
const cy = bbox.y + bbox.height / 2; const cy = bbox.y + bbox.height / 2;
const rotate = [ 'rotate(', angle, ' ', cx, ',', cy, ')' ].join(''); const rotate = [ 'rotate(', angle, ' ', cx, ',', cy, ')' ].join('');

View File

@ -15,7 +15,7 @@ import {
} from './math.js'; } from './math.js';
import { import {
assignAttributes, getElem, getRotationAngle, snapToGrid, isNullish, assignAttributes, getElem, getRotationAngle, snapToGrid, isNullish,
getBBox as utilsGetBBox getBBox
} from './utilities.js'; } from './utilities.js';
let pathActionsContext_ = null; let pathActionsContext_ = null;
@ -679,7 +679,7 @@ export const pathActionsMethod = (function () {
// const {item} = seg; // const {item} = seg;
const rubberBox = editorContext_.getRubberBox(); const rubberBox = editorContext_.getRubberBox();
const rbb = rubberBox.getBBox(); const rbb = getBBox(rubberBox);
const pt = pathActionsContext_.getGripPt(seg); const pt = pathActionsContext_.getGripPt(seg);
const ptBb = { const ptBb = {
@ -770,7 +770,7 @@ export const pathActionsMethod = (function () {
editorContext_.clearSelection(); editorContext_.clearSelection();
path.setPathContext(); path.setPathContext();
path.show(true).update(); path.show(true).update();
path.oldbbox = utilsGetBBox(path.elem); path.oldbbox = getBBox(path.elem);
subpath = false; subpath = false;
}, },
/** /**

View File

@ -7,7 +7,7 @@
import { NS } from "./namespaces.js"; import { NS } from "./namespaces.js";
import { import {
getBBox as utilsGetBBox, getBBox,
getStrokedBBoxDefaultVisible getStrokedBBoxDefaultVisible
} from "./utilities.js"; } from "./utilities.js";
import { import {
@ -286,7 +286,7 @@ export const getIntersectionListMethod = function (rect) {
let rubberBBox; let rubberBBox;
if (!rect) { if (!rect) {
rubberBBox = selectionContext_.getRubberBox().getBBox(); rubberBBox = getBBox(selectionContext_.getRubberBox());
const bb = selectionContext_.getSVGContent().createSVGRect(); const bb = selectionContext_.getSVGContent().createSVGRect();
[ "x", "y", "width", "height", "top", "right", "bottom", "left" ].forEach( [ "x", "y", "width", "height", "top", "right", "bottom", "left" ].forEach(
@ -379,7 +379,7 @@ export const setRotationAngle = function (val, preventUndo) {
val = Number.parseFloat(val); val = Number.parseFloat(val);
const elem = selectedElements[0]; const elem = selectedElements[0];
const oldTransform = elem.getAttribute("transform"); const oldTransform = elem.getAttribute("transform");
const bbox = utilsGetBBox(elem); const bbox = getBBox(elem);
const cx = bbox.x + bbox.width / 2; const cx = bbox.x + bbox.width / 2;
const cy = bbox.y + bbox.height / 2; const cy = bbox.y + bbox.height / 2;
const tlist = elem.transform.baseVal; const tlist = elem.transform.baseVal;

View File

@ -854,20 +854,6 @@ export const getBBoxWithTransform = function (elem, addSVGElementFromJson, pathA
if (!goodBb) { if (!goodBb) {
const { matrix } = transformListToTransform(tlist); const { matrix } = transformListToTransform(tlist);
bb = transformBox(bb.x, bb.y, bb.width, bb.height, matrix).aabox; bb = transformBox(bb.x, bb.y, bb.width, bb.height, matrix).aabox;
// Old technique that was exceedingly slow with large documents.
//
// Accurate way to get BBox of rotated element in Firefox:
// Put element in group and get its BBox
//
// Must use clone else FF freaks out
// const clone = elem.cloneNode(true);
// const g = document.createElementNS(NS.SVG, 'g');
// const parent = elem.parentNode;
// parent.append(g);
// g.append(clone);
// const bb2 = bboxToObj(g.getBBox());
// g.remove();
} }
} }
return bb; return bb;