summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-11 00:01:02 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-05-11 00:01:02 +0000
commite90acbb3dd052ae075bac3e3aa8c9a7ecbf889d1 (patch)
tree9bc257098f664dcc3aee4b7828354bab36838acc
parentdda72e9bf55f2d47d24a9df63d30ea3bcb92f1e3 (diff)
downloadttf2f-e90acbb3dd052ae075bac3e3aa8c9a7ecbf889d1.tar.gz
ttf2f-e90acbb3dd052ae075bac3e3aa8c9a7ecbf889d1.tar.bz2
Write out font metrics so that the first 256 glyphs match Acorn Latin 1.
Don't use this version -- it will produce inconsistent font data (outlines and encoding export needs the same thing doing to it) svn path=/trunk/tools/ttf2f/; revision=7460
-rw-r--r--src/context.h3
-rw-r--r--src/ft.c12
-rw-r--r--src/glyph.h4
-rw-r--r--src/intmetrics.c37
4 files changed, 35 insertions, 21 deletions
diff --git a/src/context.h b/src/context.h
index f555fe3..157f31c 100644
--- a/src/context.h
+++ b/src/context.h
@@ -14,7 +14,8 @@ struct ttf2f_ctx {
size_t nglyphs;
struct glyph *glyphs;
- struct glyph *latin1tab[256 - 32]; /* Not chunk zero */
+ struct glyph *latin1tab[256];
+ size_t nlatin1;
};
#endif
diff --git a/src/ft.c b/src/ft.c
index 0676bf8..7525d8d 100644
--- a/src/ft.c
+++ b/src/ft.c
@@ -115,9 +115,9 @@ int glnames(ttf2f_ctx *ctx)
/* Insert into latin1 table, if appropriate */
if (0x0020 <= code && code < 0x007f)
- ctx->latin1tab[code - 0x20] = &ctx->glyphs[i];
+ ctx->latin1tab[code] = &ctx->glyphs[i];
else if (0x00a0 <= code && code <= 0x00ff)
- ctx->latin1tab[code - 0x20] = &ctx->glyphs[i];
+ ctx->latin1tab[code] = &ctx->glyphs[i];
else {
int j;
@@ -131,12 +131,16 @@ int glnames(ttf2f_ctx *ctx)
}
if (j != 32) {
- ctx->latin1tab[j + 0x80 - 0x20] =
- &ctx->glyphs[i];
+ ctx->latin1tab[j + 0x80] = &ctx->glyphs[i];
}
}
}
+ for (i = 0; i != sizeof(ctx->latin1tab); i++) {
+ if (ctx->latin1tab[i] != NULL)
+ ctx->nlatin1++;
+ }
+
return 0;
}
diff --git a/src/glyph.h b/src/glyph.h
index 6a18b2d..8126547 100644
--- a/src/glyph.h
+++ b/src/glyph.h
@@ -33,6 +33,10 @@ struct glyph {
short width; /* advance width of glyph */
struct outline *outline; /* outline of glyph */
struct composite *composite; /* list of composite inclusions */
+
+ int done_intmetrics : 2,
+ done_outlines : 2,
+ done_encoding : 2;
};
#endif
diff --git a/src/intmetrics.c b/src/intmetrics.c
index 6b9c297..3c99696 100644
--- a/src/intmetrics.c
+++ b/src/intmetrics.c
@@ -76,37 +76,42 @@ ttf2f_result intmetrics_write(const char *savein, const char *name,
struct intmetrics_header header;
short *xwidthtab = NULL;
unsigned int xwidthtab_size = 0;
+ int xwidthtab_idx = sizeof(ctx->latin1tab);
short mapsize;
size_t i, name_len;
- const struct glyph *g;
+ struct glyph *g;
char out[1024];
FILE *output;
- /* allow for chunk 0 */
- xwidthtab = calloc(33, sizeof(short));
+ /* Total number of slots is the number of glyphs plus any spare
+ * required for the latin1 table */
+ xwidthtab_size = ctx->nglyphs + sizeof(ctx->latin1tab) - ctx->nlatin1;
+
+ xwidthtab = calloc(xwidthtab_size, sizeof(short));
if (xwidthtab == NULL)
return TTF2F_RESULT_NOMEM;
- xwidthtab_size = 32;
+ /* fill latin1 subset first */
+ for (i = 0; i != sizeof(ctx->latin1tab); i++) {
+ g = ctx->latin1tab[i];
- /* create xwidthtab - char code is now the index */
- for (i = 0; i != ctx->nglyphs; i++) {
- short *temp;
+ xwidthtab[i] = g != NULL ? g->width : 0;
+ if (g != NULL)
+ g->done_intmetrics = 1;
+ }
+
+ /* then the rest, skipping those we've already written */
+ for (i = 0; i != ctx->nglyphs; i++) {
g = &ctx->glyphs[i];
callback((i * 100) / ctx->nglyphs);
ttf2f_poll(1);
- xwidthtab_size++;
- /* +32 to skip chunk 0 */
- xwidthtab[i + 32] = g->width;
- temp = realloc(xwidthtab, (xwidthtab_size + 1) * sizeof(short));
- if (temp == NULL) {
- free(xwidthtab);
- return TTF2F_RESULT_NOMEM;
+ if (g->done_intmetrics == 0) {
+ xwidthtab[xwidthtab_idx++] = g->width;
+ g->done_intmetrics = 1;
}
- xwidthtab = temp;
}
/* fill in header */
@@ -129,7 +134,7 @@ ttf2f_result intmetrics_write(const char *savein, const char *name,
return TTF2F_RESULT_OPEN;
}
- if (fwrite((void*)&header, sizeof(struct intmetrics_header),
+ if (fwrite((void*) &header, sizeof(struct intmetrics_header),
1, output) != 1) goto error_write;
if (fputc(mapsize & 0xFF, output) == EOF) goto error_write;