Merge pull request #87 from bramp/issue-86
Update code.google.com/p/freetype-go to github.com/golang/freetype.
This commit is contained in:
commit
37f345f4d3
7 changed files with 37 additions and 32 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/llgcode/draw2d"
|
||||
|
||||
"code.google.com/p/freetype-go/freetype/truetype"
|
||||
"github.com/golang/freetype/truetype"
|
||||
)
|
||||
|
||||
var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"image/draw"
|
||||
"runtime"
|
||||
|
||||
"code.google.com/p/freetype-go/freetype/raster"
|
||||
"github.com/go-gl/gl/v2.1/gl"
|
||||
"github.com/golang/freetype/raster"
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dbase"
|
||||
"github.com/llgcode/draw2d/draw2dimg"
|
||||
|
@ -52,7 +52,7 @@ func (p *Painter) Paint(ss []raster.Span, done bool) {
|
|||
vertices []int32
|
||||
)
|
||||
for _, s := range ss {
|
||||
ma := s.A >> 16
|
||||
ma := s.Alpha >> 16
|
||||
a := uint8((ma * p.ca / M16) >> 8)
|
||||
colors = p.colors[ci:]
|
||||
colors[0] = p.cr
|
||||
|
|
|
@ -14,8 +14,11 @@ import (
|
|||
"github.com/llgcode/draw2d"
|
||||
"github.com/llgcode/draw2d/draw2dbase"
|
||||
|
||||
"code.google.com/p/freetype-go/freetype/raster"
|
||||
"code.google.com/p/freetype-go/freetype/truetype"
|
||||
"github.com/golang/freetype/raster"
|
||||
"github.com/golang/freetype/truetype"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
// Painter implements the freetype raster.Painter and has a SetColor method like the RGBAPainter
|
||||
|
@ -58,7 +61,7 @@ func NewGraphicContextWithPainter(img draw.Image, painter Painter) *GraphicConte
|
|||
painter,
|
||||
raster.NewRasterizer(width, height),
|
||||
raster.NewRasterizer(width, height),
|
||||
truetype.NewGlyphBuf(),
|
||||
&truetype.GlyphBuf{},
|
||||
dpi,
|
||||
}
|
||||
return gc
|
||||
|
@ -128,12 +131,12 @@ func (gc *GraphicContext) loadCurrentFont() (*truetype.Font, error) {
|
|||
// going downwards.
|
||||
|
||||
func (gc *GraphicContext) drawGlyph(glyph truetype.Index, dx, dy float64) error {
|
||||
if err := gc.glyphBuf.Load(gc.Current.Font, int32(gc.Current.Scale), glyph, truetype.NoHinting); err != nil {
|
||||
if err := gc.glyphBuf.Load(gc.Current.Font, fixed.Int26_6(gc.Current.Scale), glyph, font.HintingNone); err != nil {
|
||||
return err
|
||||
}
|
||||
e0 := 0
|
||||
for _, e1 := range gc.glyphBuf.End {
|
||||
DrawContour(gc, gc.glyphBuf.Point[e0:e1], dx, dy)
|
||||
for _, e1 := range gc.glyphBuf.Ends {
|
||||
DrawContour(gc, gc.glyphBuf.Points[e0:e1], dx, dy)
|
||||
e0 = e1
|
||||
}
|
||||
return nil
|
||||
|
@ -146,7 +149,7 @@ func (gc *GraphicContext) drawGlyph(glyph truetype.Index, dx, dy float64) error
|
|||
// For example, drawing a string that starts with a 'J' in an italic font may
|
||||
// affect pixels below and left of the point.
|
||||
func (gc *GraphicContext) CreateStringPath(s string, x, y float64) float64 {
|
||||
font, err := gc.loadCurrentFont()
|
||||
f, err := gc.loadCurrentFont()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return 0.0
|
||||
|
@ -154,16 +157,16 @@ func (gc *GraphicContext) CreateStringPath(s string, x, y float64) float64 {
|
|||
startx := x
|
||||
prev, hasPrev := truetype.Index(0), false
|
||||
for _, rune := range s {
|
||||
index := font.Index(rune)
|
||||
index := f.Index(rune)
|
||||
if hasPrev {
|
||||
x += fUnitsToFloat64(font.Kerning(int32(gc.Current.Scale), prev, index))
|
||||
x += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
||||
}
|
||||
err := gc.drawGlyph(index, x, y)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return startx - x
|
||||
}
|
||||
x += fUnitsToFloat64(font.HMetric(int32(gc.Current.Scale), index).AdvanceWidth)
|
||||
x += fUnitsToFloat64(f.HMetric(fixed.Int26_6(gc.Current.Scale), index).AdvanceWidth)
|
||||
prev, hasPrev = index, true
|
||||
}
|
||||
return x - startx
|
||||
|
@ -174,7 +177,7 @@ func (gc *GraphicContext) CreateStringPath(s string, x, y float64) float64 {
|
|||
// and the baseline intersect at 0, 0 in the returned coordinates.
|
||||
// Therefore the top and left coordinates may well be negative.
|
||||
func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom float64) {
|
||||
font, err := gc.loadCurrentFont()
|
||||
f, err := gc.loadCurrentFont()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return 0, 0, 0, 0
|
||||
|
@ -183,18 +186,17 @@ func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom fl
|
|||
cursor := 0.0
|
||||
prev, hasPrev := truetype.Index(0), false
|
||||
for _, rune := range s {
|
||||
index := font.Index(rune)
|
||||
index := f.Index(rune)
|
||||
if hasPrev {
|
||||
|
||||
cursor += fUnitsToFloat64(font.Kerning(int32(gc.Current.Scale), prev, index))
|
||||
cursor += fUnitsToFloat64(f.Kern(fixed.Int26_6(gc.Current.Scale), prev, index))
|
||||
}
|
||||
if err := gc.glyphBuf.Load(gc.Current.Font, int32(gc.Current.Scale), index, truetype.NoHinting); err != nil {
|
||||
if err := gc.glyphBuf.Load(gc.Current.Font, fixed.Int26_6(gc.Current.Scale), index, font.HintingNone); err != nil {
|
||||
log.Println(err)
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
e0 := 0
|
||||
for _, e1 := range gc.glyphBuf.End {
|
||||
ps := gc.glyphBuf.Point[e0:e1]
|
||||
for _, e1 := range gc.glyphBuf.Ends {
|
||||
ps := gc.glyphBuf.Points[e0:e1]
|
||||
for _, p := range ps {
|
||||
x, y := pointToF64Point(p)
|
||||
top = math.Min(top, y)
|
||||
|
@ -203,7 +205,7 @@ func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom fl
|
|||
right = math.Max(right, x+cursor)
|
||||
}
|
||||
}
|
||||
cursor += fUnitsToFloat64(font.HMetric(int32(gc.Current.Scale), index).AdvanceWidth)
|
||||
cursor += fUnitsToFloat64(f.HMetric(fixed.Int26_6(gc.Current.Scale), index).AdvanceWidth)
|
||||
prev, hasPrev = index, true
|
||||
}
|
||||
return left, top, right, bottom
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
package draw2dimg
|
||||
|
||||
import (
|
||||
"code.google.com/p/freetype-go/freetype/raster"
|
||||
"github.com/golang/freetype/raster"
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
type FtLineBuilder struct {
|
||||
|
@ -12,11 +13,11 @@ type FtLineBuilder struct {
|
|||
}
|
||||
|
||||
func (liner FtLineBuilder) MoveTo(x, y float64) {
|
||||
liner.Adder.Start(raster.Point{X: raster.Fix32(x * 256), Y: raster.Fix32(y * 256)})
|
||||
liner.Adder.Start(fixed.Point26_6{X: fixed.Int26_6(x * 64), Y: fixed.Int26_6(y * 64)})
|
||||
}
|
||||
|
||||
func (liner FtLineBuilder) LineTo(x, y float64) {
|
||||
liner.Adder.Add1(raster.Point{X: raster.Fix32(x * 256), Y: raster.Fix32(y * 256)})
|
||||
liner.Adder.Add1(fixed.Point26_6{X: fixed.Int26_6(x * 64), Y: fixed.Int26_6(y * 64)})
|
||||
}
|
||||
|
||||
func (liner FtLineBuilder) LineJoin() {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package draw2dimg
|
||||
|
||||
import (
|
||||
"code.google.com/p/freetype-go/freetype/truetype"
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/llgcode/draw2d"
|
||||
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
// DrawContour draws the given closed contour at the given sub-pixel offset.
|
||||
|
@ -45,7 +47,7 @@ func pointToF64Point(p truetype.Point) (x, y float64) {
|
|||
return fUnitsToFloat64(p.X), -fUnitsToFloat64(p.Y)
|
||||
}
|
||||
|
||||
func fUnitsToFloat64(x int32) float64 {
|
||||
func fUnitsToFloat64(x fixed.Int26_6) float64 {
|
||||
scaled := x << 2
|
||||
return float64(scaled/256) + float64(scaled%256)/256.0
|
||||
}
|
||||
|
@ -70,11 +72,11 @@ type FontExtents struct {
|
|||
// Extents returns the FontExtents for a font.
|
||||
// TODO needs to read this https://developer.apple.com/fonts/TrueType-Reference-Manual/RM02/Chap2.html#intro
|
||||
func Extents(font *truetype.Font, size float64) FontExtents {
|
||||
bounds := font.Bounds(font.FUnitsPerEm())
|
||||
bounds := font.Bounds(fixed.Int26_6(font.FUnitsPerEm()))
|
||||
scale := size / float64(font.FUnitsPerEm())
|
||||
return FontExtents{
|
||||
Ascent: float64(bounds.YMax) * scale,
|
||||
Descent: float64(bounds.YMin) * scale,
|
||||
Height: float64(bounds.YMax-bounds.YMin) * scale,
|
||||
Ascent: float64(bounds.Max.Y) * scale,
|
||||
Descent: float64(bounds.Min.Y) * scale,
|
||||
Height: float64(bounds.Max.Y-bounds.Min.Y) * scale,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
|
||||
"code.google.com/p/freetype-go/freetype/truetype"
|
||||
"github.com/golang/freetype/truetype"
|
||||
|
||||
"github.com/jung-kurt/gofpdf"
|
||||
"github.com/llgcode/draw2d"
|
||||
|
|
2
font.go
2
font.go
|
@ -9,7 +9,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"code.google.com/p/freetype-go/freetype/truetype"
|
||||
"github.com/golang/freetype/truetype"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
Loading…
Reference in a new issue