]>
git.wh0rd.org - fontconfig.git/blob - src/fcfs.c
4 * Copyright © 2000 Keith Packard
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.
29 FcFontSetCreate (void)
33 s
= (FcFontSet
*) malloc (sizeof (FcFontSet
));
36 FcMemAlloc (FC_MEM_FONTSET
, sizeof (FcFontSet
));
44 FcFontSetDestroy (FcFontSet
*s
)
48 for (i
= 0; i
< s
->nfont
; i
++)
49 FcPatternDestroy (s
->fonts
[i
]);
52 FcMemFree (FC_MEM_FONTPTR
, s
->sfont
* sizeof (FcPattern
*));
55 FcMemFree (FC_MEM_FONTSET
, sizeof (FcFontSet
));
60 FcFontSetAdd (FcFontSet
*s
, FcPattern
*font
)
65 if (s
->nfont
== s
->sfont
)
67 sfont
= s
->sfont
+ 32;
69 f
= (FcPattern
**) realloc (s
->fonts
, sfont
* sizeof (FcPattern
*));
71 f
= (FcPattern
**) malloc (sfont
* sizeof (FcPattern
*));
75 FcMemFree (FC_MEM_FONTPTR
, s
->sfont
* sizeof (FcPattern
*));
76 FcMemAlloc (FC_MEM_FONTPTR
, sfont
* sizeof (FcPattern
*));
80 s
->fonts
[s
->nfont
++] = font
;
85 FcFontSetPrepareSerialize (FcFontSet
*s
)
89 for (i
= 0; i
< s
->nfont
; i
++)
90 if (!FcPatternPrepareSerialize(s
->fonts
[i
]))
97 FcFontSetSerialize (FcFontSet
* s
)
102 for (i
= 0; i
< s
->nfont
; i
++)
104 p
= FcPatternSerialize (s
->fonts
[i
]);
105 if (!p
) return FcFalse
;
106 FcPatternDestroy (s
->fonts
[i
]);
115 FcFontSetClearStatic (void)
117 FcPatternClearStatic();
121 FcFontSetRead(int fd
, FcConfig
* config
, FcCache metadata
)
126 lseek(fd
, metadata
.fontsets_offset
, SEEK_SET
);
127 for (i
= FcSetSystem
; i
<= FcSetApplication
; i
++)
129 if (config
->fonts
[i
])
131 if (config
->fonts
[i
]->nfont
> 0 && config
->fonts
[i
]->fonts
)
132 free (config
->fonts
[i
]->fonts
);
133 free (config
->fonts
[i
]);
137 for (i
= FcSetSystem
; i
<= FcSetApplication
; i
++)
139 read(fd
, &mz
, sizeof(int));
140 if (mz
!= FC_CACHE_MAGIC
)
143 config
->fonts
[i
] = malloc(sizeof(FcFontSet
));
144 if (!config
->fonts
[i
])
146 FcMemAlloc(FC_MEM_FONTSET
, sizeof(FcFontSet
));
148 if (read(fd
, config
->fonts
[i
], sizeof(FcFontSet
)) == -1)
150 if (config
->fonts
[i
]->sfont
> 0)
152 config
->fonts
[i
]->fonts
= malloc
153 (config
->fonts
[i
]->sfont
*sizeof(FcPattern
*));
154 buf
= malloc (config
->fonts
[i
]->sfont
* sizeof(FcPattern
));
155 if (!config
->fonts
[i
]->fonts
|| !buf
)
157 for (j
= 0; j
< config
->fonts
[i
]->nfont
; j
++)
159 config
->fonts
[i
]->fonts
[j
] = buf
+j
;
160 if (read(fd
, buf
+j
, sizeof(FcPattern
)) == -1)
168 for (i
= FcSetSystem
; i
<= FcSetApplication
; i
++)
170 if (config
->fonts
[i
])
172 if (config
->fonts
[i
]->fonts
)
173 free (config
->fonts
[i
]->fonts
);
174 free(config
->fonts
[i
]);
176 config
->fonts
[i
] = 0;
182 FcFontSetWrite(int fd
, FcConfig
* config
, FcCache
* metadata
)
185 int m
= FC_CACHE_MAGIC
, z
= 0;
187 metadata
->fontsets_offset
= FcCacheNextOffset(fd
);
188 lseek(fd
, metadata
->fontsets_offset
, SEEK_SET
);
189 for (i
= FcSetSystem
; i
<= FcSetApplication
; i
++)
191 if (!config
->fonts
[i
])
193 write(fd
, &z
, sizeof(int));
197 write(fd
, &m
, sizeof(int));
199 if ((c
= write(fd
, config
->fonts
[i
], sizeof(FcFontSet
))) == -1)
202 if (config
->fonts
[i
]->nfont
> 0)
204 for (j
= 0; j
< config
->fonts
[i
]->nfont
; j
++)
206 if ((c
= write(fd
, config
->fonts
[i
]->fonts
[j
],
207 sizeof(FcPattern
))) == -1)