Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoHao committed Apr 12, 2020
2 parents 0cd9b68 + 65aa107 commit 3a9d426
Show file tree
Hide file tree
Showing 21 changed files with 266 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ If you have [Ninja](https://ninja-build.org/) installed on your system, you can
```bash
premake5 ninja
cd build/ninja
ninja otfccdump_Release_x64 otfccbuild_Release_x64
ninja otfccdump_release_x64 otfccbuild_release_x64
```

Change the targets above when necessary.
Expand Down
11 changes: 5 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
environment:
VS_VERSION: vs2015
VS_VERSION: vs2017

platform:
- x64

image: Visual Studio 2017

configuration:
- Release

install:
- set PATH=C:\msys64\usr\bin;%PATH%

before_build:
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64

build_script:
- dep\bin-win\premake5.exe vs2015
- cmd /c _vcbuild64.bat /property:Configuration=Release
- dep\bin-win\premake5.exe vs2017
- msbuild build\vs\otfcc.sln /m:%NUMBER_OF_PROCESSORS% /nr:false /nologo /verbosity:minimal /property:Configuration=Release
- make -f quick.make test
1 change: 1 addition & 0 deletions include/otfcc/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "logger.h"

typedef struct {
bool debug_wait_on_start;
bool ignore_glyph_order;
bool ignore_hints;
bool has_vertical_metrics;
Expand Down
3 changes: 1 addition & 2 deletions lib/bk/bkgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ static void dfs_attract_cells(bk_Block *b, bk_Graph *f, uint32_t *order, uint32_
return;
}
b->_visitstate = VISIT_GRAY;
for (uint32_t j = 0; j < b->length; j++) {
for (uint32_t j = b->length; j-- > 0;) {
bk_Cell *cell = &(b->cells[j]);
if (bk_cellIsPointer(cell) && cell->p) { dfs_attract_cells(cell->p, f, order, depth + 1); }
if (bk_cellIsPointer(cell) && cell->p) { dfs_attract_cells(cell->p, f, order, depth + 1); }
}
*order += 1;
f->entries[b->_index].order = *order;
Expand Down
3 changes: 2 additions & 1 deletion lib/font/caryll-sfnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static void otfcc_read_packets(otfcc_SplineFontContainer *font, FILE *file) {

for (uint32_t i = 0; i < font->packets[0].numTables; i++) {
(void)fseek(file, font->packets[count].pieces[i].offset, SEEK_SET);
(void)fread(font->packets[count].pieces[i].data, font->packets[count].pieces[i].length, 1, file);
(void)fread(font->packets[count].pieces[i].data, font->packets[count].pieces[i].length,
1, file);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/libcff/cff-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,12 @@ void cff_parseOutline(uint8_t *data, uint32_t len, cff_Index gsubr, cff_Index ls
gsubr, lsubr, stack, outline, methods, options);
break;
}
default: {
logWarning("Warning: unknown operator %d occurs in Type 2 CharString. It "
"may caused by file corruption.",
val.i);
return;
}
}
break;
case CS2_OPERAND:
Expand Down
4 changes: 2 additions & 2 deletions lib/support/base64/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ uint8_t *base64_encode(const uint8_t *src, size_t len, size_t *out_len) {
const uint8_t *end, *in;
size_t olen;

olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
olen++; /* nul termination */
olen = (len + 3 - 1) / 3 * 4; /* 3-byte blocks to 4-byte */
olen++; /* nul termination */
out = __caryll_malloc(sizeof(uint8_t) * olen);
if (out == NULL) return NULL;

Expand Down
19 changes: 16 additions & 3 deletions lib/support/bin-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#ifndef INLINE
#ifdef _MSC_VER
Expand Down Expand Up @@ -85,19 +86,31 @@ static INLINE uint64_t otfcc_endian_convert64(uint64_t i) {

static INLINE uint16_t otfcc_get16u(FILE *file) {
uint16_t tmp;
fread(&tmp, 2, 1, file);
size_t sizeRead = fread(&tmp, 2, 1, file);
if (!sizeRead) {
fprintf(stderr, "File corruption of terminated unexpectedly.\n");
exit(EXIT_FAILURE);
}
return otfcc_endian_convert16(tmp);
}

static INLINE uint32_t otfcc_get32u(FILE *file) {
uint32_t tmp;
fread(&tmp, 4, 1, file);
size_t sizeRead = fread(&tmp, 4, 1, file);
if (!sizeRead) {
fprintf(stderr, "File corruption of terminated unexpectedly.\n");
exit(EXIT_FAILURE);
}
return otfcc_endian_convert32(tmp);
}

static INLINE uint64_t otfcc_get64u(FILE *file) {
uint64_t tmp;
fread(&tmp, 8, 1, file);
size_t sizeRead = fread(&tmp, 8, 1, file);
if (!sizeRead) {
fprintf(stderr, "File corruption of terminated unexpectedly.\n");
exit(EXIT_FAILURE);
}
return otfcc_endian_convert64(tmp);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/support/unicodeconv/unicodeconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sds utf16le_to_utf8(const uint8_t *inb, int inlenb) {
}
}
in = (uint16_t *)inb;
sds out = sdsnewlen("", bytesNeeded);
sds out = sdsnewlen(NULL, bytesNeeded);
sds out0 = out;

while (in < inend) {
Expand Down Expand Up @@ -120,7 +120,7 @@ sds utf16be_to_utf8(const uint8_t *inb, int inlenb) {
}
}
in = (uint16_t *)inb;
sds out = sdsnewlen("", bytesNeeded);
sds out = sdsnewlen(NULL, bytesNeeded);
sds out0 = out;

while (in < inend) {
Expand Down
6 changes: 4 additions & 2 deletions lib/table/CFF.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,10 @@ static cff_Dict *cff_make_fd_dict(table_CFF *fd, cff_sid_entry **h) {
cffdict_input(dict, op_UnderlineThickness, cff_DOUBLE, 1, fd->underlineThickness);
cffdict_input(dict, op_StrokeWidth, cff_DOUBLE, 1, fd->strokeWidth);
if (fd->fontMatrix) {
cffdict_input(dict, op_FontMatrix, cff_DOUBLE, 6, fd->fontMatrix->a, fd->fontMatrix->b,
fd->fontMatrix->c, fd->fontMatrix->d, fd->fontMatrix->x, fd->fontMatrix->y);
cffdict_input(dict, op_FontMatrix, cff_DOUBLE, 6,
fd->fontMatrix->a, fd->fontMatrix->b,
fd->fontMatrix->c, fd->fontMatrix->d,
iVQ.getStill(fd->fontMatrix->x), iVQ.getStill(fd->fontMatrix->y));
}

// CID specific
Expand Down
13 changes: 10 additions & 3 deletions lib/table/OS_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ table_OS_2 *otfcc_readOS_2(const otfcc_Packet packet, const otfcc_Options *optio
if (length < 2) goto OS_2_CORRUPTED;
os_2 = table_iOS_2.create();
os_2->version = read_16u(data);
// version 1
if (os_2->version == 0 || (os_2->version >= 1 && length < 86)) goto OS_2_CORRUPTED;
if (os_2->version >= 1) {
// version 0 (Apple's TrueType)
if (length < 68) goto OS_2_CORRUPTED;
{
os_2->xAvgCharWidth = read_16u(data + 2);
os_2->usWeightClass = read_16u(data + 4);
os_2->usWidthClass = read_16u(data + 6);
Expand All @@ -45,11 +45,18 @@ table_OS_2 *otfcc_readOS_2(const otfcc_Packet packet, const otfcc_Options *optio
os_2->fsSelection = read_16u(data + 62);
os_2->usFirstCharIndex = read_16u(data + 64);
os_2->usLastCharIndex = read_16u(data + 66);
}
// version 0 (OpenType)
if (length >= 78) {
os_2->sTypoAscender = read_16s(data + 68);
os_2->sTypoDescender = read_16s(data + 70);
os_2->sTypoLineGap = read_16s(data + 72);
os_2->usWinAscent = read_16u(data + 74);
os_2->usWinDescent = read_16u(data + 76);
}
// version 1
if (os_2->version >= 1 && length < 86) goto OS_2_CORRUPTED;
if (os_2->version >= 1) {
os_2->ulCodePageRange1 = read_32u(data + 78);
os_2->ulCodePageRange2 = read_32u(data + 82);
}
Expand Down
73 changes: 49 additions & 24 deletions lib/table/cmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,15 @@ static void readFormat14(font_file_pointer start, uint32_t lengthLimit, table_cm
}
}

static void readCmapMappingTable(font_file_pointer start, uint32_t lengthLimit, table_cmap *cmap) {
static void readCmapMappingTable(font_file_pointer start, uint32_t lengthLimit, table_cmap *cmap,
tableid_t requiredFormat) {
uint16_t format = read_16u(start);
if (format == 4) {
readFormat4(start, lengthLimit, cmap);
} else if (format == 12) {
readFormat12(start, lengthLimit, cmap);
if (format == requiredFormat) {
if (format == 4) {
readFormat4(start, lengthLimit, cmap);
} else if (format == 12) {
readFormat12(start, lengthLimit, cmap);
}
}
}

Expand Down Expand Up @@ -264,6 +267,10 @@ static INLINE bool isValidCmapEncoding(uint16_t platform, uint16_t encoding) {
(platform == 3 && encoding == 10);
}

// Note: we do not support Apple's format 0 subtable
// since we not never support legacy fonts.
const tableid_t formatPriorities[] = {12, 4, 0};

// OTFCC will not support all `cmap` mappings.
table_cmap *otfcc_readCmap(const otfcc_Packet packet, const otfcc_Options *options) {
// the map is a reference to a hash table
Expand All @@ -277,18 +284,21 @@ table_cmap *otfcc_readCmap(const otfcc_Packet packet, const otfcc_Options *optio
uint16_t numTables = read_16u(data + 2);
if (length < 4 + 8 * numTables) goto CMAP_CORRUPTED;

// step 1 : read format 4 and 12
for (uint16_t j = 0; j < numTables; j++) {
uint16_t platform = read_16u(data + 4 + 8 * j);
uint16_t encoding = read_16u(data + 4 + 8 * j + 2);
if (!isValidCmapEncoding(platform, encoding)) continue;

uint32_t tableOffset = read_32u(data + 4 + 8 * j + 4);
readCmapMappingTable(data + tableOffset, length - tableOffset, cmap);
};
// step 1 : read format 12. The results are prioritized
for (size_t kSubtableType = 0; formatPriorities[kSubtableType]; kSubtableType++) {
for (uint16_t j = 0; j < numTables; j++) {
uint16_t platform = read_16u(data + 4 + 8 * j);
uint16_t encoding = read_16u(data + 4 + 8 * j + 2);
if (!isValidCmapEncoding(platform, encoding)) continue;

uint32_t tableOffset = read_32u(data + 4 + 8 * j + 4);
readCmapMappingTable(data + tableOffset, length - tableOffset, cmap,
formatPriorities[kSubtableType]);
};
}
HASH_SORT(cmap->unicodes, by_unicode);

// step2 : read format 14
// step 3 : read format 14
for (uint16_t j = 0; j < numTables; j++) {
uint16_t platform = read_16u(data + 4 + 8 * j);
uint16_t encoding = read_16u(data + 4 + 8 * j + 2);
Expand Down Expand Up @@ -538,6 +548,16 @@ static caryll_Buffer *otfcc_buildCmap_format4(const table_cmap *cmap) {
return buf;
}

static caryll_Buffer *otfcc_tryBuildCmap_format4(const table_cmap *cmap) {
caryll_Buffer *buf = otfcc_buildCmap_format4(cmap);
if (buflen(buf) > UINT16_MAX) {
// this cmap subtable is broken
buffree(buf);
return NULL;
} else
return buf;
}

static caryll_Buffer *otfcc_buildCmap_format12(const table_cmap *cmap) {
caryll_Buffer *buf = bufnew();
bufwrite16b(buf, 12);
Expand Down Expand Up @@ -705,18 +725,23 @@ caryll_Buffer *otfcc_buildCmap(const table_cmap *cmap, const otfcc_Options *opti
if (!cmap || !cmap->unicodes) return NULL;

cmap_Entry *entry;
bool hasSMP = false;
bool requiresFormat12 = false;
bool hasUVS = cmap->uvs && (HASH_COUNT(cmap->uvs) > 0);
foreach_hash(entry, cmap->unicodes) {
if (entry->unicode > 0xFFFF) { hasSMP = true; }
if (entry->unicode > 0xFFFF) { requiresFormat12 = true; }
}
uint8_t nTables = hasSMP ? 4 : 2;

caryll_Buffer *format4 = NULL;
if (!requiresFormat12 || !options->stub_cmap4) {
format4 = otfcc_tryBuildCmap_format4(cmap);
if (!format4)
requiresFormat12 = true;
}

uint8_t nTables = requiresFormat12 ? 4 : 2;
if (hasUVS) nTables += 1;

caryll_Buffer *format4;
if (!hasSMP || !options->stub_cmap4) {
format4 = otfcc_buildCmap_format4(cmap);
} else {
if (!format4) {
// Write a dummy
format4 = bufnew();
bufwrite16b(format4, 4); // format
Expand Down Expand Up @@ -746,7 +771,7 @@ caryll_Buffer *otfcc_buildCmap(const table_cmap *cmap, const otfcc_Options *opti
b16, 3, // BMP
p32, bk_newBlockFromBufferCopy(format4), // table
bkover);
if (hasSMP) {
if (requiresFormat12) {
bk_push(root, b16, 0, // unicode
b16, 4, // full
p32, bk_newBlockFromBufferCopy(format12), // table
Expand All @@ -763,7 +788,7 @@ caryll_Buffer *otfcc_buildCmap(const table_cmap *cmap, const otfcc_Options *opti
b16, 1, // Unicode BMP
p32, bk_newBlockFromBufferCopy(format4), // table
bkover);
if (hasSMP) {
if (requiresFormat12) {
bk_push(root, b16, 3, // Windows
b16, 10, // Unicode Full
p32, bk_newBlockFromBufferCopy(format12), // table
Expand Down
4 changes: 3 additions & 1 deletion lib/table/glyf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ typedef enum {
WE_HAVE_A_TWO_BY_TWO = (1 << 7),
WE_HAVE_INSTRUCTIONS = (1 << 8),
USE_MY_METRICS = (1 << 9),
OVERLAP_COMPOUND = (1 << 10)
OVERLAP_COMPOUND = (1 << 10),
SCALED_COMPONENT_OFFSET = (1 << 11),
UNSCALED_COMPONENT_OFFSET = (1 << 12)
} glyf_reference_flag;

typedef enum { MASK_ON_CURVE = 1 } glyf_oncurve_mask;
Expand Down
1 change: 1 addition & 0 deletions lib/table/glyf/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static void glyf_build_composite(const glyf_Glyph *g, caryll_Buffer *gbuf) {
}
if (r->roundToGrid) flags |= ROUND_XY_TO_GRID;
if (r->useMyMetrics) flags |= USE_MY_METRICS;
flags |= UNSCALED_COMPONENT_OFFSET;
bufwrite16b(gbuf, flags);
bufwrite16b(gbuf, r->glyph.index);
if (flags & ARG_1_AND_2_ARE_WORDS) {
Expand Down
6 changes: 5 additions & 1 deletion lib/table/glyf/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ static glyf_Glyph *otfcc_read_composite_glyph(font_file_pointer start,
ref.a = otfcc_from_f2dot14(read_16s(start + offset));
ref.b = otfcc_from_f2dot14(read_16s(start + offset + 2));
ref.c = otfcc_from_f2dot14(read_16s(start + offset + 4));
ref.d = otfcc_from_f2dot14(read_16s(start + offset + 2));
ref.d = otfcc_from_f2dot14(read_16s(start + offset + 6));
offset += 8;
}
ref.roundToGrid = flags & ROUND_XY_TO_GRID;
ref.useMyMetrics = flags & USE_MY_METRICS;
if (flags & SCALED_COMPONENT_OFFSET &&
(flags & WE_HAVE_AN_X_AND_Y_SCALE || flags & WE_HAVE_A_TWO_BY_TWO)) {
logWarning("glyf: SCALED_COMPONENT_OFFSET is not supported.")
}
if (flags & WE_HAVE_INSTRUCTIONS) { glyphHasInstruction = true; }
glyf_iReferenceList.push(&g->references, ref);
} while (flags & MORE_COMPONENTS);
Expand Down
18 changes: 11 additions & 7 deletions lib/table/otl/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ static bk_Block *writeOTLLookups(const table_OTL *table, const otfcc_Options *op
logNotice("Lookup %s is empty.\n", table->lookups.items[j]->name);
}
otl_Lookup *lookup = table->lookups.items[j];
bool useExtendedForIt = useExtended || preferExtForThisLut[j];
const bool canBeContextual = otfcc_chainingLookupIsContextualLookup(lookup);
const bool useExtendedForIt = useExtended || preferExtForThisLut[j];
if (useExtendedForIt) {
logNotice("[OTFCC-fea] Using extended OpenType table layout for %s/%s.\n", tag,
lookup->name);
Expand All @@ -149,19 +150,22 @@ static bk_Block *writeOTLLookups(const table_OTL *table, const otfcc_Options *op
: (lookup->type > otl_type_gpos_unknown
? lookup->type - otl_type_gpos_unknown
: lookup->type > otl_type_gsub_unknown ? lookup->type - otl_type_gsub_unknown
: 0);
: 0) -
(canBeContextual ? 1 : 0);

bk_Block *blk = bk_new_Block(b16, lookupType, // LookupType
b16, lookup->flags, // LookupFlag
b16, subtableQuantity[j], // SubTableCount
bkover);

for (tableid_t k = 0; k < subtableQuantity[j]; k++) {
if (useExtendedForIt) {
uint16_t extensionLookupType = lookup->type > otl_type_gpos_unknown
? lookup->type - otl_type_gpos_unknown
: lookup->type > otl_type_gsub_unknown
? lookup->type - otl_type_gsub_unknown
: 0;
uint16_t extensionLookupType = (lookup->type > otl_type_gpos_unknown
? lookup->type - otl_type_gpos_unknown
: lookup->type > otl_type_gsub_unknown
? lookup->type - otl_type_gsub_unknown
: 0) -
(canBeContextual ? 1 : 0);

bk_Block *stub =
bk_new_Block(b16, 1, // format
Expand Down
Loading

0 comments on commit 3a9d426

Please sign in to comment.