本文整理汇总了Golang中golang.org/x/image/math/fixed.I函数的典型用法代码示例。如果您正苦于以下问题:Golang I函数的具体用法?Golang I怎么用?Golang I使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Metrics
func (f *Face) Metrics() font.Metrics {
return font.Metrics{
Height: fixed.I(f.Height),
Ascent: fixed.I(f.Ascent),
Descent: fixed.I(f.Descent),
}
}
开发者ID:Rudloff,项目名称:platform,代码行数:7,代码来源:basicfont.go
示例2: Metrics
func (f *subface) Metrics() font.Metrics {
return font.Metrics{
Height: fixed.I(f.height),
Ascent: fixed.I(f.ascent),
Descent: fixed.I(f.height - f.ascent),
}
}
开发者ID:Rudloff,项目名称:platform,代码行数:7,代码来源:plan9font.go
示例3: generateImage
func generateImage(params Params) image.Image {
fgColor := white
var detectedFont *truetype.Font
if []rune(params.text)[0] > '\u2E7F' {
detectedFont = cjkFont
} else {
detectedFont = defaultFont
}
fontSize := float64(params.size) * 0.5
img := image.NewRGBA(image.Rect(0, 0, params.size, params.size))
if params.seed != 0 {
rand.Seed(params.seed)
}
var bgColor color.RGBA
if params.color == (color.RGBA{}) {
bgColor = colors[rand.Intn(len(colors))]
} else {
bgColor = params.color
}
if params.border {
bgColor, fgColor = fgColor, bgColor
}
draw.Draw(img, img.Bounds(), &image.Uniform{bgColor}, image.ZP, draw.Src)
if params.border {
strokeWidth := fontSize * 0.08
circleSize := fontSize * 0.92
arcAngle := math.Pi * 2
gc := draw2dimg.NewGraphicContext(img)
gc.SetStrokeColor(fgColor)
gc.SetLineWidth(strokeWidth)
gc.ArcTo(fontSize, fontSize, circleSize, circleSize, arcAngle, arcAngle)
gc.Stroke()
}
d := &font.Drawer{
Dst: img,
Src: image.NewUniform(fgColor),
Face: truetype.NewFace(detectedFont, &truetype.Options{
Size: fontSize,
DPI: 72,
}),
}
d.Dot = fixed.Point26_6{
X: (fixed.I(params.size) - d.MeasureString(params.text)) / 2,
Y: fixed.I(int(math.Ceil(fontSize * 1.35))),
}
d.DrawString(params.text)
return img
}
开发者ID:mgeist,项目名称:go-defaulter,代码行数:59,代码来源:image.go
示例4: TestRunReaderEndOfLine
func TestRunReaderEndOfLine(t *testing.T) {
f := truetype.NewFace(clearSans, nil)
defer f.Close()
c := NewReader(strings.NewReader("Hello World!\nHow are you doing?"),
Style{Offset: 0, Face: f, Foreground: image.Black, Background: image.White},
Style{Offset: 5, Face: f, Foreground: image.White},
)
r := NewRunReader(c, nil, fixed.Rectangle26_6{
Min: fixed.Point26_6{X: fixed.I(1), Y: fixed.I(1)},
Max: fixed.Point26_6{X: fixed.I(600), Y: fixed.I(600)},
})
var run Run
var err error
if run, err = r.ReadRun(); err != nil {
t.Error(run, err)
}
if run != (Run{
Offset: 0,
Text: "Hello",
Face: f,
Foreground: image.Black,
Background: image.White,
Bounds: fixed.Rectangle26_6{
Min: fixed.Point26_6{X: int26_6(1, 0), Y: int26_6(1, 0)},
Max: fixed.Point26_6{X: int26_6(28, 37), Y: int26_6(13, 0)},
},
}) {
t.Error("invalid first run:", run)
}
if run, err = r.ReadRun(); err != nil {
t.Error(run, err)
}
if run != (Run{
Offset: 5,
Text: " World!",
Face: f,
Foreground: image.White,
Background: image.White,
Bounds: fixed.Rectangle26_6{
Min: fixed.Point26_6{X: int26_6(28, 37), Y: int26_6(1, 0)},
Max: fixed.Point26_6{X: int26_6(65, 55), Y: int26_6(13, 0)},
},
}) {
t.Error("invalid second run:", run)
}
if _, err = r.ReadRun(); err != io.EOF {
t.Error(err)
}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:57,代码来源:run_test.go
示例5: Render
func (c *Context) Render(txt string, size float64, col color.Color) (*image.RGBA, error) {
bnd := c.fnt.Bounds(fixed.I(int(size + 0.5)))
lh := int26_6ToFloat64(bnd.Max.Y) - int26_6ToFloat64(bnd.Min.Y) - 0.5
c.ft.SetSrc(image.NewUniform(col))
c.ft.SetFontSize(size)
/* Render image to temporary buffer to determine final size */
tmp := nullImage{}
c.ft.SetDst(tmp)
c.ft.SetClip(tmp.Bounds())
p, err := c.ft.DrawString(txt, fixed.P(0, int(lh)))
if err != nil {
return nil, err
}
dst := image.NewRGBA(image.Rect(0, 0, int(int26_6ToFloat64(p.X)+0.5), int(lh)))
draw.Draw(dst, dst.Bounds(), image.NewUniform(color.RGBA{}), image.ZP, draw.Src)
c.ft.SetDst(dst)
c.ft.SetClip(dst.Bounds())
p, err = c.ft.DrawString(txt, fixed.P(0, int(size)))
if err != nil {
return nil, err
}
return dst, nil
}
开发者ID:farhaven,项目名称:universe,代码行数:28,代码来源:text.go
示例6: NewFontFace
func NewFontFace(path string, pixels float32, fg, bg color.Color) (fontface *FontFace, err error) {
var (
font *truetype.Font
fontbytes []byte
bounds fixed.Rectangle26_6
context *freetype.Context
points float32
dpi float32 = 96
)
if fontbytes, err = ioutil.ReadFile(path); err != nil {
return
}
if font, err = freetype.ParseFont(fontbytes); err != nil {
return
}
points = pixels * 72 / dpi
bounds = font.Bounds(fixed.I(int(pixels)))
context = freetype.NewContext()
context.SetFont(font)
context.SetFontSize(float64(points))
context.SetDPI(float64(dpi))
fontface = &FontFace{
font: font,
charw: float32(bounds.Max.X-bounds.Min.X) / 64,
charh: float32(bounds.Max.Y-bounds.Min.Y) / 64,
offy: float32(bounds.Min.Y) / 64,
fg: fg,
bg: bg,
context: context,
}
return
}
开发者ID:kurrik,项目名称:opengl-benchmarks,代码行数:32,代码来源:fontface.go
示例7: Glyph
func (f *Face) Glyph(dot fixed.Point26_6, r rune) (
dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool) {
loop:
for _, rr := range [2]rune{r, '\ufffd'} {
for _, rng := range f.Ranges {
if rr < rng.Low || rng.High <= rr {
continue
}
maskp.Y = (int(rr-rng.Low) + rng.Offset) * f.Height
ok = true
break loop
}
}
if !ok {
return image.Rectangle{}, nil, image.Point{}, 0, false
}
minX := int(dot.X+32) >> 6
minY := int(dot.Y+32)>>6 - f.Ascent
dr = image.Rectangle{
Min: image.Point{
X: minX,
Y: minY,
},
Max: image.Point{
X: minX + f.Width,
Y: minY + f.Height,
},
}
return dr, f.Mask, maskp, fixed.I(f.Advance), true
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:33,代码来源:basicfont.go
示例8: TestLineReaderEmpty
func TestLineReaderEmpty(t *testing.T) {
f := truetype.NewFace(clearSans, nil)
defer f.Close()
c := NewReader(strings.NewReader(""),
Style{Offset: 0, Face: f, Foreground: image.Black, Background: image.White},
)
r := NewLineReader(c, nil, fixed.Rectangle26_6{
Min: fixed.Point26_6{X: fixed.I(1), Y: fixed.I(1)},
Max: fixed.Point26_6{X: fixed.I(600), Y: fixed.I(600)},
})
if _, err := r.ReadLine(); err != io.EOF {
t.Error(err)
}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:17,代码来源:line_test.go
示例9: main
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.")
}
开发者ID:ReinhardHsu,项目名称:platform,代码行数:58,代码来源:main.go
示例10: renderTransitRouteName
// renderTransitRouteName will render the name of the route in the top left corner.
func (m *Module) renderTransitRouteName(rgba *image.RGBA, dimensions image.Point, text string) {
d := &font.Drawer{
Dst: rgba,
Src: foreground,
Face: truetype.NewFace(m.font, &truetype.Options{
Size: transitRouteNameFontSize,
DPI: dpi,
Hinting: font.HintingNone,
}),
}
dy := int(math.Ceil(transitRouteNameFontSize * dpi / 72))
// I can't figure out how to get rid of the annoying notification bar. For now, the Y offset here
// needs to include the height of the notification bar which is 48dp ~= 0.3in.
d.Dot = fixed.Point26_6{
X: fixed.I(5),
Y: fixed.I(int(math.Ceil(0.3*float64(dpi))) + dy),
}
d.DrawString(text)
}
开发者ID:jbowens,项目名称:muni-display,代码行数:20,代码来源:render.go
示例11: Draw
// our avatar image is square
func (g *drawer) Draw(s string, size int, bg *color.RGBA) image.Image {
// draw the background
dst := image.NewRGBA(image.Rect(0, 0, size, size))
draw.Draw(dst, dst.Bounds(), &image.Uniform{bg}, image.ZP, draw.Src)
// draw the text
drawer := &font.Drawer{
Dst: dst,
Src: image.White,
Face: g.face,
}
// font index
fi := g.font.Index([]rune(s)[0])
// glyph example: http://www.freetype.org/freetype2/docs/tutorial/metrics.png
var gbuf truetype.GlyphBuf
var err error
var _fsize fixed.Int26_6 = fixed.Int26_6(g.fontSize * g.dpi * (64.0 / 72.0))
err = gbuf.Load(g.font, _fsize, fi, font.HintingFull)
if err != nil {
// fixme
drawer.DrawString("")
return dst
}
// center
dY := int((size - int(gbuf.Bounds.Max.Y-gbuf.Bounds.Min.Y)>>6) / 2)
dX := int((size - int(gbuf.Bounds.Max.X-gbuf.Bounds.Min.X)>>6) / 2)
y := int(gbuf.Bounds.Max.Y>>6) + dY
x := 0 - int(gbuf.Bounds.Min.X>>6) + dX
//y := 10 + int(math.Ceil(g.fontSize*g.dpi/72)) //FIXME: what does it mean?
drawer.Dot = fixed.Point26_6{
X: fixed.I(x), //(fixed.I(size) - drawer.MeasureString(s)) / 2,
Y: fixed.I(y),
}
drawer.DrawString(s)
return dst
}
开发者ID:rchunping,项目名称:initials-avatar,代码行数:42,代码来源:draw.go
示例12: Draw
// our avatar image is square
func (g *drawer) Draw(s string, size int, bg *color.RGBA) image.Image {
// draw the background
dst := image.NewRGBA(image.Rect(0, 0, size, size))
draw.Draw(dst, dst.Bounds(), &image.Uniform{bg}, image.ZP, draw.Src)
// draw the text
drawer := &font.Drawer{
Dst: dst,
Src: image.White,
Face: g.face,
}
y := 10 + int(math.Ceil(g.fontSize*g.dpi/72)) //FIXME: what does it mean?
drawer.Dot = fixed.Point26_6{
X: (fixed.I(size) - drawer.MeasureString(s)) / 2,
Y: fixed.I(y),
}
drawer.DrawString(s)
return dst
}
开发者ID:ruziniu,项目名称:initials-avatar,代码行数:22,代码来源:draw.go
示例13: renderInformation
// renderLoadingScreen will render the Loading screen.
func (m *Module) renderInformation(rgba *image.RGBA, dimensions image.Point, background image.Image, text string, textSizing string) {
// Prepare a dark grey background to draw on.
draw.Draw(rgba, rgba.Bounds(), background, image.ZP, draw.Src)
d := &font.Drawer{
Dst: rgba,
Src: foreground,
Face: truetype.NewFace(m.font, &truetype.Options{
Size: informationPopupFontSize,
DPI: dpi,
Hinting: font.HintingNone,
}),
}
dy := int(math.Ceil(informationPopupFontSize * dpi / 72))
textWidth := d.MeasureString(textSizing)
d.Dot = fixed.Point26_6{
X: fixed.I(dimensions.X/2) - (textWidth / 2),
Y: fixed.I(dimensions.Y/2 + dy/2),
}
d.DrawString(text)
}
开发者ID:jbowens,项目名称:muni-display,代码行数:22,代码来源:render.go
示例14: TestVerticalLayout
func TestVerticalLayout(t *testing.T) {
layout := NewVerticalLayout(fixed.P(10, 10), fixed.I(100))
if r, ok := layout.NextBounds(); !ok {
t.Error("no bounds returned by the vertical layout")
} else if r != fixed.R(10, 10, 110, 33554431) {
t.Error("invalid bounds returned by the vertical layout:", r)
}
if _, ok := layout.NextBounds(); ok {
t.Error("incomplete vertical layout")
}
}
开发者ID:achille-roussel,项目名称:go-vu,代码行数:13,代码来源:layout_test.go
示例15: buildSprite
// buildSprite renders an image from a text and font face as well as computing its
// bounding box.
//
// TODO: This is a really naive implementation that really should be refactored
// into something more elegant.
func buildSprite(text string, face font.Face) Word {
var (
canvasWidth = 1024
canvasHeight = 1024
)
// Create temporary scratch image to determine real font size.
scratch := image.NewRGBA(image.Rect(0, 0, canvasWidth, canvasHeight))
draw.Draw(scratch, scratch.Bounds(), image.Transparent, image.ZP, draw.Src)
d := &font.Drawer{
Dst: scratch,
Src: image.White,
Face: face,
}
d.Dot = fixed.Point26_6{
X: fixed.I(canvasWidth / 2),
Y: fixed.I(canvasHeight / 2),
}
d.DrawString(text)
// Generate trimmed image and quadtree from temporary canvas.
tt := buildTree(scratch, color.RGBA{0, 0, 0, 0}).Trimmed()
r := tt.Extents
tr := image.Rect(0, 0, r.Dx(), r.Dy())
im := image.NewRGBA(tr)
draw.Draw(im, tr, scratch, r.Min, draw.Src)
t := buildTree(im, color.RGBA{0, 0, 0, 0})
return Word{
Text: text,
Image: im,
Bounds: t,
}
}
开发者ID:marcusolsson,项目名称:exp,代码行数:44,代码来源:word.go
示例16: Render
func Render(letter string, bgColor color.Color, width int, out io.Writer) error {
fg := pickForegroundColor(bgColor)
rgba := image.NewRGBA(image.Rect(0, 0, width, width))
draw.Draw(rgba, rgba.Bounds(), &image.Uniform{bgColor}, image.ZP, draw.Src)
fontSize := fontSizeFactor * float64(width)
d := &font.Drawer{
Dst: rgba,
Src: &image.Uniform{fg},
Face: truetype.NewFace(fnt, &truetype.Options{
Size: fontSize,
DPI: dpi,
Hinting: font.HintingNone,
}),
}
y := int(yOffsetFactor*float64(width)) + int(math.Ceil(fontSize*dpi/72))
d.Dot = fixed.Point26_6{
X: (fixed.I(width) - d.MeasureString(letter)) / 2,
Y: fixed.I(y),
}
d.DrawString(letter)
b := bufio.NewWriter(out)
encoder := png.Encoder{CompressionLevel: png.DefaultCompression}
err := encoder.Encode(b, rgba)
if err != nil {
return err
}
err = b.Flush()
if err != nil {
return err
}
return nil
}
开发者ID:undernewmanagement,项目名称:besticon,代码行数:36,代码来源:lettericon.go
示例17: GetStringSize
func (t *Text) GetStringSize(s string) (fixed.Int26_6, fixed.Int26_6) {
// Assumes 72 DPI
fupe := fixed.Int26_6(t.fontSize * 64.0)
width := fixed.I(0)
prev, hasPrev := t.font.Index(0), false
for _, r := range s {
idx := t.font.Index(r)
if hasPrev {
width += t.font.Kerning(fupe, prev, idx)
}
width += t.font.HMetric(fupe, idx).AdvanceWidth
prev, hasPrev = idx, true
}
fontBounds := t.font.Bounds(fupe)
return width, (fontBounds.YMax - fontBounds.YMin)
}
开发者ID:stephenwithav,项目名称:ssvgc,代码行数:19,代码来源:text.go
示例18: NewFontAtlas
func NewFontAtlas(filename string, dpi, fontSize float64) (*FontAtlas, error) {
atlas := &FontAtlas{}
atlas.Rendered = make(map[rune]Glyph, 256)
content, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
atlas.drawPadding = float32(fontSize * 0.5)
atlas.lineHeight = float32(fontSize * 1.2)
atlas.TTF, err = truetype.Parse(content)
if err != nil {
return nil, err
}
atlas.Image = image.NewRGBA(image.Rect(0, 0, 1024, 1024))
atlas.Context = freetype.NewContext()
atlas.Context.SetDPI(dpi)
atlas.Context.SetFont(atlas.TTF)
atlas.Context.SetFontSize(fontSize)
atlas.Context.SetClip(atlas.Image.Bounds())
atlas.Context.SetSrc(image.White)
atlas.Context.SetDst(atlas.Image)
atlas.maxBounds = atlas.TTF.Bounds(fixed.I(int(fontSize)))
opts := &truetype.Options{}
opts.Size = fontSize
opts.Hinting = font.HintingFull
atlas.Face = truetype.NewFace(atlas.TTF, opts)
return atlas, nil
}
开发者ID:egonelbre,项目名称:spector,代码行数:38,代码来源:fontatlas.go
示例19: main
func main() {
flag.Parse()
chimg := make(chan image.Image)
go func() {
resp, err := http.Get(fmt.Sprintf("%s/%dx%d", unsplashUrl, *width, *height))
if err != nil {
log.Fatal(err)
}
img, err := jpeg.Decode(resp.Body)
if err != nil {
log.Fatal(err)
}
chimg <- img
}()
//load font
chmask := make(chan image.Image)
go func() {
fontBytes, err := ubuntu.Asset("Ubuntu-B.ttf")
if err != nil {
log.Fatal(err)
}
f, err := truetype.Parse(fontBytes)
if err != nil {
log.Fatal(err)
}
//generate text mast
mask := image.NewRGBA(image.Rect(0, 0, *width, *height))
//draw.Draw(mask, mask.Bounds(), image.White, image.ZP, draw.Src)
d := &font.Drawer{
Dst: mask,
Src: image.White,
Face: truetype.NewFace(f, &truetype.Options{
Size: float64(*fontSize),
DPI: float64(*dpi),
Hinting: font.HintingNone,
}),
}
d.Dot = fixed.Point26_6{
X: (fixed.I(*width) - d.MeasureString(*text)) / 2,
Y: fixed.I(*height) / 2,
}
d.DrawString(*text)
chmask <- mask
}()
mask := <-chmask
img := <-chimg
finalDst := image.NewRGBA(img.Bounds())
changedDst := InvertColors(Flip(img))
//Convert dst
dstB := img.Bounds()
draw.Draw(finalDst, finalDst.Bounds(), img, dstB.Min, draw.Src)
draw.DrawMask(finalDst, finalDst.Bounds(), changedDst, image.ZP, mask, image.ZP, draw.Over)
file, err := os.Create(*output)
if err != nil {
log.Fatal(err)
}
png.Encode(file, finalDst)
}
开发者ID:yosmoc,项目名称:wallgen,代码行数:65,代码来源:wallgen.go
示例20: GlyphAdvance
func (f *Face) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool) {
return fixed.I(f.Advance), true
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:3,代码来源:basicfont.go
注:本文中的golang.org/x/image/math/fixed.I函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论