Skip to content

Commit

Permalink
party -u
Browse files Browse the repository at this point in the history
  • Loading branch information
maddyblue committed Mar 9, 2015
1 parent 87ea1fe commit 234b301
Show file tree
Hide file tree
Showing 188 changed files with 4,160 additions and 7,586 deletions.
35 changes: 31 additions & 4 deletions _third_party/code.google.com/p/freetype-go/freetype/freetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,43 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) {
if len(ps) == 0 {
return
}
// ps[0] is a truetype.Point measured in FUnits and positive Y going upwards.
// start is the same thing measured in fixed point units and positive Y
// going downwards, and offset by (dx, dy)

// The low bit of each point's Flags value is whether the point is on the
// curve. Truetype fonts only have quadratic Bézier curves, not cubics.
// Thus, two consecutive off-curve points imply an on-curve point in the
// middle of those two.
//
// See http://chanae.walon.org/pub/ttf/ttf_glyphs.htm for more details.

// ps[0] is a truetype.Point measured in FUnits and positive Y going
// upwards. start is the same thing measured in fixed point units and
// positive Y going downwards, and offset by (dx, dy).
start := raster.Point{
X: dx + raster.Fix32(ps[0].X<<2),
Y: dy - raster.Fix32(ps[0].Y<<2),
}
others := []truetype.Point(nil)
if ps[0].Flags&0x01 != 0 {
others = ps[1:]
} else {
last := raster.Point{
X: dx + raster.Fix32(ps[len(ps)-1].X<<2),
Y: dy - raster.Fix32(ps[len(ps)-1].Y<<2),
}
if ps[len(ps)-1].Flags&0x01 != 0 {
start = last
others = ps[:len(ps)-1]
} else {
start = raster.Point{
X: (start.X + last.X) / 2,
Y: (start.Y + last.Y) / 2,
}
others = ps
}
}
c.r.Start(start)
q0, on0 := start, true
for _, p := range ps[1:] {
for _, p := range others {
q := raster.Point{
X: dx + raster.Fix32(p.X<<2),
Y: dy - raster.Fix32(p.Y<<2),
Expand Down
54 changes: 7 additions & 47 deletions _third_party/code.google.com/p/freetype-go/freetype/raster/geom.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (p Point) Len() Fix32 {
func (p Point) Norm(length Fix32) Point {
d := p.Len()
if d == 0 {
return Point{0, 0}
return Point{}
}
s, t := int64(length), int64(d)
x := int64(p.X) * s / t
Expand Down Expand Up @@ -204,74 +204,34 @@ func (p Path) String() string {
return s
}

// grow adds n elements to p.
func (p *Path) grow(n int) {
n += len(*p)
if n > cap(*p) {
old := *p
*p = make([]Fix32, n, 2*n+8)
copy(*p, old)
return
}
*p = (*p)[0:n]
}

// Clear cancels any previous calls to p.Start or p.AddXxx.
func (p *Path) Clear() {
*p = (*p)[0:0]
*p = (*p)[:0]
}

// Start starts a new curve at the given point.
func (p *Path) Start(a Point) {
n := len(*p)
p.grow(4)
(*p)[n] = 0
(*p)[n+1] = a.X
(*p)[n+2] = a.Y
(*p)[n+3] = 0
*p = append(*p, 0, a.X, a.Y, 0)
}

// Add1 adds a linear segment to the current curve.
func (p *Path) Add1(b Point) {
n := len(*p)
p.grow(4)
(*p)[n] = 1
(*p)[n+1] = b.X
(*p)[n+2] = b.Y
(*p)[n+3] = 1
*p = append(*p, 1, b.X, b.Y, 1)
}

// Add2 adds a quadratic segment to the current curve.
func (p *Path) Add2(b, c Point) {
n := len(*p)
p.grow(6)
(*p)[n] = 2
(*p)[n+1] = b.X
(*p)[n+2] = b.Y
(*p)[n+3] = c.X
(*p)[n+4] = c.Y
(*p)[n+5] = 2
*p = append(*p, 2, b.X, b.Y, c.X, c.Y, 2)
}

// Add3 adds a cubic segment to the current curve.
func (p *Path) Add3(b, c, d Point) {
n := len(*p)
p.grow(8)
(*p)[n] = 3
(*p)[n+1] = b.X
(*p)[n+2] = b.Y
(*p)[n+3] = c.X
(*p)[n+4] = c.Y
(*p)[n+5] = d.X
(*p)[n+6] = d.Y
(*p)[n+7] = 3
*p = append(*p, 3, b.X, b.Y, c.X, c.Y, d.X, d.Y, 3)
}

// AddPath adds the Path q to p.
func (p *Path) AddPath(q Path) {
n, m := len(*p), len(q)
p.grow(m)
copy((*p)[n:n+m], q)
*p = append(*p, q...)
}

// AddStroke adds a stroked Path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ func (m *MonochromePainter) Paint(ss []Span, done bool) {
if j < len(ss) {
ss[j] = finalSpan
j++
m.Painter.Paint(ss[0:j], true)
m.Painter.Paint(ss[:j], true)
} else if j == len(ss) {
m.Painter.Paint(ss, false)
if cap(ss) > 0 {
ss = ss[0:1]
ss = ss[:1]
} else {
ss = make([]Span, 1)
}
Expand All @@ -224,7 +224,7 @@ func (m *MonochromePainter) Paint(ss []Span, done bool) {
// Reset the accumulator, so that this Painter can be re-used.
m.y, m.x0, m.x1 = 0, 0, 0
} else {
m.Painter.Paint(ss[0:j], false)
m.Painter.Paint(ss[:j], false)
}
}

Expand Down Expand Up @@ -253,11 +253,11 @@ func (g *GammaCorrectionPainter) Paint(ss []Span, done bool) {
M = 0x1010101 // 255*M == 1<<32-1
N = 0x8080 // N = M>>9, and N < 1<<16-1
)
for i, _ := range ss {
if ss[i].A == 0 || ss[i].A == 1<<32-1 {
for i, s := range ss {
if s.A == 0 || s.A == 1<<32-1 {
continue
}
p, q := ss[i].A/M, (ss[i].A%M)>>9
p, q := s.A/M, (s.A%M)>>9
// The resultant alpha is a linear interpolation of g.a[p] and g.a[p+1].
a := uint32(g.a[p])*(N-q) + uint32(g.a[p+1])*q
a = (a + N/2) / N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func (r *Rasterizer) Add2(b, c Point) {
s := sStack[i]
p := pStack[2*i:]
if s > 0 {
// Split the quadratic curve p[0:3] into an equivalent set of two shorter curves:
// p[0:3] and p[2:5]. The new p[4] is the old p[2], and p[0] is unchanged.
// Split the quadratic curve p[:3] into an equivalent set of two shorter curves:
// p[:3] and p[2:5]. The new p[4] is the old p[2], and p[0] is unchanged.
mx := p[1].X
p[4].X = p[2].X
p[3].X = (p[4].X + mx) / 2
Expand Down Expand Up @@ -385,8 +385,8 @@ func (r *Rasterizer) Add3(b, c, d Point) {
s := sStack[i]
p := pStack[3*i:]
if s > 0 {
// Split the cubic curve p[0:4] into an equivalent set of two shorter curves:
// p[0:4] and p[3:7]. The new p[6] is the old p[3], and p[0] is unchanged.
// Split the cubic curve p[:4] into an equivalent set of two shorter curves:
// p[:4] and p[3:7]. The new p[6] is the old p[3], and p[0] is unchanged.
m01x := (p[0].X + p[1].X) / 2
m12x := (p[1].X + p[2].X) / 2
m23x := (p[2].X + p[3].X) / 2
Expand Down Expand Up @@ -519,22 +519,22 @@ func (r *Rasterizer) Rasterize(p Painter) {
}
}
if s > len(r.spanBuf)-2 {
p.Paint(r.spanBuf[0:s], false)
p.Paint(r.spanBuf[:s], false)
s = 0
}
}
}
p.Paint(r.spanBuf[0:s], true)
p.Paint(r.spanBuf[:s], true)
}

// Clear cancels any previous calls to r.Start or r.AddXxx.
func (r *Rasterizer) Clear() {
r.a = Point{0, 0}
r.a = Point{}
r.xi = 0
r.yi = 0
r.area = 0
r.cover = 0
r.cell = r.cell[0:0]
r.cell = r.cell[:0]
for i := 0; i < len(r.cellIndex); i++ {
r.cellIndex[i] = -1
}
Expand Down Expand Up @@ -562,11 +562,11 @@ func (r *Rasterizer) SetBounds(width, height int) {
r.width = width
r.splitScale2 = ss2
r.splitScale3 = ss3
r.cell = r.cellBuf[0:0]
r.cell = r.cellBuf[:0]
if height > len(r.cellIndexBuf) {
r.cellIndex = make([]int, height)
} else {
r.cellIndex = r.cellIndexBuf[0:height]
r.cellIndex = r.cellIndexBuf[:height]
}
r.Clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (k *stroker) stroke(q Path) {
// The left-hand-side path is added immediately to k.p; the right-hand-side
// path is accumulated in k.r. Once we've finished adding the LHS to k.p,
// we add the RHS in reverse order.
k.r = Path(make([]Fix32, 0, len(q)))
k.r = make(Path, 0, len(q))
k.a = Point{q[1], q[2]}
for i := 4; i < len(q); {
switch q[i] {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 234b301

Please sign in to comment.