<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'>Could you put some comments explaining what you did in that code? I wouldn't mind learning to write some wrappers...it's inevitable in the end anyways.<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:46:21 -0500<br>CC: jason.dusek@gmail.com; swift-users@swift.org<br>To: gagemorgan@outlook.com<br><br>It’s deceptively simple!<div><br></div><div>Using just the functions exposed by cairo will be a piece of cake. The code will look almost exactly the same and work just as fast/well.</div><div><br></div><div>However, bridging the C has some nasty effects to the types of your Swift code. For example, <font face="Menlo">surface</font>&nbsp;is of type&nbsp;<font face="Menlo">COpaquePointer </font>which is really unhelpful.</div><div><br></div><div>It’d probably be a great exercise for you and the community to make nice, Swifty wrappers around Cairo to allow people to write beautiful, Cairo-using code.</div><div><br></div><div>Like this, except with an actual understanding of libcairo:&nbsp;<a href="https://gist.github.com/6b96a1e0ec1ef838b5ea" target="_blank">https://gist.github.com/6b96a1e0ec1ef838b5ea</a></div><div><br></div><div>Best,</div><div>Harlan</div><div><br></div><div><br><div><blockquote><div>On Dec 11, 2015, at 3:31 PM, Gage Morgan &lt;<a href="mailto:gagemorgan@outlook.com">gagemorgan@outlook.com</a>&gt; wrote:</div><br class="ecxApple-interchange-newline"><div><div dir="ltr" style="font-family:Calibri;font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">Sir, you've just made my day. So it's really that simple?<br><br><div><hr id="ecxstopSpelling">Subject: Re: [swift-users] Need Help with C-to-Swift (finally)<br>From:<span class="ecxApple-converted-space">&nbsp;</span><a href="mailto:harlan@harlanhaskins.com">harlan@harlanhaskins.com</a><br>Date: Fri, 11 Dec 2015 15:24:48 -0500<br>CC:<span class="ecxApple-converted-space">&nbsp;</span><a href="mailto:jason.dusek@gmail.com">jason.dusek@gmail.com</a>;<span class="ecxApple-converted-space">&nbsp;</span><a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>To:<span class="ecxApple-converted-space">&nbsp;</span><a href="mailto:gagemorgan@outlook.com">gagemorgan@outlook.com</a><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<span class="ecxApple-converted-space">&nbsp;</span><font face="Menlo">import&nbsp;CCairo</font>&nbsp;at the beginning of the file, and change the variable declarations to use<span class="ecxApple-converted-space">&nbsp;</span><font face="Menlo">let</font>&nbsp;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 &lt;<a href="mailto:gagemorgan@outlook.com">gagemorgan@outlook.com</a>&gt; 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<span class="ecxApple-converted-space">&nbsp;</span><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 class="ecxApple-converted-space">&nbsp;</span><span dir="ltr">&lt;<a href="mailto:harlan@harlanhaskins.com" target="_blank">harlan@harlanhaskins.com</a>&gt;</span><span class="ecxApple-converted-space">&nbsp;</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 &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; 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.&nbsp;</div><div><br></div><div>My goal is to generate an executable that outputs *.png images using swift.&nbsp;</div><div><br></div><div>Thanks for the support,</div><div>--MGage--<br><br><div class="ecxx_acompli_signature">Sent from<span class="ecxApple-converted-space">&nbsp;</span><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 class="ecxApple-converted-space">&nbsp;</span><span dir="ltr">&lt;<a href="mailto:jason.dusek@gmail.com" target="_blank">jason.dusek@gmail.com</a>&gt;</span><span class="ecxApple-converted-space">&nbsp;</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 &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br></div><blockquote class="ecxx_x_gmail_quote" style="border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style: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:0px !important;padding:0px !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:0px !important;padding:0px !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></div></blockquote></div></div></div></div></div></blockquote></div></div></div></div></div></div></blockquote></div><br></div></div>                                               </div></body>
</html>