Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Support #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +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)
11 changes: 10 additions & 1 deletion mkfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif
#include "mkfn.h"

#define LEN(a) ((sizeof(a) / sizeof((a)[0])))
Expand Down Expand Up @@ -95,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)
Expand Down Expand Up @@ -125,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++)
Expand Down Expand Up @@ -236,6 +242,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");
Expand Down
33 changes: 31 additions & 2 deletions otf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* OpenType and TrueType fonts */
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -118,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;
Expand Down Expand Up @@ -162,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;
Expand Down Expand Up @@ -224,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);
Expand Down Expand Up @@ -370,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++) {
Expand Down Expand Up @@ -402,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);
Expand Down Expand Up @@ -465,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);
Expand Down Expand Up @@ -521,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);
Expand Down Expand Up @@ -586,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;
Expand Down Expand Up @@ -689,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++) {
Expand Down Expand Up @@ -722,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);
Expand All @@ -747,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);
Expand All @@ -773,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;
Expand Down Expand Up @@ -845,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 */
Expand Down Expand Up @@ -1207,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;
Expand Down
14 changes: 7 additions & 7 deletions trfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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)
Expand Down Expand Up @@ -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]);
Expand All @@ -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++)
Expand Down Expand Up @@ -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++)
Expand Down
64 changes: 32 additions & 32 deletions trfn_ch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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] = {
Expand Down