diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-04-16 05:37:14 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-04-16 08:37:14 -0400 |
commit | 6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch) | |
tree | 3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/github.com/golang/freetype/example | |
parent | bf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff) | |
download | chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2 chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip |
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/github.com/golang/freetype/example')
8 files changed, 0 insertions, 1100 deletions
diff --git a/vendor/github.com/golang/freetype/example/capjoin/main.go b/vendor/github.com/golang/freetype/example/capjoin/main.go deleted file mode 100644 index 71f3356c7..000000000 --- a/vendor/github.com/golang/freetype/example/capjoin/main.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2016 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -package main - -import ( - "bufio" - "fmt" - "image" - "image/color" - "image/draw" - "image/png" - "log" - "os" - - "github.com/golang/freetype/raster" - "golang.org/x/image/math/fixed" -) - -func main() { - const ( - w = 400 - h = 400 - ) - r := raster.NewRasterizer(w, h) - r.UseNonZeroWinding = true - - cjs := []struct { - c raster.Capper - j raster.Joiner - }{ - {raster.RoundCapper, raster.RoundJoiner}, - {raster.ButtCapper, raster.BevelJoiner}, - {raster.SquareCapper, raster.BevelJoiner}, - } - - for i, cj := range cjs { - var path raster.Path - path.Start(fixed.P(30+100*i, 30+120*i)) - path.Add1(fixed.P(180+100*i, 80+120*i)) - path.Add1(fixed.P(50+100*i, 130+120*i)) - raster.Stroke(r, path, fixed.I(20), cj.c, cj.j) - } - - rgba := image.NewRGBA(image.Rect(0, 0, w, h)) - draw.Draw(rgba, rgba.Bounds(), image.Black, image.Point{}, draw.Src) - p := raster.NewRGBAPainter(rgba) - p.SetColor(color.RGBA{0x7f, 0x7f, 0x7f, 0xff}) - r.Rasterize(p) - - white := color.RGBA{0xff, 0xff, 0xff, 0xff} - for i := range cjs { - rgba.SetRGBA(30+100*i, 30+120*i, white) - rgba.SetRGBA(180+100*i, 80+120*i, white) - rgba.SetRGBA(50+100*i, 130+120*i, white) - } - - // Save that RGBA image to disk. - outFile, err := os.Create("out.png") - if err != nil { - log.Println(err) - os.Exit(1) - } - defer outFile.Close() - b := bufio.NewWriter(outFile) - err = png.Encode(b, rgba) - if err != nil { - log.Println(err) - os.Exit(1) - } - err = b.Flush() - if err != nil { - log.Println(err) - os.Exit(1) - } - fmt.Println("Wrote out.png OK.") -} diff --git a/vendor/github.com/golang/freetype/example/drawer/main.go b/vendor/github.com/golang/freetype/example/drawer/main.go deleted file mode 100644 index d26d066d9..000000000 --- a/vendor/github.com/golang/freetype/example/drawer/main.go +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2015 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -package main - -import ( - "bufio" - "flag" - "fmt" - "image" - "image/color" - "image/draw" - "image/png" - "io/ioutil" - "log" - "math" - "os" - - "github.com/golang/freetype/truetype" - "golang.org/x/image/font" - "golang.org/x/image/math/fixed" -) - -var ( - dpi = flag.Float64("dpi", 72, "screen resolution in Dots Per Inch") - fontfile = flag.String("fontfile", "../../testdata/luxisr.ttf", "filename of the ttf font") - hinting = flag.String("hinting", "none", "none | full") - size = flag.Float64("size", 12, "font size in points") - spacing = flag.Float64("spacing", 1.5, "line spacing (e.g. 2 means double spaced)") - wonb = flag.Bool("whiteonblack", false, "white text on a black background") -) - -const title = "Jabberwocky" - -var text = []string{ - "’Twas brillig, and the slithy toves", - "Did gyre and gimble in the wabe;", - "All mimsy were the borogoves,", - "And the mome raths outgrabe.", - "", - "“Beware the Jabberwock, my son!", - "The jaws that bite, the claws that catch!", - "Beware the Jubjub bird, and shun", - "The frumious Bandersnatch!”", - "", - "He took his vorpal sword in hand:", - "Long time the manxome foe he sought—", - "So rested he by the Tumtum tree,", - "And stood awhile in thought.", - "", - "And as in uffish thought he stood,", - "The Jabberwock, with eyes of flame,", - "Came whiffling through the tulgey wood,", - "And burbled as it came!", - "", - "One, two! One, two! and through and through", - "The vorpal blade went snicker-snack!", - "He left it dead, and with its head", - "He went galumphing back.", - "", - "“And hast thou slain the Jabberwock?", - "Come to my arms, my beamish boy!", - "O frabjous day! Callooh! Callay!”", - "He chortled in his joy.", - "", - "’Twas brillig, and the slithy toves", - "Did gyre and gimble in the wabe;", - "All mimsy were the borogoves,", - "And the mome raths outgrabe.", -} - -func main() { - flag.Parse() - - // Read the font data. - fontBytes, err := ioutil.ReadFile(*fontfile) - if err != nil { - log.Println(err) - return - } - f, err := truetype.Parse(fontBytes) - if err != nil { - log.Println(err) - return - } - - // Draw the background and the guidelines. - fg, bg := image.Black, image.White - ruler := color.RGBA{0xdd, 0xdd, 0xdd, 0xff} - if *wonb { - fg, bg = image.White, image.Black - ruler = color.RGBA{0x22, 0x22, 0x22, 0xff} - } - const imgW, imgH = 640, 480 - rgba := image.NewRGBA(image.Rect(0, 0, imgW, imgH)) - draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src) - for i := 0; i < 200; i++ { - rgba.Set(10, 10+i, ruler) - rgba.Set(10+i, 10, ruler) - } - - // Draw the text. - h := font.HintingNone - switch *hinting { - case "full": - h = font.HintingFull - } - d := &font.Drawer{ - Dst: rgba, - Src: fg, - Face: truetype.NewFace(f, &truetype.Options{ - Size: *size, - DPI: *dpi, - Hinting: h, - }), - } - y := 10 + int(math.Ceil(*size**dpi/72)) - dy := int(math.Ceil(*size * *spacing * *dpi / 72)) - d.Dot = fixed.Point26_6{ - X: (fixed.I(imgW) - d.MeasureString(title)) / 2, - Y: fixed.I(y), - } - d.DrawString(title) - y += dy - for _, s := range text { - d.Dot = fixed.P(10, y) - d.DrawString(s) - y += dy - } - - // Save that RGBA image to disk. - outFile, err := os.Create("out.png") - if err != nil { - log.Println(err) - os.Exit(1) - } - defer outFile.Close() - b := bufio.NewWriter(outFile) - err = png.Encode(b, rgba) - if err != nil { - log.Println(err) - os.Exit(1) - } - err = b.Flush() - if err != nil { - log.Println(err) - os.Exit(1) - } - fmt.Println("Wrote out.png OK.") -} diff --git a/vendor/github.com/golang/freetype/example/freetype/main.go b/vendor/github.com/golang/freetype/example/freetype/main.go deleted file mode 100644 index dfbde9a2f..000000000 --- a/vendor/github.com/golang/freetype/example/freetype/main.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2010 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -package main - -import ( - "bufio" - "flag" - "fmt" - "image" - "image/color" - "image/draw" - "image/png" - "io/ioutil" - "log" - "os" - - "github.com/golang/freetype" - "golang.org/x/image/font" -) - -var ( - dpi = flag.Float64("dpi", 72, "screen resolution in Dots Per Inch") - fontfile = flag.String("fontfile", "../../testdata/luxisr.ttf", "filename of the ttf font") - hinting = flag.String("hinting", "none", "none | full") - size = flag.Float64("size", 12, "font size in points") - spacing = flag.Float64("spacing", 1.5, "line spacing (e.g. 2 means double spaced)") - wonb = flag.Bool("whiteonblack", false, "white text on a black background") -) - -var text = []string{ - "’Twas brillig, and the slithy toves", - "Did gyre and gimble in the wabe;", - "All mimsy were the borogoves,", - "And the mome raths outgrabe.", - "", - "“Beware the Jabberwock, my son!", - "The jaws that bite, the claws that catch!", - "Beware the Jubjub bird, and shun", - "The frumious Bandersnatch!”", - "", - "He took his vorpal sword in hand:", - "Long time the manxome foe he sought—", - "So rested he by the Tumtum tree,", - "And stood awhile in thought.", - "", - "And as in uffish thought he stood,", - "The Jabberwock, with eyes of flame,", - "Came whiffling through the tulgey wood,", - "And burbled as it came!", - "", - "One, two! One, two! and through and through", - "The vorpal blade went snicker-snack!", - "He left it dead, and with its head", - "He went galumphing back.", - "", - "“And hast thou slain the Jabberwock?", - "Come to my arms, my beamish boy!", - "O frabjous day! Callooh! Callay!”", - "He chortled in his joy.", - "", - "’Twas brillig, and the slithy toves", - "Did gyre and gimble in the wabe;", - "All mimsy were the borogoves,", - "And the mome raths outgrabe.", -} - -func main() { - flag.Parse() - - // Read the font data. - fontBytes, err := ioutil.ReadFile(*fontfile) - if err != nil { - log.Println(err) - return - } - f, err := freetype.ParseFont(fontBytes) - if err != nil { - log.Println(err) - return - } - - // Initialize the context. - fg, bg := image.Black, image.White - ruler := color.RGBA{0xdd, 0xdd, 0xdd, 0xff} - if *wonb { - fg, bg = image.White, image.Black - ruler = color.RGBA{0x22, 0x22, 0x22, 0xff} - } - rgba := image.NewRGBA(image.Rect(0, 0, 640, 480)) - draw.Draw(rgba, rgba.Bounds(), bg, image.ZP, draw.Src) - c := freetype.NewContext() - c.SetDPI(*dpi) - c.SetFont(f) - c.SetFontSize(*size) - c.SetClip(rgba.Bounds()) - c.SetDst(rgba) - c.SetSrc(fg) - switch *hinting { - default: - c.SetHinting(font.HintingNone) - case "full": - c.SetHinting(font.HintingFull) - } - - // Draw the guidelines. - for i := 0; i < 200; i++ { - rgba.Set(10, 10+i, ruler) - rgba.Set(10+i, 10, ruler) - } - - // Draw the text. - pt := freetype.Pt(10, 10+int(c.PointToFixed(*size)>>6)) - for _, s := range text { - _, err = c.DrawString(s, pt) - if err != nil { - log.Println(err) - return - } - pt.Y += c.PointToFixed(*size * *spacing) - } - - // Save that RGBA image to disk. - outFile, err := os.Create("out.png") - if err != nil { - log.Println(err) - os.Exit(1) - } - defer outFile.Close() - b := bufio.NewWriter(outFile) - err = png.Encode(b, rgba) - if err != nil { - log.Println(err) - os.Exit(1) - } - err = b.Flush() - if err != nil { - log.Println(err) - os.Exit(1) - } - fmt.Println("Wrote out.png OK.") -} diff --git a/vendor/github.com/golang/freetype/example/gamma/main.go b/vendor/github.com/golang/freetype/example/gamma/main.go deleted file mode 100644 index cdd50bc3b..000000000 --- a/vendor/github.com/golang/freetype/example/gamma/main.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2010 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -package main - -import ( - "bufio" - "fmt" - "image" - "image/draw" - "image/png" - "log" - "os" - - "github.com/golang/freetype/raster" - "golang.org/x/image/math/fixed" -) - -func p(x, y int) fixed.Point26_6 { - return fixed.Point26_6{ - X: fixed.Int26_6(x * 64), - Y: fixed.Int26_6(y * 64), - } -} - -func main() { - // Draw a rounded corner that is one pixel wide. - r := raster.NewRasterizer(50, 50) - r.Start(p(5, 5)) - r.Add1(p(5, 25)) - r.Add2(p(5, 45), p(25, 45)) - r.Add1(p(45, 45)) - r.Add1(p(45, 44)) - r.Add1(p(26, 44)) - r.Add2(p(6, 44), p(6, 24)) - r.Add1(p(6, 5)) - r.Add1(p(5, 5)) - - // Rasterize that curve multiple times at different gammas. - const ( - w = 600 - h = 200 - ) - rgba := image.NewRGBA(image.Rect(0, 0, w, h)) - draw.Draw(rgba, image.Rect(0, 0, w, h/2), image.Black, image.ZP, draw.Src) - draw.Draw(rgba, image.Rect(0, h/2, w, h), image.White, image.ZP, draw.Src) - mask := image.NewAlpha(image.Rect(0, 0, 50, 50)) - painter := raster.NewAlphaSrcPainter(mask) - gammas := []float64{1.0 / 10.0, 1.0 / 3.0, 1.0 / 2.0, 2.0 / 3.0, 4.0 / 5.0, 1.0, 5.0 / 4.0, 3.0 / 2.0, 2.0, 3.0, 10.0} - for i, g := range gammas { - draw.Draw(mask, mask.Bounds(), image.Transparent, image.ZP, draw.Src) - r.Rasterize(raster.NewGammaCorrectionPainter(painter, g)) - x, y := 50*i+25, 25 - draw.DrawMask(rgba, image.Rect(x, y, x+50, y+50), image.White, image.ZP, mask, image.ZP, draw.Over) - y += 100 - draw.DrawMask(rgba, image.Rect(x, y, x+50, y+50), image.Black, image.ZP, mask, image.ZP, draw.Over) - } - - // Save that RGBA image to disk. - outFile, err := os.Create("out.png") - if err != nil { - log.Println(err) - os.Exit(1) - } - defer outFile.Close() - b := bufio.NewWriter(outFile) - err = png.Encode(b, rgba) - if err != nil { - log.Println(err) - os.Exit(1) - } - err = b.Flush() - if err != nil { - log.Println(err) - os.Exit(1) - } - fmt.Println("Wrote out.png OK.") -} diff --git a/vendor/github.com/golang/freetype/example/genbasicfont/main.go b/vendor/github.com/golang/freetype/example/genbasicfont/main.go deleted file mode 100644 index 5b2f2bc6f..000000000 --- a/vendor/github.com/golang/freetype/example/genbasicfont/main.go +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright 2016 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -// Program genbasicfont generates Go source code that imports -// golang.org/x/image/font/basicfont to provide a fixed width font face. -package main - -import ( - "bytes" - "flag" - "fmt" - "go/format" - "image" - "image/draw" - "io/ioutil" - "log" - "net/http" - "strings" - "unicode" - - "github.com/golang/freetype/truetype" - "golang.org/x/image/font" - "golang.org/x/image/math/fixed" -) - -var ( - fontfile = flag.String("fontfile", "../../testdata/luxisr.ttf", "filename or URL of the TTF font") - hinting = flag.String("hinting", "none", "none, vertical or full") - pkg = flag.String("pkg", "example", "the package name for the generated code") - size = flag.Float64("size", 12, "the number of pixels in 1 em") - vr = flag.String("var", "example", "the variable name for the generated code") -) - -func loadFontFile() ([]byte, error) { - if strings.HasPrefix(*fontfile, "http://") || strings.HasPrefix(*fontfile, "https://") { - resp, err := http.Get(*fontfile) - if err != nil { - return nil, err - } - defer resp.Body.Close() - return ioutil.ReadAll(resp.Body) - } - return ioutil.ReadFile(*fontfile) -} - -func parseHinting(h string) font.Hinting { - switch h { - case "full": - return font.HintingFull - case "vertical": - log.Fatal("TODO: have package truetype implement vertical hinting") - return font.HintingVertical - } - return font.HintingNone -} - -func privateUseArea(r rune) bool { - return 0xe000 <= r && r <= 0xf8ff || - 0xf0000 <= r && r <= 0xffffd || - 0x100000 <= r && r <= 0x10fffd -} - -func loadRanges(f *truetype.Font) (ret [][2]rune) { - rr := [2]rune{-1, -1} - for r := rune(0); r <= unicode.MaxRune; r++ { - if privateUseArea(r) { - continue - } - if f.Index(r) == 0 { - continue - } - if rr[1] == r { - rr[1] = r + 1 - continue - } - if rr[0] != -1 { - ret = append(ret, rr) - } - rr = [2]rune{r, r + 1} - } - if rr[0] != -1 { - ret = append(ret, rr) - } - return ret -} - -func emptyCol(m *image.Gray, r image.Rectangle, x int) bool { - for y := r.Min.Y; y < r.Max.Y; y++ { - if m.GrayAt(x, y).Y > 0 { - return false - } - } - return true -} - -func emptyRow(m *image.Gray, r image.Rectangle, y int) bool { - for x := r.Min.X; x < r.Max.X; x++ { - if m.GrayAt(x, y).Y > 0 { - return false - } - } - return true -} - -func tightBounds(m *image.Gray) (r image.Rectangle) { - r = m.Bounds() - for ; r.Min.Y < r.Max.Y && emptyRow(m, r, r.Min.Y+0); r.Min.Y++ { - } - for ; r.Min.Y < r.Max.Y && emptyRow(m, r, r.Max.Y-1); r.Max.Y-- { - } - for ; r.Min.X < r.Max.X && emptyCol(m, r, r.Min.X+0); r.Min.X++ { - } - for ; r.Min.X < r.Max.X && emptyCol(m, r, r.Max.X-1); r.Max.X-- { - } - return r -} - -func printPix(ranges [][2]rune, glyphs map[rune]*image.Gray, b image.Rectangle) []byte { - buf := new(bytes.Buffer) - for _, rr := range ranges { - for r := rr[0]; r < rr[1]; r++ { - m := glyphs[r] - fmt.Fprintf(buf, "// U+%08x '%c'\n", r, r) - for y := b.Min.Y; y < b.Max.Y; y++ { - for x := b.Min.X; x < b.Max.X; x++ { - fmt.Fprintf(buf, "%#02x, ", m.GrayAt(x, y).Y) - } - fmt.Fprintln(buf) - } - fmt.Fprintln(buf) - } - } - return buf.Bytes() -} - -func printRanges(ranges [][2]rune) []byte { - buf := new(bytes.Buffer) - offset := 0 - for _, rr := range ranges { - fmt.Fprintf(buf, "{'\\U%08x', '\\U%08x', %d},\n", rr[0], rr[1], offset) - offset += int(rr[1] - rr[0]) - } - return buf.Bytes() -} - -func main() { - flag.Parse() - b, err := loadFontFile() - if err != nil { - log.Fatal(err) - } - f, err := truetype.Parse(b) - if err != nil { - log.Fatal(err) - } - face := truetype.NewFace(f, &truetype.Options{ - Size: *size, - Hinting: parseHinting(*hinting), - }) - defer face.Close() - - fBounds := f.Bounds(fixed.Int26_6(*size * 64)) - iBounds := image.Rect( - +fBounds.Min.X.Floor(), - -fBounds.Max.Y.Ceil(), - +fBounds.Max.X.Ceil(), - -fBounds.Min.Y.Floor(), - ) - - tBounds := image.Rectangle{} - glyphs := map[rune]*image.Gray{} - advance := fixed.Int26_6(-1) - - ranges := loadRanges(f) - for _, rr := range ranges { - for r := rr[0]; r < rr[1]; r++ { - dr, mask, maskp, adv, ok := face.Glyph(fixed.Point26_6{}, r) - if !ok { - log.Fatalf("could not load glyph for %U", r) - } - if advance < 0 { - advance = adv - } else if advance != adv { - log.Fatalf("advance was not constant: got %v and %v", advance, adv) - } - dst := image.NewGray(iBounds) - draw.DrawMask(dst, dr, image.White, image.Point{}, mask, maskp, draw.Src) - glyphs[r] = dst - tBounds = tBounds.Union(tightBounds(dst)) - } - } - - // height is the glyph image height, not the inter-line spacing. - width, height := tBounds.Dx(), tBounds.Dy() - - buf := new(bytes.Buffer) - fmt.Fprintf(buf, "// generated by go generate; DO NOT EDIT.\n\npackage %s\n\n", *pkg) - fmt.Fprintf(buf, "import (\n\"image\"\n\n\"golang.org/x/image/font/basicfont\"\n)\n\n") - fmt.Fprintf(buf, "// %s contains %d %d×%d glyphs in %d Pix bytes.\n", - *vr, len(glyphs), width, height, len(glyphs)*width*height) - fmt.Fprintf(buf, `var %s = basicfont.Face{ - Advance: %d, - Width: %d, - Height: %d, - Ascent: %d, - Descent: %d, - Left: %d, - Mask: &image.Alpha{ - Stride: %d, - Rect: image.Rectangle{Max: image.Point{%d, %d*%d}}, - Pix: []byte{ - %s - }, - }, - Ranges: []basicfont.Range{ - %s - }, - }`, *vr, advance.Ceil(), width, face.Metrics().Height.Ceil(), -tBounds.Min.Y, +tBounds.Max.Y, tBounds.Min.X, - width, width, len(glyphs), height, - printPix(ranges, glyphs, tBounds), printRanges(ranges)) - - fmted, err := format.Source(buf.Bytes()) - if err != nil { - log.Fatalf("format.Source: %v", err) - } - if err := ioutil.WriteFile(*vr+".go", fmted, 0644); err != nil { - log.Fatalf("ioutil.WriteFile: %v", err) - } -} diff --git a/vendor/github.com/golang/freetype/example/raster/main.go b/vendor/github.com/golang/freetype/example/raster/main.go deleted file mode 100644 index 3e572e1c5..000000000 --- a/vendor/github.com/golang/freetype/example/raster/main.go +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright 2010 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -package main - -import ( - "bufio" - "fmt" - "image" - "image/color" - "image/draw" - "image/png" - "log" - "os" - - "github.com/golang/freetype/raster" - "golang.org/x/image/math/fixed" -) - -type node struct { - x, y, degree int -} - -// These contours "outside" and "inside" are from the 'A' glyph from the Droid -// Serif Regular font. - -var outside = []node{ - node{414, 489, 1}, - node{336, 274, 2}, - node{327, 250, 0}, - node{322, 226, 2}, - node{317, 203, 0}, - node{317, 186, 2}, - node{317, 134, 0}, - node{350, 110, 2}, - node{384, 86, 0}, - node{453, 86, 1}, - node{500, 86, 1}, - node{500, 0, 1}, - node{0, 0, 1}, - node{0, 86, 1}, - node{39, 86, 2}, - node{69, 86, 0}, - node{90, 92, 2}, - node{111, 99, 0}, - node{128, 117, 2}, - node{145, 135, 0}, - node{160, 166, 2}, - node{176, 197, 0}, - node{195, 246, 1}, - node{649, 1462, 1}, - node{809, 1462, 1}, - node{1272, 195, 2}, - node{1284, 163, 0}, - node{1296, 142, 2}, - node{1309, 121, 0}, - node{1326, 108, 2}, - node{1343, 96, 0}, - node{1365, 91, 2}, - node{1387, 86, 0}, - node{1417, 86, 1}, - node{1444, 86, 1}, - node{1444, 0, 1}, - node{881, 0, 1}, - node{881, 86, 1}, - node{928, 86, 2}, - node{1051, 86, 0}, - node{1051, 184, 2}, - node{1051, 201, 0}, - node{1046, 219, 2}, - node{1042, 237, 0}, - node{1034, 260, 1}, - node{952, 489, 1}, - node{414, 489, -1}, -} - -var inside = []node{ - node{686, 1274, 1}, - node{453, 592, 1}, - node{915, 592, 1}, - node{686, 1274, -1}, -} - -func p(n node) fixed.Point26_6 { - x, y := 20+n.x/4, 380-n.y/4 - return fixed.Point26_6{ - X: fixed.Int26_6(x << 6), - Y: fixed.Int26_6(y << 6), - } -} - -func contour(r *raster.Rasterizer, ns []node) { - if len(ns) == 0 { - return - } - i := 0 - r.Start(p(ns[i])) - for { - switch ns[i].degree { - case -1: - // -1 signifies end-of-contour. - return - case 1: - i += 1 - r.Add1(p(ns[i])) - case 2: - i += 2 - r.Add2(p(ns[i-1]), p(ns[i])) - default: - panic("bad degree") - } - } -} - -func showNodes(m *image.RGBA, ns []node) { - for _, n := range ns { - p := p(n) - x, y := int(p.X)/64, int(p.Y)/64 - if !(image.Point{x, y}).In(m.Bounds()) { - continue - } - var c color.Color - switch n.degree { - case 0: - c = color.RGBA{0, 255, 255, 255} - case 1: - c = color.RGBA{255, 0, 0, 255} - case 2: - c = color.RGBA{255, 0, 0, 255} - } - if c != nil { - m.Set(x, y, c) - } - } -} - -func main() { - // Rasterize the contours to a mask image. - const ( - w = 400 - h = 400 - ) - r := raster.NewRasterizer(w, h) - contour(r, outside) - contour(r, inside) - mask := image.NewAlpha(image.Rect(0, 0, w, h)) - p := raster.NewAlphaSrcPainter(mask) - r.Rasterize(p) - - // Draw the mask image (in gray) onto an RGBA image. - rgba := image.NewRGBA(image.Rect(0, 0, w, h)) - gray := image.NewUniform(color.Alpha{0x1f}) - draw.Draw(rgba, rgba.Bounds(), image.Black, image.ZP, draw.Src) - draw.DrawMask(rgba, rgba.Bounds(), gray, image.ZP, mask, image.ZP, draw.Over) - showNodes(rgba, outside) - showNodes(rgba, inside) - - // Save that RGBA image to disk. - outFile, err := os.Create("out.png") - if err != nil { - log.Println(err) - os.Exit(1) - } - defer outFile.Close() - b := bufio.NewWriter(outFile) - err = png.Encode(b, rgba) - if err != nil { - log.Println(err) - os.Exit(1) - } - err = b.Flush() - if err != nil { - log.Println(err) - os.Exit(1) - } - fmt.Println("Wrote out.png OK.") -} diff --git a/vendor/github.com/golang/freetype/example/round/main.go b/vendor/github.com/golang/freetype/example/round/main.go deleted file mode 100644 index 2920e8335..000000000 --- a/vendor/github.com/golang/freetype/example/round/main.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2010 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -// This program visualizes the quadratic approximation to the circle, used to -// implement round joins when stroking paths. The approximation is used in the -// stroking code for arcs between 0 and 45 degrees, but is visualized here -// between 0 and 90 degrees. The discrepancy between the approximation and the -// true circle is clearly visible at angles above 65 degrees. -package main - -import ( - "bufio" - "fmt" - "image" - "image/color" - "image/draw" - "image/png" - "log" - "math" - "os" - - "github.com/golang/freetype/raster" - "golang.org/x/image/math/fixed" -) - -// pDot returns the dot product p·q. -func pDot(p, q fixed.Point26_6) fixed.Int52_12 { - px, py := int64(p.X), int64(p.Y) - qx, qy := int64(q.X), int64(q.Y) - return fixed.Int52_12(px*qx + py*qy) -} - -func main() { - const ( - n = 17 - r = 64 * 80 - ) - s := fixed.Int26_6(r * math.Sqrt(2) / 2) - t := fixed.Int26_6(r * math.Tan(math.Pi/8)) - - m := image.NewRGBA(image.Rect(0, 0, 800, 600)) - draw.Draw(m, m.Bounds(), image.NewUniform(color.RGBA{63, 63, 63, 255}), image.ZP, draw.Src) - mp := raster.NewRGBAPainter(m) - mp.SetColor(image.Black) - z := raster.NewRasterizer(800, 600) - - for i := 0; i < n; i++ { - cx := fixed.Int26_6(6400 + 12800*(i%4)) - cy := fixed.Int26_6(640 + 8000*(i/4)) - c := fixed.Point26_6{X: cx, Y: cy} - theta := math.Pi * (0.5 + 0.5*float64(i)/(n-1)) - dx := fixed.Int26_6(r * math.Cos(theta)) - dy := fixed.Int26_6(r * math.Sin(theta)) - d := fixed.Point26_6{X: dx, Y: dy} - // Draw a quarter-circle approximated by two quadratic segments, - // with each segment spanning 45 degrees. - z.Start(c) - z.Add1(c.Add(fixed.Point26_6{X: r, Y: 0})) - z.Add2(c.Add(fixed.Point26_6{X: r, Y: t}), c.Add(fixed.Point26_6{X: s, Y: s})) - z.Add2(c.Add(fixed.Point26_6{X: t, Y: r}), c.Add(fixed.Point26_6{X: 0, Y: r})) - // Add another quadratic segment whose angle ranges between 0 and 90 - // degrees. For an explanation of the magic constants 128, 150, 181 and - // 256, read the comments in the freetype/raster package. - dot := 256 * pDot(d, fixed.Point26_6{X: 0, Y: r}) / (r * r) - multiple := fixed.Int26_6(150-(150-128)*(dot-181)/(256-181)) >> 2 - z.Add2(c.Add(fixed.Point26_6{X: dx, Y: r + dy}.Mul(multiple)), c.Add(d)) - // Close the curve. - z.Add1(c) - } - z.Rasterize(mp) - - for i := 0; i < n; i++ { - cx := fixed.Int26_6(6400 + 12800*(i%4)) - cy := fixed.Int26_6(640 + 8000*(i/4)) - for j := 0; j < n; j++ { - theta := math.Pi * float64(j) / (n - 1) - dx := fixed.Int26_6(r * math.Cos(theta)) - dy := fixed.Int26_6(r * math.Sin(theta)) - m.Set(int((cx+dx)/64), int((cy+dy)/64), color.RGBA{255, 255, 0, 255}) - } - } - - // Save that RGBA image to disk. - outFile, err := os.Create("out.png") - if err != nil { - log.Println(err) - os.Exit(1) - } - defer outFile.Close() - b := bufio.NewWriter(outFile) - err = png.Encode(b, m) - if err != nil { - log.Println(err) - os.Exit(1) - } - err = b.Flush() - if err != nil { - log.Println(err) - os.Exit(1) - } - fmt.Println("Wrote out.png OK.") -} diff --git a/vendor/github.com/golang/freetype/example/truetype/main.go b/vendor/github.com/golang/freetype/example/truetype/main.go deleted file mode 100644 index e7db2d0ca..000000000 --- a/vendor/github.com/golang/freetype/example/truetype/main.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2010 The Freetype-Go Authors. All rights reserved. -// Use of this source code is governed by your choice of either the -// FreeType License or the GNU General Public License version 2 (or -// any later version), both of which can be found in the LICENSE file. - -// +build example -// -// This build tag means that "go install github.com/golang/freetype/..." -// doesn't install this example program. Use "go run main.go" to run it or "go -// install -tags=example" to install it. - -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "log" - - "github.com/golang/freetype/truetype" - "golang.org/x/image/font" - "golang.org/x/image/math/fixed" -) - -var fontfile = flag.String("fontfile", "../../testdata/luxisr.ttf", "filename of the ttf font") - -func printBounds(b fixed.Rectangle26_6) { - fmt.Printf("Min.X:%d Min.Y:%d Max.X:%d Max.Y:%d\n", b.Min.X, b.Min.Y, b.Max.X, b.Max.Y) -} - -func printGlyph(g *truetype.GlyphBuf) { - printBounds(g.Bounds) - fmt.Print("Points:\n---\n") - e := 0 - for i, p := range g.Points { - fmt.Printf("%4d, %4d", p.X, p.Y) - if p.Flags&0x01 != 0 { - fmt.Print(" on\n") - } else { - fmt.Print(" off\n") - } - if i+1 == int(g.Ends[e]) { - fmt.Print("---\n") - e++ - } - } -} - -func main() { - flag.Parse() - fmt.Printf("Loading fontfile %q\n", *fontfile) - b, err := ioutil.ReadFile(*fontfile) - if err != nil { - log.Println(err) - return - } - f, err := truetype.Parse(b) - if err != nil { - log.Println(err) - return - } - fupe := fixed.Int26_6(f.FUnitsPerEm()) - printBounds(f.Bounds(fupe)) - fmt.Printf("FUnitsPerEm:%d\n\n", fupe) - - c0, c1 := 'A', 'V' - - i0 := f.Index(c0) - hm := f.HMetric(fupe, i0) - g := &truetype.GlyphBuf{} - err = g.Load(f, fupe, i0, font.HintingNone) - if err != nil { - log.Println(err) - return - } - fmt.Printf("'%c' glyph\n", c0) - fmt.Printf("AdvanceWidth:%d LeftSideBearing:%d\n", hm.AdvanceWidth, hm.LeftSideBearing) - printGlyph(g) - i1 := f.Index(c1) - fmt.Printf("\n'%c', '%c' Kern:%d\n", c0, c1, f.Kern(fupe, i0, i1)) - - fmt.Printf("\nThe numbers above are in FUnits.\n" + - "The numbers below are in 26.6 fixed point pixels, at 12pt and 72dpi.\n\n") - a := truetype.NewFace(f, &truetype.Options{ - Size: 12, - DPI: 72, - }) - fmt.Printf("%#v\n", a.Metrics()) -} |