plan9font: use image.Alpha for subface images.
image.Alpha is fast-pathed in draw.Draw, plan9Image is not. Change-Id: I5ed8fc4d310bb5c6ec2cffdd0ba4295dae2274cf Reviewed-on: https://go-review.googlesource.com/21453 Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
parent
8b5ac8f8e5
commit
7a320489ae
|
@ -7,16 +7,13 @@
|
|||
// http://plan9.bell-labs.com/magic/man2html/6/font
|
||||
package plan9font // import "golang.org/x/image/font/plan9font"
|
||||
|
||||
// TODO: have a subface use an *image.Alpha instead of plan9Image implementing
|
||||
// the image.Image interface? The image/draw code has a fast path for
|
||||
// *image.Alpha masks.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -59,7 +56,7 @@ type subface struct {
|
|||
height int // Inter-line spacing.
|
||||
ascent int // Height above the baseline.
|
||||
fontchars []fontchar // Character descriptions.
|
||||
img *plan9Image // Image holding the glyphs.
|
||||
img *image.Alpha // Image holding the glyphs.
|
||||
}
|
||||
|
||||
func (f *subface) Close() error { return nil }
|
||||
|
@ -300,13 +297,15 @@ func ParseSubfont(data []byte, firstRune rune) (font.Face, error) {
|
|||
if len(data) != 6*(n+1) {
|
||||
return nil, errors.New("plan9font: invalid subfont: data length mismatch")
|
||||
}
|
||||
img := image.NewAlpha(m.Bounds())
|
||||
draw.Draw(img, img.Bounds(), m, image.ZP, draw.Over)
|
||||
return &subface{
|
||||
firstRune: firstRune,
|
||||
n: n,
|
||||
height: height,
|
||||
ascent: ascent,
|
||||
fontchars: parseFontchars(data),
|
||||
img: m,
|
||||
img: img,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user