summaryrefslogtreecommitdiff
path: root/docs/pango_markup.sgml
blob: 913ece66ccb2ec7e11817a91410db142da6fca22 (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
<refentry id="PangoMarkupFormat" revision="11 Dec 2002">
<refmeta>
<refentrytitle>Text Attribute Markup</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>Pango Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Text Attribute Markup</refname><refpurpose>Simple
markup language to encode text with attributes</refpurpose>
</refnamediv>

<refsect1 id="PangoMarkupFormatLanguage">
<title>Pango Text Attribute Markup Language</title>

<para>
Frequently, you want to display some text to the user with attributes
applied to part of the text (for example, you might want bold or
italicized words). With the base Pango interfaces, you could create a
<link linkend="PangoAttrList">PangoAttrList</link> and apply it to the
text; the problem is that you'd need to apply attributes to some
numeric range of characters, for example "characters 12-17." This is
broken from an internationalization standpoint; once the text is
translated, the word you wanted to italicize could be in a different
position.
</para>

<para>
The solution is to include the text attributes in the string to be
translated. Pango provides this feature with a small markup language.
You can parse a marked-up string into the string text plus a
<link linkend="PangoAttrList">PangoAttrList</link> using either of
<link linkend="pango-parse-markup">pango_parse_markup()</link> or
<link linkend="pango-markup-parser-new">pango_markup_parser_new()</link>.
</para>

<para>
A simple example of a marked-up string might be:
<literal>"&lt;span foreground="blue" size="x-large"&gt;Blue text&lt;/span&gt; is &lt;i&gt;cool&lt;/i&gt;!"</literal>
</para>

<para>
Pango uses #GMarkup to parse this language, which means that XML features
such as numeric character entities such as &amp;#169; for &#169; can
be used too.
</para>

<para>
The root tag of a marked-up document is &lt;markup&gt;, but <link
linkend="pango-parse-markup">pango_parse_markup()</link> allows you to
omit this tag, so you will most likely never need to use it. The most
general markup tag is &lt;span&gt;, then there are some convenience
tags. &lt;span&gt; has the following attributes:
<variablelist><title>&lt;span&gt; attributes</title>

<varlistentry>
<term>font<footnote id='since_1_21'><para>Since 1.21</para></footnote></term>
<term>font_desc</term>
<listitem><para>
A font description string, such as "Sans Italic 12". See
<link linkend="pango-font-description-from-string">pango_font_description_from_string()</link>
for a description of the format of the string representation . Note that any 
other span attributes will override this description. So if you have 
"Sans Italic" and also a style="normal" attribute, you will get Sans normal, 
not italic.</para></listitem>
</varlistentry>

<varlistentry>
<term>font_family</term>
<term>face</term>
<listitem><para>
A font family name
</para></listitem>
</varlistentry>

<varlistentry>
<term>font_size<footnoteref linkend='since_1_21'/></term>
<term>size</term>
<listitem><para>
Font size in 1024ths of a point, or one of the absolute sizes 
'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
'xx-large', or one of the relative sizes 'smaller' or 'larger'.
If you want to specify a absolute size, it's usually easier
to take advantage of the ability to specify a partial
font description using 'font'; you can use
<literal>font='12.5'</literal> rather than
<literal>size='12800'</literal>.
</para></listitem>
</varlistentry>

<varlistentry>
<term>font_style<footnoteref linkend='since_1_21'/></term>
<term>style</term>
<listitem><para>
One of 'normal', 'oblique', 'italic'
</para></listitem>
</varlistentry>

<varlistentry>
<term>font_weight<footnoteref linkend='since_1_21'/></term>
<term>weight</term>
<listitem><para>
One of 'ultralight', 'light', 'normal', 'bold', 'ultrabold', 'heavy',
or a numeric weight
</para></listitem>
</varlistentry>

<varlistentry>
<term>font_variant<footnoteref linkend='since_1_21'/></term>
<term>variant</term>
<listitem><para>
One of 'normal' or 'smallcaps'
</para></listitem>
</varlistentry>

<varlistentry>
<term>font_stretch<footnoteref linkend='since_1_21'/></term>
<term>stretch</term>
<listitem><para>
One of 'ultracondensed', 'extracondensed', 'condensed',
'semicondensed', 'normal', 'semiexpanded', 'expanded',
'extraexpanded', 'ultraexpanded'
</para></listitem>
</varlistentry>

<varlistentry>
<term>font_features<footnote><para>Since 1.38</para></footnote></term>
<listitem><para>
A comma separated list of OpenType font feature settings, in the same
syntax as accepted by CSS. E.g: <literal>font_features='dlig=1, -kern, afrc on'</literal>
</para></listitem>
</varlistentry>

<varlistentry>
<term>foreground</term>
<term>fgcolor<footnoteref linkend='since_1_21'/></term>
<term>color</term>
<listitem><para>
An RGB color specification such as '#00FF00' or a color name such as 
'red'
</para></listitem>
</varlistentry>

<varlistentry>
<term>background</term>
<term>bgcolor<footnoteref linkend='since_1_21'/></term>
<listitem><para>
An RGB color specification such as '#00FF00' or a color name such as 
'red'
</para></listitem>
</varlistentry>

<varlistentry><term>underline</term>
<listitem><para>
One of 'none', 'single', 'double', 'low', 'error'
</para></listitem>
</varlistentry>

<varlistentry><term>underline_color</term>
<listitem><para>
The color of underlines; an RGB color specification such as '#00FF00'
or a color name such as 'red'
</para></listitem>
</varlistentry>

<varlistentry><term>rise</term>
<listitem><para>
Vertical displacement, in Pango units. Can be negative for 
subscript, positive for superscript.
</para></listitem>
</varlistentry>

<varlistentry><term>strikethrough</term>
<listitem><para>
'true' or 'false' whether to strike through the text
</para></listitem>
</varlistentry>

<varlistentry><term>strikethrough_color</term>
<listitem><para>
The color of strikethrough lines; an RGB color specification such as
'#00FF00' or a color name such as 'red'
</para></listitem>
</varlistentry>

<varlistentry><term>fallback</term>
<listitem><para>
'true' or 'false' whether to enable fallback. If disabled, then characters
will only be used from the closest matching font on the system. No fallback
will be done to other fonts on the system that might contain the characters
in the text.  Fallback is enabled by default. Most applications should not
disable fallback.
</para></listitem>
</varlistentry>

<varlistentry><term>lang</term>
<listitem><para>
A language code, indicating the text language
</para></listitem>
</varlistentry>

<varlistentry><term>letter_spacing</term>
<listitem><para>
Inter-letter spacing in 1024ths of a point.
</para></listitem>
</varlistentry>

<varlistentry><term>gravity</term>
<listitem><para>
One of 'south', 'east', 'north', 'west', 'auto'.
</para></listitem>
</varlistentry>

<varlistentry><term>gravity_hint</term>
<listitem><para>
One of 'natural', 'strong', 'line'.
</para></listitem>
</varlistentry>

</variablelist>

</para>

<para>
The following convenience tags are provided:

<variablelist><title>Convenience tags</title>
<varlistentry><term>b</term>
<listitem><para>
Bold
</para></listitem>
</varlistentry>
<varlistentry><term>big</term>
<listitem><para>
Makes font relatively larger, equivalent to &lt;span size="larger"&gt;
</para></listitem>
</varlistentry>
<varlistentry><term>i</term>
<listitem><para>
Italic
</para></listitem>
</varlistentry>
<varlistentry><term>s</term>
<listitem><para>
Strikethrough
</para></listitem>
</varlistentry>
<varlistentry><term>sub</term>
<listitem><para>
Subscript
</para></listitem>
</varlistentry>
<varlistentry><term>sup</term>
<listitem><para>
Superscript
</para></listitem>
</varlistentry>
<varlistentry><term>small</term>
<listitem><para>
Makes font relatively smaller, equivalent to &lt;span size="smaller"&gt;
</para></listitem>
</varlistentry>
<varlistentry><term>tt</term>
<listitem><para>
Monospace font
</para></listitem>
</varlistentry>
<varlistentry><term>u</term>
<listitem><para>
Underline
</para></listitem>
</varlistentry>
</variablelist>

</para>

</refsect1>

</refentry>