From 9aa14687129da50db0702787dc9642d395ad1c4c Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 1 Apr 2020 11:00:36 +0000 Subject: [PATCH] Bug 1626550 - Update graphite to version 1.3.14. r=lsalzman Differential Revision: https://phabricator.services.mozilla.com/D69175 --HG-- extra : moz-landing-system : lando --- gfx/graphite2/README.mozilla | 4 ++-- gfx/graphite2/include/graphite2/Font.h | 2 +- gfx/graphite2/src/CMakeLists.txt | 7 ++++-- gfx/graphite2/src/Code.cpp | 32 +++++++++++++++++++++++++- gfx/graphite2/src/Collider.cpp | 4 ++-- gfx/graphite2/src/FeatureMap.cpp | 9 ++++---- gfx/graphite2/src/Pass.cpp | 2 +- gfx/graphite2/src/files.mk | 2 -- gfx/graphite2/src/gr_face.cpp | 17 +++++++++++--- gfx/graphite2/src/gr_slot.cpp | 5 ++-- gfx/graphite2/src/inc/FeatureMap.h | 16 ++++++++----- 11 files changed, 74 insertions(+), 26 deletions(-) diff --git a/gfx/graphite2/README.mozilla b/gfx/graphite2/README.mozilla index ef0aea48e3da..1b9e1e1e1318 100644 --- a/gfx/graphite2/README.mozilla +++ b/gfx/graphite2/README.mozilla @@ -1,3 +1,3 @@ -This directory contains the Graphite2 library release 1.3.13 from -https://github.com/silnrsi/graphite/releases/download/1.3.13/graphite2-minimal-1.3.13.tgz +This directory contains the Graphite2 library release 1.3.14 from +https://github.com/silnrsi/graphite/releases/download/1.3.14/graphite2-minimal-1.3.14.tgz See ./gfx/graphite2/moz-gr-update.sh for update procedure. diff --git a/gfx/graphite2/include/graphite2/Font.h b/gfx/graphite2/include/graphite2/Font.h index 3e8214d46b50..fe569295a53f 100644 --- a/gfx/graphite2/include/graphite2/Font.h +++ b/gfx/graphite2/include/graphite2/Font.h @@ -30,7 +30,7 @@ #define GR2_VERSION_MAJOR 1 #define GR2_VERSION_MINOR 3 -#define GR2_VERSION_BUGFIX 13 +#define GR2_VERSION_BUGFIX 14 #ifdef __cplusplus extern "C" diff --git a/gfx/graphite2/src/CMakeLists.txt b/gfx/graphite2/src/CMakeLists.txt index 389cf5a2389f..b6ac26bfc2f9 100644 --- a/gfx/graphite2/src/CMakeLists.txt +++ b/gfx/graphite2/src/CMakeLists.txt @@ -111,7 +111,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") add_definitions(-mfpmath=sse -msse2) endif() if (CMAKE_COMPILER_IS_GNUCXX) - add_definitions(-Wdouble-promotion) + add_definitions(-Wno-class-memaccess -Wdouble-promotion) endif() message(STATUS "Compiler ID is: ${CMAKE_CXX_COMPILER_ID}") if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") @@ -136,9 +136,12 @@ endif() if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set_target_properties(graphite2 PROPERTIES - COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wimplicit-fallthrough -Wendif-labels -Wshadow -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -mfpmath=sse -msse2" + COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wimplicit-fallthrough -Wendif-labels -Wshadow -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden" LINK_FLAGS "-nodefaultlibs" LINKER_LANGUAGE C) + if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86|i.86") + add_definitions(-mfpmath=sse -msse2) + endif() target_link_libraries(graphite2 c) include(Graphite) nolib_test(stdc++ $) diff --git a/gfx/graphite2/src/Code.cpp b/gfx/graphite2/src/Code.cpp index 5cff6b534ea9..ec5ab298ca4b 100644 --- a/gfx/graphite2/src/Code.cpp +++ b/gfx/graphite2/src/Code.cpp @@ -101,6 +101,7 @@ private: bool valid_upto(const uint16 limit, const uint16 x) const throw(); bool test_context() const throw(); bool test_ref(int8 index) const throw(); + bool test_attr(attrCode attr) const throw(); void failure(const status_t s) const throw() { _code.failure(s); } Code & _code; @@ -381,6 +382,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) valid_upto(gr_slatMax, bc[0]); if (attrCode(bc[0]) == gr_slatUserDefn) // use IATTR for user attributes failure(out_of_range_data); + test_attr(attrCode(bc[0])); test_context(); break; case IATTR_SET_SLOT : @@ -388,6 +390,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) failure(underfull_stack); if (valid_upto(gr_slatMax, bc[0])) valid_upto(_max.attrid[bc[0]], bc[1]); + test_attr(attrCode(bc[0])); test_context(); break; case PUSH_SLOT_ATTR : @@ -396,6 +399,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) test_ref(int8(bc[1])); if (attrCode(bc[0]) == gr_slatUserDefn) // use IATTR for user attributes failure(out_of_range_data); + test_attr(attrCode(bc[0])); break; case PUSH_GLYPH_ATTR_OBS : case PUSH_ATT_TO_GATTR_OBS : @@ -422,6 +426,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) test_ref(int8(bc[1])); valid_upto(_max.attrid[bc[0]], bc[2]); } + test_attr(attrCode(bc[0])); break; case PUSH_IGLYPH_ATTR :// not implemented ++_stack_depth; @@ -441,6 +446,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) failure(underfull_stack); if (valid_upto(gr_slatMax, bc[0])) valid_upto(_max.attrid[bc[0]], bc[1]); + test_attr(attrCode(bc[0])); test_context(); break; case PUSH_PROC_STATE : // dummy: dp[0] no check necessary @@ -681,7 +687,15 @@ bool Machine::Code::decoder::test_ref(int8 index) const throw() } } else - return valid_upto(_max.rule_length, _slotref + _max.pre_context + index); + { + if (_max.rule_length == 0 + || (_slotref + _max.pre_context + index >= _max.rule_length) + || (_slotref + _max.pre_context + index < 0)) + { + failure(out_of_range_data); + return false; + } + } return true; } @@ -695,6 +709,22 @@ bool Machine::Code::decoder::test_context() const throw() return true; } +bool Machine::Code::decoder::test_attr(attrCode) const throw() +{ +#if 0 // This code is coming but causes backward compatibility problems. + if (_passtype < PASS_TYPE_POSITIONING) + { + if (attr != gr_slatBreak && attr != gr_slatDir && attr != gr_slatUserDefn + && attr != gr_slatCompRef) + { + failure(out_of_range_data); + return false; + } + } +#endif + return true; +} + inline void Machine::Code::failure(const status_t s) throw() { release_buffers(); diff --git a/gfx/graphite2/src/Collider.cpp b/gfx/graphite2/src/Collider.cpp index 6b20a91c9bc0..1929b39a58e7 100644 --- a/gfx/graphite2/src/Collider.cpp +++ b/gfx/graphite2/src/Collider.cpp @@ -1081,8 +1081,8 @@ void SlotCollision::initFromSlot(Segment *seg, Slot *slot) return; const sparse &p = glyphFace->attrs(); _flags = p[aCol]; - _limit = Rect(Position(p[aCol+1], p[aCol+2]), - Position(p[aCol+3], p[aCol+4])); + _limit = Rect(Position(int16(p[aCol+1]), int16(p[aCol+2])), + Position(int16(p[aCol+3]), int16(p[aCol+4]))); _margin = p[aCol+5]; _marginWt = p[aCol+6]; diff --git a/gfx/graphite2/src/FeatureMap.cpp b/gfx/graphite2/src/FeatureMap.cpp index e63415dd1c80..014a88fd08e0 100644 --- a/gfx/graphite2/src/FeatureMap.cpp +++ b/gfx/graphite2/src/FeatureMap.cpp @@ -71,7 +71,7 @@ namespace FeatureRef::FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, - uint32 name, uint16 uiName, uint16 flags, + uint32 name, uint16 uiName, flags_t flags, FeatureSetting *settings, uint16 num_set) throw() : m_face(&face), m_nameValues(settings), @@ -79,8 +79,8 @@ FeatureRef::FeatureRef(const Face & face, m_max(max_val), m_id(name), m_nameid(uiName), - m_flags(flags), - m_numSet(num_set) + m_numSet(num_set), + m_flags(flags) { const uint8 need_bits = bit_set_count(m_mask); m_index = (bits_offset + need_bits) / SIZEOF_CHUNK; @@ -163,7 +163,8 @@ bool FeatureMap::readFeats(const Face & face) } ::new (m_feats + i) FeatureRef (face, bits, maxVal, - label, uiName, flags, + label, uiName, + FeatureRef::flags_t(flags), uiSet, num_settings); } new (&m_defaultFeatures) Features(bits/(sizeof(uint32)*8) + 1, *this); diff --git a/gfx/graphite2/src/Pass.cpp b/gfx/graphite2/src/Pass.cpp index 76d4983aee56..db31c22d46b8 100644 --- a/gfx/graphite2/src/Pass.cpp +++ b/gfx/graphite2/src/Pass.cpp @@ -704,7 +704,7 @@ void Pass::adjustSlot(int delta, Slot * & slot_out, SlotMap & smap) const { slot_out = smap.segment.last(); ++delta; - if (!smap.highwater()) + if (!smap.highwater() || smap.highwater() == slot_out) smap.highpassed(false); } else diff --git a/gfx/graphite2/src/files.mk b/gfx/graphite2/src/files.mk index 15ebb2ef0d19..63063567bf73 100644 --- a/gfx/graphite2/src/files.mk +++ b/gfx/graphite2/src/files.mk @@ -47,7 +47,6 @@ $(_NS)_SOURCES = \ $($(_NS)_BASE)/src/gr_segment.cpp \ $($(_NS)_BASE)/src/gr_slot.cpp \ $($(_NS)_BASE)/src/json.cpp \ - $($(_NS)_BASE)/src/CachedFace.cpp \ $($(_NS)_BASE)/src/CmapCache.cpp \ $($(_NS)_BASE)/src/Code.cpp \ $($(_NS)_BASE)/src/Collider.cpp \ @@ -74,7 +73,6 @@ $(_NS)_PRIVATE_HEADERS = \ $($(_NS)_BASE)/src/inc/bits.h \ $($(_NS)_BASE)/src/inc/debug.h \ $($(_NS)_BASE)/src/inc/json.h \ - $($(_NS)_BASE)/src/inc/CachedFace.h \ $($(_NS)_BASE)/src/inc/CharInfo.h \ $($(_NS)_BASE)/src/inc/CmapCache.h \ $($(_NS)_BASE)/src/inc/Code.h \ diff --git a/gfx/graphite2/src/gr_face.cpp b/gfx/graphite2/src/gr_face.cpp index 712aa115fa71..baa469727bbc 100644 --- a/gfx/graphite2/src/gr_face.cpp +++ b/gfx/graphite2/src/gr_face.cpp @@ -163,14 +163,25 @@ const gr_feature_ref* gr_face_find_fref(const gr_face* pFace, gr_uint32 featId) unsigned short gr_face_n_fref(const gr_face* pFace) { assert(pFace); - return pFace->numFeatures(); + int res = 0; + for (int i = 0; i < pFace->numFeatures(); ++i) + if (!(pFace->feature(i)->getFlags() & FeatureRef::HIDDEN)) + ++res; + return res; } const gr_feature_ref* gr_face_fref(const gr_face* pFace, gr_uint16 i) //When finished with the FeatureRef, call destroy_FeatureRef { assert(pFace); - const FeatureRef* pRef = pFace->feature(i); - return static_cast(pRef); + int count = 0; + for (int j = 0; j < pFace->numFeatures(); ++j) + { + const FeatureRef* pRef = pFace->feature(j); + if (!(pRef->getFlags() & FeatureRef::HIDDEN)) + if (count++ == i) + return static_cast(pRef); + } + return 0; } unsigned short gr_face_n_languages(const gr_face* pFace) diff --git a/gfx/graphite2/src/gr_slot.cpp b/gfx/graphite2/src/gr_slot.cpp index 21a00fdcd512..a3c6b46a7f4d 100644 --- a/gfx/graphite2/src/gr_slot.cpp +++ b/gfx/graphite2/src/gr_slot.cpp @@ -95,8 +95,9 @@ float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const if (font) { scale = font->scale(); - if (face && font->isHinted()) - res = (res - face->glyphs().glyph(p->gid())->theAdvance().x) * scale + font->advance(p->gid()); + int gid = p->glyph(); + if (face && font->isHinted() && gid < face->glyphs().numGlyphs()) + res = (res - face->glyphs().glyph(gid)->theAdvance().x) * scale + font->advance(gid); else res = res * scale; } diff --git a/gfx/graphite2/src/inc/FeatureMap.h b/gfx/graphite2/src/inc/FeatureMap.h index 142a00e7e9f3..0f05e941a27d 100644 --- a/gfx/graphite2/src/inc/FeatureMap.h +++ b/gfx/graphite2/src/inc/FeatureMap.h @@ -56,9 +56,12 @@ class FeatureRef static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8; public: + enum flags_t : uint16 { + HIDDEN = 0x0800 + }; FeatureRef() throw(); FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, - uint32 name, uint16 uiName, uint16 flags, + uint32 name, uint16 uiName, flags_t flags, FeatureSetting *settings, uint16 num_set) throw(); ~FeatureRef() throw(); @@ -75,6 +78,7 @@ public: uint16 getNumSettings() const { return m_numSet; } uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); } int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); } + flags_t getFlags() const { return m_flags; } uint32 maxVal() const { return m_max; } const Face & getFace() const { assert(m_face); return *m_face;} const FeatureMap* getFeatureMap() const;// { return m_pFace;} @@ -88,9 +92,9 @@ private: chunk_t m_mask, // bit mask to get the value from the vector m_max; // max value the value can take uint32 m_id; // feature identifier/name - uint16 m_nameid, // Name table id for feature name - m_flags, // feature flags (unused at the moment but read from the font) - m_numSet; // number of values (number of entries in m_nameValues) + uint16 m_nameid, // Name table id for feature name + m_numSet; // number of values (number of entries in m_nameValues) + flags_t m_flags; // feature flags see FeatureRef::flags_t. byte m_bits, // how many bits to shift the value into place m_index; // index into the array to find the ulong to mask @@ -103,8 +107,8 @@ FeatureRef::FeatureRef() throw() : m_face(0), m_nameValues(0), m_mask(0), m_max(0), - m_id(0), - m_nameid(0), m_flags(0), m_numSet(0), + m_id(0), m_nameid(0), m_numSet(0), + m_flags(flags_t(0)), m_bits(0), m_index(0) { }