/src/wrappers/cairo/library/cairo_surface.e

http://github.com/tybor/Liberty · Specman e · 292 lines · 109 code · 47 blank · 136 comment · 3 complexity · 8bfb138e0fd513827bd8b664d5bca8cb MD5 · raw file

  1. note
  2. description: "cairo_surface_t: base class for Cairo surfaces."
  3. copyright: "[
  4. Copyright (C) 2007-2017: Paolo Redaelli,
  5. Soluciones Informaticas Libres S.A. (Except),
  6. Cairo team
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public License
  9. as published by the Free Software Foundation; either version 2.1 of
  10. the License, or (at your option) any later version.
  11. This library is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. 02110-1301 USA
  19. ]"
  20. date: "$Date:$"
  21. revision: "$Revision:$"
  22. wrapped_version: "1.2.4"
  23. class CAIRO_SURFACE
  24. -- A cairo_surface_t represents an image, either as the destination
  25. -- of a drawing operation or as source when drawing onto another
  26. -- surface. There are different subtypes of CAIRO_SURFACE for
  27. -- different drawing backends; for example, CAIRO_IMAGE_SURFACE is
  28. -- a bitmap image in memory.
  29. inherit
  30. C_STRUCT
  31. REFERENCE_COUNTED
  32. insert
  33. CAIRO_SURFACE_EXTERNALS
  34. CAIRO_SURFACE_TYPE
  35. CAIRO_STATUS
  36. CAIRO_CONTENT
  37. create {ANY} make_similar, from_external_pointer
  38. feature {ANY} -- Creation
  39. make_similar (another: CAIRO_SURFACE; a_content: INTEGER; a_width, an_height: INTEGER)
  40. -- Create a new surface that is as compatible as possible
  41. -- with an existing surface. For example the new surface will
  42. -- have the same fallback resolution and font options as
  43. -- other. Generally, the new surface will also use the same
  44. -- backend as other, unless that is not possible for some
  45. -- reason. The type of the returned surface may be examined
  46. -- with `type'.
  47. -- Initially the surface contents are all 0 (transparent if
  48. -- contents have transparency, black otherwise.)
  49. -- `another': an existing surface used to select the backend
  50. -- of the new surface
  51. -- content : the content for the new surface
  52. -- a_width: width of the new surface, (in device-space
  53. -- units)
  54. -- an_height : height of the new surface (in device-space units)
  55. do
  56. from_external_pointer(cairo_surface_create_similar
  57. (another.handle, a_content, a_width, an_height))
  58. -- cairo_surface_create_similar returns a pointer to the
  59. -- newly allocated surface. The caller owns the surface and
  60. -- should call cairo_surface_destroy when done with it. This
  61. -- function always returns a valid pointer, but it will
  62. -- return a pointer to a "nil" surface if other is already in
  63. -- an error state or any other error occurs.
  64. end
  65. feature {ANY} -- Operations
  66. finish
  67. -- Finishes the surface and drops all references to external
  68. -- resources. For example, for the Xlib backend it means that
  69. -- cairo will no longer access the drawable, which can be
  70. -- freed. After calling `finish' the only valid operations on
  71. -- a surface are getting and setting user data and
  72. -- referencing and destroying it. Further drawing to the
  73. -- surface will not affect the surface but will instead
  74. -- trigger a `cairo_status_surface_finished' error.
  75. -- When the last call to `destroy' decreases the reference
  76. -- count to zero, cairo will call `finish' if it hasn't been
  77. -- called already, before freeing the resources associated
  78. -- with the surface.
  79. do
  80. cairo_surface_finish(handle)
  81. end
  82. flush
  83. -- Do any pending drawing for the surface and also restore
  84. -- any temporary modification's cairo has made to the
  85. -- surface's state. This function must be called before
  86. -- switching from drawing on the surface with cairo to
  87. -- drawing on it directly with native APIs. If the surface
  88. -- doesn't support direct access, then this function does
  89. -- nothing.
  90. do
  91. cairo_surface_flush(handle)
  92. end
  93. font_options: CAIRO_FONT_OPTIONS
  94. -- the default font rendering options for the surface. This
  95. -- allows display surfaces to report the correct subpixel
  96. -- order for rendering on them, print surfaces to disable
  97. -- hinting of metrics and so forth. The result can then be
  98. -- used to create a CAIRO_SCALED_FONT.
  99. do
  100. create Result.make
  101. cairo_surface_get_font_options (handle, Result.handle)
  102. end
  103. content: INTEGER
  104. -- The content type of surface which indicates whether the
  105. -- surface contains color and/or alpha information. See
  106. -- CAIRO_CONTENT.
  107. do
  108. Result := cairo_surface_get_content (handle)
  109. ensure
  110. valid: is_valid_content (Result)
  111. end
  112. -- TODO: cairo_surface_set_user_data ()
  113. -- cairo_status_t cairo_surface_set_user_data (cairo_surface_t *surface,
  114. -- const cairo_user_data_key_t *key,
  115. -- void *user_data,
  116. -- cairo_destroy_func_t destroy);
  117. -- Attach user data to surface. To remove user data from a surface, call this
  118. -- function with the key that was used to set it and NULL for data.
  119. -- surface : a cairo_surface_t
  120. -- key : the address of a cairo_user_data_key_t to attach the user data
  121. -- to
  122. -- user_data : the user data to attach to the surface
  123. -- destroy : a cairo_destroy_func_t which will be called when the surface
  124. -- is destroyed or when new user data is attached using the same
  125. -- key.
  126. -- Returns : CAIRO_STATUS_SUCCESS or CAIRO_STATUS_NO_MEMORY if a slot could
  127. -- not be allocated for the user data.
  128. -- --------------------------------------------------------------------------
  129. -- TODO: cairo_surface_get_user_data ()
  130. -- void* cairo_surface_get_user_data (cairo_surface_t *surface,
  131. -- const cairo_user_data_key_t *key);
  132. -- Return user data previously attached to surface using the specified key.
  133. -- If no user data has been attached with the given key this function returns
  134. -- NULL.
  135. -- surface : a cairo_surface_t
  136. -- key : the address of the cairo_user_data_key_t the user data was
  137. -- attached to
  138. -- Returns : the user data previously attached or NULL.
  139. mark_dirty
  140. -- Tells cairo that drawing has been done to surface using
  141. -- means other than cairo, and that cairo should reread any
  142. -- cached areas. Note that you must call `flush' before doing
  143. -- such drawing.
  144. do
  145. cairo_surface_mark_dirty (handle)
  146. end
  147. mark_dirty_rectangle (an_x, an_y, a_width, an_height: INTEGER)
  148. -- Like `mark_dirty', but drawing has been done only to the
  149. -- specified rectangle, so that cairo can retain cached
  150. -- contents for other parts of the surface.
  151. -- Any cached clip set on the surface will be reset by this
  152. -- function, to make sure that future cairo calls have the
  153. -- clip set that they expect.
  154. -- `an_x': X coordinate of dirty rectangle
  155. -- `an_y': Y coordinate of dirty rectangle
  156. -- `a_width': width of dirty rectangle
  157. -- `an_height': height of dirty rectangle
  158. do
  159. cairo_surface_mark_dirty_rectangle (handle, an_x, an_y, a_width, an_height)
  160. end
  161. set_device_offset (an_offset: CAIRO_POINT)
  162. -- Sets an offset that is added to the device coordinates
  163. -- determined by the CTM when drawing to surface. One use
  164. -- case for this function is when we want to create a
  165. -- cairo_surface_t that redirects drawing for a portion of an
  166. -- onscreen surface to an offscreen surface in a way that is
  167. -- completely invisible to the user of the cairo API. Setting
  168. -- a transformation via `translate' isn't sufficient to do
  169. -- this, since functions like `device_to_user' will expose
  170. -- the hidden offset.
  171. -- Note that the offset affects drawing to the surface as
  172. -- well as using the surface in a source pattern.
  173. require
  174. offset_not_void: an_offset /= Void
  175. do
  176. cairo_surface_set_device_offset (handle, an_offset.x, an_offset.y)
  177. end
  178. device_offset: CAIRO_POINT
  179. -- the device offset as set by `set_device_offset'.
  180. local
  181. an_x, an_y: REAL
  182. do
  183. cairo_surface_get_device_offset (handle, $an_x, $an_y)
  184. create Result.make(an_x,an_y)
  185. end
  186. set_fallback_resolution (x_pixels_per_inch, y_pixels_per_inch: REAL)
  187. -- Set the horizontal and vertical resolution for image
  188. -- fallbacks.
  189. -- When certain operations aren't supported natively by a
  190. -- backend, cairo will fallback by rendering operations to an
  191. -- image and then overlaying that image onto the output. For
  192. -- backends that are natively vector-oriented, this function
  193. -- can be used to set the resolution used for these image
  194. -- fallbacks, (larger values will result in more detailed
  195. -- images, but also larger file sizes).
  196. -- Some examples of natively vector-oriented backends are the
  197. -- ps, pdf, and svg backends.
  198. -- For backends that are natively raster-oriented, image
  199. -- fallbacks are still possible, but they are always
  200. -- performed at the native device resolution. So this
  201. -- function has no effect on those backends.
  202. -- NOTE: The fallback resolution only takes effect at the
  203. -- time of completing a page (with `show_page' or
  204. -- `copy_page') so there is currently no way to have more
  205. -- than one fallback resolution in effect on a single page.
  206. -- x_pixels_per_inch : horizontal setting for pixels per inch
  207. -- y_pixels_per_inch : vertical setting for pixels per inch
  208. do
  209. cairo_surface_set_fallback_resolution (handle, x_pixels_per_inch, y_pixels_per_inch)
  210. end
  211. status: INTEGER
  212. -- Checks whether an error has previously occurred for this surface.
  213. do
  214. Result := cairo_surface_status (handle)
  215. ensure
  216. valid_result: is_valid_cairo_status (Result)
  217. end
  218. feature {ANY} -- Memory handling
  219. ref
  220. -- Increases the reference count on surface by one. This
  221. -- prevents surface from being destroyed until a matching
  222. -- call to `destroy' is made.
  223. local
  224. p: POINTER
  225. do
  226. p := cairo_surface_reference (handle)
  227. check p=handle end
  228. end
  229. unref
  230. -- Decreases the reference count on surface by one. If the
  231. -- result is zero, then surface and all associated resources
  232. -- are freed. See `reference'.
  233. do
  234. cairo_surface_destroy(handle)
  235. end
  236. feature {WRAPPER, WRAPPER_HANDLER} -- Low-level features
  237. type: INTEGER
  238. -- the type of the backend used to create a surface. See
  239. -- CAIRO_SURFACE_TYPE for available types.
  240. do
  241. Result := cairo_surface_get_type (handle)
  242. ensure
  243. is_valid_surface_type (Result)
  244. end
  245. end -- class CAIRO_SURFACE