Outputting in SVG format

This is a discussion on Outputting in SVG format within the C++ Programming forums, part of the General Programming Boards category; Does anyone have examples of how to output in SVG format? I did a search on the boards and didn't ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    11

    Outputting in SVG format

    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.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Lund, Sweden
    Posts
    18
    With SVG, do you mean Scalar Vector Graphics? In that case, what exactly do you want to output as an SVG document?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    11
    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.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Lund, Sweden
    Posts
    18
    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?

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    11
    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.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    11
    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.

    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/>;
                          }
    I need to overload the operator >> when I do this output.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    11
    Last edited by Basca; 10-09-2006 at 02:38 PM.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Location
    Lund, Sweden
    Posts
    18
    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();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  2. function returning hour in either 12 or 24 hour format
    By stanlvw in forum C Programming
    Replies: 4
    Last Post: 01-01-2008, 05:02 AM
  3. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  4. Seeking Format Advice
    By PsychoBrat in forum Game Programming
    Replies: 3
    Last Post: 10-05-2005, 05:41 AM
  5. Outputting in a Chart Format
    By glider_pilot123 in forum C Programming
    Replies: 9
    Last Post: 10-14-2004, 06:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21