?? pango-cairo-rendering.html
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Cairo Rendering</title><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="index.html" title="Pango Reference Manual"><link rel="up" href="rendering.html" title="Rendering with Pango"><link rel="prev" href="pango-Xft-Fonts-and-Rendering.html" title="Xft Fonts and Rendering"><link rel="next" href="pango-ATSUI-Fonts.html" title="ATSUI Fonts"><meta name="generator" content="GTK-Doc V1.8 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="pango.html" title="Basic Pango Interfaces"><link rel="chapter" href="rendering.html" title="Rendering with Pango"><link rel="chapter" href="lowlevel.html" title="Low Level Functionality"><link rel="chapter" href="tools.html" title="Pango Tools"><link rel="chapter" href="pango-hierarchy.html" title="Object Hierarchy"><link rel="index" href="index-all.html" title="Index"><link rel="index" href="index-deprecated.html" title="Index of deprecated symbols"><link rel="index" href="index-1.2.html" title="Index of new symbols in 1.2"><link rel="index" href="index-1.4.html" title="Index of new symbols in 1.4"><link rel="index" href="index-1.6.html" title="Index of new symbols in 1.6"><link rel="index" href="index-1.8.html" title="Index of new symbols in 1.8"><link rel="index" href="index-1.10.html" title="Index of new symbols in 1.10"><link rel="index" href="index-1.12.html" title="Index of new symbols in 1.12"><link rel="index" href="index-1.14.html" title="Index of new symbols in 1.14"><link rel="index" href="index-1.16.html" title="Index of new symbols in 1.16"><link rel="index" href="index-1.18.html" title="Index of new symbols in 1.18"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="pango-Xft-Fonts-and-Rendering.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="rendering.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">Pango Reference Manual</th><td><a accesskey="n" href="pango-ATSUI-Fonts.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3225283" class="shortcut">Top</a>  |  <a href="#id3226198" class="shortcut">Description</a>  |  <a href="#id3226150" class="shortcut">Object Hierarchy</a>  |  <a href="#id3226176" class="shortcut">Prerequisites</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="pango-Cairo-Rendering"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3225283"></a><span class="refentrytitle">Cairo Rendering</span></h2><p>Cairo Rendering — Rendering with the Cairo backend</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><a name="PangoCairoFontMap"></a><pre class="synopsis"> <a href="pango-Cairo-Rendering.html#PangoCairoFont">PangoCairoFont</a>; <a href="pango-Cairo-Rendering.html#PangoCairoFontMap-struct">PangoCairoFontMap</a>;<a href="pango-Fonts.html#PangoFontMap">PangoFontMap</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-get-default">pango_cairo_font_map_get_default</a> (void);<a href="pango-Fonts.html#PangoFontMap">PangoFontMap</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-new">pango_cairo_font_map_new</a> (void);<a href="pango-Fonts.html#PangoFontMap">PangoFontMap</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-new-for-font-type">pango_cairo_font_map_new_for_font_type</a> (<ahref="../cairo/cairo-cairo-font-face-t.html#cairo-font-type-t">cairo_font_type_t</a> fonttype);<ahref="../cairo/cairo-cairo-font-face-t.html#cairo-font-type-t">cairo_font_type_t</a> <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-get-font-type">pango_cairo_font_map_get_font_type</a> (<a href="pango-Cairo-Rendering.html#PangoCairoFontMap">PangoCairoFontMap</a> *fontmap);void <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-set-resolution">pango_cairo_font_map_set_resolution</a> (<a href="pango-Cairo-Rendering.html#PangoCairoFontMap">PangoCairoFontMap</a> *fontmap, double dpi);double <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-get-resolution">pango_cairo_font_map_get_resolution</a> (<a href="pango-Cairo-Rendering.html#PangoCairoFontMap">PangoCairoFontMap</a> *fontmap);<a href="pango-Text-Processing.html#PangoContext">PangoContext</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-create-context">pango_cairo_font_map_create_context</a> (<a href="pango-Cairo-Rendering.html#PangoCairoFontMap">PangoCairoFontMap</a> *fontmap);<ahref="../cairo/cairo-Scaled-Fonts.html#cairo-scaled-font-t">cairo_scaled_font_t</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-font-get-scaled-font">pango_cairo_font_get_scaled_font</a> (<a href="pango-Cairo-Rendering.html#PangoCairoFont">PangoCairoFont</a> *font);void <a href="pango-Cairo-Rendering.html#pango-cairo-context-set-resolution">pango_cairo_context_set_resolution</a> (<a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context, double dpi);double <a href="pango-Cairo-Rendering.html#pango-cairo-context-get-resolution">pango_cairo_context_get_resolution</a> (<a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context);void <a href="pango-Cairo-Rendering.html#pango-cairo-context-set-font-options">pango_cairo_context_set_font_options</a> (<a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context, const <ahref="../cairo/cairo-Font-Options.html#cairo-font-options-t">cairo_font_options_t</a> *options);const <ahref="../cairo/cairo-Font-Options.html#cairo-font-options-t">cairo_font_options_t</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-context-get-font-options">pango_cairo_context_get_font_options</a> (<a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context);void (<a href="pango-Cairo-Rendering.html#PangoCairoShapeRendererFunc">*PangoCairoShapeRendererFunc</a>) (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Text-Attributes.html#PangoAttrShape">PangoAttrShape</a> *attr, <ahref="../glib/glib-Basic-Types.html#gboolean">gboolean</a> do_path, <ahref="../glib/glib-Basic-Types.html#gpointer">gpointer</a> data);void <a href="pango-Cairo-Rendering.html#pango-cairo-context-set-shape-renderer">pango_cairo_context_set_shape_renderer</a> (<a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context, <a href="pango-Cairo-Rendering.html#PangoCairoShapeRendererFunc">PangoCairoShapeRendererFunc</a> func, <ahref="../glib/glib-Basic-Types.html#gpointer">gpointer</a> data, <ahref="../glib/glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> dnotify);<a href="pango-Cairo-Rendering.html#PangoCairoShapeRendererFunc">PangoCairoShapeRendererFunc</a> <a href="pango-Cairo-Rendering.html#pango-cairo-context-get-shape-renderer">pango_cairo_context_get_shape_renderer</a> (<a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context, <ahref="../glib/glib-Basic-Types.html#gpointer">gpointer</a> *data);void <a href="pango-Cairo-Rendering.html#pango-cairo-update-context">pango_cairo_update_context</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Text-Processing.html#PangoContext">PangoContext</a> *context);<a href="pango-Layout-Objects.html#PangoLayout">PangoLayout</a>* <a href="pango-Cairo-Rendering.html#pango-cairo-create-layout">pango_cairo_create_layout</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr);void <a href="pango-Cairo-Rendering.html#pango-cairo-update-layout">pango_cairo_update_layout</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Layout-Objects.html#PangoLayout">PangoLayout</a> *layout);void <a href="pango-Cairo-Rendering.html#pango-cairo-show-glyph-string">pango_cairo_show_glyph_string</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Fonts.html#PangoFont">PangoFont</a> *font, <a href="pango-Glyph-Storage.html#PangoGlyphString">PangoGlyphString</a> *glyphs);void <a href="pango-Cairo-Rendering.html#pango-cairo-show-layout-line">pango_cairo_show_layout_line</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Layout-Objects.html#PangoLayoutLine">PangoLayoutLine</a> *line);void <a href="pango-Cairo-Rendering.html#pango-cairo-show-layout">pango_cairo_show_layout</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Layout-Objects.html#PangoLayout">PangoLayout</a> *layout);void <a href="pango-Cairo-Rendering.html#pango-cairo-show-error-underline">pango_cairo_show_error_underline</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, double x, double y, double width, double height);void <a href="pango-Cairo-Rendering.html#pango-cairo-glyph-string-path">pango_cairo_glyph_string_path</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Fonts.html#PangoFont">PangoFont</a> *font, <a href="pango-Glyph-Storage.html#PangoGlyphString">PangoGlyphString</a> *glyphs);void <a href="pango-Cairo-Rendering.html#pango-cairo-layout-line-path">pango_cairo_layout_line_path</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Layout-Objects.html#PangoLayoutLine">PangoLayoutLine</a> *line);void <a href="pango-Cairo-Rendering.html#pango-cairo-layout-path">pango_cairo_layout_path</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, <a href="pango-Layout-Objects.html#PangoLayout">PangoLayout</a> *layout);void <a href="pango-Cairo-Rendering.html#pango-cairo-error-underline-path">pango_cairo_error_underline_path</a> (<ahref="../cairo/cairo-cairo-t.html#cairo-t">cairo_t</a> *cr, double x, double y, double width, double height);</pre></div><div class="refsect1" lang="en"><a name="id3226150"></a><h2>Object Hierarchy</h2><pre class="synopsis"> GInterface +----PangoCairoFontMap</pre></div><div class="refsect1" lang="en"><a name="id3226176"></a><h2>Prerequisites</h2><p>PangoCairoFontMap requires <a href="pango-Fonts.html#PangoFontMap">PangoFontMap</a>.</p></div><div class="refsect1" lang="en"><a name="id3226198"></a><h2>Description</h2><p>The <a href="http://cairographics.org" target="_top">Cairo library</a> is avector graphics library with a powerful rendering model. It has suchfeatures as anti-aliased primitives, alpha-compositing, andgradients. Multiple backends for Cairo are available, to allowrendering to images, to PDF files, and to the screen on X and on otherwindowing systems. The functions in this section allow using Pangoto render to Cairo surfaces.</p><p>Using Pango with Cairo is straightforward. A <a href="pango-Text-Processing.html#PangoContext"><span class="type">PangoContext</span></a> createdwith <a href="pango-Cairo-Rendering.html#pango-cairo-font-map-create-context"><code class="function">pango_cairo_font_map_create_context()</code></a> can be used on anyCairo context (cairo_t), but needs to be updated to match thecurrent transformation matrix and target surface of the Cairo contextusing <a href="pango-Cairo-Rendering.html#pango-cairo-update-context"><code class="function">pango_cairo_update_context()</code></a>. The convenience functions<a href="pango-Cairo-Rendering.html#pango-cairo-create-layout"><code class="function">pango_cairo_create_layout()</code></a> and <a href="pango-Cairo-Rendering.html#pango-cairo-update-layout"><code class="function">pango_cairo_update_layout()</code></a> handlethe common case where the program doesn't need to manipulate theproperties of the <a href="pango-Text-Processing.html#PangoContext"><span class="type">PangoContext</span></a>.</p><p>When you get the metrics of a layout or of a piece of a layout usingfunctions such as <a href="pango-Layout-Objects.html#pango-layout-get-extents"><code class="function">pango_layout_get_extents()</code></a>, the reported metricsare in user-space coordinates. If a piece of text is 10 units long,and you call cairo_scale (cr, 2.0), it still is more-or-less 10units long. However, the results will be affected by hinting(that is, the process of adjusting the text to look good on thepixel grid), so you shouldn't assume they are completely independentof the current transformation matrix. Note that the basic metricsfunctions in Pango report results in integer Pango units. To getto the floating point units used in Cairo divide by <a href="pango-Glyph-Storage.html#PANGO-SCALE:CAPS"><code class="literal">PANGO_SCALE</code></a>.</p><div class="example"><a name="rotated-example"></a><p class="title"><b>Example 1. Using Pango with Cairo</b></p><div class="example-contents"><pre class="programlisting">#include <math.h>#include <pango/pangocairo.h>static voiddraw_text (cairo_t *cr){#define RADIUS 150#define N_WORDS 10#define FONT "Sans Bold 27" PangoLayout *layout; PangoFontDescription *desc; int i; /* Center coordinates on the middle of the region we are drawing */ cairo_translate (cr, RADIUS, RADIUS); /* Create a PangoLayout, set the font and text */ layout = pango_cairo_create_layout (cr); pango_layout_set_text (layout, "Text", -1); desc = pango_font_description_from_string (FONT); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); /* Draw the layout N_WORDS times in a circle */ for (i = 0; i < N_WORDS; i++) { int width, height; double angle = (360. * i) / N_WORDS; double red; cairo_save (cr); /* Gradient from red at angle == 60 to blue at angle == 240 */ red = (1 + cos ((angle - 60) * G_PI / 180.)) / 2; cairo_set_source_rgb (cr, red, 0, 1.0 - red); cairo_rotate (cr, angle * G_PI / 180.); /* Inform Pango to re-layout the text with the new transformation */ pango_cairo_update_layout (cr, layout); pango_layout_get_size (layout, &width, &height); cairo_move_to (cr, - ((double)width / PANGO_SCALE) / 2, - RADIUS); pango_cairo_show_layout (cr, layout); cairo_restore (cr); } /* free the layout object */ g_object_unref (layout);}int main (int argc, char **argv){ cairo_t *cr; char *filename; cairo_status_t status; cairo_surface_t *surface; if (argc != 2) { g_printerr ("Usage: cairosimple OUTPUT_FILENAME\n"); return 1; } filename = argv[1]; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 2 * RADIUS, 2 * RADIUS); cr = cairo_create (surface); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_paint (cr); draw_text (cr); cairo_destroy (cr); status = cairo_surface_write_to_png (surface, filename); cairo_surface_destroy (surface); if (status != CAIRO_STATUS_SUCCESS) { g_printerr ("Could not save png to '%s'\n", filename); return 1; } return 0;}</pre></div></div><br class="example-break"><div class="figure"><a name="rotated-example-output"></a><p class="title"><b>Figure 2. Output of <a href="pango-Cairo-Rendering.html#rotated-example" title="Example 1. Using Pango with Cairo">Example 1, “Using Pango with Cairo”</a></b></p><div class="figure-contents"><div><img src="rotated-text.png" alt="Output of"></div></div></div><br class="figure-break"></div><div class="refsect1" lang="en"><a name="id3226458"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3226468"></a><h3><a name="PangoCairoFont"></a>PangoCairoFont</h3><a class="indexterm" name="id3226483"></a><pre class="programlisting">typedef struct _PangoCairoFont PangoCairoFont;</pre><p><a href="pango-Cairo-Rendering.html#PangoCairoFont"><span class="type">PangoCairoFont</span></a> is an interface exported by fonts foruse with Cairo. The actual type of the font will dependon the particular font technology Cairo was compiled to use.</p><p></p><p class="since">Since 1.18</p></div><hr><div class="refsect2" lang="en">
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -