From b989507fa6b36eb9950001d4e28f3946ffbe75f9 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 8 Nov 2018 20:48:54 +0330 Subject: [PATCH 01/17] [aat] Minor (#1369) --- src/hb-aat-layout-just-table.hh | 11 ++++++----- src/hb-aat-layout-trak-table.hh | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hb-aat-layout-just-table.hh b/src/hb-aat-layout-just-table.hh index 1d6002757..54ffec22f 100644 --- a/src/hb-aat-layout-just-table.hh +++ b/src/hb-aat-layout-just-table.hh @@ -178,6 +178,8 @@ struct RepeatedAddGlyphAction struct ActionSubrecord { + inline unsigned int get_length (void) const { return u.header.actionLength; } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -196,8 +198,6 @@ struct ActionSubrecord } } - inline unsigned int get_length () const { return u.header.actionLength; } - protected: union { ActionSubrecordHeader header; @@ -388,9 +388,10 @@ struct just { TRACE_SANITIZE (this); - return_trace (unlikely (c->check_struct (this) && - horizData.sanitize (c, this, this) && - vertData.sanitize (c, this, this))); + return_trace (likely (c->check_struct (this) && + version.major == 1 && + horizData.sanitize (c, this, this) && + vertData.sanitize (c, this, this))); } protected: diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index c579c1193..68218ecb7 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -147,9 +147,9 @@ struct TrackData inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - sizeTable.sanitize (c, base, nSizes) && - trackTable.sanitize (c, nTracks, base, nSizes)); + return_trace (likely (c->check_struct (this) && + sizeTable.sanitize (c, base, nSizes) && + trackTable.sanitize (c, nTracks, base, nSizes))); } protected: @@ -175,9 +175,9 @@ struct trak { TRACE_SANITIZE (this); - return_trace (unlikely (c->check_struct (this) && - horizData.sanitize (c, this, this) && - vertData.sanitize (c, this, this))); + return_trace (likely (c->check_struct (this) && + horizData.sanitize (c, this, this) && + vertData.sanitize (c, this, this))); } inline bool apply (hb_aat_apply_context_t *c) const From 9fae611740f514e5fc101a18c4551a20b4a47b59 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 8 Nov 2018 12:17:09 -0500 Subject: [PATCH 02/17] [test/text-rendering-tests] Update from upstream --- test/shaping/data/text-rendering-tests/DISABLED | 1 + .../data/text-rendering-tests/Makefile.sources | 2 +- .../text-rendering-tests/tests/MORX-31.tests | 16 ++++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/shaping/data/text-rendering-tests/DISABLED b/test/shaping/data/text-rendering-tests/DISABLED index ef987a4df..b0719043e 100644 --- a/test/shaping/data/text-rendering-tests/DISABLED +++ b/test/shaping/data/text-rendering-tests/DISABLED @@ -1,3 +1,4 @@ +tests/MORX-31.tests tests/MORX-41.tests # Non-Unicode cmap diff --git a/test/shaping/data/text-rendering-tests/Makefile.sources b/test/shaping/data/text-rendering-tests/Makefile.sources index 136a14d32..052a61236 100644 --- a/test/shaping/data/text-rendering-tests/Makefile.sources +++ b/test/shaping/data/text-rendering-tests/Makefile.sources @@ -51,7 +51,6 @@ TESTS = \ tests/MORX-29.tests \ tests/MORX-2.tests \ tests/MORX-30.tests \ - tests/MORX-31.tests \ tests/MORX-32.tests \ tests/MORX-33.tests \ tests/MORX-34.tests \ @@ -74,6 +73,7 @@ TESTS = \ DISBALED_TESTS = \ tests/CMAP-3.tests \ + tests/MORX-31.tests \ tests/MORX-41.tests \ tests/SHARAN-1.tests \ tests/SHBALI-1.tests \ diff --git a/test/shaping/data/text-rendering-tests/tests/MORX-31.tests b/test/shaping/data/text-rendering-tests/tests/MORX-31.tests index 6cc40b6e1..ac09e27b4 100644 --- a/test/shaping/data/text-rendering-tests/tests/MORX-31.tests +++ b/test/shaping/data/text-rendering-tests/tests/MORX-31.tests @@ -1,8 +1,8 @@ -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0041,U+0059,U+0059,U+0041,U+005A,U+005A:[X|X@364,0|I@728,0|N@1558,0|S@2388,0|A@3218,0|Y@4048,0|Y@4380,0|A@4712,0|Z@5542,0|Z@5864,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0041,U+0059,U+0059,U+0042,U+0059,U+0059:[X|X@364,0|A@728,0|I@1558,0|N@2388,0|S@3218,0|Y@4048,0|Y@4380,0|B@4712,0|Y@5542,0|Y@5874,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0042,U+0059,U+0059,U+0041,U+005A,U+005A:[X|X@364,0|I@728,0|N@1558,0|S@2388,0|B@3218,0|Y@4048,0|Y@4380,0|A@4712,0|Z@5542,0|Z@5864,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0042,U+0059,U+0059,U+0042,U+005A,U+005A:[X|X@364,0|B@728,0|I@1558,0|N@2388,0|S@3218,0|Y@4048,0|Y@4380,0|B@4712,0|Z@5542,0|Z@5864,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0041,U+0058,U+0059,U+005A,U+0041:[I|N@830,0|S@1660,0|M@2490,0|P@3320,0|Q@3653,0|R@4019,0|I@4370,0|N@5200,0|S@6030,0|A@6860,0|X@7690,0|Y@8054,0|Z@8386,0|A@8708,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0041,U+0058,U+0059,U+005A,U+0042:[I|N@830,0|S@1660,0|M@2490,0|P@3320,0|Q@3653,0|R@4019,0|A@4370,0|I@5200,0|N@6030,0|S@6860,0|X@7690,0|Y@8054,0|Z@8386,0|B@8708,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0042,U+0058,U+0059,U+005A,U+0041:[M|I@830,0|N@1660,0|S@2490,0|P@3320,0|Q@3653,0|R@4019,0|I@4370,0|N@5200,0|S@6030,0|B@6860,0|X@7690,0|Y@8054,0|Z@8386,0|A@8708,0] -../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0042,U+0058,U+0059,U+005A,U+0042:[M|I@830,0|N@1660,0|S@2490,0|P@3320,0|Q@3653,0|R@4019,0|B@4370,0|I@5200,0|N@6030,0|S@6860,0|X@7690,0|Y@8054,0|Z@8386,0|B@8708,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0041,U+0059,U+0059,U+0041,U+005A,U+005A:[I|N@830,0|I@1660,0|N@2490,0|S@3320,0|S@4150,0|X@4980,0|X@5344,0|A@5708,0|Y@6538,0|Y@6870,0|A@7202,0|Z@8032,0|Z@8354,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0041,U+0059,U+0059,U+0042,U+0059,U+0059:[I|N@830,0|S@1660,0|I@2490,0|N@3320,0|S@4150,0|X@4980,0|X@5344,0|A@5708,0|Y@6538,0|Y@6870,0|B@7202,0|Y@8032,0|Y@8364,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0042,U+0059,U+0059,U+0041,U+005A,U+005A:[X|I@364,0|I@1194,0|N@2024,0|S@2854,0|N@3684,0|S@4514,0|X@5344,0|B@5708,0|Y@6538,0|Y@6870,0|A@7202,0|Z@8032,0|Z@8354,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+0058,U+0058,U+0042,U+0059,U+0059,U+0042,U+005A,U+005A:[X|I@364,0|N@1194,0|I@2024,0|N@2854,0|S@3684,0|S@4514,0|X@5344,0|B@5708,0|Y@6538,0|Y@6870,0|B@7202,0|Z@8032,0|Z@8354,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0041,U+0058,U+0059,U+005A,U+0041:[I|N@830,0|S@1660,0|M@2490,0|I@3320,0|N@4150,0|S@4980,0|P@5810,0|Q@6143,0|R@6509,0|A@6860,0|X@7690,0|Y@8054,0|Z@8386,0|A@8708,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0041,U+0058,U+0059,U+005A,U+0042:[I|N@830,0|S@1660,0|M@2490,0|P@3320,0|I@3653,0|N@4483,0|S@5313,0|Q@6143,0|R@6509,0|A@6860,0|X@7690,0|Y@8054,0|Z@8386,0|B@8708,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0042,U+0058,U+0059,U+005A,U+0041:[M|I@830,0|N@1660,0|S@2490,0|I@3320,0|N@4150,0|S@4980,0|P@5810,0|Q@6143,0|R@6509,0|B@6860,0|X@7690,0|Y@8054,0|Z@8386,0|A@8708,0] +../fonts/TestMORXThirtyone.ttf:--font-size=1000 --ned --remove-default-ignorables --font-funcs=ft:U+004D,U+0050,U+0051,U+0052,U+0042,U+0058,U+0059,U+005A,U+0042:[M|I@830,0|N@1660,0|S@2490,0|P@3320,0|I@3653,0|N@4483,0|S@5313,0|Q@6143,0|R@6509,0|B@6860,0|X@7690,0|Y@8054,0|Z@8386,0|B@8708,0] From 2d987110c067ccbf63b1399d2a87820121925e39 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 8 Nov 2018 21:46:26 +0330 Subject: [PATCH 03/17] [aat] Minor --- src/hb-aat-layout-just-table.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-aat-layout-just-table.hh b/src/hb-aat-layout-just-table.hh index 54ffec22f..92ca6603e 100644 --- a/src/hb-aat-layout-just-table.hh +++ b/src/hb-aat-layout-just-table.hh @@ -309,8 +309,8 @@ struct WidthDeltaPair public: DEFINE_SIZE_STATIC (24); }; - -struct WidthDeltaCluster : OT::LArrayOf {}; + +typedef OT::LArrayOf WidthDeltaCluster; struct JustificationCategory { From b986fead0aee52d219ce85dd49c9109bfaf31801 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 5 Nov 2018 12:31:58 +0330 Subject: [PATCH 04/17] Hook AAT's lcar to _get_ligature_carets --- src/Makefile.sources | 1 + src/hb-aat-layout-lcar-table.hh | 92 +++++++++++++++++++++++++++++ src/hb-ot-face.hh | 1 + src/hb-ot-layout-gdef-table.hh | 6 +- src/hb-ot-layout.cc | 17 ++++-- test/api/Makefile.am | 1 + test/api/fonts/lcar.ttf | Bin 0 -> 808 bytes test/api/test-ot-ligature-carets.c | 67 +++++++++++++++++++++ 8 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 src/hb-aat-layout-lcar-table.hh create mode 100644 test/api/fonts/lcar.ttf create mode 100644 test/api/test-ot-ligature-carets.c diff --git a/src/Makefile.sources b/src/Makefile.sources index 36a115286..f83d6dcc4 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -102,6 +102,7 @@ HB_OT_sources = \ hb-aat-layout-feat-table.hh \ hb-aat-layout-just-table.hh \ hb-aat-layout-kerx-table.hh \ + hb-aat-layout-lcar-table.hh \ hb-aat-layout-morx-table.hh \ hb-aat-layout-trak-table.hh \ hb-aat-layout.hh \ diff --git a/src/hb-aat-layout-lcar-table.hh b/src/hb-aat-layout-lcar-table.hh new file mode 100644 index 000000000..e57836a08 --- /dev/null +++ b/src/hb-aat-layout-lcar-table.hh @@ -0,0 +1,92 @@ +/* + * Copyright © 2018 Ebrahim Byagowi + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ +#ifndef HB_AAT_LAYOUT_LCAR_TABLE_HH +#define HB_AAT_LAYOUT_LCAR_TABLE_HH + +#include "hb-open-type.hh" +#include "hb-aat-layout-common.hh" + +/* + * lcar -- Ligature caret + * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6lcar.html + */ +#define HB_AAT_TAG_lcar HB_TAG('l','c','a','r') + + +namespace AAT { + +typedef ArrayOf LigCaretClassEntry; + +struct lcar +{ + static const hb_tag_t tableTag = HB_AAT_TAG_lcar; + + inline unsigned int get_lig_carets (hb_font_t *font, + hb_direction_t direction, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *caret_count /* IN/OUT */, + hb_position_t *caret_array /* OUT */) const + { + const OffsetTo* entry_offset = lookup.get_value (glyph, font->face->num_glyphs); + const LigCaretClassEntry& array = entry_offset ? this+*entry_offset : Null (LigCaretClassEntry); + if (caret_count && *caret_count) + { + const HBINT16 *arr = array.sub_array (start_offset, caret_count); + unsigned int count = *caret_count; + for (unsigned int i = 0; i < count; ++i) + switch (format) + { + case 0: caret_array[i] = font->em_scale_dir (arr[i], direction); break; + case 1: + hb_position_t x, y; + font->get_glyph_contour_point_for_origin (glyph, arr[i], direction, &x, &y); + caret_array[i] = HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; + break; + } + } + return array.len; + } + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (likely (c->check_struct (this) && + version.major == 1 && + lookup.sanitize (c, this))); + } + + protected: + FixedVersion<>version; /* Version number of the ligature caret table */ + HBUINT16 format; /* Format of the ligature caret table. */ + Lookup > + lookup; /* data Lookup table associating glyphs */ + + public: + DEFINE_SIZE_MIN (8); +}; + +} /* namespace AAT */ + +#endif /* HB_AAT_LAYOUT_LCAR_TABLE_HH */ diff --git a/src/hb-ot-face.hh b/src/hb-ot-face.hh index f393d4b1b..4a36a4dcb 100644 --- a/src/hb-ot-face.hh +++ b/src/hb-ot-face.hh @@ -60,6 +60,7 @@ HB_OT_TABLE(AAT, kerx) \ HB_OT_TABLE(AAT, ankr) \ HB_OT_TABLE(AAT, trak) \ + HB_OT_TABLE(AAT, lcar) \ HB_OT_TABLE(AAT, ltag) \ /* OpenType variations. */ \ HB_OT_TABLE(OT, fvar) \ diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index ea5f1c07d..af7e5a833 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -123,10 +123,8 @@ struct CaretValueFormat2 inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const { hb_position_t x, y; - if (font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y)) - return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; - else - return 0; + font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y); + return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; } inline bool sanitize (hb_sanitize_context_t *c) const diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index eb5140fc2..33bf03c13 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -42,6 +42,8 @@ #include "hb-ot-kern-table.hh" #include "hb-ot-name-table.hh" +#include "hb-aat-layout-lcar-table.hh" + /** * SECTION:hb-ot-layout @@ -275,12 +277,15 @@ hb_ot_layout_get_ligature_carets (hb_font_t *font, unsigned int *caret_count /* IN/OUT */, hb_position_t *caret_array /* OUT */) { - return font->face->table.GDEF->table->get_lig_carets (font, - direction, - glyph, - start_offset, - caret_count, - caret_array); + unsigned int result_caret_count = 0; + unsigned int result = font->face->table.GDEF->table->get_lig_carets (font, direction, glyph, start_offset, &result_caret_count, caret_array); + if (result) + { + if (caret_count) *caret_count = result_caret_count; + } + else + result = font->face->table.lcar->get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); + return result; } diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 947832b81..4c329408f 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -74,6 +74,7 @@ endif TEST_PROGS += \ test-ot-color \ + test-ot-ligature-carets \ test-ot-name \ test-ot-tag \ $(NULL) diff --git a/test/api/fonts/lcar.ttf b/test/api/fonts/lcar.ttf new file mode 100644 index 0000000000000000000000000000000000000000..4d176636ec64de94fb6fce55c8c7469d6879c262 GIT binary patch literal 808 zcmdr~yG{Z@6g@lpki}<#Hd0V%M|=>qFeZZ0R*0`wS3oggfdD2HnD7A>78VvHSQu-5 zfR4ggSy)(5_zeb)v02Z|YNCl>;GNui&pC5v=I+fVcXpDn(SVMzDMCWI6%SA#T!_aumkTf-l66^r@U%t;MU$S3G|}exFY}WpQh?06jz= za-CWUnG_-3=~lsUv&L@thWFRWYo%hP>a`Ff?~_MV8*HWBxOVqPS6-o+J?f}Ww;M7) z*#pCX_hxqkN2EH0RB1e8cbV_(t`^mz#Oj08o*&5BM}|bO<^m>$w7%BI2VyFNn26g! zOSjBHAq>|3x+Sr`wt+ac^!Ho9^Qz`~o_w8Jf(vF(cJLpT8l2#iS=EP literal 0 HcmV?d00001 diff --git a/test/api/test-ot-ligature-carets.c b/test/api/test-ot-ligature-carets.c new file mode 100644 index 000000000..d84278513 --- /dev/null +++ b/test/api/test-ot-ligature-carets.c @@ -0,0 +1,67 @@ +/* + * Copyright © 2018 Ebrahim Byagowi + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#include "hb-test.h" + +#include + +static void +test_ot_layout_feature_get_name_ids_and_characters (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/lcar.ttf"); + hb_font_t *font = hb_font_create (face); + hb_font_set_scale (font, hb_face_get_upem (face) * 2, hb_face_get_upem (face) * 4); + + hb_position_t caret_array[2]; + unsigned int caret_count = 2; + g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_RTL, + 98, 0, &caret_count, + caret_array)); + + g_assert_cmpuint (2, ==, caret_count); + g_assert_cmpuint (1130, ==, caret_array[0]); + g_assert_cmpuint (2344, ==, caret_array[1]); + + g_assert_cmpuint (2, ==, hb_ot_layout_get_ligature_carets (font, HB_DIRECTION_BTT, + 98, 0, &caret_count, + caret_array)); + + g_assert_cmpuint (2, ==, caret_count); + g_assert_cmpuint (2260, ==, caret_array[0]); + g_assert_cmpuint (4688, ==, caret_array[1]); + + hb_font_destroy (font); + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + g_test_init (&argc, &argv, NULL); + + hb_test_add (test_ot_layout_feature_get_name_ids_and_characters); + + return hb_test_run (); +} From 5f97fe9956274d9de4e7813d7f2e850d9ffd8224 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 9 Nov 2018 10:01:50 -0500 Subject: [PATCH 05/17] Fix a few MSVC 2008 warnings https://github.com/harfbuzz/harfbuzz/issues/1374 --- src/hb-set.hh | 4 ++-- src/hb-vector.hh | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hb-set.hh b/src/hb-set.hh index 21a22525f..c47f77b70 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -375,8 +375,8 @@ struct hb_set_t if (!resize (count)) return; population = other->population; - memcpy (pages, other->pages, count * sizeof (pages[0])); - memcpy (page_map, other->page_map, count * sizeof (page_map[0])); + memcpy (pages, other->pages, count * pages.item_size); + memcpy (page_map, other->page_map, count * page_map.item_size); } inline bool is_equal (const hb_set_t *other) const diff --git a/src/hb-vector.hh b/src/hb-vector.hh index fe06addf7..7056a5b54 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -34,6 +34,9 @@ template struct hb_vector_t { + typedef Type ItemType; + enum { item_size = sizeof (Type) }; + HB_NO_COPY_ASSIGN_TEMPLATE2 (hb_vector_t, Type, StaticSize); inline hb_vector_t (void) { init (); } inline ~hb_vector_t (void) { fini (); } From 6b8178c6499f8d0ee45a57332af778af0e48d1b5 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sat, 10 Nov 2018 02:42:08 +0330 Subject: [PATCH 06/17] [glyf] minor --- src/hb-ot-glyf-table.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index d2a39f230..0623be892 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -149,7 +149,7 @@ struct glyf }; HBUINT16 flags; - HBUINT16 glyphIndex; + GlyphID glyphIndex; inline unsigned int get_size (void) const { From e26e6dbb336e48a5898738dbbd9e56e3a00b7bed Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 00:19:50 -0500 Subject: [PATCH 07/17] [post] Remove unnecessary hb_nonnull_ptr_t<> --- src/hb-ot-post-table.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 18f9976bc..b7913773e 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -259,7 +259,7 @@ struct post private: hb_blob_t *blob; uint32_t version; - hb_nonnull_ptr_t > glyphNameIndex; + const ArrayOf *glyphNameIndex; hb_vector_t index_to_offset; const uint8_t *pool; hb_atomic_ptr_t gids_sorted_by_name; From 4111c3b8cd1b1c44f722877614ec1ee25111e78c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 00:26:36 -0500 Subject: [PATCH 08/17] [post] Move sanitize close to data fields --- src/hb-ot-post-table.hh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index b7913773e..bbde8d83b 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -73,19 +73,6 @@ struct post { static const hb_tag_t tableTag = HB_OT_TAG_post; - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - if (unlikely (!c->check_struct (this))) - return_trace (false); - if (version.to_int () == 0x00020000) - { - const postV2Tail &v2 = StructAfter (*this); - return_trace (v2.sanitize (c)); - } - return_trace (true); - } - inline bool subset (hb_subset_plan_t *plan) const { unsigned int post_prime_length; @@ -265,6 +252,19 @@ struct post hb_atomic_ptr_t gids_sorted_by_name; }; + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + if (unlikely (!c->check_struct (this))) + return_trace (false); + if (version.to_int () == 0x00020000) + { + const postV2Tail &v2 = StructAfter (*this); + return_trace (v2.sanitize (c)); + } + return_trace (true); + } + public: FixedVersion<>version; /* 0x00010000 for version 1.0 * 0x00020000 for version 2.0 From b308aaccf0773e252880b9b887f3d3d1dec00168 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 00:37:17 -0500 Subject: [PATCH 09/17] [post] Minor --- src/hb-ot-post-table.hh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index bbde8d83b..77eef3f5c 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -77,11 +77,11 @@ struct post { unsigned int post_prime_length; hb_blob_t *post_blob = hb_sanitize_context_t().reference_table(plan->source); - hb_blob_t *post_prime_blob = hb_blob_create_sub_blob (post_blob, 0, post::static_size); + hb_blob_t *post_prime_blob = hb_blob_create_sub_blob (post_blob, 0, post::min_size); post *post_prime = (post *) hb_blob_get_data_writable (post_prime_blob, &post_prime_length); hb_blob_destroy (post_blob); - if (unlikely (!post_prime || post_prime_length != post::static_size)) + if (unlikely (!post_prime || post_prime_length != post::min_size)) { hb_blob_destroy (post_prime_blob); DEBUG_MSG(SUBSET, nullptr, "Invalid source post table with length %d.", post_prime_length); @@ -109,7 +109,7 @@ struct post if (version != 0x00020000) return; - const postV2Tail &v2 = StructAfter (*table); + const postV2Tail &v2 = table->v2; glyphNameIndex = &v2.glyphNameIndex; pool = &StructAfter (v2.glyphNameIndex); @@ -255,14 +255,10 @@ struct post inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!c->check_struct (this))) - return_trace (false); - if (version.to_int () == 0x00020000) - { - const postV2Tail &v2 = StructAfter (*this); - return_trace (v2.sanitize (c)); - } - return_trace (true); + return_trace (likely (c->check_struct (this) && + (version.to_int () == 0x00010000 || + (version.to_int () == 0x00020000 && v2.sanitize (c)) || + version.to_int () == 0x00030000))); } public: @@ -297,8 +293,8 @@ struct post * is downloaded as a Type 1 font. */ HBUINT32 maxMemType1; /* Maximum memory usage when an OpenType font * is downloaded as a Type 1 font. */ -/*postV2Tail v2[VAR];*/ - DEFINE_SIZE_STATIC (32); + postV2Tail v2; + DEFINE_SIZE_MIN (32); }; struct post_accelerator_t : post::accelerator_t {}; From 3a9fa8c026bf28bf87e20ec95327f74fd7070b74 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 01:56:37 -0500 Subject: [PATCH 10/17] [qsort] Fix O(N^2) behavior if all array elements are the same Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11327 Reported as https://github.com/noporpoise/sort_r/issues/7 --- src/hb-dsalgs.hh | 15 +++++++++++---- ...e-minimized-hb-shape-fuzzer-5634443633491968 | Bin 0 -> 41814 bytes 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634443633491968 diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 9ccd7f255..ffa438704 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -356,7 +356,12 @@ hb_bsearch_r (const void *key, const void *base, } -/* From https://github.com/noporpoise/sort_r */ +/* From https://github.com/noporpoise/sort_r + * With following modifications: + * + * 10 November 2018: + * https://github.com/noporpoise/sort_r/issues/7 + */ /* Isaac Turner 29 April 2014 Public Domain */ @@ -412,7 +417,7 @@ static inline void sort_r_simple(void *base, size_t nel, size_t w, /* Use median of first, middle and last items as pivot */ char *x, *y, *xend, ch; - char *pl, *pr; + char *pl, *pm, *pr; char *last = b+w*(nel-1), *tmp; char *l[3]; l[0] = b; @@ -434,13 +439,15 @@ static inline void sort_r_simple(void *base, size_t nel, size_t w, pr = last; while(pl < pr) { - for(; pl < pr; pl += w) { + pm = pl+((pr-pl+1)>>1); + for(; pl < pm; pl += w) { if(sort_r_cmpswap(pl, pr, w, compar, arg)) { pr -= w; /* pivot now at pl */ break; } } - for(; pl < pr; pr -= w) { + pm = pl+((pr-pl)>>1); + for(; pm < pr; pr -= w) { if(sort_r_cmpswap(pl, pr, w, compar, arg)) { pl += w; /* pivot now at pr */ break; diff --git a/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634443633491968 b/test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-shape-fuzzer-5634443633491968 new file mode 100644 index 0000000000000000000000000000000000000000..c63bcc582f186d12048b84c1413c20ae14a4daad GIT binary patch literal 41814 zcmeI)+iM(U7{~G7>}+h~p{^)+K*E5Uq%~|)yYZRHZbQ>lOCV6o_YLpNJkNWW_x-$k zlZ#zBlDw=G7t6;=;ls7>C1=*MYn7(o(YpS$_*;v|YmNR}op0W?Hs^1v_l1F9Eqs09 zQ)~M%Ns?-4i35|lFD$-f_0g~y_eSgb%KCn8aiP(!_&TRgEdJf%+nau`qpn`C_yLQ( zW;^P6r<`-r$eP6;wftsq6PqU7ypK#$3-b4{kLLuK8^4ye5WY zavFPIw^?g-(8JBW>geMU9n5{0TeaN6*4=qsC1)z_Gh!rJ84MWSRu)dZq&ayCUC-8V z-qw8H+8kSBwx79)&kjm&2T|{kZQ5EUk8R4i|Iqw}Vv?jAeD<_#y!4vYtXTK7SdY?n zk6~(NJ2hvyN3y&gx7(TuwxKgd@uj^ueYW@gQn1vpo+;Q<7ANohk?2i}?$ATdD{|%J zM|H3APWO1b(~s)4Fdjeam5MV@c`L1YrCklCyc4a;(dD2UpIls8T@LF}+>gU32$q7{ zdc%))Y4NV#G(Bi4``t?Dd%4Kp2%^x}akbS^Uy-wgk>r^s%4A2vdfayntjll@@=B6bgYwFw3bziLz^J7sryz#dkXB&yE3YAq4 z%IO_bmTls$tu(Z|r}?KNyKmU5qb!piR(d!}evqEbp02*QdR_~b+Uj*Z_+EM>Hx57l zU+^<~fxm`ubxG#F4L`mUe!`CHno+~!DjeQMp2Xavo6 zoc$lY|L@}s2q1s}0tg_000IagfB*srAb Date: Sat, 10 Nov 2018 18:08:11 +0330 Subject: [PATCH 11/17] [colr/feat/trak] minor --- src/hb-aat-layout-feat-table.hh | 14 ++++++------- src/hb-aat-layout-trak-table.hh | 35 ++++++++++++++++++--------------- src/hb-ot-color-colr-table.hh | 18 ++++++----------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/hb-aat-layout-feat-table.hh b/src/hb-aat-layout-feat-table.hh index b670caab8..87ab4abd3 100644 --- a/src/hb-aat-layout-feat-table.hh +++ b/src/hb-aat-layout-feat-table.hh @@ -54,13 +54,6 @@ struct SettingName struct FeatureName { - inline bool sanitize (hb_sanitize_context_t *c, const void *base) const - { - TRACE_SANITIZE (this); - return_trace (likely (c->check_struct (this) && - (base+settingTable).sanitize (c, nSettings))); - } - enum { Exclusive = 0x8000, /* If set, the feature settings are mutually exclusive. */ NotDefault = 0x4000, /* If clear, then the setting with an index of 0 in @@ -75,6 +68,13 @@ struct FeatureName * as the default. */ }; + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + return_trace (likely (c->check_struct (this) && + (base+settingTable).sanitize (c, nSettings))); + } + protected: HBUINT16 feature; /* Feature type. */ HBUINT16 nSettings; /* The number of records in the setting name array. */ diff --git a/src/hb-aat-layout-trak-table.hh b/src/hb-aat-layout-trak-table.hh index 68218ecb7..3b55967c8 100644 --- a/src/hb-aat-layout-trak-table.hh +++ b/src/hb-aat-layout-trak-table.hh @@ -171,15 +171,6 @@ struct trak inline bool has_data (void) const { return version.to_int () != 0; } - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - - return_trace (likely (c->check_struct (this) && - horizData.sanitize (c, this, this) && - vertData.sanitize (c, this, this))); - } - inline bool apply (hb_aat_apply_context_t *c) const { TRACE_APPLY (this); @@ -221,15 +212,27 @@ struct trak return_trace (true); } + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + + return_trace (likely (c->check_struct (this) && + version.major == 1 && + horizData.sanitize (c, this, this) && + vertData.sanitize (c, this, this))); + } + protected: - FixedVersion<> version; /* Version of the tracking table + FixedVersion<>version; /* Version of the tracking table * (0x00010000u for version 1.0). */ - HBUINT16 format; /* Format of the tracking table (set to 0). */ - OffsetTo horizData; /* Offset from start of tracking table to TrackData - * for horizontal text (or 0 if none). */ - OffsetTo vertData; /* Offset from start of tracking table to TrackData - * for vertical text (or 0 if none). */ - HBUINT16 reserved; /* Reserved. Set to 0. */ + HBUINT16 format; /* Format of the tracking table (set to 0). */ + OffsetTo + horizData; /* Offset from start of tracking table to TrackData + * for horizontal text (or 0 if none). */ + OffsetTo + vertData; /* Offset from start of tracking table to TrackData + * for vertical text (or 0 if none). */ + HBUINT16 reserved; /* Reserved. Set to 0. */ public: DEFINE_SIZE_STATIC (12); diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index b480af51d..fa40223b7 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -103,7 +103,12 @@ struct COLR unsigned int *count, /* IN/OUT. May be NULL. */ hb_ot_color_layer_t *layers /* OUT. May be NULL. */) const { - const BaseGlyphRecord &record = get_glyph_record (glyph); + const BaseGlyphRecord *rec = (BaseGlyphRecord *) bsearch (&glyph, + &(this+baseGlyphsZ), + numBaseGlyphs, + sizeof (BaseGlyphRecord), + BaseGlyphRecord::cmp); + const BaseGlyphRecord &record = rec ? *rec : Null (BaseGlyphRecord); hb_array_t all_layers ((this+layersZ).arrayZ, numLayers); hb_array_t glyph_layers = all_layers.sub_array (record.firstLayerIdx, @@ -129,17 +134,6 @@ struct COLR (this+layersZ).sanitize (c, numLayers))); } - private: - inline const BaseGlyphRecord &get_glyph_record (hb_codepoint_t glyph_id) const - { - const BaseGlyphRecord *rec = (BaseGlyphRecord *) bsearch (&glyph_id, - &(this+baseGlyphsZ), - numBaseGlyphs, - sizeof (BaseGlyphRecord), - BaseGlyphRecord::cmp); - return rec ? *rec : Null(BaseGlyphRecord); - } - protected: HBUINT16 version; /* Table version number (starts at 0). */ HBUINT16 numBaseGlyphs; /* Number of Base Glyph Records. */ From 929f07dbfc8b8c40771d27a502f6e5842c1c1e90 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 15:38:48 -0500 Subject: [PATCH 12/17] Fix hb_bytes_t.cmp() Ouch! --- src/hb-dsalgs.hh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index ffa438704..e98566e75 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -530,10 +530,12 @@ struct hb_bytes_t inline int cmp (const hb_bytes_t &a) const { - if (len != a.len) - return (int) a.len - (int) len; + if (!len) return 0; /* glibc's memcmp() args are declared nonnull. Meh. */ - return memcmp (a.arrayZ, arrayZ, len); + int r = memcmp (a.arrayZ, arrayZ, len); + if (r) return r; + + return a.len < len ? -1 : a.len > len ? +1 : 0; } static inline int cmp (const void *pa, const void *pb) { From 534e1d7694c96f61e853daef481b41274d5d16d8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 15:43:16 -0500 Subject: [PATCH 13/17] Fix hb_bytes_t.cmp() for realz this time --- src/hb-dsalgs.hh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index e98566e75..511b2299a 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -530,10 +530,12 @@ struct hb_bytes_t inline int cmp (const hb_bytes_t &a) const { - if (!len) return 0; /* glibc's memcmp() args are declared nonnull. Meh. */ - - int r = memcmp (a.arrayZ, arrayZ, len); - if (r) return r; + unsigned int l = MIN(a.len, len); + if (l) /* glibc's memcmp() args are declared nonnull. Meh. */ + { + int r = memcmp (a.arrayZ, arrayZ, l); + if (r) return r; + } return a.len < len ? -1 : a.len > len ? +1 : 0; } From 8bb97d2ce140b7fe81d0726c32e024d887e0be1c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 15:54:33 -0500 Subject: [PATCH 14/17] Revert back hb_bytes_t.cmp() to the scheme it was But fix UBSan complaint. There's nothing in hb_bytes_t that guarantees lexical ordering, and ordering by length first is much faster. --- src/hb-dsalgs.hh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 511b2299a..ce1342607 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -530,14 +530,13 @@ struct hb_bytes_t inline int cmp (const hb_bytes_t &a) const { - unsigned int l = MIN(a.len, len); - if (l) /* glibc's memcmp() args are declared nonnull. Meh. */ - { - int r = memcmp (a.arrayZ, arrayZ, l); - if (r) return r; - } + if (len != a.len) + return (int) a.len - (int) len; - return a.len < len ? -1 : a.len > len ? +1 : 0; + if (!len) + return 0; /* glibc's memcmp() declares args non-NULL, and UBSan doesn't like that. :( */ + + return memcmp (a.arrayZ, arrayZ, len); } static inline int cmp (const void *pa, const void *pb) { From 6213a75b68825037fbaf6f5ad4eef66e8bad4b3c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 16:09:21 -0500 Subject: [PATCH 15/17] Add trivial casts to hb_bytes_t --- src/hb-dsalgs.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index ce1342607..9b9cb5f42 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -526,6 +526,9 @@ struct hb_bytes_t template inline hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len) {} + inline operator const void * (void) const { return arrayZ; } + inline operator const char * (void) const { return arrayZ; } + inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } inline int cmp (const hb_bytes_t &a) const From f2e942f3023e3c5cb3e732ee7b4782b3df170a85 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 16:11:14 -0500 Subject: [PATCH 16/17] Fix hb_bytes_t's unused template array constructor --- src/hb-dsalgs.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 9b9cb5f42..2540d438b 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -524,7 +524,7 @@ struct hb_bytes_t inline hb_bytes_t (const char *bytes_, unsigned int len_) : arrayZ (bytes_), len (len_) {} inline hb_bytes_t (const void *bytes_, unsigned int len_) : arrayZ ((const char *) bytes_), len (len_) {} template - inline hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len) {} + inline hb_bytes_t (const T& array) : arrayZ ((const char *) array.arrayZ), len (array.len * sizeof (array.arrayZ[0])) {} inline operator const void * (void) const { return arrayZ; } inline operator const char * (void) const { return arrayZ; } From b4c61130324455bfd42095b01fa14ac901e441f1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 10 Nov 2018 16:35:39 -0500 Subject: [PATCH 17/17] Try fixing MSVC 2008 build Fixes https://github.com/harfbuzz/harfbuzz/issues/1374 --- src/hb-open-type.hh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 6d6dd7b27..56fa43345 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -337,8 +337,16 @@ struct UnsizedArrayOf { HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type); - inline const Type& operator [] (unsigned int i) const { return arrayZ[i]; } - inline Type& operator [] (unsigned int i) { return arrayZ[i]; } + /* Unlikely other places, use "int i" instead of "unsigned int i" for our + * indexing operator. For two reasons: + * 1. For UnsizedArrayOf, it's not totally unimaginable to want to look + * at items before the start of current array. + * 2. Fixes MSVC 2008 "overloads have similar conversions" issue with the + * built-in operator [] that takes int, in expressions like sizeof(array[0])). + * I suppose I could fix that by replacing 0 with 0u, but like this fix + * more now. */ + inline const Type& operator [] (int i) const { return arrayZ[i]; } + inline Type& operator [] (int i) { return arrayZ[i]; } template inline operator T * (void) { return arrayZ; } template inline operator const T * (void) const { return arrayZ; }