Re: Text stuffing with Cairo/pycairo?

[email protected] Wed, 1 May 2019 17:40:55 +0000 (UTC)
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
--===============0979978357==
Content-Type: multipart/alternative; 
	boundary="----=_Part_3407507_372540477.1556732455402"

------=_Part_3407507_372540477.1556732455402
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

=20
It is worth mentioning here that when you draw lines around the box with th=
e usual way of doing this,

=C2=A0 cairo_fill_preserve(cr);
=C2=A0 cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
=C2=A0 cairo_stroke(cr);
=C2=A0=20
=C2=A0the scale will cause the lines to be non uniform. This is mentioned i=
n the Cairo Tutorial under Working with Transforms.

To get the lines around the box to be uniform, the transformed points can b=
e mapped to device space or the starting coordinates that cairo uses. Then =
the lines around the box can be drawn. The following shows this.

Have fun drawing.
Eric

...
=C2=A0=C2=A0=C2=A0 //Order transforms and draw.
=C2=A0=C2=A0=C2=A0 cairo_save(cr);
=C2=A0=C2=A0=C2=A0 cairo_translate(cr, center_box_x, center_box_y);
=C2=A0=C2=A0=C2=A0 cairo_rotate(cr, rotate);
=C2=A0=C2=A0=C2=A0 cairo_scale(cr, box_width/fabs(2.0*move_x), box_height/f=
abs(2.0*move_y));
=C2=A0=C2=A0=C2=A0 cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 0.4);
=C2=A0=C2=A0=C2=A0 double r1=3D-fabs(scale_x);
=C2=A0=C2=A0=C2=A0 double r2=3D-fabs(scale_y);
=C2=A0=C2=A0=C2=A0 double r3=3Dfabs(2.0*scale_x);
=C2=A0=C2=A0=C2=A0 double r4=3Dfabs(2.0*scale_y);
=C2=A0=C2=A0=C2=A0 cairo_rectangle(cr, r1, r2, r3, r4);
=C2=A0=C2=A0=C2=A0 cairo_fill(cr);
=C2=A0=C2=A0=C2=A0 //Save device cordinates for the rectangle so that lines=
 are drawn correctly.
=C2=A0=C2=A0=C2=A0 double c1=3Dr1;
=C2=A0=C2=A0=C2=A0 double c2=3Dr2;
=C2=A0=C2=A0=C2=A0 double c3=3Dr1;
=C2=A0=C2=A0=C2=A0 double c4=3Dr2+r4;
=C2=A0=C2=A0=C2=A0 double c5=3Dr1+r3;
=C2=A0=C2=A0=C2=A0 double c6=3Dr2+r4;
=C2=A0=C2=A0=C2=A0 double c7=3Dr1+r3;
=C2=A0=C2=A0=C2=A0 double c8=3Dr2;
=C2=A0=C2=A0=C2=A0 cairo_user_to_device(cr, &c1, &c2);
=C2=A0=C2=A0=C2=A0 cairo_user_to_device(cr, &c3, &c4);
=C2=A0=C2=A0=C2=A0 cairo_user_to_device(cr, &c5, &c6);
=C2=A0=C2=A0=C2=A0 cairo_user_to_device(cr, &c7, &c8);
=C2=A0=C2=A0=C2=A0 cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
=C2=A0=C2=A0=C2=A0 cairo_move_to(cr, move_x, move_y);
=C2=A0=C2=A0=C2=A0 cairo_show_text(cr, string);
=C2=A0=C2=A0=C2=A0 cairo_restore(cr);=20

=C2=A0=C2=A0=C2=A0 //Draw box lines.
=C2=A0=C2=A0=C2=A0 cairo_save(cr);
=C2=A0=C2=A0=C2=A0 cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);
=C2=A0=C2=A0=C2=A0 cairo_set_line_width(cr, 4.0);
=C2=A0=C2=A0=C2=A0 //Reset transform matrix.
=C2=A0=C2=A0=C2=A0 cairo_identity_matrix(cr);
=C2=A0=C2=A0=C2=A0 cairo_move_to(cr, c1, c2);
=C2=A0=C2=A0=C2=A0 cairo_line_to(cr, c3, c4);
=C2=A0=C2=A0=C2=A0 cairo_line_to(cr, c5, c6);
=C2=A0=C2=A0=C2=A0 cairo_line_to(cr, c7, c8);
=C2=A0=C2=A0=C2=A0 cairo_close_path(cr);
=C2=A0=C2=A0=C2=A0 cairo_stroke(cr);
=C2=A0=C2=A0=C2=A0 cairo_restore(cr);
=C2=A0 }

=20
=20


