inkex.py: avoid ZeroDivisionError in getDocumentUnit()

Bug #1474188 reported by su_v
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
In Progress
Medium
jazzynico

Bug Description

Follow-up to:
Bug #1473955 Sticky zero width, height in viewBox attribute

Proposed changes (trunk, 0.91):
1) Avoid ZeroDivisionError in getDocumentUnit() if viewBox width is '0'
2) If scale factor based on width is undefined, try scale factor based on height

Todo (trunk only; to be tracked separately):
3) Support arbitrary (but uniform) document scale; don't fall back to CSS px.

Diff tested with Inkscape 0.91+devel r14244 on OS X 10.7.5.

Revision history for this message
Tristan Bailey (tristanlbailey) wrote :

I believe I may have a very similar bug, if not the same.

Upon saving a new *optimised* SVG Document on Windows 10 (completely unedited externally), the following message appears:

Traceback (most recent call last):
  File "scour.inkscape.py", line 78, in <module>
    e.affect(output=False)
  File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 265, in affect
    self.getposinlayer()
  File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 207, in getposinlayer
    x = self.unittouu( xattr[0] + 'px' )
  File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 351, in unittouu
    return retval * (self.__uuconv[u.string[u.start():u.end()]] / self.__uuconv[self.getDocumentUnit()])
  File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 326, in getDocumentUnit
    svgunitfactor = self.__uuconv[svgwidthunit] * width / viewboxwidth
ZeroDivisionError: float division

Revision history for this message
Tristan Bailey (tristanlbailey) wrote :

Forgot to mention that the problem is critical, as it comes up with an error message immediately after the first message, saying that it could not save the document.

Revision history for this message
su_v (suv-lp) wrote :

Follow-up report (see Todo) filed as:
* Bug #1508400 “inkex.py: support arbitrary (but uniform) document scale (0.92)”
  https://bugs.launchpad.net/inkscape/+bug/1508400

Revision history for this message
su_v (suv-lp) wrote :

Adding milestone - the current stable release 0.91 is affected by bug #1473955 and bug #1419122, which can result in SVG files with erroneous viewBox values. Such files may fail to be processed by python-based script extensions (this bug).

Changed in inkscape:
milestone: none → 0.92
Revision history for this message
su_v (suv-lp) wrote :

Patch from comment #1 is superseded by solution in linked branch (for bug #1508400).

Revision history for this message
su_v (suv-lp) wrote :

[ Earlier diff (obsoleted by merge proposal) deleted ]

jazzynico (jazzynico)
Changed in inkscape:
assignee: nobody → jazzynico (jazzynico)
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
su_v (suv-lp) wrote :

Follow-up report mentioned in comment #4 has been closed, re-evaluating issue tracked here:

1) The reported issue does not reproduce as is with current lp:inkscape/0.92.x: as observed in bug #1534187 (see last comment there), such viewBox values are now unconditionally (and without entry in undo history) "auto-corrected" on load of affected documents. The trigger of the reported ZeroDivisionError in inkex.py thus no longer occurs (unless the user intentionally modifies the viewBox attribute via XML Editor in the current session to set its width to zero).

2) OTOH the unconditional adding of the viewBox attribute can have undesired side-effects (modifications elsewhere in the document), as reported in bug #1589217.

As long as the changes from r13938 are in effect (adding/rewriting the viewBox attribute on load), this report could be considered obsolete.

I don't know how such a relationship could be tracked across 3 (or potentially more) reports in launchpad's bug tracker.

Revision history for this message
su_v (suv-lp) wrote : Re: [Bug 1474188] Re: inkex.py: avoid ZeroDivisionError in getDocumentUnit()

On 2016-08-30 08:54 (+0200), su_v wrote:
> As long as the changes from r13938 are in effect (adding/rewriting the
> viewBox attribute on load), this report could be considered obsolete.

The issue tracked here needs retesting once a final fix for bug #1389723
is committed (IIRC the latest series of proposed patches reverts r13938).

A test file (created with Inkscape 0.91) is attached to bug #1473955:
https://bugs.launchpad.net/inkscape/+bug/1473955/+attachment/4428280/+files/1473955-sticky-zero-width-in-viewBox.svg

Steps to reproduce:
1) launch inkscape with test file
2) run any python-based extension
   (e.g. 'Extensions > Render > Gear > Gear')

If the viewBox has not been "corrected" on-load (viewbox dimensions with
zero lengths replaced with computed value based on internal resolution
(?)), the extension will fail with the reported ZeroDivisionError.

Revision history for this message
victorialily (victorialily) wrote :

Same problem i had

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.