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