summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-08 16:40:45 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-05-08 16:40:45 +0000
commit5f8354856558a645fa8fddffe250ce81b8fb48d3 (patch)
tree9c370aff0c026c0bb6282e3d9ad3477fa54a75ad /src
parentd0ad2e0bdb23789c261fe4d8636fb559f04c5f32 (diff)
downloadttf2f-5f8354856558a645fa8fddffe250ce81b8fb48d3.tar.gz
ttf2f-5f8354856558a645fa8fddffe250ce81b8fb48d3.tar.bz2
More tidying.
svn path=/trunk/tools/ttf2f/; revision=7447
Diffstat (limited to 'src')
-rw-r--r--src/cli.c2
-rw-r--r--src/intmetrics.c58
-rw-r--r--src/intmetrics.h6
-rw-r--r--src/utils.h4
4 files changed, 33 insertions, 37 deletions
diff --git a/src/cli.c b/src/cli.c
index c21e759..e61ea25 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
mkdir(argv[2], 0755);
- if ((err = write_intmetrics(argv[2], argv[2], glist, nglyphs,
+ if ((err = intmetrics_write(argv[2], argv[2], glist, nglyphs,
metrics, progress)) != TTF2F_RESULT_OK) goto error_out;
if ((err = write_outlines(argv[2], argv[2], glist, nglyphs,
diff --git a/src/intmetrics.c b/src/intmetrics.c
index 6040008..1f9f4aa 100644
--- a/src/intmetrics.c
+++ b/src/intmetrics.c
@@ -21,19 +21,6 @@ struct intmetrics_header {
char nhi;
};
-static short mapsize;
-
-static char *character_map = 0;
-
-/* we don't use these */
-// static short *x0;
-// static short *y0;
-// static short *x1;
-// static short *y1;
-
-static short *xwidthtab = 0;
-// static short *ywidthtab;
-
struct extra_data_offsets {
short misc;
short kern;
@@ -85,15 +72,17 @@ struct kern_pair_16 {
* \param list_size Size of glyph list
* \param metrics Global font metrics
*/
-ttf2f_result write_intmetrics(const char *savein,
- const char *name,struct glyph *glyph_list, int list_size,
- struct font_metrics *metrics, void (*callback)(int progress))
+ttf2f_result intmetrics_write(const char *savein, const char *name,
+ const struct glyph *glyph_list, int list_size,
+ const struct font_metrics *metrics,
+ void (*callback)(int progress))
{
struct intmetrics_header header;
- int charmap_size = 0;
+ short *xwidthtab = NULL;
unsigned int xwidthtab_size = 0;
- int i;
- struct glyph *g;
+ short mapsize;
+ int i, name_len;
+ const struct glyph *g;
char out[1024];
FILE *output;
@@ -108,30 +97,37 @@ ttf2f_result write_intmetrics(const char *savein,
/* create xwidthtab - char code is now the index */
for (i = 0; i != list_size; i++) {
+ short *temp;
+
g = &glyph_list[i];
callback((i * 100) / list_size);
ttf2f_poll(1);
xwidthtab_size++;
- xwidthtab[i+32] = g->width;
- xwidthtab = realloc(xwidthtab,
- (xwidthtab_size+1) * sizeof(short));
- if (xwidthtab == NULL)
+ /* +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;
+ }
+ xwidthtab = temp;
}
/* fill in header */
+ name_len = max(39, strlen(name));
snprintf(header.name, 40, "%s", name);
- memset(header.name + (strlen(name) >= 40 ? 39 : strlen(name)), 0xD,
- 40 - (strlen(name) >= 40 ? 39 : strlen(name)));
+ memset(header.name + name_len, 0xD, 40 - name_len);
header.a = header.b = 16;
header.version = 0x2;
- header.flags = 0x25;
+ /* Character map size before map | No y-offset data | No bbox data */
+ header.flags = 0x25;
header.nhi = xwidthtab_size / 256;
header.nlo = xwidthtab_size % 256;
- mapsize = charmap_size;
+ /* No character map */
+ mapsize = 0;
snprintf(out, 1024, "%s" DIR_SEP "IntMetrics", savein);
if ((output = fopen(out, "wb+")) == NULL) {
@@ -145,12 +141,11 @@ ttf2f_result write_intmetrics(const char *savein,
if (fputc(mapsize & 0xFF, output) == EOF) goto error_write;
if (fputc((mapsize & 0xFF00) >> 8, output) == EOF) goto error_write;
- if (fwrite(character_map, sizeof(char), charmap_size, output)
- != (size_t)charmap_size) goto error_write;
-
if (fwrite(xwidthtab, sizeof(short), xwidthtab_size, output)
!= xwidthtab_size) goto error_write;
+ /** \todo miscellaneous data */
+
fclose(output);
#ifdef __riscos__
@@ -158,14 +153,11 @@ ttf2f_result write_intmetrics(const char *savein,
_swix(OS_File, _INR(0,2), 18, out, 0xFF6);
#endif
- if (character_map)
- free(character_map);
free(xwidthtab);
return TTF2F_RESULT_OK;
error_write:
- free(character_map);
free(xwidthtab);
fclose(output);
diff --git a/src/intmetrics.h b/src/intmetrics.h
index 5b8546d..ec1caf0 100644
--- a/src/intmetrics.h
+++ b/src/intmetrics.h
@@ -6,9 +6,9 @@
struct glyph;
struct font_metrics;
-ttf2f_result write_intmetrics(const char *savein,
- const char *name, struct glyph *glyph_list,
- int list_size, struct font_metrics *metrics,
+ttf2f_result intmetrics_write(const char *savein,
+ const char *name, const struct glyph *glyph_list,
+ int list_size, const struct font_metrics *metrics,
void (*callback)(int progress));
#endif
diff --git a/src/utils.h b/src/utils.h
index 09d348e..b577a6d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -11,6 +11,10 @@
#define DIR_SEP "/"
#endif
+#ifndef max
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
typedef enum ttf2f_result {
TTF2F_RESULT_OK,
TTF2F_RESULT_NOMEM,