0

Is there a way to combine two closed paths in Cairo, so the group of paths is filled as a single solid shape, instead of two shapes sitting next to each other?

If I draw two paths next to each other, there is a faint blank line visible between the two shapes. For example, the below script draws a square and an adjacent half circle so they both share a line. There is a faint blank line visible between the two shapes. I want there to be no dividing line between the two shapes.

import math, cairo

def draw_path_1(ctx):
    ctx.rectangle(40, 55, 30, 30)
    ctx.fill()

def draw_path_2(ctx):
    ctx.arc(70, 70, 30, -math.pi / 2, math.pi / 2)
    ctx.fill()

with cairo.SVGSurface("two_path_shape.svg", 150, 150) as surface:
    ctx = cairo.Context(surface)
    draw_path_1(ctx)
    draw_path_2(ctx)

Two shape SVG with faint line

I want some way of drawing the SVG without the faint line between the two shapes. I am not only looking for a solution specifically for this example of a square and a half circle, but some method of doing this for more complex paths.

I found that exporting the image as a png does remove this line, but that doesn't help me, as I want the final output as an SVG file.

surface.write_to_png("two_path_shape.png")
The Matt
  • 1,423
  • 1
  • 12
  • 22
  • A solution to https://stackoverflow.com/questions/843647/boolean-operations-on-cairo-paths would solve this issue, but it seems there are no such operations in Cairo – The Matt Jan 01 '23 at 18:48
  • try setting [antialiasing to fast](https://api.gtkd.org/cairo.c.types.cairo_antialias_t.html) on the square. – Robert Longson Jan 01 '23 at 19:01
  • Thanks for the suggestion, but it seems that the antialiasing only effects *rasterizing* the image. Inspecting the file shows that the SVG is not effected by changing the antialiasing mode. – The Matt Jan 01 '23 at 19:20
  • How are you displaying the final SVG file? – Robert Longson Jan 01 '23 at 21:52
  • Via Browser. I see the line in Chrome, Firefox, Safari, and Gimp. But my issue is that the line is *there*, I want the line gone, not somehow hide it in the renderer. – The Matt Jan 01 '23 at 23:02

0 Answers0