Blob Blame History Raw
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>cairomm: ps-surface.cc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">cairomm
   &#160;<span id="projectnumber">1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">ps-surface.cc</div>  </div>
</div><!--header-->
<div class="contents">
<p>An example of using <a class="el" href="classCairo_1_1PsSurface.html" title="A PsSurface provides a way to render PostScript documents from cairo. ">Cairo::PsSurface</a> class to render to PostScript</p>
<div class="fragment"><div class="line"><span class="comment">/* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,</span></div>
<div class="line"><span class="comment"> * et. al.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="preprocessor">#if defined(_MSC_VER)</span></div>
<div class="line"><span class="preprocessor">#define _USE_MATH_DEFINES</span></div>
<div class="line"><span class="preprocessor">#endif </span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cairommconfig.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cairomm/context.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cairomm/surface.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line"><span class="preprocessor">#ifdef CAIRO_HAS_PS_SURFACE</span></div>
<div class="line"></div>
<div class="line">    <a name="_a0"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00454.html">std::string</a> filename = <span class="stringliteral">&quot;image.ps&quot;</span>;</div>
<div class="line">    <span class="keywordtype">double</span> width = 600;</div>
<div class="line">    <span class="keywordtype">double</span> height = 400;</div>
<div class="line">    <span class="keyword">auto</span> surface =</div>
<div class="line">        <a name="a1"></a><a class="code" href="classCairo_1_1PsSurface.html#a0d7a34b58211563e2b1f2f4f85818e90">Cairo::PsSurface::create</a>(filename, width, height);</div>
<div class="line"></div>
<div class="line">    <span class="keyword">auto</span> cr = <a name="a2"></a><a class="code" href="classCairo_1_1Context.html#a9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface);</div>
<div class="line"></div>
<div class="line">    cr-&gt;save(); <span class="comment">// save the state of the context</span></div>
<div class="line">    cr-&gt;set_source_rgb(0.86, 0.85, 0.47);</div>
<div class="line">    cr-&gt;paint();    <span class="comment">// fill image with the color</span></div>
<div class="line">    cr-&gt;restore();  <span class="comment">// color is back to black now</span></div>
<div class="line"></div>
<div class="line">    cr-&gt;save();</div>
<div class="line">    <span class="comment">// draw a border around the image</span></div>
<div class="line">    cr-&gt;set_line_width(20.0);    <span class="comment">// make the line wider</span></div>
<div class="line">    cr-&gt;rectangle(0.0, 0.0, cairo_image_surface_get_width(surface-&gt;cobj()), height);</div>
<div class="line">    cr-&gt;stroke();</div>
<div class="line"></div>
<div class="line">    cr-&gt;set_source_rgba(0.0, 0.0, 0.0, 0.7);</div>
<div class="line">    <span class="comment">// draw a circle in the center of the image</span></div>
<div class="line">    cr-&gt;arc(width / 2.0, height / 2.0, </div>
<div class="line">            height / 4.0, 0.0, 2.0 * M_PI);</div>
<div class="line">    cr-&gt;stroke();</div>
<div class="line"></div>
<div class="line">    <span class="comment">// draw a diagonal line</span></div>
<div class="line">    cr-&gt;move_to(width / 4.0, height / 4.0);</div>
<div class="line">    cr-&gt;line_to(width * 3.0 / 4.0, height * 3.0 / 4.0);</div>
<div class="line">    cr-&gt;stroke();</div>
<div class="line">    cr-&gt;restore();</div>
<div class="line"></div>
<div class="line">    cr-&gt;show_page();</div>
<div class="line"></div>
<div class="line">    <a name="a3"></a>std::cout &lt;&lt; <span class="stringliteral">&quot;Wrote PostScript file \&quot;&quot;</span> &lt;&lt; filename &lt;&lt; <span class="stringliteral">&quot;\&quot;&quot;</span> &lt;&lt; <a name="a4"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01616.html#a8b3758bb8f17c440c7963363f42f69f3">std::endl</a>;</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#else</span></div>
<div class="line"></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;You must compile cairo with PS (Postscript) support for this example to work.&quot;</span></div>
<div class="line">        &lt;&lt; <a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01616.html#a8b3758bb8f17c440c7963363f42f69f3">std::endl</a>;</div>
<div class="line">    <span class="keywordflow">return</span> 1;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Mon Sep 21 2015 21:56:36 for cairomm by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.9.1
</small></address>
</body>
</html>