Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/image/font/{sfnt,opentype}: expose more SFNT tables #45325

Open
sbinet opened this issue Apr 1, 2021 · 3 comments
Open

x/image/font/{sfnt,opentype}: expose more SFNT tables #45325

sbinet opened this issue Apr 1, 2021 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@sbinet
Copy link
Member

sbinet commented Apr 1, 2021

What version of Go are you using (go version)?

$ go version
go version devel +135c9f45ec Wed Mar 31 04:13:44 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/binet/.cache/go-build"
GOENV="/home/binet/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/binet/dev/go/gocode/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/binet/dev/go/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/binet/sdk/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/binet/sdk/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +135c9f45ec Wed Mar 31 04:13:44 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build354109135=/tmp/go-build -gno-record-gcc-switches"

text layouting and typesetting

in the context of text layouting and typesetting, it would be great for the sfnt package to expose way to access more informations from the font tables.

e.g. somebody trying to replicate or port (parts of) the HarfBuzz library would want to have access to the informations provided by the tables sfnt is currently decoding but hiding from public consumption:

for the purpose of drawing mathematical equations, having access to the math table informations would also be quite useful.

@nigeltao

@gopherbot gopherbot added this to the Unreleased milestone Apr 1, 2021
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 2, 2021
@nigeltao
Copy link
Contributor

Sure, but we need a specific API proposal, and I don't have much spare time to work on that myself.

@sbinet
Copy link
Member Author

sbinet commented Apr 23, 2021

I guess API-wise, there are 3 main avenues:

a) export a bunch of methods (attached to the sfnt.Font type) that return a specific exported table type:

func (f *Font) CMapTable()  CMapTable
func (f *Font) KernTable()  KernxTable
func (f *Font) KernxTable() KernxTable
func (f *Font) MathTable()  MathTable
// etc...

b) export a bunch of table fields, each with its own type

type Font struct {
    // ...
    CMapTable CMapTable
    MathTable MathTable
}

c) export a single sfnt.Font method that takes as argument a Table interface that knows how to decode itself from a provided range of bytes (the sfnt.table type)

type Table interface {
    Kind() TableKind // or just: Name() string where string is the 4b-tag. eg: "OS/2", "math", "maxp", ...
    decodeFrom(src table, f *Font) error
}

func (f *Font) Table(tbl Table) error {
    src, err := f.table(tbl.Kind())
    if err != nil { return err }
    return tbl.decodeFrom(src, f)
}

type MathTable struct { ... }
func (tbl *MathTable) Kind() TableKind { return MathTableKind }
func (tbl *MathTable) decodeFrom(src table, f *Font) error { ... }

// use:
func foo(f *sfnt.Font) {
    var tbl sfnt.MathTable
    err := f.Table(&tbl)
    if err != nil { panic(err) }
}

then comes the question of whether for the Table types:

  • to be "just" a view into the table+Font sea of bytes (and thus only export methods to decode+retrieve that data on each invocation) - this complicates a bit the ownership model of the src source field of the Font values, or
  • to have the Table types decode+store the decoded data into their own dedicated fields.

from the precedent of the existing sfnt.PostTable table, I guess the latter would be preferred, but that may not be advisable if the tables are large ( eg. the "glyf" table)

@nigeltao
Copy link
Contributor

nigeltao commented May 9, 2021

then comes the question of whether for the Table types:

Well, that's the important question for me. What are the actual fields of type CMapTable, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants