Commit Graph

238 Commits

Author SHA1 Message Date
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
Nigel Tao
ce0faa1867 font/sfnt: flip the Y axis for LoadGlyph's Segments.
The underlying font format's Y axis increases up. The Go standard
graphics libraries' Y axis increases down. This change makes the Go API
consistent with the other Go libraries.

Also change Segment.Args from [6]fixed.Int26_6 to [3]fixed.Point26_6 to
emphasize that the Args are consistent with other fixed.Point26_6 use.

Change-Id: Idd7b89eb4d86890dea477ac2ef96ff8f6b1dee8d
Reviewed-on: https://go-review.googlesource.com/39072
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-31 23:39:16 +00:00
Nigel Tao
f36ba34967 font/sfnt: implement Font Dict Select.
Change-Id: I8c463b41421a35455701847520367add4727cbe3
Reviewed-on: https://go-review.googlesource.com/38871
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-30 23:40:04 +00:00
Nigel Tao
59d151bf14 font/sfnt: implement implicit vstem before hintmask.
Change-Id: I811bcf94b518dabcfbebd085ad3c6a47c17ef38e
Reviewed-on: https://go-review.googlesource.com/38288
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-30 01:47:42 +00:00
Nigel Tao
ecc1a9abb6 font/sfnt: fix argStack size check for moveto ops.
The *moveto ops don't take multiple args or arg pairs. For example, in
http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5177.Type2.pdf
page 16, the rmoveto args are listed as:
dx1 dy1
which is not the same as rlineto's args, which can be repeated:
{dxa dya}+

Change-Id: I5d13f686e604955909eb0b7e52f20ce5f0522c5d
Reviewed-on: https://go-review.googlesource.com/38289
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-30 01:44:25 +00:00
Nigel Tao
f03a046406 font/gofont: new Smallcaps; update other Go Fonts.
Bigelow & Holmes have prepared new versions of the Go Fonts. The version
numbers have changed from 2.004 to 2.008. ChangeLog:

* New! 2 new fonts, bringing the total to 12: Go Smallcaps and Go
  Smallcaps Italic.
* New! U+FFFD REPLACEMENT CHARACTER glyph added.
* U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE ring tweaked.
* U+00F0 LATIN SMALL LETTER ETH glyph lightened.
* Superfluous U+0005 <control> glyph removed.
* Split integral, chart draw, block, shade and related glyphs now span
  the full height and have fewer seams when tiled.
* Raised most capital letter diacritics and some lowercase diacritics.
* Mono character widths fixed to be uniform.
* Underline position adjusted.
* SFNT glyph order and cmap table optimized.
* SFNT glyph names (post table) regularized, consistent with the AGLFN.
* ttfautohint upgraded to the latest version, from 1.5 to 1.6.

Change-Id: I0985f07d58b984010199dd723ccdf5892ee59c78
Reviewed-on: https://go-review.googlesource.com/38870
Reviewed-by: Rob Pike <r@golang.org>
2017-03-30 00:58:26 +00:00
Nigel Tao
c0851fbc5b font/sfnt: support PostScript compound glyphs (subroutines).
Change-Id: I8aa10150aa004b1bc1128bf0b3d5c14b74ee089c
Reviewed-on: https://go-review.googlesource.com/38280
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-22 22:20:00 +00:00
Nigel Tao
2e35bd52b4 font/sfnt: increase proprietary_test coverage.
Recent commits (probably 792d36e1 "support TrueType compound glyphs" and
1995ed1a "support TrueType glyph transformations") let us decode all the
glyphs in the Adobe TrueType fonts, but I forgot to update the test
coverage in those commits.

Change-Id: I7b135005cd67082f84aee16d296debdedcc9488e
Reviewed-on: https://go-review.googlesource.com/38281
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-22 21:47:50 +00:00
Nigel Tao
2c9074b9aa font/sfnt: implement flagWeHaveATwoByTwo.
Change-Id: I9f4577b57f25a85ef0639c34215adf40df61c5ab
Reviewed-on: https://go-review.googlesource.com/38274
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-22 21:43:44 +00:00
Nigel Tao
fb59e5ba10 font/sfnt: rename a "stack" field to "argStack".
This will lessen the diff in a subsequent commit, which introduces a
call stack.

Change-Id: I478857675f47b53e6bd3ee270087a00b9d1d4d34
Reviewed-on: https://go-review.googlesource.com/38279
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2017-03-19 05:24:11 +00:00
Nigel Tao
88e2d806a0 font/sfnt: ignore version 1 kern tables.
The format is relatively complicated but rarely seen. It doesn't seem
worth the effort. Ignoring it is what Microsoft Windows and FreeType do.

