From 3913b12575166b5bedcd173459f5034365ab32c3 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Wed, 25 Aug 2021 18:44:07 +0800 Subject: [PATCH 1/5] otf.c: Fix compilation on Windows --- otf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/otf.c b/otf.c index 57c78b1..5a4a02c 100644 --- a/otf.c +++ b/otf.c @@ -1,5 +1,10 @@ /* OpenType and TrueType fonts */ +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#else #include +#endif #include #include #include From 9673b2b017768da879eb358f9910d46602244a7f Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Thu, 26 Aug 2021 19:44:32 +0800 Subject: [PATCH 2/5] otf.c: Set stdin to binary mode on Windows --- mkfn.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mkfn.c b/mkfn.c index d6a99b5..f2e5e13 100644 --- a/mkfn.c +++ b/mkfn.c @@ -19,6 +19,10 @@ #include #include #include +#ifdef _WIN32 +#include +#include +#endif #include "mkfn.h" #define LEN(a) ((sizeof(a) / sizeof((a)[0]))) @@ -236,6 +240,9 @@ int main(int argc, char *argv[]) return 0; } } +#ifdef _WIN32 + _setmode(_fileno(stdin), _O_BINARY); +#endif trfn_init(); if ((afm ? afm_read() : otf_read())) { fprintf(stderr, "neatmkfn: cannot parse the font\n"); From e3b46ad14fdaebabb4d1c462f8da683ecea5f668 Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 5 Sep 2021 11:08:31 +0800 Subject: [PATCH 3/5] mkfn, otf, trfn, trfn_ch: fix warnings --- mkfn.c | 4 +++- otf.c | 28 ++++++++++++++++++++++-- trfn.c | 14 ++++++------ trfn_ch.h | 64 +++++++++++++++++++++++++++---------------------------- 4 files changed, 68 insertions(+), 42 deletions(-) diff --git a/mkfn.c b/mkfn.c index f2e5e13..33c11a9 100644 --- a/mkfn.c +++ b/mkfn.c @@ -99,6 +99,8 @@ int mkfn_script(char *script, int nscripts) /* return 1 if the given language is to be included */ int mkfn_lang(char *lang, int nlangs) { + /* not used */ + (void) nlangs; if (!mkfn_langs) return 1; if (!lang) @@ -129,7 +131,7 @@ int mkfn_font(char *font) int mkfn_featrank(char *scrp, char *feat) { static char **order; - int i; + size_t i; if (!order || strcmp(scrp, order[0])) { order = NULL; for (i = 0; i < LEN(scriptorder); i++) diff --git a/otf.c b/otf.c index 5a4a02c..edd46d0 100644 --- a/otf.c +++ b/otf.c @@ -123,6 +123,8 @@ static void otf_cmap4(struct otf *otf, void *cmap4) void *ends, *begs, *deltas, *offsets; int beg, end, delta, offset; int i, j; + /* not used */ + (void) otf; nsegs = U16(cmap4, 6) / 2; ends = cmap4 + 14; begs = ends + 2 * nsegs + 2; @@ -167,6 +169,8 @@ static void otf_post(struct otf *otf, void *post) void *names; /* glyph names */ int cname = 0; int i; + /* not used */ + (void) otf; if (U32(post, 0) != 0x20000) return; post2 = post + 32; @@ -229,6 +233,8 @@ static void otf_kern(struct otf *otf, void *kern) int off = 4; int i, j; int n = U16(kern, 2); /* number of kern subtables */ + /* not used */ + (void) otf; for (i = 0; i < n; i++) { void *tab = kern + off; /* a kern subtable */ int cov = U16(tab, 4); @@ -375,6 +381,8 @@ static void otf_gpostype1(struct otf *otf, void *sub, char *feat) int ncov, nvals; int vlen = valuerecord_len(vfmt); int i; + /* not used */ + (void) otf; cov = coverage(sub + U16(sub, 2), &ncov); if (fmt == 1) { for (i = 0; i < ncov; i++) { @@ -407,6 +415,8 @@ static void otf_gpostype2(struct otf *otf, void *sub, char *feat) int fmtoff1, fmtoff2; int vrlen; /* the length of vfmt1 and vfmt2 */ int i, j; + /* not used */ + (void) otf; vrlen = valuerecord_len(vfmt1) + valuerecord_len(vfmt2); if (fmt == 1) { int nc1 = U16(sub, 8); @@ -470,6 +480,8 @@ static void otf_gpostype3(struct otf *otf, void *sub, char *feat) int icnt = 0; int ocnt = 0; int igrp, ogrp; + /* not used */ + (void) otf; if (fmt != 1) return; cov = coverage(sub + U16(sub, 2), NULL); @@ -526,6 +538,8 @@ static void otf_gpostype4(struct otf *otf, void *sub, char *feat) void *marks; /* mark array table */ void *bases; /* base array table */ int i, j; + /* not used */ + (void) otf; if (fmt != 1) return; mcov = coverage(sub + U16(sub, 2), &mcnt); @@ -591,6 +605,8 @@ static void otf_gpostype5(struct otf *otf, void *sub, char *feat) void *marks; /* mark array table */ void *ligas; /* ligature array table */ int i, j, k; + /* not used */ + (void) otf; /* only marks at the end of ligatures are supported */ if (fmt != 1) return; @@ -694,6 +710,8 @@ static void otf_gsubtype1(struct otf *otf, void *sub, char *feat, struct gctx *c int fmt = U16(sub, 0); int ncov; int i; + /* not used */ + (void) otf; cov = coverage(sub + U16(sub, 2), &ncov); if (fmt == 1) { for (i = 0; i < ncov; i++) { @@ -727,6 +745,8 @@ static void otf_gsubtype3(struct otf *otf, void *sub, char *feat, struct gctx *c int *cov; int fmt = U16(sub, 0); int n, i, j; + /* not used */ + (void) otf; if (fmt != 1) return; cov = coverage(sub + U16(sub, 2), NULL); @@ -752,6 +772,8 @@ static void otf_gsubtype4(struct otf *otf, void *sub, char *feat, struct gctx *c int fmt = U16(sub, 0); int *cov; int n, i, j, k; + /* not used */ + (void) otf; if (fmt != 1) return; cov = coverage(sub + U16(sub, 2), NULL); @@ -778,7 +800,7 @@ static void otf_gsubtype4(struct otf *otf, void *sub, char *feat, struct gctx *c /* chaining contextual substitution */ static void otf_gsubtype6(struct otf *otf, void *sub, char *feat, void *gsub) { - struct gctx ctx = {{0}}; + struct gctx ctx = {{0}, {0}, {0}, 0, 0, 0, 0}; void *lookups = gsub + U16(gsub, 8); int fmt = U16(sub, 0); int *cov; @@ -850,6 +872,8 @@ static int otf_featrec(struct otf *otf, void *gtab, void *featrec, void *feat = feats + U16(featrec, 4); int n = U16(feat, 2); int i, j; + /* not used */ + (void) otf; for (i = 0; i < n; i++) { int lookup = U16(feat, 4 + 2 * i); /* lookup index */ /* do not store features common to all languages in a script */ @@ -1212,7 +1236,7 @@ int otf_offsettable(void *otf_otf, void *otf_off) { int i; unsigned tag = U32(otf_off, 0); - struct otf otf_cur = {otf_otf, otf_off}; + struct otf otf_cur = {otf_otf, otf_off, {0}}; struct otf *otf = &otf_cur; if (tag != 0x00010000 && tag != 0x4F54544F) return 1; diff --git a/trfn.c b/trfn.c index d289039..3e9373b 100644 --- a/trfn.c +++ b/trfn.c @@ -107,7 +107,7 @@ static int agl_map(char *d, char *s) static int achar_map(char *name) { - int i; + size_t i; for (i = 0; i < LEN(achars); i++) { struct achar *a = &achars[i]; if (!strncmp(a->name, name, strlen(a->name))) { @@ -129,10 +129,10 @@ static int achar_map(char *name) static int achar_shape(int c, int pjoin, int njoin) { - int i; + size_t i; for (i = 0; i < LEN(achars); i++) { struct achar *a = &achars[i]; - if (a->c == c) { + if ((int) a->c == c) { if (!pjoin && !njoin) return a->c; if (!pjoin && njoin) @@ -202,7 +202,7 @@ static int trfn_name(char *dst, char *src, int codepoint) static void trfn_aglexceptions(char *dst) { - int i; + size_t i; for (i = 0; i < LEN(agl_exceptions); i++) if (!strcmp(agl_exceptions[i][0], dst)) strcpy(dst, agl_exceptions[i][1]); @@ -216,11 +216,11 @@ static void trfn_ligput(char *c) static void trfn_lig(char *c) { - int i; + size_t i; for (i = 0; i < LEN(agl_exceptions); i++) if (!strcmp(agl_exceptions[i][1], c)) return; - if (c[0] && c[1] && strlen(c) > utf8len((unsigned char) c[0])) { + if (c[0] && c[1] && strlen(c) > (size_t) utf8len((unsigned char) c[0])) { trfn_ligput(c); } else { for (i = 0; i < LEN(ligs_utf8); i++) @@ -307,7 +307,7 @@ void trfn_cdefs(void) void trfn_init(void) { - int i; + size_t i; sbuf_char = sbuf_make(); tab_agl = tab_alloc(LEN(agl)); for (i = 0; i < LEN(agl); i++) diff --git a/trfn_ch.h b/trfn_ch.h index dff5ee7..8bc27d2 100644 --- a/trfn_ch.h +++ b/trfn_ch.h @@ -379,14 +379,14 @@ static struct achar { unsigned m; unsigned f; } achars[] = { - {"hamza", 0x0621, 0xfe80}, + {"hamza", 0x0621, 0xfe80, 0, 0, 0}, {"alefwithmaddaabove", 0x0622, 0xfe81, 0, 0, 0xfe82}, {"alefwithhamzaabove", 0x0623, 0xfe83, 0, 0, 0xfe84}, {"wawwithhamzaabove", 0x0624, 0xfe85, 0, 0, 0xfe86}, {"alefwithhamzabelow", 0x0625, 0xfe87, 0, 0, 0xfe88}, {"yehwithhamzaabove", 0x0626, 0xfe89, 0xfe8b, 0xfe8c, 0xfe8a}, {"alef", 0x0627, 0xfe8d, 0, 0, 0xfe8e}, - {"arabicalef", 0x0627}, + {"arabicalef", 0x0627, 0, 0, 0, 0}, {"beh", 0x0628, 0xfe8f, 0xfe91, 0xfe92, 0xfe90}, {"tehmarbuta", 0x0629, 0xfe93, 0, 0, 0xfe94}, {"teh", 0x062a, 0xfe95, 0xfe97, 0xfe98, 0xfe96}, @@ -406,7 +406,7 @@ static struct achar { {"zah", 0x0638, 0xfec5, 0xfec7, 0xfec8, 0xfec6}, {"ain", 0x0639, 0xfec9, 0xfecb, 0xfecc, 0xfeca}, {"ghain", 0x063a, 0xfecd, 0xfecf, 0xfed0, 0xfece}, - {"tatweel", 0x0640}, + {"tatweel", 0x0640, 0, 0, 0, 0}, {"feh", 0x0641, 0xfed1, 0xfed3, 0xfed4, 0xfed2}, {"qaf", 0x0642, 0xfed5, 0xfed7, 0xfed8, 0xfed6}, {"kaf", 0x0643, 0xfed9, 0xfedb, 0xfedc, 0xfeda}, @@ -417,9 +417,9 @@ static struct achar { {"waw", 0x0648, 0xfeed, 0, 0, 0xfeee}, {"alefmaksura", 0x0649, 0xfeef, 0, 0, 0xfef0}, {"yeh", 0x064a, 0xfef1, 0xfef3, 0xfef4, 0xfef2}, - {"fathatan", 0x064b, 0xfe70}, - {"dammatan", 0x064c, 0xfe72}, - {"kasratan", 0x064d, 0xfe74}, + {"fathatan", 0x064b, 0xfe70, 0, 0, 0}, + {"dammatan", 0x064c, 0xfe72, 0, 0, 0}, + {"kasratan", 0x064d, 0xfe74, 0, 0, 0}, {"fatha", 0x064e, 0xfe76, 0, 0xfe77, 0}, {"damma", 0x064f, 0xfe78, 0, 0xfe79, 0}, {"kasra", 0x0650, 0xfe7a, 0, 0xfe7b, 0}, @@ -432,32 +432,32 @@ static struct achar { {"gaf", 0x06af, 0xfb92, 0xfb94, 0xfb95, 0xfb93}, {"farsiyeh", 0x06cc, 0xfbfc, 0xfbfe, 0xfbff, 0xfbfd}, {"lamwithalef", 0xfefb, 0xfefb, 0, 0, 0xfefc}, - {"arabiccomma", 0x060c}, - {"arabicsemicolon", 0x061b}, - {"arabicquestionmark", 0x061f}, - {"arabicindicdigitzero", 0x0660}, - {"arabicindicdigitone", 0x0661}, - {"arabicindicdigittwo", 0x0662}, - {"arabicindicdigitthree", 0x0663}, - {"arabicindicdigitfour", 0x0664}, - {"arabicindicdigitfive", 0x0665}, - {"arabicindicdigitsix", 0x0666}, - {"arabicindicdigitseven", 0x0667}, - {"arabicindicdigiteight", 0x0668}, - {"arabicindicdigitnine", 0x0669}, - {"arabicpercentsign", 0x066a}, - {"extendedarabicindicdigitzero", 0x06f0}, - {"extendedarabicindicdigitone", 0x06f1}, - {"extendedarabicindicdigittwo", 0x06f2}, - {"extendedarabicindicdigitthree", 0x06f3}, - {"extendedarabicindicdigitfour", 0x06f4}, - {"extendedarabicindicdigitfive", 0x06f5}, - {"extendedarabicindicdigitsix", 0x06f6}, - {"extendedarabicindicdigitseven", 0x06f7}, - {"extendedarabicindicdigiteight", 0x06f8}, - {"extendedarabicindicdigitnine", 0x06f9}, - {"zeronojoin", 0x200c}, - {"zerojoin", 0x200d}, + {"arabiccomma", 0x060c, 0, 0, 0, 0}, + {"arabicsemicolon", 0x061b, 0, 0, 0, 0}, + {"arabicquestionmark", 0x061f, 0, 0, 0, 0}, + {"arabicindicdigitzero", 0x0660, 0, 0, 0, 0}, + {"arabicindicdigitone", 0x0661, 0, 0, 0, 0}, + {"arabicindicdigittwo", 0x0662, 0, 0, 0, 0}, + {"arabicindicdigitthree", 0x0663, 0, 0, 0, 0}, + {"arabicindicdigitfour", 0x0664, 0, 0, 0, 0}, + {"arabicindicdigitfive", 0x0665, 0, 0, 0, 0}, + {"arabicindicdigitsix", 0x0666, 0, 0, 0, 0}, + {"arabicindicdigitseven", 0x0667, 0, 0, 0, 0}, + {"arabicindicdigiteight", 0x0668, 0, 0, 0, 0}, + {"arabicindicdigitnine", 0x0669, 0, 0, 0, 0}, + {"arabicpercentsign", 0x066a, 0, 0, 0, 0}, + {"extendedarabicindicdigitzero", 0x06f0, 0, 0, 0, 0}, + {"extendedarabicindicdigitone", 0x06f1, 0, 0, 0, 0}, + {"extendedarabicindicdigittwo", 0x06f2, 0, 0, 0, 0}, + {"extendedarabicindicdigitthree", 0x06f3, 0, 0, 0, 0}, + {"extendedarabicindicdigitfour", 0x06f4, 0, 0, 0, 0}, + {"extendedarabicindicdigitfive", 0x06f5, 0, 0, 0, 0}, + {"extendedarabicindicdigitsix", 0x06f6, 0, 0, 0, 0}, + {"extendedarabicindicdigitseven", 0x06f7, 0, 0, 0, 0}, + {"extendedarabicindicdigiteight", 0x06f8, 0, 0, 0, 0}, + {"extendedarabicindicdigitnine", 0x06f9, 0, 0, 0, 0}, + {"zeronojoin", 0x200c, 0, 0, 0, 0}, + {"zerojoin", 0x200d, 0, 0, 0, 0}, }; static int ctype_ascii[128] = { From d3eece4a96c6ba5d2542d306532650a1db2d45ee Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 5 Sep 2021 11:08:48 +0800 Subject: [PATCH 4/5] CMakeLists.txt: support building with CMake --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b778168 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.0) +project(neatmkfn C) +add_executable(mkfn mkfn.c trfn.c sbuf.c tab.c afm.c otf.c) +install(TARGETS mkfn) From 6740190c3bb913f61ee50e73cafe7e6af9314ccf Mon Sep 17 00:00:00 2001 From: Sizhe Zhao Date: Sun, 5 Sep 2021 11:11:54 +0800 Subject: [PATCH 5/5] CMakeLists.txt: link with ws2_32 --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b778168..ea5c378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 3.0) project(neatmkfn C) add_executable(mkfn mkfn.c trfn.c sbuf.c tab.c afm.c otf.c) +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + target_link_libraries(mkfn ws2_32) +endif() install(TARGETS mkfn)