1
0
Fork 0

Canvas/SVG parser: fix bounding box and rotation center.

- Calculate bounding box after adding all children.
 - Apply rotation after all SVG defined rotations to use correct
   center of rotation (as defined in Inkscape)

This (together with the SimGear and FlightGear commits) fixes
the core problems of #1333.
This commit is contained in:
Thomas Geymayer 2014-02-08 00:38:30 +01:00
parent e9ce8d522b
commit bab393aa0c
2 changed files with 10 additions and 4 deletions

View file

@ -218,7 +218,12 @@ var Element = {
if( me['_tf_rot'] == nil )
# always use the first matrix slot to ensure correct rotation
# around transformation center.
me['_tf_rot'] = Transform.new(me._node.getNode("tf[0]", 1));
# tf-rot-index can be set to change the slot to be used. This is used for
# example by the SVG parser to apply the rotation after all
# transformations defined in the SVG file.
me['_tf_rot'] = Transform.new(
me._node.getNode("tf[" ~ me.get("tf-rot-index", 0) ~ "]", 1)
);
me._tf_rot.setRotation(rot, me.getCenter());
return me;

View file

@ -70,6 +70,10 @@ var parsesvg = func(group, path, options = nil)
# Remove the topmost element from the stack
var popElement = func
{
stack[-1].updateCenter();
# Create rotation matrix after all SVG defined transformations
stack[-1].set("tf-rot-index", stack[-1].createTransform()._node.getIndex());
pop(stack);
pop(close_stack);
}
@ -469,9 +473,6 @@ var parsesvg = func(group, path, options = nil)
var cy = attr['inkscape:transform-center-y'];
if( cy != nil and cy != 0 )
stack[-1].setDouble("center-offset-y", -evalCSSNum(cy));
if( cx != nil or cy != nil )
stack[-1].updateCenter();
};
# XML parsers element close callback