fcpatternformat.html revision a32e9e42
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<HTML
3><HEAD
4><TITLE
5>FcPatternFormat</TITLE
6><META
7NAME="GENERATOR"
8CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
9REL="HOME"
10HREF="t1.html"><LINK
11REL="UP"
12TITLE="FcPattern"
13HREF="x103.html#AEN242"><LINK
14REL="PREVIOUS"
15TITLE="FcNameUnparse"
16HREF="fcnameunparse.html"></HEAD
17><BODY
18CLASS="REFENTRY"
19BGCOLOR="#FFFFFF"
20TEXT="#000000"
21LINK="#0000FF"
22VLINK="#840084"
23ALINK="#0000FF"
24><DIV
25CLASS="NAVHEADER"
26><TABLE
27SUMMARY="Header navigation table"
28WIDTH="100%"
29BORDER="0"
30CELLPADDING="0"
31CELLSPACING="0"
32><TR
33><TH
34COLSPAN="3"
35ALIGN="center"
36></TH
37></TR
38><TR
39><TD
40WIDTH="10%"
41ALIGN="left"
42VALIGN="bottom"
43><A
44HREF="fcnameunparse.html"
45ACCESSKEY="P"
46>&#60;&#60;&#60; Previous</A
47></TD
48><TD
49WIDTH="80%"
50ALIGN="center"
51VALIGN="bottom"
52></TD
53><TD
54WIDTH="10%"
55ALIGN="right"
56VALIGN="bottom"
57>&nbsp;</TD
58></TR
59></TABLE
60><HR
61ALIGN="LEFT"
62WIDTH="100%"></DIV
63><H1
64><A
65NAME="FCPATTERNFORMAT"
66></A
67>FcPatternFormat</H1
68><DIV
69CLASS="REFNAMEDIV"
70><A
71NAME="AEN1190"
72></A
73><H2
74>Name</H2
75>FcPatternFormat&nbsp;--&nbsp;Format a pattern into a string according to a format specifier</DIV
76><DIV
77CLASS="REFSYNOPSISDIV"
78><A
79NAME="AEN1193"
80></A
81><H2
82>Synopsis</H2
83><DIV
84CLASS="FUNCSYNOPSIS"
85><P
86></P
87><A
88NAME="AEN1194"
89></A
90><TABLE
91BORDER="0"
92BGCOLOR="#E0E0E0"
93WIDTH="100%"
94><TR
95><TD
96><PRE
97CLASS="FUNCSYNOPSISINFO"
98>#include &#60;fontconfig/fontconfig.h&#62;
99	</PRE
100></TD
101></TR
102></TABLE
103><P
104><CODE
105><CODE
106CLASS="FUNCDEF"
107>FcChar8 * <TT
108CLASS="FUNCTION"
109>FcPatternFormat</TT
110></CODE
111>(FcPattern *<TT
112CLASS="PARAMETER"
113><I
114>pat</I
115></TT
116>, const FcChar8 *<TT
117CLASS="PARAMETER"
118><I
119>format</I
120></TT
121>);</CODE
122></P
123><P
124></P
125></DIV
126></DIV
127><DIV
128CLASS="REFSECT1"
129><A
130NAME="AEN1203"
131></A
132><H2
133>Description</H2
134><P
135>Converts given pattern <TT
136CLASS="PARAMETER"
137><I
138>pat</I
139></TT
140> into text described by
141the format specifier <TT
142CLASS="PARAMETER"
143><I
144>format</I
145></TT
146>.
147The return value refers to newly allocated memory which should be freed by the
148caller using free(), or NULL if <TT
149CLASS="PARAMETER"
150><I
151>format</I
152></TT
153> is invalid.&#13;</P
154><P
155>&#13;The format is loosely modeled after printf-style format string.
156The format string is composed of zero or more  directives: ordinary
157characters (not "%"), which are copied unchanged to the output stream;
158and tags which are interpreted to construct text from the pattern in a
159variety of ways (explained below).
160Special characters can be escaped
161using backslash.  C-string style special characters like \n and \r are
162also supported (this is useful when the format string is not a C string
163literal).
164It is advisable to always escape curly braces that
165are meant to be copied to the output as ordinary characters.&#13;</P
166><P
167>&#13;Each tag is introduced by the character "%",
168followed by an optional minimum field width,
169followed by tag contents in curly braces ({}).
170If the minimum field width value is provided the tag
171will be expanded and the result padded to achieve the minimum width.
172If the minimum field width is positive, the padding will right-align
173the text.  Negative field width will left-align.
174The rest of this section describes various supported tag contents
175and their expansion.&#13;</P
176><P
177>&#13;A <I
178CLASS="FIRSTTERM"
179>simple</I
180> tag
181is one where the content is an identifier.  When simple
182tags are expanded, the named identifier will be looked up in
183<TT
184CLASS="PARAMETER"
185><I
186>pattern</I
187></TT
188> and the resulting list of values returned,
189joined together using comma.  For example, to print the family name and style of the
190pattern, use the format "%{family} %{style}\n".  To extend the family column
191to forty characters use "%-40{family}%{style}\n".&#13;</P
192><P
193>&#13;Simple tags expand to list of all values for an element.  To only choose
194one of the values, one can index using the syntax "%{elt[idx]}".  For example,
195to get the first family name only, use "%{family[0]}".&#13;</P
196><P
197>&#13;If a simple tag ends with "=" and the element is found in the pattern, the
198name of the element followed by "=" will be output before the list of values.
199For example, "%{weight=}" may expand to the string "weight=80".  Or to the empty
200string if <TT
201CLASS="PARAMETER"
202><I
203>pattern</I
204></TT
205> does not have weight set.&#13;</P
206><P
207>&#13;If a simple tag starts with ":" and the element is found in the pattern, ":"
208will be printed first.  For example, combining this with the =, the format
209"%{:weight=}" may expand to ":weight=80" or to the empty string
210if <TT
211CLASS="PARAMETER"
212><I
213>pattern</I
214></TT
215> does not have weight set.&#13;</P
216><P
217>&#13;If a simple tag contains the string ":-", the rest of the the tag contents
218will be used as a default string.  The default string is output if the element
219is not found in the pattern.  For example, the format
220"%{:weight=:-123}" may expand to ":weight=80" or to the string
221":weight=123" if <TT
222CLASS="PARAMETER"
223><I
224>pattern</I
225></TT
226> does not have weight set.&#13;</P
227><P
228>&#13;A <I
229CLASS="FIRSTTERM"
230>count</I
231> tag
232is one that starts with the character "#" followed by an element
233name, and expands to the number of values for the element in the pattern.
234For example, "%{#family}" expands to the number of family names
235<TT
236CLASS="PARAMETER"
237><I
238>pattern</I
239></TT
240> has set, which may be zero.&#13;</P
241><P
242>&#13;A <I
243CLASS="FIRSTTERM"
244>sub-expression</I
245> tag
246is one that expands a sub-expression.  The tag contents
247are the sub-expression to expand placed inside another set of curly braces.
248Sub-expression tags are useful for aligning an entire sub-expression, or to
249apply converters (explained later) to the entire sub-expression output.
250For example, the format "%40{{%{family} %{style}}}" expands the sub-expression
251to construct the family name followed by the style, then takes the entire
252string and pads it on the left to be at least forty characters.&#13;</P
253><P
254>&#13;A <I
255CLASS="FIRSTTERM"
256>filter-out</I
257> tag
258is one starting with the character "-" followed by a
259comma-separated list of element names, followed by a sub-expression enclosed
260in curly braces.  The sub-expression will be expanded but with a pattern that
261has the listed elements removed from it.
262For example, the format "%{-size,pixelsize{sub-expr}}" will expand "sub-expr"
263with <TT
264CLASS="PARAMETER"
265><I
266>pattern</I
267></TT
268> sans the size and pixelsize elements.&#13;</P
269><P
270>&#13;A <I
271CLASS="FIRSTTERM"
272>filter-in</I
273> tag
274is one starting with the character "+" followed by a
275comma-separated list of element names, followed by a sub-expression enclosed
276in curly braces.  The sub-expression will be expanded but with a pattern that
277only has the listed elements from the surrounding pattern.
278For example, the format "%{+family,familylang{sub-expr}}" will expand "sub-expr"
279with a sub-pattern consisting only the family and family lang elements of
280<TT
281CLASS="PARAMETER"
282><I
283>pattern</I
284></TT
285>.&#13;</P
286><P
287>&#13;A <I
288CLASS="FIRSTTERM"
289>conditional</I
290> tag
291is one starting with the character "?" followed by a
292comma-separated list of element conditions, followed by two sub-expression
293enclosed in curly braces.  An element condition can be an element name,
294in which case it tests whether the element is defined in pattern, or
295the character "!" followed by an element name, in which case the test
296is negated.  The conditional passes if all the element conditions pass.
297The tag expands the first sub-expression if the conditional passes, and
298expands the second sub-expression otherwise.
299For example, the format "%{?size,dpi,!pixelsize{pass}{fail}}" will expand
300to "pass" if <TT
301CLASS="PARAMETER"
302><I
303>pattern</I
304></TT
305> has size and dpi elements but
306no pixelsize element, and to "fail" otherwise.&#13;</P
307><P
308>&#13;An <I
309CLASS="FIRSTTERM"
310>enumerate</I
311> tag
312is one starting with the string "[]" followed by a
313comma-separated list of element names, followed by a sub-expression enclosed
314in curly braces.  The list of values for the named elements are walked in
315parallel and the sub-expression expanded each time with a pattern just having
316a single value for those elements, starting from the first value and
317continuing as long as any of those elements has a value.
318For example, the format "%{[]family,familylang{%{family} (%{familylang})\n}}"
319will expand the pattern "%{family} (%{familylang})\n" with a pattern
320having only the first value of the family and familylang elements, then expands
321it with the second values, then the third, etc.&#13;</P
322><P
323>&#13;As a special case, if an enumerate tag has only one element, and that element
324has only one value in the pattern, and that value is of type FcLangSet, the
325individual languages in the language set are enumerated.&#13;</P
326><P
327>&#13;A <I
328CLASS="FIRSTTERM"
329>builtin</I
330> tag
331is one starting with the character "=" followed by a builtin
332name.  The following builtins are defined:
333
334<P
335></P
336><DIV
337CLASS="VARIABLELIST"
338><DL
339><DT
340>unparse</DT
341><DD
342><P
343>Expands to the result of calling FcNameUnparse() on the pattern.</P
344></DD
345><DT
346>fcmatch</DT
347><DD
348><P
349>Expands to the output of the default output format of the fc-match
350command on the pattern, without the final newline.</P
351></DD
352><DT
353>fclist</DT
354><DD
355><P
356>Expands to the output of the default output format of the fc-list
357command on the pattern, without the final newline.</P
358></DD
359><DT
360>fccat</DT
361><DD
362><P
363>Expands to the output of the default output format of the fc-cat
364command on the pattern, without the final newline.</P
365></DD
366><DT
367>pkgkit</DT
368><DD
369><P
370>Expands to the list of PackageKit font() tags for the pattern.
371Currently this includes tags for each family name, and each language
372from the pattern, enumerated and sanitized into a set of tags terminated
373by newline.  Package management systems can use these tags to tag their
374packages accordingly.</P
375></DD
376></DL
377></DIV
378>
379
380For example, the format "%{+family,style{%{=unparse}}}\n" will expand
381to an unparsed name containing only the family and style element values
382from <TT
383CLASS="PARAMETER"
384><I
385>pattern</I
386></TT
387>.&#13;</P
388><P
389>&#13;The contents of any tag can be followed by a set of zero or more
390<I
391CLASS="FIRSTTERM"
392>converter</I
393>s.  A converter is specified by the
394character "|" followed by the converter name and arguments.  The
395following converters are defined:
396
397<P
398></P
399><DIV
400CLASS="VARIABLELIST"
401><DL
402><DT
403>basename</DT
404><DD
405><P
406>Replaces text with the results of calling FcStrBasename() on it.</P
407></DD
408><DT
409>dirname</DT
410><DD
411><P
412>Replaces text with the results of calling FcStrDirname() on it.</P
413></DD
414><DT
415>downcase</DT
416><DD
417><P
418>Replaces text with the results of calling FcStrDowncase() on it.</P
419></DD
420><DT
421>shescape</DT
422><DD
423><P
424>Escapes text for one level of shell expansion.
425(Escapes single-quotes, also encloses text in single-quotes.)</P
426></DD
427><DT
428>cescape</DT
429><DD
430><P
431>Escapes text such that it can be used as part of a C string literal.
432(Escapes backslash and double-quotes.)</P
433></DD
434><DT
435>xmlescape</DT
436><DD
437><P
438>Escapes text such that it can be used in XML and HTML.
439(Escapes less-than, greater-than, and ampersand.)</P
440></DD
441><DT
442>delete(<TT
443CLASS="PARAMETER"
444><I
445>chars</I
446></TT
447>)</DT
448><DD
449><P
450>Deletes all occurrences of each of the characters in <TT
451CLASS="PARAMETER"
452><I
453>chars</I
454></TT
455>
456from the text.
457FIXME: This converter is not UTF-8 aware yet.</P
458></DD
459><DT
460>escape(<TT
461CLASS="PARAMETER"
462><I
463>chars</I
464></TT
465>)</DT
466><DD
467><P
468>Escapes all occurrences of each of the characters in <TT
469CLASS="PARAMETER"
470><I
471>chars</I
472></TT
473>
474by prepending it by the first character in <TT
475CLASS="PARAMETER"
476><I
477>chars</I
478></TT
479>.
480FIXME: This converter is not UTF-8 aware yet.</P
481></DD
482><DT
483>translate(<TT
484CLASS="PARAMETER"
485><I
486>from</I
487></TT
488>,<TT
489CLASS="PARAMETER"
490><I
491>to</I
492></TT
493>)</DT
494><DD
495><P
496>Translates all occurrences of each of the characters in <TT
497CLASS="PARAMETER"
498><I
499>from</I
500></TT
501>
502by replacing them with their corresponding character in <TT
503CLASS="PARAMETER"
504><I
505>to</I
506></TT
507>.
508If <TT
509CLASS="PARAMETER"
510><I
511>to</I
512></TT
513> has fewer characters than
514<TT
515CLASS="PARAMETER"
516><I
517>from</I
518></TT
519>, it will be extended by repeating its last
520character.
521FIXME: This converter is not UTF-8 aware yet.</P
522></DD
523></DL
524></DIV
525>
526
527For example, the format "%{family|downcase|delete( )}\n" will expand
528to the values of the family element in <TT
529CLASS="PARAMETER"
530><I
531>pattern</I
532></TT
533>,
534lower-cased and with spaces removed.
535	    </P
536></DIV
537><DIV
538CLASS="REFSECT1"
539><A
540NAME="AEN1313"
541></A
542><H2
543>Since</H2
544><P
545>version 2.9.0</P
546></DIV
547><DIV
548CLASS="NAVFOOTER"
549><HR
550ALIGN="LEFT"
551WIDTH="100%"><TABLE
552SUMMARY="Footer navigation table"
553WIDTH="100%"
554BORDER="0"
555CELLPADDING="0"
556CELLSPACING="0"
557><TR
558><TD
559WIDTH="33%"
560ALIGN="left"
561VALIGN="top"
562><A
563HREF="fcnameunparse.html"
564ACCESSKEY="P"
565>&#60;&#60;&#60; Previous</A
566></TD
567><TD
568WIDTH="34%"
569ALIGN="center"
570VALIGN="top"
571><A
572HREF="t1.html"
573ACCESSKEY="H"
574>Home</A
575></TD
576><TD
577WIDTH="33%"
578ALIGN="right"
579VALIGN="top"
580>&nbsp;</TD
581></TR
582><TR
583><TD
584WIDTH="33%"
585ALIGN="left"
586VALIGN="top"
587>FcNameUnparse</TD
588><TD
589WIDTH="34%"
590ALIGN="center"
591VALIGN="top"
592><A
593HREF="x103.html#AEN242"
594ACCESSKEY="U"
595>Up</A
596></TD
597><TD
598WIDTH="33%"
599ALIGN="right"
600VALIGN="top"
601>&nbsp;</TD
602></TR
603></TABLE
604></DIV
605></BODY
606></HTML
607>