Граф коммитов

111 Коммитов

Автор SHA1 Сообщение Дата
Erik Agsjö 240a51ac9f font/sfnt: support early version 0 OS/2 tables
Version 0 OS/2 tables can be as small as 68 bytes.

See https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html.

This works is taken over from https://go.dev/cl/510055 by Erik Agsjö.

Fixes golang/go#41658

Change-Id: If6fb961943b5563ed21fe5148252005743c17168
Reviewed-on: https://go-review.googlesource.com/c/image/+/533495
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
2023-10-07 04:08:05 +00:00
Dmitri Shuralyov 4aa0222fac go.mod: update go directive to 1.18
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>
2023-09-08 23:15:45 +00:00
Nigel Tao 08ca817286 font: have Glyph return !ok for U+FFFD substitute
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.

Fixes golang/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>
2023-03-21 11:35:05 +00:00
Dmitri Shuralyov 1b7441254c font/sfnt: set type for all NameID constants
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>
2023-02-24 15:35:27 +00:00
Nigel Tao 9b8a3be425 font/plan9font: limit the font image's dimensions
Fixes golang/go#57258

Change-Id: I0249e422470219594188d050ebd6dc42f1646dff
Reviewed-on: https://go-review.googlesource.com/c/image/+/458095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2022-12-19 10:52:04 +00:00
Nigel Tao c5235ae222 font/plan9font: fix byteoffset for non-zero origin
Updates golang/go#57258

Change-Id: I4c7305c8e61f2d2cc0227c0daf0b003bbc466497
Reviewed-on: https://go-review.googlesource.com/c/image/+/458035
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
2022-12-16 00:02:52 +00:00
Nigel Tao 0888fdd524 font/plan9font: fix bounds overflow
Fixes golang/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>
2022-12-08 23:42:43 +00:00
Nigel Tao 41969df76e font/gofont: upgrade to version 2.010
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-v2010

Fixes golang/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>
2022-06-17 04:31:17 +00:00
Nigel Tao 70e8d0d3ba font/sfnt: fix Font.GlyphIndex nil Buffer dereference
Fixes golang/go#46948

Change-Id: Ie3a2e60cf858ebeded73686bbac3e8d8448132a8
Reviewed-on: https://go-review.googlesource.com/c/image/+/398774
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Auto-Submit: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
2022-04-13 10:07:46 +00:00
Russ Cox 99f80d0ecb all: gofmt
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>
2022-04-12 02:13:10 +00:00
cuishuang 723b81ca98 all: fix typos
Change-Id: I8f9f58babea80bbdad52df2b67a083f3a381c217
GitHub-Last-Rev: 79ce945721
GitHub-Pull-Request: golang/image#8
Reviewed-on: https://go-review.googlesource.com/c/image/+/389054
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
2022-03-02 09:49:43 +00:00
Nigel Tao 6944b10bf4 font/sfnt: verify the total number of contour points
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.

Fixes golang/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>
2021-10-28 20:25:45 +00:00
Nigel Tao e6eecd499c font/sfnt: fix parsing PostScript fonts' 4-byte numbers
Fixes golang/go#46836

Change-Id: Ie4ff2a9866d3f468d973e73857d6c44078c0695d
Reviewed-on: https://go-review.googlesource.com/c/image/+/329949
Trust: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-06-22 09:29:29 +00:00
Nigel Tao 7319ad40d3 vector: add example test
Fixes golang/go#45723

Change-Id: Id9131dd690a4496ed5ec8aae3bf4d54f44a53d79
Reviewed-on: https://go-review.googlesource.com/c/image/+/316069
Trust: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-05-04 12:19:37 +00:00
Russ Cox ac19c3e999 all: go fmt ./...
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>
2021-02-20 03:29:44 +00:00
Nigel Tao 4410531fe0 font/sfnt: add more package docs
Change-Id: Idebffba4a9260888914cff97d9b56c7ea392b139
Reviewed-on: https://go-review.googlesource.com/c/image/+/292249
Trust: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-02-16 03:45:30 +00:00
Nigel Tao 55ae14f3eb font/sfnt: add Font.WriteSourceTo
See https://groups.google.com/g/golang-nuts/c/bilOyOz_SCc/m/kih7w0x4AgAJ
"x/image/font: Font serialization" for the motivation.

