]>
git.wh0rd.org - fontconfig.git/blob - src/fcpat.c
4 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
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.
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.
30 FcPatternCreate (void)
34 p
= (FcPattern
*) malloc (sizeof (FcPattern
));
37 FcMemAlloc (FC_MEM_PATTERN
, sizeof (FcPattern
));
45 FcValueDestroy (FcValue v
)
49 FcStrFree ((FcChar8
*) v
.u
.s
);
52 FcMatrixFree ((FcMatrix
*) v
.u
.m
);
55 FcCharSetDestroy ((FcCharSet
*) v
.u
.c
);
63 FcValueSave (FcValue v
)
67 v
.u
.s
= FcStrCopy (v
.u
.s
);
72 v
.u
.m
= FcMatrixCopy (v
.u
.m
);
77 v
.u
.c
= FcCharSetCopy ((FcCharSet
*) v
.u
.c
);
88 FcValueListDestroy (FcValueList
*l
)
93 switch (l
->value
.type
) {
95 FcStrFree ((FcChar8
*) l
->value
.u
.s
);
98 FcMatrixFree ((FcMatrix
*) l
->value
.u
.m
);
101 FcCharSetDestroy ((FcCharSet
*) l
->value
.u
.c
);
107 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
113 FcPatternDestroy (FcPattern
*p
)
117 for (i
= 0; i
< p
->num
; i
++)
118 FcValueListDestroy (p
->elts
[i
].values
);
123 FcMemFree (FC_MEM_PATELT
, p
->size
* sizeof (FcPatternElt
));
128 FcMemFree (FC_MEM_PATTERN
, sizeof (FcPattern
));
133 FcPatternFind (FcPattern
*p
, const char *object
, FcBool insert
)
140 for (i
= 0; i
< p
->num
; i
++)
142 if (!FcStrCmpIgnoreCase ((FcChar8
*) object
, (FcChar8
*) p
->elts
[i
].object
))
154 e
= (FcPatternElt
*) realloc (p
->elts
, s
* sizeof (FcPatternElt
));
156 e
= (FcPatternElt
*) malloc (s
* sizeof (FcPatternElt
));
161 FcMemFree (FC_MEM_PATELT
, p
->size
* sizeof (FcPatternElt
));
162 FcMemAlloc (FC_MEM_PATELT
, s
* sizeof (FcPatternElt
));
165 p
->elts
[p
->size
].object
= 0;
166 p
->elts
[p
->size
].values
= 0;
174 p
->elts
[i
].object
= object
;
180 FcPatternAdd (FcPattern
*p
, const char *object
, FcValue value
, FcBool append
)
183 FcValueList
*new, **prev
;
185 new = (FcValueList
*) malloc (sizeof (FcValueList
));
189 FcMemAlloc (FC_MEM_VALLIST
, sizeof (FcValueList
));
191 value
= FcValueSave (value
);
192 if (value
.type
== FcTypeVoid
)
198 e
= FcPatternFind (p
, object
, FcTrue
);
204 for (prev
= &e
->values
; *prev
; prev
= &(*prev
)->next
);
209 new->next
= e
->values
;
216 switch (value
.type
) {
218 FcStrFree ((FcChar8
*) value
.u
.s
);
221 FcMatrixFree ((FcMatrix
*) value
.u
.m
);
224 FcCharSetDestroy ((FcCharSet
*) value
.u
.c
);
230 FcMemFree (FC_MEM_VALLIST
, sizeof (FcValueList
));
237 FcPatternDel (FcPattern
*p
, const char *object
)
242 e
= FcPatternFind (p
, object
, FcFalse
);
249 FcValueListDestroy (e
->values
);
251 /* shuffle existing ones down */
252 memmove (e
, e
+1, (p
->elts
+ p
->num
- (e
+ 1)) * sizeof (FcPatternElt
));
254 p
->elts
[p
->num
].object
= 0;
255 p
->elts
[p
->num
].values
= 0;
260 FcPatternAddInteger (FcPattern
*p
, const char *object
, int i
)
264 v
.type
= FcTypeInteger
;
266 return FcPatternAdd (p
, object
, v
, FcTrue
);
270 FcPatternAddDouble (FcPattern
*p
, const char *object
, double d
)
274 v
.type
= FcTypeDouble
;
276 return FcPatternAdd (p
, object
, v
, FcTrue
);
281 FcPatternAddString (FcPattern
*p
, const char *object
, const FcChar8
*s
)
285 v
.type
= FcTypeString
;
287 return FcPatternAdd (p
, object
, v
, FcTrue
);
291 FcPatternAddMatrix (FcPattern
*p
, const char *object
, const FcMatrix
*s
)
295 v
.type
= FcTypeMatrix
;
296 v
.u
.m
= (FcMatrix
*) s
;
297 return FcPatternAdd (p
, object
, v
, FcTrue
);
302 FcPatternAddBool (FcPattern
*p
, const char *object
, FcBool b
)
308 return FcPatternAdd (p
, object
, v
, FcTrue
);
312 FcPatternAddCharSet (FcPattern
*p
, const char *object
, const FcCharSet
*c
)
316 v
.type
= FcTypeCharSet
;
317 v
.u
.c
= (FcCharSet
*) c
;
318 return FcPatternAdd (p
, object
, v
, FcTrue
);
322 FcPatternGet (FcPattern
*p
, const char *object
, int id
, FcValue
*v
)
327 e
= FcPatternFind (p
, object
, FcFalse
);
329 return FcResultNoMatch
;
330 for (l
= e
->values
; l
; l
= l
->next
)
335 return FcResultMatch
;
343 FcPatternGetInteger (FcPattern
*p
, const char *object
, int id
, int *i
)
348 r
= FcPatternGet (p
, object
, id
, &v
);
349 if (r
!= FcResultMatch
)
359 return FcResultTypeMismatch
;
361 return FcResultMatch
;
365 FcPatternGetDouble (FcPattern
*p
, const char *object
, int id
, double *d
)
370 r
= FcPatternGet (p
, object
, id
, &v
);
371 if (r
!= FcResultMatch
)
381 return FcResultTypeMismatch
;
383 return FcResultMatch
;
387 FcPatternGetString (FcPattern
*p
, const char *object
, int id
, FcChar8
const ** s
)
392 r
= FcPatternGet (p
, object
, id
, &v
);
393 if (r
!= FcResultMatch
)
395 if (v
.type
!= FcTypeString
)
396 return FcResultTypeMismatch
;
398 return FcResultMatch
;
402 FcPatternGetMatrix (FcPattern
*p
, const char *object
, int id
, FcMatrix
**m
)
407 r
= FcPatternGet (p
, object
, id
, &v
);
408 if (r
!= FcResultMatch
)
410 if (v
.type
!= FcTypeMatrix
)
411 return FcResultTypeMismatch
;
412 *m
= (FcMatrix
*) v
.u
.m
;
413 return FcResultMatch
;
418 FcPatternGetBool (FcPattern
*p
, const char *object
, int id
, FcBool
*b
)
423 r
= FcPatternGet (p
, object
, id
, &v
);
424 if (r
!= FcResultMatch
)
426 if (v
.type
!= FcTypeBool
)
427 return FcResultTypeMismatch
;
429 return FcResultMatch
;
433 FcPatternGetCharSet (FcPattern
*p
, const char *object
, int id
, FcCharSet
**c
)
438 r
= FcPatternGet (p
, object
, id
, &v
);
439 if (r
!= FcResultMatch
)
441 if (v
.type
!= FcTypeCharSet
)
442 return FcResultTypeMismatch
;
443 *c
= (FcCharSet
*) v
.u
.c
;
444 return FcResultMatch
;
448 FcPatternDuplicate (FcPattern
*orig
)
454 new = FcPatternCreate ();
458 for (i
= 0; i
< orig
->num
; i
++)
460 for (l
= orig
->elts
[i
].values
; l
; l
= l
->next
)
461 if (!FcPatternAdd (new, orig
->elts
[i
].object
, l
->value
, FcTrue
))
468 FcPatternDestroy (new);
474 FcPatternVaBuild (FcPattern
*orig
, va_list va
)
478 FcPatternVapBuild (ret
, orig
, va
);
483 FcPatternBuild (FcPattern
*orig
, ...)
488 FcPatternVapBuild (orig
, orig
, va
);