diff options
author | Murray Cumming <murrayc@murrayc.com> | 2010-09-10 14:12:01 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2010-09-10 14:12:01 +0200 |
commit | 621454362cc0c85ee47a37f17aed35bb2780aefb (patch) | |
tree | 593b8276bbbf61e8011d2b44e08290a0ab486ff1 | |
parent | 1dcaaa6dd18e0b69b876c75f741434ae1ec7b4f2 (diff) |
Context, Surface: Add some new methods.
* cairomm/context.[h|cc]: Added in_clip().
* cairomm/surface.[h|cc]: Added get_mime_data(), set_mime_data(),
unset_mime_data().
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | cairomm/context.cc | 7 | ||||
-rw-r--r-- | cairomm/context.h | 1 | ||||
-rw-r--r-- | cairomm/surface.cc | 34 | ||||
-rw-r--r-- | cairomm/surface.h | 50 |
5 files changed, 95 insertions, 5 deletions
@@ -1,3 +1,11 @@ +2010-09-10 Murray Cumming <murrayc@murrayc-desktop> + + Context, Surface: Add some new methods. + + * cairomm/context.[h|cc]: Added in_clip(). + * cairomm/surface.[h|cc]: Added get_mime_data(), set_mime_data(), + unset_mime_data(). + 2010-09-07 Murray Cumming <murrayc@murrayc.com> Added Device class. diff --git a/cairomm/context.cc b/cairomm/context.cc index b70da2b..d758fe1 100644 --- a/cairomm/context.cc +++ b/cairomm/context.cc @@ -441,6 +441,13 @@ bool Context::in_fill(double x, double y) const return result; } +bool Context::in_clip(double x, double y) const +{ + const bool result = cairo_in_clip(const_cast<cobject*>(cobj()), x, y); + check_object_status_and_throw_exception(*this); + return result; +} + void Context::get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const { cairo_stroke_extents(const_cast<cobject*>(cobj()), &x1, &y1, &x2, &y2); diff --git a/cairomm/context.h b/cairomm/context.h index 499d9e7..59c679e 100644 --- a/cairomm/context.h +++ b/cairomm/context.h @@ -721,6 +721,7 @@ public: void show_page(); bool in_stroke(double x, double y) const; bool in_fill(double x, double y) const; + bool in_clip(double x, double y) const; void get_stroke_extents(double& x1, double& y1, double& x2, double& y2) const; void get_fill_extents(double& x1, double& y1, double& x2, double& y2) const; diff --git a/cairomm/surface.cc b/cairomm/surface.cc index eb527e6..c801ec5 100644 --- a/cairomm/surface.cc +++ b/cairomm/surface.cc @@ -89,6 +89,40 @@ void Surface::finish() check_object_status_and_throw_exception(*this); } +const unsigned char* Surface::get_mime_data(const std::string& mime_type, unsigned long& length) +{ + const unsigned char* data = 0; + cairo_surface_get_mime_data(const_cast<cobject*>(cobj()), mime_type.c_str(), &data, &length); + check_object_status_and_throw_exception(*this); + return data; +} + + +static void on_cairo_destroy(void *data) +{ + Surface::SlotDestroy* slot = static_cast<Surface::SlotDestroy*>(data); + if(!slot) + return; + + (*slot)(); + delete slot; +} + +void Surface::set_mime_data(const std::string& mime_type, unsigned char* data, unsigned long length, const SlotDestroy& slot_destroy) +{ + SlotDestroy* copy = new SlotDestroy(slot_destroy); //Deleted when the callback is called once. + cairo_surface_set_mime_data(const_cast<cobject*>(cobj()), mime_type.c_str(), data, length, + &on_cairo_destroy, copy); + check_object_status_and_throw_exception(*this); +} + +void Surface::unset_mime_data(const std::string& mime_type) +{ + cairo_surface_set_mime_data(const_cast<cobject*>(cobj()), mime_type.c_str(), + 0, 0, 0, 0); + check_object_status_and_throw_exception(*this); +} + void Surface::get_font_options(FontOptions& options) const { cairo_font_options_t* cfontoptions = cairo_font_options_create(); diff --git a/cairomm/surface.h b/cairomm/surface.h index c5b234b..3ec1a1a 100644 --- a/cairomm/surface.h +++ b/cairomm/surface.h @@ -64,7 +64,7 @@ namespace Cairo * different subtypes of cairo surface for different drawing backends. This * class is a base class for all subtypes and should not be used directly * - * Surfaces are reference-counted objects that should be used via Cairo::RefPtr. + * Surfaces are reference-counted objects that should be used via Cairo::RefPtr. */ class Surface { @@ -108,6 +108,46 @@ public: virtual ~Surface(); + /** Return mime data previously attached to surface using the specified mime type. If no data has been attached with the given mime type then this returns 0. + * + * @param mime_type The MIME type of the image data. + * @param length This will be set to the length of the image data. + * @result The image data attached to the surface. + */ + const unsigned char* get_mime_data(const std::string& mime_type, unsigned long& length); + + + /** For instance, + * void on_destroy(); + */ + typedef sigc::slot<void> SlotDestroy; + + /** Attach an image in the format mime_type to surface. To remove the data from + * a surface, call unset_mime_data() with same mime type. + * + * The attached image (or filename) data can later be used by backends which + * support it (currently: PDF, PS, SVG and Win32 Printing surfaces) to emit + * this data instead of making a snapshot of the surface. This approach tends + * to be faster and requires less memory and disk space. + * + * The recognized MIME types are the following: CAIRO_MIME_TYPE_JPEG, + * CAIRO_MIME_TYPE_PNG, CAIRO_MIME_TYPE_JP2, CAIRO_MIME_TYPE_URI. + * + * See corresponding backend surface docs for details about which MIME types + * it can handle. Caution: the associated MIME data will be discarded if you + * draw on the surface afterwards. Use this function with care. + * + * @param mime_type The MIME type of the image data. + * @param data The image data to attach to the surface. + * @param length The length of the image data. + * @param slot_destroy A callback slot that will be called when the Surface no longer needs the data. For instance, when the Surface is destroyed or when new image data is attached using the same MIME tpe. + */ + void set_mime_data(const std::string& mime_type, unsigned char* data, unsigned long length, const SlotDestroy& slot_destroy); + + /** Remove the data from a surface. See set_mime_data(). + */ + void unset_mime_data(const std::string& mime_type); + /** Retrieves the default font rendering options for the surface. This allows * display surfaces to report the correct subpixel order for rendering on * them, print surfaces to disable hinting of metrics and so forth. The @@ -319,12 +359,12 @@ private: * An ImageSurface is the most generic type of Surface and the only one that is * available by default. You can either create an ImageSurface whose data is * managed by Cairo, or you can create an ImageSurface with a data buffer that - * you allocated yourself so that you can have full access to the data. + * you allocated yourself so that you can have full access to the data. * * When you create an ImageSurface with your own data buffer, you are free to * examine the results at any point and do whatever you want with it. Note that * if you modify anything and later want to continue to draw to the surface - * with cairo, you must let cairo know via Cairo::Surface::mark_dirty() + * with cairo, you must let cairo know via Cairo::Surface::mark_dirty() * * Note that like all surfaces, an ImageSurface is a reference-counted object that should be used via Cairo::RefPtr. */ @@ -753,7 +793,7 @@ public: /** @deprecated Use SvgSurface::create_for_stream() instead */ static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points); - /** + /** * Restricts the generated SVG file to the given version. See get_versions() * for a list of available version values that can be used here. * @@ -767,7 +807,7 @@ public: /** Retrieves the list of SVG versions supported by cairo. See * restrict_to_version(). - * + * * @since 1.2 */ static const std::vector<SvgVersion> get_versions(); |