summaryrefslogtreecommitdiff
path: root/FL/Fl_SVG_Image.H
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-10-31 16:56:23 +0000
committerManolo Gouy <Manolo>2017-10-31 16:56:23 +0000
commit839f52bc18dda4ce96b87c630c935d559e3bcb60 (patch)
tree9bdf7a1ff422f57aa380776bb871549df6fda832 /FL/Fl_SVG_Image.H
parentb1cff66e86566bbed8897b0edb9873b93ccbc08b (diff)
Fix for STR#3421: Fl_SVG_Image crashes if passed an svg file that is a static const char* string
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12536 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL/Fl_SVG_Image.H')
-rw-r--r--FL/Fl_SVG_Image.H62
1 files changed, 60 insertions, 2 deletions
diff --git a/FL/Fl_SVG_Image.H b/FL/Fl_SVG_Image.H
index 0965b2639..b734ded77 100644
--- a/FL/Fl_SVG_Image.H
+++ b/FL/Fl_SVG_Image.H
@@ -43,6 +43,64 @@ struct NSVGimage;
The FLTK library can optionally be built without SVG support; in that case,
class Fl_SVG_Image is unavailable.
+
+ Example of displaying a hard-coded svg file:
+ \code
+ #include <FL/Fl.H>
+ #include <FL/Fl_Window.H>
+ #include <FL/Fl_Box.H>
+ #include <FL/Fl_SVG_Image.H>
+
+ // A black rotated rectangle
+ const char *svg_data = "<svg viewBox=\"0 0 200 200\" version = \"1.1\">\n"
+ "<rect x=\"25\" y=\"50\" width=\"150\" height=\"100\" fill=\"black\" "
+ "transform=\"rotate(45 100 100)\"> </svg>\n";
+
+ int main(int argc, char **argv) {
+ Fl_SVG_Image *svg = new Fl_SVG_Image(0, svg_data); // create SVG object
+ Fl_Window *win = new Fl_Window(720, 486, "svg test");
+ Fl_Box *box = new Fl_Box(0,0,win->w(),win->h());
+ box->image(svg); // assign svg object to Fl_Box
+ win->end();
+ win->show(argc,argv);
+ return(Fl::run());
+ }
+ \endcode
+
+ Example of displaying an svg image from a file:
+ \code
+ #include <errno.h> // errno
+ #include <string.h> // strerror
+ #include <FL/Fl.H>
+ #include <FL/Fl_Window.H>
+ #include <FL/Fl_Box.H>
+ #include <FL/Fl_SVG_Image.H>
+ #include <FL/fl_message.H>
+ int main(int argc, char **argv) {
+ Fl_Window *win = new Fl_Window(720, 486, "svg test");
+ Fl_Box *box = new Fl_Box(0,0,win->w(),win->h());
+
+ // Load svg image from disk, assign to a box
+ const char *svgpath = "/var/tmp/simple.svg";
+ Fl_SVG_Image *svg = new Fl_SVG_Image(svgpath); // load SVG object from disk
+ switch ( svg->fail() ) {
+ case Fl_Image::ERR_FILE_ACCESS:
+ // File couldn't load? show path + os error to user
+ fl_alert("%s: %s", svgpath, strerror(errno));
+ return 1;
+ case Fl_Image::ERR_FORMAT:
+ // Parsing error
+ fl_alert("%s: couldn't decode image", svgpath);
+ return 1;
+ }
+ box->image(svg); // assign svg object to box
+
+ win->end();
+ win->show(argc,argv);
+ return(Fl::run());
+ }
+ \endcode
+
*/
class FL_EXPORT Fl_SVG_Image : public Fl_RGB_Image {
private:
@@ -58,7 +116,7 @@ private:
float average_weight_;
float svg_scaling_(int W, int H);
void rasterize_(int W, int H);
- void init_(const char *filename, char *filedata, Fl_SVG_Image *copy_source);
+ void init_(const char *filename, const char *filedata, Fl_SVG_Image *copy_source);
Fl_SVG_Image(Fl_SVG_Image *source);
protected:
virtual int draw_scaled(int X, int Y, int W, int H);
@@ -66,7 +124,7 @@ public:
/** Set this to \c false to allow image re-scaling that alters the image aspect ratio.
Upon object creation, \c proportional is set to \c true, and the aspect ratio is kept constant.*/
bool proportional;
- Fl_SVG_Image(const char *filename, char *filedata = NULL);
+ Fl_SVG_Image(const char *filename, const char *filedata = NULL);
virtual ~Fl_SVG_Image();
virtual Fl_Image *copy(int W, int H);
void resize(int width, int height);