I recently asked a question on how to flip an SVG object, vertically or horizontally:
Now, programmatically I wanna be able to move, rotate and scale the object while it's still being flipped vertically or horizontaly.
I draw all usual objects in my Android app, then I'm saving it as an SVG object. All of my calculations on Android work's just right.
When I export to SVG, I know: Each objects properties (ScaleX, ScaleY, Rotation, CenterX, CenterY, MovedX, MovedY) and Width of SVG Document, Height of SVG Document but I can't seem to get it to export right. I thought I solved it, but then something's missing and I can't figure out what. And I guess I can't be the only one ever thought of this, otherwise at least this question serve some purpose.
An example of what can be done through "touch" input on my Android app:
- Draw a rectangle from Left, Top to Right, Bottom
- On add: Calculate center of the object (fix if right < left and such) save as CenterX and CenterY
- Move the object if wanted, save it as MoveX and MoveY (won't override Left/Top/Right/Bottom)
- Rotate the object and convert it to a degree and save it as Rotation
- Scale the object, but not lower than 0.1 Scale and save it as ScaleX and ScaleY
- Export it as Rectangle (x=Left, y=Top, Width=Right-Left, Height=Bottom-Right)
- Add the colors, strokes and such and then the "transform" attribute.
When an object is scaled, it's scaled around it's CENTER. When an object is rotated, it's rotated around it's center. When it's moved, it adds the difference between Current touched point on the screen and the Previous one.
Now if certain flags are set "VerticalFlip" or "HorizontalFlip", Android draws the flipped variant at the same time you draw it. When exported, it checks the object if it has either of these flags.
This is an example of how I've been calculating but maybe I'm missing something entirely, or I'm complicating things:
There's also a link below each algorithm that demonstrates that the algorithm works at least at that instance.
Now when I save it, using the exact system. Being provided all the necessary values to export it correctly, it still doesn't work. Some objects look just right, other's are entirely out of shape. Even if they've all been flipped, moved, rotated and scaled. Some of the objects exported look exactly like they should - while others do not.
Left is a screenshot of the drawing in the app, the right is the exported SVG in Inkscape. SVG Size = Size of screen that was drawing it. No scaling of the whole screen when exporting. All objects here have been scaled, rotated and moved. Only the red object here is obvious that something's wrong.