Change-Id: Iba05b4251f1dc91783eb3c43d78fb3ba79b0d912
Reviewed-on: https://go-review.googlesource.com/c/image/+/291149
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Trust: Nigel Tao <nigeltao@golang.org>
2021-02-15 06:22:27 +00:00
Nigel Tao e162460cd6 font/opentype: add Parse and similar functions
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>
2020-09-27 10:45:01 +00:00
Nigel Tao a67d67e093 font/opentype: merge face.go into opentype.go
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>
2020-09-27 00:56:34 +00:00
Nigel Tao 2fd4ef34c9 font/opentype: add ExampleNewFace
Change-Id: If2eba9c4d709d26b1187f3354ecd730a0f612d92
Reviewed-on: https://go-review.googlesource.com/c/image/+/257537
Trust: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
2020-09-26 10:34:41 +00:00
Nigel Tao 4578eab98f font/opentype: de-duplicate sfnt.loadGlyf calls
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>
2020-09-24 06:21:09 +00:00
Hajime Hoshi e59bae62ef font/opentype: implement Glyph and GlyphBounds
This CL is based on Joe Blubaugh's work (golang.org/cl/240897).
Thank you.

Fixes golang/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>
2020-09-22 02:54:26 +00:00
Nigel Tao 972c09e46d font/sfnt: fix Font.GlyphBounds with truncated hmtx table
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>
2020-08-01 11:06:59 +00:00
Sebastien Binet c137617195 font/sfnt: fix uint16 overflow in Glyph{Advance,Index}
This CL builds on top of the patch provided by user @dejadejade.

Fixes golang/go#39577.

Change-Id: I6db1561df1c659b8b1678eb96522f406e6a5799b
Reviewed-on: https://go-review.googlesource.com/c/image/+/237900
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2020-06-18 11:58:11 +00:00
Oliver Tonnhofer 3f4726a040 font/sfnt: implement Font.GlyphBounds
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>
2020-06-09 00:25:22 +00:00
Lars Lehtonen 33d19683fa font/sfnt: fix dropped errors
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>
2020-04-30 14:03:53 +00:00
Wagner Riffel cb417be4ba font/plan9font: rewrite reference to plan9.bell-labs.com to 9p.io
Change-Id: Icc934108cc672855af824a0759cce87b50ba5523
Reviewed-on: https://go-review.googlesource.com/c/image/+/192838
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-02 06:37:13 +00:00
Oliver Tonnhofer 0694c2d4d0 font/sfnt: support for large kern tables
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>
2019-02-27 22:21:17 +00:00
Oliver Tonnhofer ef4a1470e0 font/sfnt: support for kerning from GPOS tables
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>
2019-02-09 06:06:08 +00:00
Denys Smirnov 183bebdce1 font/sfnt: support cmap format 6
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>
2019-01-18 04:33:09 +00:00
Nigel Tao cd38e8056d font/sfnt: make PostTable.ItalicAngle a float64
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>
2018-11-16 02:48:01 +00:00
Denys Smirnov dd492a22e4 font/sfnt: support fonts with "true" apple version tag
OpenType specification mentions that fonts might contain Apple
version tag that is equal to "true" (see note in [1]). Currently,
the library returns a parsing error for those fonts.

CL adds Apple this version tag to the validation code and allows
fonts to omit OS/2 table, as mentioned in the TrueType spec [2].

[1] https://docs.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font

[2] https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html

Change-Id: I13406fe97b091f24aaabf9b477df9c8fc8df883c
Reviewed-on: https://go-review.googlesource.com/c/146078
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2018-11-16 02:46:09 +00:00
Denys Smirnov d9c2484c48 font/sfnt: parse and expose PostScript information
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>
2018-11-15 06:11:51 +00:00
Dmitri Shuralyov aa35264064 font/sfnt: rename ExampleRasterizeGlyph to Example_rasterizeGlyph
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

Fixes golang/go#28684

