Search code examples
pythoncairopycairo

How to merge path with pycairo?


I am drawing with pycairo using curve_to , here's the code :

ctx.move_to(0.4,0.8)
ctx.curve_to(0.3,0.4 ,0.4,0.4 ,0.4,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.fill()

ctx.move_to(0.4,0.8)
ctx.line_to(0.5,0.8)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.stroke()


ctx.move_to(0.5,0.8)
ctx.curve_to(0.6,0.4 ,0.5,0.4 ,0.5,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.fill()

ctx.move_to(0.4,0.4)
ctx.line_to(0.5,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.stroke()

enter image description here

i'm want to fill the object but as you see , i cannot fill it all because they're separate and not merged yet. So i think the closest approach here is to merge them .


Solution

  • What about:

        ctx.set_source_rgb(0,0,0)
        ctx.set_line_width(0.001)
    
        ctx.move_to(0.5,0.8)
        ctx.line_to(0.4,0.8)
        ctx.curve_to(0.3,0.4 ,0.4,0.4 ,0.4,0.4)
    
        ctx.move_to(0.4,0.4)
        ctx.line_to(0.5,0.8)
        ctx.curve_to(0.6,0.4 ,0.5,0.4 ,0.5,0.4)
    
        ctx.fill()
    

    I tested it this and it formed a filled region. I'm not sure its right.