<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Sir, you've just made my day. So it's really that simple?<br><br><div><hr id="stopSpelling">Subject: Re: [swift-users] Need Help with C-to-Swift (finally)<br>From: harlan@harlanhaskins.com<br>Date: Fri, 11 Dec 2015 15:24:48 -0500<br>CC: jason.dusek@gmail.com; swift-users@swift.org<br>To: gagemorgan@outlook.com<br><br>So, it’s a very simple almost one-to-one translation of that C code block to Swift.<div>You have to make sure to <font face="Menlo">import CCairo</font> at the beginning of the file, and change the variable declarations to use <font face="Menlo">let</font> instead of the C declaration.</div><div><br></div><div>This works for me, as is.<br><div><br></div><div><div><font face="Menlo">import CCairo</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">let surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80)</font></div><div><font face="Menlo">let cr = cairo_create (surface);</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)</font></div><div><font face="Menlo">cairo_set_font_size(cr, 32.0)</font></div><div><font face="Menlo">cairo_set_source_rgb(cr, 0.0, 0.0, 1.0)</font></div><div><font face="Menlo">cairo_move_to(cr, 10.0, 50.0)</font></div><div><font face="Menlo">cairo_show_text(cr, "Hello, world")</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">cairo_destroy(cr)</font></div><div><font face="Menlo">cairo_surface_write_to_png(surface, "hello.png")</font></div><div><font face="Menlo">cairo_surface_destroy(surface)</font></div><div><br></div><div><blockquote><div>On Dec 11, 2015, at 3:21 PM, Gage Morgan <<a href="mailto:gagemorgan@outlook.com">gagemorgan@outlook.com</a>> wrote:</div><br class="ecxApple-interchange-newline"><div>
<div>
<div>Do so here in a few. Want a bug report for that?<br>
<br>
<div class="ecxacompli_signature">Sent from <a href="https://aka.ms/qtex0l" target="_blank">Outlook Mobile</a></div>
<br>
</div>
<br>
<br>
<br>
<div class="ecxgmail_quote">On Fri, Dec 11, 2015 at 12:08 PM -0800, "Harlan Haskins"
<span dir="ltr"><<a href="mailto:harlan@harlanhaskins.com" target="_blank">harlan@harlanhaskins.com</a>></span> wrote:<br>
<br>
</div>
<div style="word-wrap:break-word;">Mind sending your CCairo modulemap?
<div><br>
</div>
<div>I’d love to help you get this translated to Swift.</div>
<div><br>
<div>
<blockquote>
<div>On Dec 11, 2015, at 2:44 PM, Gage Morgan via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:</div>
<br class="ecxx_Apple-interchange-newline">
<div>
<div>
<div>I want to call PNG surfaces from Swift, as well as use cairo_line_to() and cairo_move_to() in Swift. Thing is, I need an example of cairo used in Swift so I can apply it to the rest of cairo. </div>
<div><br>
</div>
<div>My goal is to generate an executable that outputs *.png images using swift. </div>
<div><br>
</div>
<div>Thanks for the support,</div>
<div>--MGage--<br>
<br>
<div class="ecxx_acompli_signature">Sent from <a href="https://aka.ms/qtex0l" target="_blank">
Outlook Mobile</a></div>
<br>
</div>
<br>
<br>
<br>
<div class="ecxx_gmail_quote">On Thu, Dec 10, 2015 at 10:40 PM -0800, "Jason Dusek" <span dir="ltr">
<<a href="mailto:jason.dusek@gmail.com" target="_blank">jason.dusek@gmail.com</a>></span> wrote:<br>
<br>
</div>
<div>
<div dir="ltr">When you say, output to Swift, do you mean, call it from Swift? Return the PNG or surface to Swift?</div>
<br>
<div class="ecxx_x_gmail_quote">
<div dir="ltr">On Thu, 10 Dec 2015 at 22:39 Gage Morgan via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
</div>
<blockquote class="ecxx_x_gmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">
<div>
<div dir="ltr">So, if I had this code written in C:
<div><br>
</div>
<div>
<pre style="font-family:mono;border:1px solid rgb(197,197,246);padding:0.5em;font-size:inherit;background-color:rgb(219,219,247);"><code>int
main (int argc, char *argv[])
{
cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
cairo_t *cr =
cairo_create (surface);
cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
cairo_show_text (cr, "Hello, world");
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "hello.png");
cairo_surface_destroy (surface);
return 0;
}</code></pre>
</div>
<div><br>
</div>
<div>how would I output to Swift? If I can get one or two examples, I'll be closer to finished with using Cairo in Swift.</div>
<div><br>
</div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=kKLYQ91ZFOe6ryzRU3CXyiq4yOweT6LjPwa6z8Qwa5fRJQvehCW7UCK-2BbJEgYqk9ymhv1Wllv6abHreSdhPig42FLfYVbgr7JKJ7hY1Q7iq3tkkkIpLj1sxjm0TOLD4CC06I9rFJKGqidW9EjUhQCrGd33ergA7MqltYs6YCP9DldpA78aN2AZ7es5uc68BVL57Z7AvFLHnyE3-2BiYRej3Eg-2BkjZ9JyB4s-2F4sOp6rJ8M-3D" alt="" width="1" height="1" border="0" style="min-height:1px !important;width:1px !important;border-width:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote>
</div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=z0Ft8gvIaLt1zLwfkl4og6osLD9N8tlWJY1PY2zqWLUkHnPRqf22JfuLA5kPDXFPz8S7wT7SESan5AK-2BA-2F8xvy8No6VDuVOQrToOpIS1jKsflmvk861zymvyZDLaeAmh2bGY5Av42mn-2FxzfrwFx-2F7gO8nRl5f8mR4dSLpnAQIV-2FG-2FG9l5eYt5k5bLM4UlqqyInn9oqnAGfMS-2FStYfLW9ElxFJF6nrTW-2FSbOo3A-2BW6B0-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div></blockquote></div><br></div></div></div>                                            </div></body>
</html>