Fix view center for Render extensions applied in transformed layers or groups

Bug #1503882 reported by su_v
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
Wishlist
su_v

Bug Description

Several 'Render' extensions use self.view_center to place new objects into the current layer (or group). None of them take parent transforms on layers (e.g. after a change of the page height/orientation or a resize of the page to drawing/selection) into account.

The proposed patch adds a new function to simpletransform.py, computePointInNode(), which can be used to convert self.view_center into coordinates which compensate any parent transforms of the current layer.

Affected extensions (using self.view_center):
  grid_cartesian.py
  grid_isometric.py
  grid_polar.py
  hershey.py
  lindenmayer.py
  polyhedron_3d.py
  render_barcode.py
  render_barcode_datamatrix.py
  render_barcode_qrcode.py
  render_gear_rack.py
  render_gears.py
  rtree.py
  spirograph.py
  triangle.py
  whirl.py
  wireframe_sphere.py

Changes to simpletransform.py
1) the function invertTransform() is copied from voronoi2svg.py (a later commit could remove the original version in voronoi2svg to avoid two copies).
2) a new function computePointInNode() which takes a point [x, y] and a XML node as arguments, is added. This function is called by all affected Render extensions.

=====
Patch was tested with Inkscape 0.91+devel r14397 on OS X 10.7.5.

Related branches

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

Second version of patch includes these changes:
- no transform needed if current layer is 'root'
- fix qrcode and datamatrix barcode (require center point as tuple, not as list)

description: updated
Revision history for this message
jazzynico (jazzynico) wrote :

I'm trying to test your patch but apparently use a wrong test file or a wrong procedure...
Could you please attach a test file I could use?
Thanks!

BTW, changes applied rev. 14403 broke the patch (Hunk #2 fails in rtree.py).

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

On 2015-12-07 10:25 (+0100), jazzynico wrote:
> BTW, changes applied rev. 14403 broke the patch (Hunk #2 fails in
> rtree.py).

IIRC this was fixed in the linked branch, but I'll update the branch to latest trunk today and attach the updated diff along with instructions how to test the proposed changes (sorry for the omission).

Changed in inkscape:
importance: Undecided → Wishlist
Revision history for this message
su_v (suv-lp) wrote :

Steps to reproduce:
1) launch current trunk (default prefs, default new doc)
2) zoom out a few times
3) draw a rectangle somewhere on the canvas outside the current page area
4) resize document page to the rectangle created in step 3
5) delete the rectangle
6) zoom to page ('5')
7) apply e.g. 'Extensions > Render > Gear > Gear'

Expected result:
The gear is inserted in the center of the current view (which is zoomed to the resized page area).

Actual result:
The gear is inserted outside the current view (the 'view center' ignores the transforms which had been added to the current layer by resizing the page to the selected rectangle).

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

Forgot to mention:
When testing the steps to reproduce, please keep bug #1086296 in mind (if the current layer was set to 'root' by toggling live preview of the render extension without a current selection, the gear is created outside the layer structure, and is not affected by the issue tracked here).

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

Updated diff based on current trunk (14506).

Revision history for this message
jazzynico (jazzynico) wrote :

Thanks for the steps!

Fix confirmed on Windows XP, Inkscape trunk rev. 14506.

Related, but not exactly the same cause, there are two other affected extensions: render_alphabetsoup and foldablebox. But they don't use view_center() to calculate the center.

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

On 2015-12-07 13:37 (+0100), jazzynico wrote:
> Related, but not exactly the same cause, there are two other
> affected extensions: render_alphabetsoup and foldablebox. But they
> don't use view_center() to calculate the center.

Initially, I omitted those two intentionally (since the position for the created object(s) is not related to the view center, and requires a different solution). Attached is an updated version of the diff which includes a fix for 'Alphabet Soup' and 'Foldable Box' as well. The change was also pushed to the related branch.

Revision history for this message
jazzynico (jazzynico) wrote :

Great! Thanks for the Alphabet soup and Foldable box extensions!
Tested successfully on windows XP, Inkscape trunk rev. 14527.

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

Merged in rev 14531.

@JazzyNico - thanks a lot for reviewing/testing!

Changed in inkscape:
milestone: none → 0.92
status: In Progress → Fix Committed
Bryce Harrington (bryce)
Changed in inkscape:
status: Fix Committed → Fix Released
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.