diff options
author | Patrick Lam <plam@MIT.EDU> | 2005-07-25 04:10:09 +0000 |
---|---|---|
committer | Patrick Lam <plam@MIT.EDU> | 2005-07-25 04:10:09 +0000 |
commit | 212c9f437e959fbdc5fe344c67b8c1cf8ca63edb (patch) | |
tree | a5a82c8017ff6461dd8bdb4bb3e218af91b22ee6 /src/fcfs.c | |
parent | e1b9d091c661b0e1d1e9f73c5c55ad53959c55c7 (diff) | |
download | fontconfig-212c9f437e959fbdc5fe344c67b8c1cf8ca63edb.tar.gz |
#ifdef out old cache stuff, replace with first version of new mmapping
cache. Add *Read and *Write procedures which mmap in and write out the
fontconfig data structures to disk. Currently, create cache in /tmp,
with different sections for each architecture (as returned by uname's
.machine field. Run the fc-cache binary to create a new cache file;
fontconfig then uses this cache file on subsequent runs, saving lots of
memory. Also fixes a few bugs and leaks.
Diffstat (limited to 'src/fcfs.c')
-rw-r--r-- | src/fcfs.c | 95 |
1 files changed, 95 insertions, 0 deletions
@@ -116,3 +116,98 @@ FcFontSetClearStatic (void) { FcPatternClearStatic(); } + +FcBool +FcFontSetRead(int fd, FcConfig * config, FcCache metadata) +{ + int i, mz, j; + FcPattern * buf; + + lseek(fd, metadata.fontsets_offset, SEEK_SET); + for (i = FcSetSystem; i <= FcSetApplication; i++) + { + if (config->fonts[i]) + { + if (config->fonts[i]->nfont > 0 && config->fonts[i]->fonts) + free (config->fonts[i]->fonts); + free (config->fonts[i]); + } + } + + for (i = FcSetSystem; i <= FcSetApplication; i++) + { + read(fd, &mz, sizeof(int)); + if (mz != FC_CACHE_MAGIC) + continue; + + config->fonts[i] = malloc(sizeof(FcFontSet)); + if (!config->fonts[i]) + return FcFalse; + FcMemAlloc(FC_MEM_FONTSET, sizeof(FcFontSet)); + + if (read(fd, config->fonts[i], sizeof(FcFontSet)) == -1) + goto bail; + if (config->fonts[i]->sfont > 0) + { + config->fonts[i]->fonts = malloc + (config->fonts[i]->sfont*sizeof(FcPattern *)); + buf = malloc (config->fonts[i]->sfont * sizeof(FcPattern)); + if (!config->fonts[i]->fonts || !buf) + goto bail; + for (j = 0; j < config->fonts[i]->nfont; j++) + { + config->fonts[i]->fonts[j] = buf+j; + if (read(fd, buf+j, sizeof(FcPattern)) == -1) + goto bail; + } + } + } + + return FcTrue; + bail: + for (i = FcSetSystem; i <= FcSetApplication; i++) + { + if (config->fonts[i]) + { + if (config->fonts[i]->fonts) + free (config->fonts[i]->fonts); + free(config->fonts[i]); + } + config->fonts[i] = 0; + } + return FcFalse; +} + +FcBool +FcFontSetWrite(int fd, FcConfig * config, FcCache * metadata) +{ + int c, t, i, j; + int m = FC_CACHE_MAGIC, z = 0; + + metadata->fontsets_offset = FcCacheNextOffset(fd); + lseek(fd, metadata->fontsets_offset, SEEK_SET); + for (i = FcSetSystem; i <= FcSetApplication; i++) + { + if (!config->fonts[i]) + { + write(fd, &z, sizeof(int)); + continue; + } + else + write(fd, &m, sizeof(int)); + + if ((c = write(fd, config->fonts[i], sizeof(FcFontSet))) == -1) + return FcFalse; + t = c; + if (config->fonts[i]->nfont > 0) + { + for (j = 0; j < config->fonts[i]->nfont; j++) + { + if ((c = write(fd, config->fonts[i]->fonts[j], + sizeof(FcPattern))) == -1) + return FcFalse; + } + } + } + return FcTrue; +} |