summaryrefslogtreecommitdiff
path: root/docs/reference/pygtk-gdkpangorenderer.xml
blob: df7293525936deb8b5ccc04ef5ecf7dd5055bd84 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?xml version="1.0" standalone="no"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">

<refentry id="class-gdkpangorenderer">
  <refnamediv>
    <refname>gtk.gdk.PangoRenderer</refname>
    <refpurpose>an object providing use of Pango in GDK (new in PyGTK
2.8)</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Synopsis</title>

<classsynopsis language="python">
  <ooclass><classname>gtk.gdk.PangoRenderer</classname></ooclass>
  <ooclass><classname><link linkend="class-pangorenderer">pango.Renderer</link></classname></ooclass>
<constructorsynopsis language="python">
    <methodname>pango.Renderer</methodname>
    <methodparam><parameter role="keyword">screen</parameter><initializer>None</initializer></methodparam>
  </constructorsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gdkpangorenderer--set-drawable">set_drawable</link></methodname>
    <methodparam><parameter role="keyword">drawable</parameter></methodparam>
  </methodsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gdkpangorenderer--set-gc">set_gc</link></methodname>
    <methodparam><parameter role="keyword">gc</parameter></methodparam>
  </methodsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gdkpangorenderer--set-stipple">set_stipple</link></methodname>
    <methodparam><parameter role="keyword">part</parameter></methodparam>
    <methodparam><parameter role="keyword">stipple</parameter></methodparam>
  </methodsynopsis>
<methodsynopsis language="python">
    <methodname><link linkend="method-gdkpangorenderer--set-override-color">set_override_color</link></methodname>
    <methodparam><parameter role="keyword">part</parameter></methodparam>
    <methodparam><parameter role="keyword">color</parameter></methodparam>
  </methodsynopsis>
</classsynopsis>

<programlisting>
<emphasis role="bold">Functions</emphasis>

<methodsynopsis language="python">
    <methodname><link linkend="function-gdk--gdk-pango-renderer-get-default">gtk.gdk.gdk_pango_renderer_get_default</link></methodname>
    <methodparam><parameter role="keyword">screen</parameter></methodparam>
  </methodsynopsis></programlisting>

</refsect1>

  <refsect1>
    <title>Ancestry</title>

<synopsis>+-- <link linkend="class-gobject">gobject.GObject</link>
  +-- <link linkend="class-pangorenderer">pango.Renderer</link>
    +-- <link linkend="class-gdkpangorenderer">gtkgdk.PangoRenderer</link>
</synopsis>

  </refsect1>

  <refsect1>
    <title>Properties</title>

    <blockquote role="properties">
      <informaltable pgwide="1" frame="none">
	<tgroup cols="3">
	  <colspec column="1" colwidth="1in"/>
	  <colspec column="2" colwidth="1in"/>
	  <colspec column="3" colwidth="4in"/>
	  <tbody>

	    <row valign="top">
	      <entry>"screen"</entry>
	      <entry>Read-Write-Construct Only</entry>
	      <entry>The <link
linkend="class-gdkscreen"><classname>gtk.gdk.Screen</classname></link>
for the renderer. Available in GTK+ 2.8 and above.</entry>
	    </row>

	  </tbody>
	</tgroup>
      </informaltable>
    </blockquote>

  </refsect1>

  <refsect1>
    <title>Description</title>

    <para>Pango is the text layout system used by PyGTK (via GDK and
GTK+). The functions and types in this section are used to render Pango
objects to <link
linkend="class-gdkdrawable"><classname>gtk.gdk.Drawable</classname></link>
objects, and also extend the set of Pango attributes to include stippling
and embossing.</para>

    <para>Creating a <link
linkend="class-pangolayout"><classname>pango.Layout</classname></link>
object is the first step in rendering text, and requires getting a handle to
a <link
linkend="class-pangocontext"><classname>pango.Context</classname></link>.
For PyGTK programs, you'll usually want to use the <link
linkend="method-gtkwidget--get-pango-context"><methodname>gtk.Widget.get_pango_context</methodname>()</link>
method, or the <link
linkend="method-gtkwidget--create-pango-layout"><methodname>create_pango_layout</methodname>()</link>)
method, rather than using the lowlevel <link
linkend="function-gdk--gdk-pango-context-get-for-screen"><function>gtk.gdk.gdk_pango_context_get_for_screen</function>()</link>
function. Once you have a <link
linkend="class-pangolayout"><classname>pango.Layout</classname></link>, you
can set the text and attributes of it with Pango methods like <link
linkend="method-pangolayout--set-text"><methodname>pango.Layout.set_text</methodname>()</link>
and get its size using the <link
linkend="method-pangolayout--get-size"><methodname>get_size</methodname>()</link>
method. (Note that Pango uses a fixed point system internally, so convert
between Pango units and pixels using <literal>pango.SCALE</literal> or the
<link
linkend="function-pango--PIXELS"><function>pango.PIXELS</function>()</link>
function.)</para>

    <para>Rendering a Pango layout is done most simply with the <link