------=_Part_3407507_372540477.1556732455402
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<font color='black' size='2' face='arial'>
<div> <font size="2"><br>
It is worth mentioning here that when you draw lines around the box with the usual way of doing this,<br>
<br>
&nbsp; cairo_fill_preserve(cr);<br>
&nbsp; cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
&nbsp; cairo_stroke(cr);<br>
&nbsp; <br>
&nbsp;the scale will cause the lines to be non uniform. This is mentioned in the Cairo Tutorial under Working with Transforms.<br>
<br>
To get the lines around the box to be uniform, the transformed points can be mapped to device space or the starting coordinates that cairo uses. Then the lines around the box can be drawn. The following shows this.<br>
<br>
Have fun drawing.<br>
Eric<br>
<br>
...<br>
&nbsp;&nbsp;&nbsp; //Order transforms and draw.<br>
&nbsp;&nbsp;&nbsp; cairo_save(cr);<br>
&nbsp;&nbsp;&nbsp; cairo_translate(cr, center_box_x, center_box_y);<br>
&nbsp;&nbsp;&nbsp; cairo_rotate(cr, rotate);<br>
&nbsp;&nbsp;&nbsp; cairo_scale(cr, box_width/fabs(2.0*move_x), box_height/fabs(2.0*move_y));<br>
&nbsp;&nbsp;&nbsp; cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 0.4);<br>
&nbsp;&nbsp;&nbsp; double r1=-fabs(scale_x);<br>
&nbsp;&nbsp;&nbsp; double r2=-fabs(scale_y);<br>
&nbsp;&nbsp;&nbsp; double r3=fabs(2.0*scale_x);<br>
&nbsp;&nbsp;&nbsp; double r4=fabs(2.0*scale_y);<br>
&nbsp;&nbsp;&nbsp; cairo_rectangle(cr, r1, r2, r3, r4);<br>
&nbsp;&nbsp;&nbsp; cairo_fill(cr);<br>
&nbsp;&nbsp;&nbsp; //Save device cordinates for the rectangle so that lines are drawn correctly.<br>
&nbsp;&nbsp;&nbsp; double c1=r1;<br>
&nbsp;&nbsp;&nbsp; double c2=r2;<br>
&nbsp;&nbsp;&nbsp; double c3=r1;<br>
&nbsp;&nbsp;&nbsp; double c4=r2+r4;<br>
&nbsp;&nbsp;&nbsp; double c5=r1+r3;<br>
&nbsp;&nbsp;&nbsp; double c6=r2+r4;<br>
&nbsp;&nbsp;&nbsp; double c7=r1+r3;<br>
&nbsp;&nbsp;&nbsp; double c8=r2;<br>
&nbsp;&nbsp;&nbsp; cairo_user_to_device(cr, &amp;c1, &amp;c2);<br>
&nbsp;&nbsp;&nbsp; cairo_user_to_device(cr, &amp;c3, &amp;c4);<br>
&nbsp;&nbsp;&nbsp; cairo_user_to_device(cr, &amp;c5, &amp;c6);<br>
&nbsp;&nbsp;&nbsp; cairo_user_to_device(cr, &amp;c7, &amp;c8);<br>
&nbsp;&nbsp;&nbsp; cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
&nbsp;&nbsp;&nbsp; cairo_move_to(cr, move_x, move_y);<br>
&nbsp;&nbsp;&nbsp; cairo_show_text(cr, string);<br>
&nbsp;&nbsp;&nbsp; cairo_restore(cr); <br>
<br>
&nbsp;&nbsp;&nbsp; //Draw box lines.<br>
&nbsp;&nbsp;&nbsp; cairo_save(cr);<br>
&nbsp;&nbsp;&nbsp; cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);<br>
&nbsp;&nbsp;&nbsp; cairo_set_line_width(cr, 4.0);<br>
&nbsp;&nbsp;&nbsp; //Reset transform matrix.<br>
&nbsp;&nbsp;&nbsp; cairo_identity_matrix(cr);<br>
&nbsp;&nbsp;&nbsp; cairo_move_to(cr, c1, c2);<br>
&nbsp;&nbsp;&nbsp; cairo_line_to(cr, c3, c4);<br>
&nbsp;&nbsp;&nbsp; cairo_line_to(cr, c5, c6);<br>
&nbsp;&nbsp;&nbsp; cairo_line_to(cr, c7, c8);<br>
&nbsp;&nbsp;&nbsp; cairo_close_path(cr);<br>
&nbsp;&nbsp;&nbsp; cairo_stroke(cr);<br>
&nbsp;&nbsp;&nbsp; cairo_restore(cr);<br>
&nbsp; }<br>
</font><br>
</div>

<div> <br>
</div>

<div> <br>
</div>

<div style="font-family:arial,helvetica;font-size:10pt;color:black"><br>
</div>
</font>
------=_Part_3407507_372540477.1556732455402--

--===============0979978357==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

LS0gCmNhaXJvIG1haWxpbmcgbGlzdApjYWlyb0BjYWlyb2dyYXBoaWNzLm9yZwpodHRwczovL2xp
c3RzLmNhaXJvZ3JhcGhpY3Mub3JnL21haWxtYW4vbGlzdGluZm8vY2Fpcm8=

--===============0979978357==--