diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2014-05-16 15:02:58 -0600 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2014-05-16 15:02:58 -0600 |
commit | 3f992254f2a3b7f88df989067785141cbf265037 (patch) | |
tree | b7830c2f0fc5488fa669deae1fb868ee547f93f8 /src/fchash.c | |
parent | 8284df49ef45678781fc6e05d18cc04acf04cf3c (diff) | |
download | fontconfig-3f992254f2a3b7f88df989067785141cbf265037.tar.gz |
Rewrite hashing to use FT_Stream directly
This is more robust but introduces a small change in behavior:
For .pcf.gz fonts, the new code calculates the hash of the uncompressed
font data whereas the original code was calculating the hash of the
compressed data.
No big deal IMO.
Diffstat (limited to 'src/fchash.c')
-rw-r--r-- | src/fchash.c | 75 |
1 files changed, 4 insertions, 71 deletions
diff --git a/src/fchash.c b/src/fchash.c index 3fc51f7..1526cfd 100644 --- a/src/fchash.c +++ b/src/fchash.c @@ -43,9 +43,8 @@ #define ss1(x) (ROTR32(x, 17) ^ ROTR32(x, 19) ^ SHR(x, 10)) -typedef FcChar32 FcHashDigest[8]; -static void +void FcHashInitDigest (FcHashDigest digest) { static const FcHashDigest init = { @@ -56,7 +55,7 @@ FcHashInitDigest (FcHashDigest digest) memcpy (digest, init, sizeof (FcHashDigest)); } -static void +void FcHashDigestAddBlock (FcHashDigest digest, const char block[64]) { @@ -129,7 +128,7 @@ FcHashDigestAddBlock (FcHashDigest digest, #undef H } -static void +void FcHashDigestFinish (FcHashDigest digest, const char *residual, /* < 64 bytes */ size_t total_len) @@ -164,7 +163,7 @@ FcHashDigestFinish (FcHashDigest digest, FcHashDigestAddBlock (digest, ibuf); } -static FcChar8 * +FcChar8 * FcHashToString (const FcHashDigest digest) { FcChar8 *ret = NULL; @@ -188,69 +187,3 @@ FcHashToString (const FcHashDigest digest) return ret; } - -FcChar8 * -FcHashGetDigestFromFile (const FcChar8 *filename) -{ - FcHashDigest digest; - FILE *fp; - char ibuf[64]; - size_t len; - struct stat st; - - fp = fopen ((const char *)filename, "rb"); - if (!fp) - return NULL; - - FcHashInitDigest (digest); - - if (FcStat (filename, &st)) - goto bail0; - - while (!feof (fp)) - { - if ((len = fread (ibuf, sizeof (char), 64, fp)) < 64) - { - FcHashDigestFinish (digest, ibuf, st.st_size); - break; - } - else - { - FcHashDigestAddBlock (digest, ibuf); - } - } - fclose (fp); - - return FcHashToString (digest); - -bail0: - fclose (fp); - - return NULL; -} - -FcChar8 * -FcHashGetDigestFromMemory (const char *fontdata, - size_t length) -{ - FcHashDigest digest; - size_t i = 0; - - FcHashInitDigest (digest); - - while (i <= length) - { - if ((length - i) < 64) - { - FcHashDigestFinish (digest, fontdata+i, length); - break; - } - else - { - FcHashDigestAddBlock (digest, &fontdata[i]); - } - i += 64; - } - - return FcHashToString (digest); -} |