Cairo Saved Paths with Transforms Render "Backwards" -
the below code sample in lua, intended used conky. thought compute complicated path, save it, render twice -- once filled region, again stroked path, creating outlined region.
the problem saved path seems render "backwards" compared straightforward rendering.
the first section creates rotated l-shape in green, appears expected.
the second section attempts create same l-shape saved path, render in red. resulting path not come out rotated, since didn't call cairo_rotate()
before appending path, suppose makes sense.
the third section renders set of progressively rotated l-shapes in cyan, appears expected.
the fourth section attempts same thing third section, time using saved paths, , rendering in yellow. paths come out going in wrong direction.
my guess cairo transformation functions apply transforms unstroked path components (if any) accumulated in cairo_t
context. don't quite grasp why come out "forwards" 1 way , "backwards" other way.
what misunderstanding cairo paths , transforms?
function tests (cr) local wiggle local mat_base = cairo_matrix_t:create () tolua.takeownership (mat_base) cairo_set_line_width (cr, 4) cairo_identity_matrix (cr) --- -- direct stroke of l-shaped figure. cairo_save (cr) cairo_translate (cr, 128, 128) cairo_new_path (cr) cairo_rotate (cr, math.pi / 6) cairo_move_to (cr, 150, 0) cairo_line_to (cr, 0, 0) cairo_line_to (cr, 0, 50) cairo_set_source_rgb (cr, 0, 1, 0) cairo_stroke (cr) cairo_restore (cr) --- -- capture l-shaped figure path, render. cairo_save (cr) cairo_translate (cr, 384, 128) cairo_new_path (cr) cairo_rotate (cr, math.pi / 6) cairo_move_to (cr, 150, 0) cairo_line_to (cr, 0, 0) cairo_line_to (cr, 0, 50) wiggle = cairo_copy_path (cr) cairo_restore (cr) cairo_save (cr) cairo_translate (cr, 384, 128) cairo_new_path (cr) cairo_append_path (cr, wiggle) cairo_set_source_rgb (cr, 1, 0, 0) cairo_stroke (cr) cairo_path_destroy (wiggle) cairo_restore (cr) --- -- direct stroke of set of rotated l-shaped figures. cairo_save (cr) cairo_translate (cr, 640, 128) cairo_get_matrix (cr, mat_base) cairo_new_path (cr) = 0, 4 cairo_set_matrix (cr, mat_base) cairo_rotate (cr, * math.pi / 6) cairo_move_to (cr, 150, 0) cairo_line_to (cr, 0, 0) cairo_line_to (cr, 0, 50) end cairo_set_source_rgb (cr, 0, 1, 1) cairo_stroke (cr) cairo_restore (cr) --- -- capture rotated l-shaped figures path, render. cairo_save (cr) cairo_translate (cr, 896, 128) cairo_get_matrix (cr, mat_base) cairo_new_path (cr) = 0, 4 cairo_set_matrix (cr, mat_base) cairo_rotate (cr, * math.pi / 6) cairo_move_to (cr, 150, 0) cairo_line_to (cr, 0, 0) cairo_line_to (cr, 0, 50) end wiggle = cairo_copy_path (cr) cairo_restore (cr) cairo_save (cr) cairo_new_path (cr) cairo_translate (cr, 896, 128) cairo_append_path (cr, wiggle) cairo_set_source_rgb (cr, 1, 1, 0) cairo_stroke (cr) cairo_path_destroy (wiggle) cairo_restore (cr) -- end
when call cairo_copy_path
, path expressed in current user space. if first draw path , afterwards call cairo_rotate(), cairo_copy_path()
, resulting path include same last rotation.
so in red example, copy path before undoing rotation , hence appears there no rotation.
in yellow example, copy path after rotation , first rotations in different "direction" in blue one.
try replacing a = cairo_copy_path(cr)
cairo_save(cr) ; cairo_identity_matrix(cr) ; = cairo_copy_path(cr) ; cairo_restore(cr)
. way path in surface coordinates seems more expecting.
Comments
Post a Comment