diff options
author | Jonathon Jongsma <jjongsma@gnome.org> | 2010-12-30 22:22:40 -0600 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@gnome.org> | 2010-12-30 22:22:40 -0600 |
commit | a464fb2b63ddf64425badadb14ed170fc8570c9a (patch) | |
tree | 1d1257dd243f09fa5c22b51a8b1214f79d389843 | |
parent | a1927df3f7987fde2ca03555524ee96617d30cd8 (diff) |
Add PDF versioning API
New PdfSurface functions:
get_versions()
restrict_to_version()
version_to_string()
-rw-r--r-- | cairomm/surface.cc | 27 | ||||
-rw-r--r-- | cairomm/surface.h | 32 |
2 files changed, 59 insertions, 0 deletions
diff --git a/cairomm/surface.cc b/cairomm/surface.cc index 802ce00..c5fe9ef 100644 --- a/cairomm/surface.cc +++ b/cairomm/surface.cc @@ -408,6 +408,33 @@ void PdfSurface::set_size(double width_in_points, double height_in_points) check_object_status_and_throw_exception(*this); } +void PdfSurface::restrict_to_version(PdfVersion version) +{ + cairo_pdf_surface_restrict_to_version(cobj(), static_cast<cairo_pdf_version_t>(version)); + check_object_status_and_throw_exception(*this); +} + +const std::vector<PdfVersion> PdfSurface::get_versions() +{ + cairo_pdf_version_t const *versions; + int num_versions; + cairo_pdf_get_versions(&versions, &num_versions); + + // Just copy the version array out into a std::vector. + std::vector<PdfVersion> vec; + for (int i = 0; i < num_versions; ++i) + { + vec.push_back(static_cast<PdfVersion>(versions[i])); + } + return vec; +} + +std::string PdfSurface::version_to_string(PdfVersion version) +{ + const char *cstring = cairo_pdf_version_to_string(static_cast<cairo_pdf_version_t>(version)); + return cstring ? std::string(cstring) : std::string(); +} + #endif // CAIRO_HAS_PDF_SURFACE diff --git a/cairomm/surface.h b/cairomm/surface.h index 9d1cfdf..c5bfb95 100644 --- a/cairomm/surface.h +++ b/cairomm/surface.h @@ -520,6 +520,12 @@ public: * An example of using Cairo::PdfSurface class to render to PDF */ +typedef enum +{ + PDF_VERSION_1_4 = CAIRO_PDF_VERSION_1_4, + PDF_VERSION_1_5 = CAIRO_PDF_VERSION_1_5 +} PdfVersion; + /** A PdfSurface provides a way to render PDF documents from cairo. This * surface is not rendered to the screen but instead renders the drawing to a * PDF file on disk. @@ -577,6 +583,32 @@ public: **/ void set_size(double width_in_points, double height_in_points); + /** + * Restricts the generated PDF file to version. See get_versions() for a list + * of available version values that can be used here. + * + * This function should only be called before any drawing operations have been + * performed on the given surface. The simplest way to do this is to call this + * function immediately after creating the surface. + * + * @since 1.10 + */ + void restrict_to_version(PdfVersion version); + + /** Retrieves the list of PDF versions supported by cairo. See + * restrict_to_version(). + * + * @since 1.10 + */ + static const std::vector<PdfVersion> get_versions(); + + /** Get the string representation of the given version id. This function will + * return an empty string if version isn't valid. See get_versions() + * for a way to get the list of valid version ids. + * + * @since 1.10 + */ + static std::string version_to_string(PdfVersion version); }; #endif // CAIRO_HAS_PDF_SURFACE |