Skip to content

Commit 0122e95

Browse files
committed
fixes for no stroke and adding elements
1 parent 554fd82 commit 0122e95

4 files changed

Lines changed: 25 additions & 100 deletions

File tree

addons/ofxSvg/src/ofxSvg.cpp

Lines changed: 7 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -868,53 +868,10 @@ shared_ptr<ofxSvgElement> ofxSvg::_addElementFromXmlNode( ofXml& tnode, vector<
868868
// getTransformFromSvgMatrix( transAttr.getValue(), telement->pos, telement->scale.x, telement->scale.y, telement->rotation );
869869
setTransformFromSvgMatrixString( transAttr.getValue(), telement );
870870
}
871-
872-
// std::vector<ofxSvgType> typesToApplyTransformToPath = {
873-
// OFXSVG_TYPE_RECTANGLE,
874-
// OFXSVG_TYPE_CIRCLE,
875-
// OFXSVG_TYPE_ELLIPSE
876-
// };
877-
878-
// bool bApplyTransformToPath = false;
879-
// for( auto & etype : typesToApplyTransformToPath ) {
880-
// if( etype == telement->getType() ) {
881-
// bApplyTransformToPath = true;
882-
// break;
883-
// }
884-
// }
885-
886-
// if( bApplyTransformToPath ) {
887-
// auto epath = std::dynamic_pointer_cast<ofxSvgPath>( telement );
888-
// auto outlines = epath->path.getOutline();
889-
//// auto transform = epath->getTransformMatrix();
890-
// auto transform = epath->getGlobalTransformMatrix();
891-
// for( auto& outline : outlines ) {
892-
// for( auto& v : outline ) {
893-
// v = transform * glm::vec4(v, 1.0f);
894-
// }
895-
// }
896-
// // now we have new outlines, what do we do?
897-
// epath->path.clear();
898-
// bool bFirstOne = true;
899-
// for( auto& outline : outlines ) {
900-
// for( auto& v : outline ) {
901-
// if(bFirstOne) {
902-
// bFirstOne = false;
903-
// epath->path.moveTo(v);
904-
// } else {
905-
// epath->path.lineTo(v);
906-
// }
907-
// }
908-
// if( outline.isClosed() ) {
909-
// epath->path.close();
910-
// }
911-
// }
912-
// }
913871
}
914872

915873
if( telement->getType() == OFXSVG_TYPE_TEXT ) {
916874
auto text = std::dynamic_pointer_cast<ofxSvgText>( telement );
917-
// text->ogPos = text->pos;
918875
text->create();
919876
}
920877

@@ -931,9 +888,7 @@ shared_ptr<ofxSvgElement> ofxSvg::_addElementFromXmlNode( ofXml& tnode, vector<
931888
if( mGroupStack.size() > 0 ) {
932889
auto pgroup = mGroupStack.back();
933890
ofLogVerbose("ofxSvg::_addElementFromXmlNode") << "element: " << telement->getTypeAsString() << " -" << telement->getCleanName() << "- pos: " << telement->getPosition() << "- parent: " << pgroup->getCleanName();
934-
// telement->setParent(*pgroup.get(), false);
935891
telement->setParent(*_getPushedGroup(), false);
936-
//ofLogNotice("");
937892
}
938893

939894
return telement;
@@ -959,21 +914,6 @@ std::vector<float> parseToFloats(const std::string& input) {
959914
}
960915

961916
std::vector<glm::vec3> parsePoints(const std::string& input) {
962-
// std::vector<glm::vec3> points;
963-
// std::regex regex("[-]?\\d*\\.?\\d+"); // Matches positive/negative floats
964-
// std::sregex_iterator begin(input.begin(), input.end(), regex), end;
965-
//
966-
// std::vector<float> values;
967-
//
968-
// // Extract all floating-point values using regex
969-
// for (std::sregex_iterator i = begin; i != end; ++i) {
970-
// try {
971-
// values.push_back(std::stof((*i).str()));
972-
// } catch (const std::invalid_argument&) {
973-
// std::cerr << "Invalid number found: " << (*i).str() << std::endl;
974-
// }
975-
// }
976-
977917
std::vector<glm::vec3> points;
978918
auto values = parseToFloats( input );
979919

@@ -1739,19 +1679,12 @@ void ofxSvg::_parsePath( ofXml& tnode, std::shared_ptr<ofxSvgPath> aSvgPath ) {
17391679
ofLogWarning("ofxSvg") << "unable to parse arc segment.";
17401680
}
17411681
}
1742-
1743-
// prevCmd = commandT;
1744-
// mCenterPoints.push_back(currentPos);
1745-
// mCPoints.insert( mCPoints.end(), npositions.begin(), npositions.end() );
17461682
}
17471683

