From 345502e4dc94b68ad45e995b1af2564aefb15f49 Mon Sep 17 00:00:00 2001 From: be5invis Date: Mon, 25 Jul 2016 20:40:41 +0800 Subject: [PATCH 01/16] update mac building instructions --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1bb6f73f..c4193995 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ otfccbuild [OPTIONS] [input.json] -o output.[ttf|otf] It was developed and optimized for Clang/LLVM, therefore it is *strongly* recommended to compile with Clang/LLVM, but if that's not possible GCC is also supported, GCC version 5.1 or later being the preferred choice for performance. -### Linux +### Linux (or other Unix-like) On Linux, Either Clang/LLVM or GCC can be used to build `otfcc`. @@ -81,7 +81,7 @@ make ### Windows -On Windows building `otfcc` is tested under the toolchains listed below. The default `premake5 vs2015` will produce a Visual Studio solution using Clang-CL as its compiler. +On Windows, building `otfcc` is tested under the toolchains listed below. The default `premake5 vs2015` will produce a Visual Studio solution using Clang-CL as its compiler. * GCC 5.1 included in `TDM-GCC`. Run the following from the command line: @@ -104,6 +104,8 @@ premake5 provides ability to produce XCode projects. Simply type ```bash premake5 xcode4 +xcodebuild -workspace build/xcode/otfcc.xcworkspace -scheme otfccbuild -configuration Release +xcodebuild -workspace build/xcode/otfcc.xcworkspace -scheme otfccdump -configuration Release ``` -And you can find XCode project files under `build/xcode`. \ No newline at end of file +And you can find built binaries in `bin/`. \ No newline at end of file From b2fec5e9b21057497e0964e12706a4948e6162b6 Mon Sep 17 00:00:00 2001 From: be5invis Date: Mon, 25 Jul 2016 21:33:15 +0800 Subject: [PATCH 02/16] update mac building instructions --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4193995..e5469fea 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ On Windows, building `otfcc` is tested under the toolchains listed below. The de ### Mac OS -premake5 provides ability to produce XCode projects. Simply type +premake5 provides ability to produce XCode projects. ```bash premake5 xcode4 @@ -108,4 +108,6 @@ xcodebuild -workspace build/xcode/otfcc.xcworkspace -scheme otfccbuild -configur xcodebuild -workspace build/xcode/otfcc.xcworkspace -scheme otfccdump -configuration Release ``` -And you can find built binaries in `bin/`. \ No newline at end of file +And you can find built binaries in `bin/`. + +Please ensure that Xcode’s Developer Mode is enabled. \ No newline at end of file From 90cd5a3ccab90cced6af8283d399698ef6b76059 Mon Sep 17 00:00:00 2001 From: be5invis Date: Mon, 25 Jul 2016 21:41:58 +0800 Subject: [PATCH 03/16] update mac building instructions --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e5469fea..c97e9737 100644 --- a/README.md +++ b/README.md @@ -100,14 +100,20 @@ On Windows, building `otfcc` is tested under the toolchains listed below. The de ### Mac OS -premake5 provides ability to produce XCode projects. +premake5 provides ability to produce XCode projects. Run ```bash premake5 xcode4 +``` + +And then you can open `build/xcode/otfcc.xcworkspace` and build with XCode. You can find built binaries in `bin/`. + +Please ensure that Xcode’s Developer Mode is enabled. + +To build binaries in your terminal, run + +```bash xcodebuild -workspace build/xcode/otfcc.xcworkspace -scheme otfccbuild -configuration Release xcodebuild -workspace build/xcode/otfcc.xcworkspace -scheme otfccdump -configuration Release ``` -And you can find built binaries in `bin/`. - -Please ensure that Xcode’s Developer Mode is enabled. \ No newline at end of file From 224535633049b622ed4d2cbfc6313e6bc6103faf Mon Sep 17 00:00:00 2001 From: be5invis Date: Tue, 26 Jul 2016 21:59:55 +0800 Subject: [PATCH 04/16] add installation instructions for windows and Arch --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index c97e9737..d7a7283d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,16 @@ The `otfcc` is a C library and utility used for parsing and writing OpenType fon * Full support for OpenType features (`GSUB`, `GPOS` and `GDEF`), CID-keyed CFF, vertical metrics, and more. * **4× faster than `ttx` on CFF OTF, and 40× on TTF.** +## Prebuilt installations + +### Windows + +Click the “Releases” above, and download the files in it. + +### Arch Linux + +The package `otfcc` can be found [here](https://aur.archlinux.org/packages/otfcc/). + ## Usage ### `otfccdump` : Dump an OpenType font file into JSON From b1785b6f6729dfc278bd983454d4380704586145 Mon Sep 17 00:00:00 2001 From: be5invis Date: Tue, 26 Jul 2016 22:56:01 +0800 Subject: [PATCH 05/16] update build options --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d7a7283d..cb71601c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ otfccdump [OPTIONS] input.[otf|ttf|ttc] ### `otfccbuild` : Build an OpenType font file from JSON ``` -otfccbuild [OPTIONS] [input.json] -o output.[ttf|otf] +Usage : otfccbuild [OPTIONS] [input.json] -o output.[ttf|otf] input.json : Path to input file. When absent the input will be read from the STDIN. @@ -60,13 +60,15 @@ otfccbuild [OPTIONS] [input.json] -o output.[ttf|otf] of using current time. --short-post : Don't export glyph names in the result font. It will reduce file size. - --dummy-DSIG : Include an empty DSIG table in the font. For + --dummy-dsig, -s : Include an empty DSIG table in the font. For some Microsoft applications, a DSIG is required to enable OpenType features. - --ship : Equivalent to the combination of these options: - * --ignore-glyph-order - * --short-post - * --dummy-dsig + -O : Specify the level for optimization. + -O0 Turn off any optimization. + -O1 Default optimization. + -O2 More aggressive optimizations for web font. In + this level, the --ignore-glyph-order and + --short-post will be turned on. ``` ## Building From 4085ded4bd1ae990edc1dff97d74ebb55e4f5646 Mon Sep 17 00:00:00 2001 From: be5invis Date: Tue, 26 Jul 2016 23:54:06 +0800 Subject: [PATCH 06/16] rename options --- lib/font/caryll-font.c | 119 ++++++++++++++++++------------------ lib/font/caryll-font.h | 6 +- lib/fontops/consolidate.c | 2 +- lib/fontops/consolidate.h | 2 +- lib/fontops/stat.c | 10 +-- lib/fontops/stat.h | 2 +- lib/fontops/unconsolidate.c | 10 +-- lib/fontops/unconsolidate.h | 2 +- lib/libcff/charstring_il.c | 6 +- lib/libcff/charstring_il.h | 2 +- lib/support/glyphorder.c | 8 +-- lib/support/glyphorder.h | 2 +- lib/support/options.c | 11 ++++ lib/support/options.h | 26 ++++++++ lib/support/ttinstr.c | 4 +- lib/support/ttinstr.h | 2 +- lib/support/util.h | 16 +---- lib/tables/CFF.c | 20 +++--- lib/tables/CFF.h | 6 +- lib/tables/OS_2.c | 6 +- lib/tables/OS_2.h | 6 +- lib/tables/cmap.c | 6 +- lib/tables/cmap.h | 6 +- lib/tables/cvt.c | 4 +- lib/tables/cvt.h | 4 +- lib/tables/fpgm-prep.c | 6 +- lib/tables/fpgm-prep.h | 4 +- lib/tables/gasp.c | 4 +- lib/tables/gasp.h | 4 +- lib/tables/glyf.c | 34 +++++------ lib/tables/glyf.h | 6 +- lib/tables/head.c | 6 +- lib/tables/head.h | 6 +- lib/tables/hhea.c | 6 +- lib/tables/hhea.h | 6 +- lib/tables/hmtx.c | 2 +- lib/tables/hmtx.h | 2 +- lib/tables/maxp.c | 6 +- lib/tables/maxp.h | 6 +- lib/tables/name.c | 6 +- lib/tables/name.h | 6 +- lib/tables/otl/GDEF.c | 6 +- lib/tables/otl/GDEF.h | 6 +- lib/tables/otl/otl.c | 22 ++++--- lib/tables/otl/otl.h | 6 +- lib/tables/post.c | 8 +-- lib/tables/post.h | 6 +- lib/tables/vhea.c | 6 +- lib/tables/vhea.h | 6 +- lib/tables/vmtx.c | 2 +- lib/tables/vmtx.h | 2 +- src/otfccbuild.c | 43 +++++++------ src/otfccdump.c | 20 +++--- 53 files changed, 280 insertions(+), 251 deletions(-) create mode 100644 lib/support/options.c create mode 100644 lib/support/options.h diff --git a/lib/font/caryll-font.c b/lib/font/caryll-font.c index 78daebc9..4a5513cd 100644 --- a/lib/font/caryll-font.c +++ b/lib/font/caryll-font.c @@ -105,64 +105,64 @@ caryll_font *caryll_read_font(caryll_sfnt *sfnt, uint32_t index) { } } -json_value *caryll_font_to_json(caryll_font *font, caryll_dump_options *dumpopts) { +json_value *caryll_font_to_json(caryll_font *font, caryll_options *options) { json_value *root = json_object_new(48); - dumpopts->has_vertical_metrics = !!(font->vhea) && !!(font->vmtx); - dumpopts->export_fdselect = font->CFF_ && font->CFF_->isCID; + options->has_vertical_metrics = !!(font->vhea) && !!(font->vmtx); + options->export_fdselect = font->CFF_ && font->CFF_->isCID; if (!root) return NULL; - caryll_head_to_json(font->head, root, dumpopts); - caryll_hhea_to_json(font->hhea, root, dumpopts); - caryll_maxp_to_json(font->maxp, root, dumpopts); - caryll_vhea_to_json(font->vhea, root, dumpopts); - caryll_post_to_json(font->post, root, dumpopts); - caryll_OS_2_to_json(font->OS_2, root, dumpopts); - caryll_name_to_json(font->name, root, dumpopts); - caryll_cmap_to_json(font->cmap, root, dumpopts); - caryll_CFF_to_json(font->CFF_, root, dumpopts); - caryll_glyf_to_json(font->glyf, root, dumpopts); - if (!dumpopts->ignore_hints) { - caryll_fpgm_prep_to_json(font->fpgm, root, dumpopts, "fpgm"); - caryll_fpgm_prep_to_json(font->prep, root, dumpopts, "prep"); - caryll_cvt_to_json(font->cvt_, root, dumpopts, "cvt_"); - caryll_gasp_to_json(font->gasp, root, dumpopts); + caryll_head_to_json(font->head, root, options); + caryll_hhea_to_json(font->hhea, root, options); + caryll_maxp_to_json(font->maxp, root, options); + caryll_vhea_to_json(font->vhea, root, options); + caryll_post_to_json(font->post, root, options); + caryll_OS_2_to_json(font->OS_2, root, options); + caryll_name_to_json(font->name, root, options); + caryll_cmap_to_json(font->cmap, root, options); + caryll_CFF_to_json(font->CFF_, root, options); + caryll_glyf_to_json(font->glyf, root, options); + if (!options->ignore_hints) { + caryll_fpgm_prep_to_json(font->fpgm, root, options, "fpgm"); + caryll_fpgm_prep_to_json(font->prep, root, options, "prep"); + caryll_cvt_to_json(font->cvt_, root, options, "cvt_"); + caryll_gasp_to_json(font->gasp, root, options); } - caryll_otl_to_json(font->GSUB, root, dumpopts, "GSUB"); - caryll_otl_to_json(font->GPOS, root, dumpopts, "GPOS"); + caryll_otl_to_json(font->GSUB, root, options, "GSUB"); + caryll_otl_to_json(font->GPOS, root, options, "GPOS"); - caryll_GDEF_to_json(font->GDEF, root, dumpopts); + caryll_GDEF_to_json(font->GDEF, root, options); return root; } -caryll_font *caryll_font_from_json(json_value *root, caryll_dump_options *dumpopts) { +caryll_font *caryll_font_from_json(json_value *root, caryll_options *options) { caryll_font *font = caryll_new_font(); if (!font) return NULL; font->subtype = json_obj_get_type(root, "CFF_", json_object) != NULL; - font->glyph_order = caryll_glyphorder_from_json(root, dumpopts); - font->head = caryll_head_from_json(root, dumpopts); - font->hhea = caryll_hhea_from_json(root, dumpopts); - font->OS_2 = caryll_OS_2_from_json(root, dumpopts); - font->maxp = caryll_maxp_from_json(root, dumpopts); - font->post = caryll_post_from_json(root, dumpopts); - font->name = caryll_name_from_json(root, dumpopts); - font->cmap = caryll_cmap_from_json(root, dumpopts); - font->CFF_ = caryll_CFF_from_json(root, dumpopts); - font->glyf = caryll_glyf_from_json(root, *font->glyph_order, dumpopts); - if (!dumpopts->ignore_hints) { + font->glyph_order = caryll_glyphorder_from_json(root, options); + font->head = caryll_head_from_json(root, options); + font->hhea = caryll_hhea_from_json(root, options); + font->OS_2 = caryll_OS_2_from_json(root, options); + font->maxp = caryll_maxp_from_json(root, options); + font->post = caryll_post_from_json(root, options); + font->name = caryll_name_from_json(root, options); + font->cmap = caryll_cmap_from_json(root, options); + font->CFF_ = caryll_CFF_from_json(root, options); + font->glyf = caryll_glyf_from_json(root, *font->glyph_order, options); + if (!options->ignore_hints) { font->fpgm = caryll_fpgm_prep_from_json(root, "fpgm"); font->prep = caryll_fpgm_prep_from_json(root, "prep"); font->cvt_ = caryll_cvt_from_json(root, "cvt_"); font->gasp = caryll_gasp_from_json(root); } - font->vhea = caryll_vhea_from_json(root, dumpopts); + font->vhea = caryll_vhea_from_json(root, options); if (font->glyf) { - font->GSUB = caryll_otl_from_json(root, dumpopts, "GSUB"); - font->GPOS = caryll_otl_from_json(root, dumpopts, "GPOS"); - font->GDEF = caryll_GDEF_from_json(root, dumpopts); + font->GSUB = caryll_otl_from_json(root, options, "GSUB"); + font->GPOS = caryll_otl_from_json(root, options, "GPOS"); + font->GDEF = caryll_GDEF_from_json(root, options); } return font; } -caryll_buffer *caryll_write_font(caryll_font *font, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_font(caryll_font *font, caryll_options *options) { sfnt_builder *builder = new_sfnt_builder(font->subtype == FONTTYPE_CFF ? 'OTTO' : 0x00010000); // Outline data @@ -170,54 +170,51 @@ caryll_buffer *caryll_write_font(caryll_font *font, caryll_dump_options *dumpopt caryll_buffer *bufglyf = bufnew(); caryll_buffer *bufloca = bufnew(); if (font->glyf && font->head) { - caryll_write_glyf(font->glyf, font->head, bufglyf, bufloca, dumpopts); + caryll_write_glyf(font->glyf, font->head, bufglyf, bufloca, options); } sfnt_builder_push_table(builder, 'loca', bufloca); sfnt_builder_push_table(builder, 'glyf', bufglyf); } else { caryll_cff_parse_result r = {font->CFF_, font->glyf}; - sfnt_builder_push_table(builder, 'CFF ', caryll_write_CFF(r, dumpopts)); + sfnt_builder_push_table(builder, 'CFF ', caryll_write_CFF(r, options)); } - sfnt_builder_push_table(builder, 'head', caryll_write_head(font->head, dumpopts)); - sfnt_builder_push_table(builder, 'hhea', caryll_write_hhea(font->hhea, dumpopts)); - sfnt_builder_push_table(builder, 'OS/2', caryll_write_OS_2(font->OS_2, dumpopts)); - sfnt_builder_push_table(builder, 'maxp', caryll_write_maxp(font->maxp, dumpopts)); - sfnt_builder_push_table(builder, 'name', caryll_write_name(font->name, dumpopts)); + sfnt_builder_push_table(builder, 'head', caryll_write_head(font->head, options)); + sfnt_builder_push_table(builder, 'hhea', caryll_write_hhea(font->hhea, options)); + sfnt_builder_push_table(builder, 'OS/2', caryll_write_OS_2(font->OS_2, options)); + sfnt_builder_push_table(builder, 'maxp', caryll_write_maxp(font->maxp, options)); + sfnt_builder_push_table(builder, 'name', caryll_write_name(font->name, options)); sfnt_builder_push_table(builder, 'post', - caryll_write_post(font->post, font->glyph_order, dumpopts)); - sfnt_builder_push_table(builder, 'cmap', caryll_write_cmap(font->cmap, dumpopts)); + caryll_write_post(font->post, font->glyph_order, options)); + sfnt_builder_push_table(builder, 'cmap', caryll_write_cmap(font->cmap, options)); if (font->fpgm) - sfnt_builder_push_table(builder, 'fpgm', caryll_write_fpgm_prep(font->fpgm, dumpopts)); + sfnt_builder_push_table(builder, 'fpgm', caryll_write_fpgm_prep(font->fpgm, options)); if (font->prep) - sfnt_builder_push_table(builder, 'prep', caryll_write_fpgm_prep(font->prep, dumpopts)); - if (font->cvt_) - sfnt_builder_push_table(builder, 'cvt ', caryll_write_cvt(font->cvt_, dumpopts)); + sfnt_builder_push_table(builder, 'prep', caryll_write_fpgm_prep(font->prep, options)); + if (font->cvt_) sfnt_builder_push_table(builder, 'cvt ', caryll_write_cvt(font->cvt_, options)); if (font->gasp) - sfnt_builder_push_table(builder, 'gasp', caryll_write_gasp(font->gasp, dumpopts)); + sfnt_builder_push_table(builder, 'gasp', caryll_write_gasp(font->gasp, options)); sfnt_builder_push_table(builder, 'hmtx', caryll_write_hmtx(font->hmtx, font->hhea->numberOfMetrics, font->maxp->numGlyphs - font->hhea->numberOfMetrics, - dumpopts)); + options)); if (font->vhea) - sfnt_builder_push_table(builder, 'vhea', caryll_write_vhea(font->vhea, dumpopts)); + sfnt_builder_push_table(builder, 'vhea', caryll_write_vhea(font->vhea, options)); if (font->vmtx) { sfnt_builder_push_table( builder, 'vmtx', caryll_write_vmtx(font->vmtx, font->vhea->numOfLongVerMetrics, - font->maxp->numGlyphs - font->vhea->numOfLongVerMetrics, dumpopts)); + font->maxp->numGlyphs - font->vhea->numOfLongVerMetrics, options)); } - if (font->GSUB) - sfnt_builder_push_table(builder, 'GSUB', caryll_write_otl(font->GSUB, dumpopts)); - if (font->GPOS) - sfnt_builder_push_table(builder, 'GPOS', caryll_write_otl(font->GPOS, dumpopts)); + if (font->GSUB) sfnt_builder_push_table(builder, 'GSUB', caryll_write_otl(font->GSUB, options)); + if (font->GPOS) sfnt_builder_push_table(builder, 'GPOS', caryll_write_otl(font->GPOS, options)); if (font->GDEF) - sfnt_builder_push_table(builder, 'GDEF', caryll_write_GDEF(font->GDEF, dumpopts)); + sfnt_builder_push_table(builder, 'GDEF', caryll_write_GDEF(font->GDEF, options)); - if (dumpopts->dummy_DSIG) { + if (options->dummy_DSIG) { caryll_buffer *dsig = bufnew(); bufwrite32b(dsig, 0x00000001); bufwrite16b(dsig, 0); diff --git a/lib/font/caryll-font.h b/lib/font/caryll-font.h index 8e4ada38..b40868a9 100644 --- a/lib/font/caryll-font.h +++ b/lib/font/caryll-font.h @@ -71,8 +71,8 @@ caryll_font_subtype caryll_decide_font_subtype(caryll_sfnt *sfnt, uint32_t index caryll_font *caryll_new_font(); caryll_font *caryll_read_font(caryll_sfnt *sfnt, uint32_t index); void caryll_delete_font(caryll_font *font); -json_value *caryll_font_to_json(caryll_font *font, caryll_dump_options *dumpopts); -caryll_font *caryll_font_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_font(caryll_font *font, caryll_dump_options *dumpopts); +json_value *caryll_font_to_json(caryll_font *font, caryll_options *options); +caryll_font *caryll_font_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_font(caryll_font *font, caryll_options *options); #endif diff --git a/lib/fontops/consolidate.c b/lib/fontops/consolidate.c index f40bf123..840383eb 100644 --- a/lib/fontops/consolidate.c +++ b/lib/fontops/consolidate.c @@ -200,7 +200,7 @@ void caryll_font_consolidate_otl(caryll_font *font) { consolidate_GDEF(font, font->GDEF, "GDEF"); } -void caryll_font_consolidate(caryll_font *font, caryll_dump_options *dumpopts) { +void caryll_font_consolidate(caryll_font *font, caryll_options *options) { caryll_font_consolidate_glyf(font); caryll_font_consolidate_cmap(font); if (font->glyf) caryll_font_consolidate_otl(font); diff --git a/lib/fontops/consolidate.h b/lib/fontops/consolidate.h index ebf43eba..dc43b7a6 100644 --- a/lib/fontops/consolidate.h +++ b/lib/fontops/consolidate.h @@ -13,6 +13,6 @@ #include "otl/mark.h" #include "otl/GDEF.h" -void caryll_font_consolidate(caryll_font *font, caryll_dump_options *dumpopts); +void caryll_font_consolidate(caryll_font *font, caryll_options *options); #endif diff --git a/lib/fontops/stat.c b/lib/fontops/stat.c index 76d15903..86ece84d 100644 --- a/lib/fontops/stat.c +++ b/lib/fontops/stat.c @@ -235,7 +235,7 @@ void caryll_font_stat_vmtx(caryll_font *font) { font->vhea->advanceHeightMax = maxHeight; font->vmtx = vmtx; } -void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { +void caryll_font_stat_OS_2(caryll_font *font, caryll_options *options) { cmap_entry *item; // Stat for OS/2.ulUnicodeRange. uint32_t u1 = 0; @@ -427,7 +427,7 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { font->OS_2->usLastCharIndex = 0xFFFF; } - if (!dumpopts->keep_average_char_width) { + if (!options->keep_average_char_width) { uint32_t totalWidth = 0; for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { totalWidth += font->glyf->glyphs[j]->advanceWidth; @@ -472,10 +472,10 @@ static void caryll_stat_cff_widths(caryll_font *font) { } } -void caryll_font_stat(caryll_font *font, caryll_dump_options *dumpopts) { +void caryll_font_stat(caryll_font *font, caryll_options *options) { if (font->glyf && font->head) { caryll_stat_glyf(font); - if (!dumpopts->keep_modified_time) { + if (!options->keep_modified_time) { font->head->modified = 2082844800 + (int64_t)time(NULL); } } @@ -496,7 +496,7 @@ void caryll_font_stat(caryll_font *font, caryll_dump_options *dumpopts) { if (font->prep && font->maxp && font->prep->length > font->maxp->maxSizeOfInstructions) { font->maxp->maxSizeOfInstructions = font->prep->length; } - if (font->OS_2 && font->cmap && font->glyf) caryll_font_stat_OS_2(font, dumpopts); + if (font->OS_2 && font->cmap && font->glyf) caryll_font_stat_OS_2(font, options); if (font->subtype == FONTTYPE_TTF) { if (font->maxp) font->maxp->version = 0x00010000; } else { diff --git a/lib/fontops/stat.h b/lib/fontops/stat.h index 3457f52c..1c1af8da 100644 --- a/lib/fontops/stat.h +++ b/lib/fontops/stat.h @@ -2,6 +2,6 @@ #define CARYLL_FONTOPS_STAT_H #include -void caryll_font_stat(caryll_font *font, caryll_dump_options *dumpopts); +void caryll_font_stat(caryll_font *font, caryll_options *options); #endif diff --git a/lib/fontops/unconsolidate.c b/lib/fontops/unconsolidate.c index b47c716f..e0b7f3fc 100644 --- a/lib/fontops/unconsolidate.c +++ b/lib/fontops/unconsolidate.c @@ -6,7 +6,7 @@ // 2. Replace all glyph IDs into glyph names. Note all glyph references with // same name whare one unique string entity stored in font->glyph_order. // (Separate?) -static void caryll_name_glyphs(caryll_font *font, caryll_dump_options *dumpopts) { +static void caryll_name_glyphs(caryll_font *font, caryll_options *options) { if (!font->glyf) return; glyph_order_hash *glyph_order = malloc(sizeof(glyph_order_hash)); *glyph_order = NULL; @@ -59,11 +59,11 @@ static void caryll_name_glyphs(caryll_font *font, caryll_dump_options *dumpopts) if (!actuallyNamed) sdsfree(name); } - if (dumpopts->glyph_name_prefix) { + if (options->glyph_name_prefix) { glyph_order_entry *item; foreach_hash(item, *glyph_order) { sds oldname = item->name; - item->name = sdscatprintf(sdsempty(), "%s%s", dumpopts->glyph_name_prefix, oldname); + item->name = sdscatprintf(sdsempty(), "%s%s", options->glyph_name_prefix, oldname); sdsfree(oldname); } } @@ -284,13 +284,13 @@ static void merge_vmtx(caryll_font *font) { } } } -void caryll_font_unconsolidate(caryll_font *font, caryll_dump_options *dumpopts) { +void caryll_font_unconsolidate(caryll_font *font, caryll_options *options) { // Merge metrics merge_hmtx(font); merge_vmtx(font); // Name glyphs - caryll_name_glyphs(font, dumpopts); + caryll_name_glyphs(font, options); caryll_name_cmap_entries(font); caryll_name_glyf(font); caryll_name_features(font); diff --git a/lib/fontops/unconsolidate.h b/lib/fontops/unconsolidate.h index 2e4152b5..d4a63a25 100644 --- a/lib/fontops/unconsolidate.h +++ b/lib/fontops/unconsolidate.h @@ -2,6 +2,6 @@ #define CARYLL_FONTOPS_UNCONSOLIDATE_H #include -void caryll_font_unconsolidate(caryll_font *font, caryll_dump_options *dumpopts); +void caryll_font_unconsolidate(caryll_font *font, caryll_options *options); #endif diff --git a/lib/libcff/charstring_il.c b/lib/libcff/charstring_il.c index 174e0bcb..bdcb8e02 100644 --- a/lib/libcff/charstring_il.c +++ b/lib/libcff/charstring_il.c @@ -381,10 +381,10 @@ static uint8_t decideAdvance(charstring_il *il, uint32_t j, uint8_t optimizeLeve return 1; // nothing match } -void glyph_il_peephole_optimization(charstring_il *il, caryll_dump_options *dumpopts) { - if (!dumpopts->optimize_level) return; +void glyph_il_peephole_optimization(charstring_il *il, caryll_options *options) { + if (!options->optimize_level) return; uint32_t j = 0; - while (j < il->length) { j += decideAdvance(il, j, dumpopts->optimize_level); } + while (j < il->length) { j += decideAdvance(il, j, options->optimize_level); } } // IL to buffer conversion diff --git a/lib/libcff/charstring_il.h b/lib/libcff/charstring_il.h index 9a81de0a..b12f296b 100644 --- a/lib/libcff/charstring_il.h +++ b/lib/libcff/charstring_il.h @@ -27,7 +27,7 @@ typedef struct { // basic ops charstring_il *compile_glyph_to_il(glyf_glyph *g, uint16_t defaultWidth, uint16_t nominalWidth); -void glyph_il_peephole_optimization(charstring_il *il, caryll_dump_options *dumpopts); +void glyph_il_peephole_optimization(charstring_il *il, caryll_options *options); caryll_buffer *il2blob(charstring_il *il); #endif diff --git a/lib/support/glyphorder.c b/lib/support/glyphorder.c index 8c7b4b8b..bd5e8e1c 100644 --- a/lib/support/glyphorder.c +++ b/lib/support/glyphorder.c @@ -38,9 +38,9 @@ static int dump_order_dotnotdef = 2; static int dump_order_type_cmap = 3; static int dump_order_type_glyf = 4; static void caryll_glyphorder_from_json_order_subtable(glyph_order_hash *hash, json_value *table, - caryll_dump_options *dumpopts) { + caryll_options *options) { uint32_t uplimit = table->u.array.length; - if (uplimit >= 1 && dumpopts->ignore_glyph_order) { uplimit = 1; } + if (uplimit >= 1 && options->ignore_glyph_order) { uplimit = 1; } for (uint32_t j = 0; j < uplimit; j++) { json_value *item = table->u.array.values[j]; if (item->type == json_string) { @@ -118,14 +118,14 @@ static int compare_glyphorder_entry_b(glyph_order_entry *a, glyph_order_entry *b return 0; } -glyph_order_hash *caryll_glyphorder_from_json(json_value *root, caryll_dump_options *dumpopts) { +glyph_order_hash *caryll_glyphorder_from_json(json_value *root, caryll_options *options) { if (root->type != json_object) return NULL; glyph_order_hash hash = NULL; json_value *table; if ((table = json_obj_get_type(root, "glyf", json_object))) { caryll_glyphorder_from_json_order_glyf(&hash, table); if ((table = json_obj_get_type(root, "glyph_order", json_array))) { - caryll_glyphorder_from_json_order_subtable(&hash, table, dumpopts); + caryll_glyphorder_from_json_order_subtable(&hash, table, options); } if ((table = json_obj_get_type(root, "cmap", json_object))) { caryll_glyphorder_from_json_order_cmap(&hash, table); diff --git a/lib/support/glyphorder.h b/lib/support/glyphorder.h index a81d4c92..30437ba3 100644 --- a/lib/support/glyphorder.h +++ b/lib/support/glyphorder.h @@ -16,6 +16,6 @@ int try_name_glyph(glyph_order_hash *glyph_order, int _id, sds name); void lookup_name(glyph_order_hash *glyph_order, int _gid, sds *field); void delete_glyph_order_map(glyph_order_hash *map); -glyph_order_hash *caryll_glyphorder_from_json(json_value *root, caryll_dump_options *dumpopts); +glyph_order_hash *caryll_glyphorder_from_json(json_value *root, caryll_options *options); #endif diff --git a/lib/support/options.c b/lib/support/options.c new file mode 100644 index 00000000..40b69845 --- /dev/null +++ b/lib/support/options.c @@ -0,0 +1,11 @@ +#include "options.h" + +caryll_options *caryll_new_options() { + caryll_options *options = calloc(1, sizeof(caryll_options)); + options->optimize_level = 1; + return options; +} +void caryll_delete_options(caryll_options *options) { + if (options) { free(options->glyph_name_prefix); } + free(options); +} diff --git a/lib/support/options.h b/lib/support/options.h new file mode 100644 index 00000000..9c09275c --- /dev/null +++ b/lib/support/options.h @@ -0,0 +1,26 @@ +#ifndef CARYLL_SUPPORT_OPTIONS_H +#define CARYLL_SUPPORT_OPTIONS_H + +#include +#include +#include + +typedef struct { + bool ignore_glyph_order; + bool ignore_hints; + bool has_vertical_metrics; + bool export_fdselect; + bool keep_average_char_width; + bool short_post; + bool dummy_DSIG; + bool keep_modified_time; + bool instr_as_bytes; + bool verbose; + char *glyph_name_prefix; + uint8_t optimize_level; +} caryll_options; + +caryll_options *caryll_new_options(); +void caryll_delete_options(caryll_options *options); + +#endif diff --git a/lib/support/ttinstr.c b/lib/support/ttinstr.c index 842ab7e0..aa51bdd1 100644 --- a/lib/support/ttinstr.c +++ b/lib/support/ttinstr.c @@ -478,8 +478,8 @@ static int instr_typify(struct instrdata *id) { return (lh); } -json_value *instr_to_json(uint8_t *instructions, uint32_t length, caryll_dump_options *dumpopts) { - if (dumpopts->instr_as_bytes) { +json_value *instr_to_json(uint8_t *instructions, uint32_t length, caryll_options *options) { + if (options->instr_as_bytes) { size_t len = 0; uint8_t *buf = base64_encode(instructions, length, &len); return json_string_new_nocopy((uint32_t)len, (char *)buf); diff --git a/lib/support/ttinstr.h b/lib/support/ttinstr.h index 8bc8fed0..a16db063 100644 --- a/lib/support/ttinstr.h +++ b/lib/support/ttinstr.h @@ -170,5 +170,5 @@ void instr_from_json( json_value *col, void *context, void (*Make)(void *, uint8_t *, uint32_t), void (*Wrong)(void *, char *, int)); -json_value *instr_to_json(uint8_t *instructions, uint32_t length, caryll_dump_options *dumpopts); +json_value *instr_to_json(uint8_t *instructions, uint32_t length, caryll_options *options); #endif diff --git a/lib/support/util.h b/lib/support/util.h index 74761345..bce285b8 100644 --- a/lib/support/util.h +++ b/lib/support/util.h @@ -7,6 +7,7 @@ #include "base64.h" #include "buffer.h" +#include "options.h" #include #include #include @@ -295,21 +296,6 @@ typedef struct { sds name; } glyph_handle; -// dump options -typedef struct { - bool ignore_glyph_order; - bool ignore_hints; - bool has_vertical_metrics; - bool export_fdselect; - bool keep_average_char_width; - bool short_post; - bool dummy_DSIG; - bool keep_modified_time; - bool instr_as_bytes; - char *glyph_name_prefix; - uint8_t optimize_level; -} caryll_dump_options; - #define MOVE /*move*/ static INLINE json_value *preserialize(MOVE json_value *x) { diff --git a/lib/tables/CFF.c b/lib/tables/CFF.c index f7ec89ec..3278c75c 100644 --- a/lib/tables/CFF.c +++ b/lib/tables/CFF.c @@ -706,7 +706,7 @@ static json_value *fdToJson(table_CFF *table) { return _CFF_; } -void caryll_CFF_to_json(table_CFF *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_CFF_to_json(table_CFF *table, json_value *root, caryll_options *options) { if (!table) return; json_object_push(root, "CFF_", fdToJson(table)); } @@ -804,7 +804,7 @@ static table_CFF *fdFromJson(json_value *dump) { if (!table->privateDict) table->privateDict = caryll_new_CFF_private(); return table; } -table_CFF *caryll_CFF_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_CFF *caryll_CFF_from_json(json_value *root, caryll_options *options) { json_value *dump = json_obj_get_type(root, "CFF_", json_object); if (!dump) return NULL; @@ -813,9 +813,9 @@ table_CFF *caryll_CFF_from_json(json_value *root, caryll_dump_options *dumpopts) } static caryll_buffer *compile_glyph(glyf_glyph *g, uint16_t defaultWidth, uint16_t nominalWidthX, - caryll_dump_options *dumpopts) { + caryll_options *options) { charstring_il *il = compile_glyph_to_il(g, defaultWidth, nominalWidthX); - glyph_il_peephole_optimization(il, dumpopts); + glyph_il_peephole_optimization(il, options); caryll_buffer *blob = il2blob(il); free(il->instr); free(il); @@ -826,12 +826,12 @@ typedef struct { table_glyf *glyf; uint16_t defaultWidth; uint16_t nominalWidthX; - caryll_dump_options *dumpopts; + caryll_options *options; } cff_charstring_builder_context; static caryll_buffer *callback_makeglyph(void *_context, uint32_t j) { cff_charstring_builder_context *context = (cff_charstring_builder_context *)_context; return compile_glyph(context->glyf->glyphs[j], context->defaultWidth, context->nominalWidthX, - context->dumpopts); + context->options); } static caryll_buffer *cff_make_charstrings(cff_charstring_builder_context *context) { if (context->glyf->numberGlyphs == 0) return bufnew(); @@ -1140,7 +1140,7 @@ static CFF_Index *cff_make_fdarray(uint16_t fdArrayCount, table_CFF **fdArray, } static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, - caryll_dump_options *dumpopts) { + caryll_options *options) { caryll_buffer *blob = bufnew(); // The Strings hashtable cff_sid_entry *stringHash = NULL; @@ -1184,7 +1184,7 @@ static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, g2cContext.glyf = glyf; g2cContext.defaultWidth = cff->privateDict->defaultWidthX; g2cContext.nominalWidthX = cff->privateDict->nominalWidthX; - g2cContext.dumpopts = dumpopts; + g2cContext.options = options; s = cff_make_charstrings(&g2cContext); } @@ -1282,6 +1282,6 @@ static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, return blob; } -caryll_buffer *caryll_write_CFF(caryll_cff_parse_result cffAndGlyf, caryll_dump_options *dumpopts) { - return writeCFF_CIDKeyed(cffAndGlyf.meta, cffAndGlyf.glyphs, dumpopts); +caryll_buffer *caryll_write_CFF(caryll_cff_parse_result cffAndGlyf, caryll_options *options) { + return writeCFF_CIDKeyed(cffAndGlyf.meta, cffAndGlyf.glyphs, options); } diff --git a/lib/tables/CFF.h b/lib/tables/CFF.h index 64e22395..83a13aff 100644 --- a/lib/tables/CFF.h +++ b/lib/tables/CFF.h @@ -93,8 +93,8 @@ typedef struct { table_CFF *caryll_new_CFF(); void caryll_delete_CFF(table_CFF *table); caryll_cff_parse_result caryll_read_CFF_and_glyf(caryll_packet packet); -void caryll_CFF_to_json(table_CFF *table, json_value *root, caryll_dump_options *dumpopts); -table_CFF *caryll_CFF_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_CFF(caryll_cff_parse_result cffAndGlyf, caryll_dump_options *dumpopts); +void caryll_CFF_to_json(table_CFF *table, json_value *root, caryll_options *options); +table_CFF *caryll_CFF_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_CFF(caryll_cff_parse_result cffAndGlyf, caryll_options *options); #endif diff --git a/lib/tables/OS_2.c b/lib/tables/OS_2.c index 1e1d5d2b..7a17543a 100644 --- a/lib/tables/OS_2.c +++ b/lib/tables/OS_2.c @@ -98,7 +98,7 @@ const char *codePageLabels2[] = {"oem8", "oem9", "oem10", "oem11", "oem12", "o "cp862", "cp861", "cp860", "cp857", "cp855", "cp852", "cp775", "cp737", "cp708", "cp850", "ascii", NULL}; -void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_options *options) { if (!table) return; json_value *os_2 = json_object_new(30); json_object_push(os_2, "version", json_integer_new(table->version)); @@ -157,7 +157,7 @@ void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_option json_object_push(root, "OS_2", os_2); } -table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_options *options) { table_OS_2 *os_2 = caryll_new_OS_2(); if (!os_2) return NULL; json_value *table = NULL; @@ -229,7 +229,7 @@ table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_dump_options *dumpopt return os_2; } -caryll_buffer *caryll_write_OS_2(table_OS_2 *os_2, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_OS_2(table_OS_2 *os_2, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!os_2) return buf; bufwrite16b(buf, os_2->version); diff --git a/lib/tables/OS_2.h b/lib/tables/OS_2.h index 0eb46da9..d8c08cde 100644 --- a/lib/tables/OS_2.h +++ b/lib/tables/OS_2.h @@ -49,8 +49,8 @@ typedef struct { table_OS_2 *caryll_new_OS_2(); table_OS_2 *caryll_read_OS_2(caryll_packet packet); -void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_options *dumpopts); -table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_OS_2(table_OS_2 *os_2, caryll_dump_options *dumpopts); +void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_options *options); +table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_OS_2(table_OS_2 *os_2, caryll_options *options); #endif diff --git a/lib/tables/cmap.c b/lib/tables/cmap.c index 23846dc8..d556feef 100644 --- a/lib/tables/cmap.c +++ b/lib/tables/cmap.c @@ -107,7 +107,7 @@ void caryll_delete_cmap(cmap_hash *table) { free(table); } -void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_options *options) { if (!table) return; json_value *cmap = json_object_new(HASH_COUNT(*table)); @@ -121,7 +121,7 @@ void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_dump_options json_object_push(root, "cmap", cmap); } -cmap_hash *caryll_cmap_from_json(json_value *root, caryll_dump_options *dumpopts) { +cmap_hash *caryll_cmap_from_json(json_value *root, caryll_options *options) { if (root->type != json_object) return NULL; cmap_hash hash = NULL; json_value *table = NULL; @@ -307,7 +307,7 @@ caryll_buffer *caryll_write_cmap_format12(cmap_hash *cmap) { bufwrite32b(buf, nGroups); return buf; } -caryll_buffer *caryll_write_cmap(cmap_hash *cmap, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_cmap(cmap_hash *cmap, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!cmap || !*cmap) return buf; diff --git a/lib/tables/cmap.h b/lib/tables/cmap.h index 24074983..9989a2f4 100644 --- a/lib/tables/cmap.h +++ b/lib/tables/cmap.h @@ -14,7 +14,7 @@ typedef cmap_entry *cmap_hash; cmap_hash *caryll_read_cmap(caryll_packet packet); void caryll_delete_cmap(cmap_hash *table); -void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_dump_options *dumpopts); -cmap_hash *caryll_cmap_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_cmap(cmap_hash *cmap, caryll_dump_options *dumpopts); +void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_options *options); +cmap_hash *caryll_cmap_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_cmap(cmap_hash *cmap, caryll_options *options); #endif diff --git a/lib/tables/cvt.c b/lib/tables/cvt.c index d6826d7d..4c596e6f 100644 --- a/lib/tables/cvt.c +++ b/lib/tables/cvt.c @@ -18,7 +18,7 @@ void caryll_delete_cvt(table_cvt *table) { if (table->words) free(table->words); free(table); } -void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_dump_options *dumpopts, +void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_options *options, const char *tag) { if (!table) return; json_value *arr = json_array_new(table->length); @@ -58,7 +58,7 @@ table_cvt *caryll_cvt_from_json(json_value *root, const char *tag) { return t; } -caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!table) return buf; for (uint16_t j = 0; j < table->length; j++) { bufwrite16b(buf, table->words[j]); } diff --git a/lib/tables/cvt.h b/lib/tables/cvt.h index e05633b4..08299cbb 100644 --- a/lib/tables/cvt.h +++ b/lib/tables/cvt.h @@ -11,9 +11,9 @@ typedef struct { } table_cvt; table_cvt *caryll_read_cvt(caryll_packet packet, uint32_t tag); void caryll_delete_cvt(table_cvt *table); -void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_dump_options *dumpopts, +void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_options *options, const char *tag); table_cvt *caryll_cvt_from_json(json_value *root, const char *tag); -caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_dump_options *dumpopts); +caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_options *options); #endif diff --git a/lib/tables/fpgm-prep.c b/lib/tables/fpgm-prep.c index fd8962dd..77b337ea 100644 --- a/lib/tables/fpgm-prep.c +++ b/lib/tables/fpgm-prep.c @@ -27,9 +27,9 @@ void caryll_delete_fpgm_prep(table_fpgm_prep *table) { } void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, - caryll_dump_options *dumpopts, const char *tag) { + caryll_options *options, const char *tag) { if (!table) return; - json_object_push(root, tag, instr_to_json(table->bytes, table->length, dumpopts)); + json_object_push(root, tag, instr_to_json(table->bytes, table->length, options)); } void makeFpgmPrepInstr(void *_t, uint8_t *instrs, uint32_t length) { @@ -54,7 +54,7 @@ table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, const char *tag) { return t; } -caryll_buffer *caryll_write_fpgm_prep(table_fpgm_prep *table, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_fpgm_prep(table_fpgm_prep *table, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!table) return buf; bufwrite_bytes(buf, table->length, table->bytes); diff --git a/lib/tables/fpgm-prep.h b/lib/tables/fpgm-prep.h index cc0ff421..61cea48a 100644 --- a/lib/tables/fpgm-prep.h +++ b/lib/tables/fpgm-prep.h @@ -14,8 +14,8 @@ typedef struct { table_fpgm_prep *caryll_read_fpgm_prep(caryll_packet packet, uint32_t tag); void caryll_delete_fpgm_prep(table_fpgm_prep *table); void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, - caryll_dump_options *dumpopts, const char *tag); + caryll_options *options, const char *tag); table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, const char *tag); -caryll_buffer *caryll_write_fpgm_prep(table_fpgm_prep *table, caryll_dump_options *dumpopts); +caryll_buffer *caryll_write_fpgm_prep(table_fpgm_prep *table, caryll_options *options); #endif diff --git a/lib/tables/gasp.c b/lib/tables/gasp.c index 4f7fb4ac..4e77a98d 100644 --- a/lib/tables/gasp.c +++ b/lib/tables/gasp.c @@ -49,7 +49,7 @@ table_gasp *caryll_read_gasp(caryll_packet packet) { } return NULL; } -void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_options *options) { if (!table) return; json_value *t = json_array_new(table->numRanges); for (uint16_t j = 0; j < table->numRanges; j++) { @@ -91,7 +91,7 @@ table_gasp *caryll_gasp_from_json(json_value *root) { return NULL; } -caryll_buffer *caryll_write_gasp(table_gasp *gasp, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_gasp(table_gasp *gasp, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!gasp || !gasp->records) return buf; bufwrite16b(buf, 1); diff --git a/lib/tables/gasp.h b/lib/tables/gasp.h index 69706cb3..ffe66342 100644 --- a/lib/tables/gasp.h +++ b/lib/tables/gasp.h @@ -20,7 +20,7 @@ typedef struct { table_gasp *caryll_new_gasp(); void caryll_delete_gasp(table_gasp *table); table_gasp *caryll_read_gasp(caryll_packet packet); -void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_dump_options *dumpopts); +void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_options *options); table_gasp *caryll_gasp_from_json(json_value *root); -caryll_buffer *caryll_write_gasp(table_gasp *table, caryll_dump_options *dumpopts); +caryll_buffer *caryll_write_gasp(table_gasp *table, caryll_options *options); #endif diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index d16e5ca1..be00e022 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -442,36 +442,36 @@ static json_value *glyf_glyph_maskdefs_to_json(glyf_postscript_hint_mask *masks, return a; } -static json_value *glyf_glyph_to_json(glyf_glyph *g, caryll_dump_options *dumpopts) { +static json_value *glyf_glyph_to_json(glyf_glyph *g, caryll_options *options) { json_value *glyph = json_object_new(10); - if (dumpopts->export_fdselect) { + if (options->export_fdselect) { json_object_push(glyph, "fdSelectIndex", json_integer_new(g->fdSelectIndex)); } json_object_push(glyph, "advanceWidth", json_integer_new(g->advanceWidth)); - if (dumpopts->has_vertical_metrics) { + if (options->has_vertical_metrics) { json_object_push(glyph, "advanceHeight", json_integer_new(g->advanceHeight)); json_object_push(glyph, "verticalOrigin", json_integer_new(g->verticalOrigin)); } glyf_glyph_contours_to_json(g, glyph); glyf_glyph_references_to_json(g, glyph); - if (!dumpopts->ignore_hints && g->instructions && g->instructionsLength) { + if (!options->ignore_hints && g->instructions && g->instructionsLength) { json_object_push(glyph, "instructions", - instr_to_json(g->instructions, g->instructionsLength, dumpopts)); + instr_to_json(g->instructions, g->instructionsLength, options)); } - if (!dumpopts->ignore_hints && g->stemH && g->numberOfStemH) { + if (!options->ignore_hints && g->stemH && g->numberOfStemH) { json_object_push(glyph, "stemH", preserialize(glyf_glyph_stemdefs_to_json(g->stemH, g->numberOfStemH))); } - if (!dumpopts->ignore_hints && g->stemV && g->numberOfStemV) { + if (!options->ignore_hints && g->stemV && g->numberOfStemV) { json_object_push(glyph, "stemV", preserialize(glyf_glyph_stemdefs_to_json(g->stemV, g->numberOfStemV))); } - if (!dumpopts->ignore_hints && g->hintMasks && g->numberOfHintMasks) { + if (!options->ignore_hints && g->hintMasks && g->numberOfHintMasks) { json_object_push(glyph, "hintMasks", preserialize(glyf_glyph_maskdefs_to_json( g->hintMasks, g->numberOfHintMasks, g->numberOfStemH, g->numberOfStemV))); } - if (!dumpopts->ignore_hints && g->contourMasks && g->numberOfContourMasks) { + if (!options->ignore_hints && g->contourMasks && g->numberOfContourMasks) { json_object_push(glyph, "contourMasks", preserialize(glyf_glyph_maskdefs_to_json( g->contourMasks, g->numberOfContourMasks, g->numberOfStemH, g->numberOfStemV))); @@ -487,16 +487,16 @@ void caryll_glyphorder_to_json(table_glyf *table, json_value *root) { } json_object_push(root, "glyph_order", preserialize(order)); } -void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_options *options) { if (!table) return; json_value *glyf = json_object_new(table->numberGlyphs); for (uint16_t j = 0; j < table->numberGlyphs; j++) { glyf_glyph *g = table->glyphs[j]; - json_object_push(glyf, g->name, glyf_glyph_to_json(g, dumpopts)); + json_object_push(glyf, g->name, glyf_glyph_to_json(g, options)); } json_object_push(root, "glyf", glyf); - if (!dumpopts->ignore_glyph_order) caryll_glyphorder_to_json(table, root); + if (!options->ignore_glyph_order) caryll_glyphorder_to_json(table, root); } // from json @@ -641,7 +641,7 @@ static void masks_from_json(json_value *md, uint16_t *count, glyf_postscript_hin static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, glyph_order_entry *order_entry, - caryll_dump_options *dumpopts) { + caryll_options *options) { glyf_glyph *g = caryll_new_glyf_glyph(); g->name = order_entry->name; g->advanceWidth = json_obj_getint(glyphdump, "advanceWidth"); @@ -650,7 +650,7 @@ static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, g->fdSelectIndex = json_obj_getint(glyphdump, "fdSelectIndex"); glyf_contours_from_json(json_obj_get_type(glyphdump, "contours", json_array), g); glyf_references_from_json(json_obj_get_type(glyphdump, "references", json_array), g); - if (!dumpopts->ignore_hints) { + if (!options->ignore_hints) { instr_from_json(json_obj_get(glyphdump, "instructions"), g, makeInstrsForGlyph, wrongInstrsForGlyph); stems_from_json(json_obj_get_type(glyphdump, "stemH", json_array), &g->numberOfStemH, @@ -669,7 +669,7 @@ static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, } table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, - caryll_dump_options *dumpopts) { + caryll_options *options) { if (root->type != json_object || !glyph_order) return NULL; table_glyf *glyf = NULL; json_value *table; @@ -686,7 +686,7 @@ table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order HASH_FIND_STR(glyph_order, gname, order_entry); if (glyphdump->type == json_object && order_entry && !glyf->glyphs[order_entry->gid]) { glyf->glyphs[order_entry->gid] = - caryll_glyf_glyph_from_json(glyphdump, order_entry, dumpopts); + caryll_glyf_glyph_from_json(glyphdump, order_entry, options); } sdsfree(gname); } @@ -853,7 +853,7 @@ static void glyf_write_composite(glyf_glyph *g, caryll_buffer *gbuf) { } } void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, - caryll_buffer *bufloca, caryll_dump_options *dumpopts) { + caryll_buffer *bufloca, caryll_options *options) { caryll_buffer *gbuf = bufnew(); uint32_t *loca = malloc((table->numberGlyphs + 1) * sizeof(uint32_t)); diff --git a/lib/tables/glyf.h b/lib/tables/glyf.h index b89e2463..549014d0 100644 --- a/lib/tables/glyf.h +++ b/lib/tables/glyf.h @@ -132,10 +132,10 @@ typedef enum { glyf_glyph *caryll_new_glyf_glyph(); table_glyf *caryll_read_glyf(caryll_packet packet, table_head *head, table_maxp *maxp); void caryll_delete_glyf(table_glyf *table); -void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_dump_options *dumpopts); +void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_options *options); table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, - caryll_dump_options *dumpopts); + caryll_options *options); void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, - caryll_buffer *bufloca, caryll_dump_options *dumpopts); + caryll_buffer *bufloca, caryll_options *options); #endif diff --git a/lib/tables/head.c b/lib/tables/head.c index c03aacd6..a0c08124 100644 --- a/lib/tables/head.c +++ b/lib/tables/head.c @@ -56,7 +56,7 @@ static const char *headFlagsLabels[] = {"baselineAtY_0", "lastResortFont"}; static const char *macStyleLabels[] = {"bold", "italic", "underline", "outline", "shadow", "condensed", "extended"}; -void caryll_head_to_json(table_head *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_head_to_json(table_head *table, json_value *root, caryll_options *options) { if (!table) return; json_value *head = json_object_new(15); json_object_push(head, "version", json_double_new(caryll_from_fixed(table->version))); @@ -77,7 +77,7 @@ void caryll_head_to_json(table_head *table, json_value *root, caryll_dump_option json_object_push(root, "head", head); } -table_head *caryll_head_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_head *caryll_head_from_json(json_value *root, caryll_options *options) { table_head *head = caryll_new_head(); json_value *table = NULL; if ((table = json_obj_get_type(root, "head", json_object))) { @@ -100,7 +100,7 @@ table_head *caryll_head_from_json(json_value *root, caryll_dump_options *dumpopt return head; } -caryll_buffer *caryll_write_head(table_head *head, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_head(table_head *head, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!head) return buf; bufwrite32b(buf, head->version); diff --git a/lib/tables/head.h b/lib/tables/head.h index a0c7ddf8..c4325cda 100644 --- a/lib/tables/head.h +++ b/lib/tables/head.h @@ -27,8 +27,8 @@ typedef struct { table_head *caryll_new_head(); table_head *caryll_read_head(caryll_packet packet); -void caryll_head_to_json(table_head *table, json_value *root, caryll_dump_options *dumpopts); -table_head *caryll_head_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_head(table_head *head, caryll_dump_options *dumpopts); +void caryll_head_to_json(table_head *table, json_value *root, caryll_options *options); +table_head *caryll_head_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_head(table_head *head, caryll_options *options); #endif diff --git a/lib/tables/hhea.c b/lib/tables/hhea.c index 5124f21d..d8b9198a 100644 --- a/lib/tables/hhea.c +++ b/lib/tables/hhea.c @@ -37,7 +37,7 @@ table_hhea *caryll_read_hhea(caryll_packet packet) { return NULL; } -void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_options *options) { if (!table) return; json_value *hhea = json_object_new(13); json_object_push(hhea, "version", json_double_new(caryll_from_fixed(table->version))); @@ -57,7 +57,7 @@ void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_dump_option json_object_push(root, "hhea", hhea); } -table_hhea *caryll_hhea_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_hhea *caryll_hhea_from_json(json_value *root, caryll_options *options) { table_hhea *hhea = caryll_new_hhea(); json_value *table = NULL; if ((table = json_obj_get_type(root, "hhea", json_object))) { @@ -79,7 +79,7 @@ table_hhea *caryll_hhea_from_json(json_value *root, caryll_dump_options *dumpopt return hhea; } -caryll_buffer *caryll_write_hhea(table_hhea *hhea, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_hhea(table_hhea *hhea, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!hhea) return buf; bufwrite32b(buf, hhea->version); diff --git a/lib/tables/hhea.h b/lib/tables/hhea.h index f82ce045..893da50e 100644 --- a/lib/tables/hhea.h +++ b/lib/tables/hhea.h @@ -24,8 +24,8 @@ typedef struct { table_hhea *caryll_new_hhea(); table_hhea *caryll_read_hhea(caryll_packet packet); -void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_dump_options *dumpopts); -table_hhea *caryll_hhea_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_hhea(table_hhea *hhea, caryll_dump_options *dumpopts); +void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_options *options); +table_hhea *caryll_hhea_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_hhea(table_hhea *hhea, caryll_options *options); #endif diff --git a/lib/tables/hmtx.c b/lib/tables/hmtx.c index 92359463..ba05a93c 100644 --- a/lib/tables/hmtx.c +++ b/lib/tables/hmtx.c @@ -43,7 +43,7 @@ void caryll_delete_hmtx(table_hmtx *table) { } caryll_buffer *caryll_write_hmtx(table_hmtx *hmtx, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts) { + caryll_options *options) { caryll_buffer *buf = bufnew(); if (!hmtx) return buf; if (hmtx->metrics) { diff --git a/lib/tables/hmtx.h b/lib/tables/hmtx.h index 93315cfe..620367c4 100644 --- a/lib/tables/hmtx.h +++ b/lib/tables/hmtx.h @@ -21,6 +21,6 @@ typedef struct { table_hmtx *caryll_read_hmtx(caryll_packet packet, table_hhea *hhea, table_maxp *maxp); void caryll_delete_hmtx(table_hmtx *table); caryll_buffer *caryll_write_hmtx(table_hmtx *table, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts); + caryll_options *options); #endif diff --git a/lib/tables/maxp.c b/lib/tables/maxp.c index 0e0ff367..2ba1a213 100644 --- a/lib/tables/maxp.c +++ b/lib/tables/maxp.c @@ -52,7 +52,7 @@ table_maxp *caryll_read_maxp(caryll_packet packet) { return NULL; } -void caryll_maxp_to_json(table_maxp *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_maxp_to_json(table_maxp *table, json_value *root, caryll_options *options) { if (!table) return; json_value *maxp = json_object_new(15); json_object_push(maxp, "version", json_double_new(caryll_from_fixed(table->version))); @@ -74,7 +74,7 @@ void caryll_maxp_to_json(table_maxp *table, json_value *root, caryll_dump_option json_object_push(root, "maxp", maxp); } -table_maxp *caryll_maxp_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_maxp *caryll_maxp_from_json(json_value *root, caryll_options *options) { table_maxp *maxp = caryll_new_maxp(); json_value *table = NULL; if ((table = json_obj_get_type(root, "maxp", json_object))) { @@ -90,7 +90,7 @@ table_maxp *caryll_maxp_from_json(json_value *root, caryll_dump_options *dumpopt return maxp; } -caryll_buffer *caryll_write_maxp(table_maxp *maxp, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_maxp(table_maxp *maxp, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!maxp) return buf; bufwrite32b(buf, maxp->version); diff --git a/lib/tables/maxp.h b/lib/tables/maxp.h index 99a902c2..6d660387 100644 --- a/lib/tables/maxp.h +++ b/lib/tables/maxp.h @@ -25,7 +25,7 @@ typedef struct { table_maxp *caryll_new_maxp(); table_maxp *caryll_read_maxp(caryll_packet packet); -void caryll_maxp_to_json(table_maxp *table, json_value *root, caryll_dump_options *dumpopts); -table_maxp *caryll_maxp_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_maxp(table_maxp *maxp, caryll_dump_options *dumpopts); +void caryll_maxp_to_json(table_maxp *table, json_value *root, caryll_options *options); +table_maxp *caryll_maxp_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_maxp(table_maxp *maxp, caryll_options *options); #endif diff --git a/lib/tables/name.c b/lib/tables/name.c index bc7e7333..43de56a9 100644 --- a/lib/tables/name.c +++ b/lib/tables/name.c @@ -56,7 +56,7 @@ void caryll_delete_name(table_name *table) { free(table); } -void caryll_name_to_json(table_name *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_name_to_json(table_name *table, json_value *root, caryll_options *options) { if (!table) return; json_value *name = json_array_new(table->count); for (uint16_t j = 0; j < table->count; j++) { @@ -80,7 +80,7 @@ static int name_record_sort(const void *_a, const void *_b) { if ((*a)->languageID != (*b)->languageID) return (*a)->languageID - (*b)->languageID; return (*a)->nameID - (*b)->nameID; } -table_name *caryll_name_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_name *caryll_name_from_json(json_value *root, caryll_options *options) { table_name *name = calloc(1, sizeof(table_name)); json_value *table = NULL; if ((table = json_obj_get_type(root, "name", json_array))) { @@ -135,7 +135,7 @@ table_name *caryll_name_from_json(json_value *root, caryll_dump_options *dumpopt } return name; } -caryll_buffer *caryll_write_name(table_name *name, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_name(table_name *name, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!name) return buf; bufwrite16b(buf, 0); diff --git a/lib/tables/name.h b/lib/tables/name.h index 3840d229..7f9f1fa7 100644 --- a/lib/tables/name.h +++ b/lib/tables/name.h @@ -21,7 +21,7 @@ typedef struct { table_name *caryll_read_name(caryll_packet packet); void caryll_delete_name(table_name *table); -void caryll_name_to_json(table_name *table, json_value *root, caryll_dump_options *dumpopts); -table_name *caryll_name_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_name(table_name *name, caryll_dump_options *dumpopts); +void caryll_name_to_json(table_name *table, json_value *root, caryll_options *options); +table_name *caryll_name_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_name(table_name *name, caryll_options *options); #endif diff --git a/lib/tables/otl/GDEF.c b/lib/tables/otl/GDEF.c index f1636fc0..71205c2d 100644 --- a/lib/tables/otl/GDEF.c +++ b/lib/tables/otl/GDEF.c @@ -97,7 +97,7 @@ table_GDEF *caryll_read_GDEF(caryll_packet packet) { return gdef; } -void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_dump_options *dumpopts) { +void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_options *options) { if (!gdef) return; json_value *_gdef = json_object_new(4); if (gdef->glyphClassDef) { @@ -171,7 +171,7 @@ static lig_caret_table *ligCaretFromJson(json_value *_carets) { return lc; } -table_GDEF *caryll_GDEF_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_GDEF *caryll_GDEF_from_json(json_value *root, caryll_options *options) { table_GDEF *gdef = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "GDEF", json_object))) { @@ -221,7 +221,7 @@ static caryll_buffer *writeLigCarets(lig_caret_table *lc) { return buf; } -caryll_buffer *caryll_write_GDEF(table_GDEF *gdef, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_GDEF(table_GDEF *gdef, caryll_options *options) { caryll_buffer *buf = bufnew(); bufwrite32b(buf, 0x10000); size_t offset = 12; diff --git a/lib/tables/otl/GDEF.h b/lib/tables/otl/GDEF.h index ba84d9f9..b785fe42 100644 --- a/lib/tables/otl/GDEF.h +++ b/lib/tables/otl/GDEF.h @@ -25,8 +25,8 @@ typedef struct { void caryll_delete_GDEF(table_GDEF *gdef); table_GDEF *caryll_read_GDEF(caryll_packet packet); -void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_dump_options *dumpopts); -table_GDEF *caryll_GDEF_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_GDEF(table_GDEF *gdef, caryll_dump_options *dumpopts); +void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_options *options); +table_GDEF *caryll_GDEF_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_GDEF(table_GDEF *gdef, caryll_options *options); #endif diff --git a/lib/tables/otl/otl.c b/lib/tables/otl/otl.c index 5dedbe17..06e736f8 100644 --- a/lib/tables/otl/otl.c +++ b/lib/tables/otl/otl.c @@ -324,7 +324,7 @@ static void _declare_lookup_dumper(otl_lookup_type llt, const char *lt, } } -void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options *dumpopts, +void caryll_otl_to_json(table_otl *table, json_value *root, caryll_options *options, const char *tag) { if (!table || !table->languages || !table->lookups || !table->features) return; json_value *otl = json_object_new(3); @@ -551,7 +551,7 @@ static int by_lookup_order(lookup_hash *a, lookup_hash *b) { } static int by_feature_name(feature_hash *a, feature_hash *b) { return strcmp(a->name, b->name); } static int by_language_name(language_hash *a, language_hash *b) { return strcmp(a->name, b->name); } -table_otl *caryll_otl_from_json(json_value *root, caryll_dump_options *dumpopts, const char *tag) { +table_otl *caryll_otl_from_json(json_value *root, caryll_options *options, const char *tag) { table_otl *otl = NULL; NEW(otl); json_value *table = json_obj_get_type(root, tag, json_object); @@ -646,7 +646,7 @@ static bool _declare_lookup_writer(otl_lookup_type type, } // When writing lookups, otfcc will try to maintain everything correctly. -static caryll_buffer *writeOTLLookups(table_otl *table) { +static caryll_buffer *writeOTLLookups(table_otl *table, caryll_options *options) { caryll_buffer *bufl = bufnew(); caryll_buffer *bufsts = bufnew(); uint32_t **subtableOffsets; @@ -667,7 +667,9 @@ static caryll_buffer *writeOTLLookups(table_otl *table) { } bool useExtended = lastOffset >= 0xFF00 - headerSize; if (useExtended) { - fprintf(stderr, "[OTFCC-fea] Using extended OpenType table layout.\n"); + if (options->verbose) { + fprintf(stderr, "[OTFCC-fea] Using extended OpenType table layout.\n"); + } for (uint16_t j = 0; j < table->lookupCount; j++) { if (lookupWritten[j]) { headerSize += 8 * table->lookups[j]->subtableCount; } } @@ -748,7 +750,7 @@ static uint32_t featureNameToTag(sds name) { if (sdslen(name) > 3) { tag |= ((uint8_t)name[3]) << 0; } return tag; } -static caryll_buffer *writeOTLFeatures(table_otl *table) { +static caryll_buffer *writeOTLFeatures(table_otl *table, caryll_options *options) { caryll_buffer *buff = bufnew(); bufwrite16b(buff, table->featureCount); size_t offset = 2 + table->featureCount * 6; @@ -838,7 +840,7 @@ static caryll_buffer *writeScript(script_stat_hash *script, table_otl *table) { } return buf; } -static caryll_buffer *writeOTLScriptAndLanguages(table_otl *table) { +static caryll_buffer *writeOTLScriptAndLanguages(table_otl *table, caryll_options *options) { caryll_buffer *bufs = bufnew(); script_stat_hash *h = NULL; for (uint16_t j = 0; j < table->languageCount; j++) { @@ -889,13 +891,13 @@ static caryll_buffer *writeOTLScriptAndLanguages(table_otl *table) { return bufs; } -caryll_buffer *caryll_write_otl(table_otl *table, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_otl(table_otl *table, caryll_options *options) { caryll_buffer *buf = bufnew(); bufwrite32b(buf, 0x10000); - caryll_buffer *bufl = writeOTLLookups(table); - caryll_buffer *buff = writeOTLFeatures(table); - caryll_buffer *bufs = writeOTLScriptAndLanguages(table); + caryll_buffer *bufl = writeOTLLookups(table, options); + caryll_buffer *buff = writeOTLFeatures(table, options); + caryll_buffer *bufs = writeOTLScriptAndLanguages(table, options); size_t rootOffset = 10; { diff --git a/lib/tables/otl/otl.h b/lib/tables/otl/otl.h index f1f5dd47..d16945b0 100644 --- a/lib/tables/otl/otl.h +++ b/lib/tables/otl/otl.h @@ -196,10 +196,10 @@ otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLen table_otl *caryll_new_otl(); void caryll_delete_otl(table_otl *table); table_otl *caryll_read_otl(caryll_packet packet, uint32_t tag); -void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options *dumpopts, +void caryll_otl_to_json(table_otl *table, json_value *root, caryll_options *options, const char *tag); -table_otl *caryll_otl_from_json(json_value *root, caryll_dump_options *dumpopts, const char *tag); -caryll_buffer *caryll_write_otl(table_otl *table, caryll_dump_options *dumpopts); +table_otl *caryll_otl_from_json(json_value *root, caryll_options *options, const char *tag); +caryll_buffer *caryll_write_otl(table_otl *table, caryll_options *options); #include "gsub-single.h" #include "gsub-multi.h" diff --git a/lib/tables/post.c b/lib/tables/post.c index 03f09e52..759e2b63 100644 --- a/lib/tables/post.c +++ b/lib/tables/post.c @@ -67,7 +67,7 @@ void caryll_delete_post(table_post *table) { free(table); } -void caryll_post_to_json(table_post *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_post_to_json(table_post *table, json_value *root, caryll_options *options) { if (!table) return; json_value *post = json_object_new(10); json_object_push(post, "version", json_double_new(caryll_from_fixed(table->version))); @@ -81,11 +81,11 @@ void caryll_post_to_json(table_post *table, json_value *root, caryll_dump_option json_object_push(post, "maxMemType1", json_integer_new(table->maxMemType1)); json_object_push(root, "post", post); } -table_post *caryll_post_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_post *caryll_post_from_json(json_value *root, caryll_options *options) { table_post *post = caryll_new_post(); json_value *table = NULL; if ((table = json_obj_get_type(root, "post", json_object))) { - if (dumpopts->short_post) { + if (options->short_post) { post->version = 0x30000; } else { post->version = caryll_to_fixed(json_obj_getnum(table, "version")); @@ -102,7 +102,7 @@ table_post *caryll_post_from_json(json_value *root, caryll_dump_options *dumpopt return post; } caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, - caryll_dump_options *dumpopts) { + caryll_options *options) { caryll_buffer *buf = bufnew(); if (!post) return buf; bufwrite32b(buf, post->version); diff --git a/lib/tables/post.h b/lib/tables/post.h index 194b8b65..4af2751b 100644 --- a/lib/tables/post.h +++ b/lib/tables/post.h @@ -22,9 +22,9 @@ typedef struct { table_post *caryll_new_post(); table_post *caryll_read_post(caryll_packet packet); void caryll_delete_post(table_post *table); -void caryll_post_to_json(table_post *table, json_value *root, caryll_dump_options *dumpopts); -table_post *caryll_post_from_json(json_value *root, caryll_dump_options *dumpopts); +void caryll_post_to_json(table_post *table, json_value *root, caryll_options *options); +table_post *caryll_post_from_json(json_value *root, caryll_options *options); caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, - caryll_dump_options *dumpopts); + caryll_options *options); #endif diff --git a/lib/tables/vhea.c b/lib/tables/vhea.c index 93859f4b..cc819dcc 100644 --- a/lib/tables/vhea.c +++ b/lib/tables/vhea.c @@ -35,7 +35,7 @@ table_vhea *caryll_read_vhea(caryll_packet packet) { } return NULL; } -void caryll_vhea_to_json(table_vhea *table, json_value *root, caryll_dump_options *dumpopts) { +void caryll_vhea_to_json(table_vhea *table, json_value *root, caryll_options *options) { if (!table) return; json_value *vhea = json_object_new(11); json_object_push(vhea, "ascent", json_integer_new(table->ascent)); @@ -52,7 +52,7 @@ void caryll_vhea_to_json(table_vhea *table, json_value *root, caryll_dump_option json_object_push(root, "vhea", vhea); } -table_vhea *caryll_vhea_from_json(json_value *root, caryll_dump_options *dumpopts) { +table_vhea *caryll_vhea_from_json(json_value *root, caryll_options *options) { table_vhea *vhea = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "vhea", json_object))) { @@ -73,7 +73,7 @@ table_vhea *caryll_vhea_from_json(json_value *root, caryll_dump_options *dumpopt return vhea; } -caryll_buffer *caryll_write_vhea(table_vhea *vhea, caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_vhea(table_vhea *vhea, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!vhea) return buf; bufwrite32b(buf, vhea->version); diff --git a/lib/tables/vhea.h b/lib/tables/vhea.h index 3721dbef..803ace3a 100644 --- a/lib/tables/vhea.h +++ b/lib/tables/vhea.h @@ -26,7 +26,7 @@ typedef struct { table_vhea *caryll_new_vhea(); table_vhea *caryll_read_vhea(caryll_packet packet); -void caryll_vhea_to_json(table_vhea *table, json_value *root, caryll_dump_options *dumpopts); -table_vhea *caryll_vhea_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_vhea(table_vhea *vhea, caryll_dump_options *dumpopts); +void caryll_vhea_to_json(table_vhea *table, json_value *root, caryll_options *options); +table_vhea *caryll_vhea_from_json(json_value *root, caryll_options *options); +caryll_buffer *caryll_write_vhea(table_vhea *vhea, caryll_options *options); #endif diff --git a/lib/tables/vmtx.c b/lib/tables/vmtx.c index da09e66d..f989f4a4 100644 --- a/lib/tables/vmtx.c +++ b/lib/tables/vmtx.c @@ -43,7 +43,7 @@ void caryll_delete_vmtx(table_vmtx *table) { } caryll_buffer *caryll_write_vmtx(table_vmtx *vmtx, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts) { + caryll_options *options) { caryll_buffer *buf = bufnew(); if (!vmtx) return buf; if (vmtx->metrics) { diff --git a/lib/tables/vmtx.h b/lib/tables/vmtx.h index 577ef05e..e9ef6dba 100644 --- a/lib/tables/vmtx.h +++ b/lib/tables/vmtx.h @@ -20,6 +20,6 @@ typedef struct { table_vmtx *caryll_read_vmtx(caryll_packet packet, table_vhea *vhea, table_maxp *maxp); void caryll_delete_vmtx(table_vmtx *table); caryll_buffer *caryll_write_vmtx(table_vmtx *table, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts); + caryll_options *options); #endif diff --git a/src/otfccbuild.c b/src/otfccbuild.c index b17889ad..4d73d604 100644 --- a/src/otfccbuild.c +++ b/src/otfccbuild.c @@ -124,8 +124,8 @@ int main(int argc, char *argv[]) { sds inPath = NULL; int option_index = 0; int c; - caryll_dump_options *dumpopts = calloc(1, sizeof(caryll_dump_options)); - dumpopts->optimize_level = 1; + + caryll_options *options = caryll_new_options(); struct option longopts[] = {{"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, @@ -137,6 +137,7 @@ int main(int argc, char *argv[]) { {"short-post", no_argument, NULL, 0}, {"dummy-dsig", no_argument, NULL, 's'}, {"ship", no_argument, NULL, 0}, + {"verbose", no_argument, NULL, 0}, {"optimize", required_argument, NULL, 'O'}, {"output", required_argument, NULL, 'o'}, {0, 0, 0, 0}}; @@ -150,19 +151,21 @@ int main(int argc, char *argv[]) { } else if (strcmp(longopts[option_index].name, "time") == 0) { show_time = true; } else if (strcmp(longopts[option_index].name, "ignore-hints") == 0) { - dumpopts->ignore_hints = true; + options->ignore_hints = true; } else if (strcmp(longopts[option_index].name, "keep-average-char-width") == 0) { - dumpopts->keep_average_char_width = true; + options->keep_average_char_width = true; } else if (strcmp(longopts[option_index].name, "keep-modified-time") == 0) { - dumpopts->keep_modified_time = true; + options->keep_modified_time = true; } else if (strcmp(longopts[option_index].name, "ignore-glyph-order") == 0) { - dumpopts->ignore_glyph_order = true; + options->ignore_glyph_order = true; } else if (strcmp(longopts[option_index].name, "short-post") == 0) { - dumpopts->short_post = true; + options->short_post = true; } else if (strcmp(longopts[option_index].name, "ship") == 0) { - dumpopts->ignore_glyph_order = true; - dumpopts->short_post = true; - dumpopts->dummy_DSIG = true; + options->ignore_glyph_order = true; + options->short_post = true; + options->dummy_DSIG = true; + } else if (strcmp(longopts[option_index].name, "verbose") == 0) { + options->verbose = true; } break; case 'v': @@ -175,13 +178,13 @@ int main(int argc, char *argv[]) { outputPath = sdsnew(optarg); break; case 's': - dumpopts->dummy_DSIG = true; + options->dummy_DSIG = true; break; case 'O': - dumpopts->optimize_level = atoi(optarg); - if (dumpopts->optimize_level >= 2) { - dumpopts->short_post = true; - dumpopts->ignore_glyph_order = true; + options->optimize_level = atoi(optarg); + if (options->optimize_level >= 2) { + options->short_post = true; + options->ignore_glyph_order = true; } break; } @@ -232,7 +235,7 @@ int main(int argc, char *argv[]) { caryll_font *font; { - font = caryll_font_from_json(root, dumpopts); + font = caryll_font_from_json(root, options); if (!font) { fprintf(stderr, "Cannot parse JSON file \"%s\". Exit.\n", inPath); exit(EXIT_FAILURE); @@ -241,13 +244,13 @@ int main(int argc, char *argv[]) { if (show_time) push_stopwatch("Convert JSON to font", &begin); } { - caryll_font_consolidate(font, dumpopts); + caryll_font_consolidate(font, options); if (show_time) push_stopwatch("Consolidation", &begin); - caryll_font_stat(font, dumpopts); + caryll_font_stat(font, options); if (show_time) push_stopwatch("Stating", &begin); } { - caryll_buffer *otf = caryll_write_font(font, dumpopts); + caryll_buffer *otf = caryll_write_font(font, options); FILE *outfile = u8fopen(outputPath, "wb"); fwrite(otf->data, sizeof(uint8_t), buflen(otf), outfile); fclose(outfile); @@ -255,7 +258,7 @@ int main(int argc, char *argv[]) { buffree(otf); caryll_delete_font(font); - if (dumpopts) free(dumpopts); + caryll_delete_options(options); if (show_time) push_stopwatch("Finalize", &begin); } return 0; diff --git a/src/otfccdump.c b/src/otfccdump.c index 0c8433c4..5e2d50fe 100644 --- a/src/otfccdump.c +++ b/src/otfccdump.c @@ -65,12 +65,14 @@ int main(int argc, char *argv[]) { {"ignore-hints", no_argument, NULL, 0}, {"instr-as-bytes", no_argument, NULL, 0}, {"glyph-name-prefix", required_argument, NULL, 0}, + {"verbose", no_argument, NULL, 0}, {"add-bom", no_argument, NULL, 0}, {"no-bom", no_argument, NULL, 0}, {"output", required_argument, NULL, 'o'}, {"ttc-index", required_argument, NULL, 'n'}, {0, 0, 0, 0}}; - caryll_dump_options *dumpopts = calloc(1, sizeof(caryll_dump_options)); + + caryll_options *options = caryll_new_options(); int option_index = 0; int c; @@ -93,13 +95,15 @@ int main(int argc, char *argv[]) { } else if (strcmp(longopts[option_index].name, "no-bom") == 0) { no_bom = true; } else if (strcmp(longopts[option_index].name, "ignore-glyph-order") == 0) { - dumpopts->ignore_glyph_order = true; + options->ignore_glyph_order = true; + } else if (strcmp(longopts[option_index].name, "verbose") == 0) { + options->verbose = true; } else if (strcmp(longopts[option_index].name, "ignore-hints") == 0) { - dumpopts->ignore_hints = true; + options->ignore_hints = true; } else if (strcmp(longopts[option_index].name, "instr-as-bytes") == 0) { - dumpopts->instr_as_bytes = true; + options->instr_as_bytes = true; } else if (strcmp(longopts[option_index].name, "glyph-name-prefix") == 0) { - dumpopts->glyph_name_prefix = sdsnew(optarg); + options->glyph_name_prefix = sdsnew(optarg); } break; case 'v': @@ -164,13 +168,13 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Font structure broken or corrupted \"%s\". Exit.\n", inPath); exit(EXIT_FAILURE); } - caryll_font_unconsolidate(font, dumpopts); + caryll_font_unconsolidate(font, options); if (show_time) push_stopwatch("Parse SFNT", &begin); } json_value *root; { - root = caryll_font_to_json(font, dumpopts); + root = caryll_font_to_json(font, options); if (!root) { fprintf(stderr, "Font structure broken or corrupted \"%s\". Exit.\n", inPath); exit(EXIT_FAILURE); @@ -250,7 +254,7 @@ int main(int argc, char *argv[]) { if (sfnt) caryll_delete_sfnt(sfnt); if (inPath) sdsfree(inPath); if (outputPath) sdsfree(outputPath); - if (dumpopts) free(dumpopts); + caryll_delete_options(options); if (show_time) push_stopwatch("Complete", &begin); } From 45d166bbea8d1a8ad4a11ab333c9582094f356e7 Mon Sep 17 00:00:00 2001 From: be5invis Date: Wed, 27 Jul 2016 00:14:57 +0800 Subject: [PATCH 07/16] added verbosity --- lib/font/caryll-font.c | 9 ++++----- lib/tables/CFF.c | 11 +++++++---- lib/tables/OS_2.c | 3 +++ lib/tables/cmap.c | 3 +++ lib/tables/cvt.c | 6 +++++- lib/tables/cvt.h | 2 +- lib/tables/fpgm-prep.c | 10 +++++++--- lib/tables/fpgm-prep.h | 7 ++++--- lib/tables/gasp.c | 5 ++++- lib/tables/gasp.h | 2 +- lib/tables/glyf.c | 3 +++ lib/tables/head.c | 2 ++ lib/tables/hhea.c | 2 ++ lib/tables/maxp.c | 2 ++ lib/tables/name.c | 3 +++ lib/tables/otl/GDEF.c | 3 +++ lib/tables/otl/otl.c | 3 +++ lib/tables/post.c | 3 +++ lib/tables/vhea.c | 3 +++ 19 files changed, 63 insertions(+), 19 deletions(-) diff --git a/lib/font/caryll-font.c b/lib/font/caryll-font.c index 4a5513cd..6d4f5bae 100644 --- a/lib/font/caryll-font.c +++ b/lib/font/caryll-font.c @@ -128,7 +128,6 @@ json_value *caryll_font_to_json(caryll_font *font, caryll_options *options) { } caryll_otl_to_json(font->GSUB, root, options, "GSUB"); caryll_otl_to_json(font->GPOS, root, options, "GPOS"); - caryll_GDEF_to_json(font->GDEF, root, options); return root; } @@ -148,10 +147,10 @@ caryll_font *caryll_font_from_json(json_value *root, caryll_options *options) { font->CFF_ = caryll_CFF_from_json(root, options); font->glyf = caryll_glyf_from_json(root, *font->glyph_order, options); if (!options->ignore_hints) { - font->fpgm = caryll_fpgm_prep_from_json(root, "fpgm"); - font->prep = caryll_fpgm_prep_from_json(root, "prep"); - font->cvt_ = caryll_cvt_from_json(root, "cvt_"); - font->gasp = caryll_gasp_from_json(root); + font->fpgm = caryll_fpgm_prep_from_json(root, options, "fpgm"); + font->prep = caryll_fpgm_prep_from_json(root, options, "prep"); + font->cvt_ = caryll_cvt_from_json(root, options, "cvt_"); + font->gasp = caryll_gasp_from_json(root, options); } font->vhea = caryll_vhea_from_json(root, options); if (font->glyf) { diff --git a/lib/tables/CFF.c b/lib/tables/CFF.c index 3278c75c..d4548d56 100644 --- a/lib/tables/CFF.c +++ b/lib/tables/CFF.c @@ -708,6 +708,8 @@ static json_value *fdToJson(table_CFF *table) { void caryll_CFF_to_json(table_CFF *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping CFF.\n"); + json_object_push(root, "CFF_", fdToJson(table)); } @@ -806,10 +808,12 @@ static table_CFF *fdFromJson(json_value *dump) { } table_CFF *caryll_CFF_from_json(json_value *root, caryll_options *options) { json_value *dump = json_obj_get_type(root, "CFF_", json_object); - if (!dump) + if (!dump) { return NULL; - else + } else { + if (options->verbose) fprintf(stderr, "Parsing CFF.\n"); return fdFromJson(dump); + } } static caryll_buffer *compile_glyph(glyf_glyph *g, uint16_t defaultWidth, uint16_t nominalWidthX, @@ -1139,8 +1143,7 @@ static CFF_Index *cff_make_fdarray(uint16_t fdArrayCount, table_CFF **fdArray, return cff_buildindex_callback(&context, fdArrayCount, callback_makefd); } -static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, - caryll_options *options) { +static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, caryll_options *options) { caryll_buffer *blob = bufnew(); // The Strings hashtable cff_sid_entry *stringHash = NULL; diff --git a/lib/tables/OS_2.c b/lib/tables/OS_2.c index 7a17543a..c895f7bf 100644 --- a/lib/tables/OS_2.c +++ b/lib/tables/OS_2.c @@ -100,6 +100,8 @@ const char *codePageLabels2[] = {"oem8", "oem9", "oem10", "oem11", "oem12", "o void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping OS/2.\n"); + json_value *os_2 = json_object_new(30); json_object_push(os_2, "version", json_integer_new(table->version)); json_object_push(os_2, "xAvgCharWidth", json_integer_new(table->xAvgCharWidth)); @@ -162,6 +164,7 @@ table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_options *options) { if (!os_2) return NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "OS_2", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing OS/2.\n"); os_2->version = json_obj_getnum_fallback(table, "version", 0); os_2->xAvgCharWidth = json_obj_getnum_fallback(table, "xAvgCharWidth", 0); os_2->usWeightClass = json_obj_getnum_fallback(table, "usWeightClass", 0); diff --git a/lib/tables/cmap.c b/lib/tables/cmap.c index d556feef..c7184802 100644 --- a/lib/tables/cmap.c +++ b/lib/tables/cmap.c @@ -109,6 +109,8 @@ void caryll_delete_cmap(cmap_hash *table) { void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping cmap.\n"); + json_value *cmap = json_object_new(HASH_COUNT(*table)); cmap_entry *item; @@ -126,6 +128,7 @@ cmap_hash *caryll_cmap_from_json(json_value *root, caryll_options *options) { cmap_hash hash = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "cmap", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing cmap.\n"); for (uint32_t j = 0; j < table->u.object.length; j++) { sds unicodeStr = sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); diff --git a/lib/tables/cvt.c b/lib/tables/cvt.c index 4c596e6f..9526745c 100644 --- a/lib/tables/cvt.c +++ b/lib/tables/cvt.c @@ -21,16 +21,19 @@ void caryll_delete_cvt(table_cvt *table) { void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_options *options, const char *tag) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping cvt.\n"); + json_value *arr = json_array_new(table->length); for (uint16_t j = 0; j < table->length; j++) { json_array_push(arr, json_integer_new(table->words[j])); } json_object_push(root, tag, arr); } -table_cvt *caryll_cvt_from_json(json_value *root, const char *tag) { +table_cvt *caryll_cvt_from_json(json_value *root, caryll_options *options, const char *tag) { table_cvt *t = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, tag, json_array))) { + if (options->verbose) fprintf(stderr, "Parsing cvt.\n"); // Meaningful CVT dump NEW(t); t->length = table->u.array.length; @@ -46,6 +49,7 @@ table_cvt *caryll_cvt_from_json(json_value *root, const char *tag) { } } } else if ((table = json_obj_get_type(root, tag, json_string))) { + if (options->verbose) fprintf(stderr, "Parsing cvt.\n"); // Bytes CVT dump NEW(t); size_t len; diff --git a/lib/tables/cvt.h b/lib/tables/cvt.h index 08299cbb..257b7cf8 100644 --- a/lib/tables/cvt.h +++ b/lib/tables/cvt.h @@ -13,7 +13,7 @@ table_cvt *caryll_read_cvt(caryll_packet packet, uint32_t tag); void caryll_delete_cvt(table_cvt *table); void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_options *options, const char *tag); -table_cvt *caryll_cvt_from_json(json_value *root, const char *tag); +table_cvt *caryll_cvt_from_json(json_value *root, caryll_options *options, const char *tag); caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_options *options); #endif diff --git a/lib/tables/fpgm-prep.c b/lib/tables/fpgm-prep.c index 77b337ea..be4dfe5a 100644 --- a/lib/tables/fpgm-prep.c +++ b/lib/tables/fpgm-prep.c @@ -26,9 +26,11 @@ void caryll_delete_fpgm_prep(table_fpgm_prep *table) { free(table); } -void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, - caryll_options *options, const char *tag) { +void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, caryll_options *options, + const char *tag) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping %s.\n", tag); + json_object_push(root, tag, instr_to_json(table->bytes, table->length, options)); } @@ -43,10 +45,12 @@ void wrongFpgmPrepInstr(void *_t, char *reason, int pos) { t->tag); } -table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, const char *tag) { +table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, caryll_options *options, + const char *tag) { table_fpgm_prep *t = NULL; json_value *table = NULL; if ((table = json_obj_get(root, tag))) { + if (options->verbose) fprintf(stderr, "Parsing %s.\n", tag); NEW(t); t->tag = sdsnew(tag); instr_from_json(table, t, makeFpgmPrepInstr, wrongFpgmPrepInstr); diff --git a/lib/tables/fpgm-prep.h b/lib/tables/fpgm-prep.h index 61cea48a..b58e8205 100644 --- a/lib/tables/fpgm-prep.h +++ b/lib/tables/fpgm-prep.h @@ -13,9 +13,10 @@ typedef struct { } table_fpgm_prep; table_fpgm_prep *caryll_read_fpgm_prep(caryll_packet packet, uint32_t tag); void caryll_delete_fpgm_prep(table_fpgm_prep *table); -void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, - caryll_options *options, const char *tag); -table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, const char *tag); +void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, caryll_options *options, + const char *tag); +table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, caryll_options *options, + const char *tag); caryll_buffer *caryll_write_fpgm_prep(table_fpgm_prep *table, caryll_options *options); #endif diff --git a/lib/tables/gasp.c b/lib/tables/gasp.c index 4e77a98d..0b50d2e1 100644 --- a/lib/tables/gasp.c +++ b/lib/tables/gasp.c @@ -51,6 +51,8 @@ table_gasp *caryll_read_gasp(caryll_packet packet) { } void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping gasp.\n"); + json_value *t = json_array_new(table->numRanges); for (uint16_t j = 0; j < table->numRanges; j++) { json_value *rec = json_object_new(5); @@ -66,10 +68,11 @@ void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_options *op json_object_push(root, "gasp", t); } -table_gasp *caryll_gasp_from_json(json_value *root) { +table_gasp *caryll_gasp_from_json(json_value *root, caryll_options *options) { table_gasp *gasp = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "gasp", json_array))) { + if (options->verbose) fprintf(stderr, "Parsing gasp.\n"); gasp = caryll_new_gasp(); if (!gasp) goto FAIL; gasp->numRanges = table->u.array.length; diff --git a/lib/tables/gasp.h b/lib/tables/gasp.h index ffe66342..efb8e31c 100644 --- a/lib/tables/gasp.h +++ b/lib/tables/gasp.h @@ -21,6 +21,6 @@ table_gasp *caryll_new_gasp(); void caryll_delete_gasp(table_gasp *table); table_gasp *caryll_read_gasp(caryll_packet packet); void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_options *options); -table_gasp *caryll_gasp_from_json(json_value *root); +table_gasp *caryll_gasp_from_json(json_value *root, caryll_options *options); caryll_buffer *caryll_write_gasp(table_gasp *table, caryll_options *options); #endif diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index be00e022..02176411 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -489,6 +489,8 @@ void caryll_glyphorder_to_json(table_glyf *table, json_value *root) { } void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping glyf.\n"); + json_value *glyf = json_object_new(table->numberGlyphs); for (uint16_t j = 0; j < table->numberGlyphs; j++) { glyf_glyph *g = table->glyphs[j]; @@ -674,6 +676,7 @@ table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order table_glyf *glyf = NULL; json_value *table; if ((table = json_obj_get_type(root, "glyf", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing glyf.\n"); uint16_t numGlyphs = table->u.object.length; glyf = malloc(sizeof(table_glyf)); glyf->numberGlyphs = numGlyphs; diff --git a/lib/tables/head.c b/lib/tables/head.c index a0c08124..e949a767 100644 --- a/lib/tables/head.c +++ b/lib/tables/head.c @@ -58,6 +58,7 @@ static const char *macStyleLabels[] = {"bold", "italic", "underline", "outl "shadow", "condensed", "extended"}; void caryll_head_to_json(table_head *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping head.\n"); json_value *head = json_object_new(15); json_object_push(head, "version", json_double_new(caryll_from_fixed(table->version))); json_object_push(head, "fontRevison", json_double_new(caryll_from_fixed(table->fontRevison))); @@ -81,6 +82,7 @@ table_head *caryll_head_from_json(json_value *root, caryll_options *options) { table_head *head = caryll_new_head(); json_value *table = NULL; if ((table = json_obj_get_type(root, "head", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing head.\n"); head->version = caryll_to_fixed(json_obj_getnum_fallback(table, "version", 0)); head->fontRevison = caryll_to_fixed(json_obj_getnum_fallback(table, "fontRevison", 0)); head->flags = caryll_flags_from_json(json_obj_get(table, "flags"), headFlagsLabels); diff --git a/lib/tables/hhea.c b/lib/tables/hhea.c index d8b9198a..495caa25 100644 --- a/lib/tables/hhea.c +++ b/lib/tables/hhea.c @@ -39,6 +39,7 @@ table_hhea *caryll_read_hhea(caryll_packet packet) { void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping hhea.\n"); json_value *hhea = json_object_new(13); json_object_push(hhea, "version", json_double_new(caryll_from_fixed(table->version))); json_object_push(hhea, "ascender", json_integer_new(table->ascender)); @@ -61,6 +62,7 @@ table_hhea *caryll_hhea_from_json(json_value *root, caryll_options *options) { table_hhea *hhea = caryll_new_hhea(); json_value *table = NULL; if ((table = json_obj_get_type(root, "hhea", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing hhea.\n"); hhea->version = caryll_to_fixed(json_obj_getnum_fallback(table, "version", 0)); hhea->ascender = json_obj_getnum_fallback(table, "ascender", 0); hhea->descender = json_obj_getnum_fallback(table, "descender", 0); diff --git a/lib/tables/maxp.c b/lib/tables/maxp.c index 2ba1a213..1d843aef 100644 --- a/lib/tables/maxp.c +++ b/lib/tables/maxp.c @@ -54,6 +54,7 @@ table_maxp *caryll_read_maxp(caryll_packet packet) { void caryll_maxp_to_json(table_maxp *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping maxp.\n"); json_value *maxp = json_object_new(15); json_object_push(maxp, "version", json_double_new(caryll_from_fixed(table->version))); json_object_push(maxp, "numGlyphs", json_integer_new(table->numGlyphs)); @@ -78,6 +79,7 @@ table_maxp *caryll_maxp_from_json(json_value *root, caryll_options *options) { table_maxp *maxp = caryll_new_maxp(); json_value *table = NULL; if ((table = json_obj_get_type(root, "maxp", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing maxp.\n"); maxp->version = caryll_to_fixed(json_obj_getnum(table, "version")); maxp->numGlyphs = json_obj_getnum(table, "numGlyphs"); maxp->maxZones = json_obj_getnum(table, "maxZones"); diff --git a/lib/tables/name.c b/lib/tables/name.c index 43de56a9..47224d3e 100644 --- a/lib/tables/name.c +++ b/lib/tables/name.c @@ -58,6 +58,8 @@ void caryll_delete_name(table_name *table) { void caryll_name_to_json(table_name *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping name.\n"); + json_value *name = json_array_new(table->count); for (uint16_t j = 0; j < table->count; j++) { name_record *r = table->records[j]; @@ -84,6 +86,7 @@ table_name *caryll_name_from_json(json_value *root, caryll_options *options) { table_name *name = calloc(1, sizeof(table_name)); json_value *table = NULL; if ((table = json_obj_get_type(root, "name", json_array))) { + if (options->verbose) fprintf(stderr, "Parsing name.\n"); int validCount = 0; for (uint32_t j = 0; j < table->u.array.length; j++) { if (table->u.array.values[j] && table->u.array.values[j]->type == json_object) { diff --git a/lib/tables/otl/GDEF.c b/lib/tables/otl/GDEF.c index 71205c2d..0d403a64 100644 --- a/lib/tables/otl/GDEF.c +++ b/lib/tables/otl/GDEF.c @@ -99,6 +99,8 @@ table_GDEF *caryll_read_GDEF(caryll_packet packet) { void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_options *options) { if (!gdef) return; + if (options->verbose) fprintf(stderr, "Dumping GDEF.\n"); + json_value *_gdef = json_object_new(4); if (gdef->glyphClassDef) { json_object_push(_gdef, "glyphClassDef", caryll_classdef_to_json(gdef->glyphClassDef)); @@ -175,6 +177,7 @@ table_GDEF *caryll_GDEF_from_json(json_value *root, caryll_options *options) { table_GDEF *gdef = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "GDEF", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing GDEF.\n"); gdef = caryll_new_GDEF(); gdef->glyphClassDef = caryll_classdef_from_json(json_obj_get(table, "glyphClassDef")); gdef->markAttachClassDef = diff --git a/lib/tables/otl/otl.c b/lib/tables/otl/otl.c index 06e736f8..fcee76d6 100644 --- a/lib/tables/otl/otl.c +++ b/lib/tables/otl/otl.c @@ -327,6 +327,8 @@ static void _declare_lookup_dumper(otl_lookup_type llt, const char *lt, void caryll_otl_to_json(table_otl *table, json_value *root, caryll_options *options, const char *tag) { if (!table || !table->languages || !table->lookups || !table->features) return; + if (options->verbose) fprintf(stderr, "Dumping %s.\n", tag); + json_value *otl = json_object_new(3); { // dump script list @@ -556,6 +558,7 @@ table_otl *caryll_otl_from_json(json_value *root, caryll_options *options, const NEW(otl); json_value *table = json_obj_get_type(root, tag, json_object); if (!table) goto FAIL; + if (options->verbose) fprintf(stderr, "Parsing %s.\n", tag); json_value *languages = json_obj_get_type(table, "languages", json_object); json_value *features = json_obj_get_type(table, "features", json_object); json_value *lookups = json_obj_get_type(table, "lookups", json_object); diff --git a/lib/tables/post.c b/lib/tables/post.c index 759e2b63..a45f444a 100644 --- a/lib/tables/post.c +++ b/lib/tables/post.c @@ -69,6 +69,8 @@ void caryll_delete_post(table_post *table) { void caryll_post_to_json(table_post *table, json_value *root, caryll_options *options) { if (!table) return; + if (options->verbose) fprintf(stderr, "Dumping post.\n"); + json_value *post = json_object_new(10); json_object_push(post, "version", json_double_new(caryll_from_fixed(table->version))); json_object_push(post, "italicAngle", json_integer_new(caryll_from_fixed(table->italicAngle))); @@ -85,6 +87,7 @@ table_post *caryll_post_from_json(json_value *root, caryll_options *options) { table_post *post = caryll_new_post(); json_value *table = NULL; if ((table = json_obj_get_type(root, "post", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing post.\n"); if (options->short_post) { post->version = 0x30000; } else { diff --git a/lib/tables/vhea.c b/lib/tables/vhea.c index cc819dcc..5ef7d3d9 100644 --- a/lib/tables/vhea.c +++ b/lib/tables/vhea.c @@ -38,6 +38,8 @@ table_vhea *caryll_read_vhea(caryll_packet packet) { void caryll_vhea_to_json(table_vhea *table, json_value *root, caryll_options *options) { if (!table) return; json_value *vhea = json_object_new(11); + if (options->verbose) fprintf(stderr, "Dumping vhea.\n"); + json_object_push(vhea, "ascent", json_integer_new(table->ascent)); json_object_push(vhea, "descent", json_integer_new(table->descent)); json_object_push(vhea, "lineGap", json_integer_new(table->lineGap)); @@ -56,6 +58,7 @@ table_vhea *caryll_vhea_from_json(json_value *root, caryll_options *options) { table_vhea *vhea = NULL; json_value *table = NULL; if ((table = json_obj_get_type(root, "vhea", json_object))) { + if (options->verbose) fprintf(stderr, "Parsing vhea.\n"); vhea = caryll_new_vhea(); if (!vhea) return NULL; vhea->ascent = json_obj_getnum_fallback(table, "ascent", 0); From 4349988e51827886e321cc1a41665766fea1b79c Mon Sep 17 00:00:00 2001 From: be5invis Date: Wed, 27 Jul 2016 01:27:45 +0800 Subject: [PATCH 08/16] Stat: turn off same-width optimization for CFFs. --- lib/fontops/stat.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/fontops/stat.c b/lib/fontops/stat.c index 86ece84d..361a1a43 100644 --- a/lib/fontops/stat.c +++ b/lib/fontops/stat.c @@ -147,12 +147,17 @@ void caryll_font_stat_hmtx(caryll_font *font) { table_hmtx *hmtx = malloc(sizeof(table_hmtx) * 1); if (!hmtx) return; uint16_t count_a = font->glyf->numberGlyphs; - while (count_a > 2 && - font->glyf->glyphs[count_a - 1]->advanceWidth == - font->glyf->glyphs[count_a - 2]->advanceWidth) { - count_a--; + int16_t count_k = 0; + if (font->subtype == FONTTYPE_CFF) { + // pass + } else { + while (count_a > 2 && + font->glyf->glyphs[count_a - 1]->advanceWidth == + font->glyf->glyphs[count_a - 2]->advanceWidth) { + count_a--; + } + count_k = font->glyf->numberGlyphs - count_a; } - int16_t count_k = font->glyf->numberGlyphs - count_a; hmtx->metrics = malloc(sizeof(horizontal_metric) * count_a); if (count_k > 0) { hmtx->leftSideBearing = malloc(sizeof(int16_t) * count_k); @@ -193,12 +198,17 @@ void caryll_font_stat_vmtx(caryll_font *font) { table_vmtx *vmtx = malloc(sizeof(table_vmtx) * 1); if (!vmtx) return; uint16_t count_a = font->glyf->numberGlyphs; - while (count_a > 2 && - font->glyf->glyphs[count_a - 1]->advanceHeight == - font->glyf->glyphs[count_a - 2]->advanceHeight) { - count_a--; + int16_t count_k = 0; + if (font->subtype == FONTTYPE_CFF) { + // pass + } else { + while (count_a > 2 && + font->glyf->glyphs[count_a - 1]->advanceHeight == + font->glyf->glyphs[count_a - 2]->advanceHeight) { + count_a--; + } + count_k = font->glyf->numberGlyphs - count_a; } - int16_t count_k = font->glyf->numberGlyphs - count_a; vmtx->metrics = malloc(sizeof(vertical_metric) * count_a); if (count_k > 0) { vmtx->topSideBearing = malloc(sizeof(int16_t) * count_k); From a876edbce8fc80cc81132fb60c011d9f7f0f0698 Mon Sep 17 00:00:00 2001 From: be5invis Date: Wed, 27 Jul 2016 20:41:44 +0800 Subject: [PATCH 09/16] update installation instruction --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cb71601c..a99afb47 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ The `otfcc` is a C library and utility used for parsing and writing OpenType fon ## Prebuilt installations -### Windows +### Windows & Mac -Click the “Releases” above, and download the files in it. +Click the “Releases” above, and download the archives in it. ### Arch Linux From fc04649c6ba2ca43d12cfb30af733ea9bd64063a Mon Sep 17 00:00:00 2001 From: Liam Huang Date: Fri, 29 Jul 2016 10:38:22 +0800 Subject: [PATCH 10/16] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a99afb47..719186fc 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,21 @@ The `otfcc` is a C library and utility used for parsing and writing OpenType fon ## Prebuilt installations -### Windows & Mac +### Windows Click the “Releases” above, and download the archives in it. +### Mac + +If you have [Homebrew](http://brew.sh/), just run the following in your terminal. + +```bash +brew tap caryll/tap +brew install otfcc-mac64 +``` + +Otherwise, you may need to click the “Releases” above, and download the archives in it. + ### Arch Linux The package `otfcc` can be found [here](https://aur.archlinux.org/packages/otfcc/). From 2cf12a09b97cc97b654b7be5cb6a50ccc5cd57ab Mon Sep 17 00:00:00 2001 From: be5invis Date: Fri, 29 Jul 2016 21:05:57 +0800 Subject: [PATCH 11/16] Use 120 columns --- .clang-format | 2 +- lib/font/caryll-font.c | 41 ++--- lib/font/caryll-sfnt-builder.c | 3 +- lib/font/caryll-sfnt.c | 10 +- lib/fontops/consolidate.c | 32 ++-- lib/fontops/otl/chaining.c | 10 +- lib/fontops/otl/chaining.h | 3 +- lib/fontops/otl/common.c | 11 +- lib/fontops/otl/gpos-cursive.c | 7 +- lib/fontops/otl/gpos-cursive.h | 3 +- lib/fontops/otl/gpos-pair.c | 3 +- lib/fontops/otl/gpos-pair.h | 3 +- lib/fontops/otl/gpos-single.c | 7 +- lib/fontops/otl/gpos-single.h | 3 +- lib/fontops/otl/gsub-ligature.c | 3 +- lib/fontops/otl/gsub-ligature.h | 3 +- lib/fontops/otl/gsub-multi.c | 7 +- lib/fontops/otl/gsub-multi.h | 3 +- lib/fontops/otl/gsub-reverse.c | 15 +- lib/fontops/otl/gsub-reverse.h | 3 +- lib/fontops/otl/gsub-single.c | 10 +- lib/fontops/otl/gsub-single.h | 3 +- lib/fontops/otl/mark.c | 28 ++-- lib/fontops/otl/mark.h | 6 +- lib/fontops/stat.c | 83 ++++------ lib/fontops/unconsolidate.c | 38 ++--- lib/libcff/cff-charset.c | 6 +- lib/libcff/cff-codecs.c | 68 ++++---- lib/libcff/cff-dict.c | 3 +- lib/libcff/cff-dict.h | 3 +- lib/libcff/cff-fdselect.c | 3 +- lib/libcff/cff-index.c | 6 +- lib/libcff/cff-index.h | 3 +- lib/libcff/cff-parser.c | 221 +++++++++++-------------- lib/libcff/cff-string.c | 6 +- lib/libcff/cff-writer.c | 3 +- lib/libcff/charstring_il.c | 56 +++---- lib/libcff/libcff.h | 7 +- lib/support/base64.c | 3 +- lib/support/glyphorder.c | 9 +- lib/support/ttinstr.c | 22 +-- lib/support/ttinstr.h | 15 +- lib/support/util.h | 17 +- lib/tables/CFF.c | 186 +++++++-------------- lib/tables/OS_2.c | 73 +++----- lib/tables/cmap.c | 40 ++--- lib/tables/cvt.c | 7 +- lib/tables/cvt.h | 3 +- lib/tables/fpgm-prep.c | 7 +- lib/tables/fpgm-prep.h | 3 +- lib/tables/gasp.c | 6 +- lib/tables/glyf.c | 105 +++++------- lib/tables/glyf.h | 7 +- lib/tables/hdmx.c | 3 +- lib/tables/head.c | 3 +- lib/tables/hhea.c | 6 +- lib/tables/hmtx.c | 11 +- lib/tables/hmtx.h | 3 +- lib/tables/name.c | 6 +- lib/tables/otl/GDEF.c | 35 ++-- lib/tables/otl/chaining.c | 86 ++++------ lib/tables/otl/classdef.c | 3 +- lib/tables/otl/coverage.c | 8 +- lib/tables/otl/extend.c | 14 +- lib/tables/otl/extend.h | 6 +- lib/tables/otl/gpos-common.c | 7 +- lib/tables/otl/gpos-common.h | 29 ++-- lib/tables/otl/gpos-cursive.c | 26 +-- lib/tables/otl/gpos-cursive.h | 3 +- lib/tables/otl/gpos-mark-to-ligature.c | 34 ++-- lib/tables/otl/gpos-mark-to-ligature.h | 3 +- lib/tables/otl/gpos-mark-to-single.c | 47 ++---- lib/tables/otl/gpos-mark-to-single.h | 3 +- lib/tables/otl/gpos-pair.c | 49 ++---- lib/tables/otl/gpos-single.c | 21 +-- lib/tables/otl/gpos-single.h | 3 +- lib/tables/otl/gsub-ligature.c | 19 +-- lib/tables/otl/gsub-ligature.h | 3 +- lib/tables/otl/gsub-multi.c | 22 +-- lib/tables/otl/gsub-multi.h | 3 +- lib/tables/otl/gsub-reverse.c | 18 +- lib/tables/otl/gsub-single.c | 31 ++-- lib/tables/otl/gsub-single.h | 3 +- lib/tables/otl/otl.c | 161 +++++++----------- lib/tables/otl/otl.h | 9 +- lib/tables/post.c | 3 +- lib/tables/post.h | 3 +- lib/tables/vmtx.c | 11 +- lib/tables/vmtx.h | 3 +- src/otfccbuild.c | 71 ++++---- src/otfccdump.c | 15 +- src/platform.h | 3 +- 92 files changed, 745 insertions(+), 1270 deletions(-) diff --git a/.clang-format b/.clang-format index 8d62860b..053b353a 100644 --- a/.clang-format +++ b/.clang-format @@ -6,7 +6,7 @@ AllowShortBlocksOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true -ColumnLimit: 100 +ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: true IndentCaseLabels: true AlignOperands: true diff --git a/lib/font/caryll-font.c b/lib/font/caryll-font.c index 78daebc9..ee84f05b 100644 --- a/lib/font/caryll-font.c +++ b/lib/font/caryll-font.c @@ -169,9 +169,7 @@ caryll_buffer *caryll_write_font(caryll_font *font, caryll_dump_options *dumpopt if (font->subtype == FONTTYPE_TTF) { caryll_buffer *bufglyf = bufnew(); caryll_buffer *bufloca = bufnew(); - if (font->glyf && font->head) { - caryll_write_glyf(font->glyf, font->head, bufglyf, bufloca, dumpopts); - } + if (font->glyf && font->head) { caryll_write_glyf(font->glyf, font->head, bufglyf, bufloca, dumpopts); } sfnt_builder_push_table(builder, 'loca', bufloca); sfnt_builder_push_table(builder, 'glyf', bufglyf); } else { @@ -184,38 +182,27 @@ caryll_buffer *caryll_write_font(caryll_font *font, caryll_dump_options *dumpopt sfnt_builder_push_table(builder, 'OS/2', caryll_write_OS_2(font->OS_2, dumpopts)); sfnt_builder_push_table(builder, 'maxp', caryll_write_maxp(font->maxp, dumpopts)); sfnt_builder_push_table(builder, 'name', caryll_write_name(font->name, dumpopts)); - sfnt_builder_push_table(builder, 'post', - caryll_write_post(font->post, font->glyph_order, dumpopts)); + sfnt_builder_push_table(builder, 'post', caryll_write_post(font->post, font->glyph_order, dumpopts)); sfnt_builder_push_table(builder, 'cmap', caryll_write_cmap(font->cmap, dumpopts)); - if (font->fpgm) - sfnt_builder_push_table(builder, 'fpgm', caryll_write_fpgm_prep(font->fpgm, dumpopts)); - if (font->prep) - sfnt_builder_push_table(builder, 'prep', caryll_write_fpgm_prep(font->prep, dumpopts)); - if (font->cvt_) - sfnt_builder_push_table(builder, 'cvt ', caryll_write_cvt(font->cvt_, dumpopts)); - if (font->gasp) - sfnt_builder_push_table(builder, 'gasp', caryll_write_gasp(font->gasp, dumpopts)); + if (font->fpgm) sfnt_builder_push_table(builder, 'fpgm', caryll_write_fpgm_prep(font->fpgm, dumpopts)); + if (font->prep) sfnt_builder_push_table(builder, 'prep', caryll_write_fpgm_prep(font->prep, dumpopts)); + if (font->cvt_) sfnt_builder_push_table(builder, 'cvt ', caryll_write_cvt(font->cvt_, dumpopts)); + if (font->gasp) sfnt_builder_push_table(builder, 'gasp', caryll_write_gasp(font->gasp, dumpopts)); sfnt_builder_push_table(builder, 'hmtx', caryll_write_hmtx(font->hmtx, font->hhea->numberOfMetrics, - font->maxp->numGlyphs - font->hhea->numberOfMetrics, - dumpopts)); + font->maxp->numGlyphs - font->hhea->numberOfMetrics, dumpopts)); - if (font->vhea) - sfnt_builder_push_table(builder, 'vhea', caryll_write_vhea(font->vhea, dumpopts)); + if (font->vhea) sfnt_builder_push_table(builder, 'vhea', caryll_write_vhea(font->vhea, dumpopts)); if (font->vmtx) { - sfnt_builder_push_table( - builder, 'vmtx', - caryll_write_vmtx(font->vmtx, font->vhea->numOfLongVerMetrics, - font->maxp->numGlyphs - font->vhea->numOfLongVerMetrics, dumpopts)); + sfnt_builder_push_table(builder, 'vmtx', + caryll_write_vmtx(font->vmtx, font->vhea->numOfLongVerMetrics, + font->maxp->numGlyphs - font->vhea->numOfLongVerMetrics, dumpopts)); } - if (font->GSUB) - sfnt_builder_push_table(builder, 'GSUB', caryll_write_otl(font->GSUB, dumpopts)); - if (font->GPOS) - sfnt_builder_push_table(builder, 'GPOS', caryll_write_otl(font->GPOS, dumpopts)); - if (font->GDEF) - sfnt_builder_push_table(builder, 'GDEF', caryll_write_GDEF(font->GDEF, dumpopts)); + if (font->GSUB) sfnt_builder_push_table(builder, 'GSUB', caryll_write_otl(font->GSUB, dumpopts)); + if (font->GPOS) sfnt_builder_push_table(builder, 'GPOS', caryll_write_otl(font->GPOS, dumpopts)); + if (font->GDEF) sfnt_builder_push_table(builder, 'GDEF', caryll_write_GDEF(font->GDEF, dumpopts)); if (dumpopts->dummy_DSIG) { caryll_buffer *dsig = bufnew(); diff --git a/lib/font/caryll-sfnt-builder.c b/lib/font/caryll-sfnt-builder.c index 69174817..7beddc74 100644 --- a/lib/font/caryll-sfnt-builder.c +++ b/lib/font/caryll-sfnt-builder.c @@ -104,8 +104,7 @@ caryll_buffer *sfnt_builder_serialize(sfnt_builder *builder) { // 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); + 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); diff --git a/lib/font/caryll-sfnt.c b/lib/font/caryll-sfnt.c index 96969cab..89a5ed46 100644 --- a/lib/font/caryll-sfnt.c +++ b/lib/font/caryll-sfnt.c @@ -10,8 +10,7 @@ static void caryll_read_packets(caryll_sfnt *font, FILE *file) { font->packets[count].searchRange = caryll_get16u(file); font->packets[count].entrySelector = caryll_get16u(file); font->packets[count].rangeShift = caryll_get16u(file); - font->packets[count].pieces = - (caryll_piece *)malloc(sizeof(caryll_piece) * font->packets[count].numTables); + font->packets[count].pieces = (caryll_piece *)malloc(sizeof(caryll_piece) * font->packets[count].numTables); for (uint32_t i = 0; i < font->packets[count].numTables; i++) { font->packets[count].pieces[i].tag = caryll_get32u(file); @@ -24,8 +23,7 @@ static void caryll_read_packets(caryll_sfnt *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); } } } @@ -74,9 +72,7 @@ caryll_sfnt *caryll_read_sfnt(FILE *file) { void caryll_delete_sfnt(caryll_sfnt *font) { if (font->count > 0) { for (uint32_t count = 0; count < font->count; count++) { - for (int i = 0; i < font->packets[count].numTables; i++) { - free(font->packets[count].pieces[i].data); - } + for (int i = 0; i < font->packets[count].numTables; i++) { free(font->packets[count].pieces[i].data); } free(font->packets[count].pieces); } } diff --git a/lib/fontops/consolidate.c b/lib/fontops/consolidate.c index f40bf123..cdb50af1 100644 --- a/lib/fontops/consolidate.c +++ b/lib/fontops/consolidate.c @@ -13,8 +13,7 @@ static int by_stem_pos(const void *_a, const void *_b) { } } static int by_mask_pointindex(const void *a, const void *b) { - return ((glyf_postscript_hint_mask *)a)->pointsBefore - - ((glyf_postscript_hint_mask *)b)->pointsBefore; + return ((glyf_postscript_hint_mask *)a)->pointsBefore - ((glyf_postscript_hint_mask *)b)->pointsBefore; } void caryll_font_consolidate_glyph(glyf_glyph *g, caryll_font *font) { uint16_t nReferencesConsolidated = 0; @@ -47,8 +46,7 @@ void caryll_font_consolidate_glyph(glyf_glyph *g, caryll_font *font) { g->references = NULL; g->numberOfReferences = 0; } else { - glyf_reference *consolidatedReferences = - calloc(nReferencesConsolidated, sizeof(glyf_reference)); + glyf_reference *consolidatedReferences = calloc(nReferencesConsolidated, sizeof(glyf_reference)); for (uint16_t j = 0, k = 0; j < g->numberOfReferences; j++) { if (g->references[j].glyph.name) { consolidatedReferences[k++] = g->references[j]; } } @@ -75,29 +73,19 @@ void caryll_font_consolidate_glyph(glyf_glyph *g, caryll_font *font) { for (uint16_t j = 0; j < g->numberOfStemV; j++) { vmap[g->stemV[j].map] = j; } // sort masks if (g->hintMasks) { - qsort(g->hintMasks, g->numberOfHintMasks, sizeof(glyf_postscript_hint_mask), - by_mask_pointindex); + qsort(g->hintMasks, g->numberOfHintMasks, sizeof(glyf_postscript_hint_mask), by_mask_pointindex); for (uint16_t j = 0; j < g->numberOfHintMasks; j++) { glyf_postscript_hint_mask oldmask = g->hintMasks[j]; // copy - for (uint16_t k = 0; k < g->numberOfStemH; k++) { - g->hintMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; - } - for (uint16_t k = 0; k < g->numberOfStemV; k++) { - g->hintMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; - } + for (uint16_t k = 0; k < g->numberOfStemH; k++) { g->hintMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; } + for (uint16_t k = 0; k < g->numberOfStemV; k++) { g->hintMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; } } } if (g->contourMasks) { - qsort(g->contourMasks, g->numberOfContourMasks, sizeof(glyf_postscript_hint_mask), - by_mask_pointindex); + qsort(g->contourMasks, g->numberOfContourMasks, sizeof(glyf_postscript_hint_mask), by_mask_pointindex); for (uint16_t j = 0; j < g->numberOfContourMasks; j++) { glyf_postscript_hint_mask oldmask = g->contourMasks[j]; // copy - for (uint16_t k = 0; k < g->numberOfStemH; k++) { - g->contourMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; - } - for (uint16_t k = 0; k < g->numberOfStemV; k++) { - g->contourMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; - } + for (uint16_t k = 0; k < g->numberOfStemH; k++) { g->contourMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; } + for (uint16_t k = 0; k < g->numberOfStemV; k++) { g->contourMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; } } } free(hmap); @@ -145,8 +133,8 @@ void caryll_font_consolidate_cmap(caryll_font *font) { typedef bool (*otl_consolidation_function)(caryll_font *, table_otl *, otl_subtable *, sds); #define LOOKUP_CONSOLIDATOR(llt, fn) __declare_otl_consolidation(llt, fn, font, table, lookup); -static void __declare_otl_consolidation(otl_lookup_type type, otl_consolidation_function fn, - caryll_font *font, table_otl *table, otl_lookup *lookup) { +static void __declare_otl_consolidation(otl_lookup_type type, otl_consolidation_function fn, caryll_font *font, + table_otl *table, otl_lookup *lookup) { if (lookup && lookup->subtableCount && lookup->type == type) { for (uint16_t j = 0; j < lookup->subtableCount; j++) { if (lookup->subtables[j]) { diff --git a/lib/fontops/otl/chaining.c b/lib/fontops/otl/chaining.c index 3799f3ae..80188b09 100644 --- a/lib/fontops/otl/chaining.c +++ b/lib/fontops/otl/chaining.c @@ -1,7 +1,6 @@ #include "chaining.h" -bool consolidate_chaining(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_chaining(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_chaining *subtable = &(_subtable->chaining); otl_chaining_rule *rule = subtable->rules[0]; for (uint16_t j = 0; j < rule->matchCount; j++) { @@ -26,8 +25,8 @@ bool consolidate_chaining(caryll_font *font, table_otl *table, otl_subtable *_su } } if (!foundLookup && rule->apply[j].lookupName) { - fprintf(stderr, "[Consolidate] Quoting an invalid lookup %s in lookup %s.\n", - rule->apply[j].lookupName, lookupName); + fprintf(stderr, "[Consolidate] Quoting an invalid lookup %s in lookup %s.\n", rule->apply[j].lookupName, + lookupName); DELETE(sdsfree, rule->apply[j].lookupName); } } @@ -118,8 +117,7 @@ static int classCompatible(classifier_hash **h, otl_coverage *cov, int *past) { return 1; } } -static void rewriteRule(otl_chaining_rule *rule, classifier_hash *hb, classifier_hash *hi, - classifier_hash *hf) { +static void rewriteRule(otl_chaining_rule *rule, classifier_hash *hb, classifier_hash *hi, classifier_hash *hf) { for (uint16_t m = 0; m < rule->matchCount; m++) if (rule->match[m]->numGlyphs > 0) { classifier_hash *h = (m < rule->inputBegins ? hb : m < rule->inputEnds ? hi : hf); diff --git a/lib/fontops/otl/chaining.h b/lib/fontops/otl/chaining.h index 731dd8fa..17f6983f 100644 --- a/lib/fontops/otl/chaining.h +++ b/lib/fontops/otl/chaining.h @@ -2,8 +2,7 @@ #define CARYLL_FONTOPS_OTL_CHAINING_H #include "common.h" -bool consolidate_chaining(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_chaining(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); void classify(otl_lookup *lookup); #endif diff --git a/lib/fontops/otl/common.c b/lib/fontops/otl/common.c index d5b5a65c..91ea7640 100644 --- a/lib/fontops/otl/common.c +++ b/lib/fontops/otl/common.c @@ -1,8 +1,6 @@ #include "common.h" -static int by_gid(const void *a, const void *b) { - return ((glyph_handle *)a)->gid - ((glyph_handle *)b)->gid; -} +static int by_gid(const void *a, const void *b) { return ((glyph_handle *)a)->gid - ((glyph_handle *)b)->gid; } void consolidate_coverage(caryll_font *font, otl_coverage *coverage, sds lookupName) { if (!coverage) return; @@ -14,8 +12,8 @@ void consolidate_coverage(caryll_font *font, otl_coverage *coverage, sds lookupN if (ordentry->name != coverage->glyphs[j].name) sdsfree(coverage->glyphs[j].name); coverage->glyphs[j].name = ordentry->name; } else { - fprintf(stderr, "[Consolidate] Ignored missing glyph /%s in lookup %s.\n", - coverage->glyphs[j].name, lookupName); + fprintf(stderr, "[Consolidate] Ignored missing glyph /%s in lookup %s.\n", coverage->glyphs[j].name, + lookupName); coverage->glyphs[j].gid = 0; DELETE(sdsfree, coverage->glyphs[j].name); } @@ -41,8 +39,7 @@ void consolidate_classdef(caryll_font *font, otl_classdef *cd, sds lookupName) { if (ordentry->name != cd->glyphs[j].name) sdsfree(cd->glyphs[j].name); cd->glyphs[j].name = ordentry->name; } else { - fprintf(stderr, "[Consolidate] Ignored missing glyph /%s in lookup %s.\n", - cd->glyphs[j].name, lookupName); + fprintf(stderr, "[Consolidate] Ignored missing glyph /%s in lookup %s.\n", cd->glyphs[j].name, lookupName); cd->glyphs[j].gid = 0; DELETE(sdsfree, cd->glyphs[j].name); } diff --git a/lib/fontops/otl/gpos-cursive.c b/lib/fontops/otl/gpos-cursive.c index d2c9ce75..71324317 100644 --- a/lib/fontops/otl/gpos-cursive.c +++ b/lib/fontops/otl/gpos-cursive.c @@ -7,11 +7,8 @@ typedef struct { otl_anchor exit; UT_hash_handle hh; } gpos_cursive_hash; -static int gpos_cursive_by_from_id(gpos_cursive_hash *a, gpos_cursive_hash *b) { - return a->fromid - b->fromid; -} -bool consolidate_gpos_cursive(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +static int gpos_cursive_by_from_id(gpos_cursive_hash *a, gpos_cursive_hash *b) { return a->fromid - b->fromid; } +bool consolidate_gpos_cursive(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_cursive *subtable = &(_subtable->gpos_cursive); consolidate_coverage(font, subtable->coverage, lookupName); gpos_cursive_hash *h = NULL; diff --git a/lib/fontops/otl/gpos-cursive.h b/lib/fontops/otl/gpos-cursive.h index daea58cf..fe1e6378 100644 --- a/lib/fontops/otl/gpos-cursive.h +++ b/lib/fontops/otl/gpos-cursive.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GPOS_CURSIVE_H #include "common.h" -bool consolidate_gpos_cursive(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gpos_cursive(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/gpos-pair.c b/lib/fontops/otl/gpos-pair.c index eba03c3c..50b3483d 100644 --- a/lib/fontops/otl/gpos-pair.c +++ b/lib/fontops/otl/gpos-pair.c @@ -11,8 +11,7 @@ static otl_coverage *covFromCD(otl_classdef *cd) { } return cov; } -bool consolidate_gpos_pair(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_gpos_pair(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_pair *subtable = &(_subtable->gpos_pair); consolidate_classdef(font, subtable->first, lookupName); consolidate_classdef(font, subtable->second, lookupName); diff --git a/lib/fontops/otl/gpos-pair.h b/lib/fontops/otl/gpos-pair.h index 9385e5f2..6eed10b7 100644 --- a/lib/fontops/otl/gpos-pair.h +++ b/lib/fontops/otl/gpos-pair.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GPOS_PAIR_H #include "common.h" -bool consolidate_gpos_pair(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gpos_pair(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/gpos-single.c b/lib/fontops/otl/gpos-single.c index cd57c9ed..207be8e9 100644 --- a/lib/fontops/otl/gpos-single.c +++ b/lib/fontops/otl/gpos-single.c @@ -6,12 +6,9 @@ typedef struct { otl_position_value v; UT_hash_handle hh; } gpos_single_hash; -static int gpos_by_from_id(gpos_single_hash *a, gpos_single_hash *b) { - return a->fromid - b->fromid; -} +static int gpos_by_from_id(gpos_single_hash *a, gpos_single_hash *b) { return a->fromid - b->fromid; } -bool consolidate_gpos_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_gpos_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_single *subtable = &(_subtable->gpos_single); consolidate_coverage(font, subtable->coverage, lookupName); gpos_single_hash *h = NULL; diff --git a/lib/fontops/otl/gpos-single.h b/lib/fontops/otl/gpos-single.h index 15c9e69a..c960ebc5 100644 --- a/lib/fontops/otl/gpos-single.h +++ b/lib/fontops/otl/gpos-single.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GPOS_SINGLE_H #include "common.h" -bool consolidate_gpos_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gpos_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/gsub-ligature.c b/lib/fontops/otl/gsub-ligature.c index fb4f6321..675e4f10 100644 --- a/lib/fontops/otl/gsub-ligature.c +++ b/lib/fontops/otl/gsub-ligature.c @@ -1,7 +1,6 @@ #include "gsub-ligature.h" -bool consolidate_gsub_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_gsub_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_ligature *subtable = &(_subtable->gsub_ligature); consolidate_coverage(font, subtable->to, lookupName); for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { diff --git a/lib/fontops/otl/gsub-ligature.h b/lib/fontops/otl/gsub-ligature.h index 5d54687a..e4023728 100644 --- a/lib/fontops/otl/gsub-ligature.h +++ b/lib/fontops/otl/gsub-ligature.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GSUB_LIGATURE_H #include "common.h" -bool consolidate_gsub_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gsub_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/gsub-multi.c b/lib/fontops/otl/gsub-multi.c index eaad9d82..27bc38d2 100644 --- a/lib/fontops/otl/gsub-multi.c +++ b/lib/fontops/otl/gsub-multi.c @@ -6,12 +6,9 @@ typedef struct { otl_coverage *to; UT_hash_handle hh; } gsub_multi_hash; -static int by_from_id_multi(gsub_multi_hash *a, gsub_multi_hash *b) { - return a->fromid - b->fromid; -} +static int by_from_id_multi(gsub_multi_hash *a, gsub_multi_hash *b) { return a->fromid - b->fromid; } -bool consolidate_gsub_multi(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_gsub_multi(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_multi *subtable = &(_subtable->gsub_multi); consolidate_coverage(font, subtable->from, lookupName); for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { diff --git a/lib/fontops/otl/gsub-multi.h b/lib/fontops/otl/gsub-multi.h index b4a608ce..3a5f5e3a 100644 --- a/lib/fontops/otl/gsub-multi.h +++ b/lib/fontops/otl/gsub-multi.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GSUB_MULTI_H #include "common.h" -bool consolidate_gsub_multi(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gsub_multi(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/gsub-reverse.c b/lib/fontops/otl/gsub-reverse.c index 27b3c926..0bffb429 100644 --- a/lib/fontops/otl/gsub-reverse.c +++ b/lib/fontops/otl/gsub-reverse.c @@ -7,20 +7,13 @@ typedef struct { sds toname; UT_hash_handle hh; } gsub_single_map_hash; -static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { - return a->fromid - b->fromid; -} +static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { return a->fromid - b->fromid; } -bool consolidate_gsub_reverse(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_gsub_reverse(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse); - for (uint16_t j = 0; j < subtable->matchCount; j++) { - consolidate_coverage(font, subtable->match[j], lookupName); - } + for (uint16_t j = 0; j < subtable->matchCount; j++) { consolidate_coverage(font, subtable->match[j], lookupName); } consolidate_coverage(font, subtable->to, lookupName); - if (subtable->inputIndex >= subtable->matchCount) { - subtable->inputIndex = subtable->matchCount - 1; - } + if (subtable->inputIndex >= subtable->matchCount) { subtable->inputIndex = subtable->matchCount - 1; } gsub_single_map_hash *h = NULL; otl_coverage *from = subtable->match[subtable->inputIndex]; for (uint16_t k = 0; k < from->numGlyphs && k < subtable->to->numGlyphs; k++) { diff --git a/lib/fontops/otl/gsub-reverse.h b/lib/fontops/otl/gsub-reverse.h index 8062c2cf..07c668ca 100644 --- a/lib/fontops/otl/gsub-reverse.h +++ b/lib/fontops/otl/gsub-reverse.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GSUB_REVERSE_H #include "common.h" -bool consolidate_gsub_reverse(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gsub_reverse(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/gsub-single.c b/lib/fontops/otl/gsub-single.c index 429acf69..e4cd68b2 100644 --- a/lib/fontops/otl/gsub-single.c +++ b/lib/fontops/otl/gsub-single.c @@ -7,17 +7,13 @@ typedef struct { sds toname; UT_hash_handle hh; } gsub_single_map_hash; -static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { - return a->fromid - b->fromid; -} -bool consolidate_gsub_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { return a->fromid - b->fromid; } +bool consolidate_gsub_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_single *subtable = &(_subtable->gsub_single); consolidate_coverage(font, subtable->from, lookupName); consolidate_coverage(font, subtable->to, lookupName); uint16_t len = - (subtable->from->numGlyphs < subtable->to->numGlyphs ? subtable->from->numGlyphs - : subtable->from->numGlyphs); + (subtable->from->numGlyphs < subtable->to->numGlyphs ? subtable->from->numGlyphs : subtable->from->numGlyphs); gsub_single_map_hash *h = NULL; for (uint16_t k = 0; k < len; k++) { if (subtable->from->glyphs[k].name && subtable->to->glyphs[k].name) { diff --git a/lib/fontops/otl/gsub-single.h b/lib/fontops/otl/gsub-single.h index acaff683..f4349742 100644 --- a/lib/fontops/otl/gsub-single.h +++ b/lib/fontops/otl/gsub-single.h @@ -2,7 +2,6 @@ #define CARYLL_FONTOPS_OTL_GSUB_SINGLE_H #include "common.h" -bool consolidate_gsub_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_gsub_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/otl/mark.c b/lib/fontops/otl/mark.c index bca3b8e2..40001dbc 100644 --- a/lib/fontops/otl/mark.c +++ b/lib/fontops/otl/mark.c @@ -22,16 +22,14 @@ typedef struct { } lig_hash; static int lig_by_gid(lig_hash *a, lig_hash *b) { return a->gid - b->gid; } -static void consolidateMarkArray(caryll_font *font, table_otl *table, sds lookupName, - otl_coverage *marks, otl_mark_array *markArray, - uint16_t classCount) { +static void consolidateMarkArray(caryll_font *font, table_otl *table, sds lookupName, otl_coverage *marks, + otl_mark_array *markArray, uint16_t classCount) { mark_hash *hm = NULL; for (uint16_t k = 0; k < marks->numGlyphs; k++) { if (marks->glyphs[k].name) { mark_hash *s = NULL; HASH_FIND_INT(hm, &(marks->glyphs[k].gid), s); - if (!s && markArray->records[k].anchor.present && - markArray->records[k].markClass < classCount) { + if (!s && markArray->records[k].anchor.present && markArray->records[k].markClass < classCount) { NEW(s); s->gid = marks->glyphs[k].gid; s->name = marks->glyphs[k].name; @@ -60,8 +58,8 @@ static void consolidateMarkArray(caryll_font *font, table_otl *table, sds lookup } } -static void consolidateBaseArray(caryll_font *font, table_otl *table, sds lookupName, - otl_coverage *bases, otl_anchor **baseArray) { +static void consolidateBaseArray(caryll_font *font, table_otl *table, sds lookupName, otl_coverage *bases, + otl_anchor **baseArray) { // consolidate bases base_hash *hm = NULL; for (uint16_t k = 0; k < bases->numGlyphs; k++) { @@ -98,8 +96,8 @@ static void consolidateBaseArray(caryll_font *font, table_otl *table, sds lookup } } -static void consolidateLigArray(caryll_font *font, table_otl *table, sds lookupName, - otl_coverage *bases, mark_to_ligature_base **ligArray) { +static void consolidateLigArray(caryll_font *font, table_otl *table, sds lookupName, otl_coverage *bases, + mark_to_ligature_base **ligArray) { lig_hash *hm = NULL; for (uint16_t k = 0; k < bases->numGlyphs; k++) { if (bases->glyphs[k].name) { @@ -135,24 +133,20 @@ static void consolidateLigArray(caryll_font *font, table_otl *table, sds lookupN } } -bool consolidate_mark_to_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_mark_to_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_mark_to_single *subtable = &(_subtable->gpos_mark_to_single); consolidate_coverage(font, subtable->marks, lookupName); consolidate_coverage(font, subtable->bases, lookupName); - consolidateMarkArray(font, table, lookupName, subtable->marks, subtable->markArray, - subtable->classCount); + consolidateMarkArray(font, table, lookupName, subtable->marks, subtable->markArray, subtable->classCount); consolidateBaseArray(font, table, lookupName, subtable->bases, subtable->baseArray); return false; } -bool consolidate_mark_to_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName) { +bool consolidate_mark_to_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_mark_to_ligature *subtable = &(_subtable->gpos_mark_to_ligature); consolidate_coverage(font, subtable->marks, lookupName); consolidate_coverage(font, subtable->bases, lookupName); - consolidateMarkArray(font, table, lookupName, subtable->marks, subtable->markArray, - subtable->classCount); + consolidateMarkArray(font, table, lookupName, subtable->marks, subtable->markArray, subtable->classCount); consolidateLigArray(font, table, lookupName, subtable->bases, subtable->ligArray); return false; } diff --git a/lib/fontops/otl/mark.h b/lib/fontops/otl/mark.h index 566817d6..169fc2f2 100644 --- a/lib/fontops/otl/mark.h +++ b/lib/fontops/otl/mark.h @@ -2,9 +2,7 @@ #define CARYLL_FONTOPS_OTL_MARK_H #include "common.h" -bool consolidate_mark_to_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); -bool consolidate_mark_to_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, - sds lookupName); +bool consolidate_mark_to_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); +bool consolidate_mark_to_ligature(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName); #endif diff --git a/lib/fontops/stat.c b/lib/fontops/stat.c index 76d15903..360b7623 100644 --- a/lib/fontops/stat.c +++ b/lib/fontops/stat.c @@ -5,8 +5,8 @@ typedef enum { stat_not_started = 0, stat_doing = 1, stat_completed = 2 } stat_status; -glyf_glyph_stat stat_single_glyph(table_glyf *table, glyf_reference *gr, stat_status *stated, - uint8_t depth, uint16_t topj) { +glyf_glyph_stat stat_single_glyph(table_glyf *table, glyf_reference *gr, stat_status *stated, uint8_t depth, + uint16_t topj) { glyf_glyph_stat stat = {0, 0, 0, 0, 0, 0, 0, 0, 0}; uint16_t j = gr->glyph.gid; if (depth >= 0xFF) return stat; @@ -96,8 +96,7 @@ void caryll_stat_glyf(caryll_font *font) { gr.b = 0; gr.c = 0; gr.d = 1; - glyf_glyph_stat thatstat = font->glyf->glyphs[j]->stat = - stat_single_glyph(font->glyf, &gr, stated, 0, j); + glyf_glyph_stat thatstat = font->glyf->glyphs[j]->stat = stat_single_glyph(font->glyf, &gr, stated, 0, j); if (thatstat.xMin < xmin) xmin = thatstat.xMin; if (thatstat.xMax > xmax) xmax = thatstat.xMax; if (thatstat.yMin < ymin) ymin = thatstat.yMin; @@ -124,10 +123,8 @@ void caryll_stat_maxp(caryll_font *font) { if (g->stat.nPoints > nPoints) nPoints = g->stat.nPoints; if (g->stat.nContours > nContours) nContours = g->stat.nContours; } else if (g->numberOfReferences > 0) { - if (g->stat.nCompositePoints > nCompositePoints) - nCompositePoints = g->stat.nCompositePoints; - if (g->stat.nCompositeContours > nCompositeContours) - nCompositeContours = g->stat.nCompositeContours; + if (g->stat.nCompositePoints > nCompositePoints) nCompositePoints = g->stat.nCompositePoints; + if (g->stat.nCompositeContours > nCompositeContours) nCompositeContours = g->stat.nCompositeContours; if (g->stat.nestDepth > nestDepth) nestDepth = g->stat.nestDepth; if (g->numberOfReferences > nComponents) nComponents = g->numberOfReferences; } @@ -148,8 +145,7 @@ void caryll_font_stat_hmtx(caryll_font *font) { if (!hmtx) return; uint16_t count_a = font->glyf->numberGlyphs; while (count_a > 2 && - font->glyf->glyphs[count_a - 1]->advanceWidth == - font->glyf->glyphs[count_a - 2]->advanceWidth) { + font->glyf->glyphs[count_a - 1]->advanceWidth == font->glyf->glyphs[count_a - 2]->advanceWidth) { count_a--; } int16_t count_k = font->glyf->numberGlyphs - count_a; @@ -178,8 +174,7 @@ void caryll_font_stat_hmtx(caryll_font *font) { if (advanceWidth > maxWidth) maxWidth = advanceWidth; if (lsb < minLSB) minLSB = lsb; if (rsb < minRSB) minRSB = rsb; - if (font->glyf->glyphs[j]->stat.xMax > maxExtent) - maxExtent = font->glyf->glyphs[j]->stat.xMax; + if (font->glyf->glyphs[j]->stat.xMax > maxExtent) maxExtent = font->glyf->glyphs[j]->stat.xMax; } font->hhea->numberOfMetrics = count_a; font->hhea->minLeftSideBearing = minLSB; @@ -194,8 +189,7 @@ void caryll_font_stat_vmtx(caryll_font *font) { if (!vmtx) return; uint16_t count_a = font->glyf->numberGlyphs; while (count_a > 2 && - font->glyf->glyphs[count_a - 1]->advanceHeight == - font->glyf->glyphs[count_a - 2]->advanceHeight) { + font->glyf->glyphs[count_a - 1]->advanceHeight == font->glyf->glyphs[count_a - 2]->advanceHeight) { count_a--; } int16_t count_k = font->glyf->numberGlyphs - count_a; @@ -224,9 +218,7 @@ void caryll_font_stat_vmtx(caryll_font *font) { if (advanceHeight > maxHeight) maxHeight = advanceHeight; if (tsb < minTSB) minTSB = tsb; if (bsb < minBSB) minBSB = bsb; - if (g->verticalOrigin - g->stat.yMin > maxExtent) { - maxExtent = g->verticalOrigin - g->stat.yMin; - } + if (g->verticalOrigin - g->stat.yMin > maxExtent) { maxExtent = g->verticalOrigin - g->stat.yMin; } } font->vhea->numOfLongVerMetrics = count_a; font->vhea->minTop = minTSB; @@ -254,16 +246,15 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0x0080 && u <= 0x00FF)) { u1 |= (1 << 1); } if ((u >= 0x0100 && u <= 0x017F)) { u1 |= (1 << 2); } if ((u >= 0x0180 && u <= 0x024F)) { u1 |= (1 << 3); } - if ((u >= 0x0250 && u <= 0x02AF) || (u >= 0x1D00 && u <= 0x1D7F) || - (u >= 0x1D80 && u <= 0x1DBF)) { + if ((u >= 0x0250 && u <= 0x02AF) || (u >= 0x1D00 && u <= 0x1D7F) || (u >= 0x1D80 && u <= 0x1DBF)) { u1 |= (1 << 4); } if ((u >= 0x02B0 && u <= 0x02FF) || (u >= 0xA700 && u <= 0xA71F)) { u1 |= (1 << 5); } if ((u >= 0x0300 && u <= 0x036F) || (u >= 0x1DC0 && u <= 0x1DFF)) { u1 |= (1 << 6); } if ((u >= 0x0370 && u <= 0x03FF)) { u1 |= (1 << 7); } if ((u >= 0x2C80 && u <= 0x2CFF)) { u1 |= (1 << 8); } - if ((u >= 0x0400 && u <= 0x04FF) || (u >= 0x0500 && u <= 0x052F) || - (u >= 0x2DE0 && u <= 0x2DFF) || (u >= 0xA640 && u <= 0xA69F)) { + if ((u >= 0x0400 && u <= 0x04FF) || (u >= 0x0500 && u <= 0x052F) || (u >= 0x2DE0 && u <= 0x2DFF) || + (u >= 0xA640 && u <= 0xA69F)) { u1 |= (1 << 9); } if ((u >= 0x0530 && u <= 0x058F)) { u1 |= (1 << 10); } @@ -285,8 +276,7 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0x10A0 && u <= 0x10FF) || (u >= 0x2D00 && u <= 0x2D2F)) { u1 |= (1 << 26); } if ((u >= 0x1B00 && u <= 0x1B7F)) { u1 |= (1 << 27); } if ((u >= 0x1100 && u <= 0x11FF)) { u1 |= (1 << 28); } - if ((u >= 0x1E00 && u <= 0x1EFF) || (u >= 0x2C60 && u <= 0x2C7F) || - (u >= 0xA720 && u <= 0xA7FF)) { + if ((u >= 0x1E00 && u <= 0x1EFF) || (u >= 0x2C60 && u <= 0x2C7F) || (u >= 0xA720 && u <= 0xA7FF)) { u1 |= (1 << 29); } if ((u >= 0x1F00 && u <= 0x1FFF)) { u1 |= (1 << 30); } @@ -296,12 +286,12 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0x20D0 && u <= 0x20FF)) { u2 |= (1 << 2); } if ((u >= 0x2100 && u <= 0x214F)) { u2 |= (1 << 3); } if ((u >= 0x2150 && u <= 0x218F)) { u2 |= (1 << 4); } - if ((u >= 0x2190 && u <= 0x21FF) || (u >= 0x27F0 && u <= 0x27FF) || - (u >= 0x2900 && u <= 0x297F) || (u >= 0x2B00 && u <= 0x2BFF)) { + if ((u >= 0x2190 && u <= 0x21FF) || (u >= 0x27F0 && u <= 0x27FF) || (u >= 0x2900 && u <= 0x297F) || + (u >= 0x2B00 && u <= 0x2BFF)) { u2 |= (1 << 5); } - if ((u >= 0x2200 && u <= 0x22FF) || (u >= 0x2A00 && u <= 0x2AFF) || - (u >= 0x27C0 && u <= 0x27EF) || (u >= 0x2980 && u <= 0x29FF)) { + if ((u >= 0x2200 && u <= 0x22FF) || (u >= 0x2A00 && u <= 0x2AFF) || (u >= 0x27C0 && u <= 0x27EF) || + (u >= 0x2980 && u <= 0x29FF)) { u2 |= (1 << 6); } if ((u >= 0x2300 && u <= 0x23FF)) { u2 |= (1 << 7); } @@ -324,15 +314,13 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0xAC00 && u <= 0xD7AF)) { u2 |= (1 << 24); } if ((u >= 0xD800 && u <= 0xDFFF) || u > 0xFFFF) { u2 |= (1 << 25); } if ((u >= 0x10900 && u <= 0x1091F)) { u2 |= (1 << 26); } - if ((u >= 0x4E00 && u <= 0x9FFF) || (u >= 0x2E80 && u <= 0x2EFF) || - (u >= 0x2F00 && u <= 0x2FDF) || (u >= 0x2FF0 && u <= 0x2FFF) || - (u >= 0x3400 && u <= 0x4DBF) || (u >= 0x20000 && u <= 0x2F7FF) || + if ((u >= 0x4E00 && u <= 0x9FFF) || (u >= 0x2E80 && u <= 0x2EFF) || (u >= 0x2F00 && u <= 0x2FDF) || + (u >= 0x2FF0 && u <= 0x2FFF) || (u >= 0x3400 && u <= 0x4DBF) || (u >= 0x20000 && u <= 0x2F7FF) || (u >= 0x3190 && u <= 0x319F)) { u2 |= (1 << 27); } if ((u >= 0xE000 && u <= 0xF8FF)) { u2 |= (1 << 28); } - if ((u >= 0x31C0 && u <= 0x31EF) || (u >= 0xF900 && u <= 0xFAFF) || - (u >= 0x2F800 && u <= 0x2FA1F)) { + if ((u >= 0x31C0 && u <= 0x31EF) || (u >= 0xF900 && u <= 0xFAFF) || (u >= 0x2F800 && u <= 0x2FA1F)) { u2 |= (1 << 29); } if ((u >= 0xFB00 && u <= 0xFB4F)) { u2 |= (1 << 30); } @@ -348,8 +336,7 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0x0780 && u <= 0x07BF)) { u3 |= (1 << 8); } if ((u >= 0x0D80 && u <= 0x0DFF)) { u3 |= (1 << 9); } if ((u >= 0x1000 && u <= 0x109F)) { u3 |= (1 << 10); } - if ((u >= 0x1200 && u <= 0x137F) || (u >= 0x1380 && u <= 0x139F) || - (u >= 0x2D80 && u <= 0x2DDF)) { + if ((u >= 0x1200 && u <= 0x137F) || (u >= 0x1380 && u <= 0x139F) || (u >= 0x2D80 && u <= 0x2DDF)) { u3 |= (1 << 11); } if ((u >= 0x13A0 && u <= 0x13FF)) { u3 |= (1 << 12); } @@ -360,15 +347,14 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0x1800 && u <= 0x18AF)) { u3 |= (1 << 17); } if ((u >= 0x2800 && u <= 0x28FF)) { u3 |= (1 << 18); } if ((u >= 0xA000 && u <= 0xA48F) || (u >= 0xA490 && u <= 0xA4CF)) { u3 |= (1 << 19); } - if ((u >= 0x1700 && u <= 0x171F) || (u >= 0x1720 && u <= 0x173F) || - (u >= 0x1740 && u <= 0x175F) || (u >= 0x1760 && u <= 0x177F)) { + if ((u >= 0x1700 && u <= 0x171F) || (u >= 0x1720 && u <= 0x173F) || (u >= 0x1740 && u <= 0x175F) || + (u >= 0x1760 && u <= 0x177F)) { u3 |= (1 << 20); } if ((u >= 0x10300 && u <= 0x1032F)) { u3 |= (1 << 21); } if ((u >= 0x10330 && u <= 0x1034F)) { u3 |= (1 << 22); } if ((u >= 0x10400 && u <= 0x1044F)) { u3 |= (1 << 23); } - if ((u >= 0x1D000 && u <= 0x1D0FF) || (u >= 0x1D100 && u <= 0x1D1FF) || - (u >= 0x1D200 && u <= 0x1D24F)) { + if ((u >= 0x1D000 && u <= 0x1D0FF) || (u >= 0x1D100 && u <= 0x1D1FF) || (u >= 0x1D200 && u <= 0x1D24F)) { u3 |= (1 << 24); } if ((u >= 0x1D400 && u <= 0x1D7FF)) { u3 |= (1 << 25); } @@ -383,8 +369,7 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0x2D30 && u <= 0x2D7F)) { u4 |= (1 << 2); } if ((u >= 0x4DC0 && u <= 0x4DFF)) { u4 |= (1 << 3); } if ((u >= 0xA800 && u <= 0xA82F)) { u4 |= (1 << 4); } - if ((u >= 0x10000 && u <= 0x1007F) || (u >= 0x10080 && u <= 0x100FF) || - (u >= 0x10100 && u <= 0x1013F)) { + if ((u >= 0x10000 && u <= 0x1007F) || (u >= 0x10080 && u <= 0x100FF) || (u >= 0x10100 && u <= 0x1013F)) { u4 |= (1 << 5); } if ((u >= 0x10140 && u <= 0x1018F)) { u4 |= (1 << 6); } @@ -406,8 +391,7 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if ((u >= 0xAA00 && u <= 0xAA5F)) { u4 |= (1 << 22); } if ((u >= 0x10190 && u <= 0x101CF)) { u4 |= (1 << 23); } if ((u >= 0x101D0 && u <= 0x101FF)) { u4 |= (1 << 24); } - if ((u >= 0x102A0 && u <= 0x102DF) || (u >= 0x10280 && u <= 0x1029F) || - (u >= 0x10920 && u <= 0x1093F)) { + if ((u >= 0x102A0 && u <= 0x102DF) || (u >= 0x10280 && u <= 0x1029F) || (u >= 0x10920 && u <= 0x1093F)) { u4 |= (1 << 25); } if ((u >= 0x1F030 && u <= 0x1F09F) || (u >= 0x1F000 && u <= 0x1F02F)) { u4 |= (1 << 26); } @@ -429,9 +413,7 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_dump_options *dumpopts) { if (!dumpopts->keep_average_char_width) { uint32_t totalWidth = 0; - for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { - totalWidth += font->glyf->glyphs[j]->advanceWidth; - } + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { totalWidth += font->glyf->glyphs[j]->advanceWidth; } font->OS_2->xAvgCharWidth = totalWidth / font->glyf->numberGlyphs; } } @@ -440,9 +422,7 @@ static void caryll_stat_cff_widths(caryll_font *font) { // Stat the most frequent character width uint32_t *frequency = calloc(2000, sizeof(uint32_t)); for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { - if (font->glyf->glyphs[j]->advanceWidth < 2000) { - frequency[font->glyf->glyphs[j]->advanceWidth] += 1; - } + if (font->glyf->glyphs[j]->advanceWidth < 2000) { frequency[font->glyf->glyphs[j]->advanceWidth] += 1; } } uint16_t maxfreq = 0; uint16_t maxj = 0; @@ -466,8 +446,7 @@ static void caryll_stat_cff_widths(caryll_font *font) { if (font->CFF_->fdArray) { for (uint16_t j = 0; j < font->CFF_->fdArrayCount; j++) { font->CFF_->fdArray[j]->privateDict->defaultWidthX = maxj; - font->CFF_->fdArray[j]->privateDict->nominalWidthX = - font->CFF_->privateDict->nominalWidthX; + font->CFF_->fdArray[j]->privateDict->nominalWidthX = font->CFF_->privateDict->nominalWidthX; } } } @@ -475,9 +454,7 @@ static void caryll_stat_cff_widths(caryll_font *font) { void caryll_font_stat(caryll_font *font, caryll_dump_options *dumpopts) { if (font->glyf && font->head) { caryll_stat_glyf(font); - if (!dumpopts->keep_modified_time) { - font->head->modified = 2082844800 + (int64_t)time(NULL); - } + if (!dumpopts->keep_modified_time) { font->head->modified = 2082844800 + (int64_t)time(NULL); } } if (font->head && font->CFF_) { font->CFF_->fontBBoxBottom = font->head->yMin; diff --git a/lib/fontops/unconsolidate.c b/lib/fontops/unconsolidate.c index b47c716f..3ff4209d 100644 --- a/lib/fontops/unconsolidate.c +++ b/lib/fontops/unconsolidate.c @@ -28,9 +28,7 @@ static void caryll_name_glyphs(caryll_font *font, caryll_dump_options *dumpopts) // pass 2: Map to `post` names if (font->post != NULL && font->post->post_name_map != NULL) { glyph_order_entry *s; - foreach_hash(s, *font->post->post_name_map) { - try_name_glyph(glyph_order, s->gid, sdsdup(s->name)); - } + foreach_hash(s, *font->post->post_name_map) { try_name_glyph(glyph_order, s->gid, sdsdup(s->name)); } } // pass 3: Map to AGLFN & Unicode if (font->cmap != NULL) { @@ -75,9 +73,7 @@ static void caryll_name_glyphs(caryll_font *font, caryll_dump_options *dumpopts) static void caryll_name_cmap_entries(caryll_font *font) { if (font->glyph_order != NULL && font->cmap != NULL) { cmap_entry *s; - foreach_hash(s, *font->cmap) { - lookup_name(font->glyph_order, s->glyph.gid, &s->glyph.name); - } + foreach_hash(s, *font->cmap) { lookup_name(font->glyph_order, s->glyph.gid, &s->glyph.name); } } } static void caryll_name_glyf(caryll_font *font) { @@ -87,8 +83,7 @@ static void caryll_name_glyf(caryll_font *font) { lookup_name(font->glyph_order, j, &g->name); if (g->numberOfReferences > 0 && g->references != NULL) { for (uint16_t k = 0; k < g->numberOfReferences; k++) { - lookup_name(font->glyph_order, g->references[k].glyph.gid, - &g->references[k].glyph.name); + lookup_name(font->glyph_order, g->references[k].glyph.gid, &g->references[k].glyph.name); } } } @@ -145,9 +140,7 @@ static void unconsolidate_gsub_reverse(caryll_font *font, otl_lookup *lookup, ta for (uint16_t j = 0; j < lookup->subtableCount; j++) if (lookup->subtables[j]) { subtable_gsub_reverse *subtable = &(lookup->subtables[j]->gsub_reverse); - for (uint16_t j = 0; j < subtable->matchCount; j++) { - name_coverage(font, subtable->match[j]); - } + for (uint16_t j = 0; j < subtable->matchCount; j++) { name_coverage(font, subtable->match[j]); } name_coverage(font, subtable->to); } } @@ -166,8 +159,7 @@ static void name_lookup(caryll_font *font, otl_lookup *lookup, table_otl *table) for (uint16_t j = 0; j < lookup->subtableCount; j++) if (lookup->subtables[j]) { name_coverage(font, lookup->subtables[j]->gsub_multi.from); - for (uint16_t k = 0; k < lookup->subtables[j]->gsub_multi.from->numGlyphs; - k++) { + for (uint16_t k = 0; k < lookup->subtables[j]->gsub_multi.from->numGlyphs; k++) { name_coverage(font, lookup->subtables[j]->gsub_multi.to[k]); } } @@ -176,8 +168,7 @@ static void name_lookup(caryll_font *font, otl_lookup *lookup, table_otl *table) for (uint16_t j = 0; j < lookup->subtableCount; j++) if (lookup->subtables[j]) { name_coverage(font, lookup->subtables[j]->gsub_ligature.to); - for (uint16_t k = 0; k < lookup->subtables[j]->gsub_ligature.to->numGlyphs; - k++) { + for (uint16_t k = 0; k < lookup->subtables[j]->gsub_ligature.to->numGlyphs; k++) { name_coverage(font, lookup->subtables[j]->gsub_ligature.from[k]); } } @@ -191,9 +182,7 @@ static void name_lookup(caryll_font *font, otl_lookup *lookup, table_otl *table) break; case otl_type_gpos_single: for (uint16_t j = 0; j < lookup->subtableCount; j++) - if (lookup->subtables[j]) { - name_coverage(font, lookup->subtables[j]->gpos_single.coverage); - } + if (lookup->subtables[j]) { name_coverage(font, lookup->subtables[j]->gpos_single.coverage); } break; case otl_type_gpos_pair: for (uint16_t j = 0; j < lookup->subtableCount; j++) @@ -204,9 +193,7 @@ static void name_lookup(caryll_font *font, otl_lookup *lookup, table_otl *table) break; case otl_type_gpos_cursive: for (uint16_t j = 0; j < lookup->subtableCount; j++) - if (lookup->subtables[j]) { - name_coverage(font, lookup->subtables[j]->gpos_cursive.coverage); - } + if (lookup->subtables[j]) { name_coverage(font, lookup->subtables[j]->gpos_cursive.coverage); } break; case otl_type_gpos_mark_to_base: case otl_type_gpos_mark_to_mark: @@ -252,8 +239,7 @@ static void merge_hmtx(caryll_font *font) { if (font->hhea && font->hmtx && font->glyf) { uint32_t count_a = font->hhea->numberOfMetrics; for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { - font->glyf->glyphs[j]->advanceWidth = - font->hmtx->metrics[(j < count_a ? j : count_a - 1)].advanceWidth; + font->glyf->glyphs[j]->advanceWidth = font->hmtx->metrics[(j < count_a ? j : count_a - 1)].advanceWidth; } } } @@ -262,11 +248,9 @@ static void merge_vmtx(caryll_font *font) { if (font->vhea && font->vmtx && font->glyf) { uint32_t count_a = font->vhea->numOfLongVerMetrics; for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { - font->glyf->glyphs[j]->advanceHeight = - font->vmtx->metrics[(j < count_a ? j : count_a - 1)].advanceHeight; + font->glyf->glyphs[j]->advanceHeight = font->vmtx->metrics[(j < count_a ? j : count_a - 1)].advanceHeight; if (j < count_a) { - font->glyf->glyphs[j]->verticalOrigin = - font->vmtx->metrics[j].tsb + font->glyf->glyphs[j]->stat.yMax; + font->glyf->glyphs[j]->verticalOrigin = font->vmtx->metrics[j].tsb + font->glyf->glyphs[j]->stat.yMax; } else { font->glyf->glyphs[j]->verticalOrigin = font->vmtx->topSideBearing[j - count_a] + font->glyf->glyphs[j]->stat.yMax; diff --git a/lib/libcff/cff-charset.c b/lib/libcff/cff-charset.c index f212c2ef..bfb304d3 100644 --- a/lib/libcff/cff-charset.c +++ b/lib/libcff/cff-charset.c @@ -17,8 +17,7 @@ void parse_charset(uint8_t *data, int32_t offset, uint16_t nchars, CFF_Charset * charsets->s = nchars - 1; charsets->f0.glyph = calloc(nchars - 1, sizeof(uint16_t)); - for (i = 0; i < charsets->s; i++) - charsets->f0.glyph[i] = gu2(data, offset + 1 + i * 2); + for (i = 0; i < charsets->s; i++) charsets->f0.glyph[i] = gu2(data, offset + 1 + i * 2); } break; case 1: @@ -75,8 +74,7 @@ caryll_buffer *compile_charset(CFF_Charset cset) { blob->data = calloc(blob->size, sizeof(uint8_t)); blob->data[0] = 0; for (uint32_t i = 0; i < cset.s; i++) - blob->data[1 + 2 * i] = cset.f0.glyph[i] / 256, - blob->data[2 + 2 * i] = cset.f0.glyph[i] % 256; + blob->data[1 + 2 * i] = cset.f0.glyph[i] / 256, blob->data[2 + 2 * i] = cset.f0.glyph[i] % 256; blob->cursor = blob->size; return blob; } diff --git a/lib/libcff/cff-codecs.c b/lib/libcff/cff-codecs.c index b4f1fd85..66854db6 100644 --- a/lib/libcff/cff-codecs.c +++ b/lib/libcff/cff-codecs.c @@ -40,8 +40,7 @@ caryll_buffer *encode_cff_number(int32_t val) { return bufninit(3, 28, val >> 8, val & 0xff); } else { /* In dict data we have 4 byte ints, in type2 strings we don't */ - return bufninit(5, 29, (val >> 24) & 0xff, (val >> 16) & 0xff, (val >> 8) & 0xff, - val & 0xff); + return bufninit(5, 29, (val >> 24) & 0xff, (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff); } } @@ -101,9 +100,7 @@ caryll_buffer *encode_cff_real(double val) { array[j++] = 0x0e, i++; } - for (i = 1; i < blob->size; i++) { - blob->data[i] = array[(i - 1) * 2] * 16 + array[(i - 1) * 2 + 1]; - } + for (i = 1; i < blob->size; i++) { blob->data[i] = array[(i - 1) * 2] * 16 + array[(i - 1) * 2 + 1]; } free(array); } @@ -202,8 +199,7 @@ static uint32_t cff_dec_i(uint8_t *start, CFF_Value *val) { } static const int nibble_attr[15] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 1}; -static const char *nibble_symb[15] = {"0", "1", "2", "3", "4", "5", "6", "7", - "8", "9", ".", "E", "E-", "", "-"}; +static const char *nibble_symb[15] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "E", "E-", "", "-"}; // decode double static uint32_t cff_dec_r(uint8_t *start, CFF_Value *val) { @@ -287,37 +283,31 @@ static uint32_t cff_dec_e(uint8_t *start, CFF_Value *val) { } static uint32_t (*_de_t2[256])(uint8_t *, CFF_Value *) = { - cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, - cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, - cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_e, cff_dec_e, - cff_dec_e, cff_dec_e, cff_dec_e, cff_dec_e, cff_dec_i, cff_dec_i, cff_dec_r, cff_dec_e, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, - cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_e}; + cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, + cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, cff_dec_o, + cff_dec_o, cff_dec_o, cff_dec_e, cff_dec_e, cff_dec_e, cff_dec_e, cff_dec_e, cff_dec_e, cff_dec_i, cff_dec_i, + cff_dec_r, cff_dec_e, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, + cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_e}; uint32_t decode_cff_token(uint8_t *start, CFF_Value *val) { return _de_t2[*start](start, val); } diff --git a/lib/libcff/cff-dict.c b/lib/libcff/cff-dict.c index 132632b6..6f5c9e06 100644 --- a/lib/libcff/cff-dict.c +++ b/lib/libcff/cff-dict.c @@ -53,8 +53,7 @@ CFF_Dict *parse_dict(uint8_t *data, uint32_t len) { } void parse_dict_callback(uint8_t *data, uint32_t len, void *context, - void (*callback)(uint32_t op, uint8_t top, CFF_Value *stack, - void *context)) { + void (*callback)(uint32_t op, uint8_t top, CFF_Value *stack, void *context)) { uint8_t index = 0; uint32_t advance; CFF_Value val, stack[256]; diff --git a/lib/libcff/cff-dict.h b/lib/libcff/cff-dict.h index 810a6013..97f512cc 100644 --- a/lib/libcff/cff-dict.h +++ b/lib/libcff/cff-dict.h @@ -24,8 +24,7 @@ void esrap_dict(CFF_Dict *d); CFF_Dict *parse_dict(uint8_t *data, uint32_t len); void parse_dict_callback(uint8_t *data, uint32_t len, void *context, - void (*callback)(uint32_t op, uint8_t top, CFF_Value *stack, - void *context)); + void (*callback)(uint32_t op, uint8_t top, CFF_Value *stack, void *context)); CFF_Value parse_dict_key(uint8_t *data, uint32_t len, uint32_t op, uint32_t idx); caryll_buffer *compile_dict(CFF_Dict *dict); diff --git a/lib/libcff/cff-fdselect.c b/lib/libcff/cff-fdselect.c index 583726ee..f1e9e143 100644 --- a/lib/libcff/cff-fdselect.c +++ b/lib/libcff/cff-fdselect.c @@ -55,8 +55,7 @@ void parse_fdselect(uint8_t *data, int32_t offset, uint16_t nchars, CFF_FDSelect fdselect->s = nchars - 1; fdselect->f0.fds = calloc(nchars - 1, sizeof(uint8_t)); - for (uint32_t i = 0; i < nchars - 1; i++) - fdselect->f0.fds[i] = gu1(data, offset + 1 + i); + for (uint32_t i = 0; i < nchars - 1; i++) fdselect->f0.fds[i] = gu1(data, offset + 1 + i); } break; case 3: diff --git a/lib/libcff/cff-index.c b/lib/libcff/cff-index.c index d732c1d1..8a03634b 100644 --- a/lib/libcff/cff-index.c +++ b/lib/libcff/cff-index.c @@ -64,8 +64,7 @@ void parse_index(uint8_t *data, uint32_t pos, CFF_Index *in) { } } -CFF_Index *cff_buildindex_callback(void *context, uint32_t length, - caryll_buffer *(*fn)(void *, uint32_t)) { +CFF_Index *cff_buildindex_callback(void *context, uint32_t length, caryll_buffer *(*fn)(void *, uint32_t)) { CFF_Index *idx = cff_index_init(); idx->count = length; NEW_N(idx->offset, idx->count + 1); @@ -142,8 +141,7 @@ caryll_buffer *compile_index(CFF_Index index) { } if (index.data != NULL) - memcpy(blob->data + 3 + ((index.count + 1) * index.offSize), index.data, - index.offset[index.count] - 1); + memcpy(blob->data + 3 + ((index.count + 1) * index.offSize), index.data, index.offset[index.count] - 1); } blob->cursor = blob->size; return blob; diff --git a/lib/libcff/cff-index.h b/lib/libcff/cff-index.h index 3e244dad..30546a59 100644 --- a/lib/libcff/cff-index.h +++ b/lib/libcff/cff-index.h @@ -25,8 +25,7 @@ uint32_t count_index(CFF_Index i); void parse_index(uint8_t *data, uint32_t pos, CFF_Index *in); -CFF_Index *cff_buildindex_callback(void *context, uint32_t length, - caryll_buffer *(*fn)(void *, uint32_t)); +CFF_Index *cff_buildindex_callback(void *context, uint32_t length, caryll_buffer *(*fn)(void *, uint32_t)); caryll_buffer *compile_index(CFF_Index index); diff --git a/lib/libcff/cff-parser.c b/lib/libcff/cff-parser.c index 20dcb4b5..b5ef5029 100644 --- a/lib/libcff/cff-parser.c +++ b/lib/libcff/cff-parser.c @@ -29,8 +29,7 @@ static void parse_encoding(CFF_File *cff, int32_t offset, CFF_Encoding *enc) { enc->f0.ncodes = data[offset + 1]; enc->f0.code = calloc(enc->f0.ncodes, sizeof(uint8_t)); - for (uint32_t i = 0; i < enc->f0.ncodes; i++) - enc->f0.code[i] = data[offset + 2 + i]; + for (uint32_t i = 0; i < enc->f0.ncodes; i++) enc->f0.code[i] = data[offset + 2 + i]; } break; case 1: @@ -80,8 +79,7 @@ static void parse_cff_bytecode(CFF_File *cff) { /** LINT CFF FONTSET **/ if (cff->name.count != cff->top_dict.count) - fprintf(stderr, "[libcff] Bad CFF font: (%d, name), (%d, top_dict).\n", cff->name.count, - cff->top_dict.count); + fprintf(stderr, "[libcff] Bad CFF font: (%d, name), (%d, top_dict).\n", cff->name.count, cff->top_dict.count); /* String INDEX */ pos = 4 + count_index(cff->name) + count_index(cff->top_dict); @@ -100,9 +98,7 @@ static void parse_cff_bytecode(CFF_File *cff) { /* CharStrings INDEX */ offset = - parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], - op_CharStrings, 0) - .i; + parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_CharStrings, 0).i; if (offset != -1) { parse_index(cff->raw_data, offset, &cff->char_strings); @@ -113,9 +109,8 @@ static void parse_cff_bytecode(CFF_File *cff) { } /* Encodings */ - offset = parse_dict_key(cff->top_dict.data, - cff->top_dict.offset[1] - cff->top_dict.offset[0], op_Encoding, 0) - .i; + offset = + parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_Encoding, 0).i; if (offset != -1) { parse_encoding(cff, offset, &cff->encodings); @@ -124,9 +119,7 @@ static void parse_cff_bytecode(CFF_File *cff) { } /* Charsets */ - offset = parse_dict_key(cff->top_dict.data, - cff->top_dict.offset[1] - cff->top_dict.offset[0], op_charset, 0) - .i; + offset = parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_charset, 0).i; if (offset != -1) { parse_charset(cff->raw_data, offset, cff->char_strings.count, &cff->charsets); @@ -135,9 +128,8 @@ static void parse_cff_bytecode(CFF_File *cff) { } /* FDSelect */ - offset = parse_dict_key(cff->top_dict.data, - cff->top_dict.offset[1] - cff->top_dict.offset[0], op_FDSelect, 0) - .i; + offset = + parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_FDSelect, 0).i; if (offset != -1) { parse_fdselect(cff->raw_data, offset, cff->char_strings.count, &cff->fdselect); @@ -146,9 +138,7 @@ static void parse_cff_bytecode(CFF_File *cff) { } /* Font Dict INDEX */ - offset = parse_dict_key(cff->top_dict.data, - cff->top_dict.offset[1] - cff->top_dict.offset[0], op_FDArray, 0) - .i; + offset = parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_FDArray, 0).i; if (offset != -1) { parse_index(cff->raw_data, offset, &cff->font_dict); @@ -164,13 +154,9 @@ static void parse_cff_bytecode(CFF_File *cff) { if (cff->top_dict.data != NULL) { private_len = - parse_dict_key(cff->top_dict.data, - cff->top_dict.offset[1] - cff->top_dict.offset[0], op_Private, 0) - .i; + parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_Private, 0).i; private_off = - parse_dict_key(cff->top_dict.data, - cff->top_dict.offset[1] - cff->top_dict.offset[0], op_Private, 1) - .i; + parse_dict_key(cff->top_dict.data, cff->top_dict.offset[1] - cff->top_dict.offset[0], op_Private, 1).i; } if (private_off != -1 && private_len != -1) { @@ -232,8 +218,7 @@ void CFF_close(CFF_File *file) { } } -uint8_t parse_subr(uint16_t idx, uint8_t *raw, CFF_Index fdarray, CFF_FDSelect select, - CFF_Index *subr) { +uint8_t parse_subr(uint16_t idx, uint8_t *raw, CFF_Index fdarray, CFF_FDSelect select, CFF_Index *subr) { uint8_t fd = 0; int32_t off_private, len_private; int32_t off_subr; @@ -254,11 +239,11 @@ uint8_t parse_subr(uint16_t idx, uint8_t *raw, CFF_Index fdarray, CFF_FDSelect s break; } - off_private = parse_dict_key(fdarray.data + fdarray.offset[fd] - 1, - fdarray.offset[fd + 1] - fdarray.offset[fd], op_Private, 1) + off_private = parse_dict_key(fdarray.data + fdarray.offset[fd] - 1, fdarray.offset[fd + 1] - fdarray.offset[fd], + op_Private, 1) .i; - len_private = parse_dict_key(fdarray.data + fdarray.offset[fd] - 1, - fdarray.offset[fd + 1] - fdarray.offset[fd], op_Private, 0) + len_private = parse_dict_key(fdarray.data + fdarray.offset[fd] - 1, fdarray.offset[fd + 1] - fdarray.offset[fd], + op_Private, 0) .i; if (off_private != -1 && len_private != -1) { @@ -301,23 +286,21 @@ static void reverseStack(CFF_Stack *stack, uint8_t left, uint8_t right) { static void callback_nopSetWidth(void *context, float width) {} static void callback_nopNewContour(void *context) {} static void callback_nopLineTo(void *context, float x1, float y1) {} -static void callback_nopCurveTo(void *context, float x1, float y1, float x2, float y2, float x3, - float y3) {} +static void callback_nopCurveTo(void *context, float x1, float y1, float x2, float y2, float x3, float y3) {} static void callback_nopsetHint(void *context, bool isVertical, float position, float width) {} static void callback_nopsetMask(void *context, bool isContourMask, bool *mask) { FREE(mask); } static double callback_nopgetrand(void *context) { return 0; } -#define CHECK_STACK_TOP(op, n) \ - { \ - if (stack->index < n) { \ - fprintf(stderr, "[libcff] Stack cannot provide enough parameters for %s (%04x). This " \ - "operation is ignored.\n", \ - #op, op); \ - break; \ - } \ +#define CHECK_STACK_TOP(op, n) \ + { \ + if (stack->index < n) { \ + fprintf(stderr, "[libcff] Stack cannot provide enough parameters for %s (%04x). This " \ + "operation is ignored.\n", \ + #op, op); \ + break; \ + } \ } -void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_Index lsubr, - CFF_Stack *stack, void *outline, - cff_outline_builder_interface methods) { +void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_Index lsubr, CFF_Stack *stack, + void *outline, cff_outline_builder_interface methods) { uint16_t gsubr_bias = compute_subr_bias(gsubr.count); uint16_t lsubr_bias = compute_subr_bias(lsubr.count); uint8_t *start = data; @@ -327,8 +310,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In void (*setWidth)(void *context, float width) = methods.setWidth; void (*newContour)(void *context) = methods.newContour; void (*lineTo)(void *context, float x1, float y1) = methods.lineTo; - void (*curveTo)(void *context, float x1, float y1, float x2, float y2, float x3, float y3) = - methods.curveTo; + void (*curveTo)(void *context, float x1, float y1, float x2, float y2, float x3, float y3) = methods.curveTo; void (*setHint)(void *context, bool isVertical, float position, float width) = methods.setHint; void (*setMask)(void *context, bool isContourMask, bool *mask) = methods.setMask; double (*getrand)(void *context) = methods.getrand; @@ -357,8 +339,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In for (uint16_t j = stack->index % 2; j < stack->index; j += 2) { float pos = stack->stack[j].d; float width = stack->stack[j + 1].d; - setHint(outline, (val.i == op_vstem || val.i == op_vstemhm), - pos + hintBase, width); + setHint(outline, (val.i == op_vstem || val.i == op_vstemhm), pos + hintBase, width); hintBase += pos + width; } stack->index = 0; @@ -407,8 +388,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In CHECK_STACK_TOP(op_rmoveto, 2); if (stack->index > 2) setWidth(outline, stack->stack[stack->index - 3].d); newContour(outline); - lineTo(outline, stack->stack[stack->index - 2].d, - stack->stack[stack->index - 1].d); + lineTo(outline, stack->stack[stack->index - 2].d, stack->stack[stack->index - 1].d); stack->index = 0; break; } @@ -425,8 +405,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In break; } case op_rlineto: { - for (i = 0; i < stack->index; i += 2) - lineTo(outline, stack->stack[i].d, stack->stack[i + 1].d); + for (i = 0; i < stack->index; i += 2) lineTo(outline, stack->stack[i].d, stack->stack[i + 1].d); stack->index = 0; break; } @@ -464,58 +443,54 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In } case op_rrcurveto: { for (i = 0; i < stack->index; i += 6) - curveTo(outline, stack->stack[i].d, stack->stack[i + 1].d, - stack->stack[i + 2].d, stack->stack[i + 3].d, - stack->stack[i + 4].d, stack->stack[i + 5].d); + curveTo(outline, stack->stack[i].d, stack->stack[i + 1].d, stack->stack[i + 2].d, + stack->stack[i + 3].d, stack->stack[i + 4].d, stack->stack[i + 5].d); stack->index = 0; break; } case op_rcurveline: { for (i = 0; i < stack->index - 2; i += 6) - curveTo(outline, stack->stack[i].d, stack->stack[i + 1].d, - stack->stack[i + 2].d, stack->stack[i + 3].d, - stack->stack[i + 4].d, stack->stack[i + 5].d); - lineTo(outline, stack->stack[stack->index - 2].d, - stack->stack[stack->index - 1].d); + curveTo(outline, stack->stack[i].d, stack->stack[i + 1].d, stack->stack[i + 2].d, + stack->stack[i + 3].d, stack->stack[i + 4].d, stack->stack[i + 5].d); + lineTo(outline, stack->stack[stack->index - 2].d, stack->stack[stack->index - 1].d); stack->index = 0; break; } case op_rlinecurve: { for (i = 0; i < stack->index - 6; i += 2) lineTo(outline, stack->stack[i].d, stack->stack[i + 1].d); - curveTo(outline, stack->stack[stack->index - 6].d, - stack->stack[stack->index - 5].d, stack->stack[stack->index - 4].d, - stack->stack[stack->index - 3].d, stack->stack[stack->index - 2].d, - stack->stack[stack->index - 1].d); + curveTo(outline, stack->stack[stack->index - 6].d, stack->stack[stack->index - 5].d, + stack->stack[stack->index - 4].d, stack->stack[stack->index - 3].d, + stack->stack[stack->index - 2].d, stack->stack[stack->index - 1].d); stack->index = 0; break; } case op_vvcurveto: { if (stack->index % 4 == 1) { - curveTo(outline, stack->stack[0].d, stack->stack[1].d, - stack->stack[2].d, stack->stack[3].d, 0.0, stack->stack[4].d); + curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, stack->stack[3].d, + 0.0, stack->stack[4].d); for (i = 5; i < stack->index; i += 4) - curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, - stack->stack[i + 2].d, 0.0, stack->stack[i + 3].d); + curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, stack->stack[i + 2].d, + 0.0, stack->stack[i + 3].d); } else { for (i = 0; i < stack->index; i += 4) - curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, - stack->stack[i + 2].d, 0.0, stack->stack[i + 3].d); + curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, stack->stack[i + 2].d, + 0.0, stack->stack[i + 3].d); } stack->index = 0; break; } case op_hhcurveto: { if (stack->index % 4 == 1) { - curveTo(outline, stack->stack[1].d, stack->stack[0].d, - stack->stack[2].d, stack->stack[3].d, stack->stack[4].d, 0.0); + curveTo(outline, stack->stack[1].d, stack->stack[0].d, stack->stack[2].d, stack->stack[3].d, + stack->stack[4].d, 0.0); for (i = 5; i < stack->index; i += 4) - curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, - stack->stack[i + 2].d, stack->stack[i + 3].d, 0.0); + curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, stack->stack[i + 2].d, + stack->stack[i + 3].d, 0.0); } else { for (i = 0; i < stack->index; i += 4) - curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, - stack->stack[i + 2].d, stack->stack[i + 3].d, 0.0); + curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, stack->stack[i + 2].d, + stack->stack[i + 3].d, 0.0); } stack->index = 0; break; @@ -528,23 +503,21 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In for (i = 0; i < 4 * cnt_bezier; i += 4) { if ((i / 4) % 2 == 0) - curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, - stack->stack[i + 2].d, stack->stack[i + 3].d, 0.0); + curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, stack->stack[i + 2].d, + stack->stack[i + 3].d, 0.0); else - curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, - stack->stack[i + 2].d, 0.0, stack->stack[i + 3].d); + curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, stack->stack[i + 2].d, + 0.0, stack->stack[i + 3].d); } if (stack->index % 8 == 5) { - curveTo( - outline, 0.0, stack->stack[stack->index - 5].d, - stack->stack[stack->index - 4].d, stack->stack[stack->index - 3].d, - stack->stack[stack->index - 2].d, stack->stack[stack->index - 1].d); + curveTo(outline, 0.0, stack->stack[stack->index - 5].d, stack->stack[stack->index - 4].d, + stack->stack[stack->index - 3].d, stack->stack[stack->index - 2].d, + stack->stack[stack->index - 1].d); } if (stack->index % 8 == 1) { - curveTo( - outline, stack->stack[stack->index - 5].d, 0.0, - stack->stack[stack->index - 4].d, stack->stack[stack->index - 3].d, - stack->stack[stack->index - 1].d, stack->stack[stack->index - 2].d); + curveTo(outline, stack->stack[stack->index - 5].d, 0.0, stack->stack[stack->index - 4].d, + stack->stack[stack->index - 3].d, stack->stack[stack->index - 1].d, + stack->stack[stack->index - 2].d); } stack->index = 0; break; @@ -557,62 +530,59 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In for (i = 0; i < 4 * cnt_bezier; i += 4) { if ((i / 4) % 2 == 0) - curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, - stack->stack[i + 2].d, 0.0, stack->stack[i + 3].d); + curveTo(outline, stack->stack[i].d, 0.0, stack->stack[i + 1].d, stack->stack[i + 2].d, + 0.0, stack->stack[i + 3].d); else - curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, - stack->stack[i + 2].d, stack->stack[i + 3].d, 0.0); + curveTo(outline, 0.0, stack->stack[i].d, stack->stack[i + 1].d, stack->stack[i + 2].d, + stack->stack[i + 3].d, 0.0); } if (stack->index % 8 == 5) { - curveTo( - outline, stack->stack[stack->index - 5].d, 0.0, - stack->stack[stack->index - 4].d, stack->stack[stack->index - 3].d, - stack->stack[stack->index - 1].d, stack->stack[stack->index - 2].d); + curveTo(outline, stack->stack[stack->index - 5].d, 0.0, stack->stack[stack->index - 4].d, + stack->stack[stack->index - 3].d, stack->stack[stack->index - 1].d, + stack->stack[stack->index - 2].d); } if (stack->index % 8 == 1) { - curveTo( - outline, 0.0, stack->stack[stack->index - 5].d, - stack->stack[stack->index - 4].d, stack->stack[stack->index - 3].d, - stack->stack[stack->index - 2].d, stack->stack[stack->index - 1].d); + curveTo(outline, 0.0, stack->stack[stack->index - 5].d, stack->stack[stack->index - 4].d, + stack->stack[stack->index - 3].d, stack->stack[stack->index - 2].d, + stack->stack[stack->index - 1].d); } stack->index = 0; break; } case op_hflex: { CHECK_STACK_TOP(op_hflex, 7); - curveTo(outline, stack->stack[0].d, 0.0, stack->stack[1].d, - stack->stack[2].d, stack->stack[3].d, 0.0); - curveTo(outline, stack->stack[4].d, 0.0, stack->stack[5].d, - -stack->stack[2].d, stack->stack[6].d, 0.0); + curveTo(outline, stack->stack[0].d, 0.0, stack->stack[1].d, stack->stack[2].d, + stack->stack[3].d, 0.0); + curveTo(outline, stack->stack[4].d, 0.0, stack->stack[5].d, -stack->stack[2].d, + stack->stack[6].d, 0.0); stack->index = 0; break; } case op_flex: { CHECK_STACK_TOP(op_flex, 12); - curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, - stack->stack[3].d, stack->stack[4].d, stack->stack[5].d); - curveTo(outline, stack->stack[6].d, stack->stack[7].d, stack->stack[8].d, - stack->stack[9].d, stack->stack[10].d, stack->stack[11].d); + curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, stack->stack[3].d, + stack->stack[4].d, stack->stack[5].d); + curveTo(outline, stack->stack[6].d, stack->stack[7].d, stack->stack[8].d, stack->stack[9].d, + stack->stack[10].d, stack->stack[11].d); stack->index = 0; break; } case op_hflex1: { CHECK_STACK_TOP(op_hflex1, 9); - curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, - stack->stack[3].d, stack->stack[4].d, 0.0); - curveTo(outline, stack->stack[5].d, 0.0, stack->stack[6].d, - stack->stack[7].d, stack->stack[8].d, - -(stack->stack[1].d + stack->stack[3].d + stack->stack[7].d)); + curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, stack->stack[3].d, + stack->stack[4].d, 0.0); + curveTo(outline, stack->stack[5].d, 0.0, stack->stack[6].d, stack->stack[7].d, + stack->stack[8].d, -(stack->stack[1].d + stack->stack[3].d + stack->stack[7].d)); stack->index = 0; break; } case op_flex1: { CHECK_STACK_TOP(op_flex1, 11); - double dx = stack->stack[0].d + stack->stack[2].d + stack->stack[4].d + - stack->stack[6].d + stack->stack[8].d; - double dy = stack->stack[1].d + stack->stack[3].d + stack->stack[5].d + - stack->stack[7].d + stack->stack[9].d; + double dx = stack->stack[0].d + stack->stack[2].d + stack->stack[4].d + stack->stack[6].d + + stack->stack[8].d; + double dy = stack->stack[1].d + stack->stack[3].d + stack->stack[5].d + stack->stack[7].d + + stack->stack[9].d; if (fabs(dx) > fabs(dy)) { dx = stack->stack[10].d; dy = -dy; @@ -620,10 +590,10 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In dx = -dx; dy = stack->stack[10].d; } - curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, - stack->stack[3].d, stack->stack[4].d, stack->stack[5].d); - curveTo(outline, stack->stack[6].d, stack->stack[7].d, stack->stack[8].d, - stack->stack[9].d, dx, dy); + curveTo(outline, stack->stack[0].d, stack->stack[1].d, stack->stack[2].d, stack->stack[3].d, + stack->stack[4].d, stack->stack[5].d); + curveTo(outline, stack->stack[6].d, stack->stack[7].d, stack->stack[8].d, stack->stack[9].d, dx, + dy); stack->index = 0; break; } @@ -709,8 +679,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In case op_get: { CHECK_STACK_TOP(op_get, 1); int32_t i = (int32_t)stack->stack[stack->index - 1].d; - stack->stack[stack->index - 1].d = - stack->transient[i % type2_transient_array].d; + stack->stack[stack->index - 1].d = stack->transient[i % type2_transient_array].d; break; } case op_ifelse: { @@ -789,8 +758,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In CHECK_STACK_TOP(op_callsubr, 1); uint32_t subr = (uint32_t)stack->stack[--(stack->index)].d; parse_outline_callback(lsubr.data + lsubr.offset[lsubr_bias + subr] - 1, - lsubr.offset[lsubr_bias + subr + 1] - - lsubr.offset[lsubr_bias + subr], + lsubr.offset[lsubr_bias + subr + 1] - lsubr.offset[lsubr_bias + subr], gsubr, lsubr, stack, outline, methods); break; } @@ -798,8 +766,7 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In CHECK_STACK_TOP(op_callgsubr, 1); uint32_t subr = (uint32_t)stack->stack[--(stack->index)].d; parse_outline_callback(gsubr.data + gsubr.offset[gsubr_bias + subr] - 1, - gsubr.offset[gsubr_bias + subr + 1] - - gsubr.offset[gsubr_bias + subr], + gsubr.offset[gsubr_bias + subr + 1] - gsubr.offset[gsubr_bias + subr], gsubr, lsubr, stack, outline, methods); break; } diff --git a/lib/libcff/cff-string.c b/lib/libcff/cff-string.c index df611e0d..6e00bacc 100644 --- a/lib/libcff/cff-string.c +++ b/lib/libcff/cff-string.c @@ -404,8 +404,7 @@ char *get_cff_sid(uint16_t idx, CFF_Index str) { if (idx >= 0 && idx <= 390) return strdup(string_standard[idx]); if (str.count > 0 && idx - 391 < str.count) { char *dup = calloc(str.offset[idx - 390] - str.offset[idx - 391] + 1, sizeof(uint8_t)); - strncpy(dup, (const char *)str.data + str.offset[idx - 391] - 1, - str.offset[idx - 390] - str.offset[idx - 391]); + strncpy(dup, (const char *)str.data + str.offset[idx - 391] - 1, str.offset[idx - 390] - str.offset[idx - 391]); return dup; } else return strdup("Unknown"); @@ -415,8 +414,7 @@ sds sdsget_cff_sid(uint16_t idx, CFF_Index str) { if (idx >= 0 && idx <= 390) { return sdsnew(string_standard[idx]); } else if (str.count > 0 && idx - 391 < str.count) { - return sdsnewlen(str.data + str.offset[idx - 391] - 1, - str.offset[idx - 390] - str.offset[idx - 391]); + return sdsnewlen(str.data + str.offset[idx - 391] - 1, str.offset[idx - 390] - str.offset[idx - 391]); } else { return NULL; } diff --git a/lib/libcff/cff-writer.c b/lib/libcff/cff-writer.c index 2cc4388b..c3630cf2 100644 --- a/lib/libcff/cff-writer.c +++ b/lib/libcff/cff-writer.c @@ -40,8 +40,7 @@ static void merge_cs2_int(caryll_buffer *blob, int32_t val) { static void merge_cs2_real(caryll_buffer *blob, double val) { int16_t integerPart = floor(val); uint16_t fractionPart = (val - integerPart) * 65536.0; - bufnwrite8(blob, 5, 0xFF, integerPart >> 8, integerPart & 0xFF, fractionPart >> 8, - fractionPart & 0xFF); + bufnwrite8(blob, 5, 0xFF, integerPart >> 8, integerPart & 0xFF, fractionPart >> 8, fractionPart & 0xFF); } void merge_cs2_operand(caryll_buffer *blob, double val) { double intpart; diff --git a/lib/libcff/charstring_il.c b/lib/libcff/charstring_il.c index 174e0bcb..42567540 100644 --- a/lib/libcff/charstring_il.c +++ b/lib/libcff/charstring_il.c @@ -38,8 +38,7 @@ static void il_lineto(charstring_il *il, float dx, float dy) { il_push_operand(il, dy); il_push_op(il, op_rlineto); } -static void il_curveto(charstring_il *il, float dx1, float dy1, float dx2, float dy2, float dx3, - float dy3) { +static void il_curveto(charstring_il *il, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) { il_push_operand(il, dx1); il_push_operand(il, dy1); il_push_operand(il, dx2); @@ -88,10 +87,10 @@ static void il_push_masks(charstring_il *il, glyf_glyph *g, // meta uint16_t *jm // index of pushed hmasks ) { if (!g->numberOfStemH && !g->numberOfStemV) return; - _il_push_maskgroup(il, g->numberOfContourMasks, g->contourMasks, points, g->numberOfStemH, - g->numberOfStemV, jh, op_cntrmask); - _il_push_maskgroup(il, g->numberOfHintMasks, g->hintMasks, points, g->numberOfStemH, - g->numberOfStemV, jm, op_hintmask); + _il_push_maskgroup(il, g->numberOfContourMasks, g->contourMasks, points, g->numberOfStemH, g->numberOfStemV, jh, + op_cntrmask); + _il_push_maskgroup(il, g->numberOfHintMasks, g->hintMasks, points, g->numberOfStemH, g->numberOfStemV, jm, + op_hintmask); } static void _il_push_stemgroup(charstring_il *il, // il seq @@ -170,10 +169,10 @@ charstring_il *compile_glyph_to_il(glyf_glyph *g, uint16_t defaultWidth, uint16_ if (contour->points[j].onCurve) { // A line-to il_lineto(il, contour->points[j].x, contour->points[j].y); pointsSofar++; - } else if (j < n - 2 // have enough points - && !contour->points[j + 1].onCurve // next is offcurve - && contour->points[j + 2].onCurve // and next is oncurve - ) { // means this is an bezier curve strand + } else if (j < n - 2 // have enough points + && !contour->points[j + 1].onCurve // next is offcurve + && contour->points[j + 2].onCurve // and next is oncurve + ) { // means this is an bezier curve strand il_curveto(il, contour->points[j].x, contour->points[j].y, // dz1 contour->points[j + 1].x, contour->points[j + 1].y, // dz2 contour->points[j + 2].x, contour->points[j + 2].y); // dz3 @@ -208,8 +207,8 @@ static uint8_t zroll(charstring_il *il, uint32_t j, int32_t op, int32_t op2, ... if (arity > 16 || j + arity >= il->length) return 0; if ((j == 0 || // We are at the beginning of charstring !il_matchtype(il, j - 1, j, - IL_ITEM_PHANTOM_OPERATOR)) // .. or we are right after a solid operator - && il_matchop(il, j + arity, op) // The next operator is + IL_ITEM_PHANTOM_OPERATOR)) // .. or we are right after a solid operator + && il_matchop(il, j + arity, op) // The next operator is && il_matchtype(il, j, j + arity, IL_ITEM_OPERAND) // And we have correct number of operands ) { va_list ap; @@ -240,8 +239,7 @@ static uint8_t zroll(charstring_il *il, uint32_t j, int32_t op, int32_t op2, ... return 0; } } -static uint8_t opop_roll(charstring_il *il, uint32_t j, int32_t op1, int32_t arity, int32_t op2, - int32_t resultop) { +static uint8_t opop_roll(charstring_il *il, uint32_t j, int32_t op1, int32_t arity, int32_t op2, int32_t resultop) { if (j + 1 + arity >= il->length) return 0; charstring_instruction *current = &(il->instr[j]); charstring_instruction *nextop = &(il->instr[j + 1 + arity]); @@ -270,7 +268,7 @@ static uint8_t hvlineto_roll(charstring_il *il, uint32_t j) { && il_matchop(il, j + 3, op_rlineto) // followed by a lineto && il_matchtype(il, j + 1, j + 3, IL_ITEM_OPERAND) // have enough operands && il->instr[j + checkdelta].d == 0 // and it is a h/v - && current->arity + 1 <= type2_argument_stack // we have enough stack space + && current->arity + 1 <= type2_argument_stack // we have enough stack space ) { il->instr[j + checkdelta].type = IL_ITEM_PHANTOM_OPERAND; il->instr[j].type = IL_ITEM_PHANTOM_OPERATOR; @@ -354,18 +352,18 @@ static uint32_t nextstop(charstring_il *il, uint32_t j) { ; return delta; } -#define ROLL_FALL(x) \ +#define ROLL_FALL(x) \ if ((r = (x))) return r; static uint8_t decideAdvance(charstring_il *il, uint32_t j, uint8_t optimizeLevel) { uint8_t r = 0; - ROLL_FALL(zroll(il, j, op_rlineto, op_hlineto, 0, 1)); // rlineto -> hlineto - ROLL_FALL(zroll(il, j, op_rlineto, op_vlineto, 1, 0)); // rlineto -> vlineto - ROLL_FALL(zroll(il, j, op_rmoveto, op_hmoveto, 0, 1)); // rmoveto -> hmoveto - ROLL_FALL(zroll(il, j, op_rmoveto, op_vmoveto, 1, 0)); // rmoveto -> vmoveto - ROLL_FALL(zroll(il, j, op_rrcurveto, op_hvcurveto, 0, 1, 0, 0, 1, 0)); // rrcurveto->hvcurveto - ROLL_FALL(zroll(il, j, op_rrcurveto, op_vhcurveto, 1, 0, 0, 0, 0, 1)); // rrcurveto->vhcurveto - ROLL_FALL(zroll(il, j, op_rrcurveto, op_hhcurveto, 0, 1, 0, 0, 0, 1)); // rrcurveto->hhcurveto - ROLL_FALL(zroll(il, j, op_rrcurveto, op_vvcurveto, 1, 0, 0, 0, 1, 0)); // rrcurveto->vvcurveto + ROLL_FALL(zroll(il, j, op_rlineto, op_hlineto, 0, 1)); // rlineto -> hlineto + ROLL_FALL(zroll(il, j, op_rlineto, op_vlineto, 1, 0)); // rlineto -> vlineto + ROLL_FALL(zroll(il, j, op_rmoveto, op_hmoveto, 0, 1)); // rmoveto -> hmoveto + ROLL_FALL(zroll(il, j, op_rmoveto, op_vmoveto, 1, 0)); // rmoveto -> vmoveto + ROLL_FALL(zroll(il, j, op_rrcurveto, op_hvcurveto, 0, 1, 0, 0, 1, 0)); // rrcurveto->hvcurveto + ROLL_FALL(zroll(il, j, op_rrcurveto, op_vhcurveto, 1, 0, 0, 0, 0, 1)); // rrcurveto->vhcurveto + ROLL_FALL(zroll(il, j, op_rrcurveto, op_hhcurveto, 0, 1, 0, 0, 0, 1)); // rrcurveto->hhcurveto + ROLL_FALL(zroll(il, j, op_rrcurveto, op_vvcurveto, 1, 0, 0, 0, 1, 0)); // rrcurveto->vvcurveto ROLL_FALL(opop_roll(il, j, op_rrcurveto, 6, op_rrcurveto, op_rrcurveto)); // rrcurveto roll ROLL_FALL(opop_roll(il, j, op_rrcurveto, 2, op_rlineto, op_rcurveline)); // rcurveline roll ROLL_FALL(opop_roll(il, j, op_rlineto, 6, op_rrcurveto, op_rlinecurve)); // rlinecurve roll @@ -374,11 +372,11 @@ static uint8_t decideAdvance(charstring_il *il, uint32_t j, uint8_t optimizeLeve ROLL_FALL(opop_roll(il, j, op_vstemhm, 0, op_hintmask, op_hintmask)); // hintmask roll ROLL_FALL(opop_roll(il, j, op_hstemhm, 0, op_cntrmask, op_cntrmask)); // cntrmask roll ROLL_FALL(opop_roll(il, j, op_vstemhm, 0, op_cntrmask, op_cntrmask)); // cntrmask roll - ROLL_FALL(hvlineto_roll(il, j)); // hlineto-vlineto roll - ROLL_FALL(hhvvcurve_roll(il, j)); // hhcurveto-vvcurveto roll - ROLL_FALL(hvvhcurve_roll(il, j)); // hvcurveto-vhcurveto roll - ROLL_FALL(nextstop(il, j)); // move to next stop for operand match - return 1; // nothing match + ROLL_FALL(hvlineto_roll(il, j)); // hlineto-vlineto roll + ROLL_FALL(hhvvcurve_roll(il, j)); // hhcurveto-vvcurveto roll + ROLL_FALL(hvvhcurve_roll(il, j)); // hvcurveto-vhcurveto roll + ROLL_FALL(nextstop(il, j)); // move to next stop for operand match + return 1; // nothing match } void glyph_il_peephole_optimization(charstring_il *il, caryll_dump_options *dumpopts) { diff --git a/lib/libcff/libcff.h b/lib/libcff/libcff.h index d0d3cc38..01360554 100644 --- a/lib/libcff/libcff.h +++ b/lib/libcff/libcff.h @@ -153,10 +153,9 @@ void merge_cs2_operator(caryll_buffer *blob, int32_t val); void merge_cs2_operand(caryll_buffer *blob, double val); void merge_cs2_special(caryll_buffer *blob, uint8_t val); -extern uint8_t parse_subr(uint16_t idx, uint8_t *raw, CFF_Index fdarray, CFF_FDSelect select, - CFF_Index *subr); -void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_Index lsubr, - CFF_Stack *stack, void *outline, cff_outline_builder_interface methods); +extern uint8_t parse_subr(uint16_t idx, uint8_t *raw, CFF_Index fdarray, CFF_FDSelect select, CFF_Index *subr); +void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_Index lsubr, CFF_Stack *stack, + void *outline, cff_outline_builder_interface methods); // File extern CFF_File *CFF_stream_open(uint8_t *data, uint32_t len); diff --git a/lib/support/base64.c b/lib/support/base64.c index 3a752db1..fcda1eb0 100644 --- a/lib/support/base64.c +++ b/lib/support/base64.c @@ -1,6 +1,5 @@ #include "base64.h" -static const uint8_t base64_table[64] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const uint8_t base64_table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; uint8_t *base64_encode(const uint8_t *src, size_t len, size_t *out_len) { uint8_t *out, *pos; diff --git a/lib/support/glyphorder.c b/lib/support/glyphorder.c index 8c7b4b8b..bf095324 100644 --- a/lib/support/glyphorder.c +++ b/lib/support/glyphorder.c @@ -64,12 +64,10 @@ static void caryll_glyphorder_from_json_order_subtable(glyph_order_hash *hash, j } static void caryll_glyphorder_from_json_order_cmap(glyph_order_hash *hash, json_value *table) { for (uint32_t j = 0; j < table->u.object.length; j++) { - sds unicodeStr = - sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); + sds unicodeStr = sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); json_value *item = table->u.object.values[j].value; int32_t unicode = atoi(unicodeStr); - if (item->type == json_string && unicode > 0 && - unicode <= 0x10FFFF) { // a valid unicode codepoint + if (item->type == json_string && unicode > 0 && unicode <= 0x10FFFF) { // a valid unicode codepoint sds gname = sdsnewlen(item->u.string.ptr, item->u.string.length); glyph_order_entry *item = NULL; HASH_FIND_STR(*hash, gname, item); @@ -91,8 +89,7 @@ static void caryll_glyphorder_from_json_order_cmap(glyph_order_hash *hash, json_ } static void caryll_glyphorder_from_json_order_glyf(glyph_order_hash *hash, json_value *table) { for (uint32_t j = 0; j < table->u.object.length; j++) { - sds gname = - sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); + sds gname = sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); glyph_order_entry *item = NULL; HASH_FIND_STR(*hash, gname, item); if (!item) { diff --git a/lib/support/ttinstr.c b/lib/support/ttinstr.c index 842ab7e0..f9e22588 100644 --- a/lib/support/ttinstr.c +++ b/lib/support/ttinstr.c @@ -299,8 +299,7 @@ static int strnmatch(const char *str1, const char *str2, int n) { return (0); } -static uint8_t *parse_instrs(char *text, int *len, void *context, - void (*IVError)(void *context, char *, int)) { +static uint8_t *parse_instrs(char *text, int *len, void *context, void (*IVError)(void *context, char *, int)) { short numberstack[256]; int npos = 0, nread, i; int push_left = 0, push_size = 0; @@ -332,8 +331,7 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, if (npos == 0) IVError(context, "Expected a number for a push count", (int)(pt - text)); else if (numberstack[0] > 255 || numberstack[0] <= 0) { - IVError(context, "The push count must be a number between 0 and 255", - (int)(pt - text)); + IVError(context, "The push count must be a number between 0 and 255", (int)(pt - text)); return (NULL); } else { nread = 1; @@ -341,8 +339,7 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, push_left = numberstack[0]; } } - if (push_left != 0 && push_left < npos - nread && - (*pt == '\r' || *pt == '\n' || *pt == '\0')) { + if (push_left != 0 && push_left < npos - nread && (*pt == '\r' || *pt == '\n' || *pt == '\0')) { IVError(context, "More pushes specified than needed", (int)(pt - text)); return (NULL); } @@ -351,8 +348,7 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, instrs[icnt++] = numberstack[nread] >> 8; instrs[icnt++] = numberstack[nread++] & 0xff; } else if (numberstack[0] > 255 || numberstack[0] < 0) { - IVError(context, "A value to be pushed by a byte push must be between 0 and 255", - (int)(pt - text)); + IVError(context, "A value to be pushed by a byte push must be between 0 and 255", (int)(pt - text)); return (NULL); } else instrs[icnt++] = numberstack[nread++]; @@ -405,9 +401,7 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, val = strtol(brack + 1, &bend, 2); /* Stuff in brackets should be in binary */ while (*bend == ' ' || *bend == '\t') ++bend; if (*bend != ']') { - IVError(context, - "Missing right bracket in command (or bad binary value in bracket)", - (int)(pt - text)); + IVError(context, "Missing right bracket in command (or bad binary value in bracket)", (int)(pt - text)); return (NULL); } if (val >= 32) { @@ -493,8 +487,7 @@ json_value *instr_to_json(uint8_t *instructions, uint32_t length, caryll_dump_op json_value *ret = json_array_new(id.instr_cnt); for (uint32_t i = 0; i < id.instr_cnt; ++i) { if (id.bts[i] == bt_wordhi) { - json_array_push( - ret, json_integer_new((int16_t)((id.instrs[i] << 8) | id.instrs[i + 1]))); + json_array_push(ret, json_integer_new((int16_t)((id.instrs[i] << 8) | id.instrs[i + 1]))); ++i; } else if (id.bts[i] == bt_cnt || id.bts[i] == bt_byte) { json_array_push(ret, json_integer_new(id.instrs[i])); @@ -513,8 +506,7 @@ void instr_from_json(json_value *col, void *context, void (*Make)(void *, uint8_ Make(context, NULL, 0); } else if (col->type == json_string) { size_t instrlen; - uint8_t *instructions = - base64_decode((uint8_t *)col->u.string.ptr, col->u.string.length, &instrlen); + uint8_t *instructions = base64_decode((uint8_t *)col->u.string.ptr, col->u.string.length, &instrlen); Make(context, instructions, (uint32_t)instrlen); } else if (col->type == json_array) { size_t istrlen = 0; diff --git a/lib/support/ttinstr.h b/lib/support/ttinstr.h index 8bc8fed0..93faa61a 100644 --- a/lib/support/ttinstr.h +++ b/lib/support/ttinstr.h @@ -4,17 +4,17 @@ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO @@ -27,7 +27,6 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #ifndef CARYLL_SUPPORT_TTINSTR_H #define CARYLL_SUPPORT_TTINSTR_H #include "util.h" @@ -166,9 +165,7 @@ struct instrdata { uint8_t *bts; }; -void instr_from_json( - json_value *col, void *context, - void (*Make)(void *, uint8_t *, uint32_t), - void (*Wrong)(void *, char *, int)); +void instr_from_json(json_value *col, void *context, void (*Make)(void *, uint8_t *, uint32_t), + void (*Wrong)(void *, char *, int)); json_value *instr_to_json(uint8_t *instructions, uint32_t length, caryll_dump_options *dumpopts); #endif diff --git a/lib/support/util.h b/lib/support/util.h index 74761345..4162976e 100644 --- a/lib/support/util.h +++ b/lib/support/util.h @@ -24,11 +24,11 @@ #define INLINE inline /* use standard inline */ #endif -#define FOR_TABLE(name, table) \ - for (int keep = 1, count = 0, __notfound = 1; __notfound && keep && count < packet.numTables; \ - keep = !keep, count++) \ - for (caryll_piece table = (packet.pieces)[count]; keep; keep = !keep) \ - if (table.tag == (name)) \ +#define FOR_TABLE(name, table) \ + for (int keep = 1, count = 0, __notfound = 1; __notfound && keep && count < packet.numTables; \ + keep = !keep, count++) \ + for (caryll_piece table = (packet.pieces)[count]; keep; keep = !keep) \ + if (table.tag == (name)) \ for (int k2 = 1; k2; k2 = 0, __notfound = 0) #define foreach_hash(id, range) for (id = (range); id != NULL; id = id->hh.next) @@ -129,9 +129,7 @@ static INLINE bool json_obj_getbool_fallback(json_value *obj, const char *key, b return fallback; } -static INLINE json_value *json_from_sds(sds str) { - return json_string_new_length((uint32_t)sdslen(str), str); -} +static INLINE json_value *json_from_sds(sds str) { return json_string_new_length((uint32_t)sdslen(str), str); } // flags reader and writer static INLINE json_value *caryll_flags_to_json(int flags, const char *labels[]) { @@ -348,8 +346,7 @@ static INLINE void *__caryll_allocate_clean(size_t n, unsigned long line) { } #ifdef __cplusplus #define NEW(ptr) ptr = (decltype(ptr))__caryll_allocate(sizeof(decltype(*ptr)), __LINE__) -#define NEW_CLEAN(ptr) \ - ptr = (decltype(ptr))__caryll_allocate_clean(sizeof(decltype(*ptr)), __LINE__) +#define NEW_CLEAN(ptr) ptr = (decltype(ptr))__caryll_allocate_clean(sizeof(decltype(*ptr)), __LINE__) #define NEW_N(ptr, n) ptr = (decltype(ptr))__caryll_allocate(sizeof(decltype(*ptr)) * (n), __LINE__) #define FREE(ptr) (free(ptr), ptr = nullptr) #define DELETE(fn, ptr) (fn(ptr), ptr = nullptr) diff --git a/lib/tables/CFF.c b/lib/tables/CFF.c index f7ec89ec..9a553140 100644 --- a/lib/tables/CFF.c +++ b/lib/tables/CFF.c @@ -73,49 +73,37 @@ static void callback_extract_private(uint32_t op, uint8_t top, CFF_Value *stack, case op_BlueValues: { pd->blueValuesCount = top; NEW_N(pd->blueValues, pd->blueValuesCount); - for (uint16_t j = 0; j < pd->blueValuesCount; j++) { - pd->blueValues[j] = cffnum(stack[j]); - } + for (uint16_t j = 0; j < pd->blueValuesCount; j++) { pd->blueValues[j] = cffnum(stack[j]); } break; } case op_OtherBlues: { pd->otherBluesCount = top; NEW_N(pd->otherBlues, pd->otherBluesCount); - for (uint16_t j = 0; j < pd->otherBluesCount; j++) { - pd->otherBlues[j] = cffnum(stack[j]); - } + for (uint16_t j = 0; j < pd->otherBluesCount; j++) { pd->otherBlues[j] = cffnum(stack[j]); } break; } case op_FamilyBlues: { pd->familyBluesCount = top; NEW_N(pd->familyBlues, pd->familyBluesCount); - for (uint16_t j = 0; j < pd->familyBluesCount; j++) { - pd->familyBlues[j] = cffnum(stack[j]); - } + for (uint16_t j = 0; j < pd->familyBluesCount; j++) { pd->familyBlues[j] = cffnum(stack[j]); } break; } case op_FamilyOtherBlues: { pd->familyOtherBluesCount = top; NEW_N(pd->familyOtherBlues, pd->familyOtherBluesCount); - for (uint16_t j = 0; j < pd->familyOtherBluesCount; j++) { - pd->familyOtherBlues[j] = cffnum(stack[j]); - } + for (uint16_t j = 0; j < pd->familyOtherBluesCount; j++) { pd->familyOtherBlues[j] = cffnum(stack[j]); } break; } case op_StemSnapH: { pd->stemSnapHCount = top; NEW_N(pd->stemSnapH, pd->stemSnapHCount); - for (uint16_t j = 0; j < pd->stemSnapHCount; j++) { - pd->stemSnapH[j] = cffnum(stack[j]); - } + for (uint16_t j = 0; j < pd->stemSnapHCount; j++) { pd->stemSnapH[j] = cffnum(stack[j]); } break; } case op_StemSnapV: { pd->stemSnapVCount = top; NEW_N(pd->stemSnapV, pd->stemSnapVCount); - for (uint16_t j = 0; j < pd->stemSnapVCount; j++) { - pd->stemSnapV[j] = cffnum(stack[j]); - } + for (uint16_t j = 0; j < pd->stemSnapVCount; j++) { pd->stemSnapV[j] = cffnum(stack[j]); } break; } // Numbers @@ -225,8 +213,7 @@ static void callback_extract_fd(uint32_t op, uint8_t top, CFF_Value *stack, void uint32_t privateLength = cffnum(stack[top - 2]); uint32_t privateOffset = cffnum(stack[top - 1]); meta->privateDict = caryll_new_CFF_private(); - parse_dict_callback(file->raw_data + privateOffset, privateLength, context, - callback_extract_private); + parse_dict_callback(file->raw_data + privateOffset, privateLength, context, callback_extract_private); } break; // CID @@ -255,9 +242,7 @@ typedef struct { uint64_t randx; } outline_builder_context; -static void callback_count_contour(void *context) { - ((outline_builder_context *)context)->g->numberOfContours += 1; -} +static void callback_count_contour(void *context) { ((outline_builder_context *)context)->g->numberOfContours += 1; } static void callback_countpoint_next_contour(void *_context) { outline_builder_context *context = (outline_builder_context *)_context; context->jContour += 1; @@ -271,16 +256,14 @@ static void callback_countpoint_lineto(void *_context, float x1, float y1) { context->jPoint += 1; } } -static void callback_countpoint_curveto(void *_context, float x1, float y1, float x2, float y2, - float x3, float y3) { +static void callback_countpoint_curveto(void *_context, float x1, float y1, float x2, float y2, float x3, float y3) { outline_builder_context *context = (outline_builder_context *)_context; if (context->jContour) { context->g->contours[context->jContour - 1].pointsCount += 3; context->jPoint += 3; } } -static void callback_countpoint_sethint(void *_context, bool isVertical, float position, - float width) { +static void callback_countpoint_sethint(void *_context, bool isVertical, float position, float width) { outline_builder_context *context = (outline_builder_context *)_context; if (isVertical) { context->g->numberOfStemV += 1; @@ -317,8 +300,7 @@ static void callback_draw_lineto(void *_context, float x1, float y1) { context->pointsDefined += 1; } } -static void callback_draw_curveto(void *_context, float x1, float y1, float x2, float y2, float x3, - float y3) { +static void callback_draw_curveto(void *_context, float x1, float y1, float x2, float y2, float x3, float y3) { outline_builder_context *context = (outline_builder_context *)_context; if (context->jContour) { context->g->contours[context->jContour - 1].points[context->jPoint].onCurve = false; @@ -349,8 +331,7 @@ static void callback_draw_sethint(void *_context, bool isVertical, float positio static void callback_draw_setmask(void *_context, bool isContourMask, bool *maskArray) { outline_builder_context *context = (outline_builder_context *)_context; uint16_t maskIndex = isContourMask ? context->definedContourMasks : context->definedHintMasks; - glyf_postscript_hint_mask *maskList = - isContourMask ? context->g->contourMasks : context->g->hintMasks; + glyf_postscript_hint_mask *maskList = isContourMask ? context->g->contourMasks : context->g->hintMasks; glyf_postscript_hint_mask *mask; bool duplicateMask = false; @@ -369,8 +350,7 @@ static void callback_draw_setmask(void *_context, bool isContourMask, bool *mask for (uint16_t j = 0; j < 0x100; j++) { mask->maskH[j] = j < context->g->numberOfStemH ? maskArray[j] : 0; - mask->maskV[j] = - j < context->g->numberOfStemV ? maskArray[j + context->g->numberOfStemH] : 0; + mask->maskV[j] = j < context->g->numberOfStemV ? maskArray[j + context->g->numberOfStemH] : 0; } free(maskArray); @@ -413,8 +393,7 @@ static void buildOutline(uint16_t i, cff_parse_context *context) { stack.stem = 0; outline_builder_context bc = {g, 0, 0, 0.0, 0.0, 0, 0, 0, 0, 0, 0}; - cff_outline_builder_interface pass1 = {NULL, callback_count_contour, NULL, NULL, NULL, NULL, - NULL}; + cff_outline_builder_interface pass1 = {NULL, callback_count_contour, NULL, NULL, NULL, NULL, NULL}; cff_outline_builder_interface pass2 = {NULL, callback_countpoint_next_contour, callback_countpoint_lineto, @@ -422,9 +401,8 @@ static void buildOutline(uint16_t i, cff_parse_context *context) { callback_countpoint_sethint, callback_countpoint_setmask, NULL}; - cff_outline_builder_interface pass3 = {callback_draw_setwidth, callback_draw_next_contour, - callback_draw_lineto, callback_draw_curveto, - callback_draw_sethint, callback_draw_setmask, + cff_outline_builder_interface pass3 = {callback_draw_setwidth, callback_draw_next_contour, callback_draw_lineto, + callback_draw_curveto, callback_draw_sethint, callback_draw_setmask, callback_draw_getrand}; uint8_t fd = 0; @@ -449,19 +427,15 @@ static void buildOutline(uint16_t i, cff_parse_context *context) { // PASS 1 : Count contours bc.randx = seed; - parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, - pass1); + parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, pass1); NEW_N(g->contours, g->numberOfContours); // PASS 2 : Count points stack.index = 0; stack.stem = 0; bc.randx = seed; - parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, - pass2); - for (uint16_t j = 0; j < g->numberOfContours; j++) { - NEW_N(g->contours[j].points, g->contours[j].pointsCount); - } + parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, pass2); + for (uint16_t j = 0; j < g->numberOfContours; j++) { NEW_N(g->contours[j].points, g->contours[j].pointsCount); } NEW_N(g->stemH, g->numberOfStemH); NEW_N(g->stemV, g->numberOfStemV); NEW_N(g->hintMasks, g->numberOfHintMasks); @@ -473,8 +447,7 @@ static void buildOutline(uint16_t i, cff_parse_context *context) { bc.jContour = 0; bc.jPoint = 0; bc.randx = seed; - parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, - pass3); + parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, pass3); g->numberOfContourMasks = bc.definedContourMasks; g->numberOfHintMasks = bc.definedHintMasks; @@ -567,13 +540,10 @@ caryll_cff_parse_result caryll_read_CFF_and_glyf(caryll_packet packet) { context.meta = caryll_new_CFF(); // Extract data in TOP DICT - parse_dict_callback(cffFile->top_dict.data, - cffFile->top_dict.offset[1] - cffFile->top_dict.offset[0], &context, + parse_dict_callback(cffFile->top_dict.data, cffFile->top_dict.offset[1] - cffFile->top_dict.offset[0], &context, callback_extract_fd); - if (!context.meta->fontName) { - context.meta->fontName = sdsget_cff_sid(391, cffFile->name); - } + if (!context.meta->fontName) { context.meta->fontName = sdsget_cff_sid(391, cffFile->name); } // We have FDArray if (cffFile->font_dict.count) { @@ -583,8 +553,8 @@ caryll_cff_parse_result caryll_read_CFF_and_glyf(caryll_packet packet) { context.meta->fdArray[j] = caryll_new_CFF(); context.fdArrayIndex = j; parse_dict_callback(cffFile->font_dict.data + cffFile->font_dict.offset[j] - 1, - cffFile->font_dict.offset[j + 1] - cffFile->font_dict.offset[j], - &context, callback_extract_fd); + cffFile->font_dict.offset[j + 1] - cffFile->font_dict.offset[j], &context, + callback_extract_fd); } } ret.meta = context.meta; @@ -592,8 +562,7 @@ caryll_cff_parse_result caryll_read_CFF_and_glyf(caryll_packet packet) { // Extract data of outlines context.seed = 0x1234567887654321; if (context.meta->privateDict) { - context.seed = - (uint64_t)context.meta->privateDict->initialRandomSeed ^ 0x1234567887654321; + context.seed = (uint64_t)context.meta->privateDict->initialRandomSeed ^ 0x1234567887654321; } table_glyf *glyphs; NEW(glyphs); @@ -626,25 +595,18 @@ static json_value *pdToJson(cff_private *pd) { pdDeltaToJson(_pd, "familyOtherBlues", pd->familyOtherBluesCount, pd->familyOtherBlues); pdDeltaToJson(_pd, "stemSnapH", pd->stemSnapHCount, pd->stemSnapH); pdDeltaToJson(_pd, "stemSnapV", pd->stemSnapVCount, pd->stemSnapV); - if (pd->blueScale != DEFAULT_BLUE_SCALE) - json_object_push(_pd, "blueScale", json_double_new(pd->blueScale)); - if (pd->blueShift != DEFAULT_BLUE_SHIFT) - json_object_push(_pd, "blueShift", json_double_new(pd->blueShift)); - if (pd->blueFuzz != DEFAULT_BLUE_FUZZ) - json_object_push(_pd, "blueFuzz", json_double_new(pd->blueFuzz)); + if (pd->blueScale != DEFAULT_BLUE_SCALE) json_object_push(_pd, "blueScale", json_double_new(pd->blueScale)); + if (pd->blueShift != DEFAULT_BLUE_SHIFT) json_object_push(_pd, "blueShift", json_double_new(pd->blueShift)); + if (pd->blueFuzz != DEFAULT_BLUE_FUZZ) json_object_push(_pd, "blueFuzz", json_double_new(pd->blueFuzz)); if (pd->stdHW) json_object_push(_pd, "stdHW", json_double_new(pd->stdHW)); if (pd->stdVW) json_object_push(_pd, "stdVW", json_double_new(pd->stdVW)); if (pd->forceBold) json_object_push(_pd, "forceBold", json_boolean_new(pd->forceBold)); - if (pd->languageGroup) - json_object_push(_pd, "languageGroup", json_double_new(pd->languageGroup)); + if (pd->languageGroup) json_object_push(_pd, "languageGroup", json_double_new(pd->languageGroup)); if (pd->expansionFactor != DEFAULT_EXPANSION_FACTOR) json_object_push(_pd, "expansionFactor", json_double_new(pd->expansionFactor)); - if (pd->initialRandomSeed) - json_object_push(_pd, "initialRandomSeed", json_double_new(pd->initialRandomSeed)); - if (pd->defaultWidthX) - json_object_push(_pd, "defaultWidthX", json_double_new(pd->defaultWidthX)); - if (pd->nominalWidthX) - json_object_push(_pd, "nominalWidthX", json_double_new(pd->nominalWidthX)); + if (pd->initialRandomSeed) json_object_push(_pd, "initialRandomSeed", json_double_new(pd->initialRandomSeed)); + if (pd->defaultWidthX) json_object_push(_pd, "defaultWidthX", json_double_new(pd->defaultWidthX)); + if (pd->nominalWidthX) json_object_push(_pd, "nominalWidthX", json_double_new(pd->nominalWidthX)); return _pd; } static json_value *fdToJson(table_CFF *table) { @@ -660,24 +622,17 @@ static json_value *fdToJson(table_CFF *table) { if (table->familyName) json_object_push(_CFF_, "familyName", json_from_sds(table->familyName)); if (table->weight) json_object_push(_CFF_, "weight", json_from_sds(table->weight)); - if (table->isFixedPitch) - json_object_push(_CFF_, "isFixedPitch", json_boolean_new(table->isFixedPitch)); - if (table->italicAngle) - json_object_push(_CFF_, "italicAngle", json_double_new(table->italicAngle)); + if (table->isFixedPitch) json_object_push(_CFF_, "isFixedPitch", json_boolean_new(table->isFixedPitch)); + if (table->italicAngle) json_object_push(_CFF_, "italicAngle", json_double_new(table->italicAngle)); if (table->underlinePosition != -100) json_object_push(_CFF_, "underlinePosition", json_double_new(table->underlinePosition)); if (table->underlineThickness != 50) json_object_push(_CFF_, "underlineThickness", json_double_new(table->underlineThickness)); - if (table->strokeWidth) - json_object_push(_CFF_, "strokeWidth", json_double_new(table->strokeWidth)); - if (table->fontBBoxLeft) - json_object_push(_CFF_, "fontBBoxLeft", json_double_new(table->fontBBoxLeft)); - if (table->fontBBoxBottom) - json_object_push(_CFF_, "fontBBoxBottom", json_double_new(table->fontBBoxBottom)); - if (table->fontBBoxRight) - json_object_push(_CFF_, "fontBBoxRight", json_double_new(table->fontBBoxRight)); - if (table->fontBBoxTop) - json_object_push(_CFF_, "fontBBoxTop", json_double_new(table->fontBBoxTop)); + if (table->strokeWidth) json_object_push(_CFF_, "strokeWidth", json_double_new(table->strokeWidth)); + if (table->fontBBoxLeft) json_object_push(_CFF_, "fontBBoxLeft", json_double_new(table->fontBBoxLeft)); + if (table->fontBBoxBottom) json_object_push(_CFF_, "fontBBoxBottom", json_double_new(table->fontBBoxBottom)); + if (table->fontBBoxRight) json_object_push(_CFF_, "fontBBoxRight", json_double_new(table->fontBBoxRight)); + if (table->fontBBoxTop) json_object_push(_CFF_, "fontBBoxTop", json_double_new(table->fontBBoxTop)); if (table->fontMatrix) { json_value *_fontMatrix = json_object_new(6); @@ -698,9 +653,7 @@ static json_value *fdToJson(table_CFF *table) { } if (table->fdArray) { json_value *_fdArray = json_array_new(table->fdArrayCount); - for (uint16_t j = 0; j < table->fdArrayCount; j++) { - json_array_push(_fdArray, fdToJson(table->fdArray[j])); - } + for (uint16_t j = 0; j < table->fdArrayCount; j++) { json_array_push(_fdArray, fdToJson(table->fdArray[j])); } json_object_push(_CFF_, "fdArray", _fdArray); } return _CFF_; @@ -723,8 +676,7 @@ static cff_private *pdFromJson(json_value *dump) { pdDeltaFromJson(json_obj_get(dump, "blueValues"), &(pd->blueValuesCount), &(pd->blueValues)); pdDeltaFromJson(json_obj_get(dump, "otherBlues"), &(pd->otherBluesCount), &(pd->otherBlues)); pdDeltaFromJson(json_obj_get(dump, "familyBlues"), &(pd->familyBluesCount), &(pd->familyBlues)); - pdDeltaFromJson(json_obj_get(dump, "familyOtherBlues"), &(pd->familyOtherBluesCount), - &(pd->familyOtherBlues)); + pdDeltaFromJson(json_obj_get(dump, "familyOtherBlues"), &(pd->familyOtherBluesCount), &(pd->familyOtherBlues)); pdDeltaFromJson(json_obj_get(dump, "stemSnapH"), &(pd->stemSnapHCount), &(pd->stemSnapH)); pdDeltaFromJson(json_obj_get(dump, "stemSnapV"), &(pd->stemSnapVCount), &(pd->stemSnapV)); @@ -735,8 +687,7 @@ static cff_private *pdFromJson(json_value *dump) { pd->stdVW = json_obj_getnum(dump, "stdVW"); pd->forceBold = json_obj_getbool(dump, "forceBold"); pd->languageGroup = json_obj_getnum(dump, "languageGroup"); - pd->expansionFactor = - json_obj_getnum_fallback(dump, "expansionFactor", DEFAULT_EXPANSION_FACTOR); + pd->expansionFactor = json_obj_getnum_fallback(dump, "expansionFactor", DEFAULT_EXPANSION_FACTOR); pd->initialRandomSeed = json_obj_getnum(dump, "initialRandomSeed"); // Not used -- they will be automatically calculated // pd->defaultWidthX = json_obj_getnum(dump, "defaultWidthX"); @@ -830,13 +781,11 @@ typedef struct { } cff_charstring_builder_context; static caryll_buffer *callback_makeglyph(void *_context, uint32_t j) { cff_charstring_builder_context *context = (cff_charstring_builder_context *)_context; - return compile_glyph(context->glyf->glyphs[j], context->defaultWidth, context->nominalWidthX, - context->dumpopts); + return compile_glyph(context->glyf->glyphs[j], context->defaultWidth, context->nominalWidthX, context->dumpopts); } static caryll_buffer *cff_make_charstrings(cff_charstring_builder_context *context) { if (context->glyf->numberGlyphs == 0) return bufnew(); - CFF_Index *charstring = - cff_buildindex_callback(context, context->glyf->numberGlyphs, callback_makeglyph); + CFF_Index *charstring = cff_buildindex_callback(context, context->glyf->numberGlyphs, callback_makeglyph); caryll_buffer *final_blob = compile_index(*charstring); cff_index_fini(charstring); return final_blob; @@ -898,8 +847,7 @@ static void cffdict_input(CFF_Dict *dict, uint32_t op, CFF_Value_Type t, uint16_ } va_end(ap); } -static void cffdict_input_array(CFF_Dict *dict, uint32_t op, CFF_Value_Type t, uint16_t arity, - float *arr) { +static void cffdict_input_array(CFF_Dict *dict, uint32_t op, CFF_Value_Type t, uint16_t arity, float *arr) { if (!arity || !arr) return; CFF_Dict_Entry *last = cffdict_givemeablank(dict); last->op = op; @@ -927,8 +875,8 @@ static CFF_Dict *cff_make_fd_dict(table_CFF *fd, cff_sid_entry **h) { NEW_CLEAN(dict); // ROS if (fd->cidRegistry && fd->cidOrdering) { - cffdict_input(dict, op_ROS, CFF_INTEGER, 3, sidof(h, fd->cidRegistry), - sidof(h, fd->cidOrdering), fd->cidSupplement); + cffdict_input(dict, op_ROS, CFF_INTEGER, 3, sidof(h, fd->cidRegistry), sidof(h, fd->cidOrdering), + fd->cidSupplement); } // CFF Names @@ -936,29 +884,26 @@ static CFF_Dict *cff_make_fd_dict(table_CFF *fd, cff_sid_entry **h) { if (fd->notice) cffdict_input(dict, op_Notice, CFF_INTEGER, 1, sidof(h, fd->notice)); if (fd->copyright) cffdict_input(dict, op_Copyright, CFF_INTEGER, 1, sidof(h, fd->copyright)); if (fd->fullName) cffdict_input(dict, op_FullName, CFF_INTEGER, 1, sidof(h, fd->fullName)); - if (fd->familyName) - cffdict_input(dict, op_FamilyName, CFF_INTEGER, 1, sidof(h, fd->familyName)); + if (fd->familyName) cffdict_input(dict, op_FamilyName, CFF_INTEGER, 1, sidof(h, fd->familyName)); if (fd->weight) cffdict_input(dict, op_Weight, CFF_INTEGER, 1, sidof(h, fd->weight)); // CFF Metrics - cffdict_input(dict, op_FontBBox, CFF_DOUBLE, 4, fd->fontBBoxLeft, fd->fontBBoxBottom, - fd->fontBBoxRight, fd->fontBBoxTop); + cffdict_input(dict, op_FontBBox, CFF_DOUBLE, 4, fd->fontBBoxLeft, fd->fontBBoxBottom, fd->fontBBoxRight, + fd->fontBBoxTop); cffdict_input(dict, op_isFixedPitch, CFF_INTEGER, 1, (int)fd->isFixedPitch); cffdict_input(dict, op_ItalicAngle, CFF_DOUBLE, 1, fd->italicAngle); cffdict_input(dict, op_UnderlinePosition, CFF_DOUBLE, 1, fd->underlinePosition); 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, fd->fontMatrix->x, fd->fontMatrix->y); } // CID specific if (fd->fontName) cffdict_input(dict, op_FontName, CFF_INTEGER, 1, sidof(h, fd->fontName)); - if (fd->cidFontVersion) - cffdict_input(dict, op_CIDFontVersion, CFF_DOUBLE, 1, fd->cidFontVersion); - if (fd->cidFontRevision) - cffdict_input(dict, op_CIDFontRevision, CFF_DOUBLE, 1, fd->cidFontRevision); + if (fd->cidFontVersion) cffdict_input(dict, op_CIDFontVersion, CFF_DOUBLE, 1, fd->cidFontVersion); + if (fd->cidFontRevision) cffdict_input(dict, op_CIDFontRevision, CFF_DOUBLE, 1, fd->cidFontRevision); if (fd->cidCount) cffdict_input(dict, op_CIDCount, CFF_INTEGER, 1, fd->cidCount); if (fd->UIDBase) cffdict_input(dict, op_UIDBase, CFF_INTEGER, 1, fd->UIDBase); return dict; @@ -972,8 +917,7 @@ static CFF_Dict *cff_make_private_dict(cff_private *pd) { cffdict_input_array(dict, op_BlueValues, CFF_DOUBLE, pd->blueValuesCount, pd->blueValues); cffdict_input_array(dict, op_OtherBlues, CFF_DOUBLE, pd->otherBluesCount, pd->otherBlues); cffdict_input_array(dict, op_FamilyBlues, CFF_DOUBLE, pd->familyBluesCount, pd->familyBlues); - cffdict_input_array(dict, op_FamilyOtherBlues, CFF_DOUBLE, pd->familyOtherBluesCount, - pd->familyOtherBlues); + cffdict_input_array(dict, op_FamilyOtherBlues, CFF_DOUBLE, pd->familyOtherBluesCount, pd->familyOtherBlues); cffdict_input_array(dict, op_StemSnapH, CFF_DOUBLE, pd->stemSnapHCount, pd->stemSnapH); cffdict_input_array(dict, op_StemSnapV, CFF_DOUBLE, pd->stemSnapVCount, pd->stemSnapV); @@ -1043,8 +987,7 @@ static caryll_buffer *cff_compile_nameindex(table_CFF *cff) { return buf; } -static caryll_buffer *cff_make_charset(table_CFF *cff, table_glyf *glyf, - cff_sid_entry **stringHash) { +static caryll_buffer *cff_make_charset(table_CFF *cff, table_glyf *glyf, cff_sid_entry **stringHash) { CFF_Charset *charset; NEW_CLEAN(charset); if (glyf->numberGlyphs > 1) { // At least two glyphs @@ -1056,9 +999,7 @@ static caryll_buffer *cff_make_charset(table_CFF *cff, table_glyf *glyf, charset->f2.range2[0].first = 1; charset->f2.range2[0].nleft = glyf->numberGlyphs - 2; } else { - for (uint16_t j = 1; j < glyf->numberGlyphs; j++) { - sidof(stringHash, glyf->glyphs[j]->name); - } + for (uint16_t j = 1; j < glyf->numberGlyphs; j++) { sidof(stringHash, glyf->glyphs[j]->name); } charset->f2.range2[0].first = sidof(stringHash, glyf->glyphs[1]->name); charset->f2.range2[0].nleft = glyf->numberGlyphs - 2; } @@ -1130,8 +1071,7 @@ static caryll_buffer *callback_makefd(void *_context, uint32_t i) { cff_delete_dict(fd); return blob; } -static CFF_Index *cff_make_fdarray(uint16_t fdArrayCount, table_CFF **fdArray, - cff_sid_entry **stringHash) { +static CFF_Index *cff_make_fdarray(uint16_t fdArrayCount, table_CFF **fdArray, cff_sid_entry **stringHash) { fdarray_compile_context context; context.fdArray = fdArray; context.stringHash = stringHash; @@ -1139,8 +1079,7 @@ static CFF_Index *cff_make_fdarray(uint16_t fdArrayCount, table_CFF **fdArray, return cff_buildindex_callback(&context, fdArrayCount, callback_makefd); } -static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, - caryll_dump_options *dumpopts) { +static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, caryll_dump_options *dumpopts) { caryll_buffer *blob = bufnew(); // The Strings hashtable cff_sid_entry *stringHash = NULL; @@ -1204,8 +1143,7 @@ static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, bufwrite_bufdel(blob, bufninit(11, 0, 1, // top dict index headerone item 4, // four bytes per offset 0, 0, 0, 1, // offset 1 - (delta_size >> 24) & 0xff, (delta_size >> 16) & 0xff, - (delta_size >> 8) & 0xff, + (delta_size >> 24) & 0xff, (delta_size >> 16) & 0xff, (delta_size >> 8) & 0xff, delta_size & 0xff) // offset 2 ); @@ -1271,9 +1209,7 @@ static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, r = compile_index(*fdArrayIndex); cff_index_fini(fdArrayIndex); bufwrite_bufdel(blob, r); - for (uint16_t j = 0; j < cff->fdArrayCount; j++) { - bufwrite_bufdel(blob, fdArrayPrivates[j]); - } + for (uint16_t j = 0; j < cff->fdArrayCount; j++) { bufwrite_bufdel(blob, fdArrayPrivates[j]); } free(fdArrayPrivates); } else { bufwrite_bufdel(blob, r); diff --git a/lib/tables/OS_2.c b/lib/tables/OS_2.c index 1e1d5d2b..8d005d90 100644 --- a/lib/tables/OS_2.c +++ b/lib/tables/OS_2.c @@ -72,31 +72,20 @@ table_OS_2 *caryll_read_OS_2(caryll_packet packet) { return NULL; } -const char *fsTypeLabels[] = {"_reserved1", - "restrictedLicense", - "previewPrintLicense", - "editableEmbedding", - "_reserved2", - "_reserved3", - "_reserved4", - "_reserved5", - "noSubsetting", - "bitmapEmbeddingOnly", - NULL}; -const char *fsSelectionLabels[] = {"italic", "underscore", "negative", "outlined", - "strikeout", "bold", "regular", "useTypoMetrics", - "wws", "oblique", NULL}; -const char *codePageLabels1[] = { - "latin1", "latin2", "cyrillic", "greek", "turkish", "hebrew", "arabic", - "windowsBaltic", "vietnamese", "ansi1", "ansi2", "ansi3", "ansi4", "ansi5", - "ansi6", "ansi7", "thai", "jis", "gbk", "korean", "big5", - "koreanJohab", "oem1", "oem2", "oem3", "oem4", "oem5", "oem6", - "oem7", "macRoman", "oem", "symbol", NULL}; -const char *codePageLabels2[] = {"oem8", "oem9", "oem10", "oem11", "oem12", "oem13", "oem14", - "oem15", "oem16", "oem17", "oem18", "oem19", "oem20", "oem21", - "oem22", "oem23", "cp869", "cp866", "cp865", "cp864", "cp863", - "cp862", "cp861", "cp860", "cp857", "cp855", "cp852", "cp775", - "cp737", "cp708", "cp850", "ascii", NULL}; +const char *fsTypeLabels[] = { + "_reserved1", "restrictedLicense", "previewPrintLicense", "editableEmbedding", "_reserved2", "_reserved3", + "_reserved4", "_reserved5", "noSubsetting", "bitmapEmbeddingOnly", NULL}; +const char *fsSelectionLabels[] = {"italic", "underscore", "negative", "outlined", "strikeout", "bold", + "regular", "useTypoMetrics", "wws", "oblique", NULL}; +const char *codePageLabels1[] = {"latin1", "latin2", "cyrillic", "greek", "turkish", "hebrew", "arabic", + "windowsBaltic", "vietnamese", "ansi1", "ansi2", "ansi3", "ansi4", "ansi5", + "ansi6", "ansi7", "thai", "jis", "gbk", "korean", "big5", + "koreanJohab", "oem1", "oem2", "oem3", "oem4", "oem5", "oem6", + "oem7", "macRoman", "oem", "symbol", NULL}; +const char *codePageLabels2[] = {"oem8", "oem9", "oem10", "oem11", "oem12", "oem13", "oem14", "oem15", "oem16", + "oem17", "oem18", "oem19", "oem20", "oem21", "oem22", "oem23", "cp869", "cp866", + "cp865", "cp864", "cp863", "cp862", "cp861", "cp860", "cp857", "cp855", "cp852", + "cp775", "cp737", "cp708", "cp850", "ascii", NULL}; void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_options *dumpopts) { if (!table) return; @@ -118,9 +107,7 @@ void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_option json_object_push(os_2, "sFamilyClass", json_integer_new(table->sFamilyClass)); json_value *panose = json_array_new(10); - for (uint8_t j = 0; j < 10; j++) { - json_array_push(panose, json_integer_new(table->panose[j])); - } + for (uint8_t j = 0; j < 10; j++) { json_array_push(panose, json_integer_new(table->panose[j])); } json_object_push(os_2, "panose", panose); json_object_push(os_2, "ulUnicodeRange1", json_integer_new(table->ulUnicodeRange1)); @@ -132,8 +119,7 @@ void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_option json_object_push(os_2, "achVendID", json_string_new(vendorid)); sdsfree(vendorid); - json_object_push(os_2, "fsSelection", - caryll_flags_to_json(table->fsSelection, fsSelectionLabels)); + json_object_push(os_2, "fsSelection", caryll_flags_to_json(table->fsSelection, fsSelectionLabels)); json_object_push(os_2, "usFirstCharIndex", json_integer_new(table->usFirstCharIndex)); json_object_push(os_2, "usLastCharIndex", json_integer_new(table->usLastCharIndex)); json_object_push(os_2, "sTypoAscender", json_integer_new(table->sTypoAscender)); @@ -141,19 +127,15 @@ void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_dump_option json_object_push(os_2, "sTypoLineGap", json_integer_new(table->sTypoLineGap)); json_object_push(os_2, "usWinAscent", json_integer_new(table->usWinAscent)); json_object_push(os_2, "usWinDescent", json_integer_new(table->usWinDescent)); - json_object_push(os_2, "ulCodePageRange1", - caryll_flags_to_json(table->ulCodePageRange1, codePageLabels1)); - json_object_push(os_2, "ulCodePageRange2", - caryll_flags_to_json(table->ulCodePageRange2, codePageLabels2)); + json_object_push(os_2, "ulCodePageRange1", caryll_flags_to_json(table->ulCodePageRange1, codePageLabels1)); + json_object_push(os_2, "ulCodePageRange2", caryll_flags_to_json(table->ulCodePageRange2, codePageLabels2)); json_object_push(os_2, "sxHeight", json_integer_new(table->sxHeight)); json_object_push(os_2, "sCapHeight", json_integer_new(table->sCapHeight)); json_object_push(os_2, "usDefaultChar", json_integer_new(table->usDefaultChar)); json_object_push(os_2, "usBreakChar", json_integer_new(table->usBreakChar)); json_object_push(os_2, "usMaxContext", json_integer_new(table->usMaxContext)); - json_object_push(os_2, "usLowerOpticalPointSize", - json_integer_new(table->usLowerOpticalPointSize)); - json_object_push(os_2, "usUpperOpticalPointSize", - json_integer_new(table->usUpperOpticalPointSize)); + json_object_push(os_2, "usLowerOpticalPointSize", json_integer_new(table->usLowerOpticalPointSize)); + json_object_push(os_2, "usUpperOpticalPointSize", json_integer_new(table->usUpperOpticalPointSize)); json_object_push(root, "OS_2", os_2); } @@ -177,8 +159,7 @@ table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_dump_options *dumpopt os_2->yStrikeoutSize = json_obj_getnum_fallback(table, "yStrikeoutSize", 0); os_2->yStrikeoutPosition = json_obj_getnum_fallback(table, "yStrikeoutPosition", 0); os_2->sFamilyClass = json_obj_getnum_fallback(table, "sFamilyClass", 0); - os_2->fsSelection = - caryll_flags_from_json(json_obj_get(table, "fsSelection"), fsSelectionLabels); + os_2->fsSelection = caryll_flags_from_json(json_obj_get(table, "fsSelection"), fsSelectionLabels); os_2->usFirstCharIndex = json_obj_getnum_fallback(table, "usFirstCharIndex", 0); os_2->usLastCharIndex = json_obj_getnum_fallback(table, "usLastCharIndex", 0); os_2->sTypoAscender = json_obj_getnum_fallback(table, "sTypoAscender", 0); @@ -186,19 +167,15 @@ table_OS_2 *caryll_OS_2_from_json(json_value *root, caryll_dump_options *dumpopt os_2->sTypoLineGap = json_obj_getnum_fallback(table, "sTypoLineGap", 0); os_2->usWinAscent = json_obj_getnum_fallback(table, "usWinAscent", 0); os_2->usWinDescent = json_obj_getnum_fallback(table, "usWinDescent", 0); - os_2->ulCodePageRange1 = - caryll_flags_from_json(json_obj_get(table, "ulCodePageRange1"), codePageLabels1); - os_2->ulCodePageRange2 = - caryll_flags_from_json(json_obj_get(table, "ulCodePageRange2"), codePageLabels2); + os_2->ulCodePageRange1 = caryll_flags_from_json(json_obj_get(table, "ulCodePageRange1"), codePageLabels1); + os_2->ulCodePageRange2 = caryll_flags_from_json(json_obj_get(table, "ulCodePageRange2"), codePageLabels2); os_2->sxHeight = json_obj_getnum_fallback(table, "sxHeight", 0); os_2->sCapHeight = json_obj_getnum_fallback(table, "sCapHeight", 0); os_2->usDefaultChar = json_obj_getnum_fallback(table, "usDefaultChar", 0); os_2->usBreakChar = json_obj_getnum_fallback(table, "usBreakChar", 0); os_2->usMaxContext = json_obj_getnum_fallback(table, "usMaxContext", 0); - os_2->usLowerOpticalPointSize = - json_obj_getnum_fallback(table, "usLowerOpticalPointSize", 0); - os_2->usUpperOpticalPointSize = - json_obj_getnum_fallback(table, "usUpperOpticalPointSize", 0); + os_2->usLowerOpticalPointSize = json_obj_getnum_fallback(table, "usLowerOpticalPointSize", 0); + os_2->usUpperOpticalPointSize = json_obj_getnum_fallback(table, "usUpperOpticalPointSize", 0); // panose json_value *panose = NULL; if ((panose = json_obj_get_type(table, "panose", json_array))) { diff --git a/lib/tables/cmap.c b/lib/tables/cmap.c index 23846dc8..1c00b3c3 100644 --- a/lib/tables/cmap.c +++ b/lib/tables/cmap.c @@ -20,9 +20,7 @@ static void caryll_read_format_12(font_file_pointer start, uint32_t lengthLimit, uint32_t startCode = read_32u(start + 16 + 12 * j); uint32_t endCode = read_32u(start + 16 + 12 * j + 4); uint32_t startGID = read_32u(start + 16 + 12 * j + 8); - for (uint32_t c = startCode; c <= endCode; c++) { - encode(map, c, (c - startCode) + startGID); - } + for (uint32_t c = startCode; c <= endCode; c++) { encode(map, c, (c - startCode) + startGID); } } } @@ -52,8 +50,7 @@ static void caryll_read_format_4(font_file_pointer start, uint32_t lengthLimit, } } -static void caryll_read_mapping_table(font_file_pointer start, uint32_t lengthLimit, - cmap_hash *map) { +static void caryll_read_mapping_table(font_file_pointer start, uint32_t lengthLimit, cmap_hash *map) { uint16_t format = read_16u(start); if (format == 4) { caryll_read_format_4(start, lengthLimit, map); @@ -114,8 +111,7 @@ void caryll_cmap_to_json(cmap_hash *table, json_value *root, caryll_dump_options cmap_entry *item; foreach_hash(item, *table) if (item->glyph.name) { sds key = sdsfromlonglong(item->unicode); - json_object_push(cmap, key, json_string_new_length((uint32_t)sdslen(item->glyph.name), - item->glyph.name)); + json_object_push(cmap, key, json_string_new_length((uint32_t)sdslen(item->glyph.name), item->glyph.name)); sdsfree(key); } json_object_push(root, "cmap", cmap); @@ -127,8 +123,7 @@ cmap_hash *caryll_cmap_from_json(json_value *root, caryll_dump_options *dumpopts json_value *table = NULL; if ((table = json_obj_get_type(root, "cmap", json_object))) { for (uint32_t j = 0; j < table->u.object.length; j++) { - sds unicodeStr = - sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); + sds unicodeStr = sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); json_value *item = table->u.object.values[j].value; int32_t unicode = atoi(unicodeStr); sdsfree(unicodeStr); @@ -155,16 +150,16 @@ cmap_hash *caryll_cmap_from_json(json_value *root, caryll_dump_options *dumpopts return NULL; } // writing tables -#define FLUSH_SEQUENCE_FORMAT_4 \ - bufwrite16b(endCount, lastUnicodeEnd); \ - bufwrite16b(startCount, lastUnicodeStart); \ - if (isSequencial) { \ - bufwrite16b(idDelta, lastGIDStart - lastUnicodeStart); \ - bufwrite16b(idRangeOffset, 0); \ - } else { \ - bufwrite16b(idDelta, 0); \ - bufwrite16b(idRangeOffset, lastGlyphIdArrayOffset + 1); \ - } \ +#define FLUSH_SEQUENCE_FORMAT_4 \ + bufwrite16b(endCount, lastUnicodeEnd); \ + bufwrite16b(startCount, lastUnicodeStart); \ + if (isSequencial) { \ + bufwrite16b(idDelta, lastGIDStart - lastUnicodeStart); \ + bufwrite16b(idRangeOffset, 0); \ + } else { \ + bufwrite16b(idDelta, 0); \ + bufwrite16b(idRangeOffset, lastGlyphIdArrayOffset + 1); \ + } \ segmentsCount += 1; caryll_buffer *caryll_write_cmap_format4(cmap_hash *cmap) { caryll_buffer *buf = bufnew(); @@ -192,14 +187,11 @@ caryll_buffer *caryll_write_cmap_format4(cmap_hash *cmap) { isSequencial = true; } else { if (item->unicode == lastUnicodeEnd + 1 && - !(item->glyph.gid != lastGIDEnd + 1 && isSequencial && - lastGIDEnd - lastGIDStart >= 4)) { + !(item->glyph.gid != lastGIDEnd + 1 && isSequencial && lastGIDEnd - lastGIDStart >= 4)) { if (isSequencial && !(item->glyph.gid == lastGIDEnd + 1)) { lastGlyphIdArrayOffset = glyphIdArray->cursor; // oops, sequencial glyphid broken - for (int j = lastGIDStart; j <= lastGIDEnd; j++) { - bufwrite16b(glyphIdArray, j); - } + for (int j = lastGIDStart; j <= lastGIDEnd; j++) { bufwrite16b(glyphIdArray, j); } } lastUnicodeEnd = item->unicode; isSequencial = isSequencial && (item->glyph.gid == lastGIDEnd + 1); diff --git a/lib/tables/cvt.c b/lib/tables/cvt.c index d6826d7d..d5b0e1f6 100644 --- a/lib/tables/cvt.c +++ b/lib/tables/cvt.c @@ -18,13 +18,10 @@ void caryll_delete_cvt(table_cvt *table) { if (table->words) free(table->words); free(table); } -void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_dump_options *dumpopts, - const char *tag) { +void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_dump_options *dumpopts, const char *tag) { if (!table) return; json_value *arr = json_array_new(table->length); - for (uint16_t j = 0; j < table->length; j++) { - json_array_push(arr, json_integer_new(table->words[j])); - } + for (uint16_t j = 0; j < table->length; j++) { json_array_push(arr, json_integer_new(table->words[j])); } json_object_push(root, tag, arr); } table_cvt *caryll_cvt_from_json(json_value *root, const char *tag) { diff --git a/lib/tables/cvt.h b/lib/tables/cvt.h index e05633b4..5efe04be 100644 --- a/lib/tables/cvt.h +++ b/lib/tables/cvt.h @@ -11,8 +11,7 @@ typedef struct { } table_cvt; table_cvt *caryll_read_cvt(caryll_packet packet, uint32_t tag); void caryll_delete_cvt(table_cvt *table); -void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_dump_options *dumpopts, - const char *tag); +void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_dump_options *dumpopts, const char *tag); table_cvt *caryll_cvt_from_json(json_value *root, const char *tag); caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_dump_options *dumpopts); diff --git a/lib/tables/fpgm-prep.c b/lib/tables/fpgm-prep.c index fd8962dd..3d510bf5 100644 --- a/lib/tables/fpgm-prep.c +++ b/lib/tables/fpgm-prep.c @@ -26,8 +26,8 @@ void caryll_delete_fpgm_prep(table_fpgm_prep *table) { free(table); } -void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, - caryll_dump_options *dumpopts, const char *tag) { +void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, caryll_dump_options *dumpopts, + const char *tag) { if (!table) return; json_object_push(root, tag, instr_to_json(table->bytes, table->length, dumpopts)); } @@ -39,8 +39,7 @@ void makeFpgmPrepInstr(void *_t, uint8_t *instrs, uint32_t length) { } void wrongFpgmPrepInstr(void *_t, char *reason, int pos) { table_fpgm_prep *t = (table_fpgm_prep *)_t; - fprintf(stderr, "[OTFCC] TrueType instructions parse error : %s, at %d in /%s\n", reason, pos, - t->tag); + fprintf(stderr, "[OTFCC] TrueType instructions parse error : %s, at %d in /%s\n", reason, pos, t->tag); } table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, const char *tag) { diff --git a/lib/tables/fpgm-prep.h b/lib/tables/fpgm-prep.h index cc0ff421..9a060975 100644 --- a/lib/tables/fpgm-prep.h +++ b/lib/tables/fpgm-prep.h @@ -13,8 +13,7 @@ typedef struct { } table_fpgm_prep; table_fpgm_prep *caryll_read_fpgm_prep(caryll_packet packet, uint32_t tag); void caryll_delete_fpgm_prep(table_fpgm_prep *table); -void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, - caryll_dump_options *dumpopts, const char *tag); +void caryll_fpgm_prep_to_json(table_fpgm_prep *table, json_value *root, caryll_dump_options *dumpopts, const char *tag); table_fpgm_prep *caryll_fpgm_prep_from_json(json_value *root, const char *tag); caryll_buffer *caryll_write_fpgm_prep(table_fpgm_prep *table, caryll_dump_options *dumpopts); diff --git a/lib/tables/gasp.c b/lib/tables/gasp.c index 4f7fb4ac..0a6c8eae 100644 --- a/lib/tables/gasp.c +++ b/lib/tables/gasp.c @@ -57,10 +57,8 @@ void caryll_gasp_to_json(table_gasp *table, json_value *root, caryll_dump_option json_object_push(rec, "rangeMaxPPEM", json_integer_new(table->records[j].rangeMaxPPEM)); json_object_push(rec, "dogray", json_boolean_new(table->records[j].dogray)); json_object_push(rec, "gridfit", json_boolean_new(table->records[j].gridfit)); - json_object_push(rec, "symmetric_smoothing", - json_boolean_new(table->records[j].symmetric_smoothing)); - json_object_push(rec, "symmetric_gridfit", - json_boolean_new(table->records[j].symmetric_gridfit)); + json_object_push(rec, "symmetric_smoothing", json_boolean_new(table->records[j].symmetric_smoothing)); + json_object_push(rec, "symmetric_gridfit", json_boolean_new(table->records[j].symmetric_gridfit)); json_array_push(t, rec); } json_object_push(root, "gasp", t); diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index d16e5ca1..9ef2d178 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -84,15 +84,13 @@ static glyf_glyph *caryll_read_simple_glyph(font_file_pointer start, uint16_t nu flags[flagsReadSofar] = flag; flagBytesReadSofar += 1; flagsReadSofar += 1; - next_point(contours, ¤tContour, ¤tContourPointIndex)->onCurve = - (flag & GLYF_FLAG_ON_CURVE); + next_point(contours, ¤tContour, ¤tContourPointIndex)->onCurve = (flag & GLYF_FLAG_ON_CURVE); if (flag & GLYF_FLAG_REPEAT) { // repeating flag uint8_t repeat = flagStart[flagBytesReadSofar]; flagBytesReadSofar += 1; for (uint8_t j = 0; j < repeat; j++) { flags[flagsReadSofar + j] = flag; - next_point(contours, ¤tContour, ¤tContourPointIndex)->onCurve = - (flag & GLYF_FLAG_ON_CURVE); + next_point(contours, ¤tContour, ¤tContourPointIndex)->onCurve = (flag & GLYF_FLAG_ON_CURVE); } flagsReadSofar += repeat; } @@ -108,8 +106,7 @@ static glyf_glyph *caryll_read_simple_glyph(font_file_pointer start, uint16_t nu uint8_t flag = flags[coordinatesRead]; int16_t x; if (flag & GLYF_FLAG_X_SHORT) { - x = (flag & GLYF_FLAG_POSITIVE_X ? 1 : -1) * - read_8u(coordinatesStart + coordinatesOffset); + x = (flag & GLYF_FLAG_POSITIVE_X ? 1 : -1) * read_8u(coordinatesStart + coordinatesOffset); coordinatesOffset += 1; } else { if (flag & GLYF_FLAG_SAME_X) { @@ -130,8 +127,7 @@ static glyf_glyph *caryll_read_simple_glyph(font_file_pointer start, uint16_t nu uint8_t flag = flags[coordinatesRead]; int16_t y; if (flag & GLYF_FLAG_Y_SHORT) { - y = (flag & GLYF_FLAG_POSITIVE_Y ? 1 : -1) * - read_8u(coordinatesStart + coordinatesOffset); + y = (flag & GLYF_FLAG_POSITIVE_Y ? 1 : -1) * read_8u(coordinatesStart + coordinatesOffset); coordinatesOffset += 1; } else { if (flag & GLYF_FLAG_SAME_Y) { @@ -357,9 +353,7 @@ static void caryll_delete_glyf_glyph(glyf_glyph *g) { } void caryll_delete_glyf(table_glyf *table) { if (table->glyphs) { - for (uint16_t j = 0; j < table->numberGlyphs; j++) { - caryll_delete_glyf_glyph(table->glyphs[j]); - } + for (uint16_t j = 0; j < table->numberGlyphs; j++) { caryll_delete_glyf_glyph(table->glyphs[j]); } free(table->glyphs); } free(table); @@ -396,8 +390,7 @@ static void glyf_glyph_references_to_json(glyf_glyph *g, json_value *target) { for (uint16_t k = 0; k < g->numberOfReferences; k++) { glyf_reference *r = &(g->references[k]); json_value *ref = json_object_new(9); - json_object_push(ref, "glyph", - json_string_new_length((uint32_t)sdslen(r->glyph.name), r->glyph.name)); + json_object_push(ref, "glyph", json_string_new_length((uint32_t)sdslen(r->glyph.name), r->glyph.name)); json_object_push(ref, "x", coord_to_json(r->x)); json_object_push(ref, "y", coord_to_json(r->y)); json_object_push(ref, "a", coord_to_json(r->a)); @@ -410,8 +403,7 @@ static void glyf_glyph_references_to_json(glyf_glyph *g, json_value *target) { } json_object_push(target, "references", preserialize(references)); } -static json_value *glyf_glyph_stemdefs_to_json(glyf_postscript_hint_stemdef *stems, - uint16_t count) { +static json_value *glyf_glyph_stemdefs_to_json(glyf_postscript_hint_stemdef *stems, uint16_t count) { json_value *a = json_array_new(count); for (uint16_t j = 0; j < count; j++) { json_value *stem = json_object_new(3); @@ -421,21 +413,17 @@ static json_value *glyf_glyph_stemdefs_to_json(glyf_postscript_hint_stemdef *ste } return a; } -static json_value *glyf_glyph_maskdefs_to_json(glyf_postscript_hint_mask *masks, uint16_t count, - uint16_t nh, uint16_t nv) { +static json_value *glyf_glyph_maskdefs_to_json(glyf_postscript_hint_mask *masks, uint16_t count, uint16_t nh, + uint16_t nv) { json_value *a = json_array_new(count); for (uint16_t j = 0; j < count; j++) { json_value *mask = json_object_new(3); json_object_push(mask, "pointsBefore", json_integer_new(masks[j].pointsBefore)); json_value *h = json_array_new(nh); - for (uint16_t k = 0; k < nh; k++) { - json_array_push(h, json_boolean_new(masks[j].maskH[k])); - } + for (uint16_t k = 0; k < nh; k++) { json_array_push(h, json_boolean_new(masks[j].maskH[k])); } json_object_push(mask, "maskH", h); json_value *v = json_array_new(nv); - for (uint16_t k = 0; k < nv; k++) { - json_array_push(v, json_boolean_new(masks[j].maskV[k])); - } + for (uint16_t k = 0; k < nv; k++) { json_array_push(v, json_boolean_new(masks[j].maskV[k])); } json_object_push(mask, "maskV", v); json_array_push(a, mask); } @@ -444,9 +432,7 @@ static json_value *glyf_glyph_maskdefs_to_json(glyf_postscript_hint_mask *masks, static json_value *glyf_glyph_to_json(glyf_glyph *g, caryll_dump_options *dumpopts) { json_value *glyph = json_object_new(10); - if (dumpopts->export_fdselect) { - json_object_push(glyph, "fdSelectIndex", json_integer_new(g->fdSelectIndex)); - } + if (dumpopts->export_fdselect) { json_object_push(glyph, "fdSelectIndex", json_integer_new(g->fdSelectIndex)); } json_object_push(glyph, "advanceWidth", json_integer_new(g->advanceWidth)); if (dumpopts->has_vertical_metrics) { json_object_push(glyph, "advanceHeight", json_integer_new(g->advanceHeight)); @@ -455,26 +441,23 @@ static json_value *glyf_glyph_to_json(glyf_glyph *g, caryll_dump_options *dumpop glyf_glyph_contours_to_json(g, glyph); glyf_glyph_references_to_json(g, glyph); if (!dumpopts->ignore_hints && g->instructions && g->instructionsLength) { - json_object_push(glyph, "instructions", - instr_to_json(g->instructions, g->instructionsLength, dumpopts)); + json_object_push(glyph, "instructions", instr_to_json(g->instructions, g->instructionsLength, dumpopts)); } if (!dumpopts->ignore_hints && g->stemH && g->numberOfStemH) { - json_object_push(glyph, "stemH", - preserialize(glyf_glyph_stemdefs_to_json(g->stemH, g->numberOfStemH))); + json_object_push(glyph, "stemH", preserialize(glyf_glyph_stemdefs_to_json(g->stemH, g->numberOfStemH))); } if (!dumpopts->ignore_hints && g->stemV && g->numberOfStemV) { - json_object_push(glyph, "stemV", - preserialize(glyf_glyph_stemdefs_to_json(g->stemV, g->numberOfStemV))); + json_object_push(glyph, "stemV", preserialize(glyf_glyph_stemdefs_to_json(g->stemV, g->numberOfStemV))); } if (!dumpopts->ignore_hints && g->hintMasks && g->numberOfHintMasks) { - json_object_push(glyph, "hintMasks", preserialize(glyf_glyph_maskdefs_to_json( - g->hintMasks, g->numberOfHintMasks, - g->numberOfStemH, g->numberOfStemV))); + json_object_push(glyph, "hintMasks", + preserialize(glyf_glyph_maskdefs_to_json(g->hintMasks, g->numberOfHintMasks, g->numberOfStemH, + g->numberOfStemV))); } if (!dumpopts->ignore_hints && g->contourMasks && g->numberOfContourMasks) { - json_object_push(glyph, "contourMasks", preserialize(glyf_glyph_maskdefs_to_json( - g->contourMasks, g->numberOfContourMasks, - g->numberOfStemH, g->numberOfStemV))); + json_object_push(glyph, "contourMasks", + preserialize(glyf_glyph_maskdefs_to_json(g->contourMasks, g->numberOfContourMasks, + g->numberOfStemH, g->numberOfStemV))); } return glyph; } @@ -482,8 +465,8 @@ void caryll_glyphorder_to_json(table_glyf *table, json_value *root) { if (!table) return; json_value *order = json_array_new(table->numberGlyphs); for (uint16_t j = 0; j < table->numberGlyphs; j++) { - json_array_push(order, json_string_new_length((uint32_t)sdslen(table->glyphs[j]->name), - table->glyphs[j]->name)); + json_array_push(order, + json_string_new_length((uint32_t)sdslen(table->glyphs[j]->name), table->glyphs[j]->name)); } json_object_push(root, "glyph_order", preserialize(order)); } @@ -573,8 +556,7 @@ static void makeInstrsForGlyph(void *_g, uint8_t *instrs, uint32_t len) { } static void wrongInstrsForGlyph(void *_g, char *reason, int pos) { glyf_glyph *g = (glyf_glyph *)_g; - fprintf(stderr, "[OTFCC] TrueType instructions parse error : %s, at %d in /%s\n", reason, pos, - g->name); + fprintf(stderr, "[OTFCC] TrueType instructions parse error : %s, at %d in /%s\n", reason, pos, g->name); } static void stems_from_json(json_value *sd, uint16_t *count, glyf_postscript_hint_stemdef **arr) { @@ -639,8 +621,7 @@ static void masks_from_json(json_value *md, uint16_t *count, glyf_postscript_hin } } -static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, - glyph_order_entry *order_entry, +static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, glyph_order_entry *order_entry, caryll_dump_options *dumpopts) { glyf_glyph *g = caryll_new_glyf_glyph(); g->name = order_entry->name; @@ -651,16 +632,13 @@ static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, glyf_contours_from_json(json_obj_get_type(glyphdump, "contours", json_array), g); glyf_references_from_json(json_obj_get_type(glyphdump, "references", json_array), g); if (!dumpopts->ignore_hints) { - instr_from_json(json_obj_get(glyphdump, "instructions"), g, makeInstrsForGlyph, - wrongInstrsForGlyph); - stems_from_json(json_obj_get_type(glyphdump, "stemH", json_array), &g->numberOfStemH, - &(g->stemH)); - stems_from_json(json_obj_get_type(glyphdump, "stemV", json_array), &g->numberOfStemV, - &(g->stemV)); - masks_from_json(json_obj_get_type(glyphdump, "hintMasks", json_array), - &(g->numberOfHintMasks), &(g->hintMasks)); - masks_from_json(json_obj_get_type(glyphdump, "contourMasks", json_array), - &(g->numberOfContourMasks), &(g->contourMasks)); + instr_from_json(json_obj_get(glyphdump, "instructions"), g, makeInstrsForGlyph, wrongInstrsForGlyph); + stems_from_json(json_obj_get_type(glyphdump, "stemH", json_array), &g->numberOfStemH, &(g->stemH)); + stems_from_json(json_obj_get_type(glyphdump, "stemV", json_array), &g->numberOfStemV, &(g->stemV)); + masks_from_json(json_obj_get_type(glyphdump, "hintMasks", json_array), &(g->numberOfHintMasks), + &(g->hintMasks)); + masks_from_json(json_obj_get_type(glyphdump, "contourMasks", json_array), &(g->numberOfContourMasks), + &(g->contourMasks)); } else { g->instructionsLength = 0; g->instructions = NULL; @@ -668,8 +646,7 @@ static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, return g; } -table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, - caryll_dump_options *dumpopts) { +table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, caryll_dump_options *dumpopts) { if (root->type != json_object || !glyph_order) return NULL; table_glyf *glyf = NULL; json_value *table; @@ -679,14 +656,12 @@ table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order glyf->numberGlyphs = numGlyphs; glyf->glyphs = calloc(numGlyphs, sizeof(glyf_glyph *)); for (uint16_t j = 0; j < numGlyphs; j++) { - sds gname = - sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); + sds gname = sdsnewlen(table->u.object.values[j].name, table->u.object.values[j].name_length); json_value *glyphdump = table->u.object.values[j].value; glyph_order_entry *order_entry; HASH_FIND_STR(glyph_order, gname, order_entry); if (glyphdump->type == json_object && order_entry && !glyf->glyphs[order_entry->gid]) { - glyf->glyphs[order_entry->gid] = - caryll_glyf_glyph_from_json(glyphdump, order_entry, dumpopts); + glyf->glyphs[order_entry->gid] = caryll_glyf_glyph_from_json(glyphdump, order_entry, dumpopts); } sdsfree(gname); } @@ -809,12 +784,10 @@ static void glyf_write_composite(glyf_glyph *g, caryll_buffer *gbuf) { glyf_reference *r = &(g->references[rj]); uint16_t flags = ARGS_ARE_XY_VALUES | - (rj < g->numberOfReferences - 1 ? MORE_COMPONENTS - : g->instructionsLength > 0 ? WE_HAVE_INSTRUCTIONS : 0); + (rj < g->numberOfReferences - 1 ? MORE_COMPONENTS : g->instructionsLength > 0 ? WE_HAVE_INSTRUCTIONS : 0); int16_t arg1 = r->x; int16_t arg2 = r->y; - if (!(arg1 < 128 && arg1 >= -128 && arg2 < 128 && arg2 >= -128)) - flags |= ARG_1_AND_2_ARE_WORDS; + if (!(arg1 < 128 && arg1 >= -128 && arg2 < 128 && arg2 >= -128)) flags |= ARG_1_AND_2_ARE_WORDS; if (fabsf(r->b) > EPSILON || fabsf(r->c) > EPSILON) { flags |= WE_HAVE_A_TWO_BY_TWO; } else if (fabsf(r->a - 1) > EPSILON || fabsf(r->d - 1) > EPSILON) { @@ -852,8 +825,8 @@ static void glyf_write_composite(glyf_glyph *g, caryll_buffer *gbuf) { if (g->instructions) bufwrite_bytes(gbuf, g->instructionsLength, g->instructions); } } -void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, - caryll_buffer *bufloca, caryll_dump_options *dumpopts) { +void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, caryll_buffer *bufloca, + caryll_dump_options *dumpopts) { caryll_buffer *gbuf = bufnew(); uint32_t *loca = malloc((table->numberGlyphs + 1) * sizeof(uint32_t)); diff --git a/lib/tables/glyf.h b/lib/tables/glyf.h index b89e2463..5157f2cd 100644 --- a/lib/tables/glyf.h +++ b/lib/tables/glyf.h @@ -133,9 +133,8 @@ glyf_glyph *caryll_new_glyf_glyph(); table_glyf *caryll_read_glyf(caryll_packet packet, table_head *head, table_maxp *maxp); void caryll_delete_glyf(table_glyf *table); void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_dump_options *dumpopts); -table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, - caryll_dump_options *dumpopts); -void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, - caryll_buffer *bufloca, caryll_dump_options *dumpopts); +table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, caryll_dump_options *dumpopts); +void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, caryll_buffer *bufloca, + caryll_dump_options *dumpopts); #endif diff --git a/lib/tables/hdmx.c b/lib/tables/hdmx.c index 6bcb2a57..48a54562 100644 --- a/lib/tables/hdmx.c +++ b/lib/tables/hdmx.c @@ -14,8 +14,7 @@ table_hdmx *caryll_read_hdmx(caryll_packet packet, table_maxp *maxp) { hdmx->records[i].pixelSize = *(data + 8 + i * (2 + maxp->numGlyphs)); hdmx->records[i].maxWidth = *(data + 8 + i * (2 + maxp->numGlyphs) + 1); hdmx->records[i].widths = (uint8_t *)malloc(sizeof(uint8_t) * maxp->numGlyphs); - memcpy(hdmx->records[i].widths, data + 8 + i * (2 + maxp->numGlyphs) + 2, - maxp->numGlyphs); + memcpy(hdmx->records[i].widths, data + 8 + i * (2 + maxp->numGlyphs) + 2, maxp->numGlyphs); } return hdmx; diff --git a/lib/tables/head.c b/lib/tables/head.c index c03aacd6..6e1800ea 100644 --- a/lib/tables/head.c +++ b/lib/tables/head.c @@ -54,8 +54,7 @@ static const char *headFlagsLabels[] = {"baselineAtY_0", "fontIsConverted", "optimizedForCleartype", "lastResortFont"}; -static const char *macStyleLabels[] = {"bold", "italic", "underline", "outline", - "shadow", "condensed", "extended"}; +static const char *macStyleLabels[] = {"bold", "italic", "underline", "outline", "shadow", "condensed", "extended"}; void caryll_head_to_json(table_head *table, json_value *root, caryll_dump_options *dumpopts) { if (!table) return; json_value *head = json_object_new(15); diff --git a/lib/tables/hhea.c b/lib/tables/hhea.c index 5124f21d..6dc3c124 100644 --- a/lib/tables/hhea.c +++ b/lib/tables/hhea.c @@ -51,8 +51,7 @@ void caryll_hhea_to_json(table_hhea *table, json_value *root, caryll_dump_option json_object_push(hhea, "caretSlopeRise", json_integer_new(table->caretSlopeRise)); json_object_push(hhea, "yMcaretSlopeRunax", json_integer_new(table->caretSlopeRun)); json_object_push(hhea, "caretOffset", json_integer_new(table->caretOffset)); - json_object_push(hhea, "lowestmetricDataFormatRecPPEM", - json_integer_new(table->metricDataFormat)); + json_object_push(hhea, "lowestmetricDataFormatRecPPEM", json_integer_new(table->metricDataFormat)); json_object_push(hhea, "numberOfMetrics", json_integer_new(table->numberOfMetrics)); json_object_push(root, "hhea", hhea); } @@ -72,8 +71,7 @@ table_hhea *caryll_hhea_from_json(json_value *root, caryll_dump_options *dumpopt hhea->caretSlopeRise = json_obj_getnum_fallback(table, "caretSlopeRise", 0); hhea->caretSlopeRun = json_obj_getnum_fallback(table, "yMcaretSlopeRunax", 0); hhea->caretOffset = json_obj_getnum_fallback(table, "caretOffset", 0); - hhea->metricDataFormat = - json_obj_getnum_fallback(table, "lowestmetricDataFormatRecPPEM", 0); + hhea->metricDataFormat = json_obj_getnum_fallback(table, "lowestmetricDataFormatRecPPEM", 0); hhea->numberOfMetrics = json_obj_getnum_fallback(table, "numberOfMetrics", 0); } return hhea; diff --git a/lib/tables/hmtx.c b/lib/tables/hmtx.c index 92359463..826a6f6e 100644 --- a/lib/tables/hmtx.c +++ b/lib/tables/hmtx.c @@ -1,9 +1,7 @@ #include "hmtx.h" table_hmtx *caryll_read_hmtx(caryll_packet packet, table_hhea *hhea, table_maxp *maxp) { - if (!hhea || !maxp || !hhea->numberOfMetrics || maxp->numGlyphs < hhea->numberOfMetrics) { - return NULL; - } + if (!hhea || !maxp || !hhea->numberOfMetrics || maxp->numGlyphs < hhea->numberOfMetrics) { return NULL; } FOR_TABLE('hmtx', table) { font_file_pointer data = table.data; uint32_t length = table.length; @@ -23,9 +21,7 @@ table_hmtx *caryll_read_hmtx(caryll_packet packet, table_hhea *hhea, table_maxp hmtx->metrics[ia].lsb = read_16u(data + ia * 4 + 2); } - for (uint32_t ik = 0; ik < count_k; ik++) { - hmtx->leftSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); - } + for (uint32_t ik = 0; ik < count_k; ik++) { hmtx->leftSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); } return hmtx; HMTX_CORRUPTED: @@ -42,8 +38,7 @@ void caryll_delete_hmtx(table_hmtx *table) { free(table); } -caryll_buffer *caryll_write_hmtx(table_hmtx *hmtx, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_hmtx(table_hmtx *hmtx, uint16_t count_a, uint16_t count_k, caryll_dump_options *dumpopts) { caryll_buffer *buf = bufnew(); if (!hmtx) return buf; if (hmtx->metrics) { diff --git a/lib/tables/hmtx.h b/lib/tables/hmtx.h index 93315cfe..3f2e3305 100644 --- a/lib/tables/hmtx.h +++ b/lib/tables/hmtx.h @@ -20,7 +20,6 @@ typedef struct { table_hmtx *caryll_read_hmtx(caryll_packet packet, table_hhea *hhea, table_maxp *maxp); void caryll_delete_hmtx(table_hmtx *table); -caryll_buffer *caryll_write_hmtx(table_hmtx *table, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts); +caryll_buffer *caryll_write_hmtx(table_hmtx *table, uint16_t count_a, uint16_t count_k, caryll_dump_options *dumpopts); #endif diff --git a/lib/tables/name.c b/lib/tables/name.c index bc7e7333..431102b6 100644 --- a/lib/tables/name.c +++ b/lib/tables/name.c @@ -66,8 +66,7 @@ void caryll_name_to_json(table_name *table, json_value *root, caryll_dump_option json_object_push(record, "encodingID", json_integer_new(r->encodingID)); json_object_push(record, "languageID", json_integer_new(r->languageID)); json_object_push(record, "nameID", json_integer_new(r->nameID)); - json_object_push(record, "nameString", - json_string_new_length((uint32_t)sdslen(r->nameString), r->nameString)); + json_object_push(record, "nameString", json_string_new_length((uint32_t)sdslen(r->nameString), r->nameString)); json_array_push(name, record); } json_object_push(root, "name", name); @@ -125,8 +124,7 @@ table_name *caryll_name_from_json(json_value *root, caryll_dump_options *dumpopt name->records[jj]->nameID = json_obj_getint(record, "nameID"); json_value *str = json_obj_get_type(record, "nameString", json_string); - name->records[jj]->nameString = - sdsnewlen(str->u.string.ptr, str->u.string.length); + name->records[jj]->nameString = sdsnewlen(str->u.string.ptr, str->u.string.length); jj += 1; } } diff --git a/lib/tables/otl/GDEF.c b/lib/tables/otl/GDEF.c index f1636fc0..970f01c2 100644 --- a/lib/tables/otl/GDEF.c +++ b/lib/tables/otl/GDEF.c @@ -32,8 +32,7 @@ static caret_value readCaretValue(font_file_pointer data, uint32_t tableLength, FAIL: return v; } -static caret_value_record readLigCaretRecord(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +static caret_value_record readLigCaretRecord(font_file_pointer data, uint32_t tableLength, uint32_t offset) { checkLength(offset + 2); caret_value_record g; g.values = NULL; @@ -42,8 +41,7 @@ static caret_value_record readLigCaretRecord(font_file_pointer data, uint32_t ta NEW_N(g.values, g.caretCount); for (uint16_t j = 0; j < g.caretCount; j++) { - g.values[j] = - readCaretValue(data, tableLength, offset + read_16u(data + offset + 2 + j * 2)); + g.values[j] = readCaretValue(data, tableLength, offset + read_16u(data + offset + 2 + j * 2)); } return g; FAIL: @@ -59,17 +57,15 @@ table_GDEF *caryll_read_GDEF(caryll_packet packet) { checkLength(12); gdef = caryll_new_GDEF(); uint16_t classdefOffset = read_16u(data + 4); - if (classdefOffset) { - gdef->glyphClassDef = caryll_read_classdef(data, tableLength, classdefOffset); - } + if (classdefOffset) { gdef->glyphClassDef = caryll_read_classdef(data, tableLength, classdefOffset); } uint16_t ligCaretOffset = read_16u(data + 8); if (ligCaretOffset) { checkLength(ligCaretOffset + 4); NEW(gdef->ligCarets); gdef->ligCarets->carets = NULL; - otl_coverage *cov = caryll_read_coverage( - data, tableLength, ligCaretOffset + read_16u(data + ligCaretOffset)); + otl_coverage *cov = + caryll_read_coverage(data, tableLength, ligCaretOffset + read_16u(data + ligCaretOffset)); if (!cov || cov->numGlyphs != read_16u(data + ligCaretOffset + 2)) goto FAIL; checkLength(ligCaretOffset + 4 + cov->numGlyphs * 2); if (cov->numGlyphs) { @@ -77,8 +73,7 @@ table_GDEF *caryll_read_GDEF(caryll_packet packet) { NEW_N(gdef->ligCarets->carets, cov->numGlyphs); for (uint16_t j = 0; j < cov->numGlyphs; j++) { gdef->ligCarets->carets[j] = readLigCaretRecord( - data, tableLength, - ligCaretOffset + read_16u(data + ligCaretOffset + 4 + j * 2)); + data, tableLength, ligCaretOffset + read_16u(data + ligCaretOffset + 4 + j * 2)); } } else { caryll_delete_coverage(cov); @@ -100,12 +95,9 @@ table_GDEF *caryll_read_GDEF(caryll_packet packet) { void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_dump_options *dumpopts) { if (!gdef) return; json_value *_gdef = json_object_new(4); - if (gdef->glyphClassDef) { - json_object_push(_gdef, "glyphClassDef", caryll_classdef_to_json(gdef->glyphClassDef)); - } + if (gdef->glyphClassDef) { json_object_push(_gdef, "glyphClassDef", caryll_classdef_to_json(gdef->glyphClassDef)); } if (gdef->markAttachClassDef) { - json_object_push(_gdef, "markAttachClassDef", - caryll_classdef_to_json(gdef->markAttachClassDef)); + json_object_push(_gdef, "markAttachClassDef", caryll_classdef_to_json(gdef->markAttachClassDef)); } if (gdef->ligCarets && gdef->ligCarets->coverage && gdef->ligCarets->coverage->numGlyphs) { json_value *_carets = json_object_new(gdef->ligCarets->coverage->numGlyphs); @@ -116,13 +108,9 @@ void caryll_GDEF_to_json(table_GDEF *gdef, json_value *root, caryll_dump_options for (uint16_t k = 0; k < gdef->ligCarets->carets[j].caretCount; k++) { json_value *_cv = json_object_new(1); if (gdef->ligCarets->carets[j].values[k].format == 2) { - json_object_push( - _cv, "atPoint", - json_integer_new(gdef->ligCarets->carets[j].values[k].pointIndex)); + json_object_push(_cv, "atPoint", json_integer_new(gdef->ligCarets->carets[j].values[k].pointIndex)); } else { - json_object_push( - _cv, "at", - json_integer_new(gdef->ligCarets->carets[j].values[k].coordiante)); + json_object_push(_cv, "at", json_integer_new(gdef->ligCarets->carets[j].values[k].coordiante)); } json_array_push(_record, _cv); } @@ -177,8 +165,7 @@ table_GDEF *caryll_GDEF_from_json(json_value *root, caryll_dump_options *dumpopt if ((table = json_obj_get_type(root, "GDEF", json_object))) { gdef = caryll_new_GDEF(); gdef->glyphClassDef = caryll_classdef_from_json(json_obj_get(table, "glyphClassDef")); - gdef->markAttachClassDef = - caryll_classdef_from_json(json_obj_get(table, "markAttachClassDef")); + gdef->markAttachClassDef = caryll_classdef_from_json(json_obj_get(table, "markAttachClassDef")); gdef->ligCarets = ligCaretFromJson(json_obj_get(table, "ligCarets")); } return gdef; diff --git a/lib/tables/otl/chaining.c b/lib/tables/otl/chaining.c index 3b63bcdc..40e6fb96 100644 --- a/lib/tables/otl/chaining.c +++ b/lib/tables/otl/chaining.c @@ -22,9 +22,7 @@ void delete_otl_chaining_subtable(otl_subtable *_subtable) { void caryll_delete_chaining(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) { - delete_otl_chaining_subtable(lookup->subtables[j]); - } + for (uint16_t j = 0; j < lookup->subtableCount; j++) { delete_otl_chaining_subtable(lookup->subtables[j]); } free(lookup->subtables); } free(lookup); @@ -50,8 +48,8 @@ typedef struct { otl_classdef *fc; } classdefs; -otl_coverage *singleCoverage(font_file_pointer data, uint32_t tableLength, uint16_t gid, - uint32_t _offset, uint16_t kind, void *userdata) { +otl_coverage *singleCoverage(font_file_pointer data, uint32_t tableLength, uint16_t gid, uint32_t _offset, + uint16_t kind, void *userdata) { otl_coverage *cov; NEW(cov); cov->numGlyphs = 1; @@ -60,8 +58,8 @@ otl_coverage *singleCoverage(font_file_pointer data, uint32_t tableLength, uint1 cov->glyphs[0].name = NULL; return cov; } -otl_coverage *classCoverage(font_file_pointer data, uint32_t tableLength, uint16_t cls, - uint32_t _offset, uint16_t kind, void *_classdefs) { +otl_coverage *classCoverage(font_file_pointer data, uint32_t tableLength, uint16_t cls, uint32_t _offset, uint16_t kind, + void *_classdefs) { classdefs *defs = (classdefs *)_classdefs; otl_classdef *cd = (kind == 1 ? defs->bc : kind == 2 ? defs->ic : defs->fc); otl_coverage *cov; @@ -79,16 +77,15 @@ otl_coverage *classCoverage(font_file_pointer data, uint32_t tableLength, uint16 if (cd->classes[j] == cls) { cov->glyphs[jj++] = cd->glyphs[j]; } return cov; } -otl_coverage *format3Coverage(font_file_pointer data, uint32_t tableLength, uint16_t shift, - uint32_t _offset, uint16_t kind, void *userdata) { +otl_coverage *format3Coverage(font_file_pointer data, uint32_t tableLength, uint16_t shift, uint32_t _offset, + uint16_t kind, void *userdata) { return caryll_read_coverage(data, tableLength, _offset + shift - 2); } -typedef otl_coverage *(*CoverageReaderHandler)(font_file_pointer, uint32_t, uint16_t, uint32_t, - uint16_t, void *); -otl_chaining_rule *GeneralReadContextualRule(font_file_pointer data, uint32_t tableLength, - uint32_t offset, uint16_t startGID, bool minusOne, - CoverageReaderHandler fn, void *userdata) { +typedef otl_coverage *(*CoverageReaderHandler)(font_file_pointer, uint32_t, uint16_t, uint32_t, uint16_t, void *); +otl_chaining_rule *GeneralReadContextualRule(font_file_pointer data, uint32_t tableLength, uint32_t offset, + uint16_t startGID, bool minusOne, CoverageReaderHandler fn, + void *userdata) { otl_chaining_rule *rule; NEW(rule); rule->match = NULL; @@ -116,10 +113,8 @@ otl_chaining_rule *GeneralReadContextualRule(font_file_pointer data, uint32_t ta NEW_N(rule->apply, rule->applyCount); for (uint16_t j = 0; j < nApply; j++) { rule->apply[j].index = - rule->inputBegins + - read_16u(data + offset + 4 + 2 * (rule->matchCount - minusOneQ) + j * 4); - rule->apply[j].lookupIndex = - read_16u(data + offset + 4 + 2 * (rule->matchCount - minusOneQ) + j * 4 + 2); + rule->inputBegins + read_16u(data + offset + 4 + 2 * (rule->matchCount - minusOneQ) + j * 4); + rule->apply[j].lookupIndex = read_16u(data + offset + 4 + 2 * (rule->matchCount - minusOneQ) + j * 4 + 2); rule->apply[j].lookupName = NULL; } reverseBacktracks(rule); @@ -130,8 +125,7 @@ otl_chaining_rule *GeneralReadContextualRule(font_file_pointer data, uint32_t ta return NULL; } -otl_subtable *caryll_read_contextual(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_contextual(font_file_pointer data, uint32_t tableLength, uint32_t offset) { uint16_t format = 0; otl_subtable *_subtable; NEW(_subtable); @@ -171,9 +165,8 @@ otl_subtable *caryll_read_contextual(font_file_pointer data, uint32_t tableLengt uint16_t srsCount = read_16u(data + srsOffset); for (uint16_t k = 0; k < srsCount; k++) { uint32_t srOffset = srsOffset + read_16u(data + srsOffset + 2 + k * 2); - subtable->rules[jj] = GeneralReadContextualRule(data, tableLength, srOffset, - firstCoverage->glyphs[j].gid, true, - singleCoverage, NULL); + subtable->rules[jj] = GeneralReadContextualRule( + data, tableLength, srOffset, firstCoverage->glyphs[j].gid, true, singleCoverage, NULL); jj += 1; } } @@ -207,10 +200,9 @@ otl_subtable *caryll_read_contextual(font_file_pointer data, uint32_t tableLengt if (srcOffset) { uint16_t srsCount = read_16u(data + offset + srcOffset); for (uint16_t k = 0; k < srsCount; k++) { - uint32_t srOffset = - offset + srcOffset + read_16u(data + offset + srcOffset + 2 + k * 2); - subtable->rules[jj] = GeneralReadContextualRule(data, tableLength, srOffset, j, - true, classCoverage, cds); + uint32_t srOffset = offset + srcOffset + read_16u(data + offset + srcOffset + 2 + k * 2); + subtable->rules[jj] = + GeneralReadContextualRule(data, tableLength, srOffset, j, true, classCoverage, cds); jj += 1; } } @@ -224,8 +216,7 @@ otl_subtable *caryll_read_contextual(font_file_pointer data, uint32_t tableLengt // Contextual Substitution Subtable, Coverage based. subtable->rulesCount = 1; NEW_N(subtable->rules, 1); - subtable->rules[0] = GeneralReadContextualRule(data, tableLength, offset + 2, 0, false, - format3Coverage, NULL); + subtable->rules[0] = GeneralReadContextualRule(data, tableLength, offset + 2, 0, false, format3Coverage, NULL); return _subtable; } FAIL: @@ -234,9 +225,8 @@ otl_subtable *caryll_read_contextual(font_file_pointer data, uint32_t tableLengt return NULL; } -otl_chaining_rule *GeneralReadChainingRule(font_file_pointer data, uint32_t tableLength, - uint32_t offset, uint16_t startGID, bool minusOne, - CoverageReaderHandler fn, void *userdata) { +otl_chaining_rule *GeneralReadChainingRule(font_file_pointer data, uint32_t tableLength, uint32_t offset, + uint16_t startGID, bool minusOne, CoverageReaderHandler fn, void *userdata) { otl_chaining_rule *rule; NEW(rule); rule->match = NULL; @@ -277,10 +267,8 @@ otl_chaining_rule *GeneralReadChainingRule(font_file_pointer data, uint32_t tabl NEW_N(rule->apply, rule->applyCount); for (uint16_t j = 0; j < nApply; j++) { rule->apply[j].index = - rule->inputBegins + - read_16u(data + offset + 8 + 2 * (rule->matchCount - minusOneQ) + j * 4); - rule->apply[j].lookupIndex = - read_16u(data + offset + 8 + 2 * (rule->matchCount - minusOneQ) + j * 4 + 2); + rule->inputBegins + read_16u(data + offset + 8 + 2 * (rule->matchCount - minusOneQ) + j * 4); + rule->apply[j].lookupIndex = read_16u(data + offset + 8 + 2 * (rule->matchCount - minusOneQ) + j * 4 + 2); rule->apply[j].lookupName = NULL; } reverseBacktracks(rule); @@ -332,9 +320,8 @@ otl_subtable *caryll_read_chaining(font_file_pointer data, uint32_t tableLength, uint16_t srsCount = read_16u(data + srsOffset); for (uint16_t k = 0; k < srsCount; k++) { uint32_t srOffset = srsOffset + read_16u(data + srsOffset + 2 + k * 2); - subtable->rules[jj] = GeneralReadChainingRule(data, tableLength, srOffset, - firstCoverage->glyphs[j].gid, true, - singleCoverage, NULL); + subtable->rules[jj] = GeneralReadChainingRule(data, tableLength, srOffset, firstCoverage->glyphs[j].gid, + true, singleCoverage, NULL); jj += 1; } } @@ -370,8 +357,8 @@ otl_subtable *caryll_read_chaining(font_file_pointer data, uint32_t tableLength, for (uint16_t k = 0; k < srsCount; k++) { uint16_t dsrOffset = read_16u(data + offset + srcOffset + 2 + k * 2); uint32_t srOffset = offset + srcOffset + dsrOffset; - subtable->rules[jj] = GeneralReadChainingRule(data, tableLength, srOffset, j, - true, classCoverage, cds); + subtable->rules[jj] = + GeneralReadChainingRule(data, tableLength, srOffset, j, true, classCoverage, cds); jj += 1; } } @@ -388,8 +375,7 @@ otl_subtable *caryll_read_chaining(font_file_pointer data, uint32_t tableLength, // This table has exactly one rule within it, and i love it. subtable->rulesCount = 1; NEW_N(subtable->rules, 1); - subtable->rules[0] = - GeneralReadChainingRule(data, tableLength, offset + 2, 0, false, format3Coverage, NULL); + subtable->rules[0] = GeneralReadChainingRule(data, tableLength, offset + 2, 0, false, format3Coverage, NULL); return _subtable; } FAIL: @@ -402,13 +388,13 @@ json_value *caryll_chaining_to_json(otl_subtable *_subtable) { subtable_chaining *subtable = &(_subtable->chaining); otl_chaining_rule *rule = subtable->rules[0]; json_value *_st = json_object_new(4); - + json_value *_match = json_array_new(rule->matchCount); for (uint16_t j = 0; j < rule->matchCount; j++) { json_array_push(_match, caryll_coverage_to_json(rule->match[j])); } json_object_push(_st, "match", _match); - + json_value *_apply = json_array_new(rule->applyCount); for (uint16_t j = 0; j < rule->applyCount; j++) { json_value *_application = json_object_new(2); @@ -417,7 +403,7 @@ json_value *caryll_chaining_to_json(otl_subtable *_subtable) { json_array_push(_apply, _application); } json_object_push(_st, "apply", preserialize(_apply)); - + json_object_push(_st, "inputBegins", json_integer_new(rule->inputBegins)); json_object_push(_st, "inputEnds", json_integer_new(rule->inputEnds)); return _st; @@ -436,19 +422,19 @@ otl_subtable *caryll_chaining_from_json(json_value *_subtable) { subtable->bc = NULL; subtable->ic = NULL; subtable->fc = NULL; - + NEW(subtable->rules); NEW(subtable->rules[0]); otl_chaining_rule *rule = subtable->rules[0]; - + rule->matchCount = _match->u.array.length; NEW_N(rule->match, rule->matchCount); rule->applyCount = _apply->u.array.length; NEW_N(rule->apply, rule->applyCount); - + rule->inputBegins = json_obj_getnum_fallback(_subtable, "inputBegins", 0); rule->inputEnds = json_obj_getnum_fallback(_subtable, "inputEnds", rule->matchCount); - + for (uint16_t j = 0; j < rule->matchCount; j++) { rule->match[j] = caryll_coverage_from_json(_match->u.array.values[j]); } diff --git a/lib/tables/otl/classdef.c b/lib/tables/otl/classdef.c index f681b4c9..b484a4e6 100644 --- a/lib/tables/otl/classdef.c +++ b/lib/tables/otl/classdef.c @@ -155,8 +155,7 @@ otl_classdef *caryll_classdef_from_json(json_value *_cd) { NEW_N(cd->classes, cd->numGlyphs); uint16_t maxclass = 0; for (uint16_t j = 0; j < _cd->u.object.length; j++) { - cd->glyphs[j].name = - sdsnewlen(_cd->u.object.values[j].name, _cd->u.object.values[j].name_length); + cd->glyphs[j].name = sdsnewlen(_cd->u.object.values[j].name, _cd->u.object.values[j].name_length); json_value *_cid = _cd->u.object.values[j].value; if (_cid->type == json_integer) { cd->classes[j] = _cid->u.integer; diff --git a/lib/tables/otl/coverage.c b/lib/tables/otl/coverage.c index a0ceb689..1ed6f063 100644 --- a/lib/tables/otl/coverage.c +++ b/lib/tables/otl/coverage.c @@ -122,8 +122,8 @@ otl_coverage *caryll_coverage_from_json(json_value *cov) { for (uint16_t j = 0; j < c->numGlyphs; j++) { if (cov->u.array.values[j]->type == json_string) { c->glyphs[jj].gid = 0; - c->glyphs[jj].name = sdsnewlen(cov->u.array.values[j]->u.string.ptr, - cov->u.array.values[j]->u.string.length); + c->glyphs[jj].name = + sdsnewlen(cov->u.array.values[j]->u.string.ptr, cov->u.array.values[j]->u.string.length); jj++; } } @@ -135,9 +135,7 @@ caryll_buffer *caryll_write_coverage(otl_coverage *coverage) { caryll_buffer *format1 = bufnew(); bufwrite16b(format1, 1); bufwrite16b(format1, coverage->numGlyphs); - for (uint16_t j = 0; j < coverage->numGlyphs; j++) { - bufwrite16b(format1, coverage->glyphs[j].gid); - } + for (uint16_t j = 0; j < coverage->numGlyphs; j++) { bufwrite16b(format1, coverage->glyphs[j].gid); } if (coverage->numGlyphs < 2) return format1; caryll_buffer *format2 = bufnew(); diff --git a/lib/tables/otl/extend.c b/lib/tables/otl/extend.c index c0139949..b3561310 100644 --- a/lib/tables/otl/extend.c +++ b/lib/tables/otl/extend.c @@ -2,15 +2,15 @@ // Extended tables are special // We will only deal with reading, and they will be flatten. -static otl_subtable *_caryll_read_otl_extend(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset, otl_lookup_type BASIS) { +static otl_subtable *_caryll_read_otl_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, + otl_lookup_type BASIS) { otl_subtable *_subtable; NEW(_subtable); checkLength(subtableOffset + 8); subtable_extend *subtable = &(_subtable->extend); subtable->type = read_16u(data + subtableOffset + 2) + BASIS; - subtable->subtable = caryll_read_otl_subtable( - data, tableLength, subtableOffset + read_32u(data + subtableOffset + 4), subtable->type); + subtable->subtable = caryll_read_otl_subtable(data, tableLength, + subtableOffset + read_32u(data + subtableOffset + 4), subtable->type); goto OK; FAIL: FREE(_subtable); @@ -18,11 +18,9 @@ static otl_subtable *_caryll_read_otl_extend(font_file_pointer data, uint32_t ta return _subtable; } -otl_subtable *caryll_read_otl_gsub_extend(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset) { +otl_subtable *caryll_read_otl_gsub_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset) { return _caryll_read_otl_extend(data, tableLength, subtableOffset, otl_type_gsub_unknown); } -otl_subtable *caryll_read_otl_gpos_extend(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset) { +otl_subtable *caryll_read_otl_gpos_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset) { return _caryll_read_otl_extend(data, tableLength, subtableOffset, otl_type_gpos_unknown); } diff --git a/lib/tables/otl/extend.h b/lib/tables/otl/extend.h index 10e024c2..f6b3a76f 100644 --- a/lib/tables/otl/extend.h +++ b/lib/tables/otl/extend.h @@ -2,8 +2,6 @@ #define CARYLL_TABLES_OTL_EXTEND_H #include "otl.h" -otl_subtable *caryll_read_otl_gsub_extend(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); -otl_subtable *caryll_read_otl_gpos_extend(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_otl_gsub_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); +otl_subtable *caryll_read_otl_gpos_extend(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); #endif diff --git a/lib/tables/otl/gpos-common.c b/lib/tables/otl/gpos-common.c index c712e810..bf9b4869 100644 --- a/lib/tables/otl/gpos-common.c +++ b/lib/tables/otl/gpos-common.c @@ -89,8 +89,7 @@ otl_position_value position_zero() { return v; } // Read a position value from SFNT -otl_position_value read_gpos_value(font_file_pointer data, uint32_t tableLength, uint32_t offset, - uint16_t format) { +otl_position_value read_gpos_value(font_file_pointer data, uint32_t tableLength, uint32_t offset, uint16_t format) { otl_position_value v = {0, 0, 0, 0}; if (tableLength < offset + position_format_length(format)) return v; if (format & FORMAT_DX) { v.dx = read_16u(data + offset), offset += 2; }; @@ -131,6 +130,4 @@ void write_gpos_value(caryll_buffer *buf, otl_position_value v, uint16_t format) // Anchor functions int getPositon(otl_anchor anchor) { return ((uint16_t)anchor.x) << 16 | ((uint16_t)anchor.y); } -int byAnchorIndex(anchor_aggeration_hash *a, anchor_aggeration_hash *b) { - return a->index - b->index; -} +int byAnchorIndex(anchor_aggeration_hash *a, anchor_aggeration_hash *b) { return a->index - b->index; } diff --git a/lib/tables/otl/gpos-common.h b/lib/tables/otl/gpos-common.h index b180cf2a..1aa1a962 100644 --- a/lib/tables/otl/gpos-common.h +++ b/lib/tables/otl/gpos-common.h @@ -22,8 +22,7 @@ extern const uint8_t bits_in[0x100]; uint8_t position_format_length(uint16_t format); otl_position_value position_zero(); -otl_position_value read_gpos_value(font_file_pointer data, uint32_t tableLength, uint32_t offset, - uint16_t format); +otl_position_value read_gpos_value(font_file_pointer data, uint32_t tableLength, uint32_t offset, uint16_t format); uint8_t required_position_format(otl_position_value v); void write_gpos_value(caryll_buffer *buf, otl_position_value v, uint16_t format); json_value *gpos_value_to_json(otl_position_value value); @@ -40,19 +39,19 @@ typedef struct { int getPositon(otl_anchor anchor); int byAnchorIndex(anchor_aggeration_hash *a, anchor_aggeration_hash *b); -#define ANCHOR_AGGERATOR_PUSH(agh, anchor) \ - if ((anchor).present) { \ - anchor_aggeration_hash *s; \ - int position = getPositon(anchor); \ - HASH_FIND_INT((agh), &position, s); \ - if (!s) { \ - NEW(s); \ - s->position = position; \ - s->x = (anchor).x; \ - s->y = (anchor).y; \ - s->index = HASH_COUNT(agh); \ - HASH_ADD_INT(agh, position, s); \ - } \ +#define ANCHOR_AGGERATOR_PUSH(agh, anchor) \ + if ((anchor).present) { \ + anchor_aggeration_hash *s; \ + int position = getPositon(anchor); \ + HASH_FIND_INT((agh), &position, s); \ + if (!s) { \ + NEW(s); \ + s->position = position; \ + s->x = (anchor).x; \ + s->y = (anchor).y; \ + s->index = HASH_COUNT(agh); \ + HASH_ADD_INT(agh, position, s); \ + } \ } #endif diff --git a/lib/tables/otl/gpos-cursive.c b/lib/tables/otl/gpos-cursive.c index c22ae8de..c2328869 100644 --- a/lib/tables/otl/gpos-cursive.c +++ b/lib/tables/otl/gpos-cursive.c @@ -15,8 +15,7 @@ void caryll_delete_gpos_cursive(otl_lookup *lookup) { FREE(lookup); } } -otl_subtable *caryll_read_gpos_cursive(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_gpos_cursive(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_subtable *_subtable; NEW(_subtable); subtable_gpos_cursive *subtable = &(_subtable->gpos_cursive); @@ -25,8 +24,7 @@ otl_subtable *caryll_read_gpos_cursive(font_file_pointer data, uint32_t tableLen subtable->exit = NULL; checkLength(offset + 6); - subtable->coverage = - caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); + subtable->coverage = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); if (!subtable->coverage || subtable->coverage->numGlyphs == 0) goto FAIL; NEW_N(subtable->enter, subtable->coverage->numGlyphs); NEW_N(subtable->exit, subtable->coverage->numGlyphs); @@ -40,12 +38,8 @@ otl_subtable *caryll_read_gpos_cursive(font_file_pointer data, uint32_t tableLen uint16_t exitOffset = read_16u(data + offset + 6 + 4 * j + 2); subtable->enter[j] = otl_anchor_absent(); subtable->exit[j] = otl_anchor_absent(); - if (enterOffset) { - subtable->enter[j] = otl_read_anchor(data, tableLength, offset + enterOffset); - } - if (exitOffset) { - subtable->exit[j] = otl_read_anchor(data, tableLength, offset + exitOffset); - } + if (enterOffset) { subtable->enter[j] = otl_read_anchor(data, tableLength, offset + enterOffset); } + if (exitOffset) { subtable->exit[j] = otl_read_anchor(data, tableLength, offset + exitOffset); } } goto OK; FAIL: @@ -79,15 +73,11 @@ otl_subtable *caryll_gpos_cursive_from_json(json_value *_subtable) { NEW_N(subtable->exit, _subtable->u.object.length); uint16_t jj = 0; for (uint16_t j = 0; j < _subtable->u.object.length; j++) { - if (_subtable->u.object.values[j].value && - _subtable->u.object.values[j].value->type == json_object) { - sds gname = sdsnewlen(_subtable->u.object.values[j].name, - _subtable->u.object.values[j].name_length); + if (_subtable->u.object.values[j].value && _subtable->u.object.values[j].value->type == json_object) { + sds gname = sdsnewlen(_subtable->u.object.values[j].name, _subtable->u.object.values[j].name_length); subtable->coverage->glyphs[jj].name = gname; - subtable->enter[jj] = - otl_anchor_from_json(json_obj_get(_subtable->u.object.values[j].value, "enter")); - subtable->exit[jj] = - otl_anchor_from_json(json_obj_get(_subtable->u.object.values[j].value, "exit")); + subtable->enter[jj] = otl_anchor_from_json(json_obj_get(_subtable->u.object.values[j].value, "enter")); + subtable->exit[jj] = otl_anchor_from_json(json_obj_get(_subtable->u.object.values[j].value, "exit")); jj++; } } diff --git a/lib/tables/otl/gpos-cursive.h b/lib/tables/otl/gpos-cursive.h index ede45763..f6aa4a1e 100644 --- a/lib/tables/otl/gpos-cursive.h +++ b/lib/tables/otl/gpos-cursive.h @@ -4,8 +4,7 @@ #include "otl.h" void caryll_delete_gpos_cursive(otl_lookup *lookup); -otl_subtable *caryll_read_gpos_cursive(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gpos_cursive(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gpos_cursive_to_json(otl_subtable *_subtable); otl_subtable *caryll_gpos_cursive_from_json(json_value *_subtable); caryll_buffer *caryll_write_gpos_cursive(otl_subtable *_subtable); diff --git a/lib/tables/otl/gpos-mark-to-ligature.c b/lib/tables/otl/gpos-mark-to-ligature.c index eeb69280..3a207bbe 100644 --- a/lib/tables/otl/gpos-mark-to-ligature.c +++ b/lib/tables/otl/gpos-mark-to-ligature.c @@ -31,30 +31,26 @@ static void delete_mtl_subtable(otl_subtable *_subtable) { void caryll_delete_gpos_mark_to_ligature(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) - delete_mtl_subtable(lookup->subtables[j]); + for (uint16_t j = 0; j < lookup->subtableCount; j++) delete_mtl_subtable(lookup->subtables[j]); free(lookup->subtables); } free(lookup); } } -otl_subtable *caryll_read_gpos_mark_to_ligature(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_gpos_mark_to_ligature(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_subtable *_subtable; NEW(_subtable); subtable_gpos_mark_to_ligature *subtable = &(_subtable->gpos_mark_to_ligature); if (tableLength < offset + 12) goto FAIL; subtable->marks = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); subtable->bases = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 4)); - if (!subtable->marks || subtable->marks->numGlyphs == 0 || !subtable->bases || - subtable->bases->numGlyphs == 0) + if (!subtable->marks || subtable->marks->numGlyphs == 0 || !subtable->bases || subtable->bases->numGlyphs == 0) goto FAIL; subtable->classCount = read_16u(data + offset + 6); uint32_t markArrayOffset = offset + read_16u(data + offset + 8); subtable->markArray = otl_read_mark_array(data, tableLength, markArrayOffset); - if (!subtable->markArray || subtable->markArray->markCount != subtable->marks->numGlyphs) - goto FAIL; + if (!subtable->markArray || subtable->markArray->markCount != subtable->marks->numGlyphs) goto FAIL; uint32_t ligArrayOffset = offset + read_16u(data + offset + 10); checkLength(ligArrayOffset + 2 + 2 * subtable->bases->numGlyphs); @@ -68,8 +64,7 @@ otl_subtable *caryll_read_gpos_mark_to_ligature(font_file_pointer data, uint32_t checkLength(ligAttachOffset + 2); subtable->ligArray[j]->componentCount = read_16u(data + ligAttachOffset); - checkLength(ligAttachOffset + 2 + - 2 * subtable->ligArray[j]->componentCount * subtable->classCount); + checkLength(ligAttachOffset + 2 + 2 * subtable->ligArray[j]->componentCount * subtable->classCount); NEW_N(subtable->ligArray[j]->anchors, subtable->ligArray[j]->componentCount); uint32_t _offset = ligAttachOffset + 2; @@ -103,10 +98,8 @@ json_value *caryll_gpos_mark_to_ligature_to_json(otl_subtable *st) { json_value *_bases = json_object_new(subtable->bases->numGlyphs); for (uint16_t j = 0; j < subtable->marks->numGlyphs; j++) { json_value *_mark = json_object_new(3); - sds markClassName = - sdscatfmt(sdsempty(), "ac_%i", subtable->markArray->records[j].markClass); - json_object_push(_mark, "class", - json_string_new_length((uint32_t)sdslen(markClassName), markClassName)); + sds markClassName = sdscatfmt(sdsempty(), "ac_%i", subtable->markArray->records[j].markClass); + json_object_push(_mark, "class", json_string_new_length((uint32_t)sdslen(markClassName), markClassName)); sdsfree(markClassName); json_object_push(_mark, "x", json_integer_new(subtable->markArray->records[j].anchor.x)); json_object_push(_mark, "y", json_integer_new(subtable->markArray->records[j].anchor.y)); @@ -123,8 +116,7 @@ json_value *caryll_gpos_mark_to_ligature_to_json(otl_subtable *st) { json_object_push(_anchor, "x", json_integer_new(base->anchors[k][m].x)); json_object_push(_anchor, "y", json_integer_new(base->anchors[k][m].y)); sds markClassName = sdscatfmt(sdsempty(), "ac_%i", m); - json_object_push_length(_bk, (uint32_t)sdslen(markClassName), markClassName, - _anchor); + json_object_push_length(_bk, (uint32_t)sdslen(markClassName), markClassName, _anchor); sdsfree(markClassName); } } @@ -143,8 +135,7 @@ typedef struct { uint16_t classID; UT_hash_handle hh; } classname_hash; -static void parseMarks(json_value *_marks, subtable_gpos_mark_to_ligature *subtable, - classname_hash **h) { +static void parseMarks(json_value *_marks, subtable_gpos_mark_to_ligature *subtable, classname_hash **h) { NEW(subtable->marks); subtable->marks->numGlyphs = _marks->u.object.length; NEW_N(subtable->marks->glyphs, subtable->marks->numGlyphs); @@ -180,8 +171,7 @@ static void parseMarks(json_value *_marks, subtable_gpos_mark_to_ligature *subta subtable->markArray->records[j].anchor.y = json_obj_getnum(anchorRecord, "y"); } } -static void parseBases(json_value *_bases, subtable_gpos_mark_to_ligature *subtable, - classname_hash **h) { +static void parseBases(json_value *_bases, subtable_gpos_mark_to_ligature *subtable, classname_hash **h) { uint16_t classCount = HASH_COUNT(*h); NEW(subtable->bases); subtable->bases->numGlyphs = _bases->u.object.length; @@ -203,9 +193,7 @@ static void parseBases(json_value *_bases, subtable_gpos_mark_to_ligature *subta for (uint16_t k = 0; k < subtable->ligArray[j]->componentCount; k++) { json_value *_componentRecord = baseRecord->u.array.values[k]; NEW_N(subtable->ligArray[j]->anchors[k], classCount); - for (uint16_t m = 0; m < classCount; m++) { - subtable->ligArray[j]->anchors[k][m] = otl_anchor_absent(); - } + for (uint16_t m = 0; m < classCount; m++) { subtable->ligArray[j]->anchors[k][m] = otl_anchor_absent(); } if (!_componentRecord || _componentRecord->type != json_object) { continue; } for (uint16_t m = 0; m < _componentRecord->u.object.length; m++) { sds className = sdsnewlen(_componentRecord->u.object.values[m].name, diff --git a/lib/tables/otl/gpos-mark-to-ligature.h b/lib/tables/otl/gpos-mark-to-ligature.h index fc875c1b..34319a5f 100644 --- a/lib/tables/otl/gpos-mark-to-ligature.h +++ b/lib/tables/otl/gpos-mark-to-ligature.h @@ -6,8 +6,7 @@ void delete_lig_attachment(mark_to_ligature_base *att); void caryll_delete_gpos_mark_to_ligature(otl_lookup *lookup); -otl_subtable *caryll_read_gpos_mark_to_ligature(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gpos_mark_to_ligature(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gpos_mark_to_ligature_to_json(otl_subtable *st); otl_subtable *caryll_gpos_mark_to_ligature_from_json(json_value *_subtable); caryll_buffer *caryll_write_gpos_mark_to_ligature(otl_subtable *_subtable); diff --git a/lib/tables/otl/gpos-mark-to-single.c b/lib/tables/otl/gpos-mark-to-single.c index 8163e3e1..521999f7 100644 --- a/lib/tables/otl/gpos-mark-to-single.c +++ b/lib/tables/otl/gpos-mark-to-single.c @@ -22,32 +22,26 @@ static void delete_mtb_subtable(otl_subtable *_subtable) { void caryll_delete_gpos_mark_to_single(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) - delete_mtb_subtable(lookup->subtables[j]); + for (uint16_t j = 0; j < lookup->subtableCount; j++) delete_mtb_subtable(lookup->subtables[j]); free(lookup->subtables); } free(lookup); } } -otl_subtable *caryll_read_gpos_mark_to_single(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset) { +otl_subtable *caryll_read_gpos_mark_to_single(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset) { otl_subtable *_subtable; NEW(_subtable); subtable_gpos_mark_to_single *subtable = &(_subtable->gpos_mark_to_single); if (tableLength < subtableOffset + 12) goto FAIL; - subtable->marks = caryll_read_coverage(data, tableLength, - subtableOffset + read_16u(data + subtableOffset + 2)); - subtable->bases = caryll_read_coverage(data, tableLength, - subtableOffset + read_16u(data + subtableOffset + 4)); - if (!subtable->marks || subtable->marks->numGlyphs == 0 || !subtable->bases || - subtable->bases->numGlyphs == 0) + subtable->marks = caryll_read_coverage(data, tableLength, subtableOffset + read_16u(data + subtableOffset + 2)); + subtable->bases = caryll_read_coverage(data, tableLength, subtableOffset + read_16u(data + subtableOffset + 4)); + if (!subtable->marks || subtable->marks->numGlyphs == 0 || !subtable->bases || subtable->bases->numGlyphs == 0) goto FAIL; subtable->classCount = read_16u(data + subtableOffset + 6); uint32_t markArrayOffset = subtableOffset + read_16u(data + subtableOffset + 8); subtable->markArray = otl_read_mark_array(data, tableLength, markArrayOffset); - if (!subtable->markArray || subtable->markArray->markCount != subtable->marks->numGlyphs) - goto FAIL; + if (!subtable->markArray || subtable->markArray->markCount != subtable->marks->numGlyphs) goto FAIL; uint32_t baseArrayOffset = subtableOffset + read_16u(data + subtableOffset + 10); checkLength(baseArrayOffset + 2 + 2 * subtable->bases->numGlyphs * subtable->classCount); @@ -82,10 +76,8 @@ json_value *caryll_gpos_mark_to_single_to_json(otl_subtable *st) { json_value *_bases = json_object_new(subtable->bases->numGlyphs); for (uint16_t j = 0; j < subtable->marks->numGlyphs; j++) { json_value *_mark = json_object_new(3); - sds markClassName = - sdscatfmt(sdsempty(), "ac_%i", subtable->markArray->records[j].markClass); - json_object_push(_mark, "class", - json_string_new_length((uint32_t)sdslen(markClassName), markClassName)); + sds markClassName = sdscatfmt(sdsempty(), "ac_%i", subtable->markArray->records[j].markClass); + json_object_push(_mark, "class", json_string_new_length((uint32_t)sdslen(markClassName), markClassName)); sdsfree(markClassName); json_object_push(_mark, "x", json_integer_new(subtable->markArray->records[j].anchor.x)); json_object_push(_mark, "y", json_integer_new(subtable->markArray->records[j].anchor.y)); @@ -99,8 +91,7 @@ json_value *caryll_gpos_mark_to_single_to_json(otl_subtable *st) { json_object_push(_anchor, "x", json_integer_new(subtable->baseArray[j][k].x)); json_object_push(_anchor, "y", json_integer_new(subtable->baseArray[j][k].y)); sds markClassName = sdscatfmt(sdsempty(), "ac_%i", k); - json_object_push_length(_base, (uint32_t)sdslen(markClassName), markClassName, - _anchor); + json_object_push_length(_base, (uint32_t)sdslen(markClassName), markClassName, _anchor); sdsfree(markClassName); } } @@ -116,8 +107,7 @@ typedef struct { uint16_t classID; UT_hash_handle hh; } classname_hash; -static void parseMarks(json_value *_marks, subtable_gpos_mark_to_single *subtable, - classname_hash **h) { +static void parseMarks(json_value *_marks, subtable_gpos_mark_to_single *subtable, classname_hash **h) { NEW(subtable->marks); subtable->marks->numGlyphs = _marks->u.object.length; NEW_N(subtable->marks->glyphs, subtable->marks->numGlyphs); @@ -153,8 +143,7 @@ static void parseMarks(json_value *_marks, subtable_gpos_mark_to_single *subtabl subtable->markArray->records[j].anchor.y = json_obj_getnum(anchorRecord, "y"); } } -static void parseBases(json_value *_bases, subtable_gpos_mark_to_single *subtable, - classname_hash **h) { +static void parseBases(json_value *_bases, subtable_gpos_mark_to_single *subtable, classname_hash **h) { uint16_t classCount = HASH_COUNT(*h); NEW(subtable->bases); subtable->bases->numGlyphs = _bases->u.object.length; @@ -164,15 +153,12 @@ static void parseBases(json_value *_bases, subtable_gpos_mark_to_single *subtabl char *gname = _bases->u.object.values[j].name; subtable->bases->glyphs[j].name = sdsnewlen(gname, _bases->u.object.values[j].name_length); NEW_N(subtable->baseArray[j], classCount); - for (uint16_t k = 0; k < classCount; k++) { - subtable->baseArray[j][k] = otl_anchor_absent(); - } + for (uint16_t k = 0; k < classCount; k++) { subtable->baseArray[j][k] = otl_anchor_absent(); } json_value *baseRecord = _bases->u.object.values[j].value; if (!baseRecord || baseRecord->type != json_object) continue; for (uint16_t k = 0; k < baseRecord->u.object.length; k++) { - sds className = sdsnewlen(baseRecord->u.object.values[k].name, - baseRecord->u.object.values[k].name_length); + sds className = sdsnewlen(baseRecord->u.object.values[k].name, baseRecord->u.object.values[k].name_length); classname_hash *s; HASH_FIND_STR(*h, className, s); if (!s) { @@ -181,8 +167,7 @@ static void parseBases(json_value *_bases, subtable_gpos_mark_to_single *subtabl className, gname); goto NEXT; } - subtable->baseArray[j][s->classID] = - otl_anchor_from_json(baseRecord->u.object.values[k].value); + subtable->baseArray[j][s->classID] = otl_anchor_from_json(baseRecord->u.object.values[k].value); NEXT: sdsfree(className); } @@ -235,9 +220,7 @@ caryll_buffer *caryll_write_gpos_mark_to_single(otl_subtable *_subtable) { ANCHOR_AGGERATOR_PUSH(agh, subtable->markArray->records[j].anchor); } for (uint16_t j = 0; j < subtable->bases->numGlyphs; j++) { - for (uint16_t k = 0; k < subtable->classCount; k++) { - ANCHOR_AGGERATOR_PUSH(agh, subtable->baseArray[j][k]); - } + for (uint16_t k = 0; k < subtable->classCount; k++) { ANCHOR_AGGERATOR_PUSH(agh, subtable->baseArray[j][k]); } } HASH_SORT(agh, byAnchorIndex); diff --git a/lib/tables/otl/gpos-mark-to-single.h b/lib/tables/otl/gpos-mark-to-single.h index 6aeec9e8..3c0e9643 100644 --- a/lib/tables/otl/gpos-mark-to-single.h +++ b/lib/tables/otl/gpos-mark-to-single.h @@ -3,8 +3,7 @@ #include "otl.h" void caryll_delete_gpos_mark_to_single(otl_lookup *lookup); -otl_subtable *caryll_read_gpos_mark_to_single(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gpos_mark_to_single(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gpos_mark_to_single_to_json(otl_subtable *st); otl_subtable *caryll_gpos_mark_to_single_from_json(json_value *_subtable); caryll_buffer *caryll_write_gpos_mark_to_single(otl_subtable *_subtable); diff --git a/lib/tables/otl/gpos-pair.c b/lib/tables/otl/gpos-pair.c index 3b107554..afdacf08 100644 --- a/lib/tables/otl/gpos-pair.c +++ b/lib/tables/otl/gpos-pair.c @@ -6,15 +6,11 @@ void delete_otl_gpos_pair_subtable(otl_subtable *_subtable) { subtable_gpos_pair *subtable = &(_subtable->gpos_pair); if (subtable->coverage) caryll_delete_coverage(subtable->coverage); if (subtable->firstValues) { - for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { - free(subtable->firstValues[j]); - } + for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { free(subtable->firstValues[j]); } free(subtable->firstValues); } if (subtable->secondValues) { - for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { - free(subtable->secondValues[j]); - } + for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { free(subtable->secondValues[j]); } free(subtable->secondValues); } caryll_delete_classdef(subtable->first); @@ -25,8 +21,7 @@ void delete_otl_gpos_pair_subtable(otl_subtable *_subtable) { void caryll_delete_gpos_pair(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) - delete_otl_gpos_pair_subtable(lookup->subtables[j]); + for (uint16_t j = 0; j < lookup->subtableCount; j++) delete_otl_gpos_pair_subtable(lookup->subtables[j]); free(lookup->subtables); } free(lookup); @@ -53,8 +48,7 @@ otl_subtable *caryll_read_gpos_pair(font_file_pointer data, uint32_t tableLength uint16_t subtableFormat = read_16u(data + offset); if (subtableFormat == 1) { // pair adjustment by individuals - otl_coverage *cov = - caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); + otl_coverage *cov = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); NEW(subtable->first); subtable->first->numGlyphs = cov->numGlyphs; subtable->first->maxclass = cov->numGlyphs - 1; @@ -122,11 +116,10 @@ otl_subtable *caryll_read_gpos_pair(font_file_pointer data, uint32_t tableLength pair_classifier_hash *s; HASH_FIND_INT(h, &second, s); if (s) { - subtable->firstValues[j][s->cid] = read_gpos_value( - data, tableLength, pairSetOffset + 2 + (2 + len1 + len2) * k + 2, format1); + subtable->firstValues[j][s->cid] = + read_gpos_value(data, tableLength, pairSetOffset + 2 + (2 + len1 + len2) * k + 2, format1); subtable->secondValues[j][s->cid] = read_gpos_value( - data, tableLength, pairSetOffset + 2 + (2 + len1 + len2) * k + 2 + len1, - format2); + data, tableLength, pairSetOffset + 2 + (2 + len1 + len2) * k + 2 + len1, format2); } } } @@ -149,14 +142,11 @@ otl_subtable *caryll_read_gpos_pair(font_file_pointer data, uint32_t tableLength uint16_t format2 = read_16u(data + offset + 6); uint8_t len1 = position_format_length(format1); uint8_t len2 = position_format_length(format2); - otl_coverage *cov = - caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); - subtable->first = - caryll_read_classdef(data, tableLength, offset + read_16u(data + offset + 8)); + otl_coverage *cov = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); + subtable->first = caryll_read_classdef(data, tableLength, offset + read_16u(data + offset + 8)); subtable->first = caryll_expand_classdef(cov, subtable->first); caryll_delete_coverage(cov); - subtable->second = - caryll_read_classdef(data, tableLength, offset + read_16u(data + offset + 10)); + subtable->second = caryll_read_classdef(data, tableLength, offset + read_16u(data + offset + 10)); if (!subtable->first || !subtable->second) goto FAIL; uint16_t class1Count = read_16u(data + offset + 12); uint16_t class2Count = read_16u(data + offset + 14); @@ -173,11 +163,9 @@ otl_subtable *caryll_read_gpos_pair(font_file_pointer data, uint32_t tableLength NEW_N(subtable->secondValues[j], class2Count); for (uint16_t k = 0; k < class2Count; k++) { subtable->firstValues[j][k] = - read_gpos_value(data, tableLength, - offset + 16 + (j * class2Count + k) * (len1 + len2), format1); + read_gpos_value(data, tableLength, offset + 16 + (j * class2Count + k) * (len1 + len2), format1); subtable->secondValues[j][k] = read_gpos_value( - data, tableLength, offset + 16 + (j * class2Count + k) * (len1 + len2) + len1, - format2); + data, tableLength, offset + 16 + (j * class2Count + k) * (len1 + len2) + len1, format2); } } @@ -206,14 +194,8 @@ json_value *caryll_gpos_pair_to_json(otl_subtable *_subtable) { json_array_push(row, json_integer_new(subtable->firstValues[j][k].dWidth)); } else { json_value *pair = json_object_new(2); - if (f1) { - json_object_push(pair, "first", - gpos_value_to_json(subtable->firstValues[j][k])); - } - if (f2) { - json_object_push(pair, "second", - gpos_value_to_json(subtable->secondValues[j][k])); - } + if (f1) { json_object_push(pair, "first", gpos_value_to_json(subtable->firstValues[j][k])); } + if (f2) { json_object_push(pair, "second", gpos_value_to_json(subtable->secondValues[j][k])); } json_array_push(row, pair); } } else { @@ -237,8 +219,7 @@ otl_subtable *caryll_gpos_pair_from_json(json_value *_subtable) { json_value *_mat = json_obj_get_type(_subtable, "matrix", json_array); subtable->first = caryll_classdef_from_json(json_obj_get_type(_subtable, "first", json_object)); - subtable->second = - caryll_classdef_from_json(json_obj_get_type(_subtable, "second", json_object)); + subtable->second = caryll_classdef_from_json(json_obj_get_type(_subtable, "second", json_object)); if (!_mat || !subtable->first || !subtable->second) goto FAIL; uint16_t class1Count = subtable->first->maxclass + 1; diff --git a/lib/tables/otl/gpos-single.c b/lib/tables/otl/gpos-single.c index 55f4f04a..f5be68f7 100644 --- a/lib/tables/otl/gpos-single.c +++ b/lib/tables/otl/gpos-single.c @@ -14,8 +14,7 @@ void caryll_delete_gpos_single(otl_lookup *lookup) { FREE(lookup); } } -otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_subtable *_subtable; NEW(_subtable); subtable_gpos_single *subtable = &(_subtable->gpos_single); @@ -24,14 +23,12 @@ otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLeng checkLength(offset + 6); uint16_t subtableFormat = read_16u(data + offset); - subtable->coverage = - caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); + subtable->coverage = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); if (!subtable->coverage || subtable->coverage->numGlyphs == 0) goto FAIL; NEW_N(subtable->values, subtable->coverage->numGlyphs); if (subtableFormat == 1) { - otl_position_value v = - read_gpos_value(data, tableLength, offset + 6, read_16u(data + offset + 4)); + otl_position_value v = read_gpos_value(data, tableLength, offset + 6, read_16u(data + offset + 4)); for (uint16_t j = 0; j < subtable->coverage->numGlyphs; j++) { subtable->values[j] = v; } } else { uint16_t valueFormat = read_16u(data + offset + 4); @@ -41,8 +38,7 @@ otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLeng for (uint16_t j = 0; j < subtable->coverage->numGlyphs; j++) { subtable->values[j] = - read_gpos_value(data, tableLength, - offset + 8 + j * position_format_length(valueFormat), valueFormat); + read_gpos_value(data, tableLength, offset + 8 + j * position_format_length(valueFormat), valueFormat); } } goto OK; @@ -58,8 +54,7 @@ json_value *caryll_gpos_single_to_json(otl_subtable *_subtable) { subtable_gpos_single *subtable = &(_subtable->gpos_single); json_value *st = json_object_new(subtable->coverage->numGlyphs); for (uint16_t j = 0; j < subtable->coverage->numGlyphs; j++) { - json_object_push(st, subtable->coverage->glyphs[j].name, - gpos_value_to_json(subtable->values[j])); + json_object_push(st, subtable->coverage->glyphs[j].name, gpos_value_to_json(subtable->values[j])); } return st; } @@ -72,10 +67,8 @@ otl_subtable *caryll_gpos_single_from_json(json_value *_subtable) { NEW_N(subtable->values, _subtable->u.object.length); uint16_t jj = 0; for (uint16_t j = 0; j < _subtable->u.object.length; j++) { - if (_subtable->u.object.values[j].value && - _subtable->u.object.values[j].value->type == json_object) { - sds gname = sdsnewlen(_subtable->u.object.values[j].name, - _subtable->u.object.values[j].name_length); + if (_subtable->u.object.values[j].value && _subtable->u.object.values[j].value->type == json_object) { + sds gname = sdsnewlen(_subtable->u.object.values[j].name, _subtable->u.object.values[j].name_length); subtable->coverage->glyphs[jj].name = gname; subtable->values[jj] = gpos_value_from_json(_subtable->u.object.values[j].value); jj++; diff --git a/lib/tables/otl/gpos-single.h b/lib/tables/otl/gpos-single.h index 11ddf062..6a8d8322 100644 --- a/lib/tables/otl/gpos-single.h +++ b/lib/tables/otl/gpos-single.h @@ -4,8 +4,7 @@ #include "otl.h" void caryll_delete_gpos_single(otl_lookup *lookup); -otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gpos_single_to_json(otl_subtable *_subtable); otl_subtable *caryll_gpos_single_from_json(json_value *_subtable); caryll_buffer *caryll_write_gpos_single(otl_subtable *_subtable); diff --git a/lib/tables/otl/gsub-ligature.c b/lib/tables/otl/gsub-ligature.c index 131d75e5..f28cf8e9 100644 --- a/lib/tables/otl/gsub-ligature.c +++ b/lib/tables/otl/gsub-ligature.c @@ -3,9 +3,7 @@ static void deleteGSUBLigatureSubtable(otl_subtable *_subtable) { if (!_subtable) return; subtable_gsub_ligature *subtable = &(_subtable->gsub_ligature); if (subtable->from && subtable->to) { - for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { - caryll_delete_coverage(subtable->from[j]); - } + for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { caryll_delete_coverage(subtable->from[j]); } free(subtable->from); } caryll_delete_coverage(subtable->to); @@ -21,8 +19,7 @@ void caryll_delete_gsub_ligature(otl_lookup *lookup) { FREE(lookup); } } -otl_subtable *caryll_read_gsub_ligature(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_gsub_ligature(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_subtable *_subtable; NEW(_subtable); subtable_gsub_ligature *subtable = &(_subtable->gsub_ligature); @@ -30,8 +27,7 @@ otl_subtable *caryll_read_gsub_ligature(font_file_pointer data, uint32_t tableLe subtable->to = NULL; checkLength(offset + 6); - otl_coverage *startCoverage = - caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); + otl_coverage *startCoverage = caryll_read_coverage(data, tableLength, offset + read_16u(data + offset + 2)); if (!startCoverage) goto FAIL; uint16_t setCount = read_16u(data + offset + 4); if (setCount != startCoverage->numGlyphs) goto FAIL; @@ -88,9 +84,8 @@ json_value *caryll_gsub_ligature_to_json(otl_subtable *_subtable) { for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { json_value *entry = json_object_new(2); json_object_push(entry, "from", caryll_coverage_to_json(subtable->from[j])); - json_object_push(entry, "to", - json_string_new_length((uint32_t)sdslen(subtable->to->glyphs[j].name), - subtable->to->glyphs[j].name)); + json_object_push(entry, "to", json_string_new_length((uint32_t)sdslen(subtable->to->glyphs[j].name), + subtable->to->glyphs[j].name)); json_array_push(st, preserialize(entry)); } json_value *ret = json_object_new(1); @@ -134,8 +129,8 @@ otl_subtable *caryll_gsub_ligature_from_json(json_value *_subtable) { for (uint16_t k = 0; k < st->to->numGlyphs; k++) { json_value *_from = _subtable->u.object.values[k].value; if (!_from || _from->type != json_array) continue; - st->to->glyphs[jj].name = sdsnewlen(_subtable->u.object.values[k].name, - _subtable->u.object.values[k].name_length); + st->to->glyphs[jj].name = + sdsnewlen(_subtable->u.object.values[k].name, _subtable->u.object.values[k].name_length); st->from[jj] = caryll_coverage_from_json(_from); jj += 1; } diff --git a/lib/tables/otl/gsub-ligature.h b/lib/tables/otl/gsub-ligature.h index 50bdefaa..7bdca1bb 100644 --- a/lib/tables/otl/gsub-ligature.h +++ b/lib/tables/otl/gsub-ligature.h @@ -4,8 +4,7 @@ #include "otl.h" void caryll_delete_gsub_ligature(otl_lookup *lookup); -otl_subtable *caryll_read_gsub_ligature(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gsub_ligature(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gsub_ligature_to_json(otl_subtable *_subtable); otl_subtable *caryll_gsub_ligature_from_json(json_value *_subtable); caryll_buffer *caryll_write_gsub_ligature_subtable(otl_subtable *_subtable); diff --git a/lib/tables/otl/gsub-multi.c b/lib/tables/otl/gsub-multi.c index eb11aa7f..9f1e74dd 100644 --- a/lib/tables/otl/gsub-multi.c +++ b/lib/tables/otl/gsub-multi.c @@ -3,9 +3,7 @@ static void deleteGSUBMultiSubtable(otl_subtable *_subtable) { if (!_subtable) return; subtable_gsub_multi *subtable = &(_subtable->gsub_multi); if (subtable->from && subtable->to) { - for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { - caryll_delete_coverage(subtable->to[j]); - } + for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { caryll_delete_coverage(subtable->to[j]); } free(subtable->to); } caryll_delete_coverage(subtable->from); @@ -22,8 +20,7 @@ void caryll_delete_gsub_multi(otl_lookup *lookup) { } } -otl_subtable *caryll_read_gsub_multi(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_gsub_multi(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_subtable *_subtable; NEW(_subtable); subtable_gsub_multi *subtable = &(_subtable->gsub_multi); @@ -44,9 +41,7 @@ otl_subtable *caryll_read_gsub_multi(font_file_pointer data, uint32_t tableLengt NEW(cov); cov->numGlyphs = read_16u(data + seqOffset); NEW_N(cov->glyphs, cov->numGlyphs); - for (uint16_t k = 0; k < cov->numGlyphs; k++) { - cov->glyphs[k].gid = read_16u(data + seqOffset + 2 + k * 2); - } + for (uint16_t k = 0; k < cov->numGlyphs; k++) { cov->glyphs[k].gid = read_16u(data + seqOffset + 2 + k * 2); } subtable->to[j] = cov; } return _subtable; @@ -60,8 +55,7 @@ json_value *caryll_gsub_multi_to_json(otl_subtable *_subtable) { subtable_gsub_multi *subtable = &(_subtable->gsub_multi); json_value *st = json_object_new(subtable->from->numGlyphs); for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { - json_object_push(st, subtable->from->glyphs[j].name, - caryll_coverage_to_json(subtable->to[j])); + json_object_push(st, subtable->from->glyphs[j].name, caryll_coverage_to_json(subtable->to[j])); } return st; } @@ -79,8 +73,8 @@ otl_subtable *caryll_gsub_multi_from_json(json_value *_subtable) { for (uint16_t k = 0; k < st->from->numGlyphs; k++) { json_value *_to = _subtable->u.object.values[k].value; if (!_to || _to->type != json_array) continue; - st->from->glyphs[jj].name = sdsnewlen(_subtable->u.object.values[k].name, - _subtable->u.object.values[k].name_length); + st->from->glyphs[jj].name = + sdsnewlen(_subtable->u.object.values[k].name, _subtable->u.object.values[k].name_length); st->to[jj] = caryll_coverage_from_json(_to); jj += 1; } @@ -100,9 +94,7 @@ caryll_buffer *caryll_write_gsub_multi_subtable(otl_subtable *_subtable) { for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { bufping16b(buf, &offset, &cp); bufwrite16b(buf, subtable->to[j]->numGlyphs); - for (uint16_t k = 0; k < subtable->to[j]->numGlyphs; k++) { - bufwrite16b(buf, subtable->to[j]->glyphs[k].gid); - } + for (uint16_t k = 0; k < subtable->to[j]->numGlyphs; k++) { bufwrite16b(buf, subtable->to[j]->glyphs[k].gid); } bufpong(buf, &offset, &cp); } return buf; diff --git a/lib/tables/otl/gsub-multi.h b/lib/tables/otl/gsub-multi.h index 53b46007..a2e220e0 100644 --- a/lib/tables/otl/gsub-multi.h +++ b/lib/tables/otl/gsub-multi.h @@ -4,8 +4,7 @@ #include "otl.h" void caryll_delete_gsub_multi(otl_lookup *lookup); -otl_subtable *caryll_read_gsub_multi(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gsub_multi(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gsub_multi_to_json(otl_subtable *_subtable); otl_subtable *caryll_gsub_multi_from_json(json_value *_subtable); caryll_buffer *caryll_write_gsub_multi_subtable(otl_subtable *_subtable); diff --git a/lib/tables/otl/gsub-reverse.c b/lib/tables/otl/gsub-reverse.c index 172aa8f8..61e44760 100644 --- a/lib/tables/otl/gsub-reverse.c +++ b/lib/tables/otl/gsub-reverse.c @@ -4,9 +4,7 @@ static void delete_gsub_reverse_subtable(otl_subtable *_subtable) { if (_subtable) { subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse); if (subtable->match) - for (uint16_t j = 0; j < subtable->matchCount; j++) { - caryll_delete_coverage(subtable->match[j]); - } + for (uint16_t j = 0; j < subtable->matchCount; j++) { caryll_delete_coverage(subtable->match[j]); } if (subtable->to) caryll_delete_coverage(subtable->to); free(_subtable); } @@ -15,9 +13,7 @@ static void delete_gsub_reverse_subtable(otl_subtable *_subtable) { void caryll_delete_gsub_reverse(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) { - delete_gsub_reverse_subtable(lookup->subtables[j]); - } + for (uint16_t j = 0; j < lookup->subtableCount; j++) { delete_gsub_reverse_subtable(lookup->subtables[j]); } free(lookup->subtables); } free(lookup); @@ -37,8 +33,7 @@ static void reverseBacktracks(subtable_gsub_reverse *subtable) { } } -otl_subtable *caryll_read_gsub_reverse(font_file_pointer data, uint32_t tableLength, - uint32_t offset) { +otl_subtable *caryll_read_gsub_reverse(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_subtable *_subtable; NEW(_subtable); subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse); @@ -77,8 +72,7 @@ otl_subtable *caryll_read_gsub_reverse(font_file_pointer data, uint32_t tableLen subtable->to->numGlyphs = nReplacement; NEW_N(subtable->to->glyphs, nReplacement); for (uint16_t j = 0; j < nReplacement; j++) { - subtable->to->glyphs[j].gid = - read_16u(data + offset + 10 + (nBacktrack + nForward + j) * 2); + subtable->to->glyphs[j].gid = read_16u(data + offset + 10 + (nBacktrack + nForward + j) * 2); subtable->to->glyphs[j].name = NULL; } reverseBacktracks(subtable); @@ -139,8 +133,6 @@ caryll_buffer *caryll_write_gsub_reverse(otl_subtable *_subtable) { bufpingpong16b(buf, caryll_write_coverage(subtable->match[j]), &offset, &cp); } bufwrite16b(buf, subtable->to->numGlyphs); - for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { - bufwrite16b(buf, subtable->to->glyphs[j].gid); - } + for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { bufwrite16b(buf, subtable->to->glyphs[j].gid); } return buf; } diff --git a/lib/tables/otl/gsub-single.c b/lib/tables/otl/gsub-single.c index e4fbb64d..e3bd3671 100644 --- a/lib/tables/otl/gsub-single.c +++ b/lib/tables/otl/gsub-single.c @@ -14,14 +14,12 @@ void caryll_delete_gsub_single(otl_lookup *lookup) { } } -otl_subtable *caryll_read_gsub_single(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset) { +otl_subtable *caryll_read_gsub_single(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset) { otl_subtable *subtable; NEW(subtable); if (tableLength < subtableOffset + 6) goto FAIL; uint16_t subtableFormat = read_16u(data + subtableOffset); - otl_coverage *from = caryll_read_coverage(data, tableLength, - subtableOffset + read_16u(data + subtableOffset + 2)); + otl_coverage *from = caryll_read_coverage(data, tableLength, subtableOffset + read_16u(data + subtableOffset + 2)); subtable->gsub_single.from = from; if (!from || from->numGlyphs == 0) goto FAIL; @@ -39,8 +37,7 @@ otl_subtable *caryll_read_gsub_single(font_file_pointer data, uint32_t tableLeng subtable->gsub_single.to = to; } else { uint16_t toglyphs = read_16u(data + subtableOffset + 4); - if (tableLength < subtableOffset + 6 + toglyphs * 2 || toglyphs != from->numGlyphs) - goto FAIL; + if (tableLength < subtableOffset + 6 + toglyphs * 2 || toglyphs != from->numGlyphs) goto FAIL; otl_coverage *to; NEW(to); to->numGlyphs = toglyphs; @@ -65,8 +62,7 @@ json_value *caryll_gsub_single_to_json(otl_subtable *_subtable) { subtable_gsub_single *subtable = &(_subtable->gsub_single); json_value *st = json_object_new(subtable->from->numGlyphs); for (uint16_t j = 0; j < subtable->from->numGlyphs && j < subtable->from->numGlyphs; j++) { - json_object_push(st, subtable->from->glyphs[j].name, - json_string_new(subtable->to->glyphs[j].name)); + json_object_push(st, subtable->from->glyphs[j].name, json_string_new(subtable->to->glyphs[j].name)); } return st; } @@ -82,13 +78,11 @@ otl_subtable *caryll_gsub_single_from_json(json_value *_subtable) { NEW_N(subtable->to->glyphs, subtable->to->numGlyphs); uint16_t jj = 0; for (uint16_t j = 0; j < _subtable->u.object.length; j++) { - if (_subtable->u.object.values[j].value && - _subtable->u.object.values[j].value->type == json_string) { - subtable->from->glyphs[jj].name = sdsnewlen(_subtable->u.object.values[j].name, - _subtable->u.object.values[j].name_length); - subtable->to->glyphs[jj].name = - sdsnewlen(_subtable->u.object.values[j].value->u.string.ptr, - _subtable->u.object.values[j].value->u.string.length); + if (_subtable->u.object.values[j].value && _subtable->u.object.values[j].value->type == json_string) { + subtable->from->glyphs[jj].name = + sdsnewlen(_subtable->u.object.values[j].name, _subtable->u.object.values[j].name_length); + subtable->to->glyphs[jj].name = sdsnewlen(_subtable->u.object.values[j].value->u.string.ptr, + _subtable->u.object.values[j].value->u.string.length); jj++; } } @@ -104,8 +98,7 @@ caryll_buffer *caryll_write_gsub_single_subtable(otl_subtable *_subtable) { int32_t difference = subtable->to->glyphs[0].gid - subtable->from->glyphs[0].gid; for (uint16_t j = 1; j < subtable->from->numGlyphs; j++) { isConstantDifference = - isConstantDifference && - ((subtable->to->glyphs[j].gid - subtable->from->glyphs[j].gid) == difference); + isConstantDifference && ((subtable->to->glyphs[j].gid - subtable->from->glyphs[j].gid) == difference); } } if (isConstantDifference && subtable->from->numGlyphs > 0) { @@ -117,9 +110,7 @@ caryll_buffer *caryll_write_gsub_single_subtable(otl_subtable *_subtable) { bufwrite16b(bufst, 2); bufwrite16b(bufst, 6 + subtable->to->numGlyphs * 2); bufwrite16b(bufst, subtable->to->numGlyphs); - for (uint16_t k = 0; k < subtable->to->numGlyphs; k++) { - bufwrite16b(bufst, subtable->to->glyphs[k].gid); - } + for (uint16_t k = 0; k < subtable->to->numGlyphs; k++) { bufwrite16b(bufst, subtable->to->glyphs[k].gid); } bufwrite_bufdel(bufst, caryll_write_coverage(subtable->from)); } return bufst; diff --git a/lib/tables/otl/gsub-single.h b/lib/tables/otl/gsub-single.h index 39ebdd76..3272c135 100644 --- a/lib/tables/otl/gsub-single.h +++ b/lib/tables/otl/gsub-single.h @@ -4,8 +4,7 @@ #include "otl.h" void caryll_delete_gsub_single(otl_lookup *lookup); -otl_subtable *caryll_read_gsub_single(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset); +otl_subtable *caryll_read_gsub_single(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset); json_value *caryll_gsub_single_to_json(otl_subtable *_subtable); otl_subtable *caryll_gsub_single_from_json(json_value *_subtable); caryll_buffer *caryll_write_gsub_single_subtable(otl_subtable *_subtable); diff --git a/lib/tables/otl/otl.c b/lib/tables/otl/otl.c index 5dedbe17..e3d2d583 100644 --- a/lib/tables/otl/otl.c +++ b/lib/tables/otl/otl.c @@ -25,12 +25,11 @@ typedef struct { } language_hash; void caryll_delete_lookup(otl_lookup *lookup); -otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset, otl_lookup_type lookupType); +otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, + otl_lookup_type lookupType); static void _lookup_to_json(otl_lookup *lookup, json_value *dump); static bool _parse_lookup(json_value *lookup, char *lookupName, lookup_hash **lh); -static bool _write_subtable(otl_lookup *lookup, caryll_buffer *buf, uint32_t **subtableOffsets, - uint32_t *lastOffset); +static bool _write_subtable(otl_lookup *lookup, caryll_buffer *buf, uint32_t **subtableOffsets, uint32_t *lastOffset); // COMMON PART table_otl *caryll_new_otl() { @@ -64,17 +63,14 @@ void caryll_delete_otl(table_otl *table) { free(table->features); } if (table->lookups) { - for (uint16_t j = 0; j < table->lookupCount; j++) { - caryll_delete_lookup(table->lookups[j]); - } + for (uint16_t j = 0; j < table->lookupCount; j++) { caryll_delete_lookup(table->lookups[j]); } free(table->lookups); } free(table); } -static void parseLanguage(font_file_pointer data, uint32_t tableLength, uint32_t base, - otl_language_system *lang, uint16_t featureCount, - otl_feature **features) { +static void parseLanguage(font_file_pointer data, uint32_t tableLength, uint32_t base, otl_language_system *lang, + uint16_t featureCount, otl_feature **features) { checkLength(base + 6); uint16_t rid = read_16u(data + base + 2); if (rid < featureCount) { @@ -143,10 +139,9 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL NEW(feature); features[j] = feature; uint32_t tag = read_32u(data + featureListOffset + 2 + j * 6); - features[j]->name = sdscatprintf(sdsempty(), "%c%c%c%c_%05d", (tag >> 24) & 0xFF, - (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff, j); - uint32_t featureOffset = - featureListOffset + read_16u(data + featureListOffset + 2 + j * 6 + 4); + features[j]->name = sdscatprintf(sdsempty(), "%c%c%c%c_%05d", (tag >> 24) & 0xFF, (tag >> 16) & 0xFF, + (tag >> 8) & 0xff, tag & 0xff, j); + uint32_t featureOffset = featureListOffset + read_16u(data + featureListOffset + 2 + j * 6 + 4); checkLength(featureOffset + 4); uint16_t lookupCount = read_16u(data + featureOffset + 2); @@ -159,8 +154,8 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL features[j]->lookups[k] = table->lookups[lookupid]; if (!features[j]->lookups[k]->name) { features[j]->lookups[k]->name = - sdscatprintf(sdsempty(), "lookup_%c%c%c%c_%d", (tag >> 24) & 0xFF, - (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff, lnk++); + sdscatprintf(sdsempty(), "lookup_%c%c%c%c_%d", (tag >> 24) & 0xFF, (tag >> 16) & 0xFF, + (tag >> 8) & 0xff, tag & 0xff, lnk++); } } } @@ -176,13 +171,11 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL uint32_t nLanguageCombinations = 0; for (uint16_t j = 0; j < scriptCount; j++) { - uint32_t scriptOffset = - scriptListOffset + read_16u(data + scriptListOffset + 2 + 6 * j + 4); + uint32_t scriptOffset = scriptListOffset + read_16u(data + scriptListOffset + 2 + 6 * j + 4); checkLength(scriptOffset + 4); uint16_t defaultLangSystem = read_16u(data + scriptOffset); - nLanguageCombinations += - (defaultLangSystem ? 1 : 0) + read_16u(data + scriptOffset + 2); + nLanguageCombinations += (defaultLangSystem ? 1 : 0) + read_16u(data + scriptOffset + 2); } table->languageCount = nLanguageCombinations; @@ -192,16 +185,15 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL uint16_t currentLang = 0; for (uint16_t j = 0; j < scriptCount; j++) { uint32_t tag = read_32u(data + scriptListOffset + 2 + 6 * j); - uint32_t scriptOffset = - scriptListOffset + read_16u(data + scriptListOffset + 2 + 6 * j + 4); + uint32_t scriptOffset = scriptListOffset + read_16u(data + scriptListOffset + 2 + 6 * j + 4); uint16_t defaultLangSystem = read_16u(data + scriptOffset); if (defaultLangSystem) { NEW(languages[currentLang]); - languages[currentLang]->name = sdscatprintf( - sdsempty(), "%c%c%c%c%cDFLT", (tag >> 24) & 0xFF, (tag >> 16) & 0xFF, - (tag >> 8) & 0xff, tag & 0xff, SCRIPT_LANGUAGE_SEPARATOR); - parseLanguage(data, tableLength, scriptOffset + defaultLangSystem, - languages[currentLang], table->featureCount, table->features); + languages[currentLang]->name = + sdscatprintf(sdsempty(), "%c%c%c%c%cDFLT", (tag >> 24) & 0xFF, (tag >> 16) & 0xFF, + (tag >> 8) & 0xff, tag & 0xff, SCRIPT_LANGUAGE_SEPARATOR); + parseLanguage(data, tableLength, scriptOffset + defaultLangSystem, languages[currentLang], + table->featureCount, table->features); currentLang += 1; } uint16_t langSysCount = read_16u(data + scriptOffset + 2); @@ -210,12 +202,11 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL uint16_t langSys = read_16u(data + scriptOffset + 4 + 6 * k + 4); NEW(languages[currentLang]); languages[currentLang]->name = - sdscatprintf(sdsempty(), "%c%c%c%c%c%c%c%c%c", (tag >> 24) & 0xFF, - (tag >> 16) & 0xFF, (tag >> 8) & 0xff, tag & 0xff, - SCRIPT_LANGUAGE_SEPARATOR, (langTag >> 24) & 0xFF, + sdscatprintf(sdsempty(), "%c%c%c%c%c%c%c%c%c", (tag >> 24) & 0xFF, (tag >> 16) & 0xFF, + (tag >> 8) & 0xff, tag & 0xff, SCRIPT_LANGUAGE_SEPARATOR, (langTag >> 24) & 0xFF, (langTag >> 16) & 0xFF, (langTag >> 8) & 0xff, langTag & 0xff); - parseLanguage(data, tableLength, scriptOffset + langSys, languages[currentLang], - table->featureCount, table->features); + parseLanguage(data, tableLength, scriptOffset + langSys, languages[currentLang], table->featureCount, + table->features); currentLang += 1; } } @@ -225,8 +216,7 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL // name all lookups for (uint16_t j = 0; j < table->lookupCount; j++) { if (!table->lookups[j]->name) - table->lookups[j]->name = - sdscatprintf(sdsempty(), "lookup_%02x_%d", table->lookups[j]->type, j); + table->lookups[j]->name = sdscatprintf(sdsempty(), "lookup_%02x_%d", table->lookups[j]->type, j); } return table; FAIL: @@ -234,8 +224,7 @@ static table_otl *caryll_read_otl_common(font_file_pointer data, uint32_t tableL return NULL; } -static void caryll_read_otl_lookup(font_file_pointer data, uint32_t tableLength, - otl_lookup *lookup) { +static void caryll_read_otl_lookup(font_file_pointer data, uint32_t tableLength, otl_lookup *lookup) { lookup->flags = read_16u(data + lookup->_offset + 2); lookup->subtableCount = read_16u(data + lookup->_offset + 4); if (!lookup->subtableCount || tableLength < lookup->_offset + 6 + 2 * lookup->subtableCount) { @@ -247,8 +236,7 @@ static void caryll_read_otl_lookup(font_file_pointer data, uint32_t tableLength, NEW_N(lookup->subtables, lookup->subtableCount); for (uint16_t j = 0; j < lookup->subtableCount; j++) { uint32_t subtableOffset = lookup->_offset + read_16u(data + lookup->_offset + 6 + j * 2); - lookup->subtables[j] = - caryll_read_otl_subtable(data, tableLength, subtableOffset, lookup->type); + lookup->subtables[j] = caryll_read_otl_subtable(data, tableLength, subtableOffset, lookup->type); } if (lookup->type == otl_type_gsub_extend || lookup->type == otl_type_gpos_extend) { lookup->type = 0; @@ -294,12 +282,9 @@ table_otl *caryll_read_otl(caryll_packet packet, uint32_t tag) { uint32_t length = table.length; otl = caryll_read_otl_common( data, length, - (tag == 'GSUB' ? otl_type_gsub_unknown : tag == 'GPOS' ? otl_type_gpos_unknown - : otl_type_unknown)); + (tag == 'GSUB' ? otl_type_gsub_unknown : tag == 'GPOS' ? otl_type_gpos_unknown : otl_type_unknown)); if (!otl) goto FAIL; - for (uint16_t j = 0; j < otl->lookupCount; j++) { - caryll_read_otl_lookup(data, length, otl->lookups[j]); - } + for (uint16_t j = 0; j < otl->lookupCount; j++) { caryll_read_otl_lookup(data, length, otl->lookups[j]); } return otl; FAIL: if (otl) caryll_delete_otl(otl); @@ -308,12 +293,10 @@ table_otl *caryll_read_otl(caryll_packet packet, uint32_t tag) { return NULL; } -static const char *lookupFlagsLabels[] = {"rightToLeft", "ignoreBases", "ignoreLigatures", - "ignoreMarks", NULL}; +static const char *lookupFlagsLabels[] = {"rightToLeft", "ignoreBases", "ignoreLigatures", "ignoreMarks", NULL}; -static void _declare_lookup_dumper(otl_lookup_type llt, const char *lt, - json_value *(*dumper)(otl_subtable *st), otl_lookup *lookup, - json_value *dump) { +static void _declare_lookup_dumper(otl_lookup_type llt, const char *lt, json_value *(*dumper)(otl_subtable *st), + otl_lookup *lookup, json_value *dump) { if (lookup->type == llt) { json_object_push(dump, "type", json_string_new(lt)); json_object_push(dump, "flags", caryll_flags_to_json(lookup->flags, lookupFlagsLabels)); @@ -324,8 +307,7 @@ static void _declare_lookup_dumper(otl_lookup_type llt, const char *lt, } } -void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options *dumpopts, - const char *tag) { +void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options *dumpopts, const char *tag) { if (!table || !table->languages || !table->lookups || !table->features) return; json_value *otl = json_object_new(3); { @@ -340,8 +322,7 @@ void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options json_value *features = json_array_new(table->languages[j]->featureCount); for (uint16_t k = 0; k < table->languages[j]->featureCount; k++) if (table->languages[j]->features[k]) { - json_array_push(features, - json_string_new(table->languages[j]->features[k]->name)); + json_array_push(features, json_string_new(table->languages[j]->features[k]->name)); } json_object_push(language, "features", preserialize(features)); json_object_push(languages, table->languages[j]->name, language); @@ -377,9 +358,8 @@ void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options json_object_push(root, tag, otl); } -static bool _declareLookupParser(const char *lt, otl_lookup_type llt, - otl_subtable *(*parser)(json_value *), json_value *_lookup, - char *lookupName, lookup_hash **lh) { +static bool _declareLookupParser(const char *lt, otl_lookup_type llt, otl_subtable *(*parser)(json_value *), + json_value *_lookup, char *lookupName, lookup_hash **lh) { json_value *type = json_obj_get_type(_lookup, "type", json_string); if (!type || strcmp(type->u.string.ptr, lt)) return false; lookup_hash *item = NULL; @@ -416,8 +396,7 @@ static bool _declareLookupParser(const char *lt, otl_lookup_type llt, return true; } -static feature_hash *figureOutFeaturesFromJSON(json_value *features, lookup_hash *lh, - const char *tag) { +static feature_hash *figureOutFeaturesFromJSON(json_value *features, lookup_hash *lh, const char *tag) { feature_hash *fh = NULL; for (uint32_t j = 0; j < features->u.object.length; j++) { char *featureName = features->u.object.values[j].name; @@ -465,8 +444,7 @@ static feature_hash *figureOutFeaturesFromJSON(json_value *features, lookup_hash bool isValidLanguageName(const char *name, const size_t length) { return length == 9 && name[4] == SCRIPT_LANGUAGE_SEPARATOR; } -static language_hash *figureOutLanguagesFromJson(json_value *languages, feature_hash *fh, - const char *tag) { +static language_hash *figureOutLanguagesFromJson(json_value *languages, feature_hash *fh, const char *tag) { language_hash *sh = NULL; // languages for (uint32_t j = 0; j < languages->u.object.length; j++) { @@ -534,10 +512,7 @@ static lookup_hash *figureOutLookupsFromJSON(json_value *lookups) { if (lookups->u.object.values[j].value->type == json_object) { char *lookupName = lookups->u.object.values[j].name; bool parsed = _parse_lookup(lookups->u.object.values[j].value, lookupName, &lh); - if (!parsed) { - fprintf(stderr, "[OTFCC-fea] Ignoring unknown or unsupported lookup %s.\n", - lookupName); - } + if (!parsed) { fprintf(stderr, "[OTFCC-fea] Ignoring unknown or unsupported lookup %s.\n", lookupName); } } } return lh; @@ -629,10 +604,9 @@ table_otl *caryll_otl_from_json(json_value *root, caryll_dump_options *dumpopts, return NULL; } -static bool _declare_lookup_writer(otl_lookup_type type, - caryll_buffer *(*fn)(otl_subtable *_subtable), - otl_lookup *lookup, caryll_buffer *buf, - uint32_t **subtableOffsets, uint32_t *lastOffset) { +static bool _declare_lookup_writer(otl_lookup_type type, caryll_buffer *(*fn)(otl_subtable *_subtable), + otl_lookup *lookup, caryll_buffer *buf, uint32_t **subtableOffsets, + uint32_t *lastOffset) { if (lookup->type == type) { NEW_N(*subtableOffsets, lookup->subtableCount); for (uint16_t j = 0; j < lookup->subtableCount; j++) { @@ -657,8 +631,7 @@ static caryll_buffer *writeOTLLookups(table_otl *table) { uint32_t lastOffset = 0; for (uint16_t j = 0; j < table->lookupCount; j++) { subtableOffsets[j] = NULL; - lookupWritten[j] = - _write_subtable(table->lookups[j], bufsts, &(subtableOffsets[j]), &lastOffset); + lookupWritten[j] = _write_subtable(table->lookups[j], bufsts, &(subtableOffsets[j]), &lastOffset); } // estimate the length of headers size_t headerSize = 2 + 2 * table->lookupCount; @@ -691,17 +664,14 @@ static caryll_buffer *writeOTLLookups(table_otl *table) { } // lookup type if (useExtended) { - bufwrite16b(bufl, (lookup->type > otl_type_gpos_unknown - ? otl_type_gpos_extend - otl_type_gpos_unknown - : lookup->type > otl_type_gsub_unknown - ? otl_type_gsub_extend - otl_type_gsub_unknown - : 0)); + bufwrite16b( + bufl, (lookup->type > otl_type_gpos_unknown + ? otl_type_gpos_extend - otl_type_gpos_unknown + : lookup->type > otl_type_gsub_unknown ? otl_type_gsub_extend - otl_type_gsub_unknown : 0)); } else { bufwrite16b(bufl, (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)); + : lookup->type > otl_type_gsub_unknown ? lookup->type - otl_type_gsub_unknown : 0)); } // lookup flags bufwrite16b(bufl, lookup->flags); @@ -713,11 +683,10 @@ static caryll_buffer *writeOTLLookups(table_otl *table) { for (uint16_t k = 0; k < lookup->subtableCount; k++) { // extension subtables size_t subtableStart = bufl->cursor; bufwrite16b(bufl, 1); - bufwrite16b(bufl, (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)); + bufwrite16b(bufl, + (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)); bufwrite32b(bufl, (uint32_t)(subtableOffsets[j][k] + headerSize - subtableStart)); } } else { @@ -929,21 +898,18 @@ caryll_buffer *caryll_write_otl(table_otl *table, caryll_dump_options *dumpopts) // CONFIG PART // //////////////////////////////////////////////////////////////////////////////////////// -#define DELETE_TYPE(type, fn) \ - case type: \ - fn(lookup); \ +#define DELETE_TYPE(type, fn) \ + case type: \ + fn(lookup); \ break; -#define LOOKUP_READER(llt, fn) \ - case llt: \ +#define LOOKUP_READER(llt, fn) \ + case llt: \ return fn(data, tableLength, subtableOffset); #define LOOKUP_DUMPER(llt, fn) _declare_lookup_dumper(llt, tableNames[llt], fn, lookup, dump); -#define LOOKUP_PARSER(llt, parser) \ - if (!parsed) { \ - parsed = _declareLookupParser(tableNames[llt], llt, parser, lookup, lookupName, lh); \ - } -#define LOOKUP_WRITER(type, fn) \ - if (!written) \ - written = _declare_lookup_writer(type, fn, lookup, buf, subtableOffsets, lastOffset); +#define LOOKUP_PARSER(llt, parser) \ + if (!parsed) { parsed = _declareLookupParser(tableNames[llt], llt, parser, lookup, lookupName, lh); } +#define LOOKUP_WRITER(type, fn) \ + if (!written) written = _declare_lookup_writer(type, fn, lookup, buf, subtableOffsets, lastOffset); static const char *tableNames[] = {[otl_type_unknown] = "unknown", [otl_type_gsub_unknown] = "gsub_unknown", [otl_type_gsub_single] = "gsub_single", @@ -987,8 +953,8 @@ void caryll_delete_lookup(otl_lookup *lookup) { } } -otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset, otl_lookup_type lookupType) { +otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, + otl_lookup_type lookupType) { switch (lookupType) { LOOKUP_READER(otl_type_gsub_single, caryll_read_gsub_single); LOOKUP_READER(otl_type_gsub_multiple, caryll_read_gsub_multi); @@ -1046,8 +1012,7 @@ static bool _parse_lookup(json_value *lookup, char *lookupName, lookup_hash **lh return parsed; } -static bool _write_subtable(otl_lookup *lookup, caryll_buffer *buf, uint32_t **subtableOffsets, - uint32_t *lastOffset) { +static bool _write_subtable(otl_lookup *lookup, caryll_buffer *buf, uint32_t **subtableOffsets, uint32_t *lastOffset) { bool written = false; LOOKUP_WRITER(otl_type_gsub_single, caryll_write_gsub_single_subtable); LOOKUP_WRITER(otl_type_gsub_multiple, caryll_write_gsub_multi_subtable); diff --git a/lib/tables/otl/otl.h b/lib/tables/otl/otl.h index f1f5dd47..f7863626 100644 --- a/lib/tables/otl/otl.h +++ b/lib/tables/otl/otl.h @@ -190,14 +190,13 @@ typedef struct { otl_lookup **lookups; } table_otl; -otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLength, - uint32_t subtableOffset, otl_lookup_type lookupType); +otl_subtable *caryll_read_otl_subtable(font_file_pointer data, uint32_t tableLength, uint32_t subtableOffset, + otl_lookup_type lookupType); table_otl *caryll_new_otl(); void caryll_delete_otl(table_otl *table); table_otl *caryll_read_otl(caryll_packet packet, uint32_t tag); -void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options *dumpopts, - const char *tag); +void caryll_otl_to_json(table_otl *table, json_value *root, caryll_dump_options *dumpopts, const char *tag); table_otl *caryll_otl_from_json(json_value *root, caryll_dump_options *dumpopts, const char *tag); caryll_buffer *caryll_write_otl(table_otl *table, caryll_dump_options *dumpopts); @@ -213,7 +212,7 @@ caryll_buffer *caryll_write_otl(table_otl *table, caryll_dump_options *dumpopts) #include "chaining.h" #include "extend.h" -#define checkLength(offset) \ +#define checkLength(offset) \ if (tableLength < offset) { goto FAIL; } #endif diff --git a/lib/tables/post.c b/lib/tables/post.c index 03f09e52..407e7647 100644 --- a/lib/tables/post.c +++ b/lib/tables/post.c @@ -101,8 +101,7 @@ table_post *caryll_post_from_json(json_value *root, caryll_dump_options *dumpopt } return post; } -caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, - caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, caryll_dump_options *dumpopts) { caryll_buffer *buf = bufnew(); if (!post) return buf; bufwrite32b(buf, post->version); diff --git a/lib/tables/post.h b/lib/tables/post.h index 194b8b65..88376089 100644 --- a/lib/tables/post.h +++ b/lib/tables/post.h @@ -24,7 +24,6 @@ table_post *caryll_read_post(caryll_packet packet); void caryll_delete_post(table_post *table); void caryll_post_to_json(table_post *table, json_value *root, caryll_dump_options *dumpopts); table_post *caryll_post_from_json(json_value *root, caryll_dump_options *dumpopts); -caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, - caryll_dump_options *dumpopts); +caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, caryll_dump_options *dumpopts); #endif diff --git a/lib/tables/vmtx.c b/lib/tables/vmtx.c index da09e66d..24e9cdef 100644 --- a/lib/tables/vmtx.c +++ b/lib/tables/vmtx.c @@ -1,9 +1,7 @@ #include "vmtx.h" table_vmtx *caryll_read_vmtx(caryll_packet packet, table_vhea *vhea, table_maxp *maxp) { - if (!vhea || !maxp || vhea->numOfLongVerMetrics == 0 || - maxp->numGlyphs < vhea->numOfLongVerMetrics) - return NULL; + if (!vhea || !maxp || vhea->numOfLongVerMetrics == 0 || maxp->numGlyphs < vhea->numOfLongVerMetrics) return NULL; FOR_TABLE('vmtx', table) { font_file_pointer data = table.data; uint32_t length = table.length; @@ -23,9 +21,7 @@ table_vmtx *caryll_read_vmtx(caryll_packet packet, table_vhea *vhea, table_maxp vmtx->metrics[ia].tsb = read_16u(data + ia * 4 + 2); } - for (uint32_t ik = 0; ik < count_k; ik++) { - vmtx->topSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); - } + for (uint32_t ik = 0; ik < count_k; ik++) { vmtx->topSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); } return vmtx; vmtx_CORRUPTED: @@ -42,8 +38,7 @@ void caryll_delete_vmtx(table_vmtx *table) { free(table); } -caryll_buffer *caryll_write_vmtx(table_vmtx *vmtx, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts) { +caryll_buffer *caryll_write_vmtx(table_vmtx *vmtx, uint16_t count_a, uint16_t count_k, caryll_dump_options *dumpopts) { caryll_buffer *buf = bufnew(); if (!vmtx) return buf; if (vmtx->metrics) { diff --git a/lib/tables/vmtx.h b/lib/tables/vmtx.h index 577ef05e..d93d8101 100644 --- a/lib/tables/vmtx.h +++ b/lib/tables/vmtx.h @@ -19,7 +19,6 @@ typedef struct { table_vmtx *caryll_read_vmtx(caryll_packet packet, table_vhea *vhea, table_maxp *maxp); void caryll_delete_vmtx(table_vmtx *table); -caryll_buffer *caryll_write_vmtx(table_vmtx *table, uint16_t count_a, uint16_t count_k, - caryll_dump_options *dumpopts); +caryll_buffer *caryll_write_vmtx(table_vmtx *table, uint16_t count_a, uint16_t count_k, caryll_dump_options *dumpopts); #endif diff --git a/src/otfccbuild.c b/src/otfccbuild.c index b17889ad..167a5151 100644 --- a/src/otfccbuild.c +++ b/src/otfccbuild.c @@ -18,42 +18,38 @@ #define PATCH_VER 0 #endif -void printInfo() { - fprintf(stdout, "This is otfccbuild, version %d.%d.%d.\n", MAIN_VER, SECONDARY_VER, PATCH_VER); -} +void printInfo() { fprintf(stdout, "This is otfccbuild, version %d.%d.%d.\n", MAIN_VER, SECONDARY_VER, PATCH_VER); } void printHelp() { - fprintf( - stdout, - "\n" - "Usage : otfccbuild [OPTIONS] [input.json] -o output.[ttf|otf]\n\n" - " input.json : Path to input file. When absent the input will\n" - " be read from the STDIN.\n" - " -h, --help : Display this help message and exit.\n" - " -v, --version : Display version information and exit.\n" - " -o : Set output file path to .\n" - " --time : Time each substep.\n" - " --ignore-glyph-order : Ignore the glyph order information in the input.\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" - " instead of stating the average width of glyphs. \n" - " Useful when creating a monospaced font.\n" - " --keep-modified-time : Keep the head.modified time in the json, instead\n" - " of using current time.\n" - " --short-post : Don't export glyph names in the result font. It \n" - " will reduce file size.\n" - " --dummy-dsig, -s : Include an empty DSIG table in the font. For\n" - " some Microsoft applications, a DSIG is required\n" - " to enable OpenType features.\n" - " -O : Specify the level for optimization.\n" - " -O0 Turn off any optimization.\n" - " -O1 Default optimization.\n" - " -O2 More aggressive optimizations for web font. In\n" - " this level, the --ignore-glyph-order and\n" - " --short-post will be turned on.\n" - // " -O3 In this level, CFF Subroutinization will be\n" - // " enabled to compress more. Building font may be\n" - // " slower than -O2.\n" - "\n"); + fprintf(stdout, "\n" + "Usage : otfccbuild [OPTIONS] [input.json] -o output.[ttf|otf]\n\n" + " input.json : Path to input file. When absent the input will\n" + " be read from the STDIN.\n" + " -h, --help : Display this help message and exit.\n" + " -v, --version : Display version information and exit.\n" + " -o : Set output file path to .\n" + " --time : Time each substep.\n" + " --ignore-glyph-order : Ignore the glyph order information in the input.\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" + " instead of stating the average width of glyphs. \n" + " Useful when creating a monospaced font.\n" + " --keep-modified-time : Keep the head.modified time in the json, instead\n" + " of using current time.\n" + " --short-post : Don't export glyph names in the result font. It \n" + " will reduce file size.\n" + " --dummy-dsig, -s : Include an empty DSIG table in the font. For\n" + " some Microsoft applications, a DSIG is required\n" + " to enable OpenType features.\n" + " -O : Specify the level for optimization.\n" + " -O0 Turn off any optimization.\n" + " -O1 Default optimization.\n" + " -O2 More aggressive optimizations for web font. In\n" + " this level, the --ignore-glyph-order and\n" + " --short-post will be turned on.\n" + // " -O3 In this level, CFF Subroutinization will be\n" + // " enabled to compress more. Building font may be\n" + // " slower than -O2.\n" + "\n"); } void readEntireFile(char *inPath, char **_buffer, long *_length) { char *buffer = NULL; @@ -101,9 +97,8 @@ void readEntireStdin(char **_buffer, long *_length) { } void print_table(sfnt_builder_entry *t) { - fprintf(stderr, "Writing Table %c%c%c%c, Length: %8d, Checksum: %08X\n", - ((uint32_t)(t->tag) >> 24) & 0xff, ((uint32_t)(t->tag) >> 16) & 0xff, - ((uint32_t)(t->tag) >> 8) & 0xff, t->tag & 0xff, t->length, t->checksum); + fprintf(stderr, "Writing Table %c%c%c%c, Length: %8d, Checksum: %08X\n", ((uint32_t)(t->tag) >> 24) & 0xff, + ((uint32_t)(t->tag) >> 16) & 0xff, ((uint32_t)(t->tag) >> 8) & 0xff, t->tag & 0xff, t->length, t->checksum); } #ifdef _WIN32 diff --git a/src/otfccdump.c b/src/otfccdump.c index 0c8433c4..acbe6435 100644 --- a/src/otfccdump.c +++ b/src/otfccdump.c @@ -17,9 +17,7 @@ #define PATCH_VER 0 #endif -void printInfo() { - fprintf(stdout, "This is otfccdump, version %d.%d.%d.\n", MAIN_VER, SECONDARY_VER, PATCH_VER); -} +void printInfo() { fprintf(stdout, "This is otfccdump, version %d.%d.%d.\n", MAIN_VER, SECONDARY_VER, PATCH_VER); } void printHelp() { fprintf(stdout, "\n" "Usage : otfccdump [OPTIONS] input.[otf|ttf|ttc]\n\n" @@ -150,8 +148,8 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } if (ttcindex >= sfnt->count) { - fprintf(stderr, "Subfont index %d out of range for \"%s\" (0 -- %d). Exit.\n", ttcindex, - inPath, (sfnt->count - 1)); + fprintf(stderr, "Subfont index %d out of range for \"%s\" (0 -- %d). Exit.\n", ttcindex, inPath, + (sfnt->count - 1)); exit(EXIT_FAILURE); } if (show_time) push_stopwatch("Read Input SFNT", &begin); @@ -184,9 +182,7 @@ int main(int argc, char *argv[]) { options.mode = json_serialize_mode_packed; options.opts = 0; options.indent_size = 4; - if (show_pretty || (!outputPath && isatty(fileno(stdout)))) { - options.mode = json_serialize_mode_multiline; - } + if (show_pretty || (!outputPath && isatty(fileno(stdout)))) { options.mode = json_serialize_mode_multiline; } if (show_ugly) options.mode = json_serialize_mode_packed; buf = malloc(json_measure_ex(root, options)); json_serialize_ex(buf, root, options); @@ -218,8 +214,7 @@ int main(int argc, char *argv[]) { while (written < dwNum) { DWORD len = dwNum - written; if (len > chunk) len = chunk; - WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), pwStr + written, len, &actual, - NULL); + WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), pwStr + written, len, &actual, NULL); written += len; } free(pwStr); diff --git a/src/platform.h b/src/platform.h index 3e6fd5a8..df5bf838 100644 --- a/src/platform.h +++ b/src/platform.h @@ -14,8 +14,7 @@ int get_argv_utf8(int *argc_ptr, char ***argv_ptr) { int i; int offset = (argc + 1) * sizeof(char *); int size = offset; - for (i = 0; i < argc; i++) - size += WideCharToMultiByte(CP_UTF8, 0, argv_utf16[i], -1, 0, 0, 0, 0); + for (i = 0; i < argc; i++) size += WideCharToMultiByte(CP_UTF8, 0, argv_utf16[i], -1, 0, 0, 0, 0); argv = (char **)malloc(size); for (i = 0; i < argc; i++) { argv[i] = (char *)argv + offset; From 25cd7dba936048ce154ff09660192a91b330e166 Mon Sep 17 00:00:00 2001 From: be5invis Date: Fri, 29 Jul 2016 22:19:22 +0800 Subject: [PATCH 12/16] Fully supported VORG. --- lib/font/caryll-font.c | 13 ++++---- lib/fontops/stat.c | 64 ++++++++++++++++++++++++++++++++----- lib/fontops/unconsolidate.c | 3 +- lib/support/options.h | 1 + lib/tables/VORG.c | 14 ++++++++ lib/tables/VORG.h | 7 ++-- lib/tables/glyf.c | 64 ++++++++++++++++++++----------------- lib/tables/glyf.h | 11 +++++-- lib/tables/otl/otl.c | 8 ++--- lib/tables/otl/otl.h | 2 +- src/otfccbuild.c | 4 +++ src/otfccdump.c | 1 + src/stopwatch.c | 2 +- 13 files changed, 136 insertions(+), 58 deletions(-) diff --git a/lib/font/caryll-font.c b/lib/font/caryll-font.c index 74d5c754..5c6cb50b 100644 --- a/lib/font/caryll-font.c +++ b/lib/font/caryll-font.c @@ -166,11 +166,9 @@ caryll_buffer *caryll_write_font(caryll_font *font, caryll_options *options) { // Outline data if (font->subtype == FONTTYPE_TTF) { - caryll_buffer *bufglyf = bufnew(); - caryll_buffer *bufloca = bufnew(); - if (font->glyf && font->head) { caryll_write_glyf(font->glyf, font->head, bufglyf, bufloca, options); } - sfnt_builder_push_table(builder, 'loca', bufloca); - sfnt_builder_push_table(builder, 'glyf', bufglyf); + glyf_loca_bufpair pair = caryll_write_glyf(font->glyf, font->head, options); + sfnt_builder_push_table(builder, 'glyf', pair.glyf); + sfnt_builder_push_table(builder, 'loca', pair.loca); } else { caryll_cff_parse_result r = {font->CFF_, font->glyf}; sfnt_builder_push_table(builder, 'CFF ', caryll_write_CFF(r, options)); @@ -198,9 +196,10 @@ caryll_buffer *caryll_write_font(caryll_font *font, caryll_options *options) { caryll_write_vmtx(font->vmtx, font->vhea->numOfLongVerMetrics, font->maxp->numGlyphs - font->vhea->numOfLongVerMetrics, options)); } + if (font->VORG) { sfnt_builder_push_table(builder, 'VORG', caryll_write_VORG(font->VORG, options)); } - if (font->GSUB) sfnt_builder_push_table(builder, 'GSUB', caryll_write_otl(font->GSUB, options)); - if (font->GPOS) sfnt_builder_push_table(builder, 'GPOS', caryll_write_otl(font->GPOS, options)); + if (font->GSUB) sfnt_builder_push_table(builder, 'GSUB', caryll_write_otl(font->GSUB, options, "GSUB")); + if (font->GPOS) sfnt_builder_push_table(builder, 'GPOS', caryll_write_otl(font->GPOS, options, "GPOS")); if (font->GDEF) sfnt_builder_push_table(builder, 'GDEF', caryll_write_GDEF(font->GDEF, options)); if (options->dummy_DSIG) { diff --git a/lib/fontops/stat.c b/lib/fontops/stat.c index 70d66249..8320ae68 100644 --- a/lib/fontops/stat.c +++ b/lib/fontops/stat.c @@ -139,7 +139,7 @@ void caryll_stat_maxp(caryll_font *font) { font->maxp->maxSizeOfInstructions = instSize; } -void caryll_font_stat_hmtx(caryll_font *font) { +static void caryll_font_stat_hmtx(caryll_font *font, caryll_options *options) { if (!font->glyf) return; table_hmtx *hmtx = malloc(sizeof(table_hmtx) * 1); if (!hmtx) return; @@ -188,13 +188,13 @@ void caryll_font_stat_hmtx(caryll_font *font) { font->hhea->advanceWithMax = maxWidth; font->hmtx = hmtx; } -void caryll_font_stat_vmtx(caryll_font *font) { +static void caryll_font_stat_vmtx(caryll_font *font, caryll_options *options) { if (!font->glyf) return; table_vmtx *vmtx = malloc(sizeof(table_vmtx) * 1); if (!vmtx) return; uint16_t count_a = font->glyf->numberGlyphs; int16_t count_k = 0; - if (font->subtype == FONTTYPE_CFF) { + if (font->subtype == FONTTYPE_CFF && !options->cff_short_vmtx) { // pass } else { while (count_a > 2 && @@ -427,16 +427,20 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_options *options) { font->OS_2->xAvgCharWidth = totalWidth / font->glyf->numberGlyphs; } } + +#define MAX_STAT_METRIC 4096 static void caryll_stat_cff_widths(caryll_font *font) { if (!font->glyf || !font->CFF_) return; // Stat the most frequent character width - uint32_t *frequency = calloc(2000, sizeof(uint32_t)); + uint32_t *frequency = calloc(MAX_STAT_METRIC, sizeof(uint32_t)); for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { - if (font->glyf->glyphs[j]->advanceWidth < 2000) { frequency[font->glyf->glyphs[j]->advanceWidth] += 1; } + if (font->glyf->glyphs[j]->advanceWidth < MAX_STAT_METRIC) { + frequency[font->glyf->glyphs[j]->advanceWidth] += 1; + } } uint16_t maxfreq = 0; uint16_t maxj = 0; - for (uint16_t j = 0; j < 2000; j++) { + for (uint16_t j = 0; j < MAX_STAT_METRIC; j++) { if (frequency[j] > maxfreq) { maxfreq = frequency[j]; maxj = j; @@ -461,6 +465,47 @@ static void caryll_stat_cff_widths(caryll_font *font) { } } +static void caryll_stat_cff_vorgs(caryll_font *font) { + if (!font->glyf || !font->CFF_ || !font->vhea || !font->vmtx) return; + uint32_t *frequency = calloc(MAX_STAT_METRIC, sizeof(uint32_t)); + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { + if (font->glyf->glyphs[j]->verticalOrigin >= 0 && font->glyf->glyphs[j]->verticalOrigin < MAX_STAT_METRIC) { + frequency[(uint16_t)(font->glyf->glyphs[j]->verticalOrigin)] += 1; + } + } + // stat VORG.defaultVerticalOrigin + uint16_t maxfreq = 0; + uint16_t maxj = 0; + for (uint16_t j = 0; j < MAX_STAT_METRIC; j++) { + if (frequency[j] > maxfreq) { + maxfreq = frequency[j]; + maxj = j; + } + } + + table_VORG *vorg; + NEW(vorg); + vorg->defaultVerticalOrigin = maxj; + + uint16_t nVertOrigs = 0; + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { + if (font->glyf->glyphs[j]->verticalOrigin != maxj) { nVertOrigs += 1; } + } + vorg->numVertOriginYMetrics = nVertOrigs; + NEW_N(vorg->entries, nVertOrigs); + + uint16_t jj = 0; + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { + if (font->glyf->glyphs[j]->verticalOrigin != maxj) { + vorg->entries[jj].gid = j; + vorg->entries[jj].verticalOrigin = font->glyf->glyphs[j]->verticalOrigin; + jj += 1; + } + } + + font->VORG = vorg; +} + void caryll_font_stat(caryll_font *font, caryll_options *options) { if (font->glyf && font->head) { caryll_stat_glyf(font); @@ -489,6 +534,9 @@ void caryll_font_stat(caryll_font *font, caryll_options *options) { } else { if (font->maxp) font->maxp->version = 0x00005000; } - if (font->glyf && font->hhea) caryll_font_stat_hmtx(font); - if (font->glyf && font->vhea) caryll_font_stat_vmtx(font); + if (font->glyf && font->hhea) { caryll_font_stat_hmtx(font, options); } + if (font->glyf && font->vhea) { + caryll_font_stat_vmtx(font, options); + caryll_stat_cff_vorgs(font); + } } diff --git a/lib/fontops/unconsolidate.c b/lib/fontops/unconsolidate.c index 22efc9ca..25e4eb3f 100644 --- a/lib/fontops/unconsolidate.c +++ b/lib/fontops/unconsolidate.c @@ -262,7 +262,8 @@ static void merge_vmtx(caryll_font *font) { } for (uint16_t j = 0; j < font->VORG->numVertOriginYMetrics; j++) { if (font->VORG->entries[j].gid < font->glyf->numberGlyphs) { - font->glyf->glyphs[j]->verticalOrigin = font->VORG->entries[j].verticalOrigin; + font->glyf->glyphs[font->VORG->entries[j].gid]->verticalOrigin = + font->VORG->entries[j].verticalOrigin; } } } diff --git a/lib/support/options.h b/lib/support/options.h index 9c09275c..b2dd2886 100644 --- a/lib/support/options.h +++ b/lib/support/options.h @@ -16,6 +16,7 @@ typedef struct { bool keep_modified_time; bool instr_as_bytes; bool verbose; + bool cff_short_vmtx; char *glyph_name_prefix; uint8_t optimize_level; } caryll_options; diff --git a/lib/tables/VORG.c b/lib/tables/VORG.c index 96b769ca..9e4e1e16 100644 --- a/lib/tables/VORG.c +++ b/lib/tables/VORG.c @@ -25,3 +25,17 @@ void caryll_delete_VORG(table_VORG *vorg) { if (vorg) free(vorg->entries); free(vorg); } + +caryll_buffer *caryll_write_VORG(table_VORG *table, caryll_options *options) { + caryll_buffer *buf = bufnew(); + if (!table) return buf; + bufwrite16b(buf, 1); + bufwrite16b(buf, 0); + bufwrite16b(buf, table->defaultVerticalOrigin); + bufwrite16b(buf, table->numVertOriginYMetrics); + for (uint16_t j = 0; j < table->numVertOriginYMetrics; j++) { + bufwrite16b(buf, table->entries[j].gid); + bufwrite16b(buf, table->entries[j].verticalOrigin); + } + return buf; +} diff --git a/lib/tables/VORG.h b/lib/tables/VORG.h index 42c1dc75..192f16c6 100644 --- a/lib/tables/VORG.h +++ b/lib/tables/VORG.h @@ -5,16 +5,17 @@ #include typedef struct { - int16_t verticalOrigin; uint16_t gid; + int16_t verticalOrigin; } VORG_entry; typedef struct { - VORG_entry *entries; uint16_t numVertOriginYMetrics; int16_t defaultVerticalOrigin; + VORG_entry *entries; } table_VORG; -table_VORG *caryll_read_VORG(caryll_packet packet); void caryll_delete_VORG(table_VORG *vorg); +table_VORG *caryll_read_VORG(caryll_packet packet); +caryll_buffer *caryll_write_VORG(table_VORG *table, caryll_options *options); #endif diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index 0b83e795..508c1595 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -828,38 +828,42 @@ static void glyf_write_composite(glyf_glyph *g, caryll_buffer *gbuf) { if (g->instructions) bufwrite_bytes(gbuf, g->instructionsLength, g->instructions); } } -void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, caryll_buffer *bufloca, - caryll_options *options) { - caryll_buffer *gbuf = bufnew(); - - uint32_t *loca = malloc((table->numberGlyphs + 1) * sizeof(uint32_t)); - for (uint16_t j = 0; j < table->numberGlyphs; j++) { - loca[j] = (uint32_t)bufglyf->cursor; - glyf_glyph *g = table->glyphs[j]; - bufclear(gbuf); - if (g->numberOfContours > 0) { - glyf_write_simple(g, gbuf); - } else if (g->numberOfReferences > 0) { - glyf_write_composite(g, gbuf); +glyf_loca_bufpair caryll_write_glyf(table_glyf *table, table_head *head, caryll_options *options) { + caryll_buffer *bufglyf = bufnew(); + caryll_buffer *bufloca = bufnew(); + if (table && head) { + caryll_buffer *gbuf = bufnew(); + uint32_t *loca = malloc((table->numberGlyphs + 1) * sizeof(uint32_t)); + for (uint16_t j = 0; j < table->numberGlyphs; j++) { + loca[j] = (uint32_t)bufglyf->cursor; + glyf_glyph *g = table->glyphs[j]; + bufclear(gbuf); + if (g->numberOfContours > 0) { + glyf_write_simple(g, gbuf); + } else if (g->numberOfReferences > 0) { + glyf_write_composite(g, gbuf); + } + // pad extra zeroes + buflongalign(gbuf); + bufwrite_buf(bufglyf, gbuf); } - // pad extra zeroes - buflongalign(gbuf); - bufwrite_buf(bufglyf, gbuf); - } - loca[table->numberGlyphs] = (uint32_t)bufglyf->cursor; - if (bufglyf->cursor >= 0x20000) { - head->indexToLocFormat = 1; - } else { - head->indexToLocFormat = 0; - } - // write loca table - for (uint32_t j = 0; j <= table->numberGlyphs; j++) { - if (head->indexToLocFormat) { - bufwrite32b(bufloca, loca[j]); + loca[table->numberGlyphs] = (uint32_t)bufglyf->cursor; + if (bufglyf->cursor >= 0x20000) { + head->indexToLocFormat = 1; } else { - bufwrite16b(bufloca, loca[j] >> 1); + head->indexToLocFormat = 0; + } + // write loca table + for (uint32_t j = 0; j <= table->numberGlyphs; j++) { + if (head->indexToLocFormat) { + bufwrite32b(bufloca, loca[j]); + } else { + bufwrite16b(bufloca, loca[j] >> 1); + } } + buffree(gbuf); + free(loca); } - buffree(gbuf); - free(loca); + glyf_loca_bufpair pair = {bufglyf, bufloca}; + return pair; } diff --git a/lib/tables/glyf.h b/lib/tables/glyf.h index 1a37488c..b9c1302f 100644 --- a/lib/tables/glyf.h +++ b/lib/tables/glyf.h @@ -70,7 +70,7 @@ typedef struct { // Metrics uint16_t advanceWidth; uint16_t advanceHeight; - float verticalOrigin; + int16_t verticalOrigin; // Outline // NOTE: SFNT does not support mixed glyphs, but we do. @@ -134,7 +134,12 @@ table_glyf *caryll_read_glyf(caryll_packet packet, table_head *head, table_maxp void caryll_delete_glyf(table_glyf *table); void caryll_glyf_to_json(table_glyf *table, json_value *root, caryll_options *options); table_glyf *caryll_glyf_from_json(json_value *root, glyph_order_hash glyph_order, caryll_options *options); -void caryll_write_glyf(table_glyf *table, table_head *head, caryll_buffer *bufglyf, caryll_buffer *bufloca, - caryll_options *options); + +typedef struct { + caryll_buffer *glyf; + caryll_buffer *loca; +} glyf_loca_bufpair; + +glyf_loca_bufpair caryll_write_glyf(table_glyf *table, table_head *head, caryll_options *options); #endif diff --git a/lib/tables/otl/otl.c b/lib/tables/otl/otl.c index 32ae0747..e53aee04 100644 --- a/lib/tables/otl/otl.c +++ b/lib/tables/otl/otl.c @@ -623,7 +623,7 @@ static bool _declare_lookup_writer(otl_lookup_type type, caryll_buffer *(*fn)(ot } // When writing lookups, otfcc will try to maintain everything correctly. -static caryll_buffer *writeOTLLookups(table_otl *table, caryll_options *options) { +static caryll_buffer *writeOTLLookups(table_otl *table, caryll_options *options, const char *tag) { caryll_buffer *bufl = bufnew(); caryll_buffer *bufsts = bufnew(); uint32_t **subtableOffsets; @@ -643,7 +643,7 @@ static caryll_buffer *writeOTLLookups(table_otl *table, caryll_options *options) } bool useExtended = lastOffset >= 0xFF00 - headerSize; if (useExtended) { - if (options->verbose) { fprintf(stderr, "[OTFCC-fea] Using extended OpenType table layout.\n"); } + if (options->verbose) { fprintf(stderr, "[OTFCC-fea] Using extended OpenType table layout for %s.\n", tag); } for (uint16_t j = 0; j < table->lookupCount; j++) { if (lookupWritten[j]) { headerSize += 8 * table->lookups[j]->subtableCount; } } @@ -861,11 +861,11 @@ static caryll_buffer *writeOTLScriptAndLanguages(table_otl *table, caryll_option return bufs; } -caryll_buffer *caryll_write_otl(table_otl *table, caryll_options *options) { +caryll_buffer *caryll_write_otl(table_otl *table, caryll_options *options, const char *tag) { caryll_buffer *buf = bufnew(); bufwrite32b(buf, 0x10000); - caryll_buffer *bufl = writeOTLLookups(table, options); + caryll_buffer *bufl = writeOTLLookups(table, options, tag); caryll_buffer *buff = writeOTLFeatures(table, options); caryll_buffer *bufs = writeOTLScriptAndLanguages(table, options); diff --git a/lib/tables/otl/otl.h b/lib/tables/otl/otl.h index 6c2f2152..1051c73b 100644 --- a/lib/tables/otl/otl.h +++ b/lib/tables/otl/otl.h @@ -198,7 +198,7 @@ void caryll_delete_otl(table_otl *table); table_otl *caryll_read_otl(caryll_packet packet, uint32_t tag); void caryll_otl_to_json(table_otl *table, json_value *root, caryll_options *options, const char *tag); table_otl *caryll_otl_from_json(json_value *root, caryll_options *options, const char *tag); -caryll_buffer *caryll_write_otl(table_otl *table, caryll_options *options); +caryll_buffer *caryll_write_otl(table_otl *table, caryll_options *options, const char *tag); #include "gsub-single.h" #include "gsub-multi.h" diff --git a/src/otfccbuild.c b/src/otfccbuild.c index 81a3fb1e..9e489401 100644 --- a/src/otfccbuild.c +++ b/src/otfccbuild.c @@ -161,6 +161,7 @@ int main(int argc, char *argv[]) { options->dummy_DSIG = true; } else if (strcmp(longopts[option_index].name, "verbose") == 0) { options->verbose = true; + show_time = true; } break; case 'v': @@ -180,6 +181,7 @@ int main(int argc, char *argv[]) { if (options->optimize_level >= 2) { options->short_post = true; options->ignore_glyph_order = true; + options->cff_short_vmtx = true; } break; } @@ -210,8 +212,10 @@ int main(int argc, char *argv[]) { long length; { if (inPath) { + if (options->verbose) { fprintf(stderr, "Building OpenType font from %s to %s.\n", inPath, outputPath); } readEntireFile(inPath, &buffer, &length); } else { + if (options->verbose) { fprintf(stderr, "Building OpenType font from %s to %s.\n", "[STDIN]", outputPath); } readEntireStdin(&buffer, &length); } if (show_time) push_stopwatch("Read input", &begin); diff --git a/src/otfccdump.c b/src/otfccdump.c index c0f46988..605b488f 100644 --- a/src/otfccdump.c +++ b/src/otfccdump.c @@ -96,6 +96,7 @@ int main(int argc, char *argv[]) { options->ignore_glyph_order = true; } else if (strcmp(longopts[option_index].name, "verbose") == 0) { options->verbose = true; + show_time = true; } else if (strcmp(longopts[option_index].name, "ignore-hints") == 0) { options->ignore_hints = true; } else if (strcmp(longopts[option_index].name, "instr-as-bytes") == 0) { diff --git a/src/stopwatch.c b/src/stopwatch.c index fea671b8..18329088 100644 --- a/src/stopwatch.c +++ b/src/stopwatch.c @@ -99,5 +99,5 @@ void push_stopwatch(const char *reason, struct timespec *sofar) { struct timespec diff; timespec_diff(sofar, &ends, &diff); *sofar = ends; - fprintf(stderr, "%s: %g\n", reason, diff.tv_sec + diff.tv_nsec / (double)BILLION); + fprintf(stderr, "Done %s (%gs).\n", reason, diff.tv_sec + diff.tv_nsec / (double)BILLION); } From 0594a19d360ea666221528403b0ce1f0e78cd33b Mon Sep 17 00:00:00 2001 From: be5invis Date: Fri, 29 Jul 2016 22:55:32 +0800 Subject: [PATCH 13/16] supported LTSH table --- lib/font/caryll-font.c | 12 +++++++++--- lib/font/caryll-font.h | 2 ++ lib/fontops/stat.c | 16 ++++++++++++++++ lib/fontops/unconsolidate.c | 8 ++++++++ lib/tables/LTSH.c | 12 ++++++++++++ lib/tables/LTSH.h | 2 ++ lib/tables/glyf.c | 7 +++---- lib/tables/glyf.h | 2 ++ 8 files changed, 54 insertions(+), 7 deletions(-) diff --git a/lib/font/caryll-font.c b/lib/font/caryll-font.c index 5c6cb50b..6357de05 100644 --- a/lib/font/caryll-font.c +++ b/lib/font/caryll-font.c @@ -49,6 +49,7 @@ void caryll_delete_font(caryll_font *font) { if (font->CFF_) caryll_delete_CFF(font->CFF_); if (font->glyf) caryll_delete_glyf(font->glyf); if (font->cmap) caryll_delete_cmap(font->cmap); + if (font->LTSH) caryll_delete_LTSH(font->LTSH); if (font->GSUB) caryll_delete_otl(font->GSUB); if (font->GPOS) caryll_delete_otl(font->GPOS); if (font->GDEF) caryll_delete_GDEF(font->GDEF); @@ -85,6 +86,7 @@ caryll_font *caryll_read_font(caryll_sfnt *sfnt, uint32_t index) { font->prep = caryll_read_fpgm_prep(packet, 'prep'); font->cvt_ = caryll_read_cvt(packet, 'cvt '); font->gasp = caryll_read_gasp(packet); + font->LTSH = caryll_read_LTSH(packet); font->glyf = caryll_read_glyf(packet, font->head, font->maxp); } else { caryll_cff_parse_result cffpr = caryll_read_CFF_and_glyf(packet); @@ -181,11 +183,15 @@ caryll_buffer *caryll_write_font(caryll_font *font, caryll_options *options) { sfnt_builder_push_table(builder, 'name', caryll_write_name(font->name, options)); sfnt_builder_push_table(builder, 'post', caryll_write_post(font->post, font->glyph_order, options)); sfnt_builder_push_table(builder, 'cmap', caryll_write_cmap(font->cmap, options)); - if (font->fpgm) sfnt_builder_push_table(builder, 'fpgm', caryll_write_fpgm_prep(font->fpgm, options)); - if (font->prep) sfnt_builder_push_table(builder, 'prep', caryll_write_fpgm_prep(font->prep, options)); - if (font->cvt_) sfnt_builder_push_table(builder, 'cvt ', caryll_write_cvt(font->cvt_, options)); if (font->gasp) sfnt_builder_push_table(builder, 'gasp', caryll_write_gasp(font->gasp, options)); + if (font->subtype == FONTTYPE_TTF) { + if (font->fpgm) sfnt_builder_push_table(builder, 'fpgm', caryll_write_fpgm_prep(font->fpgm, options)); + if (font->prep) sfnt_builder_push_table(builder, 'prep', caryll_write_fpgm_prep(font->prep, options)); + if (font->cvt_) sfnt_builder_push_table(builder, 'cvt ', caryll_write_cvt(font->cvt_, options)); + if (font->LTSH) sfnt_builder_push_table(builder, 'LTSH', caryll_write_LTSH(font->LTSH, options)); + } + sfnt_builder_push_table(builder, 'hmtx', caryll_write_hmtx(font->hmtx, font->hhea->numberOfMetrics, font->maxp->numGlyphs - font->hhea->numberOfMetrics, options)); diff --git a/lib/font/caryll-font.h b/lib/font/caryll-font.h index b40868a9..9ca2964e 100644 --- a/lib/font/caryll-font.h +++ b/lib/font/caryll-font.h @@ -60,6 +60,8 @@ struct _caryll_font { table_cvt *cvt_; table_gasp *gasp; + table_LTSH *LTSH; + table_otl *GSUB; table_otl *GPOS; table_GDEF *GDEF; diff --git a/lib/fontops/stat.c b/lib/fontops/stat.c index 8320ae68..22afea9e 100644 --- a/lib/fontops/stat.c +++ b/lib/fontops/stat.c @@ -506,6 +506,21 @@ static void caryll_stat_cff_vorgs(caryll_font *font) { font->VORG = vorg; } +static void caryll_stat_LTSH(caryll_font *font) { + if (!font->glyf) return; + bool needLTSH = false; + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) + if (font->glyf->glyphs[j]->yPel > 1) { needLTSH = true; } + if (!needLTSH) return; + + table_LTSH *ltsh; + NEW(ltsh); + ltsh->numGlyphs = font->glyf->numberGlyphs; + NEW_N(ltsh->yPels, ltsh->numGlyphs); + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { ltsh->yPels[j] = font->glyf->glyphs[j]->yPel; } + font->LTSH = ltsh; +} + void caryll_font_stat(caryll_font *font, caryll_options *options) { if (font->glyf && font->head) { caryll_stat_glyf(font); @@ -539,4 +554,5 @@ void caryll_font_stat(caryll_font *font, caryll_options *options) { caryll_font_stat_vmtx(font, options); caryll_stat_cff_vorgs(font); } + caryll_stat_LTSH(font); } diff --git a/lib/fontops/unconsolidate.c b/lib/fontops/unconsolidate.c index 25e4eb3f..e748a99d 100644 --- a/lib/fontops/unconsolidate.c +++ b/lib/fontops/unconsolidate.c @@ -269,10 +269,18 @@ static void merge_vmtx(caryll_font *font) { } } } +static void merge_LTSH(caryll_font *font) { + if (font->glyf && font->LTSH) { + for (uint16_t j = 0; j < font->glyf->numberGlyphs && j < font->LTSH->numGlyphs; j++) { + font->glyf->glyphs[j]->yPel = font->LTSH->yPels[j]; + } + } +} void caryll_font_unconsolidate(caryll_font *font, caryll_options *options) { // Merge metrics merge_hmtx(font); merge_vmtx(font); + merge_LTSH(font); // Name glyphs caryll_name_glyphs(font, options); diff --git a/lib/tables/LTSH.c b/lib/tables/LTSH.c index bd8db90c..f390ee2f 100644 --- a/lib/tables/LTSH.c +++ b/lib/tables/LTSH.c @@ -1,5 +1,9 @@ #include "LTSH.h" +void caryll_delete_LTSH(table_LTSH *ltsh) { + if (ltsh) { free(ltsh->yPels); } + free(ltsh); +} table_LTSH *caryll_read_LTSH(caryll_packet packet) { FOR_TABLE('LTSH', table) { font_file_pointer data = table.data; @@ -14,3 +18,11 @@ table_LTSH *caryll_read_LTSH(caryll_packet packet) { } return NULL; } +caryll_buffer *caryll_write_LTSH(table_LTSH *ltsh, caryll_options *options) { + caryll_buffer *buf = bufnew(); + if (!ltsh) return buf; + bufwrite16b(buf, 0); + bufwrite16b(buf, ltsh->numGlyphs); + for (uint16_t j = 0; j < ltsh->numGlyphs; j++) { bufwrite8(buf, ltsh->yPels[j]); } + return buf; +} diff --git a/lib/tables/LTSH.h b/lib/tables/LTSH.h index 224ef812..5e5a1cb9 100644 --- a/lib/tables/LTSH.h +++ b/lib/tables/LTSH.h @@ -11,5 +11,7 @@ typedef struct { } table_LTSH; table_LTSH *caryll_read_LTSH(caryll_packet packet); +void caryll_delete_LTSH(table_LTSH *ltsh); +caryll_buffer *caryll_write_LTSH(table_LTSH *ltsh, caryll_options *options); #endif diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index 508c1595..cc062361 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -431,7 +431,7 @@ static json_value *glyf_glyph_maskdefs_to_json(glyf_postscript_hint_mask *masks, } static json_value *glyf_glyph_to_json(glyf_glyph *g, caryll_options *options) { - json_value *glyph = json_object_new(10); + json_value *glyph = json_object_new(12); if (options->export_fdselect) { json_object_push(glyph, "fdSelectIndex", json_integer_new(g->fdSelectIndex)); } json_object_push(glyph, "advanceWidth", json_integer_new(g->advanceWidth)); if (options->has_vertical_metrics) { @@ -459,6 +459,7 @@ static json_value *glyf_glyph_to_json(glyf_glyph *g, caryll_options *options) { preserialize(glyf_glyph_maskdefs_to_json(g->contourMasks, g->numberOfContourMasks, g->numberOfStemH, g->numberOfStemV))); } + if (g->yPel) { json_object_push(glyph, "yPel", json_integer_new(g->yPel)); } return glyph; } void caryll_glyphorder_to_json(table_glyf *table, json_value *root) { @@ -631,6 +632,7 @@ static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, glyph_orde g->advanceHeight = json_obj_getint(glyphdump, "advanceHeight"); g->verticalOrigin = json_obj_getint(glyphdump, "verticalOrigin"); g->fdSelectIndex = json_obj_getint(glyphdump, "fdSelectIndex"); + g->yPel = json_obj_getint(glyphdump, "yPel"); glyf_contours_from_json(json_obj_get_type(glyphdump, "contours", json_array), g); glyf_references_from_json(json_obj_get_type(glyphdump, "references", json_array), g); if (!options->ignore_hints) { @@ -641,9 +643,6 @@ static glyf_glyph *caryll_glyf_glyph_from_json(json_value *glyphdump, glyph_orde &(g->hintMasks)); masks_from_json(json_obj_get_type(glyphdump, "contourMasks", json_array), &(g->numberOfContourMasks), &(g->contourMasks)); - } else { - g->instructionsLength = 0; - g->instructions = NULL; } return g; } diff --git a/lib/tables/glyf.h b/lib/tables/glyf.h index b9c1302f..33eabc28 100644 --- a/lib/tables/glyf.h +++ b/lib/tables/glyf.h @@ -92,6 +92,8 @@ typedef struct { // TTF instructions uint16_t instructionsLength; uint8_t *instructions; + // TTF Screen specific + uint8_t yPel; // CID FDSelect uint16_t fdSelectIndex; From 959f033646b9eb3adca2d168d0b2d7670172b7ba Mon Sep 17 00:00:00 2001 From: be5invis Date: Fri, 29 Jul 2016 23:07:14 +0800 Subject: [PATCH 14/16] format: disbale one-line loops and functions --- .clang-format | 4 +- lib/font/caryll-font.c | 4 +- lib/font/caryll-sfnt-builder.c | 12 +++-- lib/font/caryll-sfnt.c | 8 +++- lib/fontops/consolidate.c | 32 +++++++++---- lib/fontops/otl/GDEF.c | 4 +- lib/fontops/otl/chaining.c | 8 +++- lib/fontops/otl/common.c | 4 +- lib/fontops/otl/gpos-cursive.c | 4 +- lib/fontops/otl/gpos-single.c | 4 +- lib/fontops/otl/gsub-multi.c | 4 +- lib/fontops/otl/gsub-reverse.c | 8 +++- lib/fontops/otl/gsub-single.c | 4 +- lib/fontops/otl/mark.c | 12 +++-- lib/fontops/stat.c | 8 +++- lib/fontops/unconsolidate.c | 16 +++++-- lib/libcff/cff-charset.c | 3 +- lib/libcff/cff-codecs.c | 8 +++- lib/libcff/cff-dict.c | 4 +- lib/libcff/cff-fdselect.c | 7 ++- lib/libcff/cff-parser.c | 14 ++++-- lib/libcff/cff-writer.c | 8 +++- lib/libcff/charstring_il.c | 4 +- lib/support/base64.c | 3 +- lib/support/buffer.c | 20 ++++++-- lib/support/glyphorder.c | 4 +- lib/support/ttinstr.c | 24 ++++++---- lib/support/unicodeconv.c | 8 +++- lib/support/util.h | 40 ++++++++++++---- lib/tables/CFF.c | 64 +++++++++++++++++++------- lib/tables/LTSH.c | 4 +- lib/tables/OS_2.c | 4 +- lib/tables/cmap.c | 16 +++++-- lib/tables/cvt.c | 16 +++++-- lib/tables/glyf.c | 20 ++++++-- lib/tables/hmtx.c | 8 +++- lib/tables/otl/chaining.c | 16 +++++-- lib/tables/otl/classdef.c | 4 +- lib/tables/otl/coverage.c | 8 +++- lib/tables/otl/gpos-common.c | 12 +++-- lib/tables/otl/gpos-mark-to-ligature.c | 14 ++++-- lib/tables/otl/gpos-mark-to-single.c | 11 +++-- lib/tables/otl/gpos-pair.c | 15 ++++-- lib/tables/otl/gpos-single.c | 4 +- lib/tables/otl/gsub-ligature.c | 12 +++-- lib/tables/otl/gsub-multi.c | 12 +++-- lib/tables/otl/gsub-reverse.c | 12 +++-- lib/tables/otl/gsub-single.c | 4 +- lib/tables/otl/otl.c | 16 +++++-- lib/tables/post.c | 8 +++- lib/tables/vmtx.c | 8 +++- src/stopwatch.c | 4 +- 52 files changed, 426 insertions(+), 149 deletions(-) diff --git a/.clang-format b/.clang-format index 053b353a..35f45e07 100644 --- a/.clang-format +++ b/.clang-format @@ -3,9 +3,9 @@ TabWidth: 4 IndentWidth: 4 UseTab: ForIndentation AllowShortBlocksOnASingleLine: true -AllowShortFunctionsOnASingleLine: All +AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true +AllowShortLoopsOnASingleLine: false ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: true IndentCaseLabels: true diff --git a/lib/font/caryll-font.c b/lib/font/caryll-font.c index 6357de05..43f8cb5a 100644 --- a/lib/font/caryll-font.c +++ b/lib/font/caryll-font.c @@ -60,7 +60,9 @@ void caryll_delete_font(caryll_font *font) { caryll_font_subtype caryll_decide_font_subtype(caryll_sfnt *sfnt, uint32_t index) { caryll_packet packet = sfnt->packets[index]; - FOR_TABLE('CFF ', table) { return FONTTYPE_CFF; } + FOR_TABLE('CFF ', table) { + return FONTTYPE_CFF; + } return FONTTYPE_TTF; } diff --git a/lib/font/caryll-sfnt-builder.c b/lib/font/caryll-sfnt-builder.c index 7beddc74..ca40006e 100644 --- a/lib/font/caryll-sfnt-builder.c +++ b/lib/font/caryll-sfnt-builder.c @@ -17,7 +17,9 @@ static uint32_t buf_checksum(caryll_buffer *buffer) { { uint32_t *start = (uint32_t *)buffer->data; uint32_t *end = start + ((actualLength + 3) & ~3) / sizeof(uint32_t); - while (start < end) { sum += caryll_endian_convert32(*start++); } + while (start < end) { + sum += caryll_endian_convert32(*start++); + } } return sum; } @@ -33,7 +35,9 @@ static sfnt_builder_entry *createSegment(uint32_t tag, caryll_buffer *buffer) { { uint32_t *start = (uint32_t *)buffer->data; uint32_t *end = start + ((table->length + 3) & ~3) / sizeof(uint32_t); - while (start < end) { sum += caryll_endian_convert32(*start++); } + while (start < end) { + sum += caryll_endian_convert32(*start++); + } } table->checksum = sum; return table; @@ -70,7 +74,9 @@ void sfnt_builder_push_table(sfnt_builder *builder, uint32_t tag, caryll_buffer } } -static int byTag(sfnt_builder_entry *a, sfnt_builder_entry *b) { return (a->tag - b->tag); } +static int byTag(sfnt_builder_entry *a, sfnt_builder_entry *b) { + return (a->tag - b->tag); +} caryll_buffer *sfnt_builder_serialize(sfnt_builder *builder) { caryll_buffer *buffer = bufnew(); diff --git a/lib/font/caryll-sfnt.c b/lib/font/caryll-sfnt.c index 89a5ed46..e1d2ce03 100644 --- a/lib/font/caryll-sfnt.c +++ b/lib/font/caryll-sfnt.c @@ -52,7 +52,9 @@ caryll_sfnt *caryll_read_sfnt(FILE *file) { font->offsets = (uint32_t *)malloc(sizeof(uint32_t) * font->count); font->packets = (caryll_packet *)malloc(sizeof(caryll_packet) * font->count); - for (uint32_t i = 0; i < font->count; i++) { font->offsets[i] = caryll_get32u(file); } + for (uint32_t i = 0; i < font->count; i++) { + font->offsets[i] = caryll_get32u(file); + } caryll_read_packets(font, file); break; @@ -72,7 +74,9 @@ caryll_sfnt *caryll_read_sfnt(FILE *file) { void caryll_delete_sfnt(caryll_sfnt *font) { if (font->count > 0) { for (uint32_t count = 0; count < font->count; count++) { - for (int i = 0; i < font->packets[count].numTables; i++) { free(font->packets[count].pieces[i].data); } + for (int i = 0; i < font->packets[count].numTables; i++) { + free(font->packets[count].pieces[i].data); + } free(font->packets[count].pieces); } } diff --git a/lib/fontops/consolidate.c b/lib/fontops/consolidate.c index 6afcdffe..a722a491 100644 --- a/lib/fontops/consolidate.c +++ b/lib/fontops/consolidate.c @@ -58,34 +58,50 @@ void caryll_font_consolidate_glyph(glyf_glyph *g, caryll_font *font) { // Sort stems if (g->stemH) { - for (uint16_t j = 0; j < g->numberOfStemH; j++) { g->stemH[j].map = j; } + for (uint16_t j = 0; j < g->numberOfStemH; j++) { + g->stemH[j].map = j; + } qsort(g->stemH, g->numberOfStemH, sizeof(glyf_postscript_hint_stemdef), by_stem_pos); } if (g->stemV) { - for (uint16_t j = 0; j < g->numberOfStemV; j++) { g->stemV[j].map = j; } + for (uint16_t j = 0; j < g->numberOfStemV; j++) { + g->stemV[j].map = j; + } qsort(g->stemV, g->numberOfStemV, sizeof(glyf_postscript_hint_stemdef), by_stem_pos); } uint16_t *hmap; NEW_N(hmap, g->numberOfStemH); uint16_t *vmap; NEW_N(vmap, g->numberOfStemV); - for (uint16_t j = 0; j < g->numberOfStemH; j++) { hmap[g->stemH[j].map] = j; } - for (uint16_t j = 0; j < g->numberOfStemV; j++) { vmap[g->stemV[j].map] = j; } + for (uint16_t j = 0; j < g->numberOfStemH; j++) { + hmap[g->stemH[j].map] = j; + } + for (uint16_t j = 0; j < g->numberOfStemV; j++) { + vmap[g->stemV[j].map] = j; + } // sort masks if (g->hintMasks) { qsort(g->hintMasks, g->numberOfHintMasks, sizeof(glyf_postscript_hint_mask), by_mask_pointindex); for (uint16_t j = 0; j < g->numberOfHintMasks; j++) { glyf_postscript_hint_mask oldmask = g->hintMasks[j]; // copy - for (uint16_t k = 0; k < g->numberOfStemH; k++) { g->hintMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; } - for (uint16_t k = 0; k < g->numberOfStemV; k++) { g->hintMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; } + for (uint16_t k = 0; k < g->numberOfStemH; k++) { + g->hintMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; + } + for (uint16_t k = 0; k < g->numberOfStemV; k++) { + g->hintMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; + } } } if (g->contourMasks) { qsort(g->contourMasks, g->numberOfContourMasks, sizeof(glyf_postscript_hint_mask), by_mask_pointindex); for (uint16_t j = 0; j < g->numberOfContourMasks; j++) { glyf_postscript_hint_mask oldmask = g->contourMasks[j]; // copy - for (uint16_t k = 0; k < g->numberOfStemH; k++) { g->contourMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; } - for (uint16_t k = 0; k < g->numberOfStemV; k++) { g->contourMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; } + for (uint16_t k = 0; k < g->numberOfStemH; k++) { + g->contourMasks[j].maskH[k] = oldmask.maskH[hmap[k]]; + } + for (uint16_t k = 0; k < g->numberOfStemV; k++) { + g->contourMasks[j].maskV[k] = oldmask.maskV[vmap[k]]; + } } } free(hmap); diff --git a/lib/fontops/otl/GDEF.c b/lib/fontops/otl/GDEF.c index 0a3272fa..4c6f99fa 100644 --- a/lib/fontops/otl/GDEF.c +++ b/lib/fontops/otl/GDEF.c @@ -6,7 +6,9 @@ typedef struct { caret_value_record cr; UT_hash_handle hh; } GDEF_ligcaret_hash; -static int by_gid(GDEF_ligcaret_hash *a, GDEF_ligcaret_hash *b) { return a->gid - b->gid; } +static int by_gid(GDEF_ligcaret_hash *a, GDEF_ligcaret_hash *b) { + return a->gid - b->gid; +} void consolidate_GDEF(caryll_font *font, table_GDEF *gdef, char *tableName) { if (!font || !font->glyph_order || !gdef) return; if (gdef->glyphClassDef) consolidate_classdef(font, gdef->glyphClassDef, tableName); diff --git a/lib/fontops/otl/chaining.c b/lib/fontops/otl/chaining.c index 80188b09..f19babcc 100644 --- a/lib/fontops/otl/chaining.c +++ b/lib/fontops/otl/chaining.c @@ -50,7 +50,9 @@ typedef struct { int cls; UT_hash_handle hh; } classifier_hash; -static int by_gid_clsh(classifier_hash *a, classifier_hash *b) { return a->gid - b->gid; } +static int by_gid_clsh(classifier_hash *a, classifier_hash *b) { + return a->gid - b->gid; +} static int classCompatible(classifier_hash **h, otl_coverage *cov, int *past) { // checks whether a coverage is compatible to a class hash. @@ -266,5 +268,7 @@ void classify(otl_lookup *lookup) { // in this procedure we will replace the subtables' content to classes. // This can massively reduce the size of the lookup. // Remember, this process is completely automatic. - for (uint16_t j = 0; j < lookup->subtableCount; j++) { classify_around(lookup, j); } + for (uint16_t j = 0; j < lookup->subtableCount; j++) { + classify_around(lookup, j); + } } diff --git a/lib/fontops/otl/common.c b/lib/fontops/otl/common.c index 91ea7640..01c0b4d8 100644 --- a/lib/fontops/otl/common.c +++ b/lib/fontops/otl/common.c @@ -1,6 +1,8 @@ #include "common.h" -static int by_gid(const void *a, const void *b) { return ((glyph_handle *)a)->gid - ((glyph_handle *)b)->gid; } +static int by_gid(const void *a, const void *b) { + return ((glyph_handle *)a)->gid - ((glyph_handle *)b)->gid; +} void consolidate_coverage(caryll_font *font, otl_coverage *coverage, sds lookupName) { if (!coverage) return; diff --git a/lib/fontops/otl/gpos-cursive.c b/lib/fontops/otl/gpos-cursive.c index 71324317..284c3584 100644 --- a/lib/fontops/otl/gpos-cursive.c +++ b/lib/fontops/otl/gpos-cursive.c @@ -7,7 +7,9 @@ typedef struct { otl_anchor exit; UT_hash_handle hh; } gpos_cursive_hash; -static int gpos_cursive_by_from_id(gpos_cursive_hash *a, gpos_cursive_hash *b) { return a->fromid - b->fromid; } +static int gpos_cursive_by_from_id(gpos_cursive_hash *a, gpos_cursive_hash *b) { + return a->fromid - b->fromid; +} bool consolidate_gpos_cursive(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_cursive *subtable = &(_subtable->gpos_cursive); consolidate_coverage(font, subtable->coverage, lookupName); diff --git a/lib/fontops/otl/gpos-single.c b/lib/fontops/otl/gpos-single.c index 207be8e9..3b469a14 100644 --- a/lib/fontops/otl/gpos-single.c +++ b/lib/fontops/otl/gpos-single.c @@ -6,7 +6,9 @@ typedef struct { otl_position_value v; UT_hash_handle hh; } gpos_single_hash; -static int gpos_by_from_id(gpos_single_hash *a, gpos_single_hash *b) { return a->fromid - b->fromid; } +static int gpos_by_from_id(gpos_single_hash *a, gpos_single_hash *b) { + return a->fromid - b->fromid; +} bool consolidate_gpos_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gpos_single *subtable = &(_subtable->gpos_single); diff --git a/lib/fontops/otl/gsub-multi.c b/lib/fontops/otl/gsub-multi.c index 27bc38d2..9f6d093a 100644 --- a/lib/fontops/otl/gsub-multi.c +++ b/lib/fontops/otl/gsub-multi.c @@ -6,7 +6,9 @@ typedef struct { otl_coverage *to; UT_hash_handle hh; } gsub_multi_hash; -static int by_from_id_multi(gsub_multi_hash *a, gsub_multi_hash *b) { return a->fromid - b->fromid; } +static int by_from_id_multi(gsub_multi_hash *a, gsub_multi_hash *b) { + return a->fromid - b->fromid; +} bool consolidate_gsub_multi(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_multi *subtable = &(_subtable->gsub_multi); diff --git a/lib/fontops/otl/gsub-reverse.c b/lib/fontops/otl/gsub-reverse.c index 0bffb429..5d4aa90b 100644 --- a/lib/fontops/otl/gsub-reverse.c +++ b/lib/fontops/otl/gsub-reverse.c @@ -7,11 +7,15 @@ typedef struct { sds toname; UT_hash_handle hh; } gsub_single_map_hash; -static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { return a->fromid - b->fromid; } +static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { + return a->fromid - b->fromid; +} bool consolidate_gsub_reverse(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse); - for (uint16_t j = 0; j < subtable->matchCount; j++) { consolidate_coverage(font, subtable->match[j], lookupName); } + for (uint16_t j = 0; j < subtable->matchCount; j++) { + consolidate_coverage(font, subtable->match[j], lookupName); + } consolidate_coverage(font, subtable->to, lookupName); if (subtable->inputIndex >= subtable->matchCount) { subtable->inputIndex = subtable->matchCount - 1; } gsub_single_map_hash *h = NULL; diff --git a/lib/fontops/otl/gsub-single.c b/lib/fontops/otl/gsub-single.c index e4cd68b2..35555a60 100644 --- a/lib/fontops/otl/gsub-single.c +++ b/lib/fontops/otl/gsub-single.c @@ -7,7 +7,9 @@ typedef struct { sds toname; UT_hash_handle hh; } gsub_single_map_hash; -static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { return a->fromid - b->fromid; } +static int by_from_id(gsub_single_map_hash *a, gsub_single_map_hash *b) { + return a->fromid - b->fromid; +} bool consolidate_gsub_single(caryll_font *font, table_otl *table, otl_subtable *_subtable, sds lookupName) { subtable_gsub_single *subtable = &(_subtable->gsub_single); consolidate_coverage(font, subtable->from, lookupName); diff --git a/lib/fontops/otl/mark.c b/lib/fontops/otl/mark.c index 40001dbc..55c9f67e 100644 --- a/lib/fontops/otl/mark.c +++ b/lib/fontops/otl/mark.c @@ -6,21 +6,27 @@ typedef struct { otl_mark_record markrec; UT_hash_handle hh; } mark_hash; -static int mark_by_gid(mark_hash *a, mark_hash *b) { return a->gid - b->gid; } +static int mark_by_gid(mark_hash *a, mark_hash *b) { + return a->gid - b->gid; +} typedef struct { int gid; sds name; otl_anchor *anchors; UT_hash_handle hh; } base_hash; -static int base_by_gid(base_hash *a, base_hash *b) { return a->gid - b->gid; } +static int base_by_gid(base_hash *a, base_hash *b) { + return a->gid - b->gid; +} typedef struct { int gid; sds name; mark_to_ligature_base *ligAttachment; UT_hash_handle hh; } lig_hash; -static int lig_by_gid(lig_hash *a, lig_hash *b) { return a->gid - b->gid; } +static int lig_by_gid(lig_hash *a, lig_hash *b) { + return a->gid - b->gid; +} static void consolidateMarkArray(caryll_font *font, table_otl *table, sds lookupName, otl_coverage *marks, otl_mark_array *markArray, uint16_t classCount) { diff --git a/lib/fontops/stat.c b/lib/fontops/stat.c index 22afea9e..9de05d39 100644 --- a/lib/fontops/stat.c +++ b/lib/fontops/stat.c @@ -423,7 +423,9 @@ void caryll_font_stat_OS_2(caryll_font *font, caryll_options *options) { if (!options->keep_average_char_width) { uint32_t totalWidth = 0; - for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { totalWidth += font->glyf->glyphs[j]->advanceWidth; } + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { + totalWidth += font->glyf->glyphs[j]->advanceWidth; + } font->OS_2->xAvgCharWidth = totalWidth / font->glyf->numberGlyphs; } } @@ -517,7 +519,9 @@ static void caryll_stat_LTSH(caryll_font *font) { NEW(ltsh); ltsh->numGlyphs = font->glyf->numberGlyphs; NEW_N(ltsh->yPels, ltsh->numGlyphs); - for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { ltsh->yPels[j] = font->glyf->glyphs[j]->yPel; } + for (uint16_t j = 0; j < font->glyf->numberGlyphs; j++) { + ltsh->yPels[j] = font->glyf->glyphs[j]->yPel; + } font->LTSH = ltsh; } diff --git a/lib/fontops/unconsolidate.c b/lib/fontops/unconsolidate.c index e748a99d..71103243 100644 --- a/lib/fontops/unconsolidate.c +++ b/lib/fontops/unconsolidate.c @@ -28,7 +28,9 @@ static void caryll_name_glyphs(caryll_font *font, caryll_options *options) { // pass 2: Map to `post` names if (font->post != NULL && font->post->post_name_map != NULL) { glyph_order_entry *s; - foreach_hash(s, *font->post->post_name_map) { try_name_glyph(glyph_order, s->gid, sdsdup(s->name)); } + foreach_hash(s, *font->post->post_name_map) { + try_name_glyph(glyph_order, s->gid, sdsdup(s->name)); + } } // pass 3: Map to AGLFN & Unicode if (font->cmap != NULL) { @@ -73,7 +75,9 @@ static void caryll_name_glyphs(caryll_font *font, caryll_options *options) { static void caryll_name_cmap_entries(caryll_font *font) { if (font->glyph_order != NULL && font->cmap != NULL) { cmap_entry *s; - foreach_hash(s, *font->cmap) { lookup_name(font->glyph_order, s->glyph.gid, &s->glyph.name); } + foreach_hash(s, *font->cmap) { + lookup_name(font->glyph_order, s->glyph.gid, &s->glyph.name); + } } } static void caryll_name_glyf(caryll_font *font) { @@ -128,7 +132,9 @@ static void unconsolidate_gsub_chain(caryll_font *font, otl_lookup *lookup, tabl for (uint16_t j = 0; j < lookup->subtableCount; j++) { subtable_chaining *subtable = &(lookup->subtables[j]->chaining); otl_chaining_rule *rule = subtable->rules[0]; - for (uint16_t k = 0; k < rule->matchCount; k++) { name_coverage(font, rule->match[k]); } + for (uint16_t k = 0; k < rule->matchCount; k++) { + name_coverage(font, rule->match[k]); + } for (uint16_t k = 0; k < rule->applyCount; k++) if (rule->apply[k].lookupIndex < table->lookupCount) { rule->apply[k].lookupName = table->lookups[rule->apply[k].lookupIndex]->name; @@ -140,7 +146,9 @@ static void unconsolidate_gsub_reverse(caryll_font *font, otl_lookup *lookup, ta for (uint16_t j = 0; j < lookup->subtableCount; j++) if (lookup->subtables[j]) { subtable_gsub_reverse *subtable = &(lookup->subtables[j]->gsub_reverse); - for (uint16_t j = 0; j < subtable->matchCount; j++) { name_coverage(font, subtable->match[j]); } + for (uint16_t j = 0; j < subtable->matchCount; j++) { + name_coverage(font, subtable->match[j]); + } name_coverage(font, subtable->to); } } diff --git a/lib/libcff/cff-charset.c b/lib/libcff/cff-charset.c index bfb304d3..c31d5c46 100644 --- a/lib/libcff/cff-charset.c +++ b/lib/libcff/cff-charset.c @@ -17,7 +17,8 @@ void parse_charset(uint8_t *data, int32_t offset, uint16_t nchars, CFF_Charset * charsets->s = nchars - 1; charsets->f0.glyph = calloc(nchars - 1, sizeof(uint16_t)); - for (i = 0; i < charsets->s; i++) charsets->f0.glyph[i] = gu2(data, offset + 1 + i * 2); + for (i = 0; i < charsets->s; i++) + charsets->f0.glyph[i] = gu2(data, offset + 1 + i * 2); } break; case 1: diff --git a/lib/libcff/cff-codecs.c b/lib/libcff/cff-codecs.c index 66854db6..d545d97a 100644 --- a/lib/libcff/cff-codecs.c +++ b/lib/libcff/cff-codecs.c @@ -100,7 +100,9 @@ caryll_buffer *encode_cff_real(double val) { array[j++] = 0x0e, i++; } - for (i = 1; i < blob->size; i++) { blob->data[i] = array[(i - 1) * 2] * 16 + array[(i - 1) * 2 + 1]; } + for (i = 1; i < blob->size; i++) { + blob->data[i] = array[(i - 1) * 2] * 16 + array[(i - 1) * 2 + 1]; + } free(array); } @@ -310,4 +312,6 @@ static uint32_t (*_de_t2[256])(uint8_t *, CFF_Value *) = { cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_i, cff_dec_e}; -uint32_t decode_cff_token(uint8_t *start, CFF_Value *val) { return _de_t2[*start](start, val); } +uint32_t decode_cff_token(uint8_t *start, CFF_Value *val) { + return _de_t2[*start](start, val); +} diff --git a/lib/libcff/cff-dict.c b/lib/libcff/cff-dict.c index 6f5c9e06..c1d4cfb2 100644 --- a/lib/libcff/cff-dict.c +++ b/lib/libcff/cff-dict.c @@ -3,7 +3,9 @@ // DICT util functions void cff_delete_dict(CFF_Dict *dict) { if (!dict) return; - for (uint32_t j = 0; j < dict->count; j++) { free(dict->ents[j].vals); } + for (uint32_t j = 0; j < dict->count; j++) { + free(dict->ents[j].vals); + } free(dict->ents); free(dict); } diff --git a/lib/libcff/cff-fdselect.c b/lib/libcff/cff-fdselect.c index f1e9e143..a0c7e054 100644 --- a/lib/libcff/cff-fdselect.c +++ b/lib/libcff/cff-fdselect.c @@ -22,7 +22,9 @@ caryll_buffer *compile_fdselect(CFF_FDSelect fd) { caryll_buffer *blob = bufnew(); blob->size = 1 + fd.s; blob->data = calloc(blob->size, sizeof(uint8_t)); - for (uint16_t j = 0; j < fd.s; j++) { blob->data[j] = fd.f0.fds[j]; } + for (uint16_t j = 0; j < fd.s; j++) { + blob->data[j] = fd.f0.fds[j]; + } return blob; } case CFF_FDSELECT_FORMAT3: { @@ -55,7 +57,8 @@ void parse_fdselect(uint8_t *data, int32_t offset, uint16_t nchars, CFF_FDSelect fdselect->s = nchars - 1; fdselect->f0.fds = calloc(nchars - 1, sizeof(uint8_t)); - for (uint32_t i = 0; i < nchars - 1; i++) fdselect->f0.fds[i] = gu1(data, offset + 1 + i); + for (uint32_t i = 0; i < nchars - 1; i++) + fdselect->f0.fds[i] = gu1(data, offset + 1 + i); } break; case 3: diff --git a/lib/libcff/cff-parser.c b/lib/libcff/cff-parser.c index b5ef5029..1caacb1e 100644 --- a/lib/libcff/cff-parser.c +++ b/lib/libcff/cff-parser.c @@ -29,7 +29,8 @@ static void parse_encoding(CFF_File *cff, int32_t offset, CFF_Encoding *enc) { enc->f0.ncodes = data[offset + 1]; enc->f0.code = calloc(enc->f0.ncodes, sizeof(uint8_t)); - for (uint32_t i = 0; i < enc->f0.ncodes; i++) enc->f0.code[i] = data[offset + 2 + i]; + for (uint32_t i = 0; i < enc->f0.ncodes; i++) + enc->f0.code[i] = data[offset + 2 + i]; } break; case 1: @@ -288,8 +289,12 @@ static void callback_nopNewContour(void *context) {} static void callback_nopLineTo(void *context, float x1, float y1) {} static void callback_nopCurveTo(void *context, float x1, float y1, float x2, float y2, float x3, float y3) {} static void callback_nopsetHint(void *context, bool isVertical, float position, float width) {} -static void callback_nopsetMask(void *context, bool isContourMask, bool *mask) { FREE(mask); } -static double callback_nopgetrand(void *context) { return 0; } +static void callback_nopsetMask(void *context, bool isContourMask, bool *mask) { + FREE(mask); +} +static double callback_nopgetrand(void *context) { + return 0; +} #define CHECK_STACK_TOP(op, n) \ { \ if (stack->index < n) { \ @@ -405,7 +410,8 @@ void parse_outline_callback(uint8_t *data, uint32_t len, CFF_Index gsubr, CFF_In break; } case op_rlineto: { - for (i = 0; i < stack->index; i += 2) lineTo(outline, stack->stack[i].d, stack->stack[i + 1].d); + for (i = 0; i < stack->index; i += 2) + lineTo(outline, stack->stack[i].d, stack->stack[i + 1].d); stack->index = 0; break; } diff --git a/lib/libcff/cff-writer.c b/lib/libcff/cff-writer.c index c3630cf2..7ff0e347 100644 --- a/lib/libcff/cff-writer.c +++ b/lib/libcff/cff-writer.c @@ -12,7 +12,9 @@ #include "libcff.h" -caryll_buffer *compile_header(void) { return bufninit(4, 1, 0, 4, 4); } +caryll_buffer *compile_header(void) { + return bufninit(4, 1, 0, 4, 4); +} void merge_cs2_operator(caryll_buffer *blob, int32_t val) { if (val >= 0x100) { @@ -50,7 +52,9 @@ void merge_cs2_operand(caryll_buffer *blob, double val) { merge_cs2_real(blob, val); } } -void merge_cs2_special(caryll_buffer *blob, uint8_t val) { bufwrite8(blob, val); } +void merge_cs2_special(caryll_buffer *blob, uint8_t val) { + bufwrite8(blob, val); +} caryll_buffer *compile_offset(int32_t val) { return bufninit(5, 29, (val >> 24) & 0xff, (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff); diff --git a/lib/libcff/charstring_il.c b/lib/libcff/charstring_il.c index 02b894ea..21f9ffbd 100644 --- a/lib/libcff/charstring_il.c +++ b/lib/libcff/charstring_il.c @@ -382,7 +382,9 @@ static uint8_t decideAdvance(charstring_il *il, uint32_t j, uint8_t optimizeLeve void glyph_il_peephole_optimization(charstring_il *il, caryll_options *options) { if (!options->optimize_level) return; uint32_t j = 0; - while (j < il->length) { j += decideAdvance(il, j, options->optimize_level); } + while (j < il->length) { + j += decideAdvance(il, j, options->optimize_level); + } } // IL to buffer conversion diff --git a/lib/support/base64.c b/lib/support/base64.c index fcda1eb0..efbf8afd 100644 --- a/lib/support/base64.c +++ b/lib/support/base64.c @@ -44,7 +44,8 @@ uint8_t *base64_decode(const uint8_t *src, size_t len, size_t *out_len) { size_t i, count; memset(dtable, 0x80, 256); - for (i = 0; i < sizeof(base64_table); i++) dtable[base64_table[i]] = i; + for (i = 0; i < sizeof(base64_table); i++) + dtable[base64_table[i]] = i; dtable['='] = 0; count = 0; diff --git a/lib/support/buffer.c b/lib/support/buffer.c index ca86c33f..0f4cbae2 100644 --- a/lib/support/buffer.c +++ b/lib/support/buffer.c @@ -13,9 +13,15 @@ void buffree(caryll_buffer *buf) { if (buf->data) free(buf->data); free(buf); } -size_t buflen(caryll_buffer *buf) { return buf->size; } -size_t bufpos(caryll_buffer *buf) { return buf->cursor; } -void bufseek(caryll_buffer *buf, size_t pos) { buf->cursor = pos; } +size_t buflen(caryll_buffer *buf) { + return buf->size; +} +size_t bufpos(caryll_buffer *buf) { + return buf->cursor; +} +void bufseek(caryll_buffer *buf, size_t pos) { + buf->cursor = pos; +} void bufclear(caryll_buffer *buf) { buf->cursor = 0; buf->free = buf->size + buf->free; @@ -101,7 +107,9 @@ caryll_buffer *bufninit(uint32_t n, ...) { bufbeforewrite(buf, n); va_list ap; va_start(ap, n); - for (uint16_t j = 0; j < n; j++) { bufwrite8(buf, (uint8_t)va_arg(ap, int)); } + for (uint16_t j = 0; j < n; j++) { + bufwrite8(buf, (uint8_t)va_arg(ap, int)); + } va_end(ap); return buf; } @@ -109,7 +117,9 @@ void bufnwrite8(caryll_buffer *buf, uint32_t n, ...) { bufbeforewrite(buf, n); va_list ap; va_start(ap, n); - for (uint16_t j = 0; j < n; j++) { bufwrite8(buf, (uint8_t)va_arg(ap, int)); } + for (uint16_t j = 0; j < n; j++) { + bufwrite8(buf, (uint8_t)va_arg(ap, int)); + } va_end(ap); } diff --git a/lib/support/glyphorder.c b/lib/support/glyphorder.c index a6a9c242..fac37656 100644 --- a/lib/support/glyphorder.c +++ b/lib/support/glyphorder.c @@ -131,7 +131,9 @@ glyph_order_hash *caryll_glyphorder_from_json(json_value *root, caryll_options * HASH_SORT(hash, compare_glyphorder_entry_b); glyph_order_entry *item; uint32_t j = 0; - foreach_hash(item, hash) { item->gid = j++; } + foreach_hash(item, hash) { + item->gid = j++; + } glyph_order_hash *go = malloc(sizeof(glyph_order_hash)); *go = hash; return go; diff --git a/lib/support/ttinstr.c b/lib/support/ttinstr.c index 0d476256..1f92ab63 100644 --- a/lib/support/ttinstr.c +++ b/lib/support/ttinstr.c @@ -311,7 +311,8 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, void (*IVError for (pt = text; *pt; ++pt) { npos = 0; while (npos < 256) { - while (*pt == ' ' || *pt == '\t') ++pt; + while (*pt == ' ' || *pt == '\t') + ++pt; if (isdigit(*pt) || *pt == '-') { val = strtol(pt, &end, 0); if (val > 32767 || val < -32768) { @@ -323,7 +324,8 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, void (*IVError } else break; } - while (*pt == ' ' || *pt == '\t') ++pt; + while (*pt == ' ' || *pt == '\t') + ++pt; if (npos == 0 && (*pt == '\r' || *pt == '\n' || *pt == '\0')) continue; nread = 0; if (push_left == -1) { @@ -366,16 +368,19 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, void (*IVError while (nread < npos) { i = nread; if (numberstack[nread] >= 0 && numberstack[nread] <= 255) { - while (i < npos && numberstack[i] >= 0 && numberstack[i] <= 255) ++i; + while (i < npos && numberstack[i] >= 0 && numberstack[i] <= 255) + ++i; if (i - nread <= 8) instrs[icnt++] = ttf_pushb + (i - nread) - 1; else { instrs[icnt++] = ttf_npushb; instrs[icnt++] = i - nread; } - while (nread < i) instrs[icnt++] = numberstack[nread++]; + while (nread < i) + instrs[icnt++] = numberstack[nread++]; } else { - while (i < npos && (numberstack[i] < 0 || numberstack[i] > 255)) ++i; + while (i < npos && (numberstack[i] < 0 || numberstack[i] > 255)) + ++i; if (i - nread <= 8) instrs[icnt++] = ttf_pushw + (i - nread) - 1; else { @@ -399,7 +404,8 @@ static uint8_t *parse_instrs(char *text, int *len, void *context, void (*IVError for (i = 0; i < 256; ++i) if (strnmatch(pt, ff_ttf_instrnames[i], (int)(brack - pt + 1)) == 0) break; val = strtol(brack + 1, &bend, 2); /* Stuff in brackets should be in binary */ - while (*bend == ' ' || *bend == '\t') ++bend; + while (*bend == ' ' || *bend == '\t') + ++bend; if (*bend != ']') { IVError(context, "Missing right bracket in command (or bad binary value in bracket)", (int)(pt - text)); return (NULL); @@ -441,7 +447,8 @@ static int instr_typify(struct instrdata *id) { /* NPUSHB */ bts[++i] = bt_cnt; cnt = instrs[i]; - for (j = 0; j < cnt; ++j) bts[++i] = bt_byte; + for (j = 0; j < cnt; ++j) + bts[++i] = bt_byte; lh += 1 + cnt; } else if (instrs[i] == ttf_npushw) { /* NPUSHW */ @@ -456,7 +463,8 @@ static int instr_typify(struct instrdata *id) { } else if ((instrs[i] & 0xf8) == 0xb0) { /* PUSHB[n] */ cnt = (instrs[i] & 7) + 1; - for (j = 0; j < cnt; ++j) bts[++i] = bt_byte; + for (j = 0; j < cnt; ++j) + bts[++i] = bt_byte; lh += cnt; } else if ((instrs[i] & 0xf8) == 0xb8) { /* PUSHW[n] */ diff --git a/lib/support/unicodeconv.c b/lib/support/unicodeconv.c index 77f83a4d..00f42cfa 100644 --- a/lib/support/unicodeconv.c +++ b/lib/support/unicodeconv.c @@ -67,7 +67,9 @@ sds utf16le_to_utf8(const uint8_t *inb, int inlenb) { bits = 12; } - for (; bits >= 0; bits -= 6) { *out++ = ((c >> bits) & 0x3F) | 0x80; } + for (; bits >= 0; bits -= 6) { + *out++ = ((c >> bits) & 0x3F) | 0x80; + } } return out0; } @@ -160,7 +162,9 @@ sds utf16be_to_utf8(const uint8_t *inb, int inlenb) { bits = 12; } - for (; bits >= 0; bits -= 6) { *out++ = ((c >> bits) & 0x3F) | 0x80; } + for (; bits >= 0; bits -= 6) { + *out++ = ((c >> bits) & 0x3F) | 0x80; + } } return out0; } diff --git a/lib/support/util.h b/lib/support/util.h index 948f909d..4f383be3 100644 --- a/lib/support/util.h +++ b/lib/support/util.h @@ -130,7 +130,9 @@ static INLINE bool json_obj_getbool_fallback(json_value *obj, const char *key, b return fallback; } -static INLINE json_value *json_from_sds(sds str) { return json_string_new_length((uint32_t)sdslen(str), str); } +static INLINE json_value *json_from_sds(sds str) { + return json_string_new_length((uint32_t)sdslen(str), str); +} // flags reader and writer static INLINE json_value *caryll_flags_to_json(int flags, const char *labels[]) { @@ -249,7 +251,9 @@ static INLINE uint64_t caryll_get64u(FILE *file) { } // data reader -static INLINE uint8_t read_8u(uint8_t *src) { return src[0]; } +static INLINE uint8_t read_8u(uint8_t *src) { + return src[0]; +} static INLINE uint16_t read_16u(uint8_t *src) { uint16_t b0 = ((uint16_t)src[0]) << 8; uint16_t b1 = ((uint16_t)src[1]); @@ -273,20 +277,36 @@ static INLINE uint64_t read_64u(uint8_t *src) { uint64_t b7 = ((uint64_t)src[7]); return (b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7); } -static INLINE int8_t read_8s(uint8_t *src) { return (int8_t)read_8u(src); } -static INLINE int16_t read_16s(uint8_t *src) { return (int16_t)read_16u(src); } -static INLINE int32_t read_32s(uint8_t *src) { return (int32_t)read_32u(src); } -static INLINE int64_t read_64s(uint8_t *src) { return (int64_t)read_64u(src); } +static INLINE int8_t read_8s(uint8_t *src) { + return (int8_t)read_8u(src); +} +static INLINE int16_t read_16s(uint8_t *src) { + return (int16_t)read_16u(src); +} +static INLINE int32_t read_32s(uint8_t *src) { + return (int32_t)read_32u(src); +} +static INLINE int64_t read_64s(uint8_t *src) { + return (int64_t)read_64u(src); +} // f2dot14 type typedef int16_t f2dot14; -static INLINE float caryll_from_f2dot14(int16_t x) { return x / 16384.0; } -static INLINE int16_t caryll_to_f2dot14(float x) { return x * 16384.0; } +static INLINE float caryll_from_f2dot14(int16_t x) { + return x / 16384.0; +} +static INLINE int16_t caryll_to_f2dot14(float x) { + return x * 16384.0; +} // F16.16 (fixed) type typedef int32_t f16dot16; -static INLINE float caryll_from_fixed(f16dot16 x) { return x / 65536.0; } -static INLINE f16dot16 caryll_to_fixed(float x) { return x * 65536.0; } +static INLINE float caryll_from_fixed(f16dot16 x) { + return x / 65536.0; +} +static INLINE f16dot16 caryll_to_fixed(float x) { + return x * 65536.0; +} // glyph reference type typedef struct { diff --git a/lib/tables/CFF.c b/lib/tables/CFF.c index 5f2e6d2b..66cbe042 100644 --- a/lib/tables/CFF.c +++ b/lib/tables/CFF.c @@ -49,7 +49,9 @@ void caryll_delete_CFF(table_CFF *table) { caryll_delete_privatedict(table->privateDict); if (table->fdArray) { - for (uint16_t j = 0; j < table->fdArrayCount; j++) { caryll_delete_CFF(table->fdArray[j]); } + for (uint16_t j = 0; j < table->fdArrayCount; j++) { + caryll_delete_CFF(table->fdArray[j]); + } free(table->fdArray); } } @@ -73,37 +75,49 @@ static void callback_extract_private(uint32_t op, uint8_t top, CFF_Value *stack, case op_BlueValues: { pd->blueValuesCount = top; NEW_N(pd->blueValues, pd->blueValuesCount); - for (uint16_t j = 0; j < pd->blueValuesCount; j++) { pd->blueValues[j] = cffnum(stack[j]); } + for (uint16_t j = 0; j < pd->blueValuesCount; j++) { + pd->blueValues[j] = cffnum(stack[j]); + } break; } case op_OtherBlues: { pd->otherBluesCount = top; NEW_N(pd->otherBlues, pd->otherBluesCount); - for (uint16_t j = 0; j < pd->otherBluesCount; j++) { pd->otherBlues[j] = cffnum(stack[j]); } + for (uint16_t j = 0; j < pd->otherBluesCount; j++) { + pd->otherBlues[j] = cffnum(stack[j]); + } break; } case op_FamilyBlues: { pd->familyBluesCount = top; NEW_N(pd->familyBlues, pd->familyBluesCount); - for (uint16_t j = 0; j < pd->familyBluesCount; j++) { pd->familyBlues[j] = cffnum(stack[j]); } + for (uint16_t j = 0; j < pd->familyBluesCount; j++) { + pd->familyBlues[j] = cffnum(stack[j]); + } break; } case op_FamilyOtherBlues: { pd->familyOtherBluesCount = top; NEW_N(pd->familyOtherBlues, pd->familyOtherBluesCount); - for (uint16_t j = 0; j < pd->familyOtherBluesCount; j++) { pd->familyOtherBlues[j] = cffnum(stack[j]); } + for (uint16_t j = 0; j < pd->familyOtherBluesCount; j++) { + pd->familyOtherBlues[j] = cffnum(stack[j]); + } break; } case op_StemSnapH: { pd->stemSnapHCount = top; NEW_N(pd->stemSnapH, pd->stemSnapHCount); - for (uint16_t j = 0; j < pd->stemSnapHCount; j++) { pd->stemSnapH[j] = cffnum(stack[j]); } + for (uint16_t j = 0; j < pd->stemSnapHCount; j++) { + pd->stemSnapH[j] = cffnum(stack[j]); + } break; } case op_StemSnapV: { pd->stemSnapVCount = top; NEW_N(pd->stemSnapV, pd->stemSnapVCount); - for (uint16_t j = 0; j < pd->stemSnapVCount; j++) { pd->stemSnapV[j] = cffnum(stack[j]); } + for (uint16_t j = 0; j < pd->stemSnapVCount; j++) { + pd->stemSnapV[j] = cffnum(stack[j]); + } break; } // Numbers @@ -242,7 +256,9 @@ typedef struct { uint64_t randx; } outline_builder_context; -static void callback_count_contour(void *context) { ((outline_builder_context *)context)->g->numberOfContours += 1; } +static void callback_count_contour(void *context) { + ((outline_builder_context *)context)->g->numberOfContours += 1; +} static void callback_countpoint_next_contour(void *_context) { outline_builder_context *context = (outline_builder_context *)_context; context->jContour += 1; @@ -435,7 +451,9 @@ static void buildOutline(uint16_t i, cff_parse_context *context) { stack.stem = 0; bc.randx = seed; parse_outline_callback(charStringPtr, charStringLength, f->global_subr, localSubrs, &stack, &bc, pass2); - for (uint16_t j = 0; j < g->numberOfContours; j++) { NEW_N(g->contours[j].points, g->contours[j].pointsCount); } + for (uint16_t j = 0; j < g->numberOfContours; j++) { + NEW_N(g->contours[j].points, g->contours[j].pointsCount); + } NEW_N(g->stemH, g->numberOfStemH); NEW_N(g->stemV, g->numberOfStemV); NEW_N(g->hintMasks, g->numberOfHintMasks); @@ -569,7 +587,9 @@ caryll_cff_parse_result caryll_read_CFF_and_glyf(caryll_packet packet) { context.glyphs = glyphs; glyphs->numberGlyphs = cffFile->char_strings.count; NEW_N(glyphs->glyphs, glyphs->numberGlyphs); - for (uint16_t j = 0; j < glyphs->numberGlyphs; j++) { buildOutline(j, &context); } + for (uint16_t j = 0; j < glyphs->numberGlyphs; j++) { + buildOutline(j, &context); + } // Name glyphs according charset nameGlyphsAccordingToCFF(&context); @@ -583,7 +603,9 @@ caryll_cff_parse_result caryll_read_CFF_and_glyf(caryll_packet packet) { static void pdDeltaToJson(json_value *target, const char *field, uint16_t count, float *values) { if (!count || !values) return; json_value *a = json_array_new(count); - for (uint16_t j = 0; j < count; j++) { json_array_push(a, json_double_new(values[j])); } + for (uint16_t j = 0; j < count; j++) { + json_array_push(a, json_double_new(values[j])); + } json_object_push(target, field, a); } @@ -653,7 +675,9 @@ static json_value *fdToJson(table_CFF *table) { } if (table->fdArray) { json_value *_fdArray = json_array_new(table->fdArrayCount); - for (uint16_t j = 0; j < table->fdArrayCount; j++) { json_array_push(_fdArray, fdToJson(table->fdArray[j])); } + for (uint16_t j = 0; j < table->fdArrayCount; j++) { + json_array_push(_fdArray, fdToJson(table->fdArray[j])); + } json_object_push(_CFF_, "fdArray", _fdArray); } return _CFF_; @@ -670,7 +694,9 @@ static void pdDeltaFromJson(json_value *dump, uint16_t *count, float **array) { if (!dump || dump->type != json_array) return; *count = dump->u.array.length; NEW_N(*array, *count); - for (uint16_t j = 0; j < *count; j++) { (*array)[j] = json_numof(dump->u.array.values[j]); } + for (uint16_t j = 0; j < *count; j++) { + (*array)[j] = json_numof(dump->u.array.values[j]); + } } static cff_private *pdFromJson(json_value *dump) { if (!dump || dump->type != json_object) return NULL; @@ -942,7 +968,9 @@ static CFF_Dict *cff_make_private_dict(cff_private *pd) { return dict; } -static int by_sid(cff_sid_entry *a, cff_sid_entry *b) { return a->sid - b->sid; } +static int by_sid(cff_sid_entry *a, cff_sid_entry *b) { + return a->sid - b->sid; +} static caryll_buffer *callback_makestringindex(void *context, uint32_t i) { caryll_buffer **blobs = context; return blobs[i]; @@ -1003,7 +1031,9 @@ static caryll_buffer *cff_make_charset(table_CFF *cff, table_glyf *glyf, cff_sid charset->f2.range2[0].first = 1; charset->f2.range2[0].nleft = glyf->numberGlyphs - 2; } else { - for (uint16_t j = 1; j < glyf->numberGlyphs; j++) { sidof(stringHash, glyf->glyphs[j]->name); } + for (uint16_t j = 1; j < glyf->numberGlyphs; j++) { + sidof(stringHash, glyf->glyphs[j]->name); + } charset->f2.range2[0].first = sidof(stringHash, glyf->glyphs[1]->name); charset->f2.range2[0].nleft = glyf->numberGlyphs - 2; } @@ -1213,7 +1243,9 @@ static caryll_buffer *writeCFF_CIDKeyed(table_CFF *cff, table_glyf *glyf, caryll r = compile_index(*fdArrayIndex); cff_index_fini(fdArrayIndex); bufwrite_bufdel(blob, r); - for (uint16_t j = 0; j < cff->fdArrayCount; j++) { bufwrite_bufdel(blob, fdArrayPrivates[j]); } + for (uint16_t j = 0; j < cff->fdArrayCount; j++) { + bufwrite_bufdel(blob, fdArrayPrivates[j]); + } free(fdArrayPrivates); } else { bufwrite_bufdel(blob, r); diff --git a/lib/tables/LTSH.c b/lib/tables/LTSH.c index f390ee2f..cfd3257c 100644 --- a/lib/tables/LTSH.c +++ b/lib/tables/LTSH.c @@ -23,6 +23,8 @@ caryll_buffer *caryll_write_LTSH(table_LTSH *ltsh, caryll_options *options) { if (!ltsh) return buf; bufwrite16b(buf, 0); bufwrite16b(buf, ltsh->numGlyphs); - for (uint16_t j = 0; j < ltsh->numGlyphs; j++) { bufwrite8(buf, ltsh->yPels[j]); } + for (uint16_t j = 0; j < ltsh->numGlyphs; j++) { + bufwrite8(buf, ltsh->yPels[j]); + } return buf; } diff --git a/lib/tables/OS_2.c b/lib/tables/OS_2.c index 65a37428..67025d21 100644 --- a/lib/tables/OS_2.c +++ b/lib/tables/OS_2.c @@ -109,7 +109,9 @@ void caryll_OS_2_to_json(table_OS_2 *table, json_value *root, caryll_options *op json_object_push(os_2, "sFamilyClass", json_integer_new(table->sFamilyClass)); json_value *panose = json_array_new(10); - for (uint8_t j = 0; j < 10; j++) { json_array_push(panose, json_integer_new(table->panose[j])); } + for (uint8_t j = 0; j < 10; j++) { + json_array_push(panose, json_integer_new(table->panose[j])); + } json_object_push(os_2, "panose", panose); json_object_push(os_2, "ulUnicodeRange1", json_integer_new(table->ulUnicodeRange1)); diff --git a/lib/tables/cmap.c b/lib/tables/cmap.c index 47864bc5..f8bdce30 100644 --- a/lib/tables/cmap.c +++ b/lib/tables/cmap.c @@ -20,7 +20,9 @@ static void caryll_read_format_12(font_file_pointer start, uint32_t lengthLimit, uint32_t startCode = read_32u(start + 16 + 12 * j); uint32_t endCode = read_32u(start + 16 + 12 * j + 4); uint32_t startGID = read_32u(start + 16 + 12 * j + 8); - for (uint32_t c = startCode; c <= endCode; c++) { encode(map, c, (c - startCode) + startGID); } + for (uint32_t c = startCode; c <= endCode; c++) { + encode(map, c, (c - startCode) + startGID); + } } } @@ -59,7 +61,9 @@ static void caryll_read_mapping_table(font_file_pointer start, uint32_t lengthLi } } -static int by_unicode(cmap_entry *a, cmap_entry *b) { return (a->unicode - b->unicode); } +static int by_unicode(cmap_entry *a, cmap_entry *b) { + return (a->unicode - b->unicode); +} // OTFCC will not support all `cmap` mappings. cmap_hash *caryll_read_cmap(caryll_packet packet) { @@ -194,7 +198,9 @@ caryll_buffer *caryll_write_cmap_format4(cmap_hash *cmap) { if (isSequencial && !(item->glyph.gid == lastGIDEnd + 1)) { lastGlyphIdArrayOffset = glyphIdArray->cursor; // oops, sequencial glyphid broken - for (int j = lastGIDStart; j <= lastGIDEnd; j++) { bufwrite16b(glyphIdArray, j); } + for (int j = lastGIDStart; j <= lastGIDEnd; j++) { + bufwrite16b(glyphIdArray, j); + } } lastUnicodeEnd = item->unicode; isSequencial = isSequencial && (item->glyph.gid == lastGIDEnd + 1); @@ -238,7 +244,9 @@ caryll_buffer *caryll_write_cmap_format4(cmap_hash *cmap) { bufwrite16b(buf, segmentsCount << 1); uint32_t i; uint32_t j; - for (j = 0, i = 1; i <= segmentsCount; ++j) { i <<= 1; } + for (j = 0, i = 1; i <= segmentsCount; ++j) { + i <<= 1; + } bufwrite16b(buf, i); bufwrite16b(buf, j - 1); bufwrite16b(buf, 2 * segmentsCount - i); diff --git a/lib/tables/cvt.c b/lib/tables/cvt.c index 25aa2406..27fb83a1 100644 --- a/lib/tables/cvt.c +++ b/lib/tables/cvt.c @@ -8,7 +8,9 @@ table_cvt *caryll_read_cvt(caryll_packet packet, uint32_t tag) { NEW(t); t->length = length >> 1; NEW_N(t->words, (t->length + 1)); - for (uint16_t j = 0; j < t->length; j++) { t->words[j] = read_16u(data + 2 * j); } + for (uint16_t j = 0; j < t->length; j++) { + t->words[j] = read_16u(data + 2 * j); + } return t; } return NULL; @@ -23,7 +25,9 @@ void caryll_cvt_to_json(table_cvt *table, json_value *root, caryll_options *opti if (options->verbose) fprintf(stderr, "Dumping cvt.\n"); json_value *arr = json_array_new(table->length); - for (uint16_t j = 0; j < table->length; j++) { json_array_push(arr, json_integer_new(table->words[j])); } + for (uint16_t j = 0; j < table->length; j++) { + json_array_push(arr, json_integer_new(table->words[j])); + } json_object_push(root, tag, arr); } table_cvt *caryll_cvt_from_json(json_value *root, caryll_options *options, const char *tag) { @@ -53,7 +57,9 @@ table_cvt *caryll_cvt_from_json(json_value *root, caryll_options *options, const uint8_t *raw = base64_decode((uint8_t *)table->u.string.ptr, table->u.string.length, &len); t->length = (uint32_t)(len >> 1); NEW_N(t->words, (t->length + 1)); - for (uint16_t j = 0; j < t->length; j++) { t->words[j] = read_16u(raw + 2 * j); } + for (uint16_t j = 0; j < t->length; j++) { + t->words[j] = read_16u(raw + 2 * j); + } FREE(raw); } return t; @@ -62,6 +68,8 @@ table_cvt *caryll_cvt_from_json(json_value *root, caryll_options *options, const caryll_buffer *caryll_write_cvt(table_cvt *table, caryll_options *options) { caryll_buffer *buf = bufnew(); if (!table) return buf; - for (uint16_t j = 0; j < table->length; j++) { bufwrite16b(buf, table->words[j]); } + for (uint16_t j = 0; j < table->length; j++) { + bufwrite16b(buf, table->words[j]); + } return buf; } diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index cc062361..caa6efc3 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -340,7 +340,9 @@ static void caryll_delete_glyf_glyph(glyf_glyph *g) { free(g->contours); } if (g->numberOfReferences > 0 && g->references != NULL) { - for (uint16_t k = 0; k < g->numberOfReferences; k++) { g->references[k].glyph.name = NULL; } + for (uint16_t k = 0; k < g->numberOfReferences; k++) { + g->references[k].glyph.name = NULL; + } free(g->references); } if (g->instructions) { free(g->instructions); } @@ -353,7 +355,9 @@ static void caryll_delete_glyf_glyph(glyf_glyph *g) { } void caryll_delete_glyf(table_glyf *table) { if (table->glyphs) { - for (uint16_t j = 0; j < table->numberGlyphs; j++) { caryll_delete_glyf_glyph(table->glyphs[j]); } + for (uint16_t j = 0; j < table->numberGlyphs; j++) { + caryll_delete_glyf_glyph(table->glyphs[j]); + } free(table->glyphs); } free(table); @@ -420,10 +424,14 @@ static json_value *glyf_glyph_maskdefs_to_json(glyf_postscript_hint_mask *masks, json_value *mask = json_object_new(3); json_object_push(mask, "pointsBefore", json_integer_new(masks[j].pointsBefore)); json_value *h = json_array_new(nh); - for (uint16_t k = 0; k < nh; k++) { json_array_push(h, json_boolean_new(masks[j].maskH[k])); } + for (uint16_t k = 0; k < nh; k++) { + json_array_push(h, json_boolean_new(masks[j].maskH[k])); + } json_object_push(mask, "maskH", h); json_value *v = json_array_new(nv); - for (uint16_t k = 0; k < nv; k++) { json_array_push(v, json_boolean_new(masks[j].maskV[k])); } + for (uint16_t k = 0; k < nv; k++) { + json_array_push(v, json_boolean_new(masks[j].maskV[k])); + } json_object_push(mask, "maskV", v); json_array_push(a, mask); } @@ -583,7 +591,9 @@ static void stems_from_json(json_value *sd, uint16_t *count, glyf_postscript_hin } static void parse_maskbits(bool *arr, json_value *bits) { if (!bits) { - for (uint16_t j = 0; j < 0x100; j++) { arr[j] = false; } + for (uint16_t j = 0; j < 0x100; j++) { + arr[j] = false; + } } else { for (uint16_t j = 0; j < 0x100 && j < bits->u.array.length; j++) { json_value *b = bits->u.array.values[j]; diff --git a/lib/tables/hmtx.c b/lib/tables/hmtx.c index 2497f266..f879f55a 100644 --- a/lib/tables/hmtx.c +++ b/lib/tables/hmtx.c @@ -21,7 +21,9 @@ table_hmtx *caryll_read_hmtx(caryll_packet packet, table_hhea *hhea, table_maxp hmtx->metrics[ia].lsb = read_16u(data + ia * 4 + 2); } - for (uint32_t ik = 0; ik < count_k; ik++) { hmtx->leftSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); } + for (uint32_t ik = 0; ik < count_k; ik++) { + hmtx->leftSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); + } return hmtx; HMTX_CORRUPTED: @@ -48,7 +50,9 @@ caryll_buffer *caryll_write_hmtx(table_hmtx *hmtx, uint16_t count_a, uint16_t co } } if (hmtx->leftSideBearing) { - for (uint16_t j = 0; j < count_k; j++) { bufwrite16b(buf, hmtx->leftSideBearing[j]); } + for (uint16_t j = 0; j < count_k; j++) { + bufwrite16b(buf, hmtx->leftSideBearing[j]); + } } return buf; } diff --git a/lib/tables/otl/chaining.c b/lib/tables/otl/chaining.c index 40e6fb96..b382a8b5 100644 --- a/lib/tables/otl/chaining.c +++ b/lib/tables/otl/chaining.c @@ -1,7 +1,9 @@ #include "chaining.h" static void deleteRule(otl_chaining_rule *rule) { if (rule && rule->match && rule->matchCount) { - for (uint16_t k = 0; k < rule->matchCount; k++) { caryll_delete_coverage(rule->match[k]); } + for (uint16_t k = 0; k < rule->matchCount; k++) { + caryll_delete_coverage(rule->match[k]); + } } if (rule && rule->apply) free(rule->apply); if (rule) free(rule); @@ -10,7 +12,9 @@ void delete_otl_chaining_subtable(otl_subtable *_subtable) { if (_subtable) { subtable_chaining *subtable = &(_subtable->chaining); if (subtable->rules) { - for (uint16_t j = 0; j < subtable->rulesCount; j++) { deleteRule(subtable->rules[j]); } + for (uint16_t j = 0; j < subtable->rulesCount; j++) { + deleteRule(subtable->rules[j]); + } free(subtable->rules); } if (subtable->bc) { caryll_delete_classdef(subtable->bc); } @@ -22,7 +26,9 @@ void delete_otl_chaining_subtable(otl_subtable *_subtable) { void caryll_delete_chaining(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) { delete_otl_chaining_subtable(lookup->subtables[j]); } + for (uint16_t j = 0; j < lookup->subtableCount; j++) { + delete_otl_chaining_subtable(lookup->subtables[j]); + } free(lookup->subtables); } free(lookup); @@ -513,7 +519,9 @@ caryll_buffer *caryll_write_chaining_classes(otl_subtable *_subtable) { uint16_t *rcpg, totalSets = 0, totalRules = 0; NEW_N(rcpg, subtable->ic->maxclass + 1); - for (uint16_t j = 0; j <= subtable->ic->maxclass; j++) { rcpg[j] = 0; } + for (uint16_t j = 0; j <= subtable->ic->maxclass; j++) { + rcpg[j] = 0; + } for (uint16_t j = 0; j < subtable->rulesCount; j++) { uint16_t ib = subtable->rules[j]->inputBegins; uint16_t startClass = subtable->rules[j]->match[ib]->glyphs[0].gid; diff --git a/lib/tables/otl/classdef.c b/lib/tables/otl/classdef.c index b484a4e6..d9ce0723 100644 --- a/lib/tables/otl/classdef.c +++ b/lib/tables/otl/classdef.c @@ -14,7 +14,9 @@ typedef struct { UT_hash_handle hh; } coverage_entry; -static int by_covIndex(coverage_entry *a, coverage_entry *b) { return a->covIndex - b->covIndex; } +static int by_covIndex(coverage_entry *a, coverage_entry *b) { + return a->covIndex - b->covIndex; +} otl_classdef *caryll_read_classdef(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_classdef *cd; diff --git a/lib/tables/otl/coverage.c b/lib/tables/otl/coverage.c index 1ed6f063..a6f64862 100644 --- a/lib/tables/otl/coverage.c +++ b/lib/tables/otl/coverage.c @@ -11,7 +11,9 @@ typedef struct { UT_hash_handle hh; } coverage_entry; -static int by_covIndex(coverage_entry *a, coverage_entry *b) { return a->covIndex - b->covIndex; } +static int by_covIndex(coverage_entry *a, coverage_entry *b) { + return a->covIndex - b->covIndex; +} otl_coverage *caryll_read_coverage(font_file_pointer data, uint32_t tableLength, uint32_t offset) { otl_coverage *coverage; @@ -135,7 +137,9 @@ caryll_buffer *caryll_write_coverage(otl_coverage *coverage) { caryll_buffer *format1 = bufnew(); bufwrite16b(format1, 1); bufwrite16b(format1, coverage->numGlyphs); - for (uint16_t j = 0; j < coverage->numGlyphs; j++) { bufwrite16b(format1, coverage->glyphs[j].gid); } + for (uint16_t j = 0; j < coverage->numGlyphs; j++) { + bufwrite16b(format1, coverage->glyphs[j].gid); + } if (coverage->numGlyphs < 2) return format1; caryll_buffer *format2 = bufnew(); diff --git a/lib/tables/otl/gpos-common.c b/lib/tables/otl/gpos-common.c index bf9b4869..da15297d 100644 --- a/lib/tables/otl/gpos-common.c +++ b/lib/tables/otl/gpos-common.c @@ -83,7 +83,9 @@ const uint8_t bits_in[0x100] = {d(0)}; #undef a // Length of a position value in bytes -uint8_t position_format_length(uint16_t format) { return bits_in[format & 0xFF] << 1; } +uint8_t position_format_length(uint16_t format) { + return bits_in[format & 0xFF] << 1; +} otl_position_value position_zero() { otl_position_value v = {0, 0, 0, 0}; return v; @@ -129,5 +131,9 @@ void write_gpos_value(caryll_buffer *buf, otl_position_value v, uint16_t format) } // Anchor functions -int getPositon(otl_anchor anchor) { return ((uint16_t)anchor.x) << 16 | ((uint16_t)anchor.y); } -int byAnchorIndex(anchor_aggeration_hash *a, anchor_aggeration_hash *b) { return a->index - b->index; } +int getPositon(otl_anchor anchor) { + return ((uint16_t)anchor.x) << 16 | ((uint16_t)anchor.y); +} +int byAnchorIndex(anchor_aggeration_hash *a, anchor_aggeration_hash *b) { + return a->index - b->index; +} diff --git a/lib/tables/otl/gpos-mark-to-ligature.c b/lib/tables/otl/gpos-mark-to-ligature.c index 3a207bbe..ded120a1 100644 --- a/lib/tables/otl/gpos-mark-to-ligature.c +++ b/lib/tables/otl/gpos-mark-to-ligature.c @@ -4,7 +4,8 @@ void delete_lig_attachment(mark_to_ligature_base *att) { if (!att) return; if (att->anchors) { - for (uint16_t k = 0; k < att->componentCount; k++) free(att->anchors[k]); + for (uint16_t k = 0; k < att->componentCount; k++) + free(att->anchors[k]); free(att->anchors); } free(att); @@ -31,7 +32,8 @@ static void delete_mtl_subtable(otl_subtable *_subtable) { void caryll_delete_gpos_mark_to_ligature(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) delete_mtl_subtable(lookup->subtables[j]); + for (uint16_t j = 0; j < lookup->subtableCount; j++) + delete_mtl_subtable(lookup->subtables[j]); free(lookup->subtables); } free(lookup); @@ -56,7 +58,9 @@ otl_subtable *caryll_read_gpos_mark_to_ligature(font_file_pointer data, uint32_t checkLength(ligArrayOffset + 2 + 2 * subtable->bases->numGlyphs); if (read_16u(data + ligArrayOffset) != subtable->bases->numGlyphs) goto FAIL; NEW_N(subtable->ligArray, subtable->bases->numGlyphs); - for (uint16_t j = 0; j < subtable->bases->numGlyphs; j++) { subtable->ligArray[j] = NULL; } + for (uint16_t j = 0; j < subtable->bases->numGlyphs; j++) { + subtable->ligArray[j] = NULL; + } for (uint16_t j = 0; j < subtable->bases->numGlyphs; j++) { uint32_t ligAttachOffset = ligArrayOffset + read_16u(data + ligArrayOffset + 2 + j * 2); NEW(subtable->ligArray[j]); @@ -193,7 +197,9 @@ static void parseBases(json_value *_bases, subtable_gpos_mark_to_ligature *subta for (uint16_t k = 0; k < subtable->ligArray[j]->componentCount; k++) { json_value *_componentRecord = baseRecord->u.array.values[k]; NEW_N(subtable->ligArray[j]->anchors[k], classCount); - for (uint16_t m = 0; m < classCount; m++) { subtable->ligArray[j]->anchors[k][m] = otl_anchor_absent(); } + for (uint16_t m = 0; m < classCount; m++) { + subtable->ligArray[j]->anchors[k][m] = otl_anchor_absent(); + } if (!_componentRecord || _componentRecord->type != json_object) { continue; } for (uint16_t m = 0; m < _componentRecord->u.object.length; m++) { sds className = sdsnewlen(_componentRecord->u.object.values[m].name, diff --git a/lib/tables/otl/gpos-mark-to-single.c b/lib/tables/otl/gpos-mark-to-single.c index 521999f7..d6086507 100644 --- a/lib/tables/otl/gpos-mark-to-single.c +++ b/lib/tables/otl/gpos-mark-to-single.c @@ -22,7 +22,8 @@ static void delete_mtb_subtable(otl_subtable *_subtable) { void caryll_delete_gpos_mark_to_single(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) delete_mtb_subtable(lookup->subtables[j]); + for (uint16_t j = 0; j < lookup->subtableCount; j++) + delete_mtb_subtable(lookup->subtables[j]); free(lookup->subtables); } free(lookup); @@ -153,7 +154,9 @@ static void parseBases(json_value *_bases, subtable_gpos_mark_to_single *subtabl char *gname = _bases->u.object.values[j].name; subtable->bases->glyphs[j].name = sdsnewlen(gname, _bases->u.object.values[j].name_length); NEW_N(subtable->baseArray[j], classCount); - for (uint16_t k = 0; k < classCount; k++) { subtable->baseArray[j][k] = otl_anchor_absent(); } + for (uint16_t k = 0; k < classCount; k++) { + subtable->baseArray[j][k] = otl_anchor_absent(); + } json_value *baseRecord = _bases->u.object.values[j].value; if (!baseRecord || baseRecord->type != json_object) continue; @@ -220,7 +223,9 @@ caryll_buffer *caryll_write_gpos_mark_to_single(otl_subtable *_subtable) { ANCHOR_AGGERATOR_PUSH(agh, subtable->markArray->records[j].anchor); } for (uint16_t j = 0; j < subtable->bases->numGlyphs; j++) { - for (uint16_t k = 0; k < subtable->classCount; k++) { ANCHOR_AGGERATOR_PUSH(agh, subtable->baseArray[j][k]); } + for (uint16_t k = 0; k < subtable->classCount; k++) { + ANCHOR_AGGERATOR_PUSH(agh, subtable->baseArray[j][k]); + } } HASH_SORT(agh, byAnchorIndex); diff --git a/lib/tables/otl/gpos-pair.c b/lib/tables/otl/gpos-pair.c index afdacf08..e2728169 100644 --- a/lib/tables/otl/gpos-pair.c +++ b/lib/tables/otl/gpos-pair.c @@ -6,11 +6,15 @@ void delete_otl_gpos_pair_subtable(otl_subtable *_subtable) { subtable_gpos_pair *subtable = &(_subtable->gpos_pair); if (subtable->coverage) caryll_delete_coverage(subtable->coverage); if (subtable->firstValues) { - for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { free(subtable->firstValues[j]); } + for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { + free(subtable->firstValues[j]); + } free(subtable->firstValues); } if (subtable->secondValues) { - for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { free(subtable->secondValues[j]); } + for (uint16_t j = 0; j <= subtable->first->maxclass; j++) { + free(subtable->secondValues[j]); + } free(subtable->secondValues); } caryll_delete_classdef(subtable->first); @@ -21,7 +25,8 @@ void delete_otl_gpos_pair_subtable(otl_subtable *_subtable) { void caryll_delete_gpos_pair(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) delete_otl_gpos_pair_subtable(lookup->subtables[j]); + for (uint16_t j = 0; j < lookup->subtableCount; j++) + delete_otl_gpos_pair_subtable(lookup->subtables[j]); free(lookup->subtables); } free(lookup); @@ -54,7 +59,9 @@ otl_subtable *caryll_read_gpos_pair(font_file_pointer data, uint32_t tableLength subtable->first->maxclass = cov->numGlyphs - 1; subtable->first->glyphs = cov->glyphs; NEW_N(subtable->first->classes, cov->numGlyphs); - for (uint16_t j = 0; j < cov->numGlyphs; j++) { subtable->first->classes[j] = j; } + for (uint16_t j = 0; j < cov->numGlyphs; j++) { + subtable->first->classes[j] = j; + } free(cov); uint16_t format1 = read_16u(data + offset + 4); diff --git a/lib/tables/otl/gpos-single.c b/lib/tables/otl/gpos-single.c index f5be68f7..ddadf58d 100644 --- a/lib/tables/otl/gpos-single.c +++ b/lib/tables/otl/gpos-single.c @@ -29,7 +29,9 @@ otl_subtable *caryll_read_gpos_single(font_file_pointer data, uint32_t tableLeng if (subtableFormat == 1) { otl_position_value v = read_gpos_value(data, tableLength, offset + 6, read_16u(data + offset + 4)); - for (uint16_t j = 0; j < subtable->coverage->numGlyphs; j++) { subtable->values[j] = v; } + for (uint16_t j = 0; j < subtable->coverage->numGlyphs; j++) { + subtable->values[j] = v; + } } else { uint16_t valueFormat = read_16u(data + offset + 4); uint16_t valueCount = read_16u(data + offset + 6); diff --git a/lib/tables/otl/gsub-ligature.c b/lib/tables/otl/gsub-ligature.c index f28cf8e9..a09c65a3 100644 --- a/lib/tables/otl/gsub-ligature.c +++ b/lib/tables/otl/gsub-ligature.c @@ -3,7 +3,9 @@ static void deleteGSUBLigatureSubtable(otl_subtable *_subtable) { if (!_subtable) return; subtable_gsub_ligature *subtable = &(_subtable->gsub_ligature); if (subtable->from && subtable->to) { - for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { caryll_delete_coverage(subtable->from[j]); } + for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { + caryll_delete_coverage(subtable->from[j]); + } free(subtable->from); } caryll_delete_coverage(subtable->to); @@ -45,7 +47,9 @@ otl_subtable *caryll_read_gsub_ligature(font_file_pointer data, uint32_t tableLe subtable->to->numGlyphs = ligatureCount; NEW_N(subtable->to->glyphs, ligatureCount); NEW_N(subtable->from, ligatureCount); - for (uint16_t j = 0; j < ligatureCount; j++) { subtable->from[j] = NULL; }; + for (uint16_t j = 0; j < ligatureCount; j++) { + subtable->from[j] = NULL; + }; uint16_t jj = 0; for (uint16_t j = 0; j < setCount; j++) { uint32_t setOffset = offset + read_16u(data + offset + 6 + j * 2); @@ -144,7 +148,9 @@ typedef struct { int ligid; UT_hash_handle hh; } ligature_aggerator; -static int by_gid(ligature_aggerator *a, ligature_aggerator *b) { return a->gid - b->gid; } +static int by_gid(ligature_aggerator *a, ligature_aggerator *b) { + return a->gid - b->gid; +} caryll_buffer *caryll_write_gsub_ligature_subtable(otl_subtable *_subtable) { caryll_buffer *buf = bufnew(); diff --git a/lib/tables/otl/gsub-multi.c b/lib/tables/otl/gsub-multi.c index 9f1e74dd..09cf653b 100644 --- a/lib/tables/otl/gsub-multi.c +++ b/lib/tables/otl/gsub-multi.c @@ -3,7 +3,9 @@ static void deleteGSUBMultiSubtable(otl_subtable *_subtable) { if (!_subtable) return; subtable_gsub_multi *subtable = &(_subtable->gsub_multi); if (subtable->from && subtable->to) { - for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { caryll_delete_coverage(subtable->to[j]); } + for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { + caryll_delete_coverage(subtable->to[j]); + } free(subtable->to); } caryll_delete_coverage(subtable->from); @@ -41,7 +43,9 @@ otl_subtable *caryll_read_gsub_multi(font_file_pointer data, uint32_t tableLengt NEW(cov); cov->numGlyphs = read_16u(data + seqOffset); NEW_N(cov->glyphs, cov->numGlyphs); - for (uint16_t k = 0; k < cov->numGlyphs; k++) { cov->glyphs[k].gid = read_16u(data + seqOffset + 2 + k * 2); } + for (uint16_t k = 0; k < cov->numGlyphs; k++) { + cov->glyphs[k].gid = read_16u(data + seqOffset + 2 + k * 2); + } subtable->to[j] = cov; } return _subtable; @@ -94,7 +98,9 @@ caryll_buffer *caryll_write_gsub_multi_subtable(otl_subtable *_subtable) { for (uint16_t j = 0; j < subtable->from->numGlyphs; j++) { bufping16b(buf, &offset, &cp); bufwrite16b(buf, subtable->to[j]->numGlyphs); - for (uint16_t k = 0; k < subtable->to[j]->numGlyphs; k++) { bufwrite16b(buf, subtable->to[j]->glyphs[k].gid); } + for (uint16_t k = 0; k < subtable->to[j]->numGlyphs; k++) { + bufwrite16b(buf, subtable->to[j]->glyphs[k].gid); + } bufpong(buf, &offset, &cp); } return buf; diff --git a/lib/tables/otl/gsub-reverse.c b/lib/tables/otl/gsub-reverse.c index 61e44760..723927f3 100644 --- a/lib/tables/otl/gsub-reverse.c +++ b/lib/tables/otl/gsub-reverse.c @@ -4,7 +4,9 @@ static void delete_gsub_reverse_subtable(otl_subtable *_subtable) { if (_subtable) { subtable_gsub_reverse *subtable = &(_subtable->gsub_reverse); if (subtable->match) - for (uint16_t j = 0; j < subtable->matchCount; j++) { caryll_delete_coverage(subtable->match[j]); } + for (uint16_t j = 0; j < subtable->matchCount; j++) { + caryll_delete_coverage(subtable->match[j]); + } if (subtable->to) caryll_delete_coverage(subtable->to); free(_subtable); } @@ -13,7 +15,9 @@ static void delete_gsub_reverse_subtable(otl_subtable *_subtable) { void caryll_delete_gsub_reverse(otl_lookup *lookup) { if (lookup) { if (lookup->subtables) { - for (uint16_t j = 0; j < lookup->subtableCount; j++) { delete_gsub_reverse_subtable(lookup->subtables[j]); } + for (uint16_t j = 0; j < lookup->subtableCount; j++) { + delete_gsub_reverse_subtable(lookup->subtables[j]); + } free(lookup->subtables); } free(lookup); @@ -133,6 +137,8 @@ caryll_buffer *caryll_write_gsub_reverse(otl_subtable *_subtable) { bufpingpong16b(buf, caryll_write_coverage(subtable->match[j]), &offset, &cp); } bufwrite16b(buf, subtable->to->numGlyphs); - for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { bufwrite16b(buf, subtable->to->glyphs[j].gid); } + for (uint16_t j = 0; j < subtable->to->numGlyphs; j++) { + bufwrite16b(buf, subtable->to->glyphs[j].gid); + } return buf; } diff --git a/lib/tables/otl/gsub-single.c b/lib/tables/otl/gsub-single.c index e3bd3671..c1b88b1f 100644 --- a/lib/tables/otl/gsub-single.c +++ b/lib/tables/otl/gsub-single.c @@ -110,7 +110,9 @@ caryll_buffer *caryll_write_gsub_single_subtable(otl_subtable *_subtable) { bufwrite16b(bufst, 2); bufwrite16b(bufst, 6 + subtable->to->numGlyphs * 2); bufwrite16b(bufst, subtable->to->numGlyphs); - for (uint16_t k = 0; k < subtable->to->numGlyphs; k++) { bufwrite16b(bufst, subtable->to->glyphs[k].gid); } + for (uint16_t k = 0; k < subtable->to->numGlyphs; k++) { + bufwrite16b(bufst, subtable->to->glyphs[k].gid); + } bufwrite_bufdel(bufst, caryll_write_coverage(subtable->from)); } return bufst; diff --git a/lib/tables/otl/otl.c b/lib/tables/otl/otl.c index e53aee04..00867599 100644 --- a/lib/tables/otl/otl.c +++ b/lib/tables/otl/otl.c @@ -63,7 +63,9 @@ void caryll_delete_otl(table_otl *table) { free(table->features); } if (table->lookups) { - for (uint16_t j = 0; j < table->lookupCount; j++) { caryll_delete_lookup(table->lookups[j]); } + for (uint16_t j = 0; j < table->lookupCount; j++) { + caryll_delete_lookup(table->lookups[j]); + } free(table->lookups); } free(table); @@ -284,7 +286,9 @@ table_otl *caryll_read_otl(caryll_packet packet, uint32_t tag) { data, length, (tag == 'GSUB' ? otl_type_gsub_unknown : tag == 'GPOS' ? otl_type_gpos_unknown : otl_type_unknown)); if (!otl) goto FAIL; - for (uint16_t j = 0; j < otl->lookupCount; j++) { caryll_read_otl_lookup(data, length, otl->lookups[j]); } + for (uint16_t j = 0; j < otl->lookupCount; j++) { + caryll_read_otl_lookup(data, length, otl->lookups[j]); + } return otl; FAIL: if (otl) caryll_delete_otl(otl); @@ -526,8 +530,12 @@ static int by_lookup_order(lookup_hash *a, lookup_hash *b) { return a->orderType - b->orderType; } } -static int by_feature_name(feature_hash *a, feature_hash *b) { return strcmp(a->name, b->name); } -static int by_language_name(language_hash *a, language_hash *b) { return strcmp(a->name, b->name); } +static int by_feature_name(feature_hash *a, feature_hash *b) { + return strcmp(a->name, b->name); +} +static int by_language_name(language_hash *a, language_hash *b) { + return strcmp(a->name, b->name); +} table_otl *caryll_otl_from_json(json_value *root, caryll_options *options, const char *tag) { table_otl *otl = NULL; NEW(otl); diff --git a/lib/tables/post.c b/lib/tables/post.c index 3cf1c41d..f1d06940 100644 --- a/lib/tables/post.c +++ b/lib/tables/post.c @@ -54,7 +54,9 @@ table_post *caryll_read_post(caryll_packet packet) { try_name_glyph(map, j, sdsnew(standardMacNames[nameMap])); } } - for (uint32_t j = 0; j < pendingNameIndex; j++) { sdsfree(pendingNames[j]); } + for (uint32_t j = 0; j < pendingNameIndex; j++) { + sdsfree(pendingNames[j]); + } post->post_name_map = map; } return post; @@ -121,7 +123,9 @@ caryll_buffer *caryll_write_post(table_post *post, glyph_order_hash *glyphorder, // Since the glyphorder is already sorted using the "real" glyph order // we can simply write down the glyph names. glyph_order_entry *s; - foreach_hash(s, *glyphorder) { bufwrite16b(buf, 258 + s->gid); } + foreach_hash(s, *glyphorder) { + bufwrite16b(buf, 258 + s->gid); + } foreach_hash(s, *glyphorder) { bufwrite8(buf, sdslen(s->name)); bufwrite_sds(buf, s->name); diff --git a/lib/tables/vmtx.c b/lib/tables/vmtx.c index aeaaea04..9729c268 100644 --- a/lib/tables/vmtx.c +++ b/lib/tables/vmtx.c @@ -21,7 +21,9 @@ table_vmtx *caryll_read_vmtx(caryll_packet packet, table_vhea *vhea, table_maxp vmtx->metrics[ia].tsb = read_16u(data + ia * 4 + 2); } - for (uint32_t ik = 0; ik < count_k; ik++) { vmtx->topSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); } + for (uint32_t ik = 0; ik < count_k; ik++) { + vmtx->topSideBearing[ik] = read_16u(data + count_a * 4 + ik * 2); + } return vmtx; vmtx_CORRUPTED: @@ -48,7 +50,9 @@ caryll_buffer *caryll_write_vmtx(table_vmtx *vmtx, uint16_t count_a, uint16_t co } } if (vmtx->topSideBearing) { - for (uint16_t j = 0; j < count_k; j++) { bufwrite16b(buf, vmtx->topSideBearing[j]); } + for (uint16_t j = 0; j < count_k; j++) { + bufwrite16b(buf, vmtx->topSideBearing[j]); + } } return buf; } diff --git a/src/stopwatch.c b/src/stopwatch.c index 18329088..2f5ede76 100644 --- a/src/stopwatch.c +++ b/src/stopwatch.c @@ -76,7 +76,9 @@ void time_now(struct timespec *tv) { tv->tv_nsec = diff - (tv->tv_sec * ORWL_GIGA); } #else -void time_now(struct timespec *tv) { clock_gettime(CLOCK_REALTIME, tv); } +void time_now(struct timespec *tv) { + clock_gettime(CLOCK_REALTIME, tv); +} #endif #define BILLION 1000000000 From 823f5de81e0e996683cac808ee5f296de40a26f3 Mon Sep 17 00:00:00 2001 From: be5invis Date: Fri, 29 Jul 2016 23:08:46 +0800 Subject: [PATCH 15/16] Move to 0.2.4 --- makefile | 2 +- premake5.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 6fc2a1d1..e8fde904 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -VERSION=0.2.3 +VERSION=0.2.4 ifndef PREMAKE5 PREMAKE5=premake5 diff --git a/premake5.lua b/premake5.lua index 710c9be2..742e3bb0 100644 --- a/premake5.lua +++ b/premake5.lua @@ -41,7 +41,7 @@ workspace "otfcc" '_CARYLL_USE_PRE_SERIALIZED', 'MAIN_VER=0', "SECONDARY_VER=2", - "PATCH_VER=3" + "PATCH_VER=4" } location "build" From 3534ce928f66009e27fa3dc39e73594346cf2d21 Mon Sep 17 00:00:00 2001 From: be5invis Date: Fri, 29 Jul 2016 23:10:46 +0800 Subject: [PATCH 16/16] init yPel to 0 --- lib/tables/glyf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tables/glyf.c b/lib/tables/glyf.c index caa6efc3..22b71b1f 100644 --- a/lib/tables/glyf.c +++ b/lib/tables/glyf.c @@ -24,6 +24,7 @@ glyf_glyph *caryll_new_glyf_glyph() { g->hintMasks = NULL; g->contourMasks = NULL; g->fdSelectIndex = 0; + g->yPel = 0; g->stat.xMin = 0; g->stat.xMax = 0;