linkend="method-gdkdrawable--draw-layout"><methodname>draw_layout</methodname>()</link>
method; you can also draw pieces of the layout with the <link
linkend="method-gdkdrawable--draw-layout"><methodname>draw_layout</methodname>()</link>
method or the <link
linkend="method-gdkdrawable--draw-glyphs"><methodname>draw_glyphs</methodname>()</link>
method.</para>

    <para><link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
is a subclass of <link
linkend="class-pangorenderer"><classname>pango.Renderer</classname></link>
that is used internally to implement these functions. Using it directly or
subclassing it can be useful in some cases. The default renderer for a
particular screen is obtained with the <link
linkend="function-gdk--gdk-pango-renderer-get-default"><function>gtk.gdk.gdk_pango_renderer_get_default</function>()</link>
function. Pango methods like <link
linkend="method-pangorenderer--draw-layout"><methodname>pango.Renderer.draw_layout</methodname>()</link>
and <link
linkend="method-pangorenderer--draw-layout-line"><methodname>pango.Renderer.draw_layout_line</methodname>()</link>
are then used to draw objects with the renderer.</para>

    <para>In most simple cases, applications can just use the <link
linkend="method-gdkdrawable--draw-layout"><methodname>draw_layout</methodname>()</link>
method, and don't need to directly use <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
at all. Using the <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
directly is most useful when working with a transformation such as a
rotation, because the Pango drawing functions take user space coordinates
(coordinates before the transformation) instead of device
coordinates.</para>

    <para>In certain cases it can be useful to subclass <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>. Examples
of reasons to do this are to add handling of custom attributes by overriding
'prepare_run' or to do custom drawing of embedded objects by overriding
'draw_shape'.</para>

  </refsect1>

  <refsect1>
    <title>Constructor</title>

    <programlisting><constructorsynopsis language="python">
	<methodname>gtk.gdk.PangoRenderer</methodname>
	<methodparam><parameter
		       role="keyword">screen</parameter></methodparam>
      </constructorsynopsis></programlisting>
    <variablelist>
      <varlistentry>
	<term><parameter role="keyword">screen</parameter>&nbsp;:</term>
	<listitem><simpara>a <link
linkend="class-gdkscreen"><classname>gtk.gdk.Screen</classname></link></simpara></listitem>
      </varlistentry>
      <varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	<listitem><simpara>a new <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
object</simpara></listitem>
      </varlistentry>
    </variablelist>

    <note>
      <para>This constructor is available in PyGTK 2.8 and above.</para>
    </note>

    <para>Creates a new <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
object for the <link
linkend="class-gdkscreen"><classname>gtk.gdk.Screen</classname></link>
specified by screen. Normally you can use the results of the <link
linkend="function-gdk--gdk-pango-renderer-get-default"><function>gtk.gdk.gdk_pango_renderer_get_default</function>()</link>
function rather than creating a new renderer.</para>

  </refsect1>

  <refsect1>
    <title>Methods</title>

    <refsect2 id="method-gdkpangorenderer--set-drawable">
      <title>gtk.gdk.PangoRenderer.set_drawable</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>set_drawable</methodname>
	  <methodparam><parameter
			 role="keyword">drawable</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">drawable</parameter>&nbsp;:</term>
	  <listitem><simpara>the new target <link
linkend="class-gdkdrawable"><classname>gtk.gdk.Drawable</classname></link> or
          <literal>None</literal>.</simpara></listitem>
	</varlistentry>
      </variablelist>

      <note>
        <para>This method is available in PyGTK 2.8 and above.</para>
      </note>

      <para>The <methodname>set_drawable</methodname>() method sets the
<link
linkend="class-gdkdrawable"><classname>gtk.gdk.Drawable</classname></link>
specified by <parameter>drawable</parameter> as the drawable for
rendering.</para>

<para>In PyGTK 2.10, <parameter>drawable</parameter> may be
<literal>None</literal> to unset the drawable.</para>

    </refsect2>

    <refsect2 id="method-gdkpangorenderer--set-gc">
      <title>gtk.gdk.PangoRenderer.set_gc</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>set_gc</methodname>
	  <methodparam><parameter
			 role="keyword">gc</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">gc</parameter>&nbsp;:</term>
	  <listitem><simpara>a <link
linkend="class-gdkgc"><classname>gtk.gdk.GC</classname></link> or
          <literal>None</literal>.</simpara></listitem>
	</varlistentry>
      </variablelist>

      <note>
        <para>This method is available in PyGTK 2.8 and above.</para>
      </note>

      <para>The <methodname>set_gc</methodname>() method sets the graphics
context the renderer draws with to the <link
linkend="class-gdkgc"><classname>gtk.gdk.GC</classname></link> specified by
<parameter>gc</parameter>.</para>