Change-Id: I4415bd591c832650066de1d4e035b20a7230a4da
Reviewed-on: https://go-review.googlesource.com/38273
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-18 23:50:03 +00:00
Nigel Tao
6847effb9b font/sfnt: support font collections (.ttc and .otc files).
Also add tests for Apple proprietary fonts.

Change-Id: I5ce8efa2397bb01c5255d956a77c955ba1383105
Reviewed-on: https://go-review.googlesource.com/38272
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-18 07:04:21 +00:00
Nigel Tao
1995ed1a25 font/sfnt: support TrueType glyph transformations.
Change-Id: Iea2387b5e30dd0fff53e2808b25599c3be5b1cdb
Reviewed-on: https://go-review.googlesource.com/38210
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-18 06:57:45 +00:00
Nigel Tao
792d36e11d font/sfnt: support TrueType compound glyphs.
Change-Id: I129e3f7894ad0edccc9e8ca4a21fc9e60e23105b
Reviewed-on: https://go-review.googlesource.com/38111
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-15 23:27:06 +00:00
Nigel Tao
c1a19c11c3 font/sfnt: implement rcurveline and rlinecurve.
Change-Id: I563f9e4a76a5c91d2ef2b6ffccc78550ab582d08
Reviewed-on: https://go-review.googlesource.com/38110
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-15 23:13:12 +00:00
Nigel Tao
793f3be7da font/sfnt: implement {hh,vv}curveto.
Change-Id: I873f8b273d2fe9f39df7d333c36976f1b45239a0
Reviewed-on: https://go-review.googlesource.com/37917
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-12 00:23:23 +00:00
Nigel Tao
069db1da13 font/sfnt: make parseXxx dependencies explicit.
Change-Id: Ib0b76c48cd0b4288700458407077aae4e5911233
Reviewed-on: https://go-review.googlesource.com/37553
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-03-07 07:36:15 +00:00
Russ Cox
e6cbe778da draw: use type aliases for go1.8.typealias builds too
go1.8.typealias is the build tag defined by the unreleased
"Go 1.8 + type aliases" variant in the Go repo's dev.typealias branch.

Change-Id: Iff2566249ecc9a6788b78199743d2005708f1cd7
Reviewed-on: https://go-review.googlesource.com/37511
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-02-27 16:05:05 +00:00
Nigel Tao
c8ae36c95e font/sfnt: implement Font.Kern.
Change-Id: I9ffb93dd3ee08b8871dadf5bc36578710b800199
Reviewed-on: https://go-review.googlesource.com/37410
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-24 09:00:53 +00:00
Nigel Tao
b952c941a6 font/sfnt: check the versions of proprietary fonts.
Change-Id: If8d104f5d0e60b6270e7f6a0762432dfe66cfe48
Reviewed-on: https://go-review.googlesource.com/37174
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-22 03:10:26 +00:00
Nigel Tao
ed91dc314e font/sfnt: add a ppem arg to Font.LoadGlyph.
This lets us load a glyph at e.g. 12 pixels per em.

Change-Id: I048b3db89af8670782953a8361afe0e6373df9b0
Reviewed-on: https://go-review.googlesource.com/37175
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-22 03:05:44 +00:00
Nigel Tao
791b615328 font/sfnt: update test for adobe/SourceSansPro-Regular.ttf.
The latest version of that TTF file fixes the inconsistency between the
TTF and OTF versions.

Change-Id: I0b86f6ddc3f0326e538bdd18fe097be9ad8533ae
Reviewed-on: https://go-review.googlesource.com/37173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-17 22:17:21 +00:00
Nigel Tao
8491f88afc font/sfnt: implement Font.GlyphName.
This is based on the post table in the sfnt file.

Change-Id: I11f7a9bd9024cfc8f92adc5abb4d5356521f0df7
Reviewed-on: https://go-review.googlesource.com/36972
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-17 10:37:04 +00:00
Nigel Tao
153d857a8f font/sfnt: support Symbol fonts such as MS Webdings.
Change-Id: I1297246dad6288345b4b87b885fbeda06a6516ff
Reviewed-on: https://go-review.googlesource.com/37031
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-17 10:20:08 +00:00
Nigel Tao
306b829431 draw: alias the standard library's image/draw's exported types.
This relies on type aliases, a language feature new in Go 1.9.

The package documentation, in draw.go, explicitly gives the intent of
this package:

    This package is a superset of and a drop-in replacement for the
    image/draw package in the standard library.

Drop-in replacement means that I can replace all of my "image/draw"
imports with "golang.org/x/image/draw", to access additional features in
this package, and no further changes are required. That's mostly true,
but not completely true unless we use type aliases.

