// 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" "git.fromouter.space/crunchy-rocks/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", 20, "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{ "Single glyph emoji: ๐Ÿ˜‚", "Gender-modified emoji: ๐Ÿ’‚โ€โ™€๏ธ", "Skin-modified emoji: ๐Ÿ–๐Ÿฝ", "Mixed emoji: ๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง", "๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€๐Ÿ‘Œ๐Ÿ‘€ good shit goเฑฆิ sHit๐Ÿ‘Œ thats โœ” some good๐Ÿ‘Œ๐Ÿ‘Œshit right๐Ÿ‘Œ๐Ÿ‘Œ", "th ๐Ÿ‘Œ ere๐Ÿ‘Œ๐Ÿ‘Œ๐Ÿ‘Œ rightโœ”there โœ”โœ”if i doโ€Šฦฝaาฏ soโ€‡my sel๏ฝ† ๐Ÿ’ฏ i say so ", "๐Ÿ’ฏ thats what im talking about right there right there (chorus: สณแถฆแตสฐแต— แต—สฐแต‰สณแต‰)", "mMMMMแŽทะœ๐Ÿ’ฏ ๐Ÿ‘Œ๐Ÿ‘Œ ๐Ÿ‘ŒะO0ะžเฌ ๏ผฏOO๏ผฏOะžเฌ เฌ Ooooแต’แต’แต’แต’แต’แต’แต’แต’แต’๐Ÿ‘Œ ๐Ÿ‘Œ๐Ÿ‘Œ ๐Ÿ‘Œ ๐Ÿ’ฏ ๐Ÿ‘Œ ๐Ÿ‘€ ๐Ÿ‘€ ๐Ÿ‘€ ๐Ÿ‘Œ๐Ÿ‘ŒGood shit", } 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.") }