summaryrefslogtreecommitdiff
path: root/src/intmetrics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/intmetrics.c')
-rw-r--r--src/intmetrics.c58
1 files changed, 25 insertions, 33 deletions
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);