summaryrefslogtreecommitdiff
path: root/src/fcfs.c
diff options
context:
space:
mode:
authorPatrick Lam <plam@MIT.EDU>2005-06-28 03:41:02 +0000
committerPatrick Lam <plam@MIT.EDU>2005-06-28 03:41:02 +0000
commitcd2ec1a940888ebcbd323a8000d2fcced41ddf9e (patch)
tree841e371cb0e28b003cdfbab8d109e30d84b2a3db /src/fcfs.c
parentf1a42f6b5f9bcd774d09002509b2872c04025c1b (diff)
downloadfontconfig-cd2ec1a940888ebcbd323a8000d2fcced41ddf9e.tar.gz
Add functionality to allow fontconfig data structure serialization.
This patch allows the fundamental fontconfig data structures to be serialized. I've converted everything from FcPattern down to be able to use *Ptr objects, which can be either static or dynamic (using a union which either contains a pointer or an index) and replaced storage of pointers in the heap with the appropriate *Ptr object. I then changed all writes of pointers to the heap with a *CreateDynamic call, which creates a dynamic Ptr object pointing to the same object as before. This way, the fundamental fontconfig semantics should be unchanged; I did not have to change external signatures this way, although I did change some internal signatures. When given a *Ptr object, just run *U to get back to a normal pointer; it gives the right answer regardless of whether we're using static or dynamic storage. I've also implemented a Fc*Serialize call. Calling FcFontSetSerialize converts the dynamic FcFontSets contained in the config object to static FcFontSets and also converts its dependencies (e.g. everything you'd need to write to disk) to static objects. Note that you have to call Fc*PrepareSerialize first; this call will count the number of objects that actually needs to be allocated, so that we can avoid realloc. The Fc*Serialize calls then check the static pointers for nullness, and allocate the buffers if necessary. I've tested the execution of fc-list and fc-match after Fc*Serialize and they appear to work the same way.
Diffstat (limited to 'src/fcfs.c')
-rw-r--r--src/fcfs.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/fcfs.c b/src/fcfs.c
index b05688d..c202040 100644
--- a/src/fcfs.c
+++ b/src/fcfs.c
@@ -80,3 +80,39 @@ FcFontSetAdd (FcFontSet *s, FcPattern *font)
s->fonts[s->nfont++] = font;
return FcTrue;
}
+
+FcBool
+FcFontSetPrepareSerialize (FcFontSet *s)
+{
+ int i;
+
+ for (i = 0; i < s->nfont; i++)
+ if (!FcPatternPrepareSerialize(s->fonts[i]))
+ return FcFalse;
+
+ return FcTrue;
+}
+
+FcBool
+FcFontSetSerialize (FcFontSet * s)
+{
+ int i;
+ FcPattern * p;
+
+ for (i = 0; i < s->nfont; i++)
+ {
+ p = FcPatternSerialize (s->fonts[i]);
+ if (!p) return FcFalse;
+ FcPatternDestroy (s->fonts[i]);
+
+ s->fonts[i] = p;
+ }
+
+ return FcTrue;
+}
+
+void
+FcFontSetClearStatic (void)
+{
+ FcPatternClearStatic();
+}