bpmn-visualization-js icon indicating copy to clipboard operation
bpmn-visualization-js copied to clipboard

[REFACTOR] try to restore svg labels

Open tbouffard opened this issue 4 years ago • 2 comments

As of #299, we have switched to html labels as mxGraph 4.1.0 only supports wrapping out of the box with such labels.

As mention in the mxGraph documentation: Enabling HTML labels carries a possible security risk (see the section on security in the manual). This could also cause issue if we want to export the graph in svg (is html in svg foreign object correctly rendered by all svg viewer/editor?), as requested for #133

Using svg labels, wrapping could be done with svg text/tspan

tbouffard avatar Jun 17 '20 12:06 tbouffard

With 9484c99a (0.1.5-dev), we see that in case of unsupported foreign object, the label is replaced by [Object] Note

  • example given here is the svg export of the A.2.0.bpmn file from BPMN-MIWG
  • the svg export is done by implementing a mxImageExport backed by a mxSvgCanvas2D (inspired from the draw.io svg exporter implementation)

For instance, with Inkscape 1.0 (at least on Ubuntu), the exported svg (see zipped svg master_9484c99a_A.2.0.zip) is rendered as in the following

master_9484c99a_A 2 0_inkscape-1 0_export

mxGraph 4.1.1 implementation notes

The svg exporter used to generate the svg presented here doesn't customize mxSvgCanvas2D foreignObject generation. By default, mxSvgCanvas2D generate a [Object] text label as alternative for viewers that don't support the foreingObject. We could at least use an implementation that display the right text label instead (with the risk of text overflow) See https://github.com/jgraph/mxgraph/blob/v4.1.1/javascript/src/js/util/mxSvgCanvas2D.js#L363

  • mxSvgCanvas2D.prototype.createAlternateContent
  • mxSvgCanvas2D.prototype.getAlternateText
  • mxSvgCanvas2D.prototype.foAltText: returns [Object] by default

tbouffard avatar Jun 23 '20 08:06 tbouffard

draw.io article about issues that may be introduced by html labels: https://www.diagrams.net/doc/faq/svg-export-text-problems (or legacy https://desk.draw.io/support/solutions/articles/16000042487)

tbouffard avatar Jun 23 '20 19:06 tbouffard