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

proposal: x/image packages to render TrueType fonts #16904

Open
nigeltao opened this Issue Aug 28, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@nigeltao
Copy link
Contributor

nigeltao commented Aug 28, 2016

github.com/golang/freetype already exists, but its license (the Freetype license) differs from the Go standard library, and code in the stdlib or under golang.org/x cannot depend on out-of-tree code.

I propose to add two new packages in the golang.org/x/image repo that together lets you use TTFs to draw text. There are existing packages under golang.org/x/image/font that can draw bitmap fonts, but this would be the first golang.org/x package that draws vector fonts.

The golang.org/x/image/vector package rasterizes 2-D vector graphics: filled and stroked polygons and Bézier curves. 2-D vector graphics (and the scope of this package) encompasses more than just fonts, but this package will rasterize the glyphs of a vector font such as TrueType. It'd be comparable to the github.com/golang/freetype/raster package, but not based on the Freetype code.

The golang.org/x/image/font/sfnt package parses sfnt font formats, including TrueType (.ttf) and OpenType (.otf). It will implement the existing golang.org/x/image/font font.Face interface for font format agnostic text drawing. It'd be comparable to the github.com/golang/freetype/truetype package, but not based on the Freetype code.

A proof of concept (as a single "package main" instead of two separate packages) exists in a separate repository, https://github.com/google/font-go, which is in turn based on https://github.com/google/font-rs and the accompanying article (https://medium.com/@raphlinus/inside-the-fastest-font-renderer-in-the-world-75ae5270c445) by Raph Levien of Google. Roughly speaking, font.go would become package sfnt, and raster.go and acc*.{go,s} would become package vector.

@adg

This comment has been minimized.

Copy link
Contributor

adg commented Sep 1, 2016

I'm @adg and I approve this proposal.

@bradfitz

This comment has been minimized.

Copy link
Member

bradfitz commented Sep 1, 2016

I'm not @adg and I approve this proposal.

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Sep 1, 2016

CL https://golang.org/cl/28347 mentions this issue.

gopherbot pushed a commit to golang/image that referenced this issue Sep 4, 2016

vector: new package for rasterizing 2-D graphics.
Updates golang/go#16904

Change-Id: I4e11e4e859c007c3444655a227ac935c27f3f784
Reviewed-on: https://go-review.googlesource.com/28347
Reviewed-by: David Crawshaw <crawshaw@golang.org>

@quentinmit quentinmit modified the milestones: Proposals, Proposal Sep 6, 2016

@akavel

This comment has been minimized.

Copy link
Contributor

akavel commented Sep 7, 2016

Is the reference API of the Rust package published somewhere, or does one have to browse the sources? Will it be possible to stroke curves with dashes/dots pattern? (I use forked freetype-go to draw dashed lines and curves in my Go port of ditaa.)

@nigeltao

This comment has been minimized.

Copy link
Contributor Author

nigeltao commented Sep 8, 2016

I don't know enough about the Rust community to know if the API is published anywhere other than the source at https://github.com/google/font-rs but its API is pretty minimal: it is a prototype / proof of concept rather than a polished library.

I expect golang.org/x/image/vector will be as capable as github.com/golang/freetype/raster in terms of strokes, so you can build your own dashing code on top of that.

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Nov 20, 2016

CL https://golang.org/cl/33417 mentions this issue.

gopherbot pushed a commit to golang/image that referenced this issue Nov 23, 2016

font/sfnt: new package for parsing SFNT fonts.
Updates golang/go#16904

Change-Id: Ic4c55865741b712f7d82448276fc357f2edf9b45
Reviewed-on: https://go-review.googlesource.com/33417
Reviewed-by: Dave Day <djd@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.