Debian Codegraph @

src/fcfs.c

raw
1 /*
2 * fontconfig/src/fcfs.c
3 *
4 * Copyright © 2000 Keith Packard
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 the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make 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 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) 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 "fcint.h"
26
27 #include <stdlib.h>
28
29 FcFontSet *
30 FcFontSetCreate (void)
31 {
32 FcFontSet *s;
33
34 s = (FcFontSet *)malloc (sizeof (FcFontSet));
35 if (!s)
36 return 0;
37 s->nfont = 0;
38 s->sfont = 0;
39 s->fonts = 0;
40 return s;
41 }
42
43 void
44 FcFontSetDestroy (FcFontSet *s)
45 {
46 if (s) {
47 int i;
48
49 for (i = 0; i < s->nfont; i++)
50 FcPatternDestroy (s->fonts[i]);
51 if (s->fonts)
52 free (s->fonts);
53 free (s);
54 }
55 }
56
57 FcBool
58 FcFontSetAdd (FcFontSet *s, FcPattern *font)
59 {
60 FcPattern **f;
61 int sfont;
62
63 if (s->nfont == s->sfont) {
64 sfont = s->sfont + 32;
65 if (s->fonts)
66 f = (FcPattern **)realloc (s->fonts, sfont * sizeof (FcPattern *));
67 else
68 f = (FcPattern **)malloc (sfont * sizeof (FcPattern *));
69 if (!f)
70 return FcFalse;
71 s->sfont = sfont;
72 s->fonts = f;
73 }
74 s->fonts[s->nfont++] = font;
75 return FcTrue;
76 }
77
78 FcBool
79 FcFontSetSerializeAlloc (FcSerialize *serialize, const FcFontSet *s)
80 {
81 int i;
82
83 if (!FcSerializeAlloc (serialize, s, sizeof (FcFontSet)))
84 return FcFalse;
85 if (!FcSerializeAlloc (serialize, s->fonts, s->nfont * sizeof (FcPattern *)))
86 return FcFalse;
87 for (i = 0; i < s->nfont; i++) {
88 if (!FcPatternSerializeAlloc (serialize, s->fonts[i]))
89 return FcFalse;
90 }
91 return FcTrue;
92 }
93
94 FcFontSet *
95 FcFontSetSerialize (FcSerialize *serialize, const FcFontSet *s)
96 {
97 int i;
98 FcFontSet *s_serialize;
99 FcPattern **fonts_serialize;
100 FcPattern *p_serialize;
101
102 s_serialize = FcSerializePtr (serialize, s);
103 if (!s_serialize)
104 return NULL;
105 *s_serialize = *s;
106 s_serialize->sfont = s_serialize->nfont;
107
108 fonts_serialize = FcSerializePtr (serialize, s->fonts);
109 if (!fonts_serialize)
110 return NULL;
111 s_serialize->fonts = FcPtrToEncodedOffset (s_serialize,
112 fonts_serialize, FcPattern *);
113
114 for (i = 0; i < s->nfont; i++) {
115 p_serialize = FcPatternSerialize (serialize, s->fonts[i]);
116 if (!p_serialize)
117 return NULL;
118 fonts_serialize[i] = FcPtrToEncodedOffset (s_serialize,
119 p_serialize,
120 FcPattern);
121 }
122
123 return s_serialize;
124 }
125
126 FcFontSet *
127 FcFontSetDeserialize (const FcFontSet *set)
128 {
129 int i;
130 FcFontSet *newp = FcFontSetCreate();
131
132 if (!newp)
133 return NULL;
134 for (i = 0; i < set->nfont; i++) {
135 if (!FcFontSetAdd (newp, FcPatternDuplicate (FcFontSetFont (set, i))))
136 goto bail;
137 }
138
139 return newp;
140 bail:
141 FcFontSetDestroy (newp);
142
143 return NULL;
144 }
145
146 #define __fcfs__
147 #include "fcaliastail.h"
148 #undef __fcfs__