diff --git a/addons/ofxSvg/src/ofxSvgElements.cpp b/addons/ofxSvg/src/ofxSvgElements.cpp index 2d9128aca26..cf7d0ef8692 100755 --- a/addons/ofxSvg/src/ofxSvgElements.cpp +++ b/addons/ofxSvg/src/ofxSvgElements.cpp @@ -238,6 +238,14 @@ void ofxSvgImage::load() { } } +//-------------------------------------------------------------- +bool ofxSvgImage::load( const of::filesystem::path& afilePath ) { + filepath = afilePath; + bTryLoad = false; + load(); + return isLoaded(); +} + //-------------------------------------------------------------- void ofxSvgImage::customDraw() { if( !bTryLoad ) { diff --git a/addons/ofxSvg/src/ofxSvgElements.h b/addons/ofxSvg/src/ofxSvgElements.h index 3b97a908826..b6b5293375e 100755 --- a/addons/ofxSvg/src/ofxSvgElements.h +++ b/addons/ofxSvg/src/ofxSvgElements.h @@ -213,6 +213,13 @@ class ofxSvgPath : public ofxSvgElement { virtual ofRectangle getBoundingBox() override { if(mBBoxNeedsRecalc) { mBBoxNeedsRecalc = false; + + // Note: Hack to force outlines by setting a stroke if there is none. + float prevStrokeWidth = path.getStrokeWidth(); + if( prevStrokeWidth < 1.0f ) { + path.setStrokeWidth(1.f); + } + // ofRectangle brect; const auto& outlines = path.getOutline(); if( outlines.size() > 0 ) { @@ -232,6 +239,8 @@ class ofxSvgPath : public ofxSvgElement { } } } + + path.setStrokeWidth(prevStrokeWidth); } return mBounds; }; @@ -392,6 +401,7 @@ class ofxSvgImage : public ofxSvgElement { }; void load(); + bool load( const of::filesystem::path& afilePath ); bool isLoaded() { return (img.isAllocated() && img.getWidth() > 0 && img.getHeight() > 0); } diff --git a/addons/ofxSvg/src/ofxSvgGroup.h b/addons/ofxSvg/src/ofxSvgGroup.h index 753d11b239d..3e577bae1b4 100755 --- a/addons/ofxSvg/src/ofxSvgGroup.h +++ b/addons/ofxSvg/src/ofxSvgGroup.h @@ -84,7 +84,9 @@ class ofxSvgGroup : public ofxSvgElement { bool bFirstRect = true; auto allEs = getAllElements(false); for( auto& ele : allEs ) { - auto erect = ele->getBoundingBox(); + // Grab the global bounding box so that we can put it into the group space later + // If we just grab the element local bounding box, it doesn't account for position, rotation, etc. + auto erect = ele->getGlobalBoundingBox(); if( erect.width > 0 && erect.height > 0 ) { if(bFirstRect) { rrect = erect; @@ -94,6 +96,20 @@ class ofxSvgGroup : public ofxSvgElement { bFirstRect = false; } } + + if( !bFirstRect ) { + // Now lets put the rectangle into the group transform space. + auto gmat = getGlobalTransformMatrix(); + auto gmatInv = glm::inverse(gmat); + + std::vector rverts = { rrect.getTopLeft(), rrect.getTopRight(), rrect.getBottomRight(), rrect.getBottomLeft()}; + + for( auto& rv : rverts ) { + rv = glm::vec3(gmatInv * glm::vec4(rv, 1.f)); + } + return _calculateExtents( rverts ); + } + return rrect; };