<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">It’s deceptively simple!<div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">However, bridging the C has some nasty effects to the types of your Swift code. For example, <font face="Menlo" class="">surface</font> is of type <font face="Menlo" class="">COpaquePointer </font>which is really unhelpful.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Like this, except with an actual understanding of libcairo: <a href="https://gist.github.com/6b96a1e0ec1ef838b5ea" class="">https://gist.github.com/6b96a1e0ec1ef838b5ea</a></div><div class=""><br class=""></div><div class="">Best,</div><div class="">Harlan</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 11, 2015, at 3:31 PM, Gage Morgan <<a href="mailto:gagemorgan@outlook.com" class="">gagemorgan@outlook.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Sir, you've just made my day. So it's really that simple?<br class=""><br class=""><div class=""><hr id="stopSpelling" class="">Subject: Re: [swift-users] Need Help with C-to-Swift (finally)<br class="">From:<span class="Apple-converted-space"> </span><a href="mailto:harlan@harlanhaskins.com" class="">harlan@harlanhaskins.com</a><br class="">Date: Fri, 11 Dec 2015 15:24:48 -0500<br class="">CC:<span class="Apple-converted-space"> </span><a href="mailto:jason.dusek@gmail.com" class="">jason.dusek@gmail.com</a>;<span class="Apple-converted-space"> </span><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">To:<span class="Apple-converted-space"> </span><a href="mailto:gagemorgan@outlook.com" class="">gagemorgan@outlook.com</a><br class=""><br class="">So, it’s a very simple almost one-to-one translation of that C code block to Swift.<div class="">You have to make sure to<span class="Apple-converted-space"> </span><font face="Menlo" class="">import CCairo</font> at the beginning of the file, and change the variable declarations to use<span class="Apple-converted-space"> </span><font face="Menlo" class="">let</font> instead of the C declaration.</div><div class=""><br class=""></div><div class="">This works for me, as is.<br class=""><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">import CCairo</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">let surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80)</font></div><div class=""><font face="Menlo" class="">let cr = cairo_create (surface);</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)</font></div><div class=""><font face="Menlo" class="">cairo_set_font_size(cr, 32.0)</font></div><div class=""><font face="Menlo" class="">cairo_set_source_rgb(cr, 0.0, 0.0, 1.0)</font></div><div class=""><font face="Menlo" class="">cairo_move_to(cr, 10.0, 50.0)</font></div><div class=""><font face="Menlo" class="">cairo_show_text(cr, "Hello, world")</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">cairo_destroy(cr)</font></div><div class=""><font face="Menlo" class="">cairo_surface_write_to_png(surface, "hello.png")</font></div><div class=""><font face="Menlo" class="">cairo_surface_destroy(surface)</font></div><div class=""><br class=""></div><div class=""><blockquote class=""><div class="">On Dec 11, 2015, at 3:21 PM, Gage Morgan <<a href="mailto:gagemorgan@outlook.com" class="">gagemorgan@outlook.com</a>> wrote:</div><br class="ecxApple-interchange-newline"><div class=""><div class=""><div class="">Do so here in a few. Want a bug report for that?<br class=""><br class=""><div class="ecxacompli_signature">Sent from<span class="Apple-converted-space"> </span><a href="https://aka.ms/qtex0l" target="_blank" class="">Outlook Mobile</a></div><br class=""></div><br class=""><br class=""><br class=""><div class="ecxgmail_quote">On Fri, Dec 11, 2015 at 12:08 PM -0800, "Harlan Haskins"<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:harlan@harlanhaskins.com" target="_blank" class="">harlan@harlanhaskins.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><br class=""></div><div style="word-wrap: break-word;" class="">Mind sending your CCairo modulemap?<div class=""><br class=""></div><div class="">I’d love to help you get this translated to Swift.</div><div class=""><br class=""><div class=""><blockquote class=""><div class="">On Dec 11, 2015, at 2:44 PM, Gage Morgan via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="ecxx_Apple-interchange-newline"><div class=""><div class=""><div class="">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 class=""><br class=""></div><div class="">My goal is to generate an executable that outputs *.png images using swift. </div><div class=""><br class=""></div><div class="">Thanks for the support,</div><div class="">--MGage--<br class=""><br class=""><div class="ecxx_acompli_signature">Sent from<span class="Apple-converted-space"> </span><a href="https://aka.ms/qtex0l" target="_blank" class="">Outlook Mobile</a></div><br class=""></div><br class=""><br class=""><br class=""><div class="ecxx_gmail_quote">On Thu, Dec 10, 2015 at 10:40 PM -0800, "Jason Dusek"<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:jason.dusek@gmail.com" target="_blank" class="">jason.dusek@gmail.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><br class=""></div><div class=""><div dir="ltr" class="">When you say, output to Swift, do you mean, call it from Swift? Return the PNG or surface to Swift?</div><br class=""><div class="ecxx_x_gmail_quote"><div dir="ltr" class="">On Thu, 10 Dec 2015 at 22:39 Gage Morgan via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""></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 class=""><div dir="ltr" class="">So, if I had this code written in C:<div class=""><br class=""></div><div class=""><pre style="font-family: mono; border: 1px solid rgb(197, 197, 246); padding: 0.5em; font-size: inherit; background-color: rgb(219, 219, 247);" class=""><code class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></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;" class=""></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></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;" class=""></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">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 class=""></div></body></html>