<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle20
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">I’ve managed to answer my own question so here it is, just in case it’s useful for anyone else in the future.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Cairo’s built-in font support is quite basic, which is the reason why they’re referred to as “toy fonts”. The documentation concedes that Cairo alone will probably not be sufficient for professional
standard work and recommends a pairing with the Pango project. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">For my immediate project, I’m going to have to stick to Arial now, but that’s not the end of the world since it’s not a bad font for my intended purpose. While the docs say any CSS2 style face name
will work (e.g. “serif, sans-serif”), in Windows, the only font faces that seem to work for me are “Arial” and “Times”. “Courier” goes very wrong!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Having worked with it for a few days now, I quite like Cairo, but feel it’s a shame the text support is not as strong as I’d hoped for.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Warren <o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> cairo <cairo-bounces@cairographics.org>
<b>On Behalf Of </b>Warren Vick<br>
<b>Sent:</b> 25 June 2019 07:24<br>
<b>To:</b> cairo@cairographics.org<br>
<b>Subject:</b> Re: [cairo] Text stuffing with Cairo/pycairo?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Curiously, when I just select the font face as simply “Times”, the output is different (serif) and Acrobat reports the embedded font as “TimesNewRomanPSMT”. I don’t have a font of that name installed,
as far as I’m aware!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Warren<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> cairo <</span><a href="mailto:cairo-bounces@cairographics.org"><span lang="EN-US">cairo-bounces@cairographics.org</span></a><span lang="EN-US">>
<b>On Behalf Of </b>Warren Vick<br>
<b>Sent:</b> 25 June 2019 07:10<br>
<b>To:</b> </span><a href="mailto:cairo@cairographics.org"><span lang="EN-US">cairo@cairographics.org</span></a><span lang="EN-US"><br>
<b>Subject:</b> Re: [cairo] Text stuffing with Cairo/pycairo?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">I’ve made some good progress working with pyCairo after porting Eric’s C code below. I am, however, having a problem with selecting fonts…<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">I’m using pyCairo on Windows. No matter what font I select using
<b>select_font_face</b> on a context, I seem to get Arial output in my PDF. Does pyCairo pick-up fonts installed on Windows or do the TTF files need to be copied somewhere specific? Or, have I misunderstood what is meant by the face name? e.g. “Noto Sans Condensed”.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Regards,<br>
Warren<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> </span>
<a href="mailto:cecashon@aol.com"><span lang="EN-US">cecashon@aol.com</span></a><span lang="EN-US"> <</span><a href="mailto:cecashon@aol.com"><span lang="EN-US">cecashon@aol.com</span></a><span lang="EN-US">>
<br>
<b>Sent:</b> 01 May 2019 18:41<br>
<b>To:</b> Warren Vick <</span><a href="mailto:wvick@europa.uk.com"><span lang="EN-US">wvick@europa.uk.com</span></a><span lang="EN-US">>;
</span><a href="mailto:cairo@cairographics.org"><span lang="EN-US">cairo@cairographics.org</span></a><span lang="EN-US"><br>
<b>Subject:</b> Re: [cairo] Text stuffing with Cairo/pycairo?<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><br>
It is worth mentioning here that when you draw lines around the box with the usual way of doing this,<br>
<br>
cairo_fill_preserve(cr);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
cairo_stroke(cr);<br>
<br>
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>
//Order transforms and draw.<br>
cairo_save(cr);<br>
cairo_translate(cr, center_box_x, center_box_y);<br>
cairo_rotate(cr, rotate);<br>
cairo_scale(cr, box_width/fabs(2.0*move_x), box_height/fabs(2.0*move_y));<br>
cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 0.4);<br>
double r1=-fabs(scale_x);<br>
double r2=-fabs(scale_y);<br>
double r3=fabs(2.0*scale_x);<br>
double r4=fabs(2.0*scale_y);<br>
cairo_rectangle(cr, r1, r2, r3, r4);<br>
cairo_fill(cr);<br>
//Save device cordinates for the rectangle so that lines are drawn correctly.<br>
double c1=r1;<br>
double c2=r2;<br>
double c3=r1;<br>
double c4=r2+r4;<br>
double c5=r1+r3;<br>
double c6=r2+r4;<br>
double c7=r1+r3;<br>
double c8=r2;<br>
cairo_user_to_device(cr, &c1, &c2);<br>
cairo_user_to_device(cr, &c3, &c4);<br>
cairo_user_to_device(cr, &c5, &c6);<br>
cairo_user_to_device(cr, &c7, &c8);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);<br>
cairo_move_to(cr, move_x, move_y);<br>
cairo_show_text(cr, string);<br>
cairo_restore(cr); <br>
<br>
//Draw box lines.<br>
cairo_save(cr);<br>
cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);<br>
cairo_set_line_width(cr, 4.0);<br>
//Reset transform matrix.<br>
cairo_identity_matrix(cr);<br>
cairo_move_to(cr, c1, c2);<br>
cairo_line_to(cr, c3, c4);<br>
cairo_line_to(cr, c5, c6);<br>
cairo_line_to(cr, c7, c8);<br>
cairo_close_path(cr);<br>
cairo_stroke(cr);<br>
cairo_restore(cr);<br>
}<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
</div>
</body>
</html>