Blame cairomm/surface.h

Packit 908522
/* Copyright (C) 2005 The cairomm Development Team
Packit 908522
 *
Packit 908522
 * This library is free software; you can redistribute it and/or
Packit 908522
 * modify it under the terms of the GNU Library General Public
Packit 908522
 * License as published by the Free Software Foundation; either
Packit 908522
 * version 2 of the License, or (at your option) any later version.
Packit 908522
 *
Packit 908522
 * This library is distributed in the hope that it will be useful,
Packit 908522
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 908522
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 908522
 * Library General Public License for more details.
Packit 908522
 *
Packit 908522
 * You should have received a copy of the GNU Library General Public
Packit 908522
 * License along with this library; if not, write to the Free Software
Packit 908522
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 908522
 * 02110-1301, USA.
Packit 908522
 */
Packit 908522
Packit 908522
#ifndef __CAIROMM_SURFACE_H
Packit 908522
#define __CAIROMM_SURFACE_H
Packit 908522
Packit 908522
#include <string>
Packit 908522
#include <vector>
Packit 908522
Packit 908522
/* following is required for OS X */
Packit 908522
Packit 908522
#ifdef nil
Packit 908522
#undef nil
Packit 908522
#include <sigc++/slot.h>
Packit 908522
#define nil NULL
Packit 908522
#else
Packit 908522
#include <sigc++/slot.h>
Packit 908522
#endif
Packit 908522
Packit 908522
/* end OS X */
Packit 908522
Packit 908522
#include <cairomm/enums.h>
Packit 908522
#include <cairomm/exception.h>
Packit 908522
#include <cairomm/device.h>
Packit 908522
#include <cairomm/fontoptions.h>
Packit 908522
#include <cairomm/refptr.h>
Packit 908522
Packit 908522
//See xlib_surface.h for XlibSurface.
Packit 908522
//See win32_surface.h for Win32Surface.
Packit 908522
//See quartz_surface.h for QuartzSurface (Mac OS X).
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_PDF_SURFACE
Packit 908522
#include <cairo-pdf.h>
Packit 908522
#endif // CAIRO_HAS_PDF_SURFACE
Packit 908522
#ifdef CAIRO_HAS_PS_SURFACE
Packit 908522
#include <cairo-ps.h>
Packit 908522
#endif // CAIRO_HAS_PS_SURFACE
Packit 908522
#ifdef CAIRO_HAS_SVG_SURFACE
Packit 908522
#include <cairo-svg.h>
Packit 908522
#endif // CAIRO_HAS_SVG_SURFACE
Packit 908522
Packit 908522
// Experimental surfaces
Packit 908522
#ifdef CAIRO_HAS_GLITZ_SURFACE
Packit 908522
#include <cairo-glitz.h>
Packit 908522
#endif // CAIRO_HAS_GLITZ_SURFACE
Packit 908522
Packit 908522
Packit 908522
namespace Cairo
Packit 908522
{
Packit 908522
Packit 908522
/** A cairo surface represents an image, either as the destination of a drawing
Packit 908522
 * operation or as source when drawing onto another surface. There are
Packit 908522
 * different subtypes of cairo surface for different drawing backends.  This
Packit 908522
 * class is a base class for all subtypes and should not be used directly
Packit 908522
 *
Packit 908522
 * Most surface types allow accessing the surface without using Cairo
Packit 908522
 * functions. If you do this, keep in mind that it is mandatory that you call
Packit 908522
 * Cairo::Surface::flush() before reading from or writing to the surface and that
Packit 908522
 * you must use Cairo::Surface::mark_dirty() after modifying it.
Packit 908522
 *
Packit 908522
 * Surfaces are reference-counted objects that should be used via Cairo::RefPtr.
Packit 908522
 */
Packit 908522
class Surface
Packit 908522
{
Packit 908522
public:
Packit 908522
  /** For example:
Packit 908522
   * 
Packit 908522
   * ErrorStatus my_write_func(unsigned char* data, unsigned int length);
Packit 908522
   * 
Packit 908522
   *
Packit 908522
   * This is the type of function which is called when a backend needs to write
Packit 908522
   * data to an output stream. It is passed the data to write and the length of
Packit 908522
   * the data in bytes. The write function should return CAIRO_STATUS_SUCCESS if
Packit 908522
   * all the data was successfully written, CAIRO_STATUS_WRITE_ERROR otherwise.
Packit 908522
   *
Packit 908522
   * @param data the buffer containing the data to write
Packit 908522
   * @param length the amount of data to write
Packit 908522
   * @return the status code of the write operation
Packit 908522
   */
Packit 908522
  typedef sigc::slot<ErrorStatus, const unsigned char* /*data*/, unsigned int /*length*/> SlotWriteFunc;
Packit 908522
Packit 908522
  /**
Packit 908522
   * This is the type of function which is called when a backend needs to read
Packit 908522
   * data from an input stream. It is passed the buffer to read the data into
Packit 908522
   * and the length of the data in bytes. The read function should return
Packit 908522
   * CAIRO_STATUS_SUCCESS if all the data was successfully read,
Packit 908522
   * CAIRO_STATUS_READ_ERROR otherwise.
Packit 908522
   *
Packit 908522
   * @param data the buffer into which to read the data
Packit 908522
   * @param length the amount of data to read
Packit 908522
   * @return the status code of the read operation
Packit 908522
   */
Packit 908522
  typedef sigc::slot<ErrorStatus, unsigned char* /*data*/, unsigned int /*length*/> SlotReadFunc;
Packit 908522
Packit 908522
  /** Create a C++ wrapper for the C instance. This C++ instance should then be
Packit 908522
   * given to a RefPtr.
Packit 908522
   *
Packit 908522
   * @param cobject The C instance.
Packit 908522
   * @param has_reference Whether we already have a reference. Otherwise, the
Packit 908522
   * constructor will take an extra reference.
Packit 908522
   */
Packit 908522
  explicit Surface(cairo_surface_t* cobject, bool has_reference = false);
Packit 908522
Packit 908522
  Surface(const Surface&) = delete;
Packit 908522
  Surface& operator=(const Surface&) = delete;
Packit 908522
Packit 908522
  virtual ~Surface();
Packit 908522
Packit 908522
  /**
Packit 908522
   * Return mime data previously attached to surface using the specified mime
Packit 908522
   * type. If no data has been attached with the given mime type then this
Packit 908522
   * returns 0.
Packit 908522
   *
Packit 908522
   * @param mime_type The MIME type of the image data.
Packit 908522
   * @param length This will be set to the length of the image data.
Packit 908522
   * @returns The image data attached to the surface.
Packit 908522
   * @since 1.10
Packit 908522
   */
Packit 908522
  const unsigned char* get_mime_data(const std::string& mime_type, unsigned long& length);
Packit 908522
Packit 908522
Packit 908522
  /** For instance,
Packit 908522
   * void on_destroy();
Packit 908522
   */
Packit 908522
  typedef sigc::slot<void> SlotDestroy;
Packit 908522
Packit 908522
  /** Attach an image in the format mime_type to surface. To remove the data from
Packit 908522
   * a surface, call unset_mime_data() with same mime type.
Packit 908522
   *
Packit 908522
   * The attached image (or filename) data can later be used by backends which
Packit 908522
   * support it (currently: PDF, PS, SVG and Win32 Printing surfaces) to emit
Packit 908522
   * this data instead of making a snapshot of the surface. This approach tends
Packit 908522
   * to be faster and requires less memory and disk space.
Packit 908522
   *
Packit 908522
   * The recognized MIME types are the following: CAIRO_MIME_TYPE_JPEG,
Packit 908522
   * CAIRO_MIME_TYPE_PNG, CAIRO_MIME_TYPE_JP2, CAIRO_MIME_TYPE_URI.
Packit 908522
   *
Packit 908522
   * See corresponding backend surface docs for details about which MIME types
Packit 908522
   * it can handle. Caution: the associated MIME data will be discarded if you
Packit 908522
   * draw on the surface afterwards. Use this function with care.
Packit 908522
   *
Packit 908522
   * @param mime_type The MIME type of the image data. param data The image
Packit 908522
   * @data to attach to the surface. param length The length of the image data.
Packit 908522
   * @param slot_destroy A callback slot that will be called when the Surface
Packit 908522
   *   no longer needs the data. For instance, when the Surface is destroyed or
Packit 908522
   *   when new image data is attached using the same MIME tpe.
Packit 908522
   * @since 1.10
Packit 908522
   */
Packit 908522
  void set_mime_data(const std::string& mime_type, unsigned char* data,
Packit 908522
                     unsigned long length, const SlotDestroy& slot_destroy);
Packit 908522
Packit 908522
  /** Remove the data from a surface. See set_mime_data().
Packit 908522
   */
Packit 908522
  void unset_mime_data(const std::string& mime_type);
Packit 908522
Packit 908522
  /** Retrieves the default font rendering options for the surface. This allows
Packit 908522
   * display surfaces to report the correct subpixel order for rendering on
Packit 908522
   * them, print surfaces to disable hinting of metrics and so forth. The
Packit 908522
   * result can then be used with cairo_scaled_font_create().
Packit 908522
   *
Packit 908522
   * @param options 	a FontOptions object into which to store the retrieved
Packit 908522
   * options. All existing values are overwritten
Packit 908522
   */
Packit 908522
  void get_font_options(FontOptions& options) const;
Packit 908522
Packit 908522
  /** This function finishes the surface and drops all references to external
Packit 908522
   * resources. For example, for the Xlib backend it means that cairo will no
Packit 908522
   * longer access the drawable, which can be freed. After calling
Packit 908522
   * finish() the only valid operations on a surface are getting and setting
Packit 908522
   * user data and referencing and destroying it. Further drawing to the
Packit 908522
   * surface will not affect the surface but will instead trigger a
Packit 908522
   * CAIRO_STATUS_SURFACE_FINISHED error.
Packit 908522
   *
Packit 908522
   * When the Surface is destroyed, cairo will call finish() if it hasn't been
Packit 908522
   * called already, before freeing the resources associated with the Surface.
Packit 908522
   */
Packit 908522
  void finish();
Packit 908522
Packit 908522
  /** Do any pending drawing for the surface and also restore any temporary
Packit 908522
   * modifications cairo has made to the surface's state. This function must
Packit 908522
   * be called before switching from drawing on the surface with cairo to
Packit 908522
   * drawing on it directly with native APIs. If the surface doesn't support
Packit 908522
   * direct access, then this function does nothing.
Packit 908522
   */
Packit 908522
  void flush();
Packit 908522
Packit 908522
  /** Tells cairo to consider the data buffer dirty.
Packit 908522
   *
Packit 908522
   * In particular, if you've created an ImageSurface with a data buffer that
Packit 908522
   * you've allocated yourself and you draw to that data buffer using means
Packit 908522
   * other than cairo, you must call mark_dirty() before doing any additional
Packit 908522
   * drawing to that surface with cairo.
Packit 908522
   *
Packit 908522
   * Note that if you do draw to the Surface outside of cairo, you must call
Packit 908522
   * flush() before doing the drawing.
Packit 908522
   */
Packit 908522
  void mark_dirty();
Packit 908522
Packit 908522
  /** Marks a rectangular area of the given surface dirty.
Packit 908522
   *
Packit 908522
   * @param x 	 X coordinate of dirty rectangle
Packit 908522
   * @param y 	Y coordinate of dirty rectangle
Packit 908522
   * @param width 	width of dirty rectangle
Packit 908522
   * @param height 	height of dirty rectangle
Packit 908522
   */
Packit 908522
  void mark_dirty(int x, int y, int width, int height);
Packit 908522
Packit 908522
  /** Sets an offset that is added to the device coordinates determined by the
Packit 908522
   * CTM when drawing to surface. One use case for this function is when we
Packit 908522
   * want to create a Surface that redirects drawing for a portion of
Packit 908522
   * an onscreen surface to an offscreen surface in a way that is completely
Packit 908522
   * invisible to the user of the cairo API. Setting a transformation via
Packit 908522
   * cairo_translate() isn't sufficient to do this, since functions like
Packit 908522
   * Cairo::Context::device_to_user() will expose the hidden offset.
Packit 908522
   *
Packit 908522
   * Note that the offset only affects drawing to the surface, not using the
Packit 908522
   * surface in a surface pattern.
Packit 908522
   *
Packit 908522
   * @param x_offset 	the offset in the X direction, in device units
Packit 908522
   * @param y_offset 	the offset in the Y direction, in device units
Packit 908522
   */
Packit 908522
  void set_device_offset(double x_offset, double y_offset);
Packit 908522
Packit 908522
  /** Returns a previous device offset set by set_device_offset().
Packit 908522
   */
Packit 908522
  void get_device_offset(double& x_offset, double& y_offset) const;
Packit 908522
Packit 908522
  /**
Packit 908522
   * Set the horizontal and vertical resolution for image fallbacks.
Packit 908522
   *
Packit 908522
   * When certain operations aren't supported natively by a backend, cairo will
Packit 908522
   * fallback by rendering operations to an image and then overlaying that
Packit 908522
   * image onto the output. For backends that are natively vector-oriented,
Packit 908522
   * this function can be used to set the resolution used for these image
Packit 908522
   * fallbacks, (larger values will result in more detailed images, but also
Packit 908522
   * larger file sizes).
Packit 908522
   *
Packit 908522
   * Some examples of natively vector-oriented backends are the ps, pdf, and
Packit 908522
   * svg backends.
Packit 908522
   *
Packit 908522
   * For backends that are natively raster-oriented, image fallbacks are still
Packit 908522
   * possible, but they are always performed at the native device resolution.
Packit 908522
   * So this function has no effect on those backends.
Packit 908522
   *
Packit 908522
   * Note: The fallback resolution only takes effect at the time of completing
Packit 908522
   * a page (with Context::show_page() or Context::copy_page()) so there is
Packit 908522
   * currently no way to have more than one fallback resolution in effect on a
Packit 908522
   * single page.
Packit 908522
   *
Packit 908522
   * The default fallback resoultion is 300 pixels per inch in both dimensions.
Packit 908522
   *
Packit 908522
   * @param x_pixels_per_inch   Pixels per inch in the x direction
Packit 908522
   * @param y_pixels_per_inch   Pixels per inch in the y direction
Packit 908522
   *
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  void set_fallback_resolution(double x_pixels_per_inch, double y_pixels_per_inch);
Packit 908522
Packit 908522
  /** This function returns the previous fallback resolution set by
Packit 908522
   * set_fallback_resolution(), or default fallback resolution if never set.
Packit 908522
   *
Packit 908522
   * @param x_pixels_per_inch horizontal pixels per inch
Packit 908522
   * @param y_pixels_per_inch vertical pixels per inch
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  void get_fallback_resolution(double& x_pixels_per_inch, double& y_pixels_per_inch) const;
Packit 908522
Packit 908522
  SurfaceType get_type() const;
Packit 908522
Packit 908522
  /**
Packit 908522
   * This function returns the content type of surface which indicates whether
Packit 908522
   * the surface contains color and/or alpha information.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  Content get_content() const;
Packit 908522
Packit 908522
  /**
Packit 908522
   * Emits the current page for backends that support multiple pages,
Packit 908522
   * but doesn't clear it, so that the contents of the current page will
Packit 908522
   * be retained for the next page.  Use show_page() if you want to get an empty
Packit 908522
   * page after the emission.
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   */
Packit 908522
  void copy_page();
Packit 908522
Packit 908522
  /**
Packit 908522
   * Emits and clears the current page for backends that support multiple pages.
Packit 908522
   * Use copy_page() if you don't want to clear the page.
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   */
Packit 908522
  void show_page();
Packit 908522
Packit 908522
  /** Returns whether the surface supports sophisticated
Packit 908522
   * Context::show_text_glyphs() operations.  That is, whether it actually uses
Packit 908522
   * the provided text and cluster data to a Context::show_text_glyphs() call.
Packit 908522
   *
Packit 908522
   * Note: Even if this function returns %FALSE, a Context::show_text_glyphs()
Packit 908522
   * operation targeted at this surface will still succeed.  It just will act
Packit 908522
   * like a Context::show_glyphs() operation.  Users can use this function to
Packit 908522
   * avoid computing UTF-8 text and cluster mapping if the target surface does
Packit 908522
   * not use it.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   **/
Packit 908522
  bool has_show_text_glyphs() const;
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_PNG_FUNCTIONS
Packit 908522
Packit 908522
  /** Writes the contents of surface to a new file filename as a PNG image.
Packit 908522
   *
Packit 908522
   * @note For this function to be available, cairo must have been compiled
Packit 908522
   * with PNG support
Packit 908522
   *
Packit 908522
   * @param filename	the name of a file to write to
Packit 908522
   */
Packit 908522
  void write_to_png(const std::string& filename);
Packit 908522
Packit 908522
  /** Writes the Surface to the write function.
Packit 908522
   *
Packit 908522
   * @note For this function to be available, cairo must have been compiled
Packit 908522
   * with PNG support
Packit 908522
   *
Packit 908522
   * @param write_func  The function to be called when the backend needs to
Packit 908522
   * write data to an output stream
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  void write_to_png_stream(const SlotWriteFunc& write_func);
Packit 908522
Packit 908522
  /** @deprecated Use write_to_png_stream instead */
Packit 908522
  void write_to_png(cairo_write_func_t write_func, void *closure);
Packit 908522
Packit 908522
#endif // CAIRO_HAS_PNG_FUNCTIONS
Packit 908522
Packit 908522
  /** This function returns the device for a surface
Packit 908522
   * @return The device for this surface, or an empty RefPtr if the surface has
Packit 908522
   * no associated device */
Packit 908522
  RefPtr<Device> get_device();
Packit 908522
Packit 908522
  /** The underlying C cairo surface type
Packit 908522
   */
Packit 908522
  typedef cairo_surface_t cobject;
Packit 908522
  /** Provides acces to the underlying C cairo surface
Packit 908522
   */
Packit 908522
  inline cobject* cobj() { return m_cobject; }
Packit 908522
  /** Provides acces to the underlying C cairo surface
Packit 908522
   */
Packit 908522
  inline const cobject* cobj() const { return m_cobject; }
Packit 908522
Packit 908522
  #ifndef DOXYGEN_IGNORE_THIS
Packit 908522
  ///For use only by the cairomm implementation.
Packit 908522
  inline ErrorStatus get_status() const
Packit 908522
  { return cairo_surface_status(const_cast<cairo_surface_t*>(cobj())); }
Packit 908522
Packit 908522
  void reference() const;
Packit 908522
  void unreference() const;
Packit 908522
  #endif //DOXYGEN_IGNORE_THIS
Packit 908522
Packit 908522
  /** Create a new surface that is as compatible as possible with an existing
Packit 908522
   * surface. The new surface will use the same backend as other unless that is
Packit 908522
   * not possible for some reason.
Packit 908522
   *
Packit 908522
   * @param other 	an existing surface used to select the backend of the new surface
Packit 908522
   * @param content 	the content for the new surface
Packit 908522
   * @param width 	width of the new surface, (in device-space units)
Packit 908522
   * @param height 	height of the new surface (in device-space units)
Packit 908522
   * @return 	a RefPtr to the newly allocated surface.
Packit 908522
   */
Packit 908522
  static RefPtr<Surface> create(const RefPtr<Surface> other, Content content, int width, int height);
Packit 908522
Packit 908522
  /** Create a new surface that is a rectangle within the target surface. All
Packit 908522
   * operations drawn to this surface are then clipped and translated onto the
Packit 908522
   * target surface. Nothing drawn via this sub-surface outside of its bounds is
Packit 908522
   * drawn onto the target surface, making this a useful method for passing
Packit 908522
   * constrained child surfaces to library routines that draw directly onto the
Packit 908522
   * parent surface, i.e. with no further backend allocations, double buffering
Packit 908522
   * or copies.
Packit 908522
   *
Packit 908522
   * @Note The semantics of subsurfaces have not been finalized yet unless the
Packit 908522
   * rectangle is in full device units, is contained within the extents of the
Packit 908522
   * target surface, and the target or subsurface's device transforms are not
Packit 908522
   * changed.
Packit 908522
   *
Packit 908522
   * @param target an existing surface for which the sub-surface will point to
Packit 908522
   * @param x the x-origin of the sub-surface from the top-left of the target surface (in device-space units)
Packit 908522
   * @param y the y-origin of the sub-surface from the top-left of the target surface (in device-space units)
Packit 908522
   * @param width width of the sub-surface (in device-space units)
Packit 908522
   * @param height height of the sub-surface (in device-space units)
Packit 908522
   *
Packit 908522
   * @since 1.10
Packit 908522
   */
Packit 908522
  static RefPtr<Surface> create(const RefPtr<Surface>& target, double x, double y, double width, double height);
Packit 908522
Packit 908522
protected:
Packit 908522
  /** The underlying C cairo surface type that is wrapped by this Surface
Packit 908522
   */
Packit 908522
  cobject* m_cobject;
Packit 908522
};
Packit 908522
Packit 908522
/** @example image-surface.cc
Packit 908522
 * An example of using Cairo::ImageSurface class to render to PNG
Packit 908522
 */
Packit 908522
Packit 908522
/** Image surfaces provide the ability to render to memory buffers either
Packit 908522
 * allocated by cairo or by the calling code. The supported image formats are
Packit 908522
 * those defined in Cairo::Format
Packit 908522
 *
Packit 908522
 * An ImageSurface is the most generic type of Surface and the only one that is
Packit 908522
 * available by default.  You can either create an ImageSurface whose data is
Packit 908522
 * managed by Cairo, or you can create an ImageSurface with a data buffer that
Packit 908522
 * you allocated yourself so that you can have full access to the data.
Packit 908522
 *
Packit 908522
 * When you create an ImageSurface with your own data buffer, you are free to
Packit 908522
 * examine the results at any point and do whatever you want with it.  Note that
Packit 908522
 * if you modify anything and later want to continue to draw to the surface
Packit 908522
 * with cairo, you must let cairo know via Cairo::Surface::mark_dirty()
Packit 908522
 *
Packit 908522
 * Note that like all surfaces, an ImageSurface is a reference-counted object that should be used via Cairo::RefPtr.
Packit 908522
 */
Packit 908522
class ImageSurface : public Surface
Packit 908522
{
Packit 908522
protected:
Packit 908522
  //TODO?: Surface(cairo_surface_t *target);
Packit 908522
Packit 908522
public:
Packit 908522
Packit 908522
  /** Create a C++ wrapper for the C instance. This C++ instance should then be
Packit 908522
   * given to a RefPtr.
Packit 908522
   * @param cobject The C instance.
Packit 908522
   * @param has_reference Whether we already have a reference. Otherwise, the
Packit 908522
   * constructor will take an extra reference.
Packit 908522
   */
Packit 908522
  explicit ImageSurface(cairo_surface_t* cobject, bool has_reference = false);
Packit 908522
Packit 908522
  virtual ~ImageSurface();
Packit 908522
Packit 908522
  /** Gets the width of the ImageSurface in pixels
Packit 908522
   */
Packit 908522
  int get_width() const;
Packit 908522
Packit 908522
  /** Gets the height of the ImageSurface in pixels
Packit 908522
   */
Packit 908522
  int get_height() const;
Packit 908522
Packit 908522
  /// @{
Packit 908522
  /**
Packit 908522
   * Get a pointer to the data of the image surface, for direct
Packit 908522
   * inspection or modification.
Packit 908522
   *
Packit 908522
   * Return value: a pointer to the image data of this surface or NULL
Packit 908522
   * if @surface is not an image surface.
Packit 908522
   *
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  unsigned char* get_data();
Packit 908522
  const unsigned char* get_data() const;
Packit 908522
  /// @}
Packit 908522
Packit 908522
  /**
Packit 908522
   * Gets the format of the surface
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  Format get_format() const;
Packit 908522
Packit 908522
  /**
Packit 908522
   * Returns the stride of the image surface in bytes (or 0 if surface is not
Packit 908522
   * an image surface). The stride is the distance in bytes from the beginning
Packit 908522
   * of one row of the image data to the beginning of the next row.
Packit 908522
   *
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  int get_stride() const;
Packit 908522
Packit 908522
  /**
Packit 908522
   * This function provides a stride value that will respect all alignment
Packit 908522
   * requirements of the accelerated image-rendering code within cairo. Typical
Packit 908522
   * usage will be of the form:
Packit 908522
   *
Packit 908522
   * @code
Packit 908522
   * int stride;
Packit 908522
   * unsigned char *data;
Packit 908522
   * Cairo::RefPtr<Cairo::ImageSurface> surface;
Packit 908522
   *
Packit 908522
   * stride = Cairo::ImageSurface::format_stride_for_width (format, width);
Packit 908522
   * data = malloc (stride * height);
Packit 908522
   * surface = Cairo::ImageSurface::create (data, format, width, height);
Packit 908522
   * @endcode
Packit 908522
   *
Packit 908522
   * @param format A Cairo::Format value
Packit 908522
   * @param width The desired width of an image surface to be created.
Packit 908522
   * @return the appropriate stride to use given the desired format and width, or
Packit 908522
   * -1 if either the format is invalid or the width too large.
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   **/
Packit 908522
  static int format_stride_for_width(Cairo::Format format, int width);
Packit 908522
Packit 908522
  /**
Packit 908522
   * Creates an image surface of the specified format and dimensions. Initially
Packit 908522
   * the surface contents are all 0. (Specifically, within each pixel, each
Packit 908522
   * color or alpha channel belonging to format will be 0. The contents of bits
Packit 908522
   * within a pixel, but not belonging to the given format are undefined).
Packit 908522
   *
Packit 908522
   * @param format 	format of pixels in the surface to create
Packit 908522
   * @param width 	width of the surface, in pixels
Packit 908522
   * @param height 	height of the surface, in pixels
Packit 908522
   * @return 	a RefPtr to the newly created surface.
Packit 908522
   */
Packit 908522
  static RefPtr<ImageSurface> create(Format format, int width, int height);
Packit 908522
Packit 908522
  /**
Packit 908522
   * Creates an image surface for the provided pixel data. The output buffer
Packit 908522
   * must be kept around until the surface is destroyed or finish() is called on
Packit 908522
   * the surface. The initial contents of buffer will be used as the initial
Packit 908522
   * image contents; you must explicitly clear the buffer, using, for example,
Packit 908522
   * Context::rectangle() and Context::fill() if you want it cleared.
Packit 908522
   *
Packit 908522
   * Note that the stride may be larger than @a width * @a bytes_per_pixel to
Packit 908522
   * provide proper alignment for each pixel and row. This alignment is required
Packit 908522
   * to allow high-performance rendering within cairo. The correct way to obtain
Packit 908522
   * a legal stride value is to call format_stride_for_width() with the desired
Packit 908522
   * format and maximum image width value, and the use the resulting stride
Packit 908522
   * value to allocate the data and to create the image surface. See
Packit 908522
   * format_stride_for_width() for example code.
Packit 908522
   *
Packit 908522
   * @param data a pointer to a buffer supplied by the application in which to write contents. This pointer must be suitably aligned for any kind of variable, (for example, a pointer returned by malloc).
Packit 908522
   * @param format the format of pixels in the buffer
Packit 908522
   * @param width the width of the image to be stored in the buffer
Packit 908522
   * @param height the height of the image to be stored in the buffer
Packit 908522
   * @param stride the number of bytes between the start of rows in the buffer as allocated. This value should always be computed by cairo_format_stride_for_width() before allocating the data buffer.
Packit 908522
   * @return a RefPtr to the newly created surface.
Packit 908522
   */
Packit 908522
  static RefPtr<ImageSurface> create(unsigned char* data, Format format, int width, int height, int stride);
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_PNG_FUNCTIONS
Packit 908522
Packit 908522
  /** Creates a new image surface and initializes the contents to the given PNG
Packit 908522
   * file.
Packit 908522
   *
Packit 908522
   * @note For this function to be available, cairo must have been compiled
Packit 908522
   * with PNG support.
Packit 908522
   *
Packit 908522
   * @param filename	name of PNG file to load
Packit 908522
   * @return	a RefPtr to the new cairo_surface_t initialized with the
Packit 908522
   * contents of the PNG image file.
Packit 908522
   */
Packit 908522
  static RefPtr<ImageSurface> create_from_png(std::string filename);
Packit 908522
Packit 908522
  /** Creates a new image surface from PNG data read incrementally via the
Packit 908522
   * read_func function.
Packit 908522
   *
Packit 908522
   * @note For this function to be available, cairo must have been compiled
Packit 908522
   * with PNG support.
Packit 908522
   *
Packit 908522
   * @param read_func function called to read the data of the file
Packit 908522
   * @return a RefPtr to the new cairo_surface_t initialized with the
Packit 908522
   * contents of the PNG image file.
Packit 908522
   */
Packit 908522
  static RefPtr<ImageSurface> create_from_png_stream(const SlotReadFunc& read_func);
Packit 908522
  /** @deprecated Use create_from_png_stream instead */
Packit 908522
  static RefPtr<ImageSurface> create_from_png(cairo_read_func_t read_func, void *closure);
Packit 908522
Packit 908522
#endif // CAIRO_HAS_PNG_FUNCTIONS
Packit 908522
Packit 908522
};
Packit 908522
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_PDF_SURFACE
Packit 908522
Packit 908522
/** @example pdf-surface.cc
Packit 908522
 * An example of using Cairo::PdfSurface class to render to PDF
Packit 908522
 */
Packit 908522
Packit 908522
typedef enum
Packit 908522
{
Packit 908522
  PDF_VERSION_1_4 = CAIRO_PDF_VERSION_1_4,
Packit 908522
  PDF_VERSION_1_5 = CAIRO_PDF_VERSION_1_5
Packit 908522
} PdfVersion;
Packit 908522
Packit 908522
/** A PdfSurface provides a way to render PDF documents from cairo.  This
Packit 908522
 * surface is not rendered to the screen but instead renders the drawing to a
Packit 908522
 * PDF file on disk.
Packit 908522
 *
Packit 908522
 * @note For this Surface to be available, cairo must have been compiled with
Packit 908522
 * PDF support
Packit 908522
 */
Packit 908522
class PdfSurface : public Surface
Packit 908522
{
Packit 908522
public:
Packit 908522
Packit 908522
  /** Create a C++ wrapper for the C instance. This C++ instance should then be
Packit 908522
   * given to a RefPtr.
Packit 908522
   *
Packit 908522
   * @param cobject The C instance.
Packit 908522
   * @param has_reference whether we already have a reference. Otherwise, the
Packit 908522
   * constructor will take an extra reference.
Packit 908522
   */
Packit 908522
  explicit PdfSurface(cairo_surface_t* cobject, bool has_reference = false);
Packit 908522
  virtual ~PdfSurface();
Packit 908522
Packit 908522
  /** Creates a PdfSurface with a specified dimensions that will be saved as
Packit 908522
   * the given filename
Packit 908522
   *
Packit 908522
   * @param filename    The name of the PDF file to save the surface to
Packit 908522
   * @param width_in_points   The width of the PDF document in points
Packit 908522
   * @param height_in_points   The height of the PDF document in points
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  static RefPtr<PdfSurface> create(std::string filename, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /** Creates a PdfSurface with a specified dimensions that will be written to
Packit 908522
   * the given write function instead of saved directly to disk
Packit 908522
   *
Packit 908522
   * @param write_func  The function to be called when the backend needs to
Packit 908522
   * write data to an output stream
Packit 908522
   * @param width_in_points   The width of the PDF document in points
Packit 908522
   * @param height_in_points   The height of the PDF document in points
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<PdfSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
Packit 908522
  /** @deprecated use PdfSurface::create_for_stream() instead */
Packit 908522
  static RefPtr<PdfSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
/**
Packit 908522
 * Changes the size of a PDF surface for the current (and subsequent) pages.
Packit 908522
 *
Packit 908522
 * This function should only be called before any drawing operations have been
Packit 908522
 * performed on the current page. The simplest way to do this is to call this
Packit 908522
 * function immediately after creating the surface or immediately after
Packit 908522
 * completing a page with either Context::show_page() or Context::copy_page().
Packit 908522
 *
Packit 908522
 * @param width_in_points new surface width, in points (1 point == 1/72.0 inch)
Packit 908522
 * @param height_in_points new surface height, in points (1 point == 1/72.0 inch)
Packit 908522
 **/
Packit 908522
  void set_size(double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /**
Packit 908522
   * Restricts the generated PDF file to version. See get_versions() for a list
Packit 908522
   * of available version values that can be used here.
Packit 908522
   *
Packit 908522
   * This function should only be called before any drawing operations have been
Packit 908522
   * performed on the given surface. The simplest way to do this is to call this
Packit 908522
   * function immediately after creating the surface.
Packit 908522
   *
Packit 908522
   * @since 1.10
Packit 908522
   */
Packit 908522
  void restrict_to_version(PdfVersion version);
Packit 908522
Packit 908522
  /** Retrieves the list of PDF versions supported by cairo. See
Packit 908522
   * restrict_to_version().
Packit 908522
   *
Packit 908522
   * @since 1.10
Packit 908522
   */
Packit 908522
  static const std::vector<PdfVersion> get_versions();
Packit 908522
Packit 908522
  /** Get the string representation of the given version id. This function will
Packit 908522
   * return an empty string if version isn't valid. See get_versions()
Packit 908522
   * for a way to get the list of valid version ids.
Packit 908522
   *
Packit 908522
   * @since 1.10
Packit 908522
   */
Packit 908522
  static std::string version_to_string(PdfVersion version);
Packit 908522
};
Packit 908522
Packit 908522
#endif  // CAIRO_HAS_PDF_SURFACE
Packit 908522
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_PS_SURFACE
Packit 908522
Packit 908522
/** @example ps-surface.cc
Packit 908522
 * An example of using Cairo::PsSurface class to render to PostScript
Packit 908522
 */
Packit 908522
Packit 908522
/**
Packit 908522
 * describes the language level of the PostScript Language Reference that a
Packit 908522
 * generated PostScript file will conform to.
Packit 908522
 */
Packit 908522
typedef enum {
Packit 908522
    PS_LEVEL_2 = CAIRO_PS_LEVEL_2,
Packit 908522
    PS_LEVEL_3 = CAIRO_PS_LEVEL_3
Packit 908522
} PsLevel;
Packit 908522
Packit 908522
/** A PsSurface provides a way to render PostScript documents from cairo.  This
Packit 908522
 * surface is not rendered to the screen but instead renders the drawing to a
Packit 908522
 * PostScript file on disk.
Packit 908522
 *
Packit 908522
 * @note For this Surface to be available, cairo must have been compiled with
Packit 908522
 * PostScript support
Packit 908522
 */
Packit 908522
class PsSurface : public Surface
Packit 908522
{
Packit 908522
public:
Packit 908522
Packit 908522
  /** Create a C++ wrapper for the C instance. This C++ instance should then be
Packit 908522
   * given to a RefPtr.
Packit 908522
   *
Packit 908522
   * @param cobject The C instance.
Packit 908522
   * @param has_reference whether we already have a reference. Otherwise, the
Packit 908522
   * constructor will take an extra reference.
Packit 908522
   */
Packit 908522
  explicit PsSurface(cairo_surface_t* cobject, bool has_reference = false);
Packit 908522
  virtual ~PsSurface();
Packit 908522
Packit 908522
  /** Creates a PsSurface with a specified dimensions that will be saved as the
Packit 908522
   * given filename
Packit 908522
   *
Packit 908522
   * @param filename    The name of the PostScript file to save the surface to
Packit 908522
   * @param width_in_points   The width of the PostScript document in points
Packit 908522
   * @param height_in_points   The height of the PostScript document in points
Packit 908522
   */
Packit 908522
  static RefPtr<PsSurface> create(std::string filename, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /** Creates a PsSurface with a specified dimensions that will be written to
Packit 908522
   * the given write function instead of saved directly to disk
Packit 908522
   *
Packit 908522
   * @param write_func  The function to be called when the backend needs to
Packit 908522
   * write data to an output stream
Packit 908522
   * @param width_in_points   The width of the PostScript document in points
Packit 908522
   * @param height_in_points   The height of the PostScript document in points
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<PsSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
Packit 908522
  /** @deprecated use PsSurface::create_for_stream() instead */
Packit 908522
  static RefPtr<PsSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /**
Packit 908522
   * Changes the size of a PostScript surface for the current (and
Packit 908522
   * subsequent) pages.
Packit 908522
   *
Packit 908522
   * This function should only be called before any drawing operations have been
Packit 908522
   * performed on the current page. The simplest way to do this is to call this
Packit 908522
   * function immediately after creating the surface or immediately after
Packit 908522
   * completing a page with either Context::show_page() or Context::copy_page().
Packit 908522
   *
Packit 908522
   * @param width_in_points new surface width, in points (1 point == 1/72.0 inch)
Packit 908522
   * @param height_in_points new surface height, in points (1 point == 1/72.0 inch)
Packit 908522
   */
Packit 908522
  void set_size(double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /** Emit a comment into the PostScript output for the given surface.  See the
Packit 908522
   * cairo reference documentation for more information.
Packit 908522
   *
Packit 908522
   * @param comment a comment string to be emitted into the PostScript output
Packit 908522
   */
Packit 908522
  void dsc_comment(std::string comment);
Packit 908522
Packit 908522
  /**
Packit 908522
   * This function indicates that subsequent calls to dsc_comment() should direct
Packit 908522
   * comments to the Setup section of the PostScript output.
Packit 908522
   *
Packit 908522
   * This function should be called at most once per surface, and must be called
Packit 908522
   * before any call to dsc_begin_page_setup() and before any drawing is performed
Packit 908522
   * to the surface.
Packit 908522
   */
Packit 908522
  void dsc_begin_setup();
Packit 908522
Packit 908522
  /** This function indicates that subsequent calls to dsc_comment() should
Packit 908522
   * direct comments to the PageSetup section of the PostScript output.
Packit 908522
   *
Packit 908522
   * This function call is only needed for the first page of a surface. It
Packit 908522
   * should be called after any call to dsc_begin_setup() and before any drawing
Packit 908522
   * is performed to the surface.
Packit 908522
   */
Packit 908522
  void dsc_begin_page_setup();
Packit 908522
Packit 908522
  /**
Packit 908522
   * If eps is true, the PostScript surface will output Encapsulated
Packit 908522
   * PostScript.
Packit 908522
   *
Packit 908522
   * This function should only be called before any drawing operations
Packit 908522
   * have been performed on the current page. The simplest way to do
Packit 908522
   * this is to call this function immediately after creating the
Packit 908522
   * surface. An Encapsulated Postscript file should never contain more
Packit 908522
   * than one page.
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   **/
Packit 908522
  void set_eps(bool eps);
Packit 908522
Packit 908522
  /** Check whether the PostScript surface will output Encapsulated PostScript.
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  bool get_eps() const;
Packit 908522
Packit 908522
  /**
Packit 908522
   * Restricts the generated PostSript file to @level. See get_levels() for a
Packit 908522
   * list of available level values that can be used here.
Packit 908522
   *
Packit 908522
   * This function should only be called before any drawing operations have been
Packit 908522
   * performed on the given surface. The simplest way to do this is to call this
Packit 908522
   * function immediately after creating the surface.
Packit 908522
   *
Packit 908522
   * @param level PostScript level
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   **/
Packit 908522
  void restrict_to_level(PsLevel level);
Packit 908522
Packit 908522
  /**
Packit 908522
   * Used to retrieve the list of supported levels. See
Packit 908522
   * restrict_to_level().
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   **/
Packit 908522
  static const std::vector<PsLevel> get_levels();
Packit 908522
Packit 908522
  /**
Packit 908522
   * Get the string representation of the given level id. This function will
Packit 908522
   * return an empty string if level id isn't valid. See get_levels() for a way
Packit 908522
   * to get the list of valid level ids.
Packit 908522
   *
Packit 908522
   * @return the string associated to given level.
Packit 908522
   *
Packit 908522
   * @param level a level id
Packit 908522
   *
Packit 908522
   * @since 1.6
Packit 908522
   **/
Packit 908522
  static std::string level_to_string(PsLevel level);
Packit 908522
};
Packit 908522
Packit 908522
#endif // CAIRO_HAS_PS_SURFACE
Packit 908522
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_SVG_SURFACE
Packit 908522
Packit 908522
/** @example svg-surface.cc
Packit 908522
 * An example of using Cairo::SvgSurface class to render to SVG
Packit 908522
 */
Packit 908522
Packit 908522
typedef enum
Packit 908522
{
Packit 908522
  SVG_VERSION_1_1 = CAIRO_SVG_VERSION_1_1,
Packit 908522
  SVG_VERSION_1_2 = CAIRO_SVG_VERSION_1_2
Packit 908522
} SvgVersion;
Packit 908522
Packit 908522
/** A SvgSurface provides a way to render Scalable Vector Graphics (SVG) images
Packit 908522
 * from cairo.  This surface is not rendered to the screen but instead renders
Packit 908522
 * the drawing to an SVG file on disk.
Packit 908522
 *
Packit 908522
 * @note For this Surface to be available, cairo must have been compiled with
Packit 908522
 * SVG support
Packit 908522
 */
Packit 908522
class SvgSurface : public Surface
Packit 908522
{
Packit 908522
public:
Packit 908522
Packit 908522
  /** Create a C++ wrapper for the C instance. This C++ instance should then be
Packit 908522
   * given to a RefPtr.
Packit 908522
   *
Packit 908522
   * @param cobject The C instance.
Packit 908522
   * @param has_reference whether we already have a reference. Otherwise, the
Packit 908522
   * constructor will take an extra reference.
Packit 908522
   */
Packit 908522
  explicit SvgSurface(cairo_surface_t* cobject, bool has_reference = false);
Packit 908522
  virtual ~SvgSurface();
Packit 908522
Packit 908522
Packit 908522
  /** Creates a SvgSurface with a specified dimensions that will be saved as the
Packit 908522
   * given filename
Packit 908522
   *
Packit 908522
   * @param filename    The name of the SVG file to save the surface to
Packit 908522
   * @param width_in_points   The width of the SVG document in points
Packit 908522
   * @param height_in_points   The height of the SVG document in points
Packit 908522
   */
Packit 908522
  static RefPtr<SvgSurface> create(std::string filename, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /** Creates a SvgSurface with a specified dimensions that will be written to
Packit 908522
   * the given write function instead of saved directly to disk
Packit 908522
   *
Packit 908522
   * @param write_func  The function to be called when the backend needs to
Packit 908522
   * write data to an output stream
Packit 908522
   * @param width_in_points   The width of the SVG document in points
Packit 908522
   * @param height_in_points   The height of the SVG document in points
Packit 908522
   *
Packit 908522
   * @since 1.8
Packit 908522
   */
Packit 908522
  static RefPtr<SvgSurface> create_for_stream(const SlotWriteFunc& write_func, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /** @deprecated Use SvgSurface::create_for_stream() instead */
Packit 908522
  static RefPtr<SvgSurface> create(cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
Packit 908522
Packit 908522
  /**
Packit 908522
   * Restricts the generated SVG file to the given version. See get_versions()
Packit 908522
   * for a list of available version values that can be used here.
Packit 908522
   *
Packit 908522
   * This function should only be called before any drawing operations have been
Packit 908522
   * performed on the given surface. The simplest way to do this is to call this
Packit 908522
   * function immediately after creating the surface.
Packit 908522
   *
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  void restrict_to_version(SvgVersion version);
Packit 908522
Packit 908522
  /** Retrieves the list of SVG versions supported by cairo. See
Packit 908522
   * restrict_to_version().
Packit 908522
   *
Packit 908522
   * @since 1.2
Packit 908522
   */
Packit 908522
  static const std::vector<SvgVersion> get_versions();
Packit 908522
Packit 908522
  /** Get the string representation of the given version id. The returned string
Packit 908522
   * will be empty if version isn't valid. See get_versions() for a way to get
Packit 908522
   * the list of valid version ids.
Packit 908522
   *
Packit 908522
   * since: 1.2
Packit 908522
   */
Packit 908522
  static std::string version_to_string(SvgVersion version);
Packit 908522
};
Packit 908522
Packit 908522
#endif // CAIRO_HAS_SVG_SURFACE
Packit 908522
Packit 908522
Packit 908522
/*******************************************************************************
Packit 908522
 * THE FOLLOWING SURFACE TYPES ARE EXPERIMENTAL AND NOT FULLY SUPPORTED
Packit 908522
 ******************************************************************************/
Packit 908522
Packit 908522
#ifdef CAIRO_HAS_GLITZ_SURFACE
Packit 908522
Packit 908522
/** A GlitzSurface provides a way to render to the X Window System using Glitz.
Packit 908522
 * This provides a way to use OpenGL-accelerated graphics from cairo.  If you
Packit 908522
 * want to use hardware-accelerated graphics within the X Window system, you
Packit 908522
 * should use this Surface type.
Packit 908522
 *
Packit 908522
 * @note For this Surface to be available, cairo must have been compiled with
Packit 908522
 * Glitz support
Packit 908522
 *
Packit 908522
 * @warning This is an experimental surface.  It is not yet marked as a fully
Packit 908522
 * supported surface by the cairo library
Packit 908522
 */
Packit 908522
class GlitzSurface : public Surface
Packit 908522
{
Packit 908522
Packit 908522
public:
Packit 908522
Packit 908522
  /** Create a C++ wrapper for the C instance. This C++ instance should then be
Packit 908522
   * given to a RefPtr.
Packit 908522
   *
Packit 908522
   * @param cobject The C instance.
Packit 908522
   * @param has_reference whether we already have a reference. Otherwise, the
Packit 908522
   * constructor will take an extra reference.
Packit 908522
   */
Packit 908522
  explicit GlitzSurface(cairo_surface_t* cobject, bool has_reference = false);
Packit 908522
Packit 908522
  virtual ~GlitzSurface();
Packit 908522
Packit 908522
  /** Creates a new GlitzSurface
Packit 908522
   *
Packit 908522
   * @param surface  a glitz surface type
Packit 908522
   */
Packit 908522
  static RefPtr<GlitzSurface> create(glitz_surface_t *surface);
Packit 908522
Packit 908522
};
Packit 908522
Packit 908522
#endif // CAIRO_HAS_GLITZ_SURFACE
Packit 908522
Packit 908522
} // namespace Cairo
Packit 908522
Packit 908522
#endif //__CAIROMM_SURFACE_H
Packit 908522
Packit 908522
// vim: ts=2 sw=2 et