Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1207061 - Update graphite2 library to release 1.3.3. r=jdaggett
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkthame committed Sep 30, 2015
1 parent a2b704c commit e0c3f3f
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 416 deletions.
2 changes: 1 addition & 1 deletion gfx/graphite2/README.mozilla
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This directory contains the Graphite2 library from http://hg.palaso.org/graphitedev

Current version derived from upstream changeset 0f9edca71849
Current version derived from upstream changeset ff457b44c490

See gfx/graphite2/moz-gr-update.sh for update procedure.

2 changes: 1 addition & 1 deletion gfx/graphite2/include/graphite2/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#define GR2_VERSION_MAJOR 1
#define GR2_VERSION_MINOR 3
#define GR2_VERSION_BUGFIX 2
#define GR2_VERSION_BUGFIX 3

#ifdef __cplusplus
extern "C"
Expand Down
4 changes: 2 additions & 2 deletions gfx/graphite2/src/Code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ Machine::Code::Code(bool is_constraint, const byte * bytecode_begin, const byte
// Now we know exactly how much code and data the program really needs
// realloc the buffers to exactly the right size so we don't waste any
// memory.
assert((bytecode_end - bytecode_begin) >= std::ptrdiff_t(_instr_count));
assert((bytecode_end - bytecode_begin) >= std::ptrdiff_t(_data_size));
assert((bytecode_end - bytecode_begin) >= ptrdiff_t(_instr_count));
assert((bytecode_end - bytecode_begin) >= ptrdiff_t(_data_size));
memmove(_code + (_instr_count+1), _data, _data_size*sizeof(byte));
size_t const total_sz = ((_instr_count+1) + (_data_size + sizeof(instr)-1)/sizeof(instr))*sizeof(instr);
if (_out)
Expand Down
486 changes: 246 additions & 240 deletions gfx/graphite2/src/Collider.cpp

Large diffs are not rendered by default.

40 changes: 23 additions & 17 deletions gfx/graphite2/src/Decompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace {

inline
u32 read_literal(u8 const * &s, u8 const * const e, u32 l) {
if (unlikely(l == 15) && likely(s != e))
if (l == 15 && s != e)
{
u8 b = 0;
do { l += b = *s++; } while(b==0xff && s != e);
Expand All @@ -51,23 +51,23 @@ bool read_sequence(u8 const * &src, u8 const * const end, u8 const * &literal, u
literal = src;
src += literal_len;

if (unlikely(src > end - 2))
if (src > end - 2)
return false;

match_dist = *src++;
match_dist |= *src++ << 8;
match_len = read_literal(src, end, token & 0xf);

return true;
return src <= end-5;
}

}

int lz4::decompress(void const *in, size_t in_size, void *out, size_t out_size)
{
if (out_size <= in_size)
if (out_size <= in_size || in_size < sizeof(unsigned long)+1)
return -1;

u8 const * src = static_cast<u8 const *>(in),
* literal = 0,
* const src_end = src + in_size;
Expand All @@ -81,24 +81,30 @@ int lz4::decompress(void const *in, size_t in_size, void *out, size_t out_size)

while (read_sequence(src, src_end, literal, literal_len, match_len, match_dist))
{
// Copy in literal. At this point the last full sequence must be at
// least MINMATCH + 5 from the end of the output buffer.
if (unlikely(literal + align(literal_len) > src_end
|| dst + align(literal_len) > dst_end - MINMATCH+5))
return -1;
dst = overrun_copy(dst, literal, literal_len);

if (literal_len != 0)
{
// Copy in literal. At this point the last full sequence must be at
// least MINMATCH + 5 from the end of the output buffer.
if (dst + align(literal_len) > dst_end - MINMATCH+5)
return -1;
dst = overrun_copy(dst, literal, literal_len);
}

// Copy, possibly repeating, match from earlier in the
// decoded output.
u8 const * const pcpy = dst - match_dist;
if (unlikely(pcpy < static_cast<u8*>(out)
|| dst + align(match_len + MINMATCH) > dst_end))
if (pcpy < static_cast<u8*>(out)
|| dst + match_len + MINMATCH > dst_end - 5)
return -1;
dst = copy(dst, pcpy, match_len + MINMATCH);
if (dst > pcpy+sizeof(unsigned long)
&& dst + align(match_len + MINMATCH) <= dst_end)
dst = overrun_copy(dst, pcpy, match_len + MINMATCH);
else
dst = safe_copy(dst, pcpy, match_len + MINMATCH);
}

if (unlikely(literal + literal_len > src_end
|| dst + literal_len > dst_end))
if (literal + literal_len > src_end
|| dst + literal_len > dst_end)
return -1;
dst = fast_copy(dst, literal, literal_len);

Expand Down
2 changes: 1 addition & 1 deletion gfx/graphite2/src/Face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ Face::Table & Face::Table::operator = (const Table & rhs) throw()
Error Face::Table::decompress()
{
Error e;
if (e.test(_sz < 2 * sizeof(uint32) + 3, E_BADSIZE))
if (e.test(_sz < 5 * sizeof(uint32), E_BADSIZE))
return e;
byte * uncompressed_table = 0;
size_t uncompressed_size = 0;
Expand Down
8 changes: 4 additions & 4 deletions gfx/graphite2/src/Intervals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void Zones::insert(Exclusion e)
#if !defined GRAPHITE2_NTRACING
addDebug(&e);
#endif
e.x = std::max(e.x, _pos);
e.xm = std::min(e.xm, _posm);
e.x = max(e.x, _pos);
e.xm = min(e.xm, _posm);
if (e.x >= e.xm) return;

for (iterator i = _exclusions.begin(), ie = _exclusions.end(); i != ie && e.x < e.xm; ++i)
Expand Down Expand Up @@ -141,8 +141,8 @@ void Zones::remove(float x, float xm)
#if !defined GRAPHITE2_NTRACING
removeDebug(x, xm);
#endif
x = std::max(x, _pos);
xm = std::min(xm, _posm);
x = max(x, _pos);
xm = min(xm, _posm);
if (x >= xm) return;

for (iterator i = _exclusions.begin(), ie = _exclusions.end(); i != ie; ++i)
Expand Down
15 changes: 12 additions & 3 deletions gfx/graphite2/src/Pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su
return face.error(e);

m_successStart = m_numStates - m_numSuccess;
if (e.test(p + numRanges * 6 - 4 > pass_end, E_BADPASSLENGTH)) return face.error(e);
// test for beyond end - 1 to account for reading uint16
if (e.test(p + numRanges * 6 - 2 > pass_end, E_BADPASSLENGTH)) return face.error(e);
m_numGlyphs = be::peek<uint16>(p + numRanges * 6 - 4) + 1;
// Calculate the start of various arrays.
const byte * const ranges = p;
Expand Down Expand Up @@ -263,7 +264,11 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
}

byte * moved_progs = static_cast<byte *>(realloc(m_progs, prog_pool_free - m_progs));
if (e.test(!moved_progs, E_OUTOFMEM)) return face.error(e);
if (e.test(!moved_progs, E_OUTOFMEM))
{
if (prog_pool_free - m_progs == 0) m_progs = 0;
return face.error(e);
}

if (moved_progs != m_progs)
{
Expand Down Expand Up @@ -383,7 +388,11 @@ bool Pass::runGraphite(vm::Machine & m, FiniteStateMachine & fsm, bool reverse)
{
Slot *s = m.slotMap().segment.first();
if (!s || !testPassConstraint(m)) return true;
if (reverse) m.slotMap().segment.reverseSlots();
if (reverse)
{
m.slotMap().segment.reverseSlots();
s = m.slotMap().segment.first();
}
if (m_numRules)
{
Slot *currHigh = s->next();
Expand Down
67 changes: 8 additions & 59 deletions gfx/graphite2/src/Segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ of the License or (at your option) any later version.
#include "inc/Slot.h"
#include "inc/Main.h"
#include "inc/CmapCache.h"
//#include "inc/Bidi.h"
#include "inc/Collider.h"
#include "graphite2/Segment.h"

Expand Down Expand Up @@ -156,12 +155,6 @@ void Segment::appendSlot(int id, int cid, int gid, int iFeats, size_t coffset)
aSlot->originate(id);
aSlot->before(id);
aSlot->after(id);
// uint8 aBidi = m_silf->aBidi();
// if (aBidi != 0xFF)
// {
// unsigned int bAttr = glyphAttr(gid, aBidi);
// aSlot->setBidiClass((bAttr <= 22) * bAttr);
// }
if (m_last) m_last->next(aSlot);
aSlot->prev(m_last);
m_last = aSlot;
Expand Down Expand Up @@ -409,6 +402,14 @@ Position Segment::positionSlots(const Font *font, Slot * iStart, Slot * iEnd, bo
float clusterMin = 0.;
Rect bbox;

if (currdir() != isRtl)
{
Slot *temp;
reverseSlots();
temp = iStart;
iStart = iEnd;
iEnd = temp;
}
if (!iStart) iStart = m_first;
if (!iEnd) iEnd = m_last;

Expand Down Expand Up @@ -502,58 +503,6 @@ bool Segment::read_text(const Face *face, const Features* pFeats/*must not be NU
return true;
}

#if 0
Slot *process_bidi(Slot *start, int level, int prelevel, int &nextLevel, int dirover, int isol, int &cisol, int &isolerr, int &embederr, int init, Segment *seg, uint8 aMirror, BracketPairStack &stack);
void resolveImplicit(Slot *s, Segment *seg, uint8 aMirror);
void resolveWhitespace(int baseLevel, Slot *s);
Slot *resolveOrder(Slot * & s, const bool reordered, const int level = 0);

void Segment::bidiPass(int paradir, uint8 aMirror)
{
if (slotCount() == 0)
return;

Slot *s;
int baseLevel = paradir ? 1 : 0;
unsigned int bmask = 0;
unsigned int ssize = 0;
for (s = first(); s; s = s->next())
{
if (getSlotBidiClass(s) < 0)
s->setBidiClass(0);
bmask |= (1 << s->getBidiClass());
s->setBidiLevel(baseLevel);
if (s->getBidiClass() == 21)
++ssize;
}

BracketPairStack bstack(ssize);
if (bmask & (paradir ? 0x2E7892 : 0x2E789C))
{
// O(8N) algorithm, with no working data beyond what is needed for processParens
int nextLevel = paradir;
int e, i, c;
process_bidi(first(), baseLevel, paradir, nextLevel, 0, 0, c = 0, i = 0, e = 0, 1, this, aMirror, bstack);
resolveImplicit(first(), this, aMirror);
resolveWhitespace(baseLevel, last());
s = resolveOrder(s = first(), baseLevel != 0);
if (s)
{
first(s); last(s->prev());
s->prev()->next(0); s->prev(0);
}
}
else if (!(dir() & 4) && baseLevel && aMirror)
{
for (s = first(); s; s = s->next())
{
unsigned short g = glyphAttr(s->gid(), aMirror);
if (g) s->setGlyph(this, g);
}
}
}
#endif

void Segment::doMirror(uint16 aMirror)
{
Slot * s;
Expand Down
4 changes: 3 additions & 1 deletion gfx/graphite2/src/TtfUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,11 @@ const void * FindCmapSubtable(const void * pCmap, int nPlatformId, /* =3 */ int
const uint8 * pRtn = reinterpret_cast<const uint8 *>(pCmap) + offset;
if (length)
{
if (offset > length) return NULL;
if (offset + 2 > length) return NULL;
uint16 format = be::read<uint16>(pRtn);
if (format == 4)
{
if (offset + 4 > length) return NULL;
uint16 subTableLength = be::peek<uint16>(pRtn);
if (i + 1 == csuPlatforms)
{
Expand All @@ -867,6 +868,7 @@ const void * FindCmapSubtable(const void * pCmap, int nPlatformId, /* =3 */ int
}
if (format == 12)
{
if (offset + 6 > length) return NULL;
uint32 subTableLength = be::peek<uint32>(pRtn);
if (i + 1 == csuPlatforms)
{
Expand Down
3 changes: 0 additions & 3 deletions gfx/graphite2/src/inc/Collider.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ of the License or (at your option) any later version.
*/
#pragma once

#include <utility>
#include "inc/List.h"
//#include "inc/Slot.h"
#include "inc/Position.h"
#include "inc/Intervals.h"
#include "inc/debug.h"
//#include "inc/Segment.h"

namespace graphite2 {

Expand Down
31 changes: 7 additions & 24 deletions gfx/graphite2/src/inc/Compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ of the License or (at your option) any later version.
#include <cstddef>
#include <cstring>

#include <iterator>

#if ((defined GCC_VERSION && GCC_VERSION >= 302) || (defined __INTEL_COMPILER && __INTEL_COMPILER >= 800) || defined(__clang__))
#define expect(expr,value) (__builtin_expect ((expr),(value)) )
#else
#define expect(expr,value) (expr)
#endif

#define likely(expr) expect((expr) != 0, 1)
#define unlikely(expr) expect((expr) != 0, 0)


namespace
{

Expand Down Expand Up @@ -72,6 +60,12 @@ size_t align(size_t p) {
return (p + sizeof(unsigned long)-1) & ~(sizeof(unsigned long)-1);
}

inline
u8 * safe_copy(u8 * d, u8 const * s, size_t n) {
while (n--) *d++ = *s++;
return d;
}

inline
u8 * overrun_copy(u8 * d, u8 const * s, size_t n) {
size_t const WS = sizeof(unsigned long);
Expand Down Expand Up @@ -100,21 +94,10 @@ u8 * fast_copy(u8 * d, u8 const * s, size_t n) {
s += WS;
}
n &= WS-1;
while (n--) {*d++ = *s++; }

return d;
return safe_copy(d, s, n);
}


inline
u8 * copy(u8 * d, u8 const * s, size_t n) {
if (likely(d>s+sizeof(unsigned long)))
return overrun_copy(d,s,n);
else
while (n--) *d++ = *s++;
return d;
}

} // end of anonymous namespace


18 changes: 17 additions & 1 deletion gfx/graphite2/src/inc/Decompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,23 @@ of the License or (at your option) any later version.
namespace lz4
{

// return value is either decompressed size of -1
// decompress an LZ4 block
// Parameters:
// @in - Input buffer containing an LZ4 block.
// @in_size - Size of the input LZ4 block in bytes.
// @out - Output buffer to hold decompressed results.
// @out_size - The size of the buffer pointed to by @out.
// Invariants:
// @in - This buffer must be at least 1 machine word in length,
// regardless of the actual LZ4 block size.
// @in_size - This must be at least 4 and must also be <= to the
// allocated buffer @in.
// @out - This must be bigger than the input buffer and at least
// 13 bytes.
// @out_size - Must always be big enough to hold the expected size.
// Return:
// -1 - Decompression failed.
// size - Actual number of bytes decompressed.
int decompress(void const *in, size_t in_size, void *out, size_t out_size);

} // end of namespace shrinker
Expand Down
Loading

0 comments on commit e0c3f3f

Please sign in to comment.