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 releases
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Nov 23, 2016
2 parents ce1c01d + e83d182 commit c1c217a
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 64 deletions.
5 changes: 5 additions & 0 deletions lib/font/caryll-font.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ static void deleteFontTable(otfcc_Font *font, const uint32_t tag) {
case 'COLR':
if (font->COLR) DELETE(table_iCOLR.free, font->COLR);
return;
case 'SVG ':
case 'SVG_':
if (font->SVG_) DELETE(table_iSVG.free, font->SVG_);
return;
}
}

Expand Down Expand Up @@ -130,6 +134,7 @@ static INLINE void disposeFont(otfcc_Font *font) {
deleteFontTable(font, 'VORG');
deleteFontTable(font, 'CPAL');
deleteFontTable(font, 'COLR');
deleteFontTable(font, 'SVG_');

GlyphOrder.free(font->glyph_order);
}
Expand Down
19 changes: 1 addition & 18 deletions lib/font/caryll-sfnt-builder.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#include "support/util.h"
#include "otfcc/sfnt-builder.h"

#ifndef MAIN_VER
#define MAIN_VER 0
#endif
#ifndef SECONDARY_VER
#define SECONDARY_VER 0
#endif
#ifndef PATCH_VER
#define PATCH_VER 0
#endif

static uint32_t buf_checksum(caryll_Buffer *buffer) {
uint32_t actualLength = (uint32_t)buflen(buffer);
buflongalign(buffer);
Expand Down Expand Up @@ -97,7 +87,7 @@ caryll_Buffer *otfcc_SFNTBuilder_serialize(otfcc_SFNTBuilder *builder) {
bufwrite16b(buffer, nTables * 16 - searchRange);

otfcc_SFNTTableEntry *table;
size_t offset = 32 + nTables * 16;
size_t offset = 12 + nTables * 16;
size_t headOffset = offset;
HASH_SORT(builder->tables, byTag);
foreach_hash(table, builder->tables) {
Expand All @@ -115,13 +105,6 @@ caryll_Buffer *otfcc_SFNTBuilder_serialize(otfcc_SFNTBuilder *builder) {
offset += buflen(table->buffer);
}

// we are right after the table directory
// add copyright information
sds copyright = sdscatprintf(sdsempty(), "-- By OTFCC %d.%d.%d --", MAIN_VER, SECONDARY_VER, PATCH_VER);
sdsgrowzero(copyright, 20);
bufwrite_bytes(buffer, 20, (uint8_t *)copyright);
sdsfree(copyright);

// write head.checksumAdjust
uint32_t wholeChecksum = buf_checksum(buffer);
bufseek(buffer, headOffset + 8);
Expand Down
50 changes: 50 additions & 0 deletions lib/otf-writer/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,59 @@ static void statOS_2AverageWidth(otfcc_Font *font, const otfcc_Options *options)
}
font->OS_2->xAvgCharWidth = totalWidth / font->glyf->length;
}
static uint16_t statMaxContextOTL(const table_OTL *table) {
uint16_t maxc = 1;
foreach (otl_Lookup **lookup_, table->lookups) {
otl_Lookup *lookup = *lookup_;
switch (lookup->type) {
case otl_type_gpos_pair:
case otl_type_gpos_markToBase:
case otl_type_gpos_markToLigature:
case otl_type_gpos_markToMark:
if (maxc < 2) maxc = 2;
break;
case otl_type_gsub_ligature:
foreach (otl_Subtable **subtable_, lookup->subtables) {
subtable_gsub_ligature *subtable = (subtable_gsub_ligature *)*subtable_;
foreach (otl_GsubLigatureEntry *entry, *subtable) {
if (maxc < entry->from->numGlyphs) { maxc = entry->from->numGlyphs; }
};
}
break;
case otl_type_gsub_chaining:
case otl_type_gpos_chaining:
foreach (otl_Subtable **subtable_, lookup->subtables) {
subtable_chaining *subtable = (subtable_chaining *)*subtable_;
if (maxc < subtable->rule.matchCount) maxc = subtable->rule.matchCount;
}
break;
case otl_type_gsub_reverse:
foreach (otl_Subtable **subtable_, lookup->subtables) {
subtable_gsub_reverse *subtable = (subtable_gsub_reverse *)*subtable_;
if (maxc < subtable->matchCount) maxc = subtable->matchCount;
}
break;
default:;
}
}
return maxc;
}
static void statMaxContext(otfcc_Font *font, const otfcc_Options *options) {
uint16_t maxc = 1;
if (font->GSUB) {
uint16_t maxc_gsub = statMaxContextOTL(font->GSUB);
if (maxc_gsub > maxc) maxc = maxc_gsub;
}
if (font->GPOS) {
uint16_t maxc_gpos = statMaxContextOTL(font->GPOS);
if (maxc_gpos > maxc) maxc = maxc_gpos;
}
font->OS_2->usMaxContext = maxc;
}
static void statOS_2(otfcc_Font *font, const otfcc_Options *options) {
statOS_2UnicodeRanges(font, options);
statOS_2AverageWidth(font, options);
statMaxContext(font, options);
}

#define MAX_STAT_METRIC 4096
Expand Down
19 changes: 14 additions & 5 deletions lib/support/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
otfcc_Options *otfcc_newOptions() {
otfcc_Options *options;
NEW(options);
options->cff_rollCharString = true;
return options;
}
void otfcc_deleteOptions(otfcc_Options *options) {
Expand All @@ -15,15 +14,25 @@ void otfcc_deleteOptions(otfcc_Options *options) {
FREE(options);
}
void otfcc_Options_optimizeTo(otfcc_Options *options, uint8_t level) {
if (level >= 1) { options->cff_rollCharString = true; }
options->cff_rollCharString = false;
options->short_post = false;
options->ignore_glyph_order = false;
options->cff_short_vmtx = false;
options->merge_features = false;
options->force_cid = false;
options->cff_doSubroutinize = false;

if (level >= 1) {
options->cff_rollCharString = true;
options->cff_short_vmtx = true;
}
if (level >= 2) {
options->short_post = true;
options->ignore_glyph_order = true;
options->cff_short_vmtx = true;
options->cff_doSubroutinize = true;
options->merge_features = true;
}
if (level >= 3) {
options->ignore_glyph_order = true;
options->force_cid = true;
options->cff_doSubroutinize = true;
}
}
68 changes: 31 additions & 37 deletions lib/table/cmap.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cmap.h"

#include "support/util.h"
#include "bk/bkgraph.h"

// PART I, type definition

Expand Down Expand Up @@ -366,20 +367,16 @@ caryll_Buffer *otfcc_buildCmap_format12(const table_cmap *cmap) {
return buf;
}
caryll_Buffer *otfcc_buildCmap(const table_cmap *cmap, const otfcc_Options *options) {
caryll_Buffer *buf = bufnew();
if (!cmap || !cmap->unicodes) return buf;
if (!cmap || !cmap->unicodes) return bufnew();
;

cmap_Entry *entry;
bool hasSMP = false;
foreach_hash(entry, cmap->unicodes) {
if (entry->unicode > 0xFFFF) { hasSMP = true; }
}

bufwrite16b(buf, 0);
uint8_t nTables = hasSMP ? 4 : 2;
bufwrite16b(buf, nTables);
uint32_t offset = 4 + 8 * nTables;
size_t cp = 0;

caryll_Buffer *format4;
if (!hasSMP || !options->stub_cmap4) {
format4 = otfcc_buildCmap_format4(cmap);
Expand All @@ -403,36 +400,33 @@ caryll_Buffer *otfcc_buildCmap(const table_cmap *cmap, const otfcc_Options *opti
bufwrite16b(format4, 0); // idRangeOffset
bufwrite16b(format4, 0); // idRangeOffset
}
// Windows format 4;
bufwrite16b(buf, 3);
bufwrite16b(buf, 1);
bufwrite32b(buf, offset);
// Unicode format 4:
bufwrite16b(buf, 0);
bufwrite16b(buf, 3);
bufwrite32b(buf, offset);
cp = buf->cursor;
bufseek(buf, offset);
bufwrite_buf(buf, format4);
bufseek(buf, cp);
offset += buflen(format4);
buffree(format4);

caryll_Buffer *format12 = otfcc_buildCmap_format12(cmap);
bk_Block *root = bk_new_Block(b16, 0, // version
b16, nTables, // nTables
bkover);
bk_push(root, b16, 0, // unicode
b16, 3, // BMP
p32, bk_newBlockFromBufferCopy(format4), // table
bkover);
if (hasSMP) {
caryll_Buffer *format12 = otfcc_buildCmap_format12(cmap);
// Windows format 12;
bufwrite16b(buf, 3);
bufwrite16b(buf, 10);
bufwrite32b(buf, offset);
// Unicode format 12:
bufwrite16b(buf, 0);
bufwrite16b(buf, 4);
bufwrite32b(buf, offset);
cp = buf->cursor;
bufseek(buf, offset);
bufwrite_buf(buf, format12);
bufseek(buf, cp);
offset += buflen(format12);
buffree(format12);
bk_push(root, b16, 0, // unicode
b16, 4, // full
p32, bk_newBlockFromBufferCopy(format12), // table
bkover);
}
return buf;
bk_push(root, b16, 3, // Windows
b16, 1, // Unicode BMP
p32, bk_newBlockFromBufferCopy(format4), // table
bkover);
if (hasSMP) {
bk_push(root, b16, 3, // Windows
b16, 10, // Unicode Full
p32, bk_newBlockFromBufferCopy(format12), // table
bkover);
}

buffree(format4);
buffree(format12);
return bk_build_Block(root);
}
19 changes: 19 additions & 0 deletions lib/table/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
#include "support/util.h"
#include "support/unicodeconv/unicodeconv.h"

#ifndef MAIN_VER
#define MAIN_VER 0
#endif
#ifndef SECONDARY_VER
#define SECONDARY_VER 0
#endif
#ifndef PATCH_VER
#define PATCH_VER 0
#endif

#define COPYRIGHT_LEN 32

static void nameRecordDtor(otfcc_NameRecord *entry) {
DELETE(sdsfree, entry->nameString);
}
Expand Down Expand Up @@ -165,6 +177,13 @@ caryll_Buffer *otfcc_buildName(const table_name *name, const otfcc_Options *opti
bufwrite16b(buf, cafter - cbefore);
bufwrite16b(buf, cbefore);
}

// write copyright info
sds copyright = sdscatprintf(sdsempty(), "-- By OTFCC %d.%d.%d --", MAIN_VER, SECONDARY_VER, PATCH_VER);
sdsgrowzero(copyright, COPYRIGHT_LEN);
bufwrite_bytes(strings, COPYRIGHT_LEN, (uint8_t *)copyright);
sdsfree(copyright);

size_t stringsOffset = buf->cursor;
bufwrite_buf(buf, strings);
bufseek(buf, 4);
Expand Down
2 changes: 1 addition & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "dep/premake-modules/ninja"

MAIN_VER = '0'
SECONDARY_VER = '6'
PATCH_VER = '1'
PATCH_VER = '2'

function cbuildoptions()
-- Windows
Expand Down
7 changes: 4 additions & 3 deletions src/otfccbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void printHelp() {
" -O1 Default optimization.\n"
" -O2 More aggressive optimizations for web font. In this\n"
" level, the following options will be set:\n"
" --ignore-glyph-order\n"
" --short-post\n"
" --merge-features\n"
" --short-post\n"
" --subroutinize\n"
" -O3 Most aggressive opptimization strategy will be\n"
" used. In this level, these options will be set:\n"
" --force-cid\n"
" --subroutinize\n"
" --ignore-glyph-order\n"
" --verbose : Show more information when building.\n\n"
" --ignore-hints : Ignore the hinting information in the input.\n"
" --keep-average-char-width : Keep the OS/2.xAvgCharWidth value from the input\n"
Expand Down Expand Up @@ -132,6 +132,7 @@ int main(int argc, char *argv[]) {
otfcc_Options *options = otfcc_newOptions();
options->logger = otfcc_newLogger(otfcc_newStdErrTarget());
options->logger->indent(options->logger, "otfccbuild");
otfcc_Options_optimizeTo(options, 1);

struct option longopts[] = {{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
Expand Down

0 comments on commit c1c217a

Please sign in to comment.