[prev in list] [next in list] [prev in thread] [next in thread]
List: cairo
Subject: Re: [cairo] Question about extents and transformations
From: cecashon () aol ! com
Date: 2019-12-12 20:38:43
Message-ID: 1558918678.7585082.1576183123322 () mail ! yahoo ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
A path in user space can change it's bounding box size with a transform. A scale or \
rotation can change the size of a bounding box.
With your code, test the output by drawing it. That is one of the cool things about \
drawing. If you are working on a tough drawing you can often see mistakes that you \
might miss otherwise.
Eric
//gcc -Wall bounding_box1.c -o bounding_box1 `pkg-config --cflags --libs cairo` -lm
#include<cairo.h>
#include<stdio.h>
#include<math.h>
int main()
{
double width=500.0;
double height=500.0;
double x1=0.0;
double y1=0.0;
double x2=0.0;
double y2=0.0;
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, \
width, height); cairo_t *cr=cairo_create(surface);
//Paint the background.
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
cairo_paint(cr);
//Translate shape.
cairo_save(cr);
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0);
cairo_translate(cr, width/4.0, height/4.0);
cairo_move_to(cr, 100.0, 0.0);
cairo_curve_to(cr, 50.0, -50.0, -50.0, -50.0, -100.0, 0.0);
cairo_curve_to(cr, -50.0, 50.0, 50.0, 50.0, 100.0, 0.0);
cairo_path_extents(cr, &x1, &y1, &x2, &y2);
cairo_fill(cr);
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);
cairo_stroke(cr);
cairo_restore(cr);
//Translate and scale shape.
cairo_save(cr);
cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);
cairo_translate(cr, 3.0*width/4.0, height/4.0);
cairo_scale(cr, 0.75, 0.75);
cairo_move_to(cr, 100.0, 0.0);
cairo_curve_to(cr, 50.0, -50.0, -50.0, -50.0, -100.0, 0.0);
cairo_curve_to(cr, -50.0, 50.0, 50.0, 50.0, 100.0, 0.0);
cairo_path_extents(cr, &x1, &y1, &x2, &y2);
cairo_fill(cr);
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);
cairo_stroke(cr);
cairo_restore(cr);
//Translate and rotate shape.
cairo_save(cr);
cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);
cairo_translate(cr, width/4.0, 3.0*height/4.0);
cairo_rotate(cr, M_PI/2.0);
cairo_move_to(cr, 100.0, 0.0);
cairo_curve_to(cr, 50.0, -50.0, -50.0, -50.0, -100.0, 0.0);
cairo_curve_to(cr, -50.0, 50.0, 50.0, 50.0, 100.0, 0.0);
cairo_path_extents(cr, &x1, &y1, &x2, &y2);
cairo_fill(cr);
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);
cairo_stroke(cr);
cairo_restore(cr);
printf("Output to bounding_box.png\n");
cairo_surface_write_to_png(surface, "bounding_box.png");
cairo_destroy(cr);
cairo_surface_destroy(surface);
return 0;
}
[Attachment #5 (text/html)]
<div style="color:black;font: 10pt arial;">
<div> <font size="2"><br>
A path in user space can change it's bounding box size with a transform. A scale or \
rotation can change the size of a bounding box.<br> <br>
With your code, test the output by drawing it. That is one of the cool things about \
drawing. If you are working on a tough drawing you can often see mistakes that you \
might miss otherwise.<br> <br>
Eric</font></div>
<div><font size="2"><br>
</font></div>
<div><font size="2"><br>
//gcc -Wall bounding_box1.c -o bounding_box1 `pkg-config --cflags --libs cairo` \
-lm<br> <br>
#include<cairo.h><br>
#include<stdio.h><br>
#include<math.h><br>
<br>
int main()<br>
{<br>
double width=500.0;<br>
double height=500.0;<br>
double x1=0.0;<br>
double y1=0.0;<br>
double x2=0.0;<br>
double y2=0.0;<br>
cairo_surface_t \
*surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);<br> \
cairo_t *cr=cairo_create(surface);<br> <br>
//Paint the background.<br>
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);<br>
cairo_paint(cr);<br>
<br>
//Translate shape.<br>
cairo_save(cr);<br>
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0);<br>
cairo_translate(cr, width/4.0, height/4.0);<br>
cairo_move_to(cr, 100.0, 0.0);<br>
cairo_curve_to(cr, 50.0, -50.0, -50.0, -50.0, -100.0, 0.0);<br>
cairo_curve_to(cr, -50.0, 50.0, 50.0, 50.0, 100.0, 0.0);<br>
cairo_path_extents(cr, &x1, &y1, &x2, &y2);<br>
cairo_fill(cr);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);<br>
cairo_stroke(cr);<br>
cairo_restore(cr);<br>
<br>
//Translate and scale shape.<br>
cairo_save(cr);<br>
cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);<br>
cairo_translate(cr, 3.0*width/4.0, height/4.0);<br>
cairo_scale(cr, 0.75, 0.75);<br>
cairo_move_to(cr, 100.0, 0.0);<br>
cairo_curve_to(cr, 50.0, -50.0, -50.0, -50.0, -100.0, 0.0);<br>
cairo_curve_to(cr, -50.0, 50.0, 50.0, 50.0, 100.0, 0.0);<br>
cairo_path_extents(cr, &x1, &y1, &x2, &y2);<br>
cairo_fill(cr);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);<br>
cairo_stroke(cr);<br>
cairo_restore(cr);<br>
<br>
//Translate and rotate shape.<br>
cairo_save(cr);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);<br>
cairo_translate(cr, width/4.0, 3.0*height/4.0);<br>
cairo_rotate(cr, M_PI/2.0);<br>
cairo_move_to(cr, 100.0, 0.0);<br>
cairo_curve_to(cr, 50.0, -50.0, -50.0, -50.0, -100.0, 0.0);<br>
cairo_curve_to(cr, -50.0, 50.0, 50.0, 50.0, 100.0, 0.0);<br>
cairo_path_extents(cr, &x1, &y1, &x2, &y2);<br>
cairo_fill(cr);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
cairo_rectangle(cr, x1, y1, x2-x1, y2-y1);<br>
cairo_stroke(cr);<br>
cairo_restore(cr);<br>
<br>
printf("Output to bounding_box.png\n");<br>
cairo_surface_write_to_png(surface, "bounding_box.png");<br>
<br>
cairo_destroy(cr);<br>
cairo_surface_destroy(surface);<br>
<br>
return 0;<br>
}</font><br>
</div>
<div> <br>
</div>
<br>
</div>
--
cairo mailing list
cairo@cairographics.org
https://lists.cairographics.org/mailman/listinfo/cairo
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic