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: toy-text.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">toy-text.cc</div>  </div>
</div><!--header-->
<div class="contents">
<p>A relatively simple example of using <a class="el" href="classCairo_1_1ToyFontFace.html" title="A simple font face used for the cairo &#39;toy&#39; font API. ">Cairo::ToyFontFace</a></p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;cairomm/cairomm.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">double</span> HEIGHT = 200.0;</div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">double</span> WIDTH = 400.0;</div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">double</span> FONT_SIZE = 64.0;</div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">double</span> TEXT_ORIGIN_Y = (HEIGHT / 2.0) + (FONT_SIZE / 2.0);</div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">double</span> TEXT_ORIGIN_X = 50.0;  <span class="comment">// arbitrary</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>**)</div>
<div class="line">{</div>
<div class="line">  <span class="keyword">auto</span> surface =</div>
<div class="line">    <a name="a0"></a><a class="code" href="classCairo_1_1ImageSurface.html#a82887e1a0480ab16aa891e135f2b28d6">Cairo::ImageSurface::create</a>(<a name="a1"></a><a class="code" href="namespaceCairo.html#ad3f86970e1bd354b263303c9b8759166afc97f1888578477fd656cf72d3421fbc">Cairo::FORMAT_ARGB32</a>, WIDTH, HEIGHT);</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">  <span class="comment">// fill background in white</span></div>
<div class="line">  cr-&gt;set_source_rgb(1.0, 1.0, 1.0);</div>
<div class="line">  cr-&gt;paint();</div>
<div class="line"></div>
<div class="line">  <span class="comment">// draw a little dot at the point where text will be drawn</span></div>
<div class="line">  cr-&gt;arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2*M_PI);</div>
<div class="line">  cr-&gt;set_source_rgba(0.0, 1.0, 0.0, 0.5);</div>
<div class="line">  cr-&gt;fill();</div>
<div class="line"></div>
<div class="line">  <span class="comment">// draw the text</span></div>
<div class="line">  cr-&gt;move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);</div>
<div class="line">  cr-&gt;set_source_rgb(0.8, 0.2, 0.2);</div>
<div class="line">  <span class="keyword">auto</span> font =</div>
<div class="line">    <a name="a3"></a><a class="code" href="classCairo_1_1ToyFontFace.html#a07c0ca7fd0dc54c31bfa1d8a813aff59">Cairo::ToyFontFace::create</a>(<span class="stringliteral">&quot;Bitstream Charter&quot;</span>,</div>
<div class="line">                               <a name="a4"></a><a class="code" href="namespaceCairo.html#a0a2c19fefac301a702a6b7fdb368bf55affa4510656348999982452cab35cd50d">Cairo::FONT_SLANT_ITALIC</a>,</div>
<div class="line">                               <a name="a5"></a><a class="code" href="namespaceCairo.html#ad8514818fb9292a5864b57f4b8a1e546a438bd2ac850ef23ce7a537ae3395f398">Cairo::FONT_WEIGHT_BOLD</a>);</div>
<div class="line">  cr-&gt;set_font_face(font);</div>
<div class="line">  cr-&gt;set_font_size(FONT_SIZE);</div>
<div class="line">  cr-&gt;show_text(<span class="stringliteral">&quot;cairomm!&quot;</span>);</div>
<div class="line">  surface-&gt;write_to_png(<span class="stringliteral">&quot;toy-text.png&quot;</span>);</div>
<div class="line">  <span class="keywordflow">return</span> 0;</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>