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>
diff --git a/font/plan9font/plan9font.go b/font/plan9font/plan9font.go
index d853b1c..cd688b1 100644
--- a/font/plan9font/plan9font.go
+++ b/font/plan9font/plan9font.go
@@ -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 @@
// 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 @@
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
}