Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions addons/ofxSvg/src/ofxSvgElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
10 changes: 10 additions & 0 deletions addons/ofxSvg/src/ofxSvgElements.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -232,6 +239,8 @@ class ofxSvgPath : public ofxSvgElement {
}
}
}

path.setStrokeWidth(prevStrokeWidth);
}
return mBounds;
};
Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 17 additions & 1 deletion addons/ofxSvg/src/ofxSvgGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<glm::vec3> 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;
};

Expand Down
Loading