本文整理匯總了Golang中github.com/golang/freetype/truetype.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setup
func (m *Module) setup() (err error) {
// Retrieve the default system font, encoded as a TTF.
ttfBytes := font.Default()
m.font, err = truetype.Parse(ttfBytes)
return err
}
示例2: main
func main() {
flag.Parse()
fmt.Printf("Loading fontfile %q\n", *fontfile)
b, err := ioutil.ReadFile(*fontfile)
if err != nil {
log.Println(err)
return
}
font, err := truetype.Parse(b)
if err != nil {
log.Println(err)
return
}
fupe := font.FUnitsPerEm()
printBounds(font.Bounds(fupe))
fmt.Printf("FUnitsPerEm:%d\n\n", fupe)
c0, c1 := 'A', 'V'
i0 := font.Index(c0)
hm := font.HMetric(fupe, i0)
g := truetype.NewGlyphBuf()
err = g.Load(font, fupe, i0, truetype.NoHinting)
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 := font.Index(c1)
fmt.Printf("\n'%c', '%c' Kerning:%d\n", c0, c1, font.Kerning(fupe, i0, i1))
}
示例3: Fuzz
func Fuzz(data []byte) int {
f, err := truetype.Parse(data)
if err != nil {
if f != nil {
panic("font is not nil on error")
}
return 0
}
return 1
}
示例4: init
func init() {
var err error
fnt, err = truetype.Parse(fonts.OpenSansLightBytes())
if err != nil {
log.Println(err)
return
}
DefaultBackgroundColor, _ = ColorFromHex("#909090")
lightDark, _ = ColorFromHex("#505050")
}
示例5: LoadFont
func LoadFont(name, file string) error {
f, err := ioutil.ReadFile(file)
if err != nil {
return err
}
font, err := truetype.Parse(f)
if err != nil {
return err
}
draw2d.RegisterFont(draw2d.FontData{Name: name}, font)
return nil
}
示例6: init
func init() {
luximrTTF, err := truetype.Parse(luximr)
if err != nil {
common.UsageAndExit("failed to parse luximir font: %s", err)
}
luximr = nil // kill 72Kb of font data
draw2d.RegisterFont(
draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleNormal},
luximrTTF,
)
}
示例7: init
func init() {
fontBytes, err := ioutil.ReadFile("brush_strokes.ttf")
if err != nil {
panic(err)
}
strokeFont, err = truetype.Parse(fontBytes)
if err != nil {
panic(err)
}
spb, err := ioutil.ReadFile("SansPosterBold.ttf")
if err != nil {
panic(err)
}
posterFont, err = truetype.Parse(spb)
if err != nil {
panic(err)
}
}
示例8: LoadFont
func LoadFont(name, path string) error {
fontBytes, err := ioutil.ReadFile(path)
if err != nil {
return err
}
theFont, err = truetype.Parse(fontBytes)
if err != nil {
return err
}
FontName = name
return nil
}
示例9: parseFont
// parseFont parse the font file as *truetype.Font (TTF)
func parseFont(fontFile string) (*truetype.Font, error) {
fontBytes, err := ioutil.ReadFile(fontFile)
if err != nil {
return nil, err
}
font, err := truetype.Parse(fontBytes)
if err != nil {
return nil, err
}
return font, nil
}
示例10: readFont
func readFont(s string) (*truetype.Font, error) {
b, err := ioutil.ReadFile(s)
if err != nil {
return nil, err
}
f, err := truetype.Parse(b)
if err != nil {
return nil, err
}
return f, nil
}
示例11: loadFont
func loadFont(fontFileName string) *truetype.Font {
fontBytes, err := ioutil.ReadFile(path.Join(fontFolder, fontFileName))
if err != nil {
log.Println(err)
return nil
}
font, err := truetype.Parse(fontBytes)
if err != nil {
log.Println(err)
return nil
}
return font
}
示例12: getTTF
// read the font file as *truetype.Font
func getTTF(fontFile string) (*truetype.Font, error) {
fontBytes, err := ioutil.ReadFile(fontFile)
if err != nil {
return nil, err
}
ttf, err := truetype.Parse(fontBytes)
if err != nil {
return nil, err
}
return ttf, nil
}
示例13: loadFontFace
// from fogleman/gg
func loadFontFace(path string, points float64) (font.Face, error) {
fontBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
f, err := truetype.Parse(fontBytes)
if err != nil {
return nil, err
}
face := truetype.NewFace(f, &truetype.Options{
Size: points,
Hinting: font.HintingFull,
})
return face, nil
}
示例14: Load
func (cache *defaultFontCache) Load(fontData FontData) (font *truetype.Font, err error) {
var data []byte
var file = cache.namer(fontData)
if data, err = ioutil.ReadFile(filepath.Join(cache.folder, file)); err != nil {
return
}
if font, err = truetype.Parse(data); err != nil {
return
}
cache.fonts[file] = font
return
}
示例15: loadFont
func loadFont(fontFile string) FontInfo {
// Read the font data.
fontBytes, err := ioutil.ReadFile(fontFile)
if err != nil {
log.Println(err)
return FontInfo{}
}
f, err := truetype.Parse(fontBytes)
if err != nil {
log.Println(err)
return FontInfo{}
}
return FontInfo(*f)
}