Without type aliases, users might need to import both "image/draw" and
"golang.org/x/image/draw" in order to convert from two conceptually
equivalent but different (from the compiler's point of view) types, such
as from one draw.Op type to another draw.Op type, to satisfy some other
interface or function signature.

Change-Id: Ice6d000d49b019c2d8761739a904232e9cd01cae
Reviewed-on: https://go-review.googlesource.com/36730
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-02-15 00:37:23 +00:00
Nigel Tao
df2aa51d44 draw: tweak the YCbCr to RGBA conversion formula again.
This is the golang.org/x equivalent of the golang.org/cl/36732 change to
the standard library.

Change-Id: I71c09a72e24c8e1c013769a6fed8f9a031724d9d
Reviewed-on: https://go-review.googlesource.com/36733
Run-TryBot: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2017-02-10 23:08:06 +00:00
Nigel Tao
05f0a469d9 font/sfnt: support non-zero offsets in format-4 cmap tables.
Change-Id: I52592fcde96ce2f3b7700a29169b517a813f9f3c
Reviewed-on: https://go-review.googlesource.com/36371
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-07 21:45:33 +00:00
Nigel Tao
993cf229e6 font/sfnt: fix proprietary fonts and cmap format 12.
Two recent commits ("proprietary fonts" and "cmap format 12") each
passed all of its own tests, but the combination wasn't tested until
both were submitted.

Change-Id: Ic4c2ae8deb1e4623ca5543672dc46d55bfce91a4
Reviewed-on: https://go-review.googlesource.com/36372
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-07 21:42:49 +00:00
Nigel Tao
28d9a8b4a3 font/sfnt: add tests for proprietary fonts.
Change-Id: I1886e24f726598654d2474f0219a8046ba184a9f
Reviewed-on: https://go-review.googlesource.com/36370
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-04 04:20:41 +00:00
Nigel Tao
c8ab450c16 font/sfnt: support cmap format 12.
Change-Id: I2791f5aec860bbb16c6c6945703827afd55c11dc
Reviewed-on: https://go-review.googlesource.com/36291
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-04 03:42:56 +00:00
Nigel Tao
55ae12acc9 font/sfnt: use ../testdata/cmapTest.ttf.
The index numbers can be verified by running ttx over the ttf file:

<GlyphOrder>
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
<GlyphID id="0" name=".notdef"/>
<GlyphID id="1" name=".null"/>
<GlyphID id="2" name="nonmarkingreturn"/>
<GlyphID id="3" name="zero"/>
<GlyphID id="4" name="one"/>
<GlyphID id="5" name="two"/>
<GlyphID id="6" name="A"/>
<GlyphID id="7" name="B"/>
<GlyphID id="8" name="a"/>
<GlyphID id="9" name="ydieresis"/>
<GlyphID id="10" name="Amacron"/>
<GlyphID id="11" name="amacron"/>
<GlyphID id="12" name="uni4E2D"/>
<GlyphID id="13" name="u1F0A1"/>
<GlyphID id="14" name="u1F0B1"/>
<GlyphID id="15" name="u1F0B2"/>
</GlyphOrder>

Change-Id: I8c3b3f09ca25c14d92725d121481287cf57d0d01
Reviewed-on: https://go-review.googlesource.com/36080
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-03 07:45:48 +00:00
Nigel Tao
69afd001f7 font/sfnt: parse the cmap table.
Change-Id: I757d42c9caf419f549696543f0f156cfe3dbfe1a
Reviewed-on: https://go-review.googlesource.com/35512
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-02-02 02:23:30 +00:00
Nigel Tao
83686c5479 font/sfnt: parse the glyf table.
Change-Id: Ib7ff75d99d3641f68f621db4ba2279cc1bda8c3a
Reviewed-on: https://go-review.googlesource.com/35271
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-19 08:01:09 +00:00
Nigel Tao
1ff62c9216 math/fixed: add some Point and Rectangle methods.
These are analogous to the image.Point and image.Rectangle methods in
the standard library.

Change-Id: If8997421a9aeb31d29cfe5eefb79cc481a39df82
Reviewed-on: https://go-review.googlesource.com/34753
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-06 00:18:22 +00:00
Nigel Tao
3ba119400e font: fix rectangle-union for empty rectangles.
The bounding box of a string does not necessarily contain the origin.
Prior to this commit, BoundString(etc, "x") would call grow exactly
once, with the first argument being the (empty) zero rectangle.

Change-Id: Id7d4f6c250ac0749f6dae19d11f4e97f9c6f45bc
Reviewed-on: https://go-review.googlesource.com/34674
Reviewed-by: Dave Day <djd@golang.org>
2016-12-28 23:11:51 +00:00
Raphael Geronimi
f1b1ff53e1 font: add bounds measurement methods
Fixes golang/go#18297

Change-Id: Ib873b18c9bc5cac0d820c6129d9a28cb44f2a8da
Reviewed-on: https://go-review.googlesource.com/34514
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-12-20 10:41:26 +00:00
Nigel Tao
2d771d3c32 font/sfnt: add a Font.Name method.
Also make all of the Buffer fields non-exported. LoadGlyph now returns
the segments instead of setting Buffer.Segments for the caller to use.

Change-Id: I3f87070da5e8f014f88dbca70b62a4cd30e3fd66
Reviewed-on: https://go-review.googlesource.com/34532
Reviewed-by: Dave Day <djd@golang.org>
2016-12-20 10:23:14 +00:00
Nigel Tao
ed90ab82a8 font/sfnt: add a comment about contour ordering.
Change-Id: I591c735cc1c3108aa806b0a7be6c54152fe2029e
Reviewed-on: https://go-review.googlesource.com/34174
Reviewed-by: Dave Day <djd@golang.org>
2016-12-15 04:48:35 +00:00
Nigel Tao
88b013251f font/sfnt: implement rrcurveto.
Change-Id: I2e24293568b296dd916b2ef6a9c1113ffd5f9253
Reviewed-on: https://go-review.googlesource.com/34171
Reviewed-by: Dave Day <djd@golang.org>
2016-12-12 04:37:57 +00:00
Nigel Tao
ce50dba65c font/sfnt: parse Type 2 Charstrings.
Change-Id: I61beec4611612800a519045e2552c513eb83c3f8
Reviewed-on: https://go-review.googlesource.com/33932
Reviewed-by: Dave Day <djd@golang.org>
2016-12-09 07:38:38 +00:00
Nigel Tao
ae63d5d566 font: add some comments for the XxxBytes methods.
Change-Id: I391b539e79d7e35f80d9ee0b8c7c70c2f42e2e99
Reviewed-on: https://go-review.googlesource.com/34095
Reviewed-by: Dave Day <djd@golang.org>
2016-12-08 06:59:50 +00:00
Nigel Tao
e2d0a9f0e6 font/sfnt: parse CFF 2-byte operators and real numbers.
Change-Id: I6f2cdfb44817832cf833883ef6fca692a001b6b1
Reviewed-on: https://go-review.googlesource.com/33813
Reviewed-by: Dave Day <djd@golang.org>
2016-12-05 08:11:59 +00:00
Nigel Tao
5286ed5c2a font/sfnt: parse the CFF table.
Parsing the per-glyph Charstrings will be a follow-up commit.

Change-Id: I52f849a77dd7fa14b6e07420820bdfb4347c2438
Reviewed-on: https://go-review.googlesource.com/33593
Reviewed-by: Dave Day <djd@golang.org>
2016-12-01 07:43:55 +00:00
Nigel Tao
c39d899a5b 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>
2016-11-23 02:01:16 +00:00
Nigel Tao
d2f07f8aaa font/gofont: add style descriptions to the generated package docs.
Fixes golang/go#17964

Change-Id: I3b9f567db7e613a5fcf8fc5e3d4d9f15069fd19b
Reviewed-on: https://go-review.googlesource.com/33370
Reviewed-by: Rob Pike <r@golang.org>
2016-11-18 00:40:29 +00:00
Nigel Tao
b7f8df6bc0 font/gofont: new packages for the Go font family.
See https://blog.golang.org/go-fonts for details.

Change-Id: Ib7219ace9ffe49115d975439b85237472167a1c1
Reviewed-on: https://go-review.googlesource.com/33335
Reviewed-by: Rob Pike <r@golang.org>
2016-11-17 02:12:59 +00:00
Nigel Tao
507b1a44bd vector: measure the fixed point rasterizer's accuracy.
When commit 8874bef1 changed ϕ from 10 to 9, this total diff grew from:
Total diff = 3051, n = 208, avg = 14.66827 out of 65535, or 0.02238%.
to:
Total diff = 6412, n = 208, avg = 30.82692 out of 65535, or 0.04704%.

Also fix a comment typo.

Change-Id: I91cc861a3d3ab282b5431cfb141fb010fd1f8d14
Reviewed-on: https://go-review.googlesource.com/32771
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-15 01:09:02 +00:00
Nigel Tao
98f3e4e74d vector: make args float32 pairs instead of f32.Vec2.
The f32.Vec2 type doesn't seem worth it.

Change-Id: I021c7e13d7e2dd261334f4aa7e867df4fd8f1c3e
Reviewed-on: https://go-review.googlesource.com/32772
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-15 00:52:01 +00:00
Nigel Tao
c78039e8ce vector: tweak the asm register assignment.
This makes the fixed point and floating point code more similar.

Benchmarks don't show any significant change.

Change-Id: I723fa1605eaa248b40e784201b680c16cc3d26a2
Reviewed-on: https://go-review.googlesource.com/32134
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-26 22:33:17 +00:00