Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 2a38b732199ac205772f2322bdd57a78 > files > 224

lib64cairomm1.0-devel-1.10.0-3.mga4.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
        <title>cairomm: ps-surface.cc</title>
        <link href="cairomm.css" rel="stylesheet" type="text/css">
    </head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
  <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>
<div class="header">
  <div class="headertitle">
<h1>ps-surface.cc</h1> </div>
</div>
<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"><pre class="fragment"><span class="comment">/* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,</span>
<span class="comment"> * et. al.</span>
<span class="comment"> */</span>
<span class="preprocessor">#if defined(_MSC_VER)</span>
<span class="preprocessor"></span><span class="preprocessor">#define _USE_MATH_DEFINES</span>
<span class="preprocessor"></span><span class="preprocessor">#endif </span>
<span class="preprocessor"></span>
<span class="preprocessor">#include &lt;string&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;cairommconfig.h&gt;</span>
<span class="preprocessor">#include &lt;cairomm/context.h&gt;</span>
<span class="preprocessor">#include &lt;cairomm/surface.h&gt;</span>

<span class="preprocessor">#include &lt;cmath&gt;</span>

<span class="keywordtype">int</span> main()
{
<span class="preprocessor">#ifdef CAIRO_HAS_PS_SURFACE</span>
<span class="preprocessor"></span>
    <a name="_a0"></a><a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00254.html">std::string</a> filename = <span class="stringliteral">&quot;image.ps&quot;</span>;
    <span class="keywordtype">double</span> width = 600;
    <span class="keywordtype">double</span> height = 400;
    <a name="_a1"></a><a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&amp;lt;&amp;gt; is a reference-counting shared smartpointer.">Cairo::RefPtr&lt;Cairo::PsSurface&gt;</a> surface =
        <a name="a2"></a><a class="code" href="classCairo_1_1PsSurface.html#a0d7a34b58211563e2b1f2f4f85818e90" title="Creates a PsSurface with a specified dimensions that will be saved as the given filename.">Cairo::PsSurface::create</a>(filename, width, height);

    <a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&amp;lt;&amp;gt; is a reference-counting shared smartpointer.">Cairo::RefPtr&lt;Cairo::Context&gt;</a> cr = <a name="a3"></a><a class="code" href="classCairo_1_1Context.html#a9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface);

    cr-&gt;save(); <span class="comment">// save the state of the context</span>
    cr-&gt;set_source_rgb(0.86, 0.85, 0.47);
    cr-&gt;paint(); <span class="comment">// fill image with the color</span>
    cr-&gt;restore(); <span class="comment">// color is back to black now</span>

    cr-&gt;save();
    <span class="comment">// draw a border around the image</span>
    cr-&gt;set_line_width(20.0); <span class="comment">// make the line wider</span>
    cr-&gt;rectangle(0.0, 0.0, cairo_image_surface_get_width(surface-&gt;cobj()), height);
    cr-&gt;stroke();

    cr-&gt;set_source_rgba(0.0, 0.0, 0.0, 0.7);
    <span class="comment">// draw a circle in the center of the image</span>
    cr-&gt;arc(width / 2.0, height / 2.0,             height / 4.0, 0.0, 2.0 * M_PI);
    cr-&gt;stroke();

    <span class="comment">// draw a diagonal line</span>
    cr-&gt;move_to(width / 4.0, height / 4.0);
    cr-&gt;line_to(width * 3.0 / 4.0, height * 3.0 / 4.0);
    cr-&gt;stroke();
    cr-&gt;restore();

    cr-&gt;show_page();

    <a name="a4"></a><a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#aaf93fdf0812752e0e02c501dea1b38f0">std::cout</a> &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="a5"></a><a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#a9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>;
    <span class="keywordflow">return</span> 0;

<span class="preprocessor">#else</span>
<span class="preprocessor"></span>
    <a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#aaf93fdf0812752e0e02c501dea1b38f0">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;You must compile cairo with PS (Postscript) support for this example to work.&quot;</span>
        &lt;&lt; <a class="codeRef" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01136.html#a9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>;
    <span class="keywordflow">return</span> 1;

<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>}
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Mon May 9 2011 09:51:07 for cairomm by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>