Skip to content

Commit

Permalink
fix(dia.attributes): fix ambiguous order of cache keys in text attrib…
Browse files Browse the repository at this point in the history
…ute (#2333)
  • Loading branch information
kumilingus committed Sep 11, 2023
1 parent f6ffb4b commit e0a5aac
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions src/dia/attributes/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Point, Path, Polyline } from '../../g/index.mjs';
import { assign, isPlainObject, pick, isObject, isPercentage, breakText } from '../../util/util.mjs';
import { assign, isPlainObject, isObject, isPercentage, breakText } from '../../util/util.mjs';
import { isCalcAttribute, evalCalcAttribute } from './calc.mjs';
import props from './props.mjs';
import $ from 'jquery';
Expand Down Expand Up @@ -311,41 +311,54 @@ const attributesNS = {
return !attrs.textWrap || !isPlainObject(attrs.textWrap);
},
set: function(text, refBBox, node, attrs) {
var $node = $(node);
var cacheName = 'joint-text';
var cache = $node.data(cacheName);
var textAttrs = pick(attrs, 'lineHeight', 'annotations', 'textPath', 'x', 'textVerticalAnchor', 'eol', 'displayEmpty');
const $node = $(node);
const cacheName = 'joint-text';
const cache = $node.data(cacheName);
const {
lineHeight,
annotations,
textVerticalAnchor,
eol,
displayEmpty
} = attrs;
let textPath = attrs.textPath;
// eval `x` if using calc()
const { x } = textAttrs;
let x = attrs.x;
if (isCalcAttribute(x)) {
textAttrs.x = evalCalcAttribute(x, refBBox);
x = evalCalcAttribute(x, refBBox);
}

let fontSizeAttr = attrs['font-size'] || attrs['fontSize'];
if (isCalcAttribute(fontSizeAttr)) {
fontSizeAttr = evalCalcAttribute(fontSizeAttr, refBBox);
// eval `font-size` if using calc()
let fontSize = attrs['font-size'] || attrs['fontSize'];
if (isCalcAttribute(fontSize)) {
fontSize = evalCalcAttribute(fontSize, refBBox);
}
var fontSize = textAttrs.fontSize = fontSizeAttr;
var textHash = JSON.stringify([text, textAttrs]);
// Update the text only if there was a change in the string
// or any of its attributes.
const textHash = JSON.stringify([text, lineHeight, annotations, textVerticalAnchor, eol, displayEmpty, textPath, x, fontSize]);
if (cache === undefined || cache !== textHash) {
// Chrome bug:
// Tspans positions defined as `em` are not updated
// <tspan> positions defined as `em` are not updated
// when container `font-size` change.
if (fontSize) node.setAttribute('font-size', fontSize);
// Text Along Path Selector
var textPath = textAttrs.textPath;
if (isObject(textPath)) {
var pathSelector = textPath.selector;
const pathSelector = textPath.selector;
if (typeof pathSelector === 'string') {
var pathNode = this.findBySelector(pathSelector)[0];
const [pathNode] = this.findBySelector(pathSelector);
if (pathNode instanceof SVGPathElement) {
textAttrs.textPath = assign({ 'xlink:href': '#' + pathNode.id }, textPath);
textPath = assign({ 'xlink:href': '#' + pathNode.id }, textPath);
}
}
}
V(node).text('' + text, textAttrs);
V(node).text('' + text, {
lineHeight,
annotations,
textPath,
x,
textVerticalAnchor,
eol,
displayEmpty
});
$node.data(cacheName, textHash);
}
}
Expand Down

0 comments on commit e0a5aac

Please sign in to comment.