Page MenuHome

Fix SVG import of polygons
AbandonedPublic

Authored by Paul Smith (pauladamsmith) on Feb 8 2018, 6:25 PM.

Details

Summary

When a list of points in a SVG polygon contains a floating point number who's textual representation contains an exponent with a negative value, for example, 6.064e-05, the current importer will break and raise an exception to the client.

The reason is that minus signs are prepended with spaces in a pre-processing step before parsing the points string into individual points. This causes numbers such a '6.064e-05' to be erroneously broken up into '6.064e' and '-05'. The former then fails to be parsed by the float() function, as it is an invalid float string.

This patch fixes such imports.

Diff Detail

Event Timeline

Seems reasonable, @Sergey Sharybin (sergey) wrote this code though.

Is it expected that 10-3 interpreted as (10, -3)?

Sergey Sharybin (sergey) requested changes to this revision.Feb 16 2018, 9:20 AM

This was some compatibility code for files saved by some software, and also was an attempt to follow parsing rules from web browsers.

For example, this code both Firefox and Chrome will interpret as (100, -75).

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="12cm" height="4cm" viewBox="-100 -100 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="0" y="0" width="300" height="100" fill="none" stroke="blue" stroke-width="2" />
  <polygon fill="red" stroke="blue" stroke-width="10" points="100-75  100,100 300,100 300-75" />
</svg>

So, the code is to be modified in a way, that split on - is only happening when e leads the -.

This revision now requires changes to proceed.Feb 16 2018, 9:20 AM