diff --git a/src/dia/attributes/index.mjs b/src/dia/attributes/index.mjs index 9cf52e8567..f0451bbaf9 100644 --- a/src/dia/attributes/index.mjs +++ b/src/dia/attributes/index.mjs @@ -249,43 +249,51 @@ const attributesNS = { } }, + text: { qualify: function(_text, _node, attrs) { - return !attrs.textWrap || !isPlainObject(attrs.textWrap); + const textWrap = attrs['text-wrap']; + return !textWrap || !isPlainObject(textWrap); }, + set: function(text, refBBox, node, attrs) { - var $node = $(node); - var cacheName = 'joint-text'; - var cache = $node.data(cacheName); - var textAttrs = pick(attrs, 'line-height', 'annotations', 'text-path', 'x', 'text-vertical-anchor', 'eol', 'display-empty'); - let fontSize = textAttrs.fontSize = attrs['font-size']; - var textHash = JSON.stringify([text, textAttrs]); + const $node = $(node); + const cacheName = 'joint-text'; + const cache = $node.data(cacheName); + const lineHeight = attrs['line-height']; + const textVerticalAnchor = attrs['text-vertical-anchor']; + const displayEmpty = attrs['display-empty']; + const fontSize = attrs['font-size']; + const annotations = attrs.annotations; + const eol = attrs.eol; + const x = attrs.x; + let textPath = attrs['text-path']; // 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 + // 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['text-path']; 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, { - lineHeight: textAttrs['line-height'], - annotations: textAttrs.annotations, - textPath: textAttrs['text-path'], - x: textAttrs.x, - textVerticalAnchor: textAttrs['text-vertical-anchor'], - eol: textAttrs.eol, - displayEmpty: textAttrs['display-empty'] + lineHeight, + annotations, + textPath, + x, + textVerticalAnchor, + eol, + displayEmpty }); $node.data(cacheName, textHash); } @@ -643,6 +651,9 @@ export const aliases = { externalResourcesRequired: 'externalResourcesRequired', }; +// TODO: +// - move the code to cellView or move the cellView calcAttributes to this file +// - replace the values with named constants export const calcAttributes = { 'transform': 1, 'x': 1,