canvas icon indicating copy to clipboard operation
canvas copied to clipboard

load font error: GSUB: lookupOrderOffset must be NULL

Open qxdo opened this issue 1 year ago • 1 comments

hi, I'm using this into my project, I notice load some font file, return this error: load font error: GSUB: lookupOrderOffset must be NULL, here is my code:

import (
	"context"
	"errors"
	"fmt"
	"github.com/tdewolff/canvas"
	"testing"
)

func TestDrawFont(t *testing.T) {
	font_location := "fd48cf323a854ca389e08c546f34198f.otf"
	font_name := "Paralines"
	pathValue, err := drawTextPath1(context.TODO(), "T", font_location, font_name)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(fmt.Sprintf("<html><body><svg><path d=\"%s\" /></svg></body></html>", pathValue))

}

func drawTextPath1(ctx context.Context, nameText, fontRes, fontFam string) (pathStr string, err error) {
	fontFamily := canvas.NewFontFamily(fontFam)

	fmt.Println(ctx, "drawTextPath fontsPath:", fontRes)

	if err = fontFamily.LoadFontFile(fontRes, canvas.FontRegular); err != nil {
		fmt.Println(ctx, "load font error:", err)
		return "", errors.New("font not found")
	}

	face := fontFamily.Face(20, canvas.Black, canvas.FontRegular)
	path, _, err := face.ToPath(nameText)
	if err != nil {
		return pathStr, errors.New("CodeError")
	}
	//path = path.Transform(canvas.Identity.Translate(0.0, 0).Scale(1.0, -1.0).Translate(0.0, -10))
	svgPath := path.ToSVG()

	if len(svgPath) == 0 {
		return "", errors.New("text not render path")
	}
	return svgPath, nil
}

qxdo avatar Jan 22 '24 06:01 qxdo

Could you please send me the font to check what's wrong? The lookupOrderOffset in the GSUB script table should be NULL according to the specification. I've attached a commit that omits the check, but perhaps another bug has led this check to fail.

tdewolff avatar Jan 22 '24 21:01 tdewolff

Hi, this is the font file link, https://kilofolo-oss-test.oss-cn-shanghai.aliyuncs.com/fd48cf323a854ca389e08c546f34198f.otf font name is Paralines font family is also Paralines.

qxdo avatar Jan 29 '24 08:01 qxdo

Thank you, I can confirm. The offsets to the respective script list table was zero in GSUB, this is bad according to the specification but led the script table to reparse the same GSUB table and interpreted the major/minor version of it as 256 instead of NULL (hence the error). I've fixed this properly now!

tdewolff avatar Jan 29 '24 14:01 tdewolff

Thank you very much!

qxdo avatar Jan 30 '24 08:01 qxdo