/work/workdir/UnpackedTarball/fontconfig/src/fcfs.c
Line | Count | Source (jump to first uncovered line) |
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 | 637 | { |
32 | 637 | FcFontSet *s; |
33 | | |
34 | 637 | s = (FcFontSet *)malloc (sizeof (FcFontSet)); |
35 | 637 | if (!s) |
36 | 0 | return 0; |
37 | 637 | s->nfont = 0; |
38 | 637 | s->sfont = 0; |
39 | 637 | s->fonts = 0; |
40 | 637 | return s; |
41 | 637 | } |
42 | | |
43 | | void |
44 | | FcFontSetDestroy (FcFontSet *s) |
45 | 107 | { |
46 | 107 | if (s) { |
47 | 107 | int i; |
48 | | |
49 | 1.49k | for (i = 0; i < s->nfont; i++) |
50 | 1.39k | FcPatternDestroy (s->fonts[i]); |
51 | 107 | if (s->fonts) |
52 | 107 | free (s->fonts); |
53 | 107 | free (s); |
54 | 107 | } |
55 | 107 | } |
56 | | |
57 | | FcBool |
58 | | FcFontSetAdd (FcFontSet *s, FcPattern *font) |
59 | 4.04k | { |
60 | 4.04k | FcPattern **f; |
61 | 4.04k | int sfont; |
62 | | |
63 | 4.04k | if (s->nfont == s->sfont) { |
64 | 319 | sfont = s->sfont + 32; |
65 | 319 | if (s->fonts) |
66 | 0 | f = (FcPattern **)realloc (s->fonts, sfont * sizeof (FcPattern *)); |
67 | 319 | else |
68 | 319 | f = (FcPattern **)malloc (sfont * sizeof (FcPattern *)); |
69 | 319 | if (!f) |
70 | 0 | return FcFalse; |
71 | 319 | s->sfont = sfont; |
72 | 319 | s->fonts = f; |
73 | 319 | } |
74 | 4.04k | s->fonts[s->nfont++] = font; |
75 | 4.04k | return FcTrue; |
76 | 4.04k | } |
77 | | |
78 | | FcBool |
79 | | FcFontSetSerializeAlloc (FcSerialize *serialize, const FcFontSet *s) |
80 | 1 | { |
81 | 1 | int i; |
82 | | |
83 | 1 | if (!FcSerializeAlloc (serialize, s, sizeof (FcFontSet))) |
84 | 0 | return FcFalse; |
85 | 1 | if (!FcSerializeAlloc (serialize, s->fonts, s->nfont * sizeof (FcPattern *))) |
86 | 0 | return FcFalse; |
87 | 14 | for (i = 0; i < s->nfont; i++) { |
88 | 13 | if (!FcPatternSerializeAlloc (serialize, s->fonts[i])) |
89 | 0 | return FcFalse; |
90 | 13 | } |
91 | 1 | return FcTrue; |
92 | 1 | } |
93 | | |
94 | | FcFontSet * |
95 | | FcFontSetSerialize (FcSerialize *serialize, const FcFontSet *s) |
96 | 1 | { |
97 | 1 | int i; |
98 | 1 | FcFontSet *s_serialize; |
99 | 1 | FcPattern **fonts_serialize; |
100 | 1 | FcPattern *p_serialize; |
101 | | |
102 | 1 | s_serialize = FcSerializePtr (serialize, s); |
103 | 1 | if (!s_serialize) |
104 | 0 | return NULL; |
105 | 1 | *s_serialize = *s; |
106 | 1 | s_serialize->sfont = s_serialize->nfont; |
107 | | |
108 | 1 | fonts_serialize = FcSerializePtr (serialize, s->fonts); |
109 | 1 | if (!fonts_serialize) |
110 | 0 | return NULL; |
111 | 1 | s_serialize->fonts = FcPtrToEncodedOffset (s_serialize, |
112 | 1 | fonts_serialize, FcPattern *); |
113 | | |
114 | 14 | for (i = 0; i < s->nfont; i++) { |
115 | 13 | p_serialize = FcPatternSerialize (serialize, s->fonts[i]); |
116 | 13 | if (!p_serialize) |
117 | 0 | return NULL; |
118 | 13 | fonts_serialize[i] = FcPtrToEncodedOffset (s_serialize, |
119 | 13 | p_serialize, |
120 | 13 | FcPattern); |
121 | 13 | } |
122 | | |
123 | 1 | return s_serialize; |
124 | 1 | } |
125 | | |
126 | | FcFontSet * |
127 | | FcFontSetDeserialize (const FcFontSet *set) |
128 | 0 | { |
129 | 0 | int i; |
130 | 0 | FcFontSet *newp = FcFontSetCreate(); |
131 | |
|
132 | 0 | if (!newp) |
133 | 0 | return NULL; |
134 | 0 | for (i = 0; i < set->nfont; i++) { |
135 | 0 | if (!FcFontSetAdd (newp, FcPatternDuplicate (FcFontSetFont (set, i)))) |
136 | 0 | goto bail; |
137 | 0 | } |
138 | | |
139 | 0 | return newp; |
140 | 0 | bail: |
141 | 0 | FcFontSetDestroy (newp); |
142 | |
|
143 | 0 | return NULL; |
144 | 0 | } |
145 | | |
146 | | #define __fcfs__ |
147 | | #include "fcaliastail.h" |
148 | | #undef __fcfs__ |