There's no reason for this module to still be assuming the semantics
of Go 1.12. Pick 1.18 as a semi-arbitrary newer version because it's
used by a few other golang.org/x modules, and it's enough to get the
nice new features like module graph pruning, removed // +build lines,
and so on. See https://go.dev/ref/mod#go-mod-file-go.
Done with:
go get go@1.18
go mod tidy
go fix ./...
Using go1.21.1.
Change-Id: Icb6874f531accb433bf7e45e7ef0f65af118bf19
Reviewed-on: https://go-review.googlesource.com/c/image/+/526895
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nigel Tao <nigeltao@golang.org>
Commit-Queue: Nigel Tao <nigeltao@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
The other return values may still be non-zero, but this lets callers
identify when substitution happens.
"TODO: is falling back on the U+FFFD glyph the responsibility of the
Drawer or the Face?" was resolved. The answer is "the Face". For
kerning, the previous rune is unchanged (and not set to U+FFFD).
This also fixes an inconsistency in the basicfont.Face implementation,
where GlyphAdvance and GlyphBounds would unconditionally return a
non-zero advance, but Glyph could return a zero advance when the Face
doesn't have a U+FFFD entry.
Fixesgolang/go#58252
Change-Id: Ie97e68e1d5e2efd13c9e84ad12db4495d83a5ca3
Reviewed-on: https://go-review.googlesource.com/c/image/+/474376
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
Previously only NameIDCopyright had NameID type,
the rest were untyped integer constants.
Change-Id: I714308b4eea78ebc65c2f7a10f7316c17cfd403c
Reviewed-on: https://go-review.googlesource.com/c/image/+/468938
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Fixesgolang/go#56931
Change-Id: If5f56aeb63d955b30e1c62f37f4debfa441e2446
Reviewed-on: https://go-review.googlesource.com/c/image/+/456195
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Compared to the previous release (version 2.008, March 2017):
- Fix the "knobbly l" in Go Medium and Go Medium Italic (issue golang/go#23497).
- Fix the unintentional swap of u-acute and u-circumflex in Go Smallcaps
and Go Smallcaps Italic.
- Add U+01CD ..= U+01DC Pinyin diacritic-vowel combinations.
- Add U+2070 ..= U+208E superscript and subscript numerals. The existing
superscript 1, 2, 3 and n were adjusted for consistency (e.g.
superscript '1' now has a baseline if regular '1' does).
- Add U+037E GREEK QUESTION MARK.
- Add U+222A UNION.
- ttfautohint upgraded to the latest version, from 1.6 to 1.8.
Unlike the v2.008 changes, the v2.010 changes were largely
algorithmically generated, by
https://github.com/nigeltao/fontscripts/tree/master/cmd/upgrade-go-fonts-to-v2010Fixesgolang/go#23497
Change-Id: I777d44ace005087f7b865f9a5227736cad49e1f6
Reviewed-on: https://go-review.googlesource.com/c/image/+/412654
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Gofmt to update doc comments to the new formatting.
For golang/go#51082.
Change-Id: Iae65e4d8854b66205e4cbcdd1ae0eec48c582496
Reviewed-on: https://go-review.googlesource.com/c/image/+/399615
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
The SFNT file format explicitly lists the number of points in each
simple (non-compound) glyph and, in this package, this is loaded in func
loadGlyf as the numPoints variable. numPoints is then passed to func
findXYIndexes to verify that the (variable length) remaning glyph data
has content for that many points. loadGlyf then uses a glyfIter to
iterate over those points, but prior to this commit, fails to enforce
that the glyfIter also honors numPoints when walking each contour of a
glyph. This can lead to a panic (slice index out of bounds) on a
malformed SFNT file, if glyfIter then tries to walk too many points.
Fixesgolang/go#48006
Change-Id: I92530e570eb37ce0087927ca23060acebe0a7705
Reviewed-on: https://go-review.googlesource.com/c/image/+/358994
Reviewed-by: Andrew Gerrand <adg@golang.org>
Trust: Nigel Tao <nigeltao@golang.org>
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).
Not strictly necessary but will avoid spurious changes
as files are edited.
Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild
Change-Id: Ib758eb8b75286993f3bd83b5004be667846118d4
Reviewed-on: https://go-review.googlesource.com/c/image/+/294419
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
They delegate to the corresponding sfnt functions. Users (such as
example_test.go) now only need to import one package: opentype.
Also expand opentype and sfnt package docs to emphasize their
differences.
Change-Id: If641f978baa147780e5521aa3e65ee7db3ac1bc3
Reviewed-on: https://go-review.googlesource.com/c/image/+/257539
Trust: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
There's no need for two .go files if one of them is just a placeholder.
If we're only going to have one, it might as well have the same name as
the package.
Change-Id: I0eb639d00e84f0d942adca49b1391987ae77bd7b
Reviewed-on: https://go-review.googlesource.com/c/image/+/257538
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Nigel Tao <nigeltao@golang.org>
Prior to this commit, opentype.Face.Glyph started with:
segments, err := f.f.LoadGlyph(&f.buf, x, etc)
etc
bounds, advance, err := f.f.GlyphBounds(&f.buf, x, etc)
etc
doStuffWith(segments)
One problem with this is that both f.f.FooBar calls ultimately lead to
sfnt.loadGlyf(etc, x, etc) calls and the second one is unnecessary
duplicate work for the same sfnt.GlyphIndex x.
A subtler problem is that the sfnt.Font.LoadGlyph doc comment says that
"the segments become invalid to use once [the buffer] is re-used" and we
were re-using &f.buf before walking the segments.
The fix to both problems is to downgrade the GlyphBounds call to a
cheaper GlyphAdvance call and to also move it above the LoadGlyph call.
This commit also defines and exports a new sfnt.Segments type (with a
Bounds method).
This commit also renames some s/segs/segments/ variables for
consistency, and tweaks some opentype.Face.Glyph comments.
Change-Id: I7d327db742dd701448dc097f30a87227b0fc61f6
Reviewed-on: https://go-review.googlesource.com/c/image/+/256957
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Nigel Tao <nigeltao@golang.org>
This CL is based on Joe Blubaugh's work (golang.org/cl/240897).
Thank you.
Fixesgolang/go#22451
Change-Id: I02e194b9e0a227128ff111cf9f40d6a569dfbd2c
Reviewed-on: https://go-review.googlesource.com/c/image/+/255237
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Trust: David Symonds <dsymonds@golang.org>
Thanks to Joe Blubaugh for the suggestion.
Change-Id: I27cb776614b5a4a0d023755f01b4db06e3d9a1c5
Reviewed-on: https://go-review.googlesource.com/c/image/+/244997
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Updates golang/go#30699
Font.GlyphBounds returns the glyph's bounding box and advance as
expected by the GlyphBounds method of the font.Face interface.
Change-Id: Iaee8b6d88afc48f21d00bf84219b99f993b3ab9a
Reviewed-on: https://go-review.googlesource.com/c/image/+/166477
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Pick up dropped errors in parseGPOSScriptFeatures()
and parseGPOSKern().
Change-Id: I50d9b1feca4c69163df644702afb0c386c2987f7
Reviewed-on: https://go-review.googlesource.com/c/image/+/210499
Reviewed-by: Sebastien Binet <seb.binet@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
The subtable length from the kern table is only uint16. Fonts like
Cambria, Calibri or Corbel have more then 10k kerning pairs and the
encoded length is truncated to uint16. Validate length with truncated
values as well.
Change-Id: I788b709e913790b936d928e7b1e92f628b9c0adf
Reviewed-on: https://go-review.googlesource.com/c/159637
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This CL adds support for reading kerning information from GPOS tables.
Most modern fonts like Noto or Roboto do not provide a kern table.
Instead they use the GPOS table for kerning.
This CL is limited to horizontal kerning and latin scripts.
The proprietary_test was extended to check all supported variations.
gpos.go has full test coverage (excluding error conditions).
Additionally, the new TestBulkKern (opt-in) can be used to check parsing
of large font collection.
Fixes: golang/go#29528
Change-Id: I9f1ae142c9e26170dd836ccaca1526bbefe9698a
Reviewed-on: https://go-review.googlesource.com/c/159638
Reviewed-by: Nigel Tao <nigeltao@golang.org>
The library provides support for CMap formats 2, 4 and 12, but
does not support CMap format 6.
CL adds support for CMap format 6 (trimmed table mapping).
Change-Id: I40657c4805c14017367af17596023da96b2c7483
Reviewed-on: https://go-review.googlesource.com/c/146079
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Previously, it was a float32, which obviously has 32 bits of state. Not
all of that 32 bit state space is meaningful, since NaN has multiple bit
representations. The underlying file format field (of type "Fixed" or
16.16 fixed point) is also 32 bits of state
(https://docs.microsoft.com/en-us/typography/opentype/spec/post).
Therefore, converting from 32 bit fixed point to 32 bit floating point
can be lossy. Instead, use 64 bit floating point. 53 significand bits
can losslessly represent all possible 16.16 fixed point values.
Using float64 is also arguably more Go-like, as the default type for the
ideal constant 0.5 is float64, not float32.
Change-Id: I5abe7979a020af2ac4784d6c2723ab8e39e38e34
Reviewed-on: https://go-review.googlesource.com/c/149837
Reviewed-by: Denys Smirnov <denis.smirnov.91@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Currently the library only parses the version in PostScript table.
However use cases such as PDF document processing requires this
information to be exposed.
CL parses a minimal set of the fields from the PostScript table
and exposes it via new PostTable method.
Change-Id: Ia86eecea9f5aaf557c7e4737f2474966aa30cff2
Reviewed-on: https://go-review.googlesource.com/c/145797
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This change renames the example to follow correct naming convention,
as documented at https://godoc.org/testing#hdr-Examples. As a result,
it shows up in godoc.
This issue was caught and reported by vet:
$ go vet golang.org/x/image/font/sfnt
# golang.org/x/image/font/sfnt_test
font/sfnt/example_test.go:19: ExampleRasterizeGlyph refers to unknown identifier: RasterizeGlyph
Fixesgolang/go#28684
Change-Id: I2749c638c5f3ed15e4db0448bc7a5e2c12c056e5
Reviewed-on: https://go-review.googlesource.com/c/148576
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Currently, the library produces a parsing error when the font
contains a PostScript table of version 1.0.
CL adds this version to the validation code and implements a glyph
name lookup for it.
Change-Id: Id4999d8b252e5c2d8e897f637ba31270336cfe9a
Reviewed-on: https://go-review.googlesource.com/c/146080
Reviewed-by: Nigel Tao <nigeltao@golang.org>
The library assumes the hmtx size to be equal to 2*nGlyph + 2*nHm,
which is a simplification of 4*nHm + 2*(nGlyph-nHm) as described
in the spec. However, fonts seen in the wild sometimes omit the
second term (left side bearings), making validation to fail.
CL fixes the validation code by allowing to omit the second term.
Fixesgolang/go#28379
Change-Id: I2293e498e72f95e5fe08c2b375ea7b020d06cde3
Reviewed-on: https://go-review.googlesource.com/c/144080
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Library assumes that OS/2 header size is at least 96 bytes,
which is not the case for fonts with OS/2 table version <= 1.
This CL adds a version test and handles the legacy header.
Fixesgolang/go#28339
Change-Id: I79bd8f8bbf262c1caaf4e66888446159b5e4fb43
Reviewed-on: https://go-review.googlesource.com/c/144079
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
This CL adds the type Face that implements the font.Face interface.
This CL also adds tests using gofont/goregular as an input font, using
github.com/golang/freetype/truetype as reference values.
Updates golang/go#22451.
Change-Id: I2a6945309331b251ec2ddec95b6e809ad10aa116
Reviewed-on: https://go-review.googlesource.com/73870
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Also add tests for the Noto proprietary fonts. Prior to this commit,
NotoColorEmoji.ttf was unsupported. It's still not well supported, but
the error message returned is now more informative.
Change-Id: I61a3301d7f2458a4b838eb1de7a73d6472e3486f
Reviewed-on: https://go-review.googlesource.com/43694
Reviewed-by: David Crawshaw <crawshaw@golang.org>
A future commit will actually use subtables past the first one, but for
now, ignore them instead of failing on their presence.
Also add tests for the DejaVu proprietary fonts. Prior to this commit,
DejaVuSans-ExtraLight.ttf was unsupported.
Change-Id: Ic78a59c5ab30e4091efa2a04b89b12cb786157db
Reviewed-on: https://go-review.googlesource.com/42192
Reviewed-by: David Crawshaw <crawshaw@golang.org>