lunasvg
lunasvg copied to clipboard
Local transformation and internal SVG element access - Element translation
Data
This issue refers to: issue 98 Library version: v2.3.9 (master) Testing SVG file: groups.svg.zip (InkScape)
Document | Details | InkScape SVG Properties |
---|---|---|
unit: px document W: 163 H: 288 Top left (0, 0) Bottom rigth (163, 288) Center (81.5, 144) g1 (group 1) W: 163 H: 152 B1 (0, 0) Bottom rigth (163, 152) C1 (81.5, 76) g2 (group 2) W: 108 H: 111 B2 (50, 178) Bottom rigth (158, 288) C2 (104, 232.5) |
Scope
I want to translate in X the element g1 applying a translation of -81.5px, which is half of document width.
Testing code
// Load document
auto document = Document::loadFromFile(filesvg);
Box dbox(0, 0, document->width(), document->height());
// Retrieve the SVG element - g1
auto elementg1 = document->getElementById("g1");
auto boxg1 = elementg1.getBBox().transformed(elementg1.getAbsoluteTransform());
// Retrieve element transformation matrix - g1
auto transformg1 = elementg1.getLocalTransform();
// Modify the transformation matrix
transformg1.translate(-81.5, 0);
// Apply the modified transformation to the SVG element.
setTransformAttribute(elementg1, transformg1);
// Document update
document->updateLayout();
// Render bitmap
auto bitmap = document->renderToBitmap();
Results
The element g1 disappears from the document; it happens using both methods
auto transformg1 = elementg1.getLocalTransform();
or
auto transformg1 = elementg1.getAbsoluteTransform();
Expected | Obtained |
---|---|