Change-Id: I2749c638c5f3ed15e4db0448bc7a5e2c12c056e5
Reviewed-on: https://go-review.googlesource.com/c/148576
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-09 00:22:02 +00:00
Denys Smirnov fe2fa19765 font/sfnt: support post table version 1.0
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>
2018-11-07 04:00:41 +00:00
Denys Smirnov 63626fb251 font/sfnt: fix hmtx table size validation
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.

Fixes golang/go#28379

Change-Id: I2293e498e72f95e5fe08c2b375ea7b020d06cde3
Reviewed-on: https://go-review.googlesource.com/c/144080
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2018-11-02 02:16:09 +00:00
Denys Smirnov 2a2258ff36 font/sfnt: support parsing legacy fonts with OS2 table version <= 1
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.

Fixes golang/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>
2018-10-25 23:34:08 +00:00
Elias Naur 991ec62608 image/font: expose caret slope
Change-Id: I775224dd3fc7e5b6c2fc5c4a7d3db83bb36d047d
Reviewed-on: https://go-review.googlesource.com/136255
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2018-09-26 01:56:37 +00:00
Elias Naur e1a1ede689 font,font/sfnt: expose font x-Height and capHeight
Change-Id: I6e3e6e51c7e270e16413c23990f6df5e22cbfeb6
Reviewed-on: https://go-review.googlesource.com/135555
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2018-09-20 23:51:50 +00:00
Elias Naur cc896f830c font/sfnt,font/opentype: correct font height computation
According to https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html
the line spacing of a font is computed as

line space = ascent - descent + linegap

Use that formula to compute the Height field of a Font's Metrics.

Change-Id: I1c44eca9f662e0aae68716cd8859670fe0b394d7
Reviewed-on: https://go-review.googlesource.com/120815
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2018-06-28 06:20:38 +00:00
Sebastien Binet e5db4c4663 font/opentype: implement font.Face interface
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>
2017-12-08 23:31:33 +00:00
Elias Naur f7e31b4ea2 font/sfnt: add Metrics to Font
Change-Id: I4bfcf264e5ee7e4f3ddf89e289d730f230095401
Reviewed-on: https://go-review.googlesource.com/67330
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2017-10-13 01:36:00 +00:00
Nigel Tao 426cfd8eeb font/sfnt: implement hflex and hflex1.
Change-Id: I288a014a5b6c54e54ffa69b76a8b12fa7fdbc708
Reviewed-on: https://go-review.googlesource.com/43474
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-05-23 02:19:15 +00:00
Nigel Tao d835a09709 font/sfnt: add ErrColoredGlyph.
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>
2017-05-23 02:17:49 +00:00
Nigel Tao f483456c9f font/sfnt: don't reject multiple kern subtables.
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>
2017-05-04 00:22:41 +00:00
Nigel Tao 3210c0296b font/sfnt: support .dfont files.
Change-Id: Id7aa18c48c65586c688cee230ce87f4d88dae9b5
Reviewed-on: https://go-review.googlesource.com/40893
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-04-21 22:58:11 +00:00
Nigel Tao 7c3fafc74f font/sfnt: explicitly close glyph contours.
Change-Id: I4a59167cfe5d84f0ef6732711cca9b46a52b445c
Reviewed-on: https://go-review.googlesource.com/39930
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-04-10 07:42:48 +00:00
Nigel Tao 1de9a5bb2a font/sfnt: implement Font.Bounds.
Change-Id: I24ab4cfa74a791ebb8223b38e5d6624c74caa9f8
Reviewed-on: https://go-review.googlesource.com/39670
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-04-10 07:35:26 +00:00
Nigel Tao 84a6511894 font/sfnt: use charmap EncodeRune API.
Change-Id: I91d850d1816b43748580f6f8a8f19151472750d0
Reviewed-on: https://go-review.googlesource.com/39070
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-05 22:33:02 +00:00
Nigel Tao 10ed294205 font/sfnt: implement Font.GlyphAdvance.
Change-Id: I3e15c6e634d858a87e73221bd9d5a9e3979d674a
Reviewed-on: https://go-review.googlesource.com/39250
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-04-05 22:26:46 +00:00