1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
<!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: pdf-surface.cc</title>
<link href="cairomm.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related 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="contents">
<h1>pdf-surface.cc</h1>An example of using <a class="el" href="classCairo_1_1PdfSurface.html" title="A PdfSurface provides a way to render PDF documents from cairo.">Cairo::PdfSurface</a> class to render to PDF<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00906.html">string</a>></span>
<span class="preprocessor">#include <<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00777.html">iostream</a>></span>
<span class="preprocessor">#include <cairommconfig.h></span>
<span class="preprocessor">#include <cairomm/context.h></span>
<span class="preprocessor">#include <cairomm/surface.h></span>
<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 <<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00667.html">cmath</a>></span>
<span class="keywordtype">int</span> main()
{
<span class="preprocessor">#ifdef CAIRO_HAS_PDF_SURFACE</span>
<span class="preprocessor"></span>
<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/a00218.html">std::string</a> filename = <span class="stringliteral">"image.pdf"</span>;
<span class="keywordtype">int</span> width = 600;
<span class="keywordtype">int</span> height = 400;
<a name="_a1"></a><a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::PdfSurface></a> surface =
<a name="a2"></a><a class="code" href="classCairo_1_1PdfSurface.html#92403fe5ad8ae6862e005c3d185e9123" title="Creates a PdfSurface with a specified dimensions that will be saved as the given...">Cairo::PdfSurface::create</a>(filename, width, height);
<a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::Context></a> cr = <a name="a3"></a><a class="code" href="classCairo_1_1Context.html#9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface);
cr->save(); <span class="comment">// save the state of the context</span>
cr->set_source_rgb(0.86, 0.85, 0.47);
cr->paint(); <span class="comment">// fill image with the color</span>
cr->restore(); <span class="comment">// color is back to black now</span>
cr->save();
<span class="comment">// draw a border around the image</span>
cr->set_line_width(20.0); <span class="comment">// make the line wider</span>
cr->rectangle(0.0, 0.0, cairo_image_surface_get_width(surface->cobj()), height);
cr->stroke();
cr->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->arc(width / 2.0, height / 2.0,
height / 4.0, 0.0, 2.0 * M_PI);
cr->stroke();
<span class="comment">// draw a diagonal line</span>
cr->move_to(width / 4.0, height / 4.0);
cr->line_to(width * 3.0 / 4.0, height * 3.0 / 4.0);
cr->stroke();
cr->restore();
cr->show_page();
<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/a00969.html#af93fdf0812752e0e02c501dea1b38f0">std::cout</a> << <span class="stringliteral">"Wrote PDF file \""</span> << filename << <span class="stringliteral">"\""</span> << <a name="a5"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00969.html#9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>;
<span class="keywordflow">return</span> 0;
<span class="preprocessor">#else</span>
<span class="preprocessor"></span>
<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00969.html#af93fdf0812752e0e02c501dea1b38f0">std::cout</a> << <span class="stringliteral">"You must compile cairo with PDF support for this example to work."</span>
<< std::endl;
<span class="keywordflow">return</span> 1;
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Aug 13 11:40:12 2009 for cairomm by 
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>
|