#include <string.h>
#include <time.h>
+/* This cast to "int" assumes we don't have any stupidly large arrays. */
+#define lenof(x) ((int)(sizeof(x) / sizeof((x)[0])))
+
/* Font identity information. */
#define FAMILY_NAME "Bedstead"
#define VERSION "3.246"
{ "--semi-condensed", " Semi Condensed", 87.5, 4 },
{ "--extended", " Extended", 125.0, 7 },
};
-static int const nwidths = sizeof(widths) / sizeof(widths[0]);
static struct width const *width = &widths[0];
{ "--bold", " Bold", +50, 700 },
};
-static int const nweights = sizeof(weights) / sizeof(weights[0]);
-
static struct weight const *weight = &weights[0];
/* U(N) sets the code point and name of a glyph not in AGLFN */
#undef U
-#define NGLYPHS (sizeof(glyphs) / sizeof(glyphs[0]))
-static int const nglyphs = NGLYPHS;
-
-static struct glyph const *glyphs_by_name[NGLYPHS];
+static struct glyph const *glyphs_by_name[lenof(glyphs)];
/*
* This array defines 'aalt' mappings that should not be automatically
int noverrides;
} const gsub_features[] = {
{ "aalt", SCRIPT_ALL, .overrides = aalt_overrides,
- .noverrides = sizeof(aalt_overrides) / sizeof(aalt_overrides[0]) },
+ .noverrides = lenof(aalt_overrides) },
{ "smcp", SCRIPT_LATN, .suffix = ".sc" },
{ "c2sc", SCRIPT_LATN, .suffix = ".c2sc" },
{ "rtlm", SCRIPT_ALL, .suffix = ".rtlm" },
{ "ss16", SCRIPT_ALL, ".sep6", .name = "6-cell separated graphics" },
};
-static int const ngsub_features =
- sizeof(gsub_features) / sizeof(gsub_features[0]);
-
static struct gsub_script {
char const *tag;
unsigned int flag;
{ "latn", SCRIPT_LATN },
};
-static int const ngsub_scripts = sizeof(gsub_scripts) / sizeof(gsub_scripts[0]);
-
static void dochar(struct glyph *g);
static void dochar_plotter(struct glyph *g);
static void domosaic(struct glyph *g);
{
struct glyph * const *gp;
- gp = bsearch(name, glyphs_by_name, nglyphs,
+ gp = bsearch(name, glyphs_by_name, lenof(glyphs_by_name),
sizeof(glyphs_by_name[0]), &compare_glyph_to_name);
assert(gp != NULL);
return *gp;
}
while (argc > 1) {
- for (i = 0; i < nwidths; i++)
+ for (i = 0; i < lenof(widths); i++)
if (strcmp(argv[1], widths[i].option) == 0) {
width = &widths[i];
argv++; argc--;
goto next;
}
- for (i = 0; i < nweights; i++)
+ for (i = 0; i < lenof(weights); i++)
if (strcmp(argv[1], weights[i].option) == 0) {
weight = &weights[i];
argv++; argc--;
}
/* Put glyphs into FontForge-compatible order. */
- qsort(glyphs, nglyphs, sizeof(glyphs[0]), &compare_glyphs_by_ffid);
+ qsort(glyphs, lenof(glyphs), sizeof(glyphs[0]),
+ &compare_glyphs_by_ffid);
printf("<?xml version='1.0'?>\n");
printf("<ttFont sfntVersion='OTTO'>\n");
/* Convenient macros for TTX values. */
printf("<maxp>\n");
TTXS("tableVersion", "0x5000");
- TTXI("numGlyphs", nglyphs);
+ TTXI("numGlyphs", lenof(glyphs));
printf("</maxp>\n");
printf("<OS_2>\n");
/* Stylistic set names. */
#define NAMEBASE_GSUB 0x100
#define NAMEBASE_GSUB_SUB 0x200
- for (i = 0; i < ngsub_features; i++) {
+ for (i = 0; i < lenof(gsub_features); i++) {
if (gsub_features[i].name != NULL)
NAME(NAMEBASE_GSUB + i, gsub_features[i].name);
for (int j = 0; j < MAXSUBNAME; j++)
TTXI("minMemType1", 0); TTXI("maxMemType1", 0);
printf("</post>\n");
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
glyphs_by_name[i] = glyphs + i;
- qsort(glyphs_by_name, nglyphs, sizeof(glyphs_by_name[0]),
+ qsort(glyphs_by_name, lenof(glyphs_by_name), sizeof(glyphs_by_name[0]),
&compare_glyphs_by_name);
printf("<GlyphOrder>\n");
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
printf("<GlyphID name='%s'/>\n", glyphs[i].name);
printf("</GlyphOrder>\n");
/* } */
printf("<Subrs>\n");
nsubrs = 0;
- for (i = 0; i < nglyphs; i++) {
+ for (i = 0; i < lenof(glyphs); i++) {
struct glyph *g = &glyphs[i];
if (g->flags & IS_ALIAS) {
g = realglyph(g);
printf("</Subrs>\n");
printf("</Private>\n");
printf("<CharStrings>\n");
- for (i = 0; i < nglyphs; i++) {
+ for (i = 0; i < lenof(glyphs); i++) {
printf("<CharString name='%s'>", glyphs[i].name);
doglyph(&glyphs[i]);
printf("</CharString>\n");
printf("</CFFFont>\n");
printf("</CFF>\n");
printf("<hmtx>\n");
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
printf("<mtx name='%s' width='%d' lsb='%d'/>\n",
glyphs[i].name, (int)(XSIZE * XPIX),
(int)realglyph(&glyphs[i])->left_sidebearing);
printf(" format='12' reserved='0' length='0' nGroups='0'");
}
printf(">\n");
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
if (glyphs[i].unicode >= 0 &&
glyphs[i].unicode < limit)
printf("<map code='0x%lx' name='%s'/>\n",
printf("<GSUB>\n");
TTXS("Version", "0x00010000");
printf("<ScriptList>\n");
- for (i = 0; i < ngsub_scripts; i++) {
+ for (i = 0; i < lenof(gsub_scripts); i++) {
printf("<ScriptRecord>\n");
TTXS("ScriptTag", gsub_scripts[i].tag);
printf("<Script><DefaultLangSys>\n");
TTXI("ReqFeatureIndex", 0xffff); /* No required feature. */
- for (j = 0; j < ngsub_features; j++)
+ for (j = 0; j < lenof(gsub_features); j++)
if (gsub_features[j].scripts & gsub_scripts[i].flag)
TTXI("FeatureIndex", j);
printf("</DefaultLangSys></Script>\n");
}
printf("</ScriptList>\n");
printf("<FeatureList>\n");
- for (i = 0; i < ngsub_features; i++) {
+ for (i = 0; i < lenof(gsub_features); i++) {
printf("<FeatureRecord>\n");
TTXS("FeatureTag", gsub_features[i].tag);
printf("<Feature>\n");
}
printf("</FeatureList>\n");
printf("<LookupList>\n");
- for (i = 0; i < ngsub_features; i++) {
+ for (i = 0; i < lenof(gsub_features); i++) {
printf("<Lookup> <!-- '%s' -->\n", gsub_features[i].tag);
if (gsub_features[i].suffix != NULL) {
/* Single lookup for all glyphs with a suffix. */
{
int i, j, next_override = 0;
- for (i = 1; i < nglyphs; i++) {
+ for (i = 1; i < lenof(glyphs_by_name); i++) {
#define HASDOT(x) (strchr(glyphs_by_name[x]->name, '.') != NULL)
/*
* We want to map each glyph with a name that doesn't
printf("%s<AlternateSet glyph='%s'>",
overridden ? "<!-- " : "",
glyphs_by_name[i-1]->name);
- for (; i < nglyphs && HASDOT(i); i++)
+ for (; i < lenof(glyphs_by_name) && HASDOT(i); i++)
printf("<Alternate glyph='%s'/>",
glyphs_by_name[i]->name);
printf("</AlternateSet>%s\n",
int i;
char *dot;
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
if ((dot = strchr(glyphs[i].name, '.')) != NULL &&
strcmp(dot, suffix) == 0)
printf("<Substitution in='%.*s' out='%s'/>\n",
printf("<SinglePos Format='1'>\n");
printf("<!-- dx = %d; dh = %d -->\n", dx, dh);
printf("<Coverage>\n");
- for (i = 0; i < nglyphs; i++) {
+ for (i = 0; i < lenof(glyphs); i++) {
struct glyph *g = realglyph(&glyphs[i]);
if (g->flags & (MOS6|MOS4)) continue;
int fp = glyph_footprint(g->data);
int i, col = -1, row = 0;
int npages = 0;
bool newcol = false;
- struct glyph const *sorted[NGLYPHS], *g;
+ struct glyph const *sorted[lenof(glyphs)], *g;
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
glyphs_by_name[i] = glyphs + i;
- qsort(glyphs_by_name, nglyphs, sizeof(glyphs_by_name[0]),
+ qsort(glyphs_by_name, lenof(glyphs_by_name), sizeof(glyphs_by_name[0]),
&compare_glyphs_by_name);
- for (i = 0; i < nglyphs; i++)
+ for (i = 0; i < lenof(glyphs); i++)
sorted[i] = &glyphs[i];
- qsort(sorted, nglyphs, sizeof(sorted[0]), &byunicode);
+ qsort(sorted, lenof(sorted), sizeof(sorted[0]), &byunicode);
printf("%%!PS-Adobe\n");
printf("%%%%Creator: bedstead %s\n", VERSION);
printf("%%%%Title: %s %s Glyph Complement\n", FAMILY_NAME, VERSION);
printf(" } for\n");
printf("} def\n");
printf("%%%%EndProlog\n");
- for (i = 0; i < nglyphs; i++) {
+ for (i = 0; i < lenof(sorted); i++) {
g = sorted[i];
if (g->unicode / nrow != unicol ||
(g->unicode == -1 && row == nrow)) {
printf("FONT_DESCENT %d\n", base);
printf("DEFAULT_CHAR %d\n", 0xf1ff);
printf("ENDPROPERTIES\n");
- printf("CHARS %d\n", nglyphs);
- for (i = 0; i < nglyphs; i++) {
+ printf("CHARS %d\n", lenof(glyphs));
+ for (i = 0; i < lenof(glyphs); i++) {
struct glyph *g = &glyphs[i];
printf("STARTCHAR %s\n", g->name);
printf("ENCODING %d\n", g->unicode);