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:
Ethan Burns 2016-04-02 12:19:39 -04:00 committed by Nigel Tao
parent 8b5ac8f8e5
commit 7a320489ae

View File

@ -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"
@ -54,12 +51,12 @@ func parseFontchars(p []byte) []fontchar {
// subface implements font.Face for a Plan 9 subfont.
type subface struct {
firstRune rune // First rune in the subfont.
n int // Number of characters in the subfont.
height int // Inter-line spacing.
ascent int // Height above the baseline.
fontchars []fontchar // Character descriptions.
img *plan9Image // Image holding the glyphs.
firstRune rune // First rune in the subfont.
n int // Number of characters in the subfont.
height int // Inter-line spacing.
ascent int // Height above the baseline.
fontchars []fontchar // Character descriptions.
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
}