summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/encoding.c4
-rw-r--r--src/ft.c2
-rw-r--r--src/intmetrics.c7
-rw-r--r--src/utils.h4
4 files changed, 11 insertions, 6 deletions
diff --git a/src/encoding.c b/src/encoding.c
index b331355..18220c8 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -35,7 +35,7 @@ ttf2f_result encoding_write(const char *savein, const char *name,
fprintf(output, "%% Encoding file for font '%s'\n\n", name);
/* Write latin1 first */
- for (i = 0; i != sizeof(ctx->latin1tab); i++) {
+ for (i = 0; i != N_ELEMENTS(ctx->latin1tab); i++) {
if (ctx->latin1tab[i] == NULL) {
if (type == ENCODING_TYPE_NORMAL) {
fprintf(output, "/.notdef\n");
@@ -56,7 +56,7 @@ ttf2f_result encoding_write(const char *savein, const char *name,
ttf2f_poll(1);
if (g->done_encoding == 0) {
- encoding_write_glyph(i + sizeof(ctx->latin1tab),
+ encoding_write_glyph(i + N_ELEMENTS(ctx->latin1tab),
g, type, output);
g->done_encoding = 1;
diff --git a/src/ft.c b/src/ft.c
index 7525d8d..0fe7c51 100644
--- a/src/ft.c
+++ b/src/ft.c
@@ -136,7 +136,7 @@ int glnames(ttf2f_ctx *ctx)
}
}
- for (i = 0; i != sizeof(ctx->latin1tab); i++) {
+ for (i = 0; i != N_ELEMENTS(ctx->latin1tab); i++) {
if (ctx->latin1tab[i] != NULL)
ctx->nlatin1++;
}
diff --git a/src/intmetrics.c b/src/intmetrics.c
index 3c99696..51ed5fd 100644
--- a/src/intmetrics.c
+++ b/src/intmetrics.c
@@ -76,7 +76,7 @@ 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);
+ int xwidthtab_idx = N_ELEMENTS(ctx->latin1tab);
short mapsize;
size_t i, name_len;
struct glyph *g;
@@ -85,14 +85,15 @@ ttf2f_result intmetrics_write(const char *savein, const char *name,
/* 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_size = ctx->nglyphs +
+ N_ELEMENTS(ctx->latin1tab) - ctx->nlatin1;
xwidthtab = calloc(xwidthtab_size, sizeof(short));
if (xwidthtab == NULL)
return TTF2F_RESULT_NOMEM;
/* fill latin1 subset first */
- for (i = 0; i != sizeof(ctx->latin1tab); i++) {
+ for (i = 0; i != N_ELEMENTS(ctx->latin1tab); i++) {
g = ctx->latin1tab[i];
xwidthtab[i] = g != NULL ? g->width : 0;
diff --git a/src/utils.h b/src/utils.h
index b577a6d..6912426 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -15,6 +15,10 @@
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
+#ifndef N_ELEMENTS
+#define N_ELEMENTS(x) (sizeof((x)) / sizeof((x)[0]))
+#endif
+
typedef enum ttf2f_result {
TTF2F_RESULT_OK,
TTF2F_RESULT_NOMEM,