From cd35ecb8fa468581929aa96a43e5a08c4c0599f3 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 24 Oct 2012 09:20:13 +0100 Subject: [PATCH] bug 803347 - update graphite2 lib to upstream commit 4ddfa0f51098. r=jdaggett --- gfx/graphite2/src/Code.cpp | 9 ++++----- gfx/graphite2/src/Face.cpp | 5 ++--- gfx/graphite2/src/FeatureMap.cpp | 16 ++++++++-------- gfx/graphite2/src/FileFace.cpp | 7 ------- gfx/graphite2/src/Font.cpp | 3 +-- gfx/graphite2/src/GlyphCache.cpp | 18 +++++++++--------- gfx/graphite2/src/Pass.cpp | 17 ++++++++++------- gfx/graphite2/src/Sparse.cpp | 2 +- gfx/graphite2/src/inc/FeatureMap.h | 3 --- gfx/graphite2/src/inc/GlyphCache.h | 12 ++++++------ gfx/graphite2/src/inc/Main.h | 12 ++++++++++++ gfx/graphite2/src/inc/Segment.h | 4 ++-- gfx/graphite2/src/inc/Silf.h | 12 ++++++------ gfx/graphite2/src/inc/Sparse.h | 14 ++++++++++++-- gfx/graphite2/src/inc/bits.h | 11 +++++++---- gfx/graphite2/src/inc/opcode_table.h | 6 +++--- gfx/graphite2/src/inc/opcodes.h | 4 ++-- 17 files changed, 85 insertions(+), 70 deletions(-) diff --git a/gfx/graphite2/src/Code.cpp b/gfx/graphite2/src/Code.cpp index c2262b69101f..656582fcee1f 100644 --- a/gfx/graphite2/src/Code.cpp +++ b/gfx/graphite2/src/Code.cpp @@ -169,17 +169,16 @@ Machine::Code::Code(bool is_constraint, const byte * bytecode_begin, const byte bytecode_end, pre_context, rule_length, - static_cast(silf.numClasses()), - static_cast(face.glyphs().numAttrs()), - static_cast(face.numFeatures()), + silf.numClasses(), + face.glyphs().numAttrs(), + face.numFeatures(), {1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,255, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0, - static_cast(silf.numUser())} + 0,0,0,0,0,0,0, silf.numUser()} }; decoder dec(lims, *this); diff --git a/gfx/graphite2/src/Face.cpp b/gfx/graphite2/src/Face.cpp index bccf4eeb5b84..3428aeaccf4d 100644 --- a/gfx/graphite2/src/Face.cpp +++ b/gfx/graphite2/src/Face.cpp @@ -25,7 +25,6 @@ License, as published by the Free Software Foundation, either version 2 of the License or (at your option) any later version. */ #include -#include #include "graphite2/Segment.h" #include "inc/CmapCache.h" #include "inc/debug.h" @@ -54,7 +53,7 @@ Face::Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops) m_descent(0) { memset(&m_ops, 0, sizeof m_ops); - memcpy(&m_ops, &ops, std::min(sizeof m_ops, ops.size)); + memcpy(&m_ops, &ops, min(sizeof m_ops, ops.size)); } @@ -92,7 +91,7 @@ bool Face::readGlyphs(uint32 faceOptions) return false; if (faceOptions & gr_face_preloadGlyphs) - nameTable(); // preload the name table along with the glyphs, heh. + nameTable(); // preload the name table along with the glyphs. return true; } diff --git a/gfx/graphite2/src/FeatureMap.cpp b/gfx/graphite2/src/FeatureMap.cpp index c625950b8a81..aa638d5cb4c6 100644 --- a/gfx/graphite2/src/FeatureMap.cpp +++ b/gfx/graphite2/src/FeatureMap.cpp @@ -185,23 +185,23 @@ bool SillMap::readFace(const Face & face) bool SillMap::readSill(const Face & face) { const Face::Table sill(face, TtfUtil::Tag::Sill); - const byte *pSill = sill; + const byte *p = sill; - if (!pSill) return true; + if (!p) return true; if (sill.size() < 12) return false; - if (be::read(pSill) != 0x00010000UL) return false; - m_numLanguages = be::read(pSill); + if (be::read(p) != 0x00010000UL) return false; + m_numLanguages = be::read(p); m_langFeats = new LangFeaturePair[m_numLanguages]; if (!m_langFeats || !m_FeatureMap.m_numFeats) { m_numLanguages = 0; return true; } //defensive - pSill += 6; // skip the fast search + p += 6; // skip the fast search if (sill.size() < m_numLanguages * 8U + 12) return false; for (int i = 0; i < m_numLanguages; i++) { - uint32 langid = be::read(pSill); - uint16 numSettings = be::read(pSill); - uint16 offset = be::read(pSill); + uint32 langid = be::read(p); + uint16 numSettings = be::read(p); + uint16 offset = be::read(p); if (offset + 8U * numSettings > sill.size() && numSettings > 0) return false; Features* feats = new Features(*m_FeatureMap.m_defaultFeatures); const byte *pLSet = sill + offset; diff --git a/gfx/graphite2/src/FileFace.cpp b/gfx/graphite2/src/FileFace.cpp index 8187b92e3312..dc2f017ed004 100644 --- a/gfx/graphite2/src/FileFace.cpp +++ b/gfx/graphite2/src/FileFace.cpp @@ -25,14 +25,7 @@ License, as published by the Free Software Foundation, either version 2 of the License or (at your option) any later version. */ #include -//#include "graphite2/Segment.h" -//#include "inc/CmapCache.h" -//#include "inc/Endian.h" #include "inc/FileFace.h" -//#include "inc/GlyphFace.h" -//#include "inc/SegCacheStore.h" -//#include "inc/Segment.h" -//#include "inc/NameTable.h" #ifndef GRAPHITE2_NFILEFACE diff --git a/gfx/graphite2/src/Font.cpp b/gfx/graphite2/src/Font.cpp index b090bb0fa80f..8860d3b58be6 100644 --- a/gfx/graphite2/src/Font.cpp +++ b/gfx/graphite2/src/Font.cpp @@ -24,7 +24,6 @@ Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public License, as published by the Free Software Foundation, either version 2 of the License or (at your option) any later version. */ -#include #include "inc/Face.h" #include "inc/Font.h" #include "inc/GlyphCache.h" @@ -39,7 +38,7 @@ Font::Font(float ppm, const Face & f, const void * appFontHandle, const gr_font_ { memset(&m_ops, 0, sizeof m_ops); if (m_hinted) - memcpy(&m_ops, ops, std::min(sizeof m_ops, ops->size)); + memcpy(&m_ops, ops, min(sizeof m_ops, ops->size)); else m_ops.glyph_advance_x = &Face::default_glyph_advance; diff --git a/gfx/graphite2/src/GlyphCache.cpp b/gfx/graphite2/src/GlyphCache.cpp index 7f3044792814..dae49bf1f066 100644 --- a/gfx/graphite2/src/GlyphCache.cpp +++ b/gfx/graphite2/src/GlyphCache.cpp @@ -24,8 +24,6 @@ Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public License, as published by the Free Software Foundation, either version 2 of the License or (at your option) any later version. */ -#include - #include "graphite2/Font.h" #include "inc/Main.h" @@ -175,6 +173,11 @@ const GlyphFace *GlyphCache::glyph(unsigned short glyphid) const //result m { GlyphFace * g = new GlyphFace(); if (g) p = _glyph_loader->read_glyph(glyphid, *g); + if (!p) + { + delete g; + return *_glyphs; + } } return p; } @@ -183,7 +186,7 @@ uint16 GlyphCache::glyphAttr(uint16 gid, uint16 gattr) const { const GlyphFace * p = glyphSafe(gid); - return p && gattr < _num_attrs ? p->attrs()[gattr] : 0; + return p && gattr < p->attrs().size() ? p->attrs()[gattr] : 0; } @@ -236,7 +239,7 @@ GlyphCache::Loader::Loader(const Face & face, const bool dumb_font) / (_long_fmt ? sizeof(uint32) : sizeof(uint16)) - 1; if (version != 0x00010000 - || _num_attrs == 0 || _num_attrs > 0x1000 // is this hard limit appropriate? + || _num_attrs == 0 || _num_attrs > 0x3000 // is this hard limit appropriate? || _num_glyphs_graphics > _num_glyphs_attributes) { _head = Face::Table(); @@ -260,7 +263,7 @@ unsigned short int GlyphCache::Loader::units_per_em() const throw() inline unsigned short int GlyphCache::Loader::num_glyphs() const throw() { - return std::max(_num_glyphs_graphics, _num_glyphs_attributes); + return max(_num_glyphs_graphics, _num_glyphs_attributes); } inline @@ -333,11 +336,8 @@ const GlyphFace * GlyphCache::Loader::read_glyph(unsigned short glyphid, GlyphFa new (&glyph) GlyphFace(bbox, advance, glat2_iterator(m_pGlat + glocs), glat2_iterator(m_pGlat + gloce)); } - if (glyph.attrs().size() > _num_attrs) - { - glyph.~GlyphFace(); + if (glyph.attrs().capacity() > _num_attrs) return 0; - } } return &glyph; diff --git a/gfx/graphite2/src/Pass.cpp b/gfx/graphite2/src/Pass.cpp index 51fabc8e8b04..a44648a85a62 100644 --- a/gfx/graphite2/src/Pass.cpp +++ b/gfx/graphite2/src/Pass.cpp @@ -275,16 +275,19 @@ bool Pass::readRanges(const byte * ranges, size_t num_ranges) memset(m_cols, 0xFF, m_numGlyphs * sizeof(uint16)); for (size_t n = num_ranges; n; --n) { - const uint16 first = be::read(ranges), - last = be::read(ranges), - col = be::read(ranges); - uint16 *p; + uint16 * ci = m_cols + be::read(ranges), + * ci_end = m_cols + be::read(ranges) + 1, + col = be::read(ranges); - if (first > last || last >= m_numGlyphs || col >= m_sColumns) + if (ci >= ci_end || ci_end > m_cols+m_numGlyphs || col >= m_sColumns) return false; - for (p = m_cols + first; p <= m_cols + last; ) - *p++ = col; + // A glyph must only belong to one column at a time + while (ci != ci_end && *ci == 0xffff) + *ci++ = col; + + if (ci != ci_end) + return false; } return true; } diff --git a/gfx/graphite2/src/Sparse.cpp b/gfx/graphite2/src/Sparse.cpp index 64675a2939da..83256cb814f5 100644 --- a/gfx/graphite2/src/Sparse.cpp +++ b/gfx/graphite2/src/Sparse.cpp @@ -47,7 +47,7 @@ sparse::mapped_type sparse::operator [] (const key_type k) const throw() } -size_t sparse::size() const throw() +size_t sparse::capacity() const throw() { size_t n = m_nchunks, s = 0; diff --git a/gfx/graphite2/src/inc/FeatureMap.h b/gfx/graphite2/src/inc/FeatureMap.h index ffc58c9b19a4..dc5175c30544 100644 --- a/gfx/graphite2/src/inc/FeatureMap.h +++ b/gfx/graphite2/src/inc/FeatureMap.h @@ -25,9 +25,6 @@ License, as published by the Free Software Foundation, either version 2 of the License or (at your option) any later version. */ #pragma once -// #include -// #include "graphite2/Types.h" -//#include "graphite2/Font.h" #include "inc/Main.h" #include "inc/FeatureVal.h" diff --git a/gfx/graphite2/src/inc/GlyphCache.h b/gfx/graphite2/src/inc/GlyphCache.h index 4f000dca6987..d5291ab0e59f 100644 --- a/gfx/graphite2/src/inc/GlyphCache.h +++ b/gfx/graphite2/src/inc/GlyphCache.h @@ -48,9 +48,9 @@ public: GlyphCache(const Face & face, const uint32 face_options); ~GlyphCache(); - size_t numGlyphs() const throw(); - size_t numAttrs() const throw(); - size_t unitsPerEm() const throw(); + unsigned short numGlyphs() const throw(); + unsigned short numAttrs() const throw(); + unsigned short unitsPerEm() const throw(); const GlyphFace *glyph(unsigned short glyphid) const; //result may be changed by subsequent call with a different glyphid const GlyphFace *glyphSafe(unsigned short glyphid) const; @@ -67,19 +67,19 @@ private: }; inline -size_t GlyphCache::numGlyphs() const throw() +unsigned short GlyphCache::numGlyphs() const throw() { return _num_glyphs; } inline -size_t GlyphCache::numAttrs() const throw() +unsigned short GlyphCache::numAttrs() const throw() { return _num_attrs; } inline -size_t GlyphCache::unitsPerEm() const throw() +unsigned short GlyphCache::unitsPerEm() const throw() { return _upem; } diff --git a/gfx/graphite2/src/inc/Main.h b/gfx/graphite2/src/inc/Main.h index 6ddaf37dfaf0..674af80e854b 100644 --- a/gfx/graphite2/src/inc/Main.h +++ b/gfx/graphite2/src/inc/Main.h @@ -56,6 +56,18 @@ template T * grzeroalloc(size_t n) return reinterpret_cast(calloc(n, sizeof(T))); } +template +inline T min(const T a, const T b) +{ + return a < b ? a : b; +} + +template +inline T max(const T a, const T b) +{ + return a > b ? a : b; +} + } // namespace graphite2 #define CLASS_NEW_DELETE \ diff --git a/gfx/graphite2/src/inc/Segment.h b/gfx/graphite2/src/inc/Segment.h index a2ff6d084821..8a3b601ab087 100644 --- a/gfx/graphite2/src/inc/Segment.h +++ b/gfx/graphite2/src/inc/Segment.h @@ -150,8 +150,8 @@ public: //only used by: GrSegment* makeAndInitialize(const GrFont *font, c private: Rect m_bbox; // ink box of the segment Position m_advance; // whole segment advance - SlotRope m_slots; // std::vector of slot buffers - AttributeRope m_userAttrs; // std::vector of userAttrs buffers + SlotRope m_slots; // Vector of slot buffers + AttributeRope m_userAttrs; // Vector of userAttrs buffers JustifyRope m_justifies; // Slot justification info buffers FeatureList m_feats; // feature settings referenced by charinfos in this segment Slot * m_freeSlots; // linked list of free slots diff --git a/gfx/graphite2/src/inc/Silf.h b/gfx/graphite2/src/inc/Silf.h index 724590777084..652f084c8ec6 100644 --- a/gfx/graphite2/src/inc/Silf.h +++ b/gfx/graphite2/src/inc/Silf.h @@ -78,7 +78,7 @@ public: uint16 findClassIndex(uint16 cid, uint16 gid) const; uint16 getClassGlyph(uint16 cid, unsigned int index) const; uint16 findPseudo(uint32 uid) const; - size_t numUser() const { return m_aUser; } + uint8 numUser() const { return m_aUser; } uint8 aPseudo() const { return m_aPseudo; } uint8 aBreak() const { return m_aBreak; } uint8 aMirror() const {return m_aMirror; } @@ -86,11 +86,11 @@ public: uint8 positionPass() const { return m_pPass; } uint8 justificationPass() const { return m_jPass; } uint8 bidiPass() const { return m_bPass; } - size_t numPasses() const { return m_numPasses; } - size_t maxCompPerLig() const { return m_iMaxComp; } - size_t numClasses() const { return m_nClass; } - uint8 flags() const { return m_flags; } - size_t numJustLevels() const { return m_numJusts; } + uint8 numPasses() const { return m_numPasses; } + uint8 maxCompPerLig() const { return m_iMaxComp; } + uint16 numClasses() const { return m_nClass; } + byte flags() const { return m_flags; } + uint8 numJustLevels() const { return m_numJusts; } Justinfo *justAttrs() const { return m_justs; } uint16 endLineGlyphid() const { return m_gEndLine; } const gr_faceinfo *silfInfo() const { return &m_silfinfo; } diff --git a/gfx/graphite2/src/inc/Sparse.h b/gfx/graphite2/src/inc/Sparse.h index 2eca5b6161c2..bbe6bcfb95ca 100644 --- a/gfx/graphite2/src/inc/Sparse.h +++ b/gfx/graphite2/src/inc/Sparse.h @@ -33,7 +33,11 @@ of the License or (at your option) any later version. namespace graphite2 { - +// A read-only packed fast sparse array of uint16 with uint16 keys. +// Like most container classes this has capacity and size properties and these +// refer to the number of stored entries and the number of addressable entries +// as normal. However due the sparse nature the capacity is always <= than the +// size. class sparse { public: @@ -64,6 +68,7 @@ public: operator bool () const throw(); mapped_type operator [] (const key_type k) const throw(); + size_t capacity() const throw(); size_t size() const throw(); size_t _sizeof() const throw(); @@ -137,11 +142,16 @@ sparse::operator bool () const throw() return m_array.map != 0; } +inline +size_t sparse::size() const throw() +{ + return m_nchunks*SIZEOF_CHUNK; +} inline size_t sparse::_sizeof() const throw() { - return sizeof(sparse) + size()*sizeof(mapped_type) + m_nchunks*sizeof(chunk); + return sizeof(sparse) + capacity()*sizeof(mapped_type) + m_nchunks*sizeof(chunk); } } // namespace graphite2 diff --git a/gfx/graphite2/src/inc/bits.h b/gfx/graphite2/src/inc/bits.h index aec2a005fed6..56b2d10224eb 100644 --- a/gfx/graphite2/src/inc/bits.h +++ b/gfx/graphite2/src/inc/bits.h @@ -26,6 +26,9 @@ of the License or (at your option) any later version. */ #pragma once +namespace graphite2 +{ + template inline unsigned int bit_set_count(T v) { @@ -72,16 +75,16 @@ inline unsigned int log_binary(T v) } template -inline T haszero(const T x) +inline T has_zero(const T x) { return (x - T(~T(0)/255)) & ~x & T(~T(0)/255*128); } template -inline T zerobytes(const T x, unsigned char n) +inline T zero_bytes(const T x, unsigned char n) { const T t = T(~T(0)/255*n); - return T((haszero(x^t) >> 7)*n); + return T((has_zero(x^t) >> 7)*n); } - +} diff --git a/gfx/graphite2/src/inc/opcode_table.h b/gfx/graphite2/src/inc/opcode_table.h index efab472a2071..06916f6c875b 100644 --- a/gfx/graphite2/src/inc/opcode_table.h +++ b/gfx/graphite2/src/inc/opcode_table.h @@ -55,8 +55,8 @@ static const opcode_t opcode_table[] = {{do2(sub)}, 0, "SUB"}, {{do2(mul)}, 0, "MUL"}, {{do2(div_)}, 0, "DIV"}, - {{do2(min)}, 0, "MIN"}, - {{do2(max)}, 0, "MAX"}, + {{do2(min_)}, 0, "MIN"}, + {{do2(max_)}, 0, "MAX"}, {{do2(neg)}, 0, "NEG"}, {{do2(trunc8)}, 0, "TRUNC8"}, {{do2(trunc16)}, 0, "TRUNC16"}, @@ -114,7 +114,7 @@ static const opcode_t opcode_table[] = {{do_(put_glyph), NILOP}, 2, "PUT_GLYPH"}, // output_class output_class {{do2(push_glyph_attr)}, 3, "PUSH_GLYPH_ATTR"}, // gattrnum gattrnum slot {{do2(push_att_to_glyph_attr)}, 3, "PUSH_ATT_TO_GLYPH_ATTR"}, // gattrnum gattrnum slot - // private internal private opcodes for internal use only, comes after all other on disk opcodes. + // private opcodes for internal use only, comes after all other on disk opcodes. {{do_(temp_copy), NILOP}, 0, "TEMP_COPY"} }; diff --git a/gfx/graphite2/src/inc/opcodes.h b/gfx/graphite2/src/inc/opcodes.h index 6127c8ff3593..6fad29f66fcc 100644 --- a/gfx/graphite2/src/inc/opcodes.h +++ b/gfx/graphite2/src/inc/opcodes.h @@ -132,12 +132,12 @@ STARTOP(div_) binop(/); ENDOP -STARTOP(min) +STARTOP(min_) const int32 a = pop(), b = *sp; if (a < b) *sp = a; ENDOP -STARTOP(max) +STARTOP(max_) const int32 a = pop(), b = *sp; if (a > b) *sp = a; ENDOP