Does anyone have examples of how to output in SVG format? I did a search on the boards and didn't get anything to return.
Does anyone have examples of how to output in SVG format? I did a search on the boards and didn't get anything to return.
With SVG, do you mean Scalar Vector Graphics? In that case, what exactly do you want to output as an SVG document?
Yes SVG=scalar vector graphics, and i'm attempting to output shapes and then fill in the color of the shape. Basically the program will have the user input for a rectangle the lower left coordinates (x,y) the width (w) the height(h) and the color, then output the shape drawn in SVG format.
To me that seems quite easy. First create a SVG document with a rectangle, take a look at the source. Now, what depends on user input?
Where is the problem? What have you done so far?
Well I guess my problem is in that I'm relativly new to programming, and completely unfamiliar with SVG. You say to just open an SVG file and create a rect and look at the source, but I'm not familiar with that. I've done all the code within C++ but the output, and I can list the code for you if you like, it's rather long and lacking comments at the moment, but I can put in the comments if you wish to view the code.
This is basically what my output code looks like right now, and I know that it is extremely incorrect, I was just taking a shot in the dark.
I need to overload the operator >> when I do this output.Code:ostream operator >>(ostream& outputStream, Rectangle& z) { outputStream << Rectangle:<Rectangle x=z.x y=z.y width=z.w height=z.h fill=z.color/>; }
Last edited by Basca; 10-09-2006 at 02:38 PM.
I took a look at the SVG example file http://www.w3schools.com/svg/rect1.svg
So in practice I just output an identical document, except for the height and width variables.
Code:#include <fstream> #include <iostream> #include <string> using namespace std; int main() { string fname; int width, height; cout << "Width: "; cin >> width; cout << "Height: "; cin >> height; cout << "Save as: "; cin >> fname; ofstream file(fname.c_str()); file << "<?xml version=\"1.0\" standalone=\"no\"?>" << endl << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" " << "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << endl << " <svg width=\"100%\" height=\"100%\" version=\"1.1\"" << " xmlns=\"http://www.w3.org/2000/svg\">" << endl << " <rect width=\"" << width << "\" height=\"" << height << "\"" << " style=\"fill:rgb(0,0,255); stroke-width:1; " << "stroke:rgb(0,0,0)\"/>" << endl << "</svg>" << endl; file.close(); }