From 8777d2c5295fbe22403f92c4f68ad6421ed72d46 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 26 Nov 2023 17:21:31 +0900 Subject: [PATCH] text/v2: allow io.Reader for NewGoTextFaceSource This enables to pass fs.File to NewGoTextFaceSource. Updates #2454 --- text/v2/gotextfacesource.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/text/v2/gotextfacesource.go b/text/v2/gotextfacesource.go index f636c92be..eee5230e5 100644 --- a/text/v2/gotextfacesource.go +++ b/text/v2/gotextfacesource.go @@ -74,8 +74,8 @@ type GoTextFaceSource struct { m sync.Mutex } -func toFontResource(source io.ReadSeeker) (font.Resource, error) { - // font.Resource has io.ReaderAt in addition to io.ReadSeeker. +func toFontResource(source io.Reader) (font.Resource, error) { + // font.Resource has io.Seeker and io.ReaderAt in addition to io.Reader. // If source has it, use it as it is. if s, ok := source.(font.Resource); ok { return s, nil @@ -83,7 +83,7 @@ func toFontResource(source io.ReadSeeker) (font.Resource, error) { // Read all the bytes and convert this to bytes.Reader. // This is a very rough solution, but it works. - // TODO: Implement io.ReaderAt in a more efficient way. + // TODO: Implement io.ReaderAt in a more efficient way when source is io.Seeker. bs, err := io.ReadAll(source) if err != nil { return nil, err @@ -93,7 +93,7 @@ func toFontResource(source io.ReadSeeker) (font.Resource, error) { } // NewGoTextFaceSource parses an OpenType or TrueType font and returns a GoTextFaceSource object. -func NewGoTextFaceSource(source io.ReadSeeker) (*GoTextFaceSource, error) { +func NewGoTextFaceSource(source io.Reader) (*GoTextFaceSource, error) { src, err := toFontResource(source) if err != nil { return nil, err @@ -119,7 +119,7 @@ func NewGoTextFaceSource(source io.ReadSeeker) (*GoTextFaceSource, error) { } // NewGoTextFaceSourcesFromCollection parses an OpenType or TrueType font collection and returns a slice of GoTextFaceSource objects. -func NewGoTextFaceSourcesFromCollection(source io.ReadSeeker) ([]*GoTextFaceSource, error) { +func NewGoTextFaceSourcesFromCollection(source io.Reader) ([]*GoTextFaceSource, error) { src, err := toFontResource(source) if err != nil { return nil, err