]> git.wh0rd.org - fontconfig.git/blame - src/fcname.c
Reinstate the old global cache code. For the forseeable future, it's
[fontconfig.git] / src / fcname.c
CommitLineData
24330d27 1/*
94421e40 2 * $RCSId: xc/lib/fontconfig/src/fcname.c,v 1.15 2002/09/26 00:17:28 keithp Exp $
24330d27 3 *
46b51147 4 * Copyright © 2000 Keith Packard
24330d27
KP
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
15 *
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
23 */
24
25#include <ctype.h>
26#include <stdlib.h>
27#include <string.h>
28#include <stdio.h>
29#include "fcint.h"
30
31static const FcObjectType _FcBaseObjectTypes[] = {
32 { FC_FAMILY, FcTypeString, },
4f27c1c0 33 { FC_FAMILYLANG, FcTypeString, },
24330d27 34 { FC_STYLE, FcTypeString, },
4f27c1c0
KP
35 { FC_STYLELANG, FcTypeString, },
36 { FC_FULLNAME, FcTypeString, },
37 { FC_FULLNAMELANG, FcTypeString, },
24330d27
KP
38 { FC_SLANT, FcTypeInteger, },
39 { FC_WEIGHT, FcTypeInteger, },
81fa16c3 40 { FC_WIDTH, FcTypeInteger, },
24330d27 41 { FC_SIZE, FcTypeDouble, },
2a41214a 42 { FC_ASPECT, FcTypeDouble, },
24330d27
KP
43 { FC_PIXEL_SIZE, FcTypeDouble, },
44 { FC_SPACING, FcTypeInteger, },
45 { FC_FOUNDRY, FcTypeString, },
46/* { FC_CORE, FcTypeBool, }, */
47 { FC_ANTIALIAS, FcTypeBool, },
f077d662 48 { FC_HINT_STYLE, FcTypeInteger, },
4c003605
KP
49 { FC_HINTING, FcTypeBool, },
50 { FC_VERTICAL_LAYOUT, FcTypeBool, },
51 { FC_AUTOHINT, FcTypeBool, },
52 { FC_GLOBAL_ADVANCE, FcTypeBool, },
24330d27
KP
53/* { FC_XLFD, FcTypeString, }, */
54 { FC_FILE, FcTypeString, },
55 { FC_INDEX, FcTypeInteger, },
56 { FC_RASTERIZER, FcTypeString, },
57 { FC_OUTLINE, FcTypeBool, },
58 { FC_SCALABLE, FcTypeBool, },
4c003605 59 { FC_DPI, FcTypeDouble },
24330d27
KP
60 { FC_RGBA, FcTypeInteger, },
61 { FC_SCALE, FcTypeDouble, },
62/* { FC_RENDER, FcTypeBool, },*/
63 { FC_MINSPACE, FcTypeBool, },
64 { FC_CHAR_WIDTH, FcTypeInteger },
65 { FC_CHAR_HEIGHT, FcTypeInteger },
66 { FC_MATRIX, FcTypeMatrix },
67 { FC_CHARSET, FcTypeCharSet },
d8d73958 68 { FC_LANG, FcTypeLangSet },
a342e87d 69 { FC_FONTVERSION, FcTypeInteger },
dbf68dd5 70 { FC_CAPABILITY, FcTypeString },
537e3d23 71 { FC_FONTFORMAT, FcTypeString },
414f7202 72 { FC_EMBOLDEN, FcTypeBool },
24330d27
KP
73};
74
75#define NUM_OBJECT_TYPES (sizeof _FcBaseObjectTypes / sizeof _FcBaseObjectTypes[0])
76
77typedef struct _FcObjectTypeList FcObjectTypeList;
78
79struct _FcObjectTypeList {
80 const FcObjectTypeList *next;
81 const FcObjectType *types;
82 int ntypes;
83};
84
85static const FcObjectTypeList _FcBaseObjectTypesList = {
86 0,
87 _FcBaseObjectTypes,
88 NUM_OBJECT_TYPES
89};
90
91static const FcObjectTypeList *_FcObjectTypes = &_FcBaseObjectTypesList;
92
93FcBool
94FcNameRegisterObjectTypes (const FcObjectType *types, int ntypes)
95{
96 FcObjectTypeList *l;
97
98 l = (FcObjectTypeList *) malloc (sizeof (FcObjectTypeList));
99 if (!l)
100 return FcFalse;
9dac3c59 101 FcMemAlloc (FC_MEM_OBJECTTYPE, sizeof (FcObjectTypeList));
24330d27
KP
102 l->types = types;
103 l->ntypes = ntypes;
104 l->next = _FcObjectTypes;
105 _FcObjectTypes = l;
106 return FcTrue;
107}
108
109FcBool
110FcNameUnregisterObjectTypes (const FcObjectType *types, int ntypes)
111{
112 const FcObjectTypeList *l, **prev;
113
114 for (prev = &_FcObjectTypes;
115 (l = *prev);
116 prev = (const FcObjectTypeList **) &(l->next))
117 {
118 if (l->types == types && l->ntypes == ntypes)
119 {
120 *prev = l->next;
9dac3c59 121 FcMemFree (FC_MEM_OBJECTTYPE, sizeof (FcObjectTypeList));
24330d27
KP
122 free ((void *) l);
123 return FcTrue;
124 }
125 }
126 return FcFalse;
127}
128
129const FcObjectType *
130FcNameGetObjectType (const char *object)
131{
132 int i;
133 const FcObjectTypeList *l;
134 const FcObjectType *t;
135
136 for (l = _FcObjectTypes; l; l = l->next)
137 {
138 for (i = 0; i < l->ntypes; i++)
139 {
140 t = &l->types[i];
bc9469ba 141 if (!strcmp (object, t->object))
24330d27
KP
142 return t;
143 }
144 }
145 return 0;
146}
147
4262e0b3
PL
148static int objectptr_count = 1;
149static int objectptr_alloc = 0;
150static int * objectptr_indices = 0;
151
152void
153FcObjectNewBank(void)
154{
155 objectptr_count = 1;
156 objectptr_alloc = 0;
157 objectptr_indices = 0;
158}
159
160// XXX todo: introduce a hashtable for faster lookup
161FcObjectPtr
162FcObjectToPtr (const char * object)
163{
164 int i;
165 const FcObjectTypeList *l;
166 const FcObjectType *t;
167
168 for (l = _FcObjectTypes; l; l = l->next)
169 {
170 for (i = 0; i < l->ntypes; i++)
171 {
172 t = &l->types[i];
173 if (!strcmp (object, t->object))
174 return i;
175 }
176 }
177 abort();
178 return 0;
179}
180
181const char *
182FcObjectPtrU (FcObjectPtr si)
183{
184 return _FcObjectTypes->types[si].object;
185}
186
187int
188FcObjectNeededBytes (FcObjectPtr si)
189{
190 return 0;
191}
192
193void *
194FcObjectDistributeBytes (FcCache * metadata, void * block_ptr)
195{
196 return block_ptr;
197}
198
199FcObjectPtr
200FcObjectSerialize (FcObjectPtr si)
201{
202 return si;
203}
204
205void
206FcObjectUnserialize (FcCache metadata, FcConfig * config, void *block_ptr)
207{
208}
209
210int
211FcObjectPtrCompare (const FcObjectPtr a, const FcObjectPtr b)
212{
213 return a - b;
214}
215
24330d27 216static const FcConstant _FcBaseConstants[] = {
81fa16c3
KP
217 { (FcChar8 *) "thin", "weight", FC_WEIGHT_THIN, },
218 { (FcChar8 *) "extralight", "weight", FC_WEIGHT_EXTRALIGHT, },
219 { (FcChar8 *) "ultralight", "weight", FC_WEIGHT_EXTRALIGHT, },
ccb3e93b 220 { (FcChar8 *) "light", "weight", FC_WEIGHT_LIGHT, },
1f71c4d8 221 { (FcChar8 *) "book", "weight", FC_WEIGHT_BOOK, },
81fa16c3 222 { (FcChar8 *) "regular", "weight", FC_WEIGHT_REGULAR, },
ccb3e93b
KP
223 { (FcChar8 *) "medium", "weight", FC_WEIGHT_MEDIUM, },
224 { (FcChar8 *) "demibold", "weight", FC_WEIGHT_DEMIBOLD, },
81fa16c3 225 { (FcChar8 *) "semibold", "weight", FC_WEIGHT_DEMIBOLD, },
ccb3e93b 226 { (FcChar8 *) "bold", "weight", FC_WEIGHT_BOLD, },
81fa16c3
KP
227 { (FcChar8 *) "extrabold", "weight", FC_WEIGHT_EXTRABOLD, },
228 { (FcChar8 *) "ultrabold", "weight", FC_WEIGHT_EXTRABOLD, },
ccb3e93b
KP
229 { (FcChar8 *) "black", "weight", FC_WEIGHT_BLACK, },
230
231 { (FcChar8 *) "roman", "slant", FC_SLANT_ROMAN, },
232 { (FcChar8 *) "italic", "slant", FC_SLANT_ITALIC, },
233 { (FcChar8 *) "oblique", "slant", FC_SLANT_OBLIQUE, },
234
81fa16c3
KP
235 { (FcChar8 *) "ultracondensed", "width", FC_WIDTH_ULTRACONDENSED },
236 { (FcChar8 *) "extracondensed", "width", FC_WIDTH_EXTRACONDENSED },
237 { (FcChar8 *) "condensed", "width", FC_WIDTH_CONDENSED },
238 { (FcChar8 *) "semicondensed", "width", FC_WIDTH_SEMICONDENSED },
239 { (FcChar8 *) "normal", "width", FC_WIDTH_NORMAL },
240 { (FcChar8 *) "semiexpanded", "width", FC_WIDTH_SEMIEXPANDED },
241 { (FcChar8 *) "expanded", "width", FC_WIDTH_EXPANDED },
242 { (FcChar8 *) "extraexpanded", "width", FC_WIDTH_EXTRAEXPANDED },
243 { (FcChar8 *) "ultraexpanded", "width", FC_WIDTH_ULTRAEXPANDED },
244
ccb3e93b 245 { (FcChar8 *) "proportional", "spacing", FC_PROPORTIONAL, },
a05d257f 246 { (FcChar8 *) "dual", "spacing", FC_DUAL, },
ccb3e93b
KP
247 { (FcChar8 *) "mono", "spacing", FC_MONO, },
248 { (FcChar8 *) "charcell", "spacing", FC_CHARCELL, },
249
1852d490 250 { (FcChar8 *) "unknown", "rgba", FC_RGBA_UNKNOWN },
ccb3e93b
KP
251 { (FcChar8 *) "rgb", "rgba", FC_RGBA_RGB, },
252 { (FcChar8 *) "bgr", "rgba", FC_RGBA_BGR, },
253 { (FcChar8 *) "vrgb", "rgba", FC_RGBA_VRGB },
254 { (FcChar8 *) "vbgr", "rgba", FC_RGBA_VBGR },
1852d490 255 { (FcChar8 *) "none", "rgba", FC_RGBA_NONE },
f077d662
OT
256
257 { (FcChar8 *) "hintnone", "hintstyle", FC_HINT_NONE },
258 { (FcChar8 *) "hintslight", "hintstyle", FC_HINT_SLIGHT },
259 { (FcChar8 *) "hintmedium", "hintstyle", FC_HINT_MEDIUM },
260 { (FcChar8 *) "hintfull", "hintstyle", FC_HINT_FULL },
24330d27
KP
261};
262
263#define NUM_FC_CONSTANTS (sizeof _FcBaseConstants/sizeof _FcBaseConstants[0])
264
265typedef struct _FcConstantList FcConstantList;
266
267struct _FcConstantList {
268 const FcConstantList *next;
269 const FcConstant *consts;
270 int nconsts;
271};
272
273static const FcConstantList _FcBaseConstantList = {
274 0,
275 _FcBaseConstants,
276 NUM_FC_CONSTANTS
277};
278
279static const FcConstantList *_FcConstants = &_FcBaseConstantList;
280
281FcBool
282FcNameRegisterConstants (const FcConstant *consts, int nconsts)
283{
284 FcConstantList *l;
285
286 l = (FcConstantList *) malloc (sizeof (FcConstantList));
287 if (!l)
288 return FcFalse;
9dac3c59 289 FcMemAlloc (FC_MEM_CONSTANT, sizeof (FcConstantList));
24330d27
KP
290 l->consts = consts;
291 l->nconsts = nconsts;
292 l->next = _FcConstants;
293 _FcConstants = l;
294 return FcTrue;
295}
296
297FcBool
298FcNameUnregisterConstants (const FcConstant *consts, int nconsts)
299{
300 const FcConstantList *l, **prev;
301
302 for (prev = &_FcConstants;
303 (l = *prev);
304 prev = (const FcConstantList **) &(l->next))
305 {
306 if (l->consts == consts && l->nconsts == nconsts)
307 {
308 *prev = l->next;
9dac3c59 309 FcMemFree (FC_MEM_CONSTANT, sizeof (FcConstantList));
24330d27
KP
310 free ((void *) l);
311 return FcTrue;
312 }
313 }
314 return FcFalse;
315}
316
317const FcConstant *
ccb3e93b 318FcNameGetConstant (FcChar8 *string)
24330d27
KP
319{
320 const FcConstantList *l;
321 int i;
94421e40 322
24330d27
KP
323 for (l = _FcConstants; l; l = l->next)
324 {
325 for (i = 0; i < l->nconsts; i++)
326 if (!FcStrCmpIgnoreCase (string, l->consts[i].name))
327 return &l->consts[i];
328 }
329 return 0;
330}
331
332FcBool
ccb3e93b 333FcNameConstant (FcChar8 *string, int *result)
24330d27
KP
334{
335 const FcConstant *c;
336
337 if ((c = FcNameGetConstant(string)))
338 {
339 *result = c->value;
340 return FcTrue;
341 }
342 return FcFalse;
343}
344
345FcBool
ca60d2b5 346FcNameBool (const FcChar8 *v, FcBool *result)
24330d27
KP
347{
348 char c0, c1;
349
350 c0 = *v;
94421e40 351 c0 = FcToLower (c0);
24330d27
KP
352 if (c0 == 't' || c0 == 'y' || c0 == '1')
353 {
354 *result = FcTrue;
355 return FcTrue;
356 }
357 if (c0 == 'f' || c0 == 'n' || c0 == '0')
358 {
359 *result = FcFalse;
360 return FcTrue;
361 }
362 if (c0 == 'o')
363 {
364 c1 = v[1];
94421e40 365 c1 = FcToLower (c1);
24330d27
KP
366 if (c1 == 'n')
367 {
368 *result = FcTrue;
369 return FcTrue;
370 }
371 if (c1 == 'f')
372 {
373 *result = FcFalse;
374 return FcTrue;
375 }
376 }
377 return FcFalse;
378}
379
380static FcValue
ccb3e93b 381FcNameConvert (FcType type, FcChar8 *string, FcMatrix *m)
24330d27
KP
382{
383 FcValue v;
384
385 v.type = type;
386 switch (v.type) {
387 case FcTypeInteger:
388 if (!FcNameConstant (string, &v.u.i))
ccb3e93b 389 v.u.i = atoi ((char *) string);
24330d27
KP
390 break;
391 case FcTypeString:
4262e0b3 392 v.u.s = FcObjectStaticName(string);
24330d27
KP
393 break;
394 case FcTypeBool:
395 if (!FcNameBool (string, &v.u.b))
396 v.u.b = FcFalse;
397 break;
398 case FcTypeDouble:
ccb3e93b 399 v.u.d = strtod ((char *) string, 0);
24330d27
KP
400 break;
401 case FcTypeMatrix:
4262e0b3 402 v.u.m = m;
ccb3e93b 403 sscanf ((char *) string, "%lg %lg %lg %lg", &m->xx, &m->xy, &m->yx, &m->yy);
24330d27
KP
404 break;
405 case FcTypeCharSet:
4262e0b3 406 v.u.c = FcNameParseCharSet (string);
24330d27 407 break;
d8d73958 408 case FcTypeLangSet:
4262e0b3 409 v.u.l = FcNameParseLangSet (string);
d8d73958 410 break;
24330d27
KP
411 default:
412 break;
413 }
414 return v;
415}
416
ccb3e93b
KP
417static const FcChar8 *
418FcNameFindNext (const FcChar8 *cur, const char *delim, FcChar8 *save, FcChar8 *last)
24330d27 419{
ccb3e93b 420 FcChar8 c;
24330d27
KP
421
422 while ((c = *cur))
423 {
424 if (c == '\\')
425 {
426 ++cur;
427 if (!(c = *cur))
428 break;
429 }
430 else if (strchr (delim, c))
431 break;
432 ++cur;
433 *save++ = c;
434 }
435 *save = 0;
436 *last = *cur;
437 if (*cur)
438 cur++;
439 return cur;
440}
441
442FcPattern *
ccb3e93b 443FcNameParse (const FcChar8 *name)
24330d27 444{
ccb3e93b 445 FcChar8 *save;
24330d27
KP
446 FcPattern *pat;
447 double d;
ccb3e93b
KP
448 FcChar8 *e;
449 FcChar8 delim;
24330d27
KP
450 FcValue v;
451 FcMatrix m;
452 const FcObjectType *t;
453 const FcConstant *c;
454
9dac3c59 455 /* freed below */
ccb3e93b 456 save = malloc (strlen ((char *) name) + 1);
24330d27
KP
457 if (!save)
458 goto bail0;
459 pat = FcPatternCreate ();
460 if (!pat)
461 goto bail1;
462
463 for (;;)
464 {
465 name = FcNameFindNext (name, "-,:", save, &delim);
466 if (save[0])
467 {
468 if (!FcPatternAddString (pat, FC_FAMILY, save))
469 goto bail2;
470 }
471 if (delim != ',')
472 break;
473 }
474 if (delim == '-')
475 {
476 for (;;)
477 {
478 name = FcNameFindNext (name, "-,:", save, &delim);
ccb3e93b 479 d = strtod ((char *) save, (char **) &e);
24330d27
KP
480 if (e != save)
481 {
482 if (!FcPatternAddDouble (pat, FC_SIZE, d))
483 goto bail2;
484 }
485 if (delim != ',')
486 break;
487 }
488 }
489 while (delim == ':')
490 {
491 name = FcNameFindNext (name, "=_:", save, &delim);
492 if (save[0])
493 {
494 if (delim == '=' || delim == '_')
495 {
ccb3e93b 496 t = FcNameGetObjectType ((char *) save);
24330d27
KP
497 for (;;)
498 {
499 name = FcNameFindNext (name, ":,", save, &delim);
c552f59b 500 if (t)
24330d27
KP
501 {
502 v = FcNameConvert (t->type, save, &m);
503 if (!FcPatternAdd (pat, t->object, v, FcTrue))
504 {
d8d73958
KP
505 switch (v.type) {
506 case FcTypeCharSet:
4262e0b3 507 FcCharSetDestroy ((FcCharSet *) v.u.c);
d8d73958
KP
508 break;
509 case FcTypeLangSet:
4262e0b3 510 FcLangSetDestroy ((FcLangSet *) v.u.l);
d8d73958
KP
511 break;
512 default:
513 break;
514 }
24330d27
KP
515 goto bail2;
516 }
d8d73958
KP
517 switch (v.type) {
518 case FcTypeCharSet:
4262e0b3 519 FcCharSetDestroy ((FcCharSet *) v.u.c);
d8d73958
KP
520 break;
521 case FcTypeLangSet:
4262e0b3 522 FcLangSetDestroy ((FcLangSet *) v.u.l);
d8d73958
KP
523 break;
524 default:
525 break;
526 }
24330d27
KP
527 }
528 if (delim != ',')
529 break;
530 }
531 }
532 else
533 {
534 if ((c = FcNameGetConstant (save)))
535 {
536 if (!FcPatternAddInteger (pat, c->object, c->value))
537 goto bail2;
538 }
539 }
540 }
541 }
542
543 free (save);
544 return pat;
545
546bail2:
547 FcPatternDestroy (pat);
548bail1:
549 free (save);
550bail0:
551 return 0;
552}
24330d27 553static FcBool
c2e7c611 554FcNameUnparseString (FcStrBuf *buf,
24330d27
KP
555 const FcChar8 *string,
556 const FcChar8 *escape)
557{
558 FcChar8 c;
559 while ((c = *string++))
560 {
561 if (escape && strchr ((char *) escape, (char) c))
562 {
c2e7c611 563 if (!FcStrBufChar (buf, escape[0]))
24330d27
KP
564 return FcFalse;
565 }
c2e7c611 566 if (!FcStrBufChar (buf, c))
24330d27
KP
567 return FcFalse;
568 }
569 return FcTrue;
570}
571
572static FcBool
c2e7c611 573FcNameUnparseValue (FcStrBuf *buf,
4262e0b3
PL
574 int bank,
575 FcValue *v0,
24330d27
KP
576 FcChar8 *escape)
577{
578 FcChar8 temp[1024];
4262e0b3 579 FcValue v = FcValueCanonicalize(v0);
24330d27
KP
580
581 switch (v.type) {
582 case FcTypeVoid:
583 return FcTrue;
584 case FcTypeInteger:
585 sprintf ((char *) temp, "%d", v.u.i);
586 return FcNameUnparseString (buf, temp, 0);
587 case FcTypeDouble:
588 sprintf ((char *) temp, "%g", v.u.d);
589 return FcNameUnparseString (buf, temp, 0);
590 case FcTypeString:
4262e0b3 591 return FcNameUnparseString (buf, v.u.s, escape);
24330d27 592 case FcTypeBool:
ccb3e93b 593 return FcNameUnparseString (buf, v.u.b ? (FcChar8 *) "True" : (FcChar8 *) "False", 0);
24330d27
KP
594 case FcTypeMatrix:
595 sprintf ((char *) temp, "%g %g %g %g",
4262e0b3 596 v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy);
24330d27
KP
597 return FcNameUnparseString (buf, temp, 0);
598 case FcTypeCharSet:
4262e0b3 599 return FcNameUnparseCharSet (buf, v.u.c);
d8d73958 600 case FcTypeLangSet:
4262e0b3 601 return FcNameUnparseLangSet (buf, v.u.l);
88c747e2
KP
602 case FcTypeFTFace:
603 return FcTrue;
24330d27
KP
604 }
605 return FcFalse;
606}
607
608static FcBool
c2e7c611 609FcNameUnparseValueList (FcStrBuf *buf,
cd2ec1a9 610 FcValueListPtr v,
ccb3e93b 611 FcChar8 *escape)
24330d27 612{
cd2ec1a9 613 while (FcValueListPtrU(v))
24330d27 614 {
4262e0b3 615 if (!FcNameUnparseValue (buf, v.bank, &FcValueListPtrU(v)->value, escape))
24330d27 616 return FcFalse;
cd2ec1a9 617 if (FcValueListPtrU(v = FcValueListPtrU(v)->next))
ccb3e93b 618 if (!FcNameUnparseString (buf, (FcChar8 *) ",", 0))
24330d27
KP
619 return FcFalse;
620 }
621 return FcTrue;
622}
623
624#define FC_ESCAPE_FIXED "\\-:,"
625#define FC_ESCAPE_VARIABLE "\\=_:,"
626
627FcChar8 *
628FcNameUnparse (FcPattern *pat)
629{
c2e7c611 630 FcStrBuf buf;
24330d27
KP
631 FcChar8 buf_static[8192];
632 int i;
633 FcPatternElt *e;
634 const FcObjectTypeList *l;
635 const FcObjectType *o;
636
c2e7c611 637 FcStrBufInit (&buf, buf_static, sizeof (buf_static));
e9be9cd1 638 e = FcPatternFindElt (pat, FC_FAMILY);
24330d27
KP
639 if (e)
640 {
ccb3e93b 641 if (!FcNameUnparseValueList (&buf, e->values, (FcChar8 *) FC_ESCAPE_FIXED))
24330d27
KP
642 goto bail0;
643 }
e9be9cd1 644 e = FcPatternFindElt (pat, FC_SIZE);
24330d27
KP
645 if (e)
646 {
ccb3e93b 647 if (!FcNameUnparseString (&buf, (FcChar8 *) "-", 0))
24330d27 648 goto bail0;
ccb3e93b 649 if (!FcNameUnparseValueList (&buf, e->values, (FcChar8 *) FC_ESCAPE_FIXED))
24330d27
KP
650 goto bail0;
651 }
652 for (l = _FcObjectTypes; l; l = l->next)
653 {
654 for (i = 0; i < l->ntypes; i++)
655 {
656 o = &l->types[i];
657 if (!strcmp (o->object, FC_FAMILY) ||
658 !strcmp (o->object, FC_SIZE) ||
659 !strcmp (o->object, FC_FILE))
660 continue;
661
e9be9cd1 662 e = FcPatternFindElt (pat, o->object);
24330d27
KP
663 if (e)
664 {
ccb3e93b 665 if (!FcNameUnparseString (&buf, (FcChar8 *) ":", 0))
24330d27 666 goto bail0;
ccb3e93b 667 if (!FcNameUnparseString (&buf, (FcChar8 *) o->object, (FcChar8 *) FC_ESCAPE_VARIABLE))
24330d27 668 goto bail0;
ccb3e93b 669 if (!FcNameUnparseString (&buf, (FcChar8 *) "=", 0))
24330d27
KP
670 goto bail0;
671 if (!FcNameUnparseValueList (&buf, e->values,
ccb3e93b 672 (FcChar8 *) FC_ESCAPE_VARIABLE))
24330d27
KP
673 goto bail0;
674 }
675 }
676 }
c2e7c611 677 return FcStrBufDone (&buf);
24330d27 678bail0:
c2e7c611 679 FcStrBufDestroy (&buf);
24330d27
KP
680 return 0;
681}