<para>In PyGTK 2.10, <parameter>gc</parameter> may be
<literal>None</literal> to unset the gc to use for drawing.</para>

    </refsect2>

    <refsect2 id="method-gdkpangorenderer--set-stipple">
      <title>gtk.gdk.PangoRenderer.set_stipple</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>set_stipple</methodname>
	  <methodparam><parameter
			 role="keyword">part</parameter></methodparam>
	  <methodparam><parameter
			 role="keyword">stipple</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">part</parameter>&nbsp;:</term>
	  <listitem><simpara> the part to render with the
stipple</simpara></listitem>
	</varlistentry>
	<varlistentry>
	  <term><parameter role="keyword">stipple</parameter>&nbsp;:</term>
	  <listitem><simpara> the new stipple bitmap</simpara> or
          <literal>None</literal>.</listitem>
	</varlistentry>
      </variablelist>

      <note>
        <para>This method is available in PyGTK 2.8 and above.</para>
      </note>

      <para>The <methodname>set_stipple</methodname>() method sets the
stipple for one render part (foreground, background, underline,
strikethrough) to the bitmap specified by
<parameter>stipple</parameter>. The value of part must be one of the <xref
linkend="pango-render-part-constants"
endterm="pango-render-part-constants-title"></xref>. Note that this is
overwritten when iterating through the individual styled runs of a <link
linkend="class-pangolayout"><classname>pango.Layout</classname></link> or
<link
linkend="class-pangolayoutline"><classname>pango.LayoutLine</classname></link>. This
method is thus only useful when you call low level methods like <link
linkend="method-pangorenderer--draw-glyphs"><methodname>draw_glyphs</methodname>()</link>
directly, or in the 'prepare_run' virtual function of a subclass of <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>.</para>

<para>In PyGTK 2.10 <parameter>stipple</parameter> may be set to
<literal>None</literal>.</para>

    </refsect2>

    <refsect2 id="method-gdkpangorenderer--set-override-color">
      <title>gtk.gdk.PangoRenderer.set_override_color</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>set_override_color</methodname>
	  <methodparam><parameter
			 role="keyword">part</parameter></methodparam>
	  <methodparam><parameter
			 role="keyword">color</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">part</parameter>&nbsp;:</term>
	  <listitem><simpara> the part to render with
<parameter>color</parameter></simpara></listitem>
	</varlistentry>
	<varlistentry>
	  <term><parameter role="keyword">color</parameter>&nbsp;:</term>
	  <listitem><simpara>a <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link> or
          <literal>None</literal>.</simpara></listitem>
	</varlistentry>
      </variablelist>

      <note>
        <para>This method is available in PyGTK 2.8 and above.</para>
      </note>

      <para>The <methodname>set_override_color</methodname>() method sets
the color for a particular render part (foreground, background, underline,
strikethrough.) to the <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
specified by <parameter>color</parameter>, overriding any attributes on the
layouts renderered with this renderer.</para>

<para>In PyGTK 2.10 <parameter>color</parameter> may be set to
<literal>None</literal>.</para>

    </refsect2>

  </refsect1>

  <refsect1>
    <title>Functions</title>

    <refsect2 id="function-gdk--gdk-pango-renderer-get-default">
      <title>gtk.gdk.gdk_pango_renderer_get_default</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>gtk.gdk.gdk_pango_renderer_get_default</methodname>
	  <methodparam><parameter
			 role="keyword">screen</parameter></methodparam>
	</methodsynopsis></programlisting>
      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">screen</parameter>&nbsp;:</term>
	  <listitem><simpara>a <link
linkend="class-gdkscreen"><classname>gtk.gdk.Screen</classname></link></simpara></listitem>
	</varlistentry>
	<varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	  <listitem><simpara>the default <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
object for <parameter>screen</parameter>.</simpara></listitem>
	</varlistentry>
      </variablelist>

      <note>
        <para>This function is available in PyGTK 2.8 and above.</para>
      </note>

      <para>The
<function>gtk.gdk.gdk_pango_renderer_get_default</function>() function
returns the default <link
linkend="class-gdkpangorenderer"><classname>gtk.gdk.PangoRenderer</classname></link>
for the <link
linkend="class-gdkscreen"><classname>gtk.gdk.Screen</classname></link>
specified by <parameter>screen</parameter>. This default renderer is shared
by all users of the display, so properties such as the color or
transformation matrix set for the renderer may be overwritten by methods
such as <link
linkend="method-gdkdrawable--draw-layout"><methodname>gtk.gdk.Drawable.draw_layout</methodname>()</link>.</para>

      <para>Before using the renderer, you need to call the <link
linkend="method-gdkpangorenderer--set-drawable"><methodname>set_drawable</methodname>()</link>
and <link
linkend="method-gdkpangorenderer--set-gc"><methodname>set_gc</methodname>()</link>
methods to set the drawable and graphics context to use for drawing.</para>

    </refsect2>

  </refsect1>

</refentry>