Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus committed Sep 11, 2023
1 parent 3162b53 commit 878830d
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/dia/attributes/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// <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['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);
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 878830d

Please sign in to comment.