/src/wrappers/cairo/library/cairo_path.e

http://github.com/tybor/Liberty · Specman e · 497 lines · 50 code · 31 blank · 416 comment · 2 complexity · 8121bbda6b180275d034fc6122089264 MD5 · raw file

  1. note
  2. description: "Paths: Creating paths and manipulating path data."
  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_PATH
  24. -- Notes for the implementator of cairo_path_t wrapper
  25. -- The cairo_path_t type is one area in which most language
  26. -- bindings will differ significantly from the C API. The C API for
  27. -- cairo_path_t is designed for efficiency and to avoid auxiliary
  28. -- objects that would be have to be manually memory managed by the
  29. -- application. However, a language binding should not present
  30. -- cairo_path_t as an array, but rather as an opaque that can be
  31. -- iterated over. Different languages have quite different
  32. -- conventions for how iterators work, so it is impossible to give
  33. -- an exact specification for how this API should work, but the
  34. -- type names and methods should be similar to the language's
  35. -- mapping of the following:
  36. -- typedef struct cairo_path_iterator cairo_path_iterator_t;
  37. -- typedef struct cairo_path_element cairo_path_element_t;
  38. -- cairo_path_iterator_t *cairo_path_get_iterator (cairo_path_t *path);
  39. -- cairo_bool_t cairo_path_iterator_has_next (cairo_path_iterator_t *iterator);
  40. -- cairo_path_element_t *cairo_path_iterator_next (cairo_path_iterator_t *iterator);
  41. -- cairo_path_element_type_t cairo_path_element_get_type (cairo_path_element_t *element);
  42. -- void cairo_path_element_get_point (cairo_path_element_t *element, int index, double *x, double *y);
  43. -- The above is written using the Java conventions for
  44. -- iterators. To illustrate how the API for PathIterator might
  45. -- depend on the native iteration conventions of the API, examine
  46. -- three versions of the loop, first written in a hypothetical Java
  47. -- binding:
  48. -- PathIterator iter = cr.copyPath().iterator();
  49. -- while (cr.hasNext()) {
  50. -- PathElement element = iter.next();
  51. -- if (element.getType() == PathElementType.MOVE_TO) {
  52. -- Point p = element.getPoint(0);
  53. -- doMoveTo (p.x, p.y);
  54. -- }
  55. -- }
  56. -- And then in a hypothetical C++ binding:
  57. -- Path path = cr.copyPath();
  58. -- for (PathIterator iter = path.begin(); iter != path.end(); iter++) {
  59. -- PathElement element = *iter;
  60. -- if (element.getType() == PathElementType.MOVE_TO) {
  61. -- Point p = element.getPoint(0);
  62. -- doMoveTo (p.x, p.y);
  63. -- }
  64. -- }
  65. -- And then finally in a Python binding:
  66. -- for element in cr.copy_path():
  67. -- if element.getType == cairo.PATH_ELEMENT_MOVE_TO:
  68. -- (x, y) = element.getPoint(0)
  69. -- doMoveTo (x, y);
  70. -- While many of the API elements stay the same in the three
  71. -- examples, the exact iteration mechanism is quite different, to
  72. -- match how users of the language would expect to iterate over a
  73. -- container.
  74. -- You should not present an API for mutating or for creating new
  75. -- cairo_path_t objects. In the future, these guidelines may be
  76. -- extended to present an API for creating a cairo_path_t from
  77. -- scratch for use with cairo_append_path() but the current
  78. -- expectation is that cairo_append_path() will mostly be used with
  79. -- paths from cairo_copy_path().
  80. inherit
  81. C_STRUCT
  82. insert
  83. CAIRO_PATH_EXTERNALS
  84. CAIRO_PATH_STRUCT
  85. CAIRO_STATUS
  86. create {ANY} from_external_pointer
  87. feature {} -- Creation
  88. dispose
  89. -- Immediately releases all memory associated with
  90. -- path.
  91. -- NOTE: cairo_path_destroy function should only be called
  92. -- with a pointer to a cairo_path_t returned by a cairo
  93. -- function. Any path that is created manually (ie. outside
  94. -- of cairo) should be destroyed manually as well.
  95. do
  96. cairo_path_destroy(handle)
  97. handle := default_pointer
  98. end
  99. -- TODO: features to manually build a path, instead of getting it
  100. -- from a context.
  101. append (another: CAIRO_PATH)
  102. -- Append `another' path onto the current path. The path may
  103. -- be either the return value from one of `copy_path' or
  104. -- `copy_path_flat' or it may be constructed manually. See
  105. -- cairo_path_t for details on how the path data structure
  106. -- should be initialized, and note that another.status must be
  107. -- initialized to `cairo_status_success'.
  108. require
  109. another_not_void: another /= Void
  110. do
  111. cairo_append_path(handle, another.handle)
  112. end
  113. -- get_current_point ()
  114. --
  115. -- void cairo_get_current_point (cairo_t *cr,
  116. -- double *x,
  117. -- double *y);
  118. --
  119. -- Gets the current point of the current path, which is conceptually the
  120. -- final point reached by the path so far.
  121. --
  122. -- The current point is returned in the user-space coordinate system. If
  123. -- there is no defined current point then x and y will both be set to 0.0.
  124. --
  125. -- Most path construction functions alter the current point. See the
  126. -- following for details on how they affect the current point:
  127. --
  128. -- cairo_new_path(), cairo_move_to(), cairo_line_to(), cairo_curve_to(),
  129. -- cairo_arc(), cairo_rel_move_to(), cairo_rel_line_to(),
  130. -- cairo_rel_curve_to(), cairo_arc(), cairo_text_path(),
  131. -- cairo_stroke_to_path()
  132. --
  133. -- cr : a cairo context
  134. -- x : return value for X coordinate of the current point
  135. -- y : return value for Y coordinate of the current point
  136. --
  137. -- --------------------------------------------------------------------------
  138. --
  139. -- cairo_new_path ()
  140. --
  141. -- void cairo_new_path (cairo_t *cr);
  142. --
  143. -- Clears the current path. After this call there will be no path and no
  144. -- current point.
  145. --
  146. -- cr : a cairo context
  147. --
  148. -- --------------------------------------------------------------------------
  149. --
  150. -- cairo_new_sub_path ()
  151. --
  152. -- void cairo_new_sub_path (cairo_t *cr);
  153. --
  154. -- Begin a new sub-path. Note that the existing path is not affected. After
  155. -- this call there will be no current point.
  156. --
  157. -- In many cases, this call is not needed since new sub-paths are frequently
  158. -- started with cairo_move_to().
  159. --
  160. -- A call to cairo_new_sub_path() is particularly useful when beginning a new
  161. -- sub-path with one of the cairo_arc() calls. This makes things easier as it
  162. -- is no longer necessary to manually compute the arc's initial coordinates
  163. -- for a call to cairo_move_to().
  164. --
  165. -- cr : a cairo context
  166. --
  167. -- Since 1.2
  168. --
  169. -- --------------------------------------------------------------------------
  170. --
  171. -- cairo_close_path ()
  172. --
  173. -- void cairo_close_path (cairo_t *cr);
  174. --
  175. -- Adds a line segment to the path from the current point to the beginning of
  176. -- the current sub-path, (the most recent point passed to cairo_move_to()),
  177. -- and closes this sub-path. After this call the current point will be at the
  178. -- joined endpoint of the sub-path.
  179. --
  180. -- The behavior of cairo_close_path() is distinct from simply calling
  181. -- cairo_line_to() with the equivalent coordinate in the case of stroking.
  182. -- When a closed sub-path is stroked, there are no caps on the ends of the
  183. -- sub-path. Instead, there is a line join connecting the final and initial
  184. -- segments of the sub-path.
  185. --
  186. -- If there is no current point before the call to cairo_close_path, this
  187. -- function will have no effect.
  188. --
  189. -- Note: As of cairo version 1.2.4 any call to cairo_close_path will place an
  190. -- explicit MOVE_TO element into the path immediately after the CLOSE_PATH
  191. -- element, (which can be seen in cairo_copy_path() for example). This can
  192. -- simplify path processing in some cases as it may not be necessary to save
  193. -- the "last move_to point" during processing as the MOVE_TO immediately
  194. -- after the CLOSE_PATH will provide that point.
  195. --
  196. -- cr : a cairo context
  197. --
  198. -- --------------------------------------------------------------------------
  199. --
  200. -- cairo_arc ()
  201. --
  202. -- void cairo_arc (cairo_t *cr,
  203. -- double xc,
  204. -- double yc,
  205. -- double radius,
  206. -- double angle1,
  207. -- double angle2);
  208. --
  209. -- Adds a circular arc of the given radius to the current path. The arc is
  210. -- centered at (xc, yc), begins at angle1 and proceeds in the direction of
  211. -- increasing angles to end at angle2. If angle2 is less than angle1 it will
  212. -- be progressively increased by 2*M_PI until it is greater than angle1.
  213. --
  214. -- If there is a current point, an initial line segment will be added to the
  215. -- path to connect the current point to the beginning of the arc.
  216. --
  217. -- Angles are measured in radians. An angle of 0.0 is in the direction of the
  218. -- positive X axis (in user space). An angle of M_PI/2.0 radians (90 degrees)
  219. -- is in the direction of the positive Y axis (in user space). Angles
  220. -- increase in the direction from the positive X axis toward the positive Y
  221. -- axis. So with the default transformation matrix, angles increase in a
  222. -- clockwise direction.
  223. --
  224. -- (To convert from degrees to radians, use degrees * (M_PI / 180.).)
  225. --
  226. -- This function gives the arc in the direction of increasing angles; see
  227. -- cairo_arc_negative() to get the arc in the direction of decreasing angles.
  228. --
  229. -- The arc is circular in user space. To achieve an elliptical arc, you can
  230. -- scale the current transformation matrix by different amounts in the X and
  231. -- Y directions. For example, to draw an ellipse in the box given by x, y,
  232. -- width, height:
  233. --
  234. -- cairo_save (cr);
  235. -- cairo_translate (cr, x + width / 2., y + height / 2.);
  236. -- cairo_scale (cr, 1. / (height / 2.), 1. / (width / 2.));
  237. -- cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
  238. -- cairo_restore (cr);
  239. --
  240. -- cr : a cairo context
  241. -- xc : X position of the center of the arc
  242. -- yc : Y position of the center of the arc
  243. -- radius : the radius of the arc
  244. -- angle1 : the start angle, in radians
  245. -- angle2 : the end angle, in radians
  246. --
  247. -- --------------------------------------------------------------------------
  248. --
  249. -- cairo_arc_negative ()
  250. --
  251. -- void cairo_arc_negative (cairo_t *cr,
  252. -- double xc,
  253. -- double yc,
  254. -- double radius,
  255. -- double angle1,
  256. -- double angle2);
  257. --
  258. -- Adds a circular arc of the given radius to the current path. The arc is
  259. -- centered at (xc, yc), begins at angle1 and proceeds in the direction of
  260. -- decreasing angles to end at angle2. If angle2 is greater than angle1 it
  261. -- will be progressively decreased by 2*M_PI until it is greater than angle1.
  262. --
  263. -- See cairo_arc() for more details. This function differs only in the
  264. -- direction of the arc between the two angles.
  265. --
  266. -- cr : a cairo context
  267. -- xc : X position of the center of the arc
  268. -- yc : Y position of the center of the arc
  269. -- radius : the radius of the arc
  270. -- angle1 : the start angle, in radians
  271. -- angle2 : the end angle, in radians
  272. --
  273. -- --------------------------------------------------------------------------
  274. --
  275. -- cairo_curve_to ()
  276. --
  277. -- void cairo_curve_to (cairo_t *cr,
  278. -- double x1,
  279. -- double y1,
  280. -- double x2,
  281. -- double y2,
  282. -- double x3,
  283. -- double y3);
  284. --
  285. -- Adds a cubic Bezier spline to the path from the current point to position
  286. -- (x3, y3) in user-space coordinates, using (x1, y1) and (x2, y2) as the
  287. -- control points. After this call the current point will be (x3, y3).
  288. --
  289. -- If there is no current point before the call to cairo_curve_to() this
  290. -- function will behave as if preceded by a call to cairo_move_to (cr, x1,
  291. -- y1).
  292. --
  293. -- cr : a cairo context
  294. -- x1 : the X coordinate of the first control point
  295. -- y1 : the Y coordinate of the first control point
  296. -- x2 : the X coordinate of the second control point
  297. -- y2 : the Y coordinate of the second control point
  298. -- x3 : the X coordinate of the end of the curve
  299. -- y3 : the Y coordinate of the end of the curve
  300. --
  301. -- --------------------------------------------------------------------------
  302. --
  303. -- cairo_line_to ()
  304. --
  305. -- void cairo_line_to (cairo_t *cr,
  306. -- double x,
  307. -- double y);
  308. --
  309. -- Adds a line to the path from the current point to position (x, y) in
  310. -- user-space coordinates. After this call the current point will be (x, y).
  311. --
  312. -- If there is no current point before the call to cairo_line_to() this
  313. -- function will behave as cairo_move_to (cr, x, y).
  314. --
  315. -- cr : a cairo context
  316. -- x : the X coordinate of the end of the new line
  317. -- y : the Y coordinate of the end of the new line
  318. --
  319. -- --------------------------------------------------------------------------
  320. --
  321. -- cairo_move_to ()
  322. --
  323. -- void cairo_move_to (cairo_t *cr,
  324. -- double x,
  325. -- double y);
  326. --
  327. -- Begin a new sub-path. After this call the current point will be (x, y).
  328. --
  329. -- cr : a cairo context
  330. -- x : the X coordinate of the new position
  331. -- y : the Y coordinate of the new position
  332. --
  333. -- --------------------------------------------------------------------------
  334. --
  335. -- cairo_rectangle ()
  336. --
  337. -- void cairo_rectangle (cairo_t *cr,
  338. -- double x,
  339. -- double y,
  340. -- double width,
  341. -- double height);
  342. --
  343. -- Adds a closed sub-path rectangle of the given size to the current path at
  344. -- position (x, y) in user-space coordinates.
  345. --
  346. -- This function is logically equivalent to:
  347. --
  348. -- cairo_move_to (cr, x, y);
  349. -- cairo_rel_line_to (cr, width, 0);
  350. -- cairo_rel_line_to (cr, 0, height);
  351. -- cairo_rel_line_to (cr, -width, 0);
  352. -- cairo_close_path (cr);
  353. --
  354. -- cr : a cairo context
  355. -- x : the X coordinate of the top left corner of the rectangle
  356. -- y : the Y coordinate to the top left corner of the rectangle
  357. -- width : the width of the rectangle
  358. -- height : the height of the rectangle
  359. --
  360. -- --------------------------------------------------------------------------
  361. --
  362. -- cairo_glyph_path ()
  363. --
  364. -- void cairo_glyph_path (cairo_t *cr,
  365. -- cairo_glyph_t *glyphs,
  366. -- int num_glyphs);
  367. --
  368. -- cr :
  369. -- glyphs :
  370. -- num_glyphs :
  371. --
  372. -- --------------------------------------------------------------------------
  373. --
  374. -- cairo_text_path ()
  375. --
  376. -- void cairo_text_path (cairo_t *cr,
  377. -- const char *utf8);
  378. --
  379. -- cr :
  380. -- utf8 :
  381. --
  382. -- --------------------------------------------------------------------------
  383. --
  384. -- cairo_rel_curve_to ()
  385. --
  386. -- void cairo_rel_curve_to (cairo_t *cr,
  387. -- double dx1,
  388. -- double dy1,
  389. -- double dx2,
  390. -- double dy2,
  391. -- double dx3,
  392. -- double dy3);
  393. --
  394. -- Relative-coordinate version of cairo_curve_to(). All offsets are relative
  395. -- to the current point. Adds a cubic Bezier spline to the path from the
  396. -- current point to a point offset from the current point by (dx3, dy3),
  397. -- using points offset by (dx1, dy1) and (dx2, dy2) as the control points.
  398. -- After this call the current point will be offset by (dx3, dy3).
  399. --
  400. -- Given a current point of (x, y), cairo_rel_curve_to (cr, dx1, dy1, dx2,
  401. -- dy2, dx3, dy3) is logically equivalent to cairo_curve_to (cr, x + dx1, y +
  402. -- dy1, x + dx2, y + dy2, x + dx3, y + dy3).
  403. --
  404. -- It is an error to call this function with no current point. Doing so will
  405. -- cause cr to shutdown with a status of CAIRO_STATUS_NO_CURRENT_POINT.
  406. --
  407. -- cr : a cairo context
  408. -- dx1 : the X offset to the first control point
  409. -- dy1 : the Y offset to the first control point
  410. -- dx2 : the X offset to the second control point
  411. -- dy2 : the Y offset to the second control point
  412. -- dx3 : the X offset to the end of the curve
  413. -- dy3 : the Y offset to the end of the curve
  414. --
  415. -- --------------------------------------------------------------------------
  416. --
  417. -- cairo_rel_line_to ()
  418. --
  419. -- void cairo_rel_line_to (cairo_t *cr,
  420. -- double dx,
  421. -- double dy);
  422. --
  423. -- Relative-coordinate version of cairo_line_to(). Adds a line to the path
  424. -- from the current point to a point that is offset from the current point by
  425. -- (dx, dy) in user space. After this call the current point will be offset
  426. -- by (dx, dy).
  427. --
  428. -- Given a current point of (x, y), cairo_rel_line_to(cr, dx, dy) is
  429. -- logically equivalent to cairo_line_to (cr, x + dx, y + dy).
  430. --
  431. -- It is an error to call this function with no current point. Doing so will
  432. -- cause cr to shutdown with a status of CAIRO_STATUS_NO_CURRENT_POINT.
  433. --
  434. -- cr : a cairo context
  435. -- dx : the X offset to the end of the new line
  436. -- dy : the Y offset to the end of the new line
  437. --
  438. -- --------------------------------------------------------------------------
  439. --
  440. -- cairo_rel_move_to ()
  441. --
  442. -- void cairo_rel_move_to (cairo_t *cr,
  443. -- double dx,
  444. -- double dy);
  445. --
  446. -- Begin a new sub-path. After this call the current point will offset by (x,
  447. -- y).
  448. --
  449. -- Given a current point of (x, y), cairo_rel_move_to(cr, dx, dy) is
  450. -- logically equivalent to cairo_move_to (cr, x + dx, y + dy).
  451. --
  452. -- It is an error to call this function with no current point. Doing so will
  453. -- cause cr to shutdown with a status of CAIRO_STATUS_NO_CURRENT_POINT.
  454. --
  455. -- cr : a cairo context
  456. -- dx : the X offset
  457. -- dy : the Y offset
  458. feature {ANY} -- Access
  459. status: INTEGER
  460. -- The current error status
  461. do
  462. Result := cairo_path_get_status (handle)
  463. ensure
  464. is_valid_cairo_status (Result)
  465. end
  466. end -- class CAIRO_PATH