aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar Bram Stein <blsteingmailcom>2016-12-19 09:24:05 +0100
committerLibravatarLarge Libravatar GitHub <noreplygithubcom>2016-12-19 09:24:05 +0100
commit6cb8b06633c8d7c25d8a1aa46417d4b414b46dbc (patch)
treefe5fd220cbf5be011ec2b17dd444c6a033deadfe
parent81c3038f9b099a34b88faad621cb79f0bcba0e6b (diff)
parente5ecdfae981ca0b603892deffa9ef2892c5d1d9c (diff)
downloadsfnt2woff-zopfli-6cb8b06633c8d7c25d8a1aa46417d4b414b46dbc.tar.gz
sfnt2woff-zopfli-6cb8b06633c8d7c25d8a1aa46417d4b414b46dbc.tar.bz2
sfnt2woff-zopfli-6cb8b06633c8d7c25d8a1aa46417d4b414b46dbc.tar.lz
sfnt2woff-zopfli-6cb8b06633c8d7c25d8a1aa46417d4b414b46dbc.zip

Merge pull request #4 from fangel/make-numiterations-configurable

Made number of iterations configurable with a flag

-rw-r--r--sfnt2woff.c12
-rw-r--r--woff.c9
-rw-r--r--woff.h3
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);
diff --git a/woff.c b/woff.c
index 03a0baa..c0f1192 100644
--- a/woff.c
+++ b/woff.c
@@ -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);
diff --git a/woff.h b/woff.h
index d8c6f55..e792526 100644
--- a/woff.h
+++ b/woff.h
@@ -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);
/*****************************************************************************