# [cairo] is skew supposed to move/shift top/left x?

Mark Olesen markjolesen at gmail.com
Thu Feb 11 04:38:30 UTC 2016

```When skewing in the x direction, top x seems to move to the right a bit.I
have attached a png. The red rectangle is not skewed, while the black is
skewed at 45. The skewed (black) rectangle looks shifted to the right a few
pixels. That is the top is not aligned. I would think there should be a
diagonal line cutting through the top left hitting the bottom right corner.
>From my past history, I am probably doing something wrong. Thanks in

#include <cairo.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

/*
http://cairographics.org/cookbook/matrix_transform/http://cairographics.org/cookbook/matrix_transform/
Lets take that C = math.cos(A), S = math.sin(A), T = math.tan(A)
X-skew by A    --    mtrx = cairo.Matrix(1,0,T,1,0,0)
Y-skew by A    --    mtrx = cairo.Matrix(1,T,0,1,0,0)
*/

int
main (int argc, char *argv[])
{
cairo_surface_t* cs;
cairo_t *cr;
double angle;
double skewx;
cairo_matrix_t matrix;

cs= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 130.,100.);
cr= cairo_create(cs);

cairo_set_source_rgb(cr, 1., 0., 0.);
cairo_rectangle(cr, 10., 10., 50., 50.);
cairo_stroke(cr);

angle= 45.;
skewx= tan(angle * M_PI / 180.);
cairo_matrix_init(
&matrix,
1.0, 0.0,
skewx, 1.0,
0.0, 0.0);
cairo_transform(cr, &matrix);
cairo_rectangle(cr, 10., 10., 50., 50.);
cairo_set_source_rgb(cr, 0., 0., 0.);
cairo_stroke(cr);

cairo_surface_write_to_png(cs, "skew.png");

cairo_destroy(cr);
cairo_surface_destroy(cs);

return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20160210/bbb15049/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: skew.png
Type: image/png
Size: 595 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20160210/bbb15049/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 1131 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20160210/bbb15049/attachment-0001.c>
```