From efd8dbcc39d968c36e79f1c34d321b123a7f9805 Mon Sep 17 00:00:00 2001 From: Steven Edwards Date: Tue, 1 Sep 2015 15:57:34 -0400 Subject: [PATCH] Inlined decodeUTF16 func to remove runes.go --- truetype/runes.go | 16 ---------------- truetype/truetype.go | 8 +++++++- 2 files changed, 7 insertions(+), 17 deletions(-) delete mode 100644 truetype/runes.go diff --git a/truetype/runes.go b/truetype/runes.go deleted file mode 100644 index 995d1d4..0000000 --- a/truetype/runes.go +++ /dev/null @@ -1,16 +0,0 @@ -package truetype - -import ( - "bytes" - "io/ioutil" - - "golang.org/x/text/encoding/unicode" - "golang.org/x/text/transform" -) - -func decodeUTF16(b []byte) ([]byte, error) { - r := bytes.NewReader(b) - enc := unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM) - r2 := transform.NewReader(r, enc.NewDecoder()) - return ioutil.ReadAll(r2) -} diff --git a/truetype/truetype.go b/truetype/truetype.go index 78e1103..6741826 100644 --- a/truetype/truetype.go +++ b/truetype/truetype.go @@ -18,9 +18,13 @@ package truetype // import "github.com/golang/freetype/truetype" import ( + "bytes" "fmt" + "io/ioutil" "golang.org/x/image/math/fixed" + "golang.org/x/text/encoding/unicode" + "golang.org/x/text/transform" ) // An Index is a Font's index of a rune. @@ -335,7 +339,9 @@ func (f *Font) parseName() error { // assume UTF-16, try to parse it if its length is even if value[0] == 0 && length&1 == 0 { var err error - value, err = decodeUTF16(value) + + enc := unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM) + value, err = ioutil.ReadAll(transform.NewReader(bytes.NewReader(value), enc.NewDecoder())) if err != nil { return err }