Converts the given pattern into text format described by the format specifier.
The format specifier is similar to a C style printf string, which the
-printf(2) man page provides a good introduction to. However, as RPM already
-knows the type of data that is being printed, you must omit the type
+printf(2) man page provides a good introduction to. However, as fontconfig
+already knows the type of data that is being printed, you must omit the type
specifier. In its place put the element name you wish to print enclosed in
curly braces ({}). For example, to print the family name and style the
pattern, use the format "%{family} %{style}\n".
+There can be an option width specifier after the percent sign and before
+the opening brace. The width modifier acts similar to those in printf.
The return value refers to newly allocated memory which should be freed by the
caller using free().
@@
FcStrBuf *buf,
const FcChar8 *format)
{
+ int width, before;
+
+ /* parse an optional width specifier */
+ width = strtol (format, (char **) &format, 10);
+
+ before = buf->len;
+
switch (*format) {
case '{':
{
if (!p)
{
message ("Pattern format missing closing brace");
- return format;
+ break;
}
/* extract the element name */
memcpy (scratch1, format, p - format);
}
p++; /* skip over '}' */
- return p;
+ format = p;
+ break;
}
default:
message ("Pattern format has invalid character after '%%' at %d",
format - format_orig);
- return format;
+ break;
+ }
+
+ /* align to width */
+ if (!buf->failed)
+ {
+ int after, len;
+
+ after = buf->len;
+
+ len = after - before;
+
+ if (len < -width)
+ {
+ /* left align */
+ while (len++ < -width)
+ FcStrBufChar (buf, ' ');
+ }
+ else if (len < width)
+ {
+ /* right align */
+ while (len++ < width)
+ FcStrBufChar (buf, ' ');
+ len = after - before;
+ memmove (buf->buf + buf->len - len,
+ buf->buf + buf->len - width,
+ len);
+ memset (buf->buf + buf->len - width,
+ ' ',
+ width - len);
+ }
}
+
+ return format;
}
static char escaped_char(const char ch)