void SVGImage::defineMarker (const Marker& marker, int dfltname) { if( lastMarker == marker ) return; using namespace std; string name = marker.uniqueName(); //cout << name << endl;; string savedtab=tab; string marktab=string(" "); string intab=string(" "); ostr << tab << "<defs>\n"; double r = marker.getRange(); double r2 = 2*r; ostr << marktab << "<marker id=\"" << name << "\" markerUnits=\"strokeWidth\" " << "markerWidth=\"" << r2 << "\" markerHeight=\"" << r2 << "\" " << "viewBox=\"0 0 " << r2 << " " << r2 << "\" \n" << marktab << " " << "refX=\"" << r << "\" refY=\"" << r << "\" "; string col; { stringstream ss; ss.fill('0'); ss << '#' << hex << setw(6) << marker.getColor().getRGB(); col = ss.str(); } // These are here just in case. ostr.fill('0'); ostr << "stroke-width=\".2pt\" " << "fill=\"none\">\n"; // Initial marker tab is set up...now to put the shape in... if (marker.hasDefaultMark()) { Marker::Mark mark = marker.getMark(); switch(mark) { case Marker::DOT: ostr << intab << "<circle cx=\"" << r << "\" cy=\"" << r << "\" " <<"r=\"" << r << "\" style=\"fill:" << col << ";stroke:" << col << "\"/>\n"; break; case Marker::PLUS: ostr << intab << "<line x1=\"0\" y1=\"" << r << "\" " << "x2=\"" << r2 << "\" y2=\"" << r << "\"/>\n"; ostr << intab << "<line x1=\"" << r << "\" y1=\"0\" " << "x2=\"" << r << "\" y2=\"" << r2 << "\"/>\n"; break; case Marker::X: ostr << intab << "<line x1=\"0\" y1=\"0\" " << "x2=\"" << r2 << "\" y2=\"" << r2 << "\"/>\n"; ostr << intab << "<line x1=\"" << r2 << "\" y1=\"0\" " << "x2=\"0\" y2=\"" << r2 << "\"/>\n"; break; } } else { //This should not be called as BasicShapes were removed...but left // here as a placeholder if it ever comes back. //Todo: // * Make sure marker color works as necessary (useMarkerColor) // * Add some to the tab variable? // * Need to fix shape coordinates? //ostr << intab << markerShape << endl; } ostr << marktab << "</marker>\n"; ostr << tab << "</defs>\n"; markerDefined = true; lastMarker = marker; }
void SVGImage::line (const Line& line) { using namespace std; if ( line.size() == 0 ) { comment("Empty Line ignored..."); return; } Marker cmarker; StyleType tmarker = getCorrectMarker(&cmarker,line); if( tmarker == SHAPE ) { if ( !markerDefined || (lastMarker != line.getMarker()) ) { defineMarker( line.getMarker() ); } } StrokeStyle ss; StyleType tss = getCorrectStrokeStyle(&ss,line); if ( line.size() <= 2 ) { ostr << tab << "<line"; auto_ptr<Path> abspath = line.asAbsolute(); Path::const_iterator i=abspath->begin(); // Since there is no method for drawing a single point and there already // is a marker defined... if( line.size() == 1 ) { ostr << " x1=\"" << i->first << "\""; ostr << " y1=\"" << i->second << "\""; ostr << " x2=\"" << i->first << "\""; ostr << " y2=\"" << i->second << "\""; } else { ostr << " x1=\"" << i->first << "\""; ostr << " y1=\"" << i->second << "\""; i++; ostr << " x2=\"" << i->first << "\""; ostr << " y2=\"" << i->second << "\""; } string tmp = strokeDesc(ss,tss,((tmarker!=NONE)&&(tmarker!=CLEAR))); if(tmp.size()) ostr << " style=\"" << tmp << "\""; if( tmarker != NONE && tmarker != CLEAR ) { string mname = cmarker.uniqueName(); ostr << endl << tab << " marker-end=\"url(#" << mname << ")\" marker-mid=\"url(#" << mname << ")\" marker-start=\"url(#" << mname << ")\""; } //else if( hasDefaultMarker ) // ostr << endl << tab << " marker-end=\"url(#default)\" marker-mid=\"url(#default)\" marker-start=\"url(#default)\""; ostr << "/>" << endl; } else { // open line tag and specify x,y coords of two end points ostr << tab << "<polyline"; string tmp = strokeDesc(ss,tss,((tmarker!=NONE)&&(tmarker!=CLEAR))); if(tmp.size()) ostr << " style=\"" << tmp << "\""; if( tmarker != NONE && tmarker != CLEAR ) { string mname = cmarker.uniqueName(); ostr << endl << tab << " marker-end=\"url(#" << mname << ")\" marker-mid=\"url(#" << mname << ")\" marker-start=\"url(#" << mname << ")\""; } ostr << endl; outputPoints(line, ostr); // Close xml tag ostr << "/>" << endl; } }