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
|
<!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: toy-text.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>toy-text.cc</h1>A relatively simple example of using <a class="el" href="classCairo_1_1ToyFontFace.html" title="A simple font face used for the cairo 'toy' font API.">Cairo::ToyFontFace</a><p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <cairomm/cairomm.h></span>
<span class="keyword">const</span> <span class="keywordtype">double</span> HEIGHT = 200.0;
<span class="keyword">const</span> <span class="keywordtype">double</span> WIDTH = 400.0;
<span class="keyword">const</span> <span class="keywordtype">double</span> FONT_SIZE = 64.0;
<span class="keyword">const</span> <span class="keywordtype">double</span> TEXT_ORIGIN_Y = (HEIGHT / 2.0) + (FONT_SIZE / 2.0);
<span class="keyword">const</span> <span class="keywordtype">double</span> TEXT_ORIGIN_X = 50.0; <span class="comment">// arbitrary</span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span>, <span class="keywordtype">char</span>**)
{
<a name="_a0"></a><a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::ImageSurface></a> surface =
<a name="a1"></a><a class="code" href="classCairo_1_1ImageSurface.html#82887e1a0480ab16aa891e135f2b28d6" title="Creates an image surface of the specified format and dimensions.">Cairo::ImageSurface::create</a>(<a name="a2"></a><a class="code" href="namespaceCairo.html#d3f86970e1bd354b263303c9b8759166fc97f1888578477fd656cf72d3421fbc">Cairo::FORMAT_ARGB32</a>, 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);
<span class="comment">// fill background in white</span>
cr->set_source_rgb(1.0, 1.0, 1.0);
cr->paint();
<span class="comment">// draw a little dot at the point where text will be drawn</span>
cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2*M_PI);
cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
cr->fill();
<span class="comment">// draw the text</span>
cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
cr->set_source_rgb(0.8, 0.2, 0.2);
<a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::ToyFontFace></a> font =
<a name="a4"></a><a class="code" href="classCairo_1_1ToyFontFace.html#07c0ca7fd0dc54c31bfa1d8a813aff59" title="Creates a font face from a triplet of family, slant, and weight.">Cairo::ToyFontFace::create</a>(<span class="stringliteral">"Bitstream Charter"</span>,
<a name="a5"></a><a class="code" href="namespaceCairo.html#0a2c19fefac301a702a6b7fdb368bf55ffa4510656348999982452cab35cd50d">Cairo::FONT_SLANT_ITALIC</a>,
<a name="a6"></a><a class="code" href="namespaceCairo.html#d8514818fb9292a5864b57f4b8a1e546438bd2ac850ef23ce7a537ae3395f398">Cairo::FONT_WEIGHT_BOLD</a>);
cr->set_font_face(font);
cr->set_font_size(FONT_SIZE);
cr->show_text(<span class="stringliteral">"cairomm!"</span>);
surface->write_to_png(<span class="stringliteral">"toy-text.png"</span>);
<span class="keywordflow">return</span> 0;
}
</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>
|