17481684
// ofLogNotice("ofxSvg") << "["<<cchar<<"]: " << currentString;
17491685

1750-
17511686
justInCase++;
17521687
}
1753-
1754-
// mCurrentPathPos = currentPos;
17551688
}
17561689

17571690
//--------------------------------------------------------------
@@ -2029,23 +1962,6 @@ glm::mat4 ofxSvg::setTransformFromSvgMatrixString( string aStr, std::shared_ptr<
20291962
// aele->pos.y = pos3.y;
20301963

20311964
ofLogVerbose("ofxSvg::setTransformFromSvgMatrixString") << "pos: " << aele->getPosition() << " rotation: " << trotation << " scale: " << aele->getScale();
2032-
2033-
// apos.x = matrixF[4];
2034-
// apos.y = matrixF[5];
2035-
//
2036-
// scaleX = std::sqrtf(matrixF[0] * matrixF[0] + matrixF[1] * matrixF[1]) * (float)ofSign(matrixF[0]);
2037-
// scaleY = std::sqrtf(matrixF[2] * matrixF[2] + matrixF[3] * matrixF[3]) * (float)ofSign(matrixF[3]);
2038-
//
2039-
// arotation = glm::degrees( std::atan2f(matrixF[2],matrixF[3]) );
2040-
// if( scaleX < 0 && scaleY < 0 ){
2041-
//
2042-
// }else{
2043-
// arotation *= -1.0f;
2044-
// }
2045-
// cout << " rotation is " << arotation << endl;
2046-
// std::cout << "matrix rotation is " << arotation << " ScaleX: " << scaleX << " scaleY: " << scaleY << " apos: " << apos << std::endl;
2047-
2048-
// return true;
20491965
}
20501966
}
20511967

