diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-03-31 06:19:10 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2016-03-31 06:19:10 +0000 |
commit | 87e19428d83034111980b20ffb3289bf433f98e9 (patch) | |
tree | 64451b09f1ca2788d616db1b3f374869e9863517 /Build/source/libs/graphite2/graphite2-src | |
parent | dfc8229942ebce9588f66dfb359c072117b78562 (diff) |
graphite2 1.3.8
git-svn-id: svn://tug.org/texlive/trunk@40193 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/graphite2/graphite2-src')
10 files changed, 71 insertions, 39 deletions
diff --git a/Build/source/libs/graphite2/graphite2-src/ChangeLog b/Build/source/libs/graphite2/graphite2-src/ChangeLog index e2157225a71..d55a2ab2724 100644 --- a/Build/source/libs/graphite2/graphite2-src/ChangeLog +++ b/Build/source/libs/graphite2/graphite2-src/ChangeLog @@ -1,3 +1,9 @@ +1.3.8 + . Various bug fixes arising from fuzzing + . Fix regression that stopped piglatin from working + . Make collision avoidance kerning give more regular results + . Minor modification to clustering algorithm to handle variable width chars + 1.3.7 . Bug fixes . Start to deprecate SegCache. This will be going away in a later release. diff --git a/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h b/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h index 866294da9f1..1f2ca4eaff7 100644 --- a/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h +++ b/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h @@ -30,7 +30,7 @@ #define GR2_VERSION_MAJOR 1 #define GR2_VERSION_MINOR 3 -#define GR2_VERSION_BUGFIX 7 +#define GR2_VERSION_BUGFIX 8 #ifdef __cplusplus extern "C" diff --git a/Build/source/libs/graphite2/graphite2-src/src/Code.cpp b/Build/source/libs/graphite2/graphite2-src/src/Code.cpp index 247a0529cfa..92ba92379cb 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Code.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Code.cpp @@ -97,7 +97,7 @@ private: opcode fetch_opcode(const byte * bc); void analyse_opcode(const opcode, const int8 * const dp) throw(); bool emit_opcode(opcode opc, const byte * & bc); - bool validate_opcode(const opcode opc, const byte * const bc); + bool validate_opcode(const byte opc, const byte * const bc); bool valid_upto(const uint16 limit, const uint16 x) const throw(); bool test_context() const throw(); bool test_ref(int8 index) const throw(); @@ -266,13 +266,13 @@ bool Machine::Code::decoder::load(const byte * bc, const byte * bc_end) opcode Machine::Code::decoder::fetch_opcode(const byte * bc) { - const opcode opc = opcode(*bc++); + const byte opc = *bc++; // Do some basic sanity checks based on what we know about the opcode if (!validate_opcode(opc, bc)) return MAX_OPCODE; // And check it's arguments as far as possible - switch (opc) + switch (opcode(opc)) { case NOP : break; @@ -470,7 +470,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) break; } - return bool(_code) ? opc : MAX_OPCODE; + return bool(_code) ? opcode(opc) : MAX_OPCODE; } @@ -572,6 +572,7 @@ bool Machine::Code::decoder::emit_opcode(opcode opc, const byte * & bc) assert(_out_index == 0); _in_ctxt_item = true; _out_index = _max.pre_context + int8(_data[-2]); + _slotref = int8(_data[-2]); _out_length = _max.rule_length; const size_t ctxt_start = _code._instr_count; @@ -589,11 +590,13 @@ bool Machine::Code::decoder::emit_opcode(opcode opc, const byte * & bc) _out_length = 1; _out_index = 0; + _slotref = 0; _in_ctxt_item = false; } else { _out_index = 0; + _slotref = 0; return false; } } @@ -626,7 +629,7 @@ void Machine::Code::decoder::apply_analysis(instr * const code, instr * code_end inline -bool Machine::Code::decoder::validate_opcode(const opcode opc, const byte * const bc) +bool Machine::Code::decoder::validate_opcode(const byte opc, const byte * const bc) { if (opc >= MAX_OPCODE) { @@ -664,7 +667,17 @@ bool Machine::Code::decoder::valid_upto(const uint16 limit, const uint16 x) cons inline bool Machine::Code::decoder::test_ref(int8 index) const throw() { - return valid_upto(_max.rule_length, _slotref + _max.pre_context + index); + if (_code._constraint && !_in_ctxt_item) + { + if (index > 0 || -index > _max.pre_context) + { + failure(out_of_range_data); + return false; + } + } + else + return valid_upto(_max.rule_length, _slotref + _max.pre_context + index); + return true; } bool Machine::Code::decoder::test_context() const throw() diff --git a/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp b/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp index 591b01ebe90..2df46ebc4de 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp @@ -829,9 +829,9 @@ bool KernCollider::initSlot(Segment *seg, Slot *aSlot, const Rect &limit, float // Calculate the height of the glyph and how many horizontal slices to use. if (_maxy >= 1e37f) { - _maxy = ymax; - _miny = ymin; _sliceWidth = margin / 1.5f; + _maxy = ymax + margin; + _miny = ymin - margin; numSlices = int((_maxy - _miny + 2) / (_sliceWidth / 1.5f) + 1.f); // +2 helps with rounding errors _edges.clear(); _edges.insert(_edges.begin(), numSlices, (dir & 1) ? 1e38f : -1e38f); @@ -841,7 +841,7 @@ bool KernCollider::initSlot(Segment *seg, Slot *aSlot, const Rect &limit, float { if (_miny != ymin) { - numSlices = int((ymin - _miny) / _sliceWidth - 1); + numSlices = int((ymin - margin - _miny) / _sliceWidth - 1); _miny += numSlices * _sliceWidth; if (numSlices < 0) _edges.insert(_edges.begin(), -numSlices, (dir & 1) ? 1e38f : -1e38f); @@ -855,7 +855,7 @@ bool KernCollider::initSlot(Segment *seg, Slot *aSlot, const Rect &limit, float } if (_maxy != ymax) { - numSlices = int((ymax - _miny) / _sliceWidth + 1); + numSlices = int((ymax + margin - _miny) / _sliceWidth + 1); _maxy = numSlices * _sliceWidth + _miny; if (numSlices > (int)_edges.size()) _edges.insert(_edges.end(), numSlices - _edges.size(), (dir & 1) ? 1e38f : -1e38f); @@ -935,28 +935,33 @@ bool KernCollider::mergeSlot(Segment *seg, Slot *slot, const Position &currShift return false; const Rect &bb = seg->theGlyphBBoxTemporary(slot->gid()); const float sx = slot->origin().x + currShift.x; - float x = sx + (rtl > 0 ? bb.tr.x : bb.bl.x); + float x = (sx + (rtl > 0 ? bb.tr.x : bb.bl.x)) * rtl; // this isn't going to reduce _mingap so skip - if ((rtl > 0 && x < _xbound - _mingap - currSpace) || (rtl <= 0 && x > _xbound + _mingap + currSpace)) + if (x < rtl * (_xbound - _mingap - currSpace)) return false; const float sy = slot->origin().y + currShift.y; - int smin = max(0, int((bb.bl.y + (1 - _miny + sy)) / _sliceWidth + 1)); - int smax = min((int)_edges.size() - 1, int((bb.tr.y + (1 - _miny + sy)) / _sliceWidth + 1)); + int smin = max(1, int((bb.bl.y + (1 - _miny + sy)) / _sliceWidth + 1)) - 1; + int smax = min((int)_edges.size() - 2, int((bb.tr.y + (1 - _miny + sy)) / _sliceWidth + 1)) + 1; + if (smin > smax) + return false; bool collides = false; + float below = smin > 0 ? _edges[smin-1] * rtl : 1e38f; + float here = _edges[smin] * rtl; + float above = smin < (int)_edges.size() - 1 ? _edges[smin+1] * rtl : 1e38f; for (int i = smin; i <= smax; ++i) { float t; float y = (float)(_miny - 1 + (i + .5f) * _sliceWidth); // vertical center of slice - if (x * rtl > _edges[i] * rtl - _mingap - currSpace) + if ( (x > here - _mingap - currSpace) + || (x > below - _mingap - currSpace) + || (x > above - _mingap - currSpace)) { // 2 * currSpace to account for the space that is already separating them and the space we want to add - float m = get_edge(seg, slot, currShift, y, _sliceWidth, rtl > 0) + 2 * rtl * currSpace; - t = rtl * (_edges[i] - m); + float m = get_edge(seg, slot, currShift, y, _sliceWidth, rtl > 0) * rtl + 2 * currSpace; // Check slices above and below (if any). - if (i < (int)_edges.size() - 1) t = min(t, rtl * (_edges[i+1] - m)); - if (i > 0) t = min(t, rtl * (_edges[i-1] - m)); + t = min(min(here, below), above) - m; // _mingap is positive to shrink if (t < _mingap) { @@ -965,13 +970,15 @@ bool KernCollider::mergeSlot(Segment *seg, Slot *slot, const Position &currShift } #if !defined GRAPHITE2_NTRACING // Debugging - remember the closest neighboring edge for this slice. - if (rtl * m > rtl * _nearEdges[i]) + if (m > rtl * _nearEdges[i]) { _slotNear[i] = slot; - _nearEdges[i] = m; + _nearEdges[i] = m * rtl; } #endif } + below = here; here = above; + above = i < (int)_edges.size() - 2 ? _edges[i+2] * rtl : 1e38f; } return collides; // note that true is not a necessarily reliable value diff --git a/Build/source/libs/graphite2/graphite2-src/src/GlyphCache.cpp b/Build/source/libs/graphite2/graphite2-src/src/GlyphCache.cpp index ae9035d1d4b..b521d5e5a93 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/GlyphCache.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/GlyphCache.cpp @@ -211,6 +211,8 @@ GlyphCache::~GlyphCache() const GlyphFace *GlyphCache::glyph(unsigned short glyphid) const //result may be changed by subsequent call with a different glyphid { + if (glyphid >= numGlyphs()) + return _glyphs[0]; const GlyphFace * & p = _glyphs[glyphid]; if (p == 0 && _glyph_loader) { @@ -389,12 +391,14 @@ const GlyphFace * GlyphCache::Loader::read_glyph(unsigned short glyphid, GlyphFa gloce = be::peek<uint16>(gloc); } - if (glocs + 1 >= m_pGlat.size() || gloce > m_pGlat.size()) + if (glocs >= m_pGlat.size() - 1 || gloce > m_pGlat.size()) return 0; const uint32 glat_version = be::peek<uint32>(m_pGlat); if (glat_version >= 0x00030000) { + if (glocs >= gloce) + return 0; const byte * p = m_pGlat + glocs; uint16 bmap = be::read<uint16>(p); int num = bit_set_count((uint32)bmap); diff --git a/Build/source/libs/graphite2/graphite2-src/src/Justifier.cpp b/Build/source/libs/graphite2/graphite2-src/src/Justifier.cpp index e40e0290216..f8a6f3bbebb 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Justifier.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Justifier.cpp @@ -100,7 +100,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS int numLevels = silf()->numJustLevels(); if (!numLevels) { - for (s = pSlot; s != end; s = s->next()) + for (s = pSlot; s && s != end; s = s->nextSibling()) { CharInfo *c = charinfo(s->before()); if (isWhitespace(c->unicodeChar())) @@ -113,7 +113,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS } if (!icount) { - for (s = pSlot; s != end; s = s->nextSibling()) + for (s = pSlot; s && s != end; s = s->nextSibling()) { s->setJustify(this, 0, 3, 1); s->setJustify(this, 0, 2, 1); @@ -124,7 +124,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS } Vector<JustifyTotal> stats(numLevels); - for (s = pFirst; s != end; s = s->nextSibling()) + for (s = pFirst; s && s != end; s = s->nextSibling()) { float w = s->origin().x / scale + s->advance() - base; if (w > currWidth) currWidth = w; @@ -139,13 +139,14 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS float error = 0.; float diffpw; int tWeight = stats[i].weight(); + if (tWeight == 0) continue; do { error = 0.; diff = width - currWidth; diffpw = diff / tWeight; tWeight = 0; - for (s = pFirst; s != end; s = s->nextSibling()) // don't include final glyph + for (s = pFirst; s && s != end; s = s->nextSibling()) // don't include final glyph { int w = s->getJustify(this, i, 3); float pref = diffpw * w + error; diff --git a/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp b/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp index 6f6b91331f5..7289406c092 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp @@ -339,7 +339,7 @@ bool Pass::readStates(const byte * starts, const byte *states, const byte * o_ru *t = be::read<uint16>(states); if (e.test(*t >= m_numStates, E_BADSTATE)) { - face.error_context((face.error_context() & 0xFFFF00) + EC_ATRANS + (((t - m_transitions) / m_numColumns) << 24)); + face.error_context((face.error_context() & 0xFFFF00) + EC_ATRANS + (((t - m_transitions) / m_numColumns) << 8)); return face.error(e); } } @@ -861,7 +861,6 @@ bool Pass::collisionShift(Segment *seg, int dir, json * const dbgout) const bool Pass::collisionKern(Segment *seg, int dir, json * const dbgout) const { - KernCollider kerncoll(dbgout); Slot *start = seg->first(); float ymin = 1e38f; float ymax = -1e38f; @@ -884,7 +883,7 @@ bool Pass::collisionKern(Segment *seg, int dir, json * const dbgout) const ymin = min(y + bbox.bl.y, ymin); if (start && (c->flags() & (SlotCollision::COLL_KERN | SlotCollision::COLL_FIX)) == (SlotCollision::COLL_KERN | SlotCollision::COLL_FIX)) - resolveKern(seg, s, start, kerncoll, dir, ymin, ymax, dbgout); + resolveKern(seg, s, start, dir, ymin, ymax, dbgout); if (c->flags() & SlotCollision::COLL_END) start = NULL; if (c->flags() & SlotCollision::COLL_START) @@ -1023,7 +1022,7 @@ bool Pass::resolveCollisions(Segment *seg, Slot *slotFix, Slot *start, return true; } -float Pass::resolveKern(Segment *seg, Slot *slotFix, GR_MAYBE_UNUSED Slot *start, KernCollider &coll, int dir, +float Pass::resolveKern(Segment *seg, Slot *slotFix, GR_MAYBE_UNUSED Slot *start, int dir, float &ymin, float &ymax, json *const dbgout) const { Slot *nbor; // neighboring slot @@ -1043,6 +1042,7 @@ float Pass::resolveKern(Segment *seg, Slot *slotFix, GR_MAYBE_UNUSED Slot *start } bool seenEnd = (cFix->flags() & SlotCollision::COLL_END) != 0; bool isInit = false; + KernCollider coll(dbgout); for (nbor = slotFix->next(); nbor; nbor = nbor->next()) { diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h index d7bb4f389fd..1a01b7a43f7 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h @@ -184,7 +184,7 @@ inline Machine::status_t Machine::status() const throw() return _status; } -inline void Machine::check_final_stack(const int32 * const sp) +inline void Machine::check_final_stack(const stack_t * const sp) { stack_t const * const base = _stack + STACK_GUARD, * const limit = base + STACK_MAX; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Pass.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Pass.h index c8f1aa20ba5..82da2caf15e 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Pass.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Pass.h @@ -81,7 +81,7 @@ private: bool collisionFinish(Segment *seg, GR_MAYBE_UNUSED json * const dbgout) const; bool resolveCollisions(Segment *seg, Slot *slot, Slot *start, ShiftCollider &coll, bool isRev, int dir, bool &moved, bool &hasCol, json * const dbgout) const; - float resolveKern(Segment *seg, Slot *slot, Slot *start, KernCollider &coll, int dir, + float resolveKern(Segment *seg, Slot *slot, Slot *start, int dir, float &ymin, float &ymax, json *const dbgout) const; const Silf * m_silf; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h b/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h index 23f595fde1f..3b6dd3fc3d8 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h @@ -67,7 +67,8 @@ of the License or (at your option) any later version. // #define NOT_IMPLEMENTED assert(false) #define NOT_IMPLEMENTED -#define binop(op) const int32 a = pop(); *sp = int32(*sp) op a +#define binop(op) const uint32 a = pop(); *sp = uint32(*sp) op a +#define sbinop(op) const int32 a = pop(); *sp = int32(*sp) op a #define use_params(n) dp += n #define declare_params(n) const byte * param = dp; \ @@ -130,7 +131,7 @@ ENDOP STARTOP(div_) if (*sp == 0) DIE; - binop(/); + sbinop(/); ENDOP STARTOP(min_) @@ -181,19 +182,19 @@ STARTOP(not_eq_) ENDOP STARTOP(less) - binop(<); + sbinop(<); ENDOP STARTOP(gtr) - binop(>); + sbinop(>); ENDOP STARTOP(less_eq) - binop(<=); + sbinop(<=); ENDOP STARTOP(gtr_eq) - binop(>=); + sbinop(>=); ENDOP STARTOP(next) |