@@ -125,35 +125,6 @@ string ofxSvgElement::toString( int nlevel ) {
125125 return tstr;
126126}
127127
128- // //--------------------------------------------------------------
129- // glm::mat4 ofxSvgElement::getTransformMatrix() {
130- // glm::mat4 rmat = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, pos.y, 0.0f));
131- // if( rotation != 0.0f ) {
132- // // glm::quat rq = glm::angleAxis(ofDegToRad(rotation), glm::vec3(0.f, 0.f, 1.0f ));
133- // // rmat = rmat * glm::toMat4((const glm::quat&)rq);
134- // rmat = glm::rotate(rmat, glm::radians(rotation), glm::vec3(0.f, 0.f, 1.f));
135- // }
136- // if( scale.x != 1.0f || scale.y != 1.0f ) {
137- // rmat = glm::scale(rmat, glm::vec3(scale.x, scale.y, 1.0f));
138- // }
139- // return rmat;
140- // };
141- //
142- // //--------------------------------------------------------------
143- // ofNode ofxSvgElement::getNodeTransform() {
144- // ofNode tnode;// = ofxSvgBase::getNodeTransform();
145- // tnode.setPosition(pos.x, pos.y, 0.0f);
146- // if( rotation != 0.0f ) {
147- // glm::quat rq = glm::angleAxis(ofDegToRad(rotation), glm::vec3(0.f, 0.f, 1.0f ));
148- // tnode.setOrientation(rq);
149- // }
150- // tnode.setScale(1.0f);
151- // if( scale.x != 1.0f || scale.y != 1.0f ) {
152- // tnode.setScale(scale.x, scale.y, 1.f );
153- // }
154- // return tnode;
155- // }
156-
157128// --------------------------------------------------------------
158129void ofxSvgPath::applyStyle (ofxSvgCssClass& aclass) {
159130 if ( aclass.hasProperty (" fill" )) {
@@ -221,25 +192,13 @@ void ofxSvgPath::applyStyle(ofxSvgCssClass& aclass) {
221192
222193// --------------------------------------------------------------
223194void ofxSvgPath::customDraw () {
224- // ofPushMatrix(); {
225- // transformGL(); {
226195
227196 bool bHasOffset = mOffsetPos .x != 0 .f || mOffsetPos .y != 0 .f ;
228197 if (bHasOffset) {
229198 ofPushMatrix ();
230199 ofTranslate (mOffsetPos .x , mOffsetPos .y );
231200 }
232201
233- ofSetColor ( ofColor::orange );
234- // ofDrawCircle(0, 0, 15);
235-
236- // ofTranslate(pos.x, pos.y);
237-
238- ofSetColor ( ofColor::green );
239- // ofDrawCircle(0, 0, 10);
240-
241- // if( rotation != 0.0 ) ofRotateZDeg( rotation );
242- // ofScale( scale.x, scale.y );
243202 if (isVisible ()) {
244203 ofColor fillColor = getFillColor ();
245204 ofColor strokeColor = getStrokeColor ();
@@ -266,17 +225,9 @@ void ofxSvgPath::customDraw() {
266225 if (bHasOffset) {
267226 ofPopMatrix ();
268227 }
269-
270- // } restoreTransformGL();
271- // } ofPopMatrix();
272228}
273229
274230#pragma mark - Image
275- // --------------------------------------------------------------
276- // ofRectangle ofxSvgImage::getRectangle() {
277- // return ofRectangle(pos.x, pos.y, getWidth(), getHeight());
278- // }
279-
280231// --------------------------------------------------------------
281232void ofxSvgImage::load () {
282233 if ( !bTryLoad ) {
@@ -295,15 +246,10 @@ void ofxSvgImage::customDraw() {
295246
296247 if ( isVisible () ) {
297248 if ( img.isAllocated () ) {
298- // ofPushMatrix(); {
299- // transformGL(); {
300- // ofTranslate( pos.x, pos.y );
301- // if( rotation != 0.0 ) ofRotateZDeg( rotation );
302- // ofScale( scale.x, scale.y );
303- if (bUseShapeColor) ofSetColor ( getColor () );
304- img.draw ( 0 , 0 );
305- // } ofPopMatrix();
306- // } restoreTransformGL();
249+ if (bUseShapeColor) {
250+ ofSetColor ( getColor () );
251+ }
252+ img.draw ( 0 , 0 );
307253 }
308254 }
309255}
@@ -318,6 +264,7 @@ void ofxSvgImage::customDraw() {
318264
319265
320266#pragma mark - Text
267+ // --------------------------------------------------------------
321268std::vector<std::string> ofxSvgText::splitBySpanTags (const std::string& input) {
322269 std::vector<std::string> result;
323270 std::regex span_regex (R"( <[^>]+>[\s\S]*?</[^>]+>)" ); // Match tags with content including newlines
@@ -349,11 +296,8 @@ std::vector<std::string> ofxSvgText::splitBySpanTags(const std::string& input) {
349296 return result;
350297}
351298
352- // struct SpanData {
353- // std::string style;
354- // std::string content;
355- // };
356299
300+ // --------------------------------------------------------------
357301ofxSvgText::SpanData ofxSvgText::extractSpanData (const std::string& spanTag) {
358302 SpanData data;
359303
@@ -375,6 +319,7 @@ ofxSvgText::SpanData ofxSvgText::extractSpanData(const std::string& spanTag) {
375319 return data;
376320}
377321
322+ // --------------------------------------------------------------
378323bool ofxSvgText::endsWithLineEnding (const std::string& astr) {
379324 if (astr.size () >= 2 && astr.substr (astr.size () - 2 ) == " \r\n " ) {
380325 // Windows line ending
@@ -386,6 +331,7 @@ bool ofxSvgText::endsWithLineEnding(const std::string& astr) {
386331 return false ;
387332}
388333
334+ // --------------------------------------------------------------
389335std::vector<std::string> ofxSvgText::splitWordsAndLineEndings (const std::string& input) {
390336 std::vector<std::string> result;
391337
@@ -401,9 +347,18 @@ std::vector<std::string> ofxSvgText::splitWordsAndLineEndings(const std::string&
401347 return result;
402348}
403349
404- // build the text spans from a string and not from xml //
350+ // build the text spans from a string and not from xml / svg file structure / /
405351// --------------------------------------------------------------
406352void ofxSvgText::setText ( const std::string& astring, std::string aFontFamily, int aFontSize, float aMaxWidth ) {
353+ ofxSvgCssClass css;
354+ css.addProperty (" font-family" , aFontFamily);
355+ css.addProperty (" font-size" , aFontSize);
356+ css.addProperty (" color" , getColor () );
357+ setText ( astring, css, aMaxWidth );
358+ }
359+
360+ // --------------------------------------------------------------
361+ void ofxSvgText::setText ( const std::string& astring, const ofxSvgCssClass& aSvgCssClass, float aMaxWidth ) {
407362 meshes.clear ();
408363 textSpans.clear ();
409364
@@ -422,10 +377,15 @@ void ofxSvgText::setText( const std::string& astring, std::string aFontFamily, i
422377 bool bLastCharIsSpace = false ;
423378
424379 // ofLogNotice("ofxSvgText") << "spanString: |" <<spanString<<"|";
425- ofxSvgCssClass css;
426- css.addProperty (" font-family" , aFontFamily);
427- css.addProperty (" font-size" , aFontSize);
428- css.addProperty (" color" , getColor () );
380+ ofxSvgCssClass css = mSvgCssClass ;
381+ if ( !css.hasProperty (" color" )) {
382+ // default to black
383+ css.setColor (ofColor (0 ));
384+ }
385+ css.setClassProperties ( aSvgCssClass );
386+ // css.addProperty("font-family", aFontFamily);
387+ // css.addProperty("font-size", aFontSize);
388+ // css.addProperty("color", getColor() );
429389 if (spanString.find (" <span" ) != std::string::npos) {
430390 SpanData data = extractSpanData (spanString);
431391// std::cout << "Found <span> tag.\n";
@@ -645,6 +605,10 @@ void ofxSvgText::create() {
645605 vector< std::shared_ptr<TextSpan> > tspans = textSpans;
646606
647607 for ( auto & tspan : textSpans ) {
608+
609+ // lets add any missing properties for the text spans from the ofxSvgText class
610+ tspan->mSvgCssClass .addMissingClassProperties (mSvgCssClass );
611+
648612// auto tkey = ofxSvgFontBook::getFontKey(tspan->getFontFamily(), tspan->isBold(), tspan->isItalic() );
649613 if ( !ofxSvgFontBook::hasFont (tspan->getFontFamily (), tspan->getFontSize (), tspan->isBold (), tspan->isItalic () )) {
650614 ofLogVerbose (" ofxSvgText" ) << " Trying to load font " << tspan->getFontFamily () << " bold: " << tspan->isBold () << " italic: " << tspan->isItalic () << " | " << ofGetFrameNum ();
@@ -742,65 +706,56 @@ void ofxSvgText::create() {
742706// ofRectangle()
743707// tempSpan->lineHeight = tfont.getStringBoundingBox("M", 0, 0).height;
744708 tempSpan->lineHeight = tfont.getLineHeight ();
745- // tempSpan.rect.x = tempSpan.rect.x - ogPos.x;
746- // tempSpan.rect.y = tempSpan.rect.x - ogPos.x;
747- // tempSpan.rect.y -= tempSpan.lineHeight;
748709 }
749710 }
750711}
751712
752713// --------------------------------------------------------------
753714void ofxSvgText::customDraw () {
754715 if ( !isVisible () ) return ;
755-
716+
756717 if (bUseShapeColor) {
757- ofSetColor ( 255 , 255 , 255 , 255 .f * alpha );
758- }
718+ ofSetColor ( 255 , 255 , 255 , 255 .f * alpha );
719+ }
759720 std::map< string, std::map<int , ofMesh> >::iterator mainIt;
760721
761722 if (areTextSpansDirty ()) {
762723 // sets textSpan->mBTextDirty to false;
763724 create ();
764725 }
765726
766- // transformGL(); {
767- ofTexture* tex = NULL ;
768- for ( mainIt = meshes.begin (); mainIt != meshes.end (); ++mainIt ) {
769- string fontKey = mainIt->first ;
770- std::map< int , ofMesh >::iterator mIt ;
771- for ( mIt = meshes[ fontKey ].begin (); mIt != meshes[ fontKey ].end (); ++mIt ) {
772- int fontSize = mIt ->first ;
773- // let's check to make sure that the texture is there, so that we can bind it //
774- bool bHasTexture = false ;
775- // if( fonts.count( fontKey ) ) {
776- if ( ofxSvgFontBook::hasBookFont (fontKey)) {
777- auto & fbook = ofxSvgFontBook::getBookFont (fontKey);
778- if ( fbook.textures .count ( fontSize ) ) {
779- bHasTexture = true ;
780- tex = &fbook.textures [ fontSize ];
781- }
727+ ofTexture* tex = NULL ;
728+ for ( mainIt = meshes.begin (); mainIt != meshes.end (); ++mainIt ) {
729+ string fontKey = mainIt->first ;
730+ std::map< int , ofMesh >::iterator mIt ;
731+ for ( mIt = meshes[ fontKey ].begin (); mIt != meshes[ fontKey ].end (); ++mIt ) {
732+ int fontSize = mIt ->first ;
733+ // let's check to make sure that the texture is there, so that we can bind it //
734+ bool bHasTexture = false ;
735+ // if( fonts.count( fontKey ) ) {
736+ if ( ofxSvgFontBook::hasBookFont (fontKey)) {
737+ auto & fbook = ofxSvgFontBook::getBookFont (fontKey);
738+ if ( fbook.textures .count ( fontSize ) ) {
739+ bHasTexture = true ;
740+ tex = &fbook.textures [ fontSize ];
782741 }
783-
784- if ( bHasTexture ) tex->bind ();
785- ofMesh& tMeshMesh = mIt ->second ;
786- if ( bUseShapeColor ) {
787- vector< ofFloatColor >& tcolors = tMeshMesh.getColors ();
788- for ( auto & tc : tcolors ) {
789- // if( bOverrideColor ) {
790- // tc = _overrideColor;
791- // } else {
792- tc.a = alpha;
793- // }
794- }
795- } else {
796- tMeshMesh.disableColors ();
742+ }
743+
744+ if ( bHasTexture ) tex->bind ();
745+ ofMesh& tMeshMesh = mIt ->second ;
746+ if ( bUseShapeColor ) {
747+ vector< ofFloatColor >& tcolors = tMeshMesh.getColors ();
748+ for ( auto & tc : tcolors ) {
749+ tc.a = alpha;
797750 }
798- tMeshMesh.draw ();
799- if ( bHasTexture ) tex->unbind ();
800- tMeshMesh.enableColors ();
751+ } else {
752+ tMeshMesh.disableColors ();
801753 }
754+ tMeshMesh.draw ();
755+ if ( bHasTexture ) tex->unbind ();
756+ tMeshMesh.enableColors ();
802757 }
803- // } restoreTransformGL();
758+ }
804759}
805760
806761// //--------------------------------------------------------------
@@ -878,15 +833,6 @@ ofTrueTypeFont& ofxSvgText::getFont() {
878833 return ofxSvgFontBook::defaultFont;
879834}
880835
881- // //--------------------------------------------------------------
882- // ofColor ofxSvgText::getColor() {
883- // if( textSpans.size() > 0 ) {
884- // return textSpans[0]->getColor();
885- // }
886- // ofLogWarning("ofxSvgText") << __FUNCTION__ << " : no font detected from text spans, returning black.";
887- // return ofColor(0,255);
888- // }
889-
890836// get the bounding rect for all of the text spans in this text element
891837// should be called after create //
892838// --------------------------------------------------------------
0 commit comments