<div dir="ltr">Try flooring x1,y1 before subtracting them from x2,y2 for computing the size of your surface.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">behdad<br><a href="http://behdad.org/" target="_blank">http://behdad.org/</a></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 8, 2022 at 10:21 AM Andreas Falkenhahn <<a href="mailto:andreas@falkenhahn.com">andreas@falkenhahn.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Is there really nobody who knows how to solve this? There surely must be a way to find out the *exact* extents of transformed graphics? The idea is to find out the exact dimensions in order to allocate a Cairo surface that *exactly* matches the size of the path.<br>
<br>
On 28.08.2022 at 21:47 Andreas Falkenhahn wrote:<br>
<br>
> Hi,<br>
<br>
> is there any way to get the *exact* extents of transformed<br>
> graphics? AFAICS, cairo_fill_extents() is in user coordinates, i.e.<br>
> it doesn't take any transformation settings into account. So I've<br>
> tried to apply the transformation manually to what I get from<br>
> cairo_fill_extents() but I don't seem to get it 100% right. It looks<br>
> like one row is missing at the bottom. <br>
<br>
> This is what I've tried:<br>
<br>
> cairo_t *cr;<br>
> cairo_surface_t *surface;<br>
> cairo_matrix_t cm;<br>
> int k;<br>
> double tx = 0, ty = 0;<br>
> double x1, y1, x2, y2;<br>
> <br>
> surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 1000, 1000);<br>
> cr = cairo_create(surface);<br>
<br>
> for(k = 0; k < 2; k++) {<br>
> <br>
> cairo_new_path(cr);<br>
> cairo_move_to(cr, tx, ty);<br>
> cairo_set_font_size(cr, 100);<br>
> cairo_text_path(cr, "C"); <br>
> <br>
> if(!k) { <br>
> <br>
> double width, height;<br>
> <br>
> cairo_fill_extents(cr, &x1, &y1, &x2, &y2);<br>
> <br>
> tx = -x1;<br>
> ty = -y1; <br>
> <br>
> width = fabs(x2 - x1);<br>
> height = fabs(y2 - y1);<br>
<br>
> width = ceil(width * 4.6);<br>
> height = ceil(height * 4.6);<br>
> <br>
> cairo_destroy(cr);<br>
> cairo_surface_destroy(surface);<br>
> <br>
> surface =<br>
> cairo_image_surface_create(CAIRO_FORMAT_A8, width, height);<br>
> cr = cairo_create(surface); <br>
> <br>
> cairo_matrix_init(&cm, 4.6, 0, 0, 4.6, 0, 0);<br>
> cairo_set_matrix(cr, &cm); <br>
> }<br>
> }<br>
> <br>
> cairo_fill(cr);<br>
<br>
> cairo_surface_flush(surface);<br>
> cairo_surface_write_to_png(surface, "tmp.png");<br>
> <br>
> cairo_destroy(cr);<br>
> cairo_surface_destroy(surface);<br>
<br>
> I'm attaching the resulting image. As you can see, there's at least<br>
> one row of the "C" shape missing at the bottom of the image.<br>
<br>
> Any ideas how to get this right? Is this some sort of floating<br>
> point inaccuracy and should I just add 1 to width/height to solve<br>
> this or am I doing something wrong here and there is a better way?<br>
<br>
<br>
<br>
-- <br>
Best regards,<br>
Andreas Falkenhahn mailto:<a href="mailto:andreas@falkenhahn.com" target="_blank">andreas@falkenhahn.com</a><br>
<br>
</blockquote></div>