<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
in my opinion it should be like this and everything will be fine</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
         width  = fabs( x2 - x1 + 0.5 );
<div>         height = fabs( y2 - y1 + 0.5 );</div>
<br>
</div>
<div id="signature_bookmark" style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
-- Rafał <br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<a href="https://github.com/rjopek/glfw-cairo" id="LPNoLPOWALinkPreview">https://github.com/rjopek/glfw-cairo</a><br>
</div>
<div class="_Entity _EType_OWALinkPreview _EId_OWALinkPreview _EReadonly_1"></div>
<br>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>Od:</b> cairo <cairo-bounces@cairographics.org> w imieniu użytkownika Andreas Falkenhahn <andreas@falkenhahn.com><br>
<b>Wysłane:</b> czwartek, 8 września 2022 19:24<br>
<b>Do:</b> Behdad Esfahbod <behdad@behdad.org><br>
<b>DW:</b> cairo@cairographics.org <cairo@cairographics.org><br>
<b>Temat:</b> Re: [cairo] How to get extents of transformed graphics</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">I've tried this:<br>
<br>
        width = fabs(x2 - floor(x1));<br>
        height = fabs(y2 - floor(y1));<br>
<br>
        width = ceil(width * 4.6);<br>
        height = ceil(height * 4.6);<br>
<br>
Still cuts off a line of the "C" shape. I've also tried this:<br>
<br>
        width = fabs(ceil(x2) - floor(x1));<br>
        height = fabs(ceil(y2) - floor(y1));<br>
<br>
        width = ceil(width * 4.6);<br>
        height = ceil(height * 4.6);<br>
<br>
No success either. A line is cut off.<br>
<br>
Any more ideas? You can find my test program below...<br>
<br>
On 08.09.2022 at 19:03 Behdad Esfahbod wrote:<br>
<br>
> Try flooring x1,y1 before subtracting them from x2,y2 for computing the size of your surface.<br>
<br>
<br>
> behdad<br>
> <a href="http://behdad.org/" data-auth="NotApplicable">http://behdad.org/</a><br>
<br>
> On Thu, Sep 8, 2022 at 10:21 AM Andreas Falkenhahn <andreas@falkenhahn.com> wrote:<br>
<br>
> Is there really nobody who knows how to solve this? There surely<br>
> must be a way to find out the *exact* extents of transformed<br>
> graphics? The idea is to find out the exact dimensions in order to<br>
> 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                            <a href="mailto:andreas@falkenhahn.com" data-auth="NotApplicable">
mailto:andreas@falkenhahn.com</a><br>
>  <br>
>  <br>
<br>
<br>
-- <br>
Best regards,<br>
 Andreas Falkenhahn                            <a href="mailto:andreas@falkenhahn.com" data-auth="NotApplicable">
mailto:andreas@falkenhahn.com</a><br>
<br>
</div>
</span></font></div>
</body>
</html>