[PATCH] [Cairomm] Allow creation of SVG/PDF/PS surfaces without specifing a file name
Patrick Niklaus <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAFxP+1NvZQfBcs16h=yfYeLy4Uz-_7hHd30j3w9-yd9_9Z8OBQ@mail.gmail.com> |
Hey, cairomm currently does not allow to create PngSurface, SvgSurface and PsSurface without specifying a file name or a write function. However the cairo API allows this by passing NULL as file name. [1] This is a simple patch to add this functionality to cairomm. Regards, Patrick [1] http://www.cairographics.org/manual/cairo-SVG-Surfaces.html#cairo-svg-surface-create -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
0001-Allow-creation-of-SVG-PS-PDF-surfaces-without-a-file.patch
(application/octet-stream, 4.4 KB)
From c30e98805fb57172c3cec029e8d86e428f974e26 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus <[email protected]> Date: Sun, 20 Jan 2013 18:12:31 +0100 Subject: [PATCH] Allow creation of SVG/PS/PDF surfaces without a file/buffer --- cairomm/surface.cc | 21 +++++++++++++++++++++ cairomm/surface.h | 26 ++++++++++++++++++++++++++ 2 Dateien geändert, 47 Zeilen hinzugefügt(+) diff --git a/cairomm/surface.cc b/cairomm/surface.cc index 88e72cf..3ad9e8b 100644 --- a/cairomm/surface.cc +++ b/cairomm/surface.cc @@ -382,6 +382,13 @@ PdfSurface::~PdfSurface() // surface is destroyed in base class } +RefPtr<PdfSurface> PdfSurface::create(double width_in_points, double height_in_points) +{ + cairo_surface_t* cobject = cairo_pdf_surface_create(NULL, width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr<PdfSurface>(new PdfSurface(cobject, true /* has reference */)); +} + RefPtr<PdfSurface> PdfSurface::create(std::string filename, double width_in_points, double height_in_points) { cairo_surface_t* cobject = cairo_pdf_surface_create(filename.c_str(), width_in_points, height_in_points); @@ -457,6 +464,13 @@ PsSurface::~PsSurface() // surface is destroyed in base class } +RefPtr<PsSurface> PsSurface::create(double width_in_points, double height_in_points) +{ + cairo_surface_t* cobject = cairo_ps_surface_create(NULL, width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr<PsSurface>(new PsSurface(cobject, true /* has reference */)); +} + RefPtr<PsSurface> PsSurface::create(std::string filename, double width_in_points, double height_in_points) { cairo_surface_t* cobject = cairo_ps_surface_create(filename.c_str(), width_in_points, height_in_points); @@ -565,6 +579,13 @@ SvgSurface::~SvgSurface() // surface is destroyed in base class } +RefPtr<SvgSurface> SvgSurface::create(double width_in_points, double height_in_points) +{ + cairo_surface_t* cobject = cairo_svg_surface_create(NULL, width_in_points, height_in_points); + check_status_and_throw_exception(cairo_surface_status(cobject)); + return RefPtr<SvgSurface>(new SvgSurface(cobject, true /* has reference */)); +} + RefPtr<SvgSurface> SvgSurface::create(std::string filename, double width_in_points, double height_in_points) { cairo_surface_t* cobject = cairo_svg_surface_create(filename.c_str(), width_in_points, height_in_points); diff --git a/cairomm/surface.h b/cairomm/surface.h index 64412cb..0650cd4 100644 --- a/cairomm/surface.h +++ b/cairomm/surface.h @@ -614,6 +614,16 @@ public: explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false); virtual ~PdfSurface(); + + /** Creates a PdfSurface that may be queried and used as a source, without + * generating a temporary file. + * + * @param width_in_points The width of the PDF document in points + * @param height_in_points The height of the PDF document in points + * @since 1.2 + */ + static RefPtr<PdfSurface> create(double width_in_points, double height_in_points); + /** Creates a PdfSurface with a specified dimensions that will be saved as * the given filename * @@ -717,6 +727,13 @@ public: explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false); virtual ~PsSurface(); + /** Creates a PsSurface that may be queried and used as a source, without + * generating a temporary file. + * @param width_in_points The width of the PostScript document in points + * @param height_in_points The height of the PostScript document in points + */ + static RefPtr<PsSurface> create(double width_in_points, double height_in_points); + /** Creates a PsSurface with a specified dimensions that will be saved as the * given filename * @@ -882,6 +899,15 @@ public: */ static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points); + + /** Creates a SvgSurface that may be queried and used as a source, without + * generating a temporary file. + * + * @param width_in_points The width of the SVG document in points + * @param height_in_points The height of the SVG document in points + */ + static RefPtr<SvgSurface> create(double width_in_points, double height_in_points); + /** Creates a SvgSurface with a specified dimensions that will be written to * the given write function instead of saved directly to disk * -- 1.7.11.7