]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcmatrix.c
Add functionality to allow fontconfig data structure serialization.
[fontconfig.git] / src / fcmatrix.c
index 889c3b8c77f26b9e8436f5322ac9e53d5092baa7..6a5aa5dd8fa6b71b79f298ae7ad9d0e1b7dcae8d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $RCSId: $
  *
- * Copyright © 2000 Tuomas J. Lukka
+ * Copyright Â© 2000 Tuomas J. Lukka
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 #include <ctype.h>
 #include "fcint.h"
 
-const FcMatrix    FcIdentityMatrix = { 1, 0, 0, 1 };
+FcMatrix    _id = { 1, 0, 0, 1 };
+const FcMatrixPtr    FcIdentityMatrix = {
+    .storage = FcStorageDynamic,
+    .u.dyn = &_id
+};
 
 FcMatrix *
 FcMatrixCopy (const FcMatrix *mat) 
@@ -43,10 +47,17 @@ FcMatrixCopy (const FcMatrix *mat)
     return r;
 }
 
+void
+FcMatrixPtrDestroy (FcMatrixPtr mi)
+{
+    if (mi.storage == FcStorageDynamic)
+       FcMatrixFree (mi.u.dyn);
+}
+
 void
 FcMatrixFree (FcMatrix *mat)
 {
-    if (mat != &FcIdentityMatrix)
+    if (mat != FcMatrixPtrU(FcIdentityMatrix))
     {
        FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix));
        free (mat);
@@ -115,3 +126,59 @@ FcMatrixShear (FcMatrix *m, double sh, double sv)
     r.yy = 1;
     FcMatrixMultiply (m, &r, m);
 }
+
+static FcMatrix * matrices = 0;
+static int matrix_ptr = 0, matrix_count = 0;
+
+void 
+FcMatrixClearStatic (void)
+{
+    matrices = 0;
+    matrix_ptr = 0;
+    matrix_count = 0;
+}
+
+FcMatrix *
+FcMatrixPtrU (FcMatrixPtr mi)
+{
+    switch (mi.storage)
+    {
+    case FcStorageDynamic:
+       return mi.u.dyn;
+    case FcStorageStatic:
+       return &matrices[mi.u.stat];
+    default:
+       return 0;
+
+    }
+}
+
+FcMatrixPtr
+FcMatrixPtrCreateDynamic (FcMatrix *mi)
+{
+    FcMatrixPtr new;
+    new.storage = FcStorageDynamic;
+    new.u.dyn = mi;
+    return new;
+}
+
+FcBool
+FcMatrixPrepareSerialize(FcMatrix *m)
+{
+    matrix_count++;
+    return FcTrue;
+}
+
+FcMatrixPtr
+FcMatrixSerialize(FcMatrix *m)
+{
+    FcMatrixPtr new;
+
+    if (matrix_count == matrix_ptr)
+       return FcMatrixPtrCreateDynamic(0);
+
+    new.storage = FcStorageStatic;
+    new.u.stat = matrix_ptr++;
+    return new;
+}
+