26 double maximum_x = bounding_box->
max_x();
27 double minimum_x = bounding_box->
min_x();
28 double maximum_y = bounding_box->
max_y();
29 double minimum_y = bounding_box->
min_y();
32 double x_span = maximum_x - minimum_x;
33 double y_span = maximum_y - minimum_y;
37 double x_scale = x_width / x_span;
38 double y_scale = y_height / y_span;
42 x_scale = std::min(x_scale, y_scale);
47 double scaled_x_span = x_span;
48 double scaled_y_span = y_span;
53 double x_offset = (minimum_x + maximum_x) / 2.0 - scaled_x_span / 2.0;
55 double y_offset = (minimum_y + maximum_y) / 2.0 + scaled_y_span / 2.0;
91 void SVG::line(
double x1,
double y1,
double x2,
double y2,
96 "<line x1=\"%f%s\" y1=\"%f%s\"",
99 " x2=\"%f%s\" y2=\"%f%s\"",
102 " style=\"stroke:%s\"/>\n", stroke);
127 (void)sprintf(file_name,
"%s.svg", base_name);
130 File__format(stderr,
"Unable to open %s.svg\n", base_name);
143 "<?xml version=\"1.0\" standalone=\"no\"?>\n\n");
145 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
147 " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n\n");
149 "<svg width=\"%f%s\" height=\"%f%s\"\n",
150 width * x_scale, units, height * y_scale, units);
152 " version=\"1.1\"\n");
154 " xmlns=\"http://www.w3.org/2000/svg\">\n\n");
177 "<rect x=\"%f%s\" y=\"%f%s\"", x_final,
units, y_final,
units);
179 " width=\"%f%s\" height=\"%f%s\"",
182 " style=\"stroke:%s; fill:%s\"/>\n", stroke_color, fill_color);
200 "<text x=\"%f%s\" y=\"%f%s\"",
203 " style=\"font-family:%s; font-size:%d\">", font_family, font_size);
double width
Width of SVG image.
SVG(String_Const base_name, double width, double height, double x_scale, double y_scale, String_Const units)
Open an SVG object:
double y_scale
Amount to scale Y by.
double y_offset
Amount to offset Y by.
void File__close(File file)
Closes file.
void cartesian_scale(double x_width, double y_height, BoundingBox *bounding_box)
Turns svg into a cartesian graphing canvas bounded by bounding_box.
double x_scale
Amount to scale X by.
FILE * File
FILE is a file I/O object.
void line(double x1, double y1, double x2, double y2, String_Const stroke)
Draw a line from (x1, y1) to (x2, y2) using stroke.
void File__format(File file, String_Const format,...)
will write format out to file with all patterns that start with "%" replaced by formatted versions of...
File stream
The output stream.
void text(String_Const message, double x, double y, String_Const font_family, unsigned int font_size)
draw message at (x, y).
double x_offset
Amount to offset X by.
void setOffsets(double x_offset, double y_offset)
String_Const units
Units to use for SVG values.
double height
Hight of SVG image.
File File__open(String_Const file_name, String_Const flags)
will open file_name using flags to specify read/write options.
const char * String_Const
bool String__equal(String_Const string1, String_Const string2)
Returns true if string1 equals string2.
void rectangle(double x, double y, double width, double height, String_Const stroke_color, String_Const fill_color)
Draw a width by height rectangle at (x, y).