FcPatternFormat.3 revision a6844aab
1.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $
2.TH "FcPatternFormat" "3" "18 November 2009" "" ""
3.SH NAME
4FcPatternFormat \- Format a pattern into a string according to a format specifier
5.SH SYNOPSIS
6.nf
7\fB#include <fontconfig.h>
8.sp
9FcChar8 * FcPatternFormat(FcPattern *\fIpat\fB);
10(const FcChar8 *\fIformat\fB);
11\fR.fi
12.SH "DESCRIPTION"
13.PP
14Converts given pattern \fIpat\fR into text described by
15the format specifier \fIformat\fR\&.
16The return value refers to newly allocated memory which should be freed by the
17caller using free(), or NULL if \fIformat\fR is invalid.
18.PP
19The format is loosely modelled after printf-style format string.
20The format string is composed of zero or more directives: ordinary
21characters (not "%"), which are copied unchanged to the output stream;
22and tags which are interpreted to construct text from the pattern in a
23variety of ways (explained below).
24Special characters can be escaped
25using backslash. C-string style special characters like \\n and \\r are
26also supported (this is useful when the format string is not a C string
27literal).
28It is advisable to always escape curly braces that
29are meant to be copied to the output as ordinary characters.
30.PP
31Each tags is introduced by the character "%",
32followed by an optional minimum field width,
33followed by tag contents in curly braces ({}).
34If the minimum field width value is provided the tag
35will be expanded and the result padded to achieve the minimum width.
36If the minimum field width is positive, the padding will right-align
37the text. Negative field width will left-align.
38The rest of this section describes various supported tag contents
39and their expansion.
40.PP
41A \fIsimple\fR tag
42is one where the content is an identifier. When simple
43tags are expanded, the named identifier will be looked up in
44\fIpattern\fR and the resulting list of values returned,
45joined together using comma. For example, to print the family name and style the
46pattern, use the format "%{family} %{style}\\n". To extend the family column
47to forty characters use "%-40{family}%{style}\\n".
48.PP
49Simple tags expand to list of all values for an element. To only choose
50one of the values, one can index using the syntax "%{elt[idx]}". For example,
51to get the first family name only, use "%{family[0]}".
52.PP
53If a simple tag ends with "=" and the element is found in the pattern, the
54name of the element followed by "=" will be output before the list of values.
55For example, "%{weight=}" may expand to the string "weight=80". Or to the empty
56string if \fIpattern\fR does not have weight set.
57.PP
58If a simple tag starts with ":" and the element is found in the pattern, ":"
59will be printed first. For example, combining this with the =, the format
60"%{:weight=}" may expand to ":weight=80" or to the empty string
61if \fIpattern\fR does not have weight set.
62.PP
63If a simple tag contains the string ":-", the rest of the the tag contents
64will be used as a default string. The default string is output if the element
65is not found in the pattern. For example, the format
66"%{:weight=:-123}" may expand to ":weight=80" or to the string
67":weight=123" if \fIpattern\fR does not have weight set.
68.PP
69A \fIcount\fR tag
70is one that starts with the character "#" followed by an element
71name, and expands to the number of values for the element in the pattern.
72For example, "%{#family}" expands to the number of family names
73\fIpattern\fR has set, which may be zero.
74.PP
75A \fIsub-expression\fR tag
76is one that expands a sub-expression. The tag contents
77are the sub-expression to expand placed inside another set of curly braces.
78Sub-expression tags are useful for aligning an entire sub-expression, or to
79apply converters (explained later) on an entire sub-expression.
80For example, the format "%40{{%{family} %{style}}}" expands the sub-expression
81to construct the family name followed by the style, then takes the entire
82string and pads it on the left to be at least forty characters.
83.PP
84A \fIfilter-out\fR tag
85is one starting with the character "-" followed by a
86comma-separated list of element names, followed by a sub-expression enclosed
87in curly braces. The sub-expression will be expanded but with a pattern that
88has the listed elements removed from it.
89For example, the format "%{-size,pixelsize{sub-expr}}" will expand "sub-expr"
90with \fIpattern\fR sans the size and pixelsize elements.
91.PP
92A \fIfilter-in\fR tag
93is one starting with the character "+" followed by a
94comma-separated list of element names, followed by a sub-expression enclosed
95in curly braces. The sub-expression will be expanded but with a pattern that
96only has the listed elements from the surrounding pattern.
97For example, the format "%{+family,familylang{sub-expr}}" will expand "sub-expr"
98with a sub-pattern consisting only the family and family lang elements of
99\fIpattern\fR\&.
100.PP
101A \fIconditional\fR tag
102is one starting with the character "?" followed by a
103comma-separated list of element conditions, followed by two sub-expression
104enclosed in curly braces. An element condition can be an element name,
105in which case it tests whether the element is defined in pattern, or
106the character "!" followed by an element name, in which case the test
107is negated. The conditional passes if all the element conditions pass.
108The tag expands the first sub-expression if the conditional passes, and
109expands the second sub-expression otherwise.
110For example, the format "%{?size,dpi,!pixelsize{pass}{fail}}" will expand
111to "pass" if \fIpattern\fR has size and dpi elements but
112no pixelsize element, and to "fail" otherwise.
113.PP
114An \fIenumerate\fR tag
115is one starting with the string "[]" followed by a
116comma-separated list of element names, followed by a sub-expression enclosed
117in curly braces. The list of values for the named elements are walked in
118parallel and the sub-expression expanded each time with a pattern just having
119a single value for those elements, starting from the first value and
120continuing as long as any of those elements has a value.
121For example, the format "%{[]family,familylang{%{family} (%{familylang})\\n}}"
122will expand the pattern "%{family} (%{familylang})\\n" with a pattern
123having only the first value of the family and familylang elemtns, then expands
124it with the second values, then the third, etc.
125.PP
126As a special case, if an enumerate tag has only one element, and that element
127has only one value in the pattern, and that value is of type FcLangSet, the
128individual languages in the language set are enumerated.
129.PP
130A \fIbuiltin\fR tag
131is one starting with the character "=" followed by a builtin
132name. The following builtins are defined:
133.TP
134\fBunparse\fR
135Expands to the result of calling FcNameUnparse() on the pattern.
136.TP
137\fBfcmatch\fR
138Expands to the output of the default output format of the fc-match
139command on the pattern, without the final newline.
140.TP
141\fBfclist\fR
142Expands to the output of the default output format of the fc-list
143command on the pattern, without the final newline.
144.TP
145\fBpkgkit\fR
146Expands to the list of PackageKit font() tags for the pattern.
147Currently this includes tags for each family name, and each language
148from the pattern, enumerated and sanitized into a set of tags terminated
149by newline. Package management systems can use these tags to tag their
150packages accordingly.
151.PP
152For example, the format "%{+family,style{%{=unparse}}}\\n" will expand
153to an unparsed name containing only the family and style element values
154from \fIpattern\fR\&.
155.PP
156The contents of any tag can be followed by a set of zero or more
157\fIconverter\fRs. A converter is specified by the
158character "|" followed by the converter name and arguments. The
159following converters are defined:
160.TP
161\fBbasename\fR
162Replaces text with the results of calling FcStrBasename() on it.
163.TP
164\fBdirname\fR
165Replaces text with the results of calling FcStrDirname() on it.
166.TP
167\fBdowncase\fR
168Replaces text with the results of calling FcStrDowncase() on it.
169.TP
170\fBshescape\fR
171Escapes text for one level of shell expansion.
172(Escapes single-quotes, also encloses text in single-quotes.)
173.TP
174\fBcescape\fR
175Escapes text such that it can be used as part of a C string literal.
176(Escapes backslash and double-quotes.)
177.TP
178\fBxmlescape\fR
179Escapes text such that it can be used in XML and HTML.
180(Escapes less-than, greater-than, and ampersand.)
181.TP
182\fBdelete(\fIchars\fB)\fR
183Deletes all occurrences of each of the characters in \fIchars\fR
184from the text.
185FIXME: This converter is not UTF-8 aware yet.
186.TP
187\fBescape(\fIchars\fB)\fR
188Escapes all occurrences of each of the characters in \fIchars\fR
189by prepending it by the first character in \fIchars\fR\&.
190FIXME: This converter is not UTF-8 aware yet.
191.TP
192\fBtranslate(\fIfrom\fB,\fIto\fB)\fR
193Translates all occurrences of each of the characters in \fIfrom\fR
194by replacing them with their corresponding character in \fIto\fR\&.
195If \fIto\fR has fewer characters than
196\fIfrom\fR, it will be extended by repeating its last
197character.
198FIXME: This converter is not UTF-8 aware yet.
199.PP
200For example, the format "%{family|downcase|delete( )}\\n" will expand
201to the values of the family element in \fIpattern\fR,
202lower-cased and with spaces removed.
203.SH "VERSION"
204.PP
205Fontconfig version 2.8.0
206