diff options
Merge pull request #4 from fangel/make-numiterations-configurable
Made number of iterations configurable with a flag
-rw-r--r-- | sfnt2woff.c | 12 | ||||
-rw-r--r-- | woff.c | 9 | ||||
-rw-r--r-- | woff.h | 3 |
3 files changed, 19 insertions, 5 deletions
diff --git a/sfnt2woff.c b/sfnt2woff.c index 2faae4a..943f2b1 100644 --- a/sfnt2woff.c +++ b/sfnt2woff.c @@ -65,6 +65,7 @@ usage(const char * progName) "Options:\n" " -v <maj>.<min> set font version number (major and minor, both integers)\n" " -m <metadata.xml> include metadata from <metadata.xml> (not validated)\n" + " -n <iterations> number of zopfli iterations (default = 15)\n" " -p <private.dat> include private data block\n" , progName); } @@ -102,10 +103,11 @@ main(int argc, char * argv[]) const char * metadataFile = NULL; const char * privateFile = NULL; unsigned int maj = 0, min = 0; + int numiterations = 0; uint32_t status = eWOFF_ok; int opt; - while ((opt = getopt(argc, argv, "v:m:p:h")) != -1) { + while ((opt = getopt(argc, argv, "v:m:p:n:h")) != -1) { switch (opt) { case 'v': if (sscanf(optarg, "%u.%u", &maj, &min) < 2 || maj > 0xffff || min > 0xffff) { @@ -119,6 +121,12 @@ main(int argc, char * argv[]) case 'p': privateFile = optarg; break; + case 'n': + if (sscanf(optarg, "%u", &numiterations) < 1 || !numiterations || numiterations > 5000) { + fprintf(stderr, "# invalid number of iterations - please specify number between 0 and 5000\n"); + numiterations = 0; + } + break; case 'h': case '?': usage(progName); @@ -140,7 +148,7 @@ main(int argc, char * argv[]) const uint8_t * sfntData = readFile(argv[0], &sfntLen); uint32_t woffLen; - const uint8_t * woffData = woffEncode(sfntData, sfntLen, maj, min, &woffLen, &status); + const uint8_t * woffData = woffEncode(sfntData, sfntLen, maj, min, numiterations, &woffLen, &status); free((void *)sfntData); if (WOFF_FAILURE(status)) { reportErr(status); @@ -121,7 +121,8 @@ calcChecksum(const sfntDirEntry * dirEntry, const uint8_t * woffEncode(const uint8_t * sfntData, uint32_t sfntLen, uint16_t majorVersion, uint16_t minorVersion, - uint32_t * woffLen, uint32_t * pStatus) + int32_t numiterations, uint32_t * woffLen, + uint32_t * pStatus) { uint8_t * woffData = NULL; tableOrderRec * tableOrder = NULL; @@ -255,6 +256,9 @@ woffEncode(const uint8_t * sfntData, uint32_t sfntLen, ZopfliOptions options; ZopfliInitOptions(&options); + if (numiterations) { + options.numiterations = numiterations; + } for (order = 0; order < numTables; ++order) { uLong sourceLen, destLen = 0; @@ -368,7 +372,8 @@ woffEncode(const uint8_t * sfntData, uint32_t sfntLen, free(woffData); woffData = (uint8_t *) woffEncode(cleanSfnt, sfntLen, majorVersion, minorVersion, - &tableOffset, &status); + numiterations, &tableOffset, + &status); free((void *) cleanSfnt); if (WOFF_FAILURE(status)) { FAIL(status); @@ -107,7 +107,8 @@ extern "C" { */ const uint8_t * woffEncode(const uint8_t * sfntData, uint32_t sfntLen, uint16_t majorVersion, uint16_t minorVersion, - uint32_t * woffLen, uint32_t * status); + int32_t numiterations, uint32_t * woffLen, + uint32_t * status); /***************************************************************************** |