gofmt on package
This commit is contained in:
parent
f837e5edf3
commit
873e6bfa2b
3 changed files with 31 additions and 32 deletions
|
@ -20,7 +20,7 @@ func NewDashConverter(dash []float, dashOffset float, converter VertexConverter)
|
||||||
|
|
||||||
func (dasher *DashVertexConverter) NextCommand(cmd VertexCommand) {
|
func (dasher *DashVertexConverter) NextCommand(cmd VertexCommand) {
|
||||||
dasher.command = cmd
|
dasher.command = cmd
|
||||||
if(dasher.command == VertexStopCommand) {
|
if dasher.command == VertexStopCommand {
|
||||||
dasher.next.NextCommand(VertexStopCommand)
|
dasher.next.NextCommand(VertexStopCommand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ type GraphicContext struct {
|
||||||
PaintedImage *image.RGBA
|
PaintedImage *image.RGBA
|
||||||
fillRasterizer *raster.Rasterizer
|
fillRasterizer *raster.Rasterizer
|
||||||
strokeRasterizer *raster.Rasterizer
|
strokeRasterizer *raster.Rasterizer
|
||||||
freetype *freetype.Context
|
freetype *freetype.Context
|
||||||
defaultFontData FontData
|
defaultFontData FontData
|
||||||
DPI int
|
DPI int
|
||||||
current *contextStack
|
current *contextStack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ type contextStack struct {
|
||||||
join Join
|
join Join
|
||||||
previous *contextStack
|
previous *contextStack
|
||||||
fontSize float
|
fontSize float
|
||||||
fontData FontData
|
fontData FontData
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,14 +53,14 @@ func NewGraphicContext(pi *image.RGBA) *GraphicContext {
|
||||||
width, height := gc.PaintedImage.Bounds().Dx(), gc.PaintedImage.Bounds().Dy()
|
width, height := gc.PaintedImage.Bounds().Dx(), gc.PaintedImage.Bounds().Dy()
|
||||||
gc.fillRasterizer = raster.NewRasterizer(width, height)
|
gc.fillRasterizer = raster.NewRasterizer(width, height)
|
||||||
gc.strokeRasterizer = raster.NewRasterizer(width, height)
|
gc.strokeRasterizer = raster.NewRasterizer(width, height)
|
||||||
|
|
||||||
gc.DPI = 92
|
gc.DPI = 92
|
||||||
gc.defaultFontData = FontData{"luxi", FontFamilySans, FontStyleNormal}
|
gc.defaultFontData = FontData{"luxi", FontFamilySans, FontStyleNormal}
|
||||||
gc.freetype = freetype.NewContext()
|
gc.freetype = freetype.NewContext()
|
||||||
gc.freetype.SetDPI(gc.DPI)
|
gc.freetype.SetDPI(gc.DPI)
|
||||||
gc.freetype.SetClip(pi.Bounds())
|
gc.freetype.SetClip(pi.Bounds())
|
||||||
gc.freetype.SetDst(pi)
|
gc.freetype.SetDst(pi)
|
||||||
|
|
||||||
gc.current = new(contextStack)
|
gc.current = new(contextStack)
|
||||||
|
|
||||||
gc.current.tr = NewIdentityMatrix()
|
gc.current.tr = NewIdentityMatrix()
|
||||||
|
@ -73,7 +73,7 @@ func NewGraphicContext(pi *image.RGBA) *GraphicContext {
|
||||||
gc.current.join = RoundJoin
|
gc.current.join = RoundJoin
|
||||||
gc.current.fontSize = 10
|
gc.current.fontSize = 10
|
||||||
gc.current.fontData = gc.defaultFontData
|
gc.current.fontData = gc.defaultFontData
|
||||||
|
|
||||||
return gc
|
return gc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ func (gc *GraphicContext) Close() {
|
||||||
gc.current.path.Close()
|
gc.current.path.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gc *GraphicContext) FillString(text string) (cursor float){
|
func (gc *GraphicContext) FillString(text string) (cursor float) {
|
||||||
gc.freetype.SetSrc(image.NewColorImage(gc.current.strokeColor))
|
gc.freetype.SetSrc(image.NewColorImage(gc.current.strokeColor))
|
||||||
// Draw the text.
|
// Draw the text.
|
||||||
x, y := gc.current.path.LastPoint()
|
x, y := gc.current.path.LastPoint()
|
||||||
|
@ -244,11 +244,11 @@ func (gc *GraphicContext) FillString(text string) (cursor float){
|
||||||
x0, fontSize := 0.0, gc.current.fontSize
|
x0, fontSize := 0.0, gc.current.fontSize
|
||||||
gc.current.tr.VectorTransform(&x0, &fontSize)
|
gc.current.tr.VectorTransform(&x0, &fontSize)
|
||||||
font := GetFont(gc.current.fontData)
|
font := GetFont(gc.current.fontData)
|
||||||
if(font == nil) {
|
if font == nil {
|
||||||
font = GetFont(gc.defaultFontData)
|
font = GetFont(gc.defaultFontData)
|
||||||
}
|
}
|
||||||
if(font == nil) {
|
if font == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
gc.freetype.SetFont(font)
|
gc.freetype.SetFont(font)
|
||||||
gc.freetype.SetFontSize(fontSize)
|
gc.freetype.SetFontSize(fontSize)
|
||||||
|
@ -258,14 +258,13 @@ func (gc *GraphicContext) FillString(text string) (cursor float){
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
x1, _ := gc.current.path.LastPoint()
|
x1, _ := gc.current.path.LastPoint()
|
||||||
x2, y2 := float(p.X) / 256, float(p.Y) / 256
|
x2, y2 := float(p.X)/256, float(p.Y)/256
|
||||||
gc.current.tr.InverseTransform(&x2, &y2)
|
gc.current.tr.InverseTransform(&x2, &y2)
|
||||||
width := x2 - x1
|
width := x2 - x1
|
||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (gc *GraphicContext) paint(rasterizer *raster.Rasterizer, color image.Color) {
|
func (gc *GraphicContext) paint(rasterizer *raster.Rasterizer, color image.Color) {
|
||||||
painter := raster.NewRGBAPainter(gc.PaintedImage)
|
painter := raster.NewRGBAPainter(gc.PaintedImage)
|
||||||
painter.SetColor(color)
|
painter.SetColor(color)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fontFolder = "../../fonts/"
|
fontFolder = "../../fonts/"
|
||||||
fonts = make(map[string] *truetype.Font)
|
fonts = make(map[string]*truetype.Font)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,32 +34,34 @@ const (
|
||||||
|
|
||||||
|
|
||||||
type FontData struct {
|
type FontData struct {
|
||||||
Name string
|
Name string
|
||||||
Family FontFamily
|
Family FontFamily
|
||||||
Style FontStyle
|
Style FontStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func GetFont(fontData FontData) *truetype.Font {
|
||||||
func GetFont(fontData FontData) (*truetype.Font) {
|
|
||||||
fontFileName := fontData.Name
|
fontFileName := fontData.Name
|
||||||
switch fontData.Family {
|
switch fontData.Family {
|
||||||
case FontFamilySans: fontFileName += "s"
|
case FontFamilySans:
|
||||||
case FontFamilySerif: fontFileName += "r"
|
fontFileName += "s"
|
||||||
case FontFamilyMono: fontFileName += "m"
|
case FontFamilySerif:
|
||||||
|
fontFileName += "r"
|
||||||
|
case FontFamilyMono:
|
||||||
|
fontFileName += "m"
|
||||||
}
|
}
|
||||||
if(fontData.Style & FontStyleBold != 0) {
|
if fontData.Style&FontStyleBold != 0 {
|
||||||
fontFileName += "b"
|
fontFileName += "b"
|
||||||
} else {
|
} else {
|
||||||
fontFileName += "r"
|
fontFileName += "r"
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fontData.Style & FontStyleItalic != 0) {
|
if fontData.Style&FontStyleItalic != 0 {
|
||||||
fontFileName += "i"
|
fontFileName += "i"
|
||||||
}
|
}
|
||||||
fontFileName += ".ttf"
|
fontFileName += ".ttf"
|
||||||
font := fonts[fontFileName]
|
font := fonts[fontFileName]
|
||||||
if(font != nil) {
|
if font != nil {
|
||||||
return font
|
return font
|
||||||
}
|
}
|
||||||
fonts[fontFileName] = loadFont(fontFileName)
|
fonts[fontFileName] = loadFont(fontFileName)
|
||||||
|
@ -74,7 +76,7 @@ func SetFontFolder(folder string) {
|
||||||
fontFolder = folder
|
fontFolder = folder
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFont(fontFileName string) (*truetype.Font) {
|
func loadFont(fontFileName string) *truetype.Font {
|
||||||
fontBytes, err := ioutil.ReadFile(path.Join(fontFolder, fontFileName))
|
fontBytes, err := ioutil.ReadFile(path.Join(fontFolder, fontFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -87,5 +89,3 @@ func loadFont(fontFileName string) (*truetype.Font) {
|
||||||
}
|
}
|
||||||
return font
|
return font
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue