#ifndef SVG_H # define SVG_H # include # include using std::string; using std::vector; // --------------------------------------------------------------------- // Use 'Colors::red' (for example) to refer to that color or // 'Colors::none' if you want to indicate that nothing should be drawn // --------------------------------------------------------------------- namespace Colors { static const string none = "none"; static const string red = "red"; static const string green = "green"; static const string blue = "blue"; static const string black = "black"; static const string cyan = "cyan"; static const string magenta = "magenta"; static const string yellow = "yellow"; }; // --------------------------------------------------------------------- // Constructs an SVG object and accumulates commands (rect, circle) // which are ultimately output via the 'write' method. // --------------------------------------------------------------------- class SVG { public: // ------------------------------------------------------------------ // SVG - Construct an SVG object using 'width' and 'height' // ------------------------------------------------------------------ SVG(int width, int height) : mWidth(width), mHeight(height) { } // ------------------------------------------------------------------ // rect - Draw a rectangle at (x, y) using 'width', 'height' and // 'fill' (use 'Colors::none' if you don't wish to fill) // and edge with color 'stroke' (as above, use 'Colors::none' // if you don't want an edge) // ------------------------------------------------------------------ void rect( int x, int y, int width, int height, const string &stroke, const string &fill ); // ------------------------------------------------------------------ // circle - Draw a circle at (x, y) with radius: 'radius' // ------------------------------------------------------------------ void circle( int x, int y, int radius, const string &stroke, const string &fill ); // ------------------------------------------------------------------ // line - Draw a line from (x1, y1) to (x2, y2) // ------------------------------------------------------------------ void line( int x1, int y1, int x2, int y2, const string &color ); // ------------------------------------------------------------------ // border - Draw a border using color 'color' // ------------------------------------------------------------------ void border(const string &color); // ------------------------------------------------------------------ // Get the SVG file's width and height // ------------------------------------------------------------------ int getWidth() const; int getHeight() const; // ------------------------------------------------------------------ // write - Write the svg data to 'fileName', returns: true on // success, false otherwise 'errMsg' will contain a message // with details about the error // ------------------------------------------------------------------ bool write(const string &fileName, string &errMsg); private: int mWidth; int mHeight; vector mCommands; }; #endif