From 18f815fe72cafead3deb8b8c81a9bfb00b639696 Mon Sep 17 00:00:00 2001 From: Yarmola Date: Thu, 27 Feb 2020 17:49:25 +0300 Subject: [PATCH] FontLab-required changes --- c/makeotf/makeotf_lib/api/hotconv.h | 20 ++- c/makeotf/makeotf_lib/api/typecomp.h | 2 + c/makeotf/makeotf_lib/source/hotconv/GDEF.c | 4 +- c/makeotf/makeotf_lib/source/hotconv/GDEF.h | 10 ++ c/makeotf/makeotf_lib/source/hotconv/GPOS.c | 139 +++++++++++++----- c/makeotf/makeotf_lib/source/hotconv/GPOS.h | 13 ++ c/makeotf/makeotf_lib/source/hotconv/GSUB.c | 133 +++++++++++++---- c/makeotf/makeotf_lib/source/hotconv/GSUB.h | 12 ++ c/makeotf/makeotf_lib/source/hotconv/OS_2.h | 10 ++ c/makeotf/makeotf_lib/source/hotconv/cmap.c | 2 +- c/makeotf/makeotf_lib/source/hotconv/cmap.h | 10 ++ c/makeotf/makeotf_lib/source/hotconv/common.h | 2 +- .../makeotf_lib/source/hotconv/dlgauto.h | 14 +- c/makeotf/makeotf_lib/source/hotconv/feat.c | 131 +++++++++++++++-- c/makeotf/makeotf_lib/source/hotconv/feat.h | 29 ++++ .../makeotf_lib/source/hotconv/featerr.c | 4 +- .../makeotf_lib/source/hotconv/featgram.c | 23 ++- .../makeotf_lib/source/hotconv/featscan.c | 4 +- c/makeotf/makeotf_lib/source/hotconv/head.c | 20 ++- c/makeotf/makeotf_lib/source/hotconv/head.h | 13 ++ c/makeotf/makeotf_lib/source/hotconv/hot.c | 66 ++++++++- c/makeotf/makeotf_lib/source/hotconv/map.c | 77 +++++++++- c/makeotf/makeotf_lib/source/hotconv/map.h | 18 +++ c/makeotf/makeotf_lib/source/hotconv/name.c | 24 ++- c/makeotf/makeotf_lib/source/hotconv/name.h | 10 ++ c/makeotf/makeotf_lib/source/hotconv/otl.c | 50 ++++++- .../makeotf_lib/source/typecomp/common.h | 2 +- c/makeotf/makeotf_lib/source/typecomp/parse.c | 41 ++++-- c/makeotf/makeotf_lib/source/typecomp/tc.c | 14 ++ c/public/lib/source/dynarr/dynarr.c | 14 +- c/public/lib/source/t1read/t1read.c | 2 +- 31 files changed, 782 insertions(+), 131 deletions(-) diff --git a/c/makeotf/makeotf_lib/api/hotconv.h b/c/makeotf/makeotf_lib/api/hotconv.h index 015968e66..59a782e5c 100644 --- a/c/makeotf/makeotf_lib/api/hotconv.h +++ b/c/makeotf/makeotf_lib/api/hotconv.h @@ -181,7 +181,8 @@ enum { hotNOTE, hotWARNING, hotERROR, - hotFATAL + hotFATAL, + hotFATALQUIT //FONTLAB }; struct hotCallbacks_ { @@ -304,6 +305,8 @@ struct hotCallbacks_ { void (*featClose)(void *ctx); void (*featAddAnonData)(void *ctx, char *data, long count, unsigned long tag); + //FONTLAB + unsigned short (*featNoGlyph) (void *ctx, char *name); /* [Optional] These functions are called to handle feature file support. featOpen() is called to open either the main feature file for the font @@ -409,6 +412,8 @@ char *hotReadFont(hotCtx g, int flags, int *psinfo, hotReadFontOverrides *fontOv #define HOT_SUBSET (1<<13) #define HOT_SUPRESS__WIDTH_OPT (1<<14) /* suppress width optimization in CFF: makes it easier to poke at charstrings with other tools */ #define HOT_VERBOSE (1<<15) /* Print all warnings and notes: else suppress the most annoying ones. */ +//FONTLAB +#define HOT_NOREORDER (1<<16) /* Keep glyph ordering */ struct hotReadFontOverrides_ /* Record for instructions to modify font as it is read in. */ { @@ -764,9 +769,16 @@ int hotAddName(hotCtx g, #define HOT_NAME_DESCRIPTION 10 #define HOT_NAME_VENDOR_URL 11 #define HOT_NAME_DESIGNER_URL 12 +//FONTLAB +#define HOT_NAME_LICENSE 13 +#define HOT_NAME_LICENSE_URL 14 + #define HOT_NAME_PREF_FAMILY 16 #define HOT_NAME_PREF_SUBFAMILY 17 #define HOT_NAME_COMP_FULL 18 +//FONTLAB +#define HOT_NAME_SAMPLE_TEXT 19 + #define HOT_NAME_WPF_FAMILY 21 #define HOT_NAME_WPF_STYLE 22 #define HOT_NAME_REG_LAST HOT_NAME_WPF_STYLE @@ -822,6 +834,9 @@ void hotConvert(hotCtx g); convertFlags is used to control the processing of the data. */ +//FONTLAB +void hotReuse(hotCtx g); + /* convertFlags values */ #define HOT_ID2_CHAIN_CONTXT3 (1 << 0) /* Index the backup glyph node list */ /* backwards (relative to the spec) */ @@ -864,6 +879,9 @@ void hotConvert(hotCtx g); /* hotFree() destroys the library context and all the resources allocated to it. It must be the last function called by a client of the library. */ +// FONTLAB +#define HOT_CUSTOM_UNICODE (1 << 2) + void hotFree(hotCtx g); /* Environment variables used to set default values */ diff --git a/c/makeotf/makeotf_lib/api/typecomp.h b/c/makeotf/makeotf_lib/api/typecomp.h index 733ed8210..f439d3740 100644 --- a/c/makeotf/makeotf_lib/api/typecomp.h +++ b/c/makeotf/makeotf_lib/api/typecomp.h @@ -236,6 +236,8 @@ void tcCompactFont(tcCtx g, long flags); #define TC_SUPPRESS_WIDTH_OPT (1<<17) /* suppress width optimization in CFF: makes it easier to peek at charstrings with other tools */ #define TC_VERBOSE (1<<18) /* print all warnings and notes, including the annoyingly repetitive ones. */ +//FONTLAB +#define TC_NOREORDER (1<<19) /* Do not reorder glyphs */ int tcSetStats(tcCtx g, int gather); diff --git a/c/makeotf/makeotf_lib/source/hotconv/GDEF.c b/c/makeotf/makeotf_lib/source/hotconv/GDEF.c index 02cafbdb8..5306cbe0b 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/GDEF.c +++ b/c/makeotf/makeotf_lib/source/hotconv/GDEF.c @@ -242,7 +242,9 @@ void GDEFFree(hotCtx g) { dnaFREE(h->glyphClasses); if (h->glyphClassTable != NULL) { - otlTableFree(g, h->glyphClassTable); + otlTableFreeClassDef(g, h->glyphClassTable); // FONTLAB memleaks + otlTableFree(g, h->glyphClassTable); + h->glyphClassTable = NULL; // FONTLAB memleaks } for (i = 0; i < h->attachEntries.cnt; i++) { diff --git a/c/makeotf/makeotf_lib/source/hotconv/GDEF.h b/c/makeotf/makeotf_lib/source/hotconv/GDEF.h index 3e2fe58f0..863ca5d21 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/GDEF.h +++ b/c/makeotf/makeotf_lib/source/hotconv/GDEF.h @@ -11,6 +11,11 @@ #define GDEF_ TAG('G', 'D', 'E', 'F') #define kMaxMarkAttachClasses 15 +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + /* Standard functions */ void GDEFNew(hotCtx g); int GDEFFill(hotCtx g); @@ -29,4 +34,9 @@ unsigned short addGlyphMarkClassGDEF(hotCtx g, GNode *markClass); unsigned short addMarkSetClassGDEF(hotCtx g, GNode *markClass); +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_GDEF_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/GPOS.c b/c/makeotf/makeotf_lib/source/hotconv/GPOS.c index 7439786a0..257ab05ff 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/GPOS.c +++ b/c/makeotf/makeotf_lib/source/hotconv/GPOS.c @@ -544,6 +544,14 @@ void GPOSWrite(hotCtx g) { } } +//FONTLAB +unsigned GPOSGetMaxContext(hotCtx g) +{ + GPOSCtx h = g->ctx.GPOS; + return h->maxContext; +} +//FONTLAB END + void GPOSReuse(hotCtx g) { GPOSCtx h = g->ctx.GPOS; int i; @@ -560,6 +568,8 @@ void GPOSReuse(hotCtx g) { if (sub->extension.use) { freeExtension(g, h, sub); /* In addition to the following frees: */ } + //FONTLAB + if (sub->tbl) { switch (sub->lkpType) { case GPOSSingle: freeSinglePos(g, sub); @@ -597,6 +607,7 @@ void GPOSReuse(hotCtx g) { break; } } + } //FONTLAB h->new.rules.cnt = 0; h->new.markClassList.cnt = 0; @@ -616,7 +627,9 @@ void GPOSReuse(hotCtx g) { h->maxContext = 0; h->hadError = 0; - otlTableReuse(g, h->otl); + //FONTLAB + if (h->otl) + otlTableReuse(g, h->otl); } void GPOSFree(hotCtx g) { @@ -710,6 +723,8 @@ static void startNewSubtable(hotCtx g) { sub->lkpFlag = h->new.lkpFlag; sub->markSetIndex = h->new.markSetIndex; sub->label = h->new.label; + //FONTLAB + sub->tbl = NULL; sub->extension.use = h->new.useExtension; if (h->new.useExtension && (!IS_REF_LAB(h->new.label)) && (!hasFeatureParam)) { @@ -747,7 +762,11 @@ void GPOSLookupBegin(hotCtx g, unsigned lkpType, unsigned lkpFlag, Label label, short useExtension, unsigned short useMarkSetIndex) { GPOSCtx h = g->ctx.GPOS; SubtableInfo *newsi = &h->new; - +// FONTLAB + for (int i = 0; i < newsi->baseList.cnt; i++) { + dnaFREE(newsi->baseList.array[i].anchorMarkInfo); + } +// FONTLAB OVER DF(2, (stderr, " { GPOS lkpType=%s%d lkpFlag=%d label=%x\n", useExtension ? "EXTENSION:" : "", lkpType, lkpFlag, label)); @@ -1525,26 +1544,35 @@ static void writeSinglePos(hotCtx g, GPOSCtx h, Subtable *sub) { } static void freeSinglePos1(hotCtx g, Subtable *sub) { - SinglePosFormat1 *fmt = sub->tbl; + SinglePosFormat1 *fmt = sub->tbl; + //FONTLAB + if (fmt) MEM_FREE(g, fmt); } static void freeSinglePos2(hotCtx g, Subtable *sub) { - SinglePosFormat2 *fmt = sub->tbl; + SinglePosFormat2 *fmt = sub->tbl; + //FONTLAB + if (fmt) { MEM_FREE(g, fmt->Value); MEM_FREE(g, fmt); + } } static void freeSinglePos(hotCtx g, Subtable *sub) { - switch (*(unsigned short *)sub->tbl) { - case 1: - freeSinglePos1(g, sub); - break; - - case 2: - freeSinglePos2(g, sub); - break; - } + //FONTLAB + if (!sub || !sub->tbl) + return; + + switch (*(unsigned short *)sub->tbl) { + case 1: + freeSinglePos1(g, sub); + break; + + case 2: + freeSinglePos2(g, sub); + break; + } } /* ---------------------------- Pair Adjustment ---------------------------- */ @@ -1674,9 +1702,10 @@ static int validInClassDef(GPOSCtx h, int classDefInx, GNode *gc, return -1; /* One of the glyphs already exists in a class */ } } - /* Classes start numbering from 0 for ClassDef1, 1 for ClassDef2 */ - *class = (unsigned short)((classDefInx == 0) ? cdef->classInfo.cnt - : cdef->classInfo.cnt + 1); + /* Classes start numbering from 0 for ClassDef1, 1 for ClassDef2 */// FONTLAB: now act equal for left and right classes + // *class = (unsigned short)((classDefInx == 0) ? cdef->classInfo.cnt + // : cdef->classInfo.cnt + 1); + *class = (unsigned short)(cdef->classInfo.cnt + 1); *insert = 1; return (int)inx; } @@ -1689,9 +1718,9 @@ static void insertInClassDef(GPOSCtx h, int classDefInx, GNode *gc, int inx, ClassDef *cdef = &h->classDef[classDefInx]; ClassInfo *ci = INSERT(cdef->classInfo, inx); - /* Classes start numbering from 0 for ClassDef1, 1 for ClassDef2 */ - ci->class = (classDefInx == 0) ? cdef->classInfo.cnt - 1 - : cdef->classInfo.cnt; + /* Classes start numbering from 0 for ClassDef1, 1 for ClassDef2 */ // FONTLAB: now act equal for left and right classes +// ci->class = (classDefInx == 0) ? cdef->classInfo.cnt - 1 +// : cdef->classInfo.cnt; ci->class = class; ci->gc = gc; @@ -2020,7 +2049,9 @@ static void addPosRule(hotCtx g, GPOSCtx h, SubtableInfo *si, GNode *targ, char rule = dnaNEXT(si->rules); rule->targ = targ; - } else { + } + else if (targ->metricsInfo) // FONTLAB + { if (targ->metricsInfo->cnt == 1) { /* assume it is an xAdvance adjustment */ GPOSAddSingle(g, si, targ, 0, 0, targ->metricsInfo->metrics[0], 0); @@ -2552,7 +2583,9 @@ static Offset classDefMake(hotCtx g, GPOSCtx h, otlTbl t, int cdefInx, if (g->convertFlags & HOT_DO_NOT_OPTIMIZE_KERN) *count = (unsigned short)cdef->classInfo.cnt + 1; else - *count = (unsigned short)((cdefInx == 0) ? cdef->classInfo.cnt : cdef->classInfo.cnt + 1); + // *count = (unsigned short)((cdefInx == 0) ? cdef->classInfo.cnt : cdef->classInfo.cnt + 1); // FONTLAB: now act equal for left and right classes + *count = (unsigned short)(cdef->classInfo.cnt + 1); + otlClassBegin(g, t); for (i = 0; i < cdef->classInfo.cnt; i++) { ClassInfo *ci = &cdef->classInfo.array[i]; @@ -3332,6 +3365,9 @@ static void freePairPos1(hotCtx g, Subtable *sub) { int i; PairPosFormat1 *fmt = sub->tbl; + if (!fmt) //FONTLAB + return; + /* Free pair sets */ for (i = 0; i < fmt->PairSetCount; i++) { MEM_FREE(g, fmt->PairSet_[i].PairValueRecord); @@ -3349,7 +3385,12 @@ static void freePairPos1(hotCtx g, Subtable *sub) { static void freePairPos2(hotCtx g, Subtable *sub) { PairPosFormat2 *fmt = sub->tbl; - MEM_FREE(g, fmt->Class1Record[0].Class2Record); + if (!fmt) //FONTLAB + return; + + if (fmt->Class1Record != NULL) { + MEM_FREE(g, fmt->Class1Record[0].Class2Record); + } MEM_FREE(g, fmt->Class1Record); MEM_FREE(g, fmt); @@ -3358,6 +3399,14 @@ static void freePairPos2(hotCtx g, Subtable *sub) { /* Free pair positioning subtable */ static void freePairPos(hotCtx g, Subtable *sub) { + if (!sub || !sub->tbl) //FONTLAB + { + fprintf(stderr, "Format-specific data in subtable is NULL\n"); + return; + } + + // FONTLAB OVER + switch (*(unsigned short *)sub->tbl) { case 1: freePairPos1(g, sub); @@ -3380,6 +3429,9 @@ static void freeFeatParam(hotCtx g, Subtable *sub) { static void freeChain3(hotCtx g, GPOSCtx h, Subtable *sub) { ChainContextPosFormat3 *fmt = sub->tbl; + if (!fmt) //FONTLAB + return; + if (fmt->Backtrack != NULL) { MEM_FREE(g, fmt->Backtrack); } @@ -3398,6 +3450,9 @@ static void freeChain3(hotCtx g, GPOSCtx h, Subtable *sub) { /* Free Chain substitution format table */ static void freeChain(hotCtx g, GPOSCtx h, Subtable *sub) { + if (!sub || !sub->tbl) //FONTLAB + return; + switch (*(unsigned short *)sub->tbl) { case 1: break; @@ -3605,7 +3660,9 @@ static void checkBaseAnchorConflict(hotCtx g, BaseGlyphRec *baseGlyphArray, long } /* Sort by GID, anchor count, and then by anchor value */ - qsort(baseGlyphArray, recCnt, sizeof(BaseGlyphRec), cmpBaseRec); + if (!isMarkToLigature) //FONTLAB: If it's ligatures, we shouldn't change the order + qsort(baseGlyphArray, recCnt, sizeof(BaseGlyphRec), cmpBaseRec); + prev = &(baseGlyphArray[0]); cur = &(baseGlyphArray[1]); last = &(baseGlyphArray[recCnt - 1]); @@ -3967,16 +4024,19 @@ static void fillMarkToBase(hotCtx g, GPOSCtx h) { for (j = 0; j < fmt->ClassCount; j++) { if (baseAnchorArray[j] == 0xFFFFFFFFL) { - char msg[1024]; - baseAnchorArray[j] = 0xFFFFFFFFL; - featGlyphDump(g, baseRec->gid, '\0', 0); - if (h->new.fileName != NULL) { - sprintf(msg, " [%s line %ld]", h->new.fileName, baseRec->lineNum); - } else { - msg[0] = '\0'; - } - hotMsg(g, hotWARNING, "MarkToBase or MarkToMark error in %s. Glyph '%s' does not have an anchor point for a mark class that was used in a previous statement in the same lookup table. Setting the anchor point offset to 0.", - g->error_id_text, g->note.array, msg); +//FONTLAB: such a situation takes place with avoided and looks proper... + baseAnchorArray[j] = getAnchoOffset(g, &kDefaultAnchor, fmt); /* this returns the offset from the start of the anchor list. To be adjusted later*/ + featGlyphDump(g, baseRec->gid, '\0', 0); +// char msg[1024]; +// baseAnchorArray[j] = 0xFFFFFFFFL; +// featGlyphDump(g, baseRec->gid, '\0', 0); +// if (h->new.fileName != NULL) { +// sprintf(msg, " [%s line %ld]", h->new.fileName, baseRec->lineNum); +// } else { +// msg[0] = '\0'; +// } +// hotMsg(g, hotWARNING, "MarkToBase or MarkToMark error in %s. Glyph '%s' does not have an anchor point for a mark class that was used in a previous statement in the same lookup table. Setting the anchor point offset to 0.", +// g->error_id_text, g->note.array, msg); } } } @@ -4053,7 +4113,7 @@ static void writeMarkToBase(hotCtx g, GPOSCtx h, Subtable *sub) { for (i = 0; i < fmt->BaseArray_.BaseCount; i++) { BaseRecord *baseRec = &fmt->BaseArray_.BaseRecord[i]; for (j = 0; j < markClassCnt; j++) { - if (baseRec->BaseAnchorArray[j] == 0xFFFFFFFFL) + if (baseRec->BaseAnchorArray[j] == 0 || baseRec->BaseAnchorArray[j] == 0xFFFFFFFFL) // FONTLAB OUT2((Offset)0); else OUT2((Offset)(baseRec->BaseAnchorArray[j] + anchorListOffset)); @@ -4084,6 +4144,9 @@ static void freeMarkToBase(hotCtx g, Subtable *sub) { long i; MarkBasePosFormat1 *fmt = sub->tbl; + if (!fmt) //FONTLAB + return; + for (i = 0; i < fmt->BaseArray_.BaseCount; i++) { BaseRecord *baseRec = &fmt->BaseArray_.BaseRecord[i]; MEM_FREE(g, baseRec->BaseAnchorArray); @@ -4532,6 +4595,10 @@ static void writeCursive(hotCtx g, GPOSCtx h, Subtable *sub) { static void freeCursive(hotCtx g, Subtable *sub) { CursivePosFormat1 *fmt = sub->tbl; + + if (!fmt) //FONTLAB + return; + MEM_FREE(g, fmt->EntryExitRecord); dnaFREE(fmt->anchorList); MEM_FREE(g, fmt); @@ -4578,5 +4645,9 @@ static void freeExtension(hotCtx g, GPOSCtx h, Subtable *sub) { otlTableReuse(g, sub->extension.otl); otlTableFree(g, sub->extension.otl); + + if (!fmt) //FONTLAB + return; + MEM_FREE(g, fmt); } diff --git a/c/makeotf/makeotf_lib/source/hotconv/GPOS.h b/c/makeotf/makeotf_lib/source/hotconv/GPOS.h index 9b807a0aa..c0fcf0f27 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/GPOS.h +++ b/c/makeotf/makeotf_lib/source/hotconv/GPOS.h @@ -10,6 +10,11 @@ #define GPOS_ TAG('G', 'P', 'O', 'S') +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + /* Standard functions */ void GPOSNew(hotCtx g); @@ -18,6 +23,9 @@ void GPOSWrite(hotCtx g); void GPOSReuse(hotCtx g); void GPOSFree(hotCtx g); +//FONTLAB +unsigned GPOSGetMaxContext(hotCtx g); + /* Supplementary functions (See otl.h for script, language, feature, and lookup flag definitions) */ void GPOSFeatureBegin(hotCtx g, Tag script, Tag language, Tag feature); @@ -53,4 +61,9 @@ void GPOSAddPair(hotCtx g, void *si, GNode *first, GNode *second, char *filename void GPOSPrintAFMKernData(hotCtx g); +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_GPOS_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/GSUB.c b/c/makeotf/makeotf_lib/source/hotconv/GSUB.c index cd50d0897..c677db203 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/GSUB.c +++ b/c/makeotf/makeotf_lib/source/hotconv/GSUB.c @@ -445,6 +445,14 @@ void GSUBWrite(hotCtx g) { } } +//FONTLAB +unsigned GSUBGetMaxContext(hotCtx g) +{ + GSUBCtx h = g->ctx.GSUB; + return h->maxContext; +} +//FONTLAB END + void GSUBReuse(hotCtx g) { GSUBCtx h = g->ctx.GSUB; int i; @@ -462,6 +470,8 @@ void GSUBReuse(hotCtx g) { if (sub->extension.use) { freeExtension(g, h, sub); /* In addition to the following frees: */ } + //FONTLAB + if (sub->tbl) { switch (sub->lkpType) { case GSUBSingle: freeSingle(g, h, sub); @@ -503,6 +513,7 @@ void GSUBReuse(hotCtx g) { #endif /* HOT_FEAT_SUPPORT */ } } + } //FONTLAB h->new.rules.cnt = 0; h->offset.featParam = h->offset.subtable = 0; @@ -514,7 +525,9 @@ void GSUBReuse(hotCtx g) { h->featNameID.cnt = 0; h->maxContext = 0; - otlTableReuse(g, h->otl); + //FONTLAB + if (h->otl) + otlTableReuse(g, h->otl); } void GSUBFree(hotCtx g) { @@ -1016,7 +1029,9 @@ static void checkAndSortSingle(hotCtx g, GSUBCtx h) { SubstRule *prev = curr - 1; if (curr->targ->gid == prev->targ->gid) { - if (curr->repl->gid == prev->repl->gid) { + //FONTLAB: we decided to reduce the strictness of input fea-file checking + // if (curr->repl->gid == prev->repl->gid) + { featGlyphDump(g, curr->targ->gid, ',', 0); *dnaNEXT(g->note) = ' '; featGlyphDump(g, curr->repl->gid, '\0', 0); @@ -1032,13 +1047,16 @@ static void checkAndSortSingle(hotCtx g, GSUBCtx h) { prev->targ = NULL; prev->repl = NULL; nDuplicates++; - } else { - featGlyphDump(g, curr->targ->gid, '\0', 0); - hotMsg(g, hotFATAL, - "Duplicate target glyph for single " - "substitution in %s: %s", - g->error_id_text, g->note.array); - } + } + /* FONTLAB + else { + featGlyphDump(g, curr->targ->gid, '\0', 0); + hotMsg(g, hotFATAL, + "Duplicate target glyph for single " + "substitution in %s: %s", + g->error_id_text, g->note.array); + } + */ } } @@ -1221,6 +1239,9 @@ static void writeSingle(hotCtx g, GSUBCtx h, Subtable *sub) { static void freeSingle1(hotCtx g, GSUBCtx h, Subtable *sub) { SingleSubstFormat1 *fmt = sub->tbl; + //FONTLAB + if (!fmt) + return; MEM_FREE(g, fmt); } @@ -1229,6 +1250,9 @@ static void freeSingle1(hotCtx g, GSUBCtx h, Subtable *sub) { static void freeSingle2(hotCtx g, GSUBCtx h, Subtable *sub) { SingleSubstFormat2 *fmt = sub->tbl; + //FONTLAB + if (!fmt) + return; MEM_FREE(g, fmt->Substitute); MEM_FREE(g, fmt); } @@ -1236,6 +1260,10 @@ static void freeSingle2(hotCtx g, GSUBCtx h, Subtable *sub) { /* Free single substitution format table */ static void freeSingle(hotCtx g, GSUBCtx h, Subtable *sub) { + //FONTLAB + if (!sub || !sub->tbl) + return; + switch (*(unsigned short *)sub->tbl) { case 1: freeSingle1(g, h, sub); @@ -1407,7 +1435,8 @@ static void fillMultiple(hotCtx g, GSUBCtx h) { /* Check for duplicates */ if (j != 0 && rule->targ->gid == (rule - 1)->targ->gid) { featGlyphDump(g, rule->targ->gid, '\0', 0); - hotMsg(g, hotFATAL, + //FONTLAB: we decided to reduce the strictness of input fea-file checking + hotMsg(g, hotNOTE /*hotFATAL*/, "Duplicate target glyph for multiple substitution in " "%s: %s", g->error_id_text, @@ -1474,7 +1503,13 @@ static void writeMultiple(hotCtx g, GSUBCtx h, Subtable *sub) { static void freeMultiple(hotCtx g, GSUBCtx h, Subtable *sub) { MultipleSubstFormat1 *fmt = sub->tbl; - MEM_FREE(g, fmt->Sequence_[0].Substitute); + //FONTLAB + if (!fmt) + return; + + if (fmt->Sequence_ != NULL) { + MEM_FREE(g, fmt->Sequence_[0].Substitute); + } MEM_FREE(g, fmt->Sequence_); MEM_FREE(g, fmt->Sequence); MEM_FREE(g, fmt); @@ -1615,7 +1650,8 @@ static void fillAlternate(hotCtx g, GSUBCtx h) { /* Check for duplicates */ if (j != 0 && rule->targ->gid == (rule - 1)->targ->gid) { featGlyphDump(g, rule->targ->gid, '\0', 0); - hotMsg(g, hotFATAL, + //FONTLAB: we decided to reduce the strictness of input fea-file checking + hotMsg(g, hotNOTE /*hotFATAL*/, "Duplicate target glyph for alternate substitution in " "%s: %s", g->error_id_text, @@ -1681,7 +1717,14 @@ static void writeAlternate(hotCtx g, GSUBCtx h, Subtable *sub) { static void freeAlternate(hotCtx g, GSUBCtx h, Subtable *sub) { AlternateSubstFormat1 *fmt = sub->tbl; - MEM_FREE(g, fmt->AlternateSet_[0].Alternate); + //FONTLAB + if (!fmt) + return; + + if (fmt->AlternateSet_ != NULL) { + MEM_FREE(g, fmt->AlternateSet_[0].Alternate); + } + MEM_FREE(g, fmt->AlternateSet_); MEM_FREE(g, fmt->AlternateSet); MEM_FREE(g, fmt); @@ -1763,7 +1806,9 @@ static void checkAndSortLigature(hotCtx g, GSUBCtx h) { SubstRule *prev = curr - 1; if (cmpLigature(curr, prev) == 0) { - if (curr->repl->gid == prev->repl->gid) { + //FONTLAB: we decided to reduce the strictness of input fea-file checking + // if (curr->repl->gid == prev->repl->gid) + { featPatternDump(g, curr->targ, ',', 0); *dnaNEXT(g->note) = ' '; featGlyphDump(g, curr->repl->gid, '\0', 0); @@ -1779,18 +1824,21 @@ static void checkAndSortLigature(hotCtx g, GSUBCtx h) { prev->targ = NULL; prev->repl = NULL; nDuplicates++; - } else { - featPatternDump(g, curr->targ, '\0', 0); - hotMsg(g, hotFATAL, - "Duplicate target sequence but different " - "replacement glyphs in ligature substitutions in " - "%s: %s", - g->error_id_text, - g->note.array); - } - } - } - + } + /* //FONTLAB + else { + featPatternDump(g, curr->targ, '\0', 0); + hotMsg(g, hotFATAL, + "Duplicate target sequence but different " + "replacement glyphs in ligature substitutions in " + "%s: %s", + g->error_id_text, + g->note.array); + } + */ + } + } + if (nDuplicates > 0) { /* Duplicates sink to the bottom */ qsort(h->new.rules.array, h->new.rules.cnt, sizeof(SubstRule), @@ -2664,6 +2712,10 @@ static void freeChain1(hotCtx g, GSUBCtx h, Subtable *sub) { /* xxx */ + //FONTLAB + if (!fmt) + return; + MEM_FREE(g, fmt); } @@ -2674,6 +2726,10 @@ static void freeChain2(hotCtx g, GSUBCtx h, Subtable *sub) { /* xxx */ + //FONTLAB + if (!fmt) + return; + MEM_FREE(g, fmt); } @@ -2682,6 +2738,10 @@ static void freeChain2(hotCtx g, GSUBCtx h, Subtable *sub) { static void freeChain3(hotCtx g, GSUBCtx h, Subtable *sub) { ChainContextSubstFormat3 *fmt = sub->tbl; + //FONTLAB + if (!fmt) + return; + if (fmt->Backtrack != NULL) { MEM_FREE(g, fmt->Backtrack); } @@ -2700,6 +2760,10 @@ static void freeChain3(hotCtx g, GSUBCtx h, Subtable *sub) { /* Free Chain substitution format table */ static void freeChain(hotCtx g, GSUBCtx h, Subtable *sub) { + //FONTLAB + if (!sub || !sub->tbl) + return; + switch (*(unsigned short *)sub->tbl) { case 1: freeChain1(g, h, sub); @@ -2774,6 +2838,8 @@ static void fillReverseChain1(hotCtx g, GSUBCtx h, otlTbl otl, Subtable *sub, GNode *pInput = NULL; GNode *pLook = NULL; GNode *p, *r; + //FONTLAB + GNode *saveP = NULL; unsigned subCount = 0; SubstRule *rule = &h->new.rules.array[inx]; @@ -2812,6 +2878,8 @@ static void fillReverseChain1(hotCtx g, GSUBCtx h, otlTbl otl, Subtable *sub, /* again. */ if (rule->repl != NULL) { /* No need for this whole block, if subCount === 0. */ + //FONTLAB + saveP = pInput; for (p = pInput, r = rule->repl; p != NULL; p = p->nextCl, r = r->nextCl) { /* I require in feat.c that pInput and repl lists have the same length */ p->nextSeq = r; @@ -2871,6 +2939,10 @@ static void fillReverseChain1(hotCtx g, GSUBCtx h, otlTbl otl, Subtable *sub, } sub->tbl = fmt; + + //FONTLAB + if (saveP) + saveP->nextSeq = NULL; // FONTLAB: We had problems in recycleNode without this nulling, because of double links to the same nodes in targ and repl } static void fillReverseChain(hotCtx g, GSUBCtx h) { @@ -2953,6 +3025,10 @@ static void writeReverseChain(hotCtx g, GSUBCtx h, Subtable *sub) { static void freeReverseChain(hotCtx g, GSUBCtx h, Subtable *sub) { ReverseChainContextSubstFormat1 *fmt = sub->tbl; + //FONTLAB + if (!fmt) + return; + if (fmt->Backtrack != NULL) { MEM_FREE(g, fmt->Backtrack); } @@ -3000,6 +3076,11 @@ static void freeExtension(hotCtx g, GSUBCtx h, Subtable *sub) { otlTableReuse(g, sub->extension.otl); otlTableFree(g, sub->extension.otl); + + //FONTLAB + if (!fmt) + return; + MEM_FREE(g, fmt); } diff --git a/c/makeotf/makeotf_lib/source/hotconv/GSUB.h b/c/makeotf/makeotf_lib/source/hotconv/GSUB.h index 95b06baf8..26d375099 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/GSUB.h +++ b/c/makeotf/makeotf_lib/source/hotconv/GSUB.h @@ -10,6 +10,11 @@ #define GSUB_ TAG('G', 'S', 'U', 'B') +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + /* Standard functions */ void GSUBNew(hotCtx g); @@ -18,6 +23,8 @@ void GSUBWrite(hotCtx g); void GSUBReuse(hotCtx g); void GSUBFree(hotCtx g); +//FONTLAB +unsigned GSUBGetMaxContext(hotCtx g); /* Supplementary functions (See otl.h for script, language, feature, and lookup flag definitions) */ void GSUBFeatureBegin(hotCtx g, Tag script, Tag language, Tag feature); @@ -72,4 +79,9 @@ void GSUBAddCVParam(hotCtx g, void *param); GSUBFeatureEnd(g); */ +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_GSUB_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/OS_2.h b/c/makeotf/makeotf_lib/source/hotconv/OS_2.h index 56831bbc0..a97d99e17 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/OS_2.h +++ b/c/makeotf/makeotf_lib/source/hotconv/OS_2.h @@ -7,6 +7,11 @@ #include "common.h" +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + #define OS_2_ TAG('O', 'S', '/', '2') /* Standard functions */ @@ -36,4 +41,9 @@ void OS_2SetWidthClass(hotCtx g, unsigned short widthClass); void OS_2LowerOpticalPointSize(hotCtx g, unsigned short opSize); void OS_2UpperOpticalPointSize(hotCtx g, unsigned short opSize); +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_OS_2_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/cmap.c b/c/makeotf/makeotf_lib/source/hotconv/cmap.c index 2687c9104..e95ca2b58 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/cmap.c +++ b/c/makeotf/makeotf_lib/source/hotconv/cmap.c @@ -1319,7 +1319,7 @@ int cmapFill(hotCtx g) { } if (!checkMacPlatform(h)) { - hotMsg(h->g, hotWARNING, "no Mac cmap specified"); +// FONTLAB hotMsg(h->g, hotWARNING, "no Mac cmap specified"); } h->tbl.version = cmap_VERSION; diff --git a/c/makeotf/makeotf_lib/source/hotconv/cmap.h b/c/makeotf/makeotf_lib/source/hotconv/cmap.h index 156ac84a1..995a881e2 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/cmap.h +++ b/c/makeotf/makeotf_lib/source/hotconv/cmap.h @@ -9,6 +9,11 @@ #define cmap_ TAG('c', 'm', 'a', 'p') +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + /* cmap platform/script codes */ /* Unicode */ #define cmap_UNI 0 /* Platform: Unicode */ @@ -54,4 +59,9 @@ void cmapEndUVSEncoding(hotCtx g); void cmapPointToPreviousEncoding(hotCtx g, unsigned platform, unsigned platformSpecific); +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_CMAP_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/common.h b/c/makeotf/makeotf_lib/source/hotconv/common.h index 671dd14c4..d4c552494 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/common.h +++ b/c/makeotf/makeotf_lib/source/hotconv/common.h @@ -423,7 +423,7 @@ struct hotCtx_ { vheaCtx vhea; vmtxCtx vmtx; } ctx; - dnaCtx dnaCtx; + dnaCtxPtr dnaCtx; dnaDCL(char, data); /* CFF data object buffer */ dnaDCL(char, tmp); /* Temporary conversion buffer */ dnaDCL(char, note); /* Buffer for accumulated messages */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/dlgauto.h b/c/makeotf/makeotf_lib/source/hotconv/dlgauto.h index 5d8e223cc..bda8c06fe 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/dlgauto.h +++ b/c/makeotf/makeotf_lib/source/hotconv/dlgauto.h @@ -47,6 +47,9 @@ int zzbufovf; /* indicates that buf int zzcharfull = 0; static zzchar_t *zznextpos; /* points to next available position in zzlextext*/ static int zzclass; +//FONTLAB +int err_fatal_linenum = -1; + #ifdef __USE_PROTOS void zzerrstd(const char *); @@ -66,11 +69,14 @@ static FILE *zzstream_in = 0; static int (*zzfunc_in)(void) = zzerr_in; static zzchar_t *zzstr_in = 0; -#ifdef USER_ZZMODE_STACK + +//FONTLAB +//#ifdef USER_ZZMODE_STACK int zzauto = 0; -#else -static int zzauto = 0; -#endif +//#else +//static int zzauto = 0; +//#endif + static int zzadd_erase; static char zzebuf[70]; diff --git a/c/makeotf/makeotf_lib/source/hotconv/feat.c b/c/makeotf/makeotf_lib/source/hotconv/feat.c index d6bb61bbe..ca45de7ba 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/feat.c +++ b/c/makeotf/makeotf_lib/source/hotconv/feat.c @@ -17,6 +17,19 @@ #include "BASE.h" #include "name.h" +//FONTLAB + +#define MAX_NOTE_LEN 1024 +static char str_stderr_msg[MAX_NOTE_LEN]; +extern int zzauto; +extern int err_fatal_linenum; +extern char str_err_hotmsg[]; + +static char err_fatal_filename[1024]; + +//FONTLAB OVER + + #define MAX_NUM_LEN 3 /* For glyph ranges */ #define MAX_PATH 1024 @@ -460,8 +473,11 @@ static void CDECL featMsg(int msgType, char *fmt, ...) { va_start(ap, fmt); vsprintf(msgVar, fmt, ap); va_end(ap); - sprintf(msg, "%s [%s %d]", msgVar, INCL.file, zzline); - +// FONTLAB +// sprintf(msg, "%s [%s %d]", msgVar, INCL.file, zzline); + sprintf(msg, "%s", msgVar); + strncpy(err_fatal_filename, INCL.file, sizeof(err_fatal_filename) - 1); + hotMsg(g, msgType, msg); } @@ -494,6 +510,26 @@ int featGetTagReturnMode(void) { return h->returnMode.tag; } +//FONTLAB +char *featGetErrorFileName(void) +{ + return err_fatal_filename; +} + +char *getLastStdErrMessage(void) +{ + return str_stderr_msg; +} + +void reinitGlobals() +{ + zzauto = 0; + err_fatal_linenum = -1; + str_err_hotmsg[0] = '\0'; +} + +//FONTLAB OVER + /* Add ch to the accumulating name table override string */ void featAddNameStringChar(char ch) { @@ -875,6 +911,10 @@ static void addVendorString(hotCtx g) { *dnaNEXT(h->nameString) = '\0'; setVendId_str(g, h->nameString.array); +// FONTLAB ??? +// if (setVendId_str(g, h->nameString.array)) { +// featMsg(hotERROR, "Bad string"); +// } } /* Return 1 if last line was seen. isEOL indicates whether ch is the last char @@ -1026,7 +1066,11 @@ void zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok, fprintf(stderr, " in %s", egroup); } } - fprintf(stderr, " [%s %d]\n", INCL.file, zzline); + //FONTLAB + // fprintf(stderr, " [%s %d]\n", INCL.file, zzline); + fprintf(stderr, "\n"); + strncpy(err_fatal_filename, INCL.file, sizeof(err_fatal_filename) - 1); + hotMsg(g, hotFATAL, "aborting because of errors"); } @@ -1736,7 +1780,8 @@ static HashElement *hashInstallElement(char *name, int existsOK) { /* new mark statement; otherwise, we are redefining a class */ if (!existsOK) { featMsg(hotWARNING, "Glyph class @%s redefined", - g->font.FontName.array, name); + /*g->font.FontName.array, */ //FONTLAB + name); MEM_FREE(g, el->name); featRecycleNodes(g, el->value.head); el->value.head = NULL; @@ -1746,6 +1791,33 @@ static HashElement *hashInstallElement(char *name, int existsOK) { return el; } +// FONTLAB +void _getNamedGlyphClasses(hotCtx g, FeaGlyphClasses res[]) +{ + unsigned i; + featCtx h = g->ctx.feat; + HashElement *j; + int count = 0; + for (i = 0; count < HASH_SIZE && i < HASH_SIZE; i++) + { + for (j = h->ht[i]; j != NULL; j = j->next) + { + // fprintf(stderr, "[%4u] @%s = ", i, j->name); + // featGlyphClassDump(g, j->value.head, '\n', 1); + + res[count].name = j->name; + res[count].startGlyph = j->value.head; + count++; + + if (count >= HASH_SIZE) + break; + } + } + res[count].name = NULL; + res[count].startGlyph = NULL; +} +// FONTLAB OVER + static void hashFree(featCtx h) { unsigned i; int iterations = 0; @@ -1770,7 +1842,7 @@ static void hashFree(featCtx h) { /* Map feature file glyph name to gid; emit error message and return notdef if not found (in order to continue until hotQuitOnError() called) */ -static GID featMapGName2GID(hotCtx g, char *gname, int allowNotdef) { +static GID featMapGName2GID(hotCtx g, char *gname, int allowNotdef, int allowIgnore) { // FONTLAB GID gid; char *realname; @@ -1780,6 +1852,12 @@ static GID featMapGName2GID(hotCtx g, char *gname, int allowNotdef) { gid = mapName2GID(g, gname, &realname); + //FONTLAB + if (allowIgnore && gid == GID_UNDEF && strcmp(gname, ".notdef") != 0 && g->cb.featNoGlyph != NULL) { + gid = g->cb.featNoGlyph(g->cb.ctx, gname); + } + //FONTLAB OVER + /* Return the glyph if found in the font. When allowNotdef is set, we * always return and callers should check for GID_UNDEF as we can't return * GID_NOTDEF in this case. */ @@ -1787,6 +1865,12 @@ static GID featMapGName2GID(hotCtx g, char *gname, int allowNotdef) { return gid; } + //FONTLAB + if (gid != GID_UNDEF) { + return gid; + } + //FONTLAB OVER + if (realname != NULL && strcmp(gname, realname) != 0) { featMsg(hotERROR, "Glyph \"%s\" (alias \"%s\") not in font", realname, gname); @@ -1865,7 +1949,7 @@ static void addAlphaRange(GID first, GID last, char *firstName, char *p, ptr = &gname[p - firstName]; for (; *ptr <= q; (*ptr)++) { - GID gid = (*ptr == *p) ? first : (*ptr == q) ? last : featMapGName2GID(g, gname, FALSE); + GID gid = (*ptr == *p) ? first : (*ptr == q) ? last : featMapGName2GID(g, gname, FALSE, TRUE); gcAddGlyph(gid); } } @@ -1880,11 +1964,14 @@ static void addNumRange(GID first, GID last, char *firstName, char *p1, long firstNum = getNum(p1, numLen); long lastNum = getNum(q1, numLen); + char fmt[128]; // FONTLAB - correction of error with range parsing + fmt[0] = '\0'; + for (i = firstNum; i <= lastNum; i++) { GID gid; - char fmt[128]; + // char fmt[128]; // FONTLAB char preNum[MAX_TOKEN]; - fmt[0] = '\0'; + // fmt[0] = '\0'; // FONTLAB if (i == firstNum) { gid = first; } else if (i == lastNum) { @@ -1898,7 +1985,7 @@ static void addNumRange(GID first, GID last, char *firstName, char *p1, preNum[p1 - firstName] = '\0'; } sprintf(gname, fmt, preNum, i, p2); - gid = featMapGName2GID(g, gname, FALSE); + gid = featMapGName2GID(g, gname, FALSE, TRUE); } gcAddGlyph(gid); } @@ -2068,6 +2155,10 @@ int featOpenIncludeFile(hotCtx g, char *filename) { return 0; /* Indicates no feature file for this font */ } else { InclFile *prev = &h->stack.array[h->stack.cnt - 2]; + //FONTLAB + zzline = prev->lineno; + strncpy(err_fatal_filename, prev->file, sizeof(err_fatal_filename) - 1); + hotMsg(g, hotFATAL, "include file <%s> not found [%s %d]", filename, prev->file, prev->lineno); } @@ -2466,7 +2557,9 @@ static int checkTag(Tag tag, int type, int atStart) { if (tag != h->curr.script) { if (tagAssign(tag, scriptTag, 1) == 0) { - zzerr("script behavior already specified"); + //FONTLAB: we decided to treat this as a warning + // zzerr("script behavior already specified"); + featMsg(hotWARNING, "script behavior already specified (text was \"%s\")", zzlextext); } h->language.cnt = 0; @@ -3012,9 +3105,21 @@ static void prepRule(Tag newTbl, int newlkpType, GNode *targ, GNode *repl) { !IS_REF_LAB(h->curr.label) && h->prev.label == h->curr.label) { if (h->curr.tbl != h->prev.tbl || h->curr.lkpType != h->prev.lkpType) { + //FONTLAB: we decided to allow one-glyph (single) rules for Ligature and Multiple types (main type is detected by the first rule of subtable) + if (h->curr.tbl == GSUB_ && h->curr.lkpType == GSUBSingle && h->prev.lkpType == GSUBLigature) + { + h->curr.lkpType = GSUBLigature; + } + else if (h->curr.tbl == GSUB_ && h->curr.lkpType == GSUBSingle && h->prev.lkpType == GSUBMultiple) + { + h->curr.lkpType = GSUBMultiple; + } + else + { // FONTLAB OVER featMsg(hotFATAL, "Lookup type different from previous " "rules in this lookup block"); + } // FONTLAB } else if (h->curr.lkpFlag != h->prev.lkpFlag) { featMsg(hotFATAL, "Lookup flags different from previous " @@ -4142,6 +4247,7 @@ static Label featGetLabelIndex(char *name) { curr = name2NamedLkp(name); if (curr == NULL) { featMsg(hotFATAL, "lookup name \"%s\" not defined", name); + return -1; } return curr->state.label; } @@ -4431,6 +4537,11 @@ void featReuse(hotCtx g) { h->metricsInfo.cnt = 0; h->anchorMarkInfo.cnt = 0; h->prod.cnt = 0; +// FONTLAB (memleak fix) + for (i = 0; i < h->markClasses.cnt; i++) { + MEM_FREE(g, h->markClasses.array[i]->markClassName); + } +// FONTLAB OVER h->markClasses.cnt = 0; h->anchorDefs.cnt = 0; h->valueDefs.cnt = 0; diff --git a/c/makeotf/makeotf_lib/source/hotconv/feat.h b/c/makeotf/makeotf_lib/source/hotconv/feat.h index 2b1bd9a80..69eaa874c 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/feat.h +++ b/c/makeotf/makeotf_lib/source/hotconv/feat.h @@ -7,6 +7,11 @@ #include "common.h" +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + #if HOT_DEBUG #define DF_LEVEL ((g->font.debug & HOT_DB_FEAT_2) ? 2 : ((g->font.debug & HOT_DB_FEAT_1) ? 1 : 0)) #define DF(L, p) \ @@ -121,6 +126,25 @@ int featFill(hotCtx g); void featReuse(hotCtx g); void featFree(hotCtx g); +//FONTLAB +typedef struct +{ + char *name; + GNode *startGlyph; +} FeaGlyphClasses; + +void _getNamedGlyphClasses(hotCtx g, FeaGlyphClasses res[]); + +int featGetErrorLineNum(void); +char *featGetErrorFileName(void); +char *getLastStdErrMessage(void); +char *getLastHotMessage(void); + +//FONTLAB - hotconv error correction - some global values should be reinit after previous unsuccessful (throw1 exit) fea-file parsing +void reinitGlobals(); + +//FONTLAB OVER + /* --- Supplementary functions --- */ GNode *featSetNewNode(hotCtx g, GID gid); void featRecycleNodes(hotCtx g, GNode *node); @@ -165,4 +189,9 @@ int featValidateGPOSChain(hotCtx g, GNode *targ, int lookupType); #endif /* HOT_FEAT_SUPPORT */ +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_FEAT_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/featerr.c b/c/makeotf/makeotf_lib/source/hotconv/featerr.c index 9d561bde9..e674fc67a 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/featerr.c +++ b/c/makeotf/makeotf_lib/source/hotconv/featerr.c @@ -11,8 +11,8 @@ */ #define ANTLR_VERSION 13333 -#include "pcctscfg.h" -#include "pccts_stdio.h" +//#include "pcctscfg.h" // FONTLAB +//#include "pccts_stdio.h" // FONTLAB /* --- This section will be included in all feat*.c files created. --- */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/featgram.c b/c/makeotf/makeotf_lib/source/hotconv/featgram.c index ec1820245..3fd954497 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/featgram.c +++ b/c/makeotf/makeotf_lib/source/hotconv/featgram.c @@ -11,8 +11,8 @@ */ #define ANTLR_VERSION 13333 -#include "pcctscfg.h" -#include "pccts_stdio.h" +//#include "pcctscfg.h" // FONTLAB +//#include "pccts_stdio.h" // FONTLAB /* --- This section will be included in all feat*.c files created. --- */ @@ -56,6 +56,13 @@ void zzcr_attr(Attrib *attr, int type, char *text); ANTLR_INFO +//FONTLAB +void InitGlobalVars() +{ + zzasp = ZZA_STACKSIZE; +} +//FONTLAB OVER + void featureFile(void); #include "feat.c" @@ -83,7 +90,8 @@ int allowNotdef; zzmatch(T_GNAME); gname = zzaCur; - _retv = featMapGName2GID(g, gname.text, allowNotdef); + _retv = featMapGName2GID(g, gname.text, allowNotdef, strchr(gname.text, '-') ? FALSE : TRUE); // FONTLAB +// _retv = featMapGName2GID(g, gname.text, allowNotdef); if (tok != NULL) strcpy(tok, gname.text); zzCONSUME; @@ -163,7 +171,8 @@ char *gcname; if ((setwd1[LA(1)] & 0x2)) { gid = glyph(p, TRUE); - if (gid == GID_UNDEF) { + //FONTLAB + if (gid == GID_UNDEF && strcmp(p, ".notdef") != 0) { char *secondPart = p; char *firstPart = p; /* it might be a range.*/ @@ -173,8 +182,8 @@ char *gcname; if (secondPart != NULL) { *secondPart = '\0'; secondPart++; - gid = featMapGName2GID(g, firstPart, FALSE); - endgid = featMapGName2GID(g, secondPart, FALSE); + gid = featMapGName2GID(g, firstPart, FALSE, TRUE); // FONTLAB + endgid = featMapGName2GID(g, secondPart, FALSE, TRUE); // FONTLAB if (gid != 0 && endgid != 0) { gcAddRange(gid, endgid, firstPart, secondPart); } else { @@ -182,7 +191,7 @@ char *gcname; } } else { - featMapGName2GID(g, firstPart, FALSE); + featMapGName2GID(g, firstPart, FALSE, FALSE); // FONTLAB hotMsg(g, hotFATAL, "aborting because of errors"); } zzEXIT(zztasp4); diff --git a/c/makeotf/makeotf_lib/source/hotconv/featscan.c b/c/makeotf/makeotf_lib/source/hotconv/featscan.c index 2fc14e5ee..f7e941cf2 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/featscan.c +++ b/c/makeotf/makeotf_lib/source/hotconv/featscan.c @@ -10,8 +10,8 @@ */ #define ANTLR_VERSION 13333 -#include "pcctscfg.h" -#include "pccts_stdio.h" +//#include "pcctscfg.h" +//#include "pccts_stdio.h" /* --- This section will be included in all feat*.c files created. --- */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/head.c b/c/makeotf/makeotf_lib/source/hotconv/head.c index 532b0f46a..c20ddb529 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/head.c +++ b/c/makeotf/makeotf_lib/source/hotconv/head.c @@ -100,6 +100,23 @@ static void saveTime(longDateTime ldt, struct tm *tm) { tm->tm_hour, tm->tm_min, tm->tm_sec); } +//FONTLAB +void headSetTime(hotCtx g, unsigned long *tt_time) +{ + headCtx h = g->ctx.head; + + char *ldt = h->tbl.created; + unsigned long elapsed = tt_time[0]; + + ldt[0] = ldt[1] = ldt[2] = ldt[3] = 0; + + ldt[4] = (char)(elapsed>>24); + ldt[5] = (char)(elapsed>>16); + ldt[6] = (char)(elapsed>>8); + ldt[7] = (char)elapsed; +} +//FONTLAB OVER + int headFill(hotCtx g) { headCtx h = g->ctx.head; @@ -109,7 +126,8 @@ int headFill(hotCtx g) { h->tbl.magicNumber = 0x5F0F3CF5; h->tbl.flags = head_BASELINE_0 | head_LSB_0; h->tbl.unitsPerEm = g->font.unitsPerEm; - saveTime(h->tbl.created, &g->time); + //FONTLAB + // saveTime(h->tbl.created, &g->time); saveTime(h->tbl.modified, &g->time); h->tbl.xMin = g->font.bbox.left; h->tbl.yMin = g->font.bbox.bottom; diff --git a/c/makeotf/makeotf_lib/source/hotconv/head.h b/c/makeotf/makeotf_lib/source/hotconv/head.h index b8c6991dc..665ca8205 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/head.h +++ b/c/makeotf/makeotf_lib/source/hotconv/head.h @@ -7,6 +7,11 @@ #include "common.h" +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + #define head_ TAG('h', 'e', 'a', 'd') /* Standard functions */ @@ -16,6 +21,14 @@ void headWrite(hotCtx g); void headReuse(hotCtx g); void headFree(hotCtx g); +//FONTLAB +void headSetTime(hotCtx g, unsigned long *tt_time); + #define HEAD_ADJUST_OFFSET (2 * int32) /* Checksum adjustment offset */ +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_HEAD_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/hot.c b/c/makeotf/makeotf_lib/source/hotconv/hot.c index 9380a579a..f5bbd8519 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/hot.c +++ b/c/makeotf/makeotf_lib/source/hotconv/hot.c @@ -22,6 +22,26 @@ #include #include +//FONTLAB +extern int zzline; +extern int err_fatal_linenum; +#define ERR_MSG_LEN 4096 +char str_err_hotmsg[ERR_MSG_LEN]; + +int featGetErrorLineNum(void) +{ +// fprintf(stderr, "line_assigned [%d]\n", err_fatal_linenum); + return err_fatal_linenum; +} + +char *getLastHotMessage(void) +{ + return str_err_hotmsg; +} + +//FONTLAB OVER + + /* Windows-specific macros */ #define FAMILY_UNSET 255 /* Flags unset Windows Family field */ #define ANSI_CHARSET 0 @@ -88,6 +108,16 @@ static void *hot_manage(ctlMemoryCallbacks *cb, void *old, size_t size) { } hotCtx hotNew(hotCallbacks *hotcb) { + //FONTLAB + { + void InitGlobalVars(); + + // Set an initial state. Otherwise, subsequent calls can produce + // an unpredictable result (for example, "Stack overflow" error) + InitGlobalVars(); + } + //FONTLAB OVER + hotCtx g = hotcb->malloc(hotcb->ctx, sizeof(struct hotCtx_)); tcCallbacks tccb; time_t now; @@ -382,6 +412,10 @@ char *hotReadFont(hotCtx g, int flags, int *psinfo, hotReadFontOverrides *fontOv } else { g->cb.getFinalGlyphName = NULL; /* suppresses renaming in feature file */ } + //FONTLAB + if (flags & HOT_NOREORDER) + tcflags |= TC_NOREORDER; /* turn on renaming in typecomp */ + //FONTLAB OVER if (flags & HOT_SUBSET) { tcflags |= TC_SUBSET; /* turn on subsetting to GOADB list in typecomp */ } @@ -1019,7 +1053,7 @@ static void setVBounds(hotCtx g) { } } -static void hotReuse(hotCtx g) { +void hotReuse(hotCtx g) { g->hadError = 0; g->convertFlags = 0; @@ -1205,6 +1239,8 @@ void hotFree(hotCtx g) { } dnaFREE(g->font.mm.instance); + dnaFree(g->dnaCtx); //FONTLAB memleaks + MEM_FREE(g, g); } @@ -1816,7 +1852,7 @@ void hotAddAnonTable(hotCtx g, unsigned long tag, hotAnonRefill refill) { /* Call fatal if hadError is set (this is set by a hotMsg() hotERROR call) */ void hotQuitOnError(hotCtx g) { if (g->hadError) { - hotMsg(g, hotFATAL, "aborting because of errors"); + hotMsg(g, hotFATALQUIT, "aborting because of errors"); // FONTLAB } } @@ -1829,6 +1865,20 @@ void CDECL hotMsg(hotCtx g, int level, char *fmt, ...) { void (*fatal)(void *) = NULL; /* Suppress optimizer warning */ void *ctx = NULL; /* Suppress optimizer warning */ + //FONTLAB + if (err_fatal_linenum < 0) + { + err_fatal_linenum = zzline; + str_err_hotmsg[0] = '\0'; + } + + if (level == hotFATAL) + err_fatal_linenum = zzline; + + if (level == hotFATALQUIT) + level = hotFATAL; + //FONTLAB OVER + if (level == hotFATAL) { fatal = g->cb.fatal; ctx = g->cb.ctx; @@ -1870,6 +1920,18 @@ void CDECL hotMsg(hotCtx g, int level, char *fmt, ...) { vsprintf(p, fmt, ap); va_end(ap); g->cb.message(g->cb.ctx, level, message); + //FONTLAB + int len = strlen(message); + if (len > (ERR_MSG_LEN - 2)) + len = ERR_MSG_LEN - 2; + + int lenNow = strlen(str_err_hotmsg); + if ((lenNow + 2 + len) > ERR_MSG_LEN) + str_err_hotmsg[0] = '\0'; + + strcat(str_err_hotmsg, message); + strcat(str_err_hotmsg, "\n"); + //FONTLAB OVER } } diff --git a/c/makeotf/makeotf_lib/source/hotconv/map.c b/c/makeotf/makeotf_lib/source/hotconv/map.c index c739b63be..8270d2838 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/map.c +++ b/c/makeotf/makeotf_lib/source/hotconv/map.c @@ -465,17 +465,27 @@ hotGlyphInfo *mapName2Glyph(hotCtx g, char *gname, char **useAliasDB) { void mapGID2Name(hotCtx g, GID gid, char *msg) { int len; - hotGlyphInfo *hGID = &g->font.glyphs.array[gid]; + //FONTLAB + //hotGlyphInfo *hGID = &g->font.glyphs.array[gid]; + hotGlyphInfo *hGID = (gid < g->font.glyphs.cnt) ? &g->font.glyphs.array[gid] : NULL; - if (hGID->srcName == NULL) { + if (!hGID) + { + strcpy(msg, "[null]"); + len = strlen(msg); + } + else + { + if (hGID->srcName == NULL) { sprintf(msg, "%s", hGID->gname.str); len = strlen(msg); - } else { + } else { if (g->convertFlags & HOT_CONVERT_FINAL_NAMES) - sprintf(msg, "%s", hGID->gname.str); + sprintf(msg, "%s", hGID->gname.str); else - sprintf(msg, "%s", hGID->srcName); + sprintf(msg, "%s", hGID->srcName); len = strlen(msg); + } } } @@ -2676,12 +2686,59 @@ static void initGlyphs(hotCtx g) { */ } +//FONTLAB +void mapInitGlyphs(hotCtx g) +{ + initGlyphs(g); +} + +/* Initialize both CID and non-CID fonts */ +void mapInitSortedArray(hotCtx g) +{ + mapCtx h = g->ctx.map; + long i; + long nGlyphs = g->font.glyphs.cnt; + + dnaSET_CNT(h->sort.gname, nGlyphs); /* Includes .notdef/CID 0 */ + + if (!IS_CID(g)) + for (i = 0; i < 256; i++) + h->sort.platEnc[i] = NULL; + + for (i = 0; i < nGlyphs; i++) + { + hotGlyphInfo *gi = &g->font.glyphs.array[i]; + h->sort.gname.array[i] = gi; /* Init sort ptrs to array elements */ + if (gi->uv != UV_UNDEF) + { + UV code = gi->uv; + gi->uv = UV_UNDEF; + + addUVToGlyph(g, gi, code); + }; + } + + /* Sort by glyph name/CID */ + qsort(h->sort.gname.array, h->sort.gname.cnt, sizeof(hotGlyphInfo *), IS_CID(g) ? cmpCID : cmpGlyphName); + qsort(h->sort.uv.array, h->sort.uv.cnt, sizeof(hotGlyphInfo *), cmpUV); +} + +void mapSortUv(hotCtx g) +{ + mapCtx h = g->ctx.map; + + qsort(h->sort.uv.array, h->sort.uv.cnt, sizeof(hotGlyphInfo *), cmpUV); +} + /* Initialize both CID and non-CID fonts */ static void mapInit(hotCtx g) { initGlyphs(g); if (!IS_CID(g)) { + //FONTLAB + if ((g->convertFlags & HOT_CUSTOM_UNICODE) == 0) { assignUVs(g); setCodePages(g); + } } /* non-CID: gname and uv lookup utilities ready to be used. */ @@ -2700,9 +2757,13 @@ void mapApplyReencoding(hotCtx g, hotEncoding *comEncoding, if (IS_CID(g)) { return; } - - mapInit(g); /* This assigns UVs */ - + + //FONTLAB + if ((g->convertFlags & HOT_CUSTOM_UNICODE) == 0) + mapInit(g); /* This assigns UVs */ + else + setCodePages(g); + if (g->font.flags & HOT_WIN) { reenc = comEncoding; } else if (g->font.flags & HOT_MAC) { diff --git a/c/makeotf/makeotf_lib/source/hotconv/map.h b/c/makeotf/makeotf_lib/source/hotconv/map.h index d190d332d..47cde8b9c 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/map.h +++ b/c/makeotf/makeotf_lib/source/hotconv/map.h @@ -14,8 +14,17 @@ #include "common.h" +//FONLTAB +#ifdef __cplusplus +extern "C" { +#endif + /* Standard functions */ void mapNew(hotCtx g); +//FONTLAB +void mapInitGlyphs(hotCtx g); +//FONTLAB OVER + int mapFill(hotCtx g); void mapReuse(hotCtx g); void mapFree(hotCtx g); @@ -52,4 +61,13 @@ GID mapWinANSI2GID(hotCtx g, int code); hotGlyphInfo *mapPlatEnc2Glyph(hotCtx g, int code); GID mapPlatEnc2GID(hotCtx g, int code); +//FONTLAB +void mapSortUv(hotCtx g); +void mapInitSortedArray(hotCtx g); + +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* MAP_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/name.c b/c/makeotf/makeotf_lib/source/hotconv/name.c index 625dd0bd4..bdc6ea8af 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/name.c +++ b/c/makeotf/makeotf_lib/source/hotconv/name.c @@ -63,6 +63,10 @@ static int enumNames(nameCtx h, int index, unsigned short platspecId, unsigned short languageId, unsigned short nameId) { + // FONTLAB + if (index < 0) + index = 0; + for (; index < h->tbl.record.cnt; index++) { NameRecord *rec = &h->tbl.record.array[index]; @@ -186,6 +190,9 @@ static void addName(nameCtx h, if (index != -1) { /* Matching name found */ rec = &h->tbl.record.array[index]; + //FONTLAB + return; + } else { /* No matching name found; append name */ rec = dnaNEXT(h->tbl.record); @@ -334,8 +341,9 @@ static void addStdNames(nameCtx h, int win, int mac) { } /* Add PostScript name */ - addStdNamePair(h, win, mac, HOT_NAME_FONTNAME, - strlen(g->font.FontName.array), g->font.FontName.array); + //FONTLAB + // addStdNamePair(h, win, mac, HOT_NAME_FONTNAME, + // strlen(g->font.FontName.array), g->font.FontName.array); } /* Delete a target name from list if the same as reference name. */ @@ -476,10 +484,14 @@ static void fillNames(nameCtx h) { MATCH_ANY, HOT_NAME_FAMILY); - if (tempString == NULL) { - hotMsg(h->g, hotFATAL, "I can't find a Family name for this font !"); - } - addWinDfltName(h, HOT_NAME_FAMILY, strlen(tempString), tempString); + // FONTLAB - sometimes we should deal with fea files without full valid name table + /* + if (tempString == NULL) { + hotMsg(h->g, hotFATAL, "I can't find a Family name for this font !"); + } + */ + if (tempString != NULL) // FONTLAB + addWinDfltName(h, HOT_NAME_FAMILY, strlen(tempString), tempString); } /**************************** First fill out all the Windows menu names */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/name.h b/c/makeotf/makeotf_lib/source/hotconv/name.h index 055b8be5b..1723f8917 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/name.h +++ b/c/makeotf/makeotf_lib/source/hotconv/name.h @@ -12,6 +12,11 @@ #define MISSING_MAC_DEFAULT_NAME 0x0002 #define MISSING_WIN_DEFAULT_NAME 0x0001 +//FONTLAB +#ifdef __cplusplus +extern "C" { +#endif + /* Standard functions */ void nameNew(hotCtx g); int nameFill(hotCtx g); @@ -31,4 +36,9 @@ unsigned short nameReserveUserID(hotCtx g); int nameVerifyDefaultNames(hotCtx g, unsigned short nameId); +//FONTLAB +#ifdef __cplusplus +} +#endif + #endif /* HOTCONV_NAME_H */ diff --git a/c/makeotf/makeotf_lib/source/hotconv/otl.c b/c/makeotf/makeotf_lib/source/hotconv/otl.c index b15e3f45e..542d300fe 100644 --- a/c/makeotf/makeotf_lib/source/hotconv/otl.c +++ b/c/makeotf/makeotf_lib/source/hotconv/otl.c @@ -428,6 +428,15 @@ static void coverageNew(hotCtx g, otlTbl t) { /* Fill format 1 table */ static CoverageFormat1 *fillCoverage1(hotCtx g, unsigned nGlyphs, GID *glyph) { + + // FONTLAB + if (nGlyphs == 0) + { + hotMsg(g, hotFATAL, "empty coverage"); + return NULL; + } + // FONTLAB OVER + unsigned int i; unsigned int dstIndex; CoverageFormat1 *fmt = MEM_NEW(g, sizeof(CoverageFormat1)); /* This may be more than we need, because we skip duplicate glyph IDs, but there's no harm in that. */ @@ -1575,7 +1584,9 @@ static Offset fillFeatureList(hotCtx g, otlTbl t) { /* This works because prepFeature has sorted the subtables so that anon subtables are last, preceded by Stand-Alone subtables */ int spanLimit = t->subtable.cnt - (t->nAnonSubtables + t->nStandAloneSubtables); - nFeatures = spanLimit ? t->subtable.array[spanLimit - 1].index.feature + 1 : 0; + //FONTLAB + nFeatures = (spanLimit <= 0) ? 0 : t->subtable.array[spanLimit - 1].index.feature + 1; +// nFeatures = spanLimit ? t->subtable.array[spanLimit - 1].index.feature + 1 : 0; /* Allocate features */ t->tbl.FeatureList_.FeatureCount = nFeatures; t->tbl.FeatureList_.FeatureRecord = @@ -1995,6 +2006,43 @@ void otlTableReuse(hotCtx g, otlTbl t) { t->nStandAloneSubtables = t->nAnonSubtables = t->nRefLookups = t->nFeatParams = 0; } +//FONTLAB +void otlTableFreeClassDef(hotCtx g, otlTbl t) +{ + // FONTLAB: memory leaks in GDEF are corrected + //freeClass(g, &t->class.new->tbl); + + if (t == NULL) + { + return; + } + + if (t->class.new == NULL) + { + return; + } + + unsigned short *ptbl = t->class.new->tbl; + if (!ptbl) + { + return; + } + + switch (*ptbl) + { + case 1: + freeClass1(g, t->class.new->tbl); + break; + case 2: + freeClass2(g, t->class.new->tbl); + break; + } + + MEM_FREE(g, t->class.new->tbl); + t->class.new->tbl = NULL; +} +//FONTLAB OVER + void otlTableFree(hotCtx g, otlTbl t) { if (t == NULL) { return; diff --git a/c/makeotf/makeotf_lib/source/typecomp/common.h b/c/makeotf/makeotf_lib/source/typecomp/common.h index 62730afb5..84cee8c52 100644 --- a/c/makeotf/makeotf_lib/source/typecomp/common.h +++ b/c/makeotf/makeotf_lib/source/typecomp/common.h @@ -142,7 +142,7 @@ struct tcCtx_ { uint32_t maxNumSubrs; SubrParseData *spd; /* Subroutinizer parse data */ struct { /* --- Module contexts */ - dnaCtx dnaCtx; + dnaCtxPtr dnaCtx; charsetCtx charset; csCtx cs; encodingCtx encoding; diff --git a/c/makeotf/makeotf_lib/source/typecomp/parse.c b/c/makeotf/makeotf_lib/source/typecomp/parse.c index d6e30c2f6..b498aff1a 100644 --- a/c/makeotf/makeotf_lib/source/typecomp/parse.c +++ b/c/makeotf/makeotf_lib/source/typecomp/parse.c @@ -489,6 +489,8 @@ static void readEncoding(parseCtx h) { length += namet.length; } while (psMatchToken(h->ps, psGetToken(h->ps), PS_OPERATOR, "dup")); } + else //FONTLAB + length = 0; /* Allocate name buffer */ h->encoding.data.cnt = 0; @@ -674,7 +676,9 @@ static void readChars(parseCtx h) { if (g->flags & TC_NOOLDOPS && sid < TABLE_LEN(stdcodes)) { /* Save standard-encoded char index */ uint8_t code = stdcodes[sid]; - h->component.stdindex[code] = h->chars.cnt - 1; + if (code != -1) { // FontLab + h->component.stdindex[code] = h->chars.cnt - 1; + } } } /* end if-else sid == SID_UNDEF */ } else { @@ -687,17 +691,19 @@ static void readChars(parseCtx h) { ((bname = h->encoding.custom[stdcodes[sid]]) != NULL && tc_strncmp(name.data, name.length, bname) == 0))) { uint8_t code = stdcodes[sid]; + if (code != -1) { // FontLab /* Standard encoded glyph save as possible component */ - new = dnaNEXT(h->component.chars); - new->index = h->buf.cnt; - new->length = binlen; - new->code = code; - new->id = sid; - new->encrypted = 1; - - /* Save standard-encoded char index */ - h->component.stdindex[code] = - COMP_CHAR | (h->component.chars.cnt - 1); + new = dnaNEXT(h->component.chars); + new->index = h->buf.cnt; + new->length = binlen; + new->code = code; + new->id = sid; + new->encrypted = 1; + + /* Save standard-encoded char index */ + h->component.stdindex[code] = + COMP_CHAR | (h->component.chars.cnt - 1); + } } } @@ -981,7 +987,8 @@ static void reorderChars(parseCtx h) { h->reorder.index.cnt = 0; /* We need to sort by SID to make sure that the added .notdef gets moved to array[0]. */ - qsort(&h->chars.array[0], h->chars.cnt, sizeof(Char), cmpSIDs); + if (!(g->flags & TC_NOREORDER)) //FONTLAB + qsort(&h->chars.array[0], h->chars.cnt, sizeof(Char), cmpSIDs); if (h->encoding.std) { /* Add StandardEncoding */ @@ -993,7 +1000,8 @@ static void reorderChars(parseCtx h) { } } else { /* Add custom encoding */ - qsort(&h->chars.array[1], h->chars.cnt - 1, sizeof(Char), cmpSIDs); + if (!(g->flags & TC_NOREORDER)) //FONTLAB + qsort(&h->chars.array[1], h->chars.cnt - 1, sizeof(Char), cmpSIDs); for (i = 0; i < 256; i++) { SID sid; @@ -1026,7 +1034,8 @@ static void reorderChars(parseCtx h) { } /* Sort chars by encoding then SID for unencoded glyphs */ - qsort(&h->chars.array[1], h->chars.cnt - 1, sizeof(Char), cmpChars); + if (!(g->flags & TC_NOREORDER)) //FONTLAB + qsort(&h->chars.array[1], h->chars.cnt - 1, sizeof(Char), cmpChars); /* Build encoding, charset, and index arrays (excluding .notdef) */ @@ -1985,7 +1994,7 @@ static void saveROS(parseCtx h, DICT *dict, int iKey) { /* Save string or literal value */ static void saveString(parseCtx h, DICT *dict, int iKey) { - unsigned length; + unsigned length = 0; //FONTLAB char *strng = NULL; /* Suppress optimizer warning */ Key *key = &h->keys[iKey]; psToken *token = &key->value; @@ -2477,6 +2486,8 @@ void parseNew(tcCtx g) { dnaINIT(g->ctx.dnaCtx, h->reorder.charset, 256, 64); dnaINIT(g->ctx.dnaCtx, h->reorder.index, 256, 64); + memset(&h->subset, 0, sizeof(h->subset)); //FONTLAB + h->firstNotice = 1; /* Initialize font dict keys. The chameleon key is saved in */ diff --git a/c/makeotf/makeotf_lib/source/typecomp/tc.c b/c/makeotf/makeotf_lib/source/typecomp/tc.c index 2924116ea..0ec88473c 100644 --- a/c/makeotf/makeotf_lib/source/typecomp/tc.c +++ b/c/makeotf/makeotf_lib/source/typecomp/tc.c @@ -18,6 +18,9 @@ #include #include +//FONTLAB +#include + /* CFF header */ typedef struct { unsigned char major; /* Major version number */ @@ -983,6 +986,7 @@ void tcFree(tcCtx g) { freeFonts(g); dnaFREE(h->set); + dnaFree(g->ctx.dnaCtx); // FONTLAB MEM_FREE(g, h); g->cb.free(g->cb.ctx, g); /* Free context */ } @@ -998,7 +1002,17 @@ void tcAddFont(tcCtx g, long flags) { g->flags = flags; font->filename = (g->cb.psId == NULL) ? "?" : g->cb.psId(g->cb.ctx); + + //FONTLAB + const char* local = setlocale(LC_NUMERIC, NULL); + if (!local || strcmp(local, "C")) + setlocale(LC_NUMERIC, "C"); + parseFont(g, font); + + //FONTLAB + if (local && strcmp(local, "C")) + setlocale(LC_NUMERIC, local); } /* Add additional copyright notice to font set */ diff --git a/c/public/lib/source/dynarr/dynarr.c b/c/public/lib/source/dynarr/dynarr.c index c81e6b647..19c75ed58 100644 --- a/c/public/lib/source/dynarr/dynarr.c +++ b/c/public/lib/source/dynarr/dynarr.c @@ -17,8 +17,8 @@ struct dnaCtx_ { /* Library context */ }; /* Validate client and create context. */ -dnaCtx dnaNew(ctlMemoryCallbacks *mem_cb, CTL_CHECK_ARGS_DCL) { - dnaCtx h; +dnaCtxPtr dnaNew(ctlMemoryCallbacks *mem_cb, CTL_CHECK_ARGS_DCL) { + dnaCtxPtr h; /* Check client/library compatibility */ if (CTL_CHECK_ARGS_TEST(DNA_VERSION)) { @@ -26,7 +26,7 @@ dnaCtx dnaNew(ctlMemoryCallbacks *mem_cb, CTL_CHECK_ARGS_DCL) { } /* Allocate context */ - h = (dnaCtx)mem_cb->manage(mem_cb, NULL, sizeof(struct dnaCtx_)); + h = (dnaCtxPtr)mem_cb->manage(mem_cb, NULL, sizeof(struct dnaCtx_)); if (h == NULL) { return NULL; } @@ -40,7 +40,7 @@ dnaCtx dnaNew(ctlMemoryCallbacks *mem_cb, CTL_CHECK_ARGS_DCL) { } /* Free library context. */ -void dnaFree(dnaCtx h) { +void dnaFree(dnaCtxPtr h) { if (h == NULL) { return; } @@ -49,7 +49,7 @@ void dnaFree(dnaCtx h) { } /* Initialize dynamic array. */ -void dnaInit(dnaCtx h, void *object, size_t init, size_t incr, int check) { +void dnaInit(dnaCtxPtr h, void *object, size_t init, size_t incr, int check) { dnaGeneric *da = (dnaGeneric *)object; if (check && da->size != 0) { @@ -72,7 +72,7 @@ long dnaGrow(void *object, size_t elemsize, long index) { void *new_ptr; size_t new_size; dnaGeneric *da = (dnaGeneric *)object; - dnaCtx h = da->ctx; + dnaCtxPtr h = da->ctx; if (index < da->size || elemsize == 0) { return 0; /* Use existing allocation */ @@ -185,7 +185,7 @@ long dnaExtend(void *object, size_t elemsize, long length) { void dnaFreeObj(void *object) { dnaGeneric *da = (dnaGeneric *)object; if (da->size != 0) { - dnaCtx h = da->ctx; + dnaCtxPtr h = da->ctx; h->mem.manage(&h->mem, da->array, 0); da->size = 0; } diff --git a/c/public/lib/source/t1read/t1read.c b/c/public/lib/source/t1read/t1read.c index 8e7d7b690..564b926f9 100644 --- a/c/public/lib/source/t1read/t1read.c +++ b/c/public/lib/source/t1read/t1read.c @@ -162,7 +162,7 @@ struct t1rCtx_ { float ForceBoldThreshold; } mm; pstCtx pst; /* pstoken lib context */ - dnaCtx dna; /* dynarr lib context */ + dnaCtxPtr dna; /* dynarr lib context */ struct /* Client callbacks */ { ctlMemoryCallbacks mem;