golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.36k stars 17.71k forks source link

x/image/font: negative XHeight and CapHeight with M+ 1p Font #69378

Open hajimehoshi opened 2 months ago

hajimehoshi commented 2 months ago

Go version

go version go1.22.6 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/hajimehoshi/Library/Caches/go-build'
GOENV='/Users/hajimehoshi/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/hajimehoshi/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/hajimehoshi/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/hajimehoshi/ebiten/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/cj/73zbb35j0qx5t4b6rnqq0__h0000gn/T/go-build3402016389=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

  1. Download MPLUS1p-Regular.ttf at https://fonts.google.com/specimen/M+PLUS+1p
  2. Run this program
package main

import (
    "fmt"
    "os"

    "golang.org/x/image/font/opentype"
)

func showMetrics() error {
    file, err := os.ReadFile("MPLUS1p-Regular.ttf")
    if err != nil {
        return err
    }

    f, err := opentype.Parse(file)
    if err != nil {
        return err
    }
    face, err := opentype.NewFace(f, &opentype.FaceOptions{
        Size: 12,
        DPI:  72,
    })
    if err != nil {
        return err
    }
    m := face.Metrics()
    fmt.Printf("x-height: %s\n", m.XHeight.String())
    fmt.Printf("cap-height: %s\n", m.CapHeight.String())
    return nil
}

func main() {
    if err := showMetrics(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}

What did you see happen?

Negative values are shown

x-height: -6:15
cap-height: -8:49

What did you expect to see?

Positive values are shown

hajimehoshi commented 2 months ago

@nigeltao ?

gabyhelp commented 2 months ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

hajimehoshi commented 2 months ago

I guess this value should be inverted https://cs.opensource.google/go/x/image/+/refs/tags/v0.20.0:font/sfnt/sfnt.go;l=1201;drc=240a51ac9f088c1c81cad2cf80a37b99c52abcde

Thoughts? (CC @dmitshur)