Skip to content

Commit 17b595a

Browse files
committed
Implement getAbsoluteTransform
1 parent 1c989d7 commit 17b595a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
*.user

source/lunasvg.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,25 @@ Matrix DomElement::getLocalTransform() const
332332

333333
Matrix DomElement::getAbsoluteTransform() const
334334
{
335-
return getLocalTransform();
335+
if(m_element == nullptr || !m_element->box())
336+
return Matrix();
337+
auto transform = m_element->box()->localTransform();
338+
for(auto currentElement = m_element->parent(); currentElement; currentElement = currentElement->parent()) {
339+
if(auto box = currentElement->box()) {
340+
transform.postmultiply(box->localTransform());
341+
}
342+
}
343+
344+
return transform;
336345
}
337346

338-
Bitmap DomElement::renderToBitmap(std::uint32_t width, std::uint32_t height, std::uint32_t backgroundColor) const {
347+
Bitmap DomElement::renderToBitmap(std::uint32_t width, std::uint32_t height, std::uint32_t backgroundColor) const
348+
{
339349
if(m_element == nullptr || !m_element->box())
340350
return Bitmap();
341-
342351
auto elementBounds = m_element->box()->map(m_element->box()->strokeBoundingBox());
343352
if(elementBounds.empty())
344353
return Bitmap();
345-
346354
if(width == 0 && height == 0) {
347355
width = static_cast<std::uint32_t>(std::ceil(elementBounds.w));
348356
height = static_cast<std::uint32_t>(std::ceil(elementBounds.h));

0 commit comments

Comments
 (0)