@@ -2339,6 +2255,8 @@ std::shared_ptr<ofxSvgRectangle> ofxSvg::add( const ofRectangle& arect ) {
23392255
std::shared_ptr<ofxSvgRectangle> ofxSvg::add( const ofRectangle& arect, float aRoundRadius ) {
23402256
auto rect = std::make_shared<ofxSvgRectangle>();
23412257
rect->setPosition(arect.x, arect.y, 0.0f);
2258+
rect->width = arect.getWidth();
2259+
rect->height = arect.getHeight();
23422260
rect->roundRadius = -1; // force setting round
23432261
rect->setRoundRadius(std::max(0.f,aRoundRadius));
23442262
rect->applyStyle(mCurrentCss);
@@ -2853,7 +2771,6 @@ bool ofxSvg::_toXml( ofXml& aParentNode, std::shared_ptr<ofxSvgElement> aele ) {
28532771

28542772

28552773
} else if( aele->getType() == OFXSVG_TYPE_TEXT ) {
2856-
// TODO: Maybe at some point ;/
28572774
auto ttext = std::dynamic_pointer_cast<ofxSvgText>(aele);
28582775
for( auto tspan : ttext->textSpans ) {
28592776
if( auto spanXml = txml.appendChild("tspan")) {
@@ -2870,17 +2787,12 @@ bool ofxSvg::_toXml( ofXml& aParentNode, std::shared_ptr<ofxSvgElement> aele ) {
28702787
}
28712788

28722789
// figure out if we need a transform attribute
2873-
// if( aele->getType() == OFXSVG_TYPE_IMAGE || aele->getRotationDeg() != 0.0f || aele->getScale().x != 1.0f || aele->getScale().y != 1.0f ) {
2874-
auto matrixString = getSvgMatrixStringFromElement(aele);
2875-
if( !matrixString.empty() ) {
2876-
if( auto xattr = txml.appendAttribute("transform")) {
2877-
xattr.set(matrixString);
2878-
}
2790+
auto matrixString = getSvgMatrixStringFromElement(aele);
2791+
if( !matrixString.empty() ) {
2792+
if( auto xattr = txml.appendAttribute("transform")) {
2793+
xattr.set(matrixString);
28792794
}
2880-
// if( auto xattr = txml.appendAttribute("transform")) {
2881-
// xattr.set( getSvgMatrixStringFromElement(aele) );
2882-
// }
2883-
// }
2795+
}
28842796
return txml;
28852797
}
28862798

addons/ofxSvg/src/ofxSvgCss.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ bool ofxSvgCssClass::addProperties( std::string aPropertiesString ) {
196196
addProperty(propStr);
197197
// pindex++;
198198
}
199-
200-
// for( auto& prop : properties ) {
201-
// ofLogNotice("ofx::svg2::CssClass") << " prop: " << prop.first << " : " << prop.second.srcString;
202-
// }
203199
}
204200
return properties.size() > 0;
205201
}
@@ -248,6 +244,13 @@ bool ofxSvgCssClass::addProperty( const std::string& aName, const ofColor& acolo
248244
return addProperty(aName, prop );
249245
}
250246

247+
//--------------------------------------------------
248+
bool ofxSvgCssClass::removeProperty( std::string aPropString ) {
249+
bool bHas = hasProperty(aPropString);
250+
properties.erase(aPropString);
251+
return bHas;
252+
}
253+
251254
//--------------------------------------------------
252255
bool ofxSvgCssClass::setColor(const ofColor& acolor) {
253256
return addProperty("color", acolor);
@@ -280,7 +283,10 @@ bool ofxSvgCssClass::setStrokeWidth( const float& awidth ) {
280283

281284
//--------------------------------------------------
282285
bool ofxSvgCssClass::setNoStroke() {
283-
return addProperty("stroke", "none" );
286+
// return addProperty("stroke", "none" );
287+
bool bstroke = removeProperty("stroke");
288+
bool bstrokeW = removeProperty("stroke-width");
289+
return bstroke || bstrokeW;
284290
}
285291

286292
//--------------------------------------------------

addons/ofxSvg/src/ofxSvgCss.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class ofxSvgCssClass {
4040
bool addProperty( const std::string& aName, const float& avalue );
4141
bool addProperty( const std::string& aName, const ofColor& acolor );
4242

43+
bool removeProperty( std::string aPropString );
44+
4345
bool setColor(const ofColor& acolor);
4446

4547
bool setFillColor(const ofColor& acolor);

addons/ofxSvg/src/ofxSvgElements.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class ofxSvgElement : public ofNode {
4343
/// \brief Get the name of the element; or the id attribute from the xml node.
4444
/// \return std::string name of element.
4545
std::string getName() { return name; }
46+
/// \brief Set the name of the element; or the id attribute of the xml node.
47+
/// \param aname string; name to be used for the element
48+
void setName( const std::string& aname ) {
49+
name = aname;
50+
}
4651
/// \brief Get name with escaped characters and attempts to remove added naming patterns.
4752
/// Removes the numbers added to the name by illustrator
4853
/// ie. lelbow_00000070086365269320197030000010368508730034196876_ becomes lelbow

0 commit comments

Comments
 (0)