Skip to content

Commit

Permalink
Implement getAbsoluteTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Apr 12, 2024
1 parent 1c989d7 commit 17b595a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
*.user
16 changes: 12 additions & 4 deletions source/lunasvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,25 @@ Matrix DomElement::getLocalTransform() const

Matrix DomElement::getAbsoluteTransform() const
{
return getLocalTransform();
if(m_element == nullptr || !m_element->box())
return Matrix();
auto transform = m_element->box()->localTransform();
for(auto currentElement = m_element->parent(); currentElement; currentElement = currentElement->parent()) {
if(auto box = currentElement->box()) {
transform.postmultiply(box->localTransform());
}
}

return transform;
}

Bitmap DomElement::renderToBitmap(std::uint32_t width, std::uint32_t height, std::uint32_t backgroundColor) const {
Bitmap DomElement::renderToBitmap(std::uint32_t width, std::uint32_t height, std::uint32_t backgroundColor) const
{
if(m_element == nullptr || !m_element->box())
return Bitmap();

auto elementBounds = m_element->box()->map(m_element->box()->strokeBoundingBox());
if(elementBounds.empty())
return Bitmap();

if(width == 0 && height == 0) {
width = static_cast<std::uint32_t>(std::ceil(elementBounds.w));
height = static_cast<std::uint32_t>(std::ceil(elementBounds.h));
Expand Down

0 comments on commit 17b595a

Please sign in to comment.