Home Forums DITA and XMetaL Discussion Hello! Why do some SVGs work and not others?? Reply To: Hello! Why do some SVGs work and not others??

Derek Read

Reply to: Hello! Why do some SVGs work and not others??

Sorry, my mistake. When this code was originally written (as a demo for our developers to base the shipping version on) we didn't put any unit conversions in. Our developers have added support for cm and in. The code could be easily extended to handle mm (as that is just cm * 10).

If this was just for your machine then I'm not too worried about showing you how to make this minor improvement. However, it sounds like you need to roll out any change to various other people so that gets a little more worrying. Manually changing files this way means that the product will not cleanly uninstall (you will need to manually remove this particular file later), and an installation repair (via Add or Remove Programs in the Control Panel) will eliminate the “fix”. Also, depending on your Windows version and IT security settings it may be troublesome to actually make these changes.

The file is here on a default install of XMetaL Author Enterprise 6.0 on Windows XP:
C:Program FilesXMetaL 6.0AuthorDITAXACssharedobjectjsobject_op.js

The code that does the unit conversion is this:
[code]    // If there are units, convert it to pixels assuming 96dpi
    if (SVGwidth.indexOf(“in”) > 0) {
      SVGwidth  = parseInt(parseFloat(SVGwidth) * 96.0);
    } else if (SVGwidth.indexOf(“cm”) > 0) {
      SVGwidth  = parseInt(parseFloat(SVGwidth) * 96.0 / 2.54);
    }
    if (SVGheight.indexOf(“in”) > 0) {
      SVGheight = parseInt(parseFloat(SVGheight) * 96.0);
    } else if (SVGheight.indexOf(“cm”) > 0) {
      SVGheight = parseInt(parseFloat(SVGheight) * 96.0 / 2.54);
    }[/code]

Adding another 'else if' to each of those, as follows, should give you mm support:
[code]    // If there are units, convert it to pixels assuming 96dpi
    if (SVGwidth.indexOf(“in”) > 0) {
      SVGwidth  = parseInt(parseFloat(SVGwidth) * 96.0);
    } else if (SVGwidth.indexOf(“cm”) > 0) {
      SVGwidth  = parseInt(parseFloat(SVGwidth) * 96.0 / 2.54);
    } else if (SVGwidth.indexOf(“mm”) > 0) {
      SVGwidth = parseInt(parseFloat(SVGwidth) * 96.0 / 25.4);
    }
    if (SVGheight.indexOf(“in”) > 0) {
      SVGheight = parseInt(parseFloat(SVGheight) * 96.0);
    } else if (SVGheight.indexOf(“cm”) > 0) {
      SVGheight = parseInt(parseFloat(SVGheight) * 96.0 / 2.54);
    } else if (SVGheight.indexOf(“mm”) > 0) {
      SVGheight = parseInt(parseFloat(SVGheight) * 96.0 / 25.4);
    }[/code]

If you don't feel comfortable modifying script I would not attempt this. Officially, making modifications to the product like this is not supported, so you will need to make that decision.

Best to back up that file before making the change so you can easily restore the original.

I'll make a recommendation that we try to extend this portion of the code to handle all the common units that might be set inside an SVG file (I guess we thought we had them all based on various sample SVG files we had seen at the time).

Reply

Products
Downloads
Support