From 2c9074b9aac388cac1da4f83607a8f1333e875b4 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 18 Mar 2017 22:40:49 +1100 Subject: [PATCH] font/sfnt: implement flagWeHaveATwoByTwo. Change-Id: I9f4577b57f25a85ef0639c34215adf40df61c5ab Reviewed-on: https://go-review.googlesource.com/38274 Reviewed-by: David Crawshaw --- font/sfnt/sfnt.go | 4 +- font/sfnt/sfnt_test.go | 64 +++++++++++++ font/sfnt/truetype.go | 3 - font/testdata/glyfTest.sfd | 183 +++++++++++++++++++++++++++++++------ font/testdata/glyfTest.ttf | Bin 2000 -> 2136 bytes 5 files changed, 219 insertions(+), 35 deletions(-) diff --git a/font/sfnt/sfnt.go b/font/sfnt/sfnt.go index 20ade4d..a497d0e 100644 --- a/font/sfnt/sfnt.go +++ b/font/sfnt/sfnt.go @@ -1194,9 +1194,9 @@ func tform(txx, txy, tyx, tyy int16, dx, dy, x, y fixed.Int26_6) (newX, newY fix const half = 1 << 13 newX = dx + fixed.Int26_6((int64(x)*int64(txx)+half)>>14) + - fixed.Int26_6((int64(y)*int64(txy)+half)>>14) + fixed.Int26_6((int64(y)*int64(tyx)+half)>>14) newY = dy + - fixed.Int26_6((int64(x)*int64(tyx)+half)>>14) + + fixed.Int26_6((int64(x)*int64(txy)+half)>>14) + fixed.Int26_6((int64(y)*int64(tyy)+half)>>14) return newX, newY } diff --git a/font/sfnt/sfnt_test.go b/font/sfnt/sfnt_test.go index 4f10e84..dc1c9c5 100644 --- a/font/sfnt/sfnt_test.go +++ b/font/sfnt/sfnt_test.go @@ -388,6 +388,70 @@ func TestTrueTypeSegments(t *testing.T) { lineTo(614, 1638), lineTo(614, 0), lineTo(205, 0), + }, { + // five + // - contour #0 + moveTo(0, 0), + lineTo(0, 100), + lineTo(400, 100), + lineTo(400, 0), + lineTo(0, 0), + }, { + // six + // - contour #0 + moveTo(0, 0), + lineTo(0, 100), + lineTo(400, 100), + lineTo(400, 0), + lineTo(0, 0), + // - contour #1 + translate(111, 234, moveTo(205, 0)), + translate(111, 234, lineTo(205, 1638)), + translate(111, 234, lineTo(614, 1638)), + translate(111, 234, lineTo(614, 0)), + translate(111, 234, lineTo(205, 0)), + }, { + // seven + // - contour #0 + moveTo(0, 0), + lineTo(0, 100), + lineTo(400, 100), + lineTo(400, 0), + lineTo(0, 0), + // - contour #1 + transform(1<<13, 0, 0, 1<<13, 56, 117, moveTo(205, 0)), + transform(1<<13, 0, 0, 1<<13, 56, 117, lineTo(205, 1638)), + transform(1<<13, 0, 0, 1<<13, 56, 117, lineTo(614, 1638)), + transform(1<<13, 0, 0, 1<<13, 56, 117, lineTo(614, 0)), + transform(1<<13, 0, 0, 1<<13, 56, 117, lineTo(205, 0)), + }, { + // eight + // - contour #0 + moveTo(0, 0), + lineTo(0, 100), + lineTo(400, 100), + lineTo(400, 0), + lineTo(0, 0), + // - contour #1 + transform(3<<13, 0, 0, 1<<13, 56, 117, moveTo(205, 0)), + transform(3<<13, 0, 0, 1<<13, 56, 117, lineTo(205, 1638)), + transform(3<<13, 0, 0, 1<<13, 56, 117, lineTo(614, 1638)), + transform(3<<13, 0, 0, 1<<13, 56, 117, lineTo(614, 0)), + transform(3<<13, 0, 0, 1<<13, 56, 117, lineTo(205, 0)), + }, { + // nine + // - contour #0 + moveTo(0, 0), + lineTo(0, 100), + lineTo(400, 100), + lineTo(400, 0), + lineTo(0, 0), + // - contour #1 + transform(22381, 8192, 5996, 14188, 237, 258, moveTo(205, 0)), + transform(22381, 8192, 5996, 14188, 237, 258, lineTo(205, 1638)), + transform(22381, 8192, 5996, 14188, 237, 258, lineTo(614, 1638)), + transform(22381, 8192, 5996, 14188, 237, 258, lineTo(614, 0)), + transform(22381, 8192, 5996, 14188, 237, 258, lineTo(205, 0)), }} testSegments(t, "glyfTest.ttf", wants) diff --git a/font/sfnt/truetype.go b/font/sfnt/truetype.go index 553302f..cce0cc7 100644 --- a/font/sfnt/truetype.go +++ b/font/sfnt/truetype.go @@ -285,9 +285,6 @@ func loadCompoundGlyf(f *Font, b *Buffer, data []byte, stackBottom, recursionDep elem.transformYX = int16(u16(data[4:])) elem.transformYY = int16(u16(data[6:])) data = data[8:] - // TODO: find a font that does this, so we can verify that - // we've got the xy vs yx ordering right. - return errUnsupportedCompoundGlyph } } diff --git a/font/testdata/glyfTest.sfd b/font/testdata/glyfTest.sfd index e61c54c..6b57a54 100644 --- a/font/testdata/glyfTest.sfd +++ b/font/testdata/glyfTest.sfd @@ -2,7 +2,7 @@ SplineFontDB: 3.0 FontName: glyfTest FullName: glyfTest FamilyName: glyfTest -Weight: Regular +Weight: Book Copyright: Copyright 2016 The Go Authors. All rights reserved.\nUse of this font is governed by a BSD-style license that can be found at https://golang.org/LICENSE. Version: 001.000 ItalicAngle: -11.25 @@ -10,38 +10,75 @@ UnderlinePosition: -204 UnderlineWidth: 102 Ascent: 1638 Descent: 410 +sfntRevision: 0x00010000 LayerCount: 2 Layer: 0 1 "Back" 1 Layer: 1 1 "Fore" 0 -XUID: [1021 367 888937226 7862908] +XUID: [1021 367 888937226 5879518] FSType: 8 -OS2Version: 0 +OS2Version: 4 OS2_WeightWidthSlopeOnly: 0 OS2_UseTypoMetrics: 1 CreationTime: 1484386143 -ModificationTime: 1484386143 +ModificationTime: 1489831626 PfmFamily: 17 TTFWeight: 400 TTFWidth: 5 LineGap: 184 VLineGap: 0 -OS2TypoAscent: 0 -OS2TypoAOffset: 1 -OS2TypoDescent: 0 -OS2TypoDOffset: 1 +Panose: 2 0 5 3 0 0 0 0 0 0 +OS2TypoAscent: 1638 +OS2TypoAOffset: 0 +OS2TypoDescent: -410 +OS2TypoDOffset: 0 OS2TypoLinegap: 184 -OS2WinAscent: 0 -OS2WinAOffset: 1 +OS2WinAscent: 1984 +OS2WinAOffset: 0 OS2WinDescent: 0 -OS2WinDOffset: 1 -HheadAscent: 0 -HheadAOffset: 1 +OS2WinDOffset: 0 +HheadAscent: 1984 +HheadAOffset: 0 HheadDescent: 0 -HheadDOffset: 1 +HheadDOffset: 0 +OS2SubXSize: 1331 +OS2SubYSize: 1433 +OS2SubXOff: 55 +OS2SubYOff: 286 +OS2SupXSize: 1331 +OS2SupYSize: 1433 +OS2SupXOff: -191 +OS2SupYOff: 983 +OS2StrikeYSize: 102 +OS2StrikeYPos: 530 OS2Vendor: 'PfEd' +OS2CodePages: 00000001.00000000 +OS2UnicodeRanges: 00000001.00000000.00000000.00000000 MarkAttachClasses: 1 DEI: 91125 -LangName: 1033 +ShortTable: cvt 2 + 68 + 1297 +EndShort +ShortTable: maxp 16 + 1 + 0 + 10 + 18 + 2 + 8 + 2 + 2 + 0 + 1 + 1 + 0 + 64 + 46 + 2 + 1 +EndShort +LangName: 1033 "" "" "Regular" "FontForge : glyfTest : 18-3-2017" "" "Version 001.000" +GaspTable: 1 65535 2 0 Encoding: UnicodeBmp UnicodeInterp: none NameList: Adobe Glyph List @@ -49,18 +86,47 @@ DisplaySize: -24 AntiAlias: 1 FitToEm: 1 WinInfo: 0 32 23 -BeginPrivate: 0 -EndPrivate -TeXData: 1 0 0 346030 173015 115343 0 -1048576 115343 783286 444596 497025 792723 393216 433062 380633 303038 157286 324010 404750 52429 2506097 1059062 262144 -BeginChars: 65536 2 +BeginChars: 65539 10 + +StartChar: .notdef +Encoding: 65536 -1 0 +Width: 748 +Flags: W +LayerCount: 2 +Fore +SplineSet +68 0 m 1,0,-1 + 68 1365 l 1,1,-1 + 612 1365 l 1,2,-1 + 612 0 l 1,3,-1 + 68 0 l 1,0,-1 +136 68 m 1,4,-1 + 544 68 l 1,5,-1 + 544 1297 l 1,6,-1 + 136 1297 l 1,7,-1 + 136 68 l 1,4,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: .null +Encoding: 65537 -1 1 +Width: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: nonmarkingreturn +Encoding: 65538 -1 2 +Width: 682 +Flags: W +LayerCount: 2 +EndChar StartChar: zero -Encoding: 48 48 0 +Encoding: 48 48 3 Width: 1228 -VWidth: 0 Flags: W -HStem: 0 205<508 700> 1434 205<529 720> -VStem: 205 164<500 1088> 860 164<550 1139> LayerCount: 2 Fore SplineSet @@ -69,7 +135,7 @@ SplineSet 369 471 369 471 435 338 c 0,4,5 502 205 502 205 614 205 c 0,6,7 860 205 860 205 860 1024 c 0,8,9 - 860 1167 860 1167 793 1300 c 0,10,11 + 860 1167 860 1167 793 1300 c 1,10,11 727 1434 727 1434 614 1434 c 0,0,1 614 1638 m 0,12,13 1024 1638 1024 1638 1024 819 c 128,-1,14 @@ -81,22 +147,79 @@ Validated: 1 EndChar StartChar: one -Encoding: 49 49 1 +Encoding: 49 49 4 Width: 819 -VWidth: 0 Flags: W -HStem: 0 43G<205 614> -VStem: 205 410<0 1638> LayerCount: 2 Fore SplineSet -205 0 m 25,0,-1 +205 0 m 1,0,-1 205 1638 l 1,1,-1 614 1638 l 1,2,-1 614 0 l 1,3,-1 - 205 0 l 25,0,-1 + 205 0 l 1,0,-1 EndSplineSet Validated: 1 EndChar + +StartChar: five +Encoding: 53 53 5 +Width: 400 +Flags: W +LayerCount: 2 +Fore +SplineSet +0 0 m 1,0,-1 + 0 100 l 1,1,-1 + 400 100 l 1,2,-1 + 400 0 l 1,3,-1 + 0 0 l 1,0,-1 +EndSplineSet +Validated: 1 +EndChar + +StartChar: six +Encoding: 54 54 6 +Width: 400 +Flags: W +LayerCount: 2 +Fore +Refer: 5 53 N 1 0 0 1 0 0 2 +Refer: 4 49 N 1 0 0 1 111 234 2 +Validated: 1 +EndChar + +StartChar: seven +Encoding: 55 55 7 +Width: 400 +Flags: W +LayerCount: 2 +Fore +Refer: 5 53 N 1 0 0 1 0 0 2 +Refer: 4 49 N 0.5 0 0 0.5 56 117 2 +Validated: 1 +EndChar + +StartChar: eight +Encoding: 56 56 8 +Width: 400 +Flags: W +LayerCount: 2 +Fore +Refer: 5 53 N 1 0 0 1 0 0 2 +Refer: 4 49 N 1.5 0 0 0.5 56 117 2 +Validated: 1 +EndChar + +StartChar: nine +Encoding: 57 57 9 +Width: 400 +Flags: W +LayerCount: 2 +Fore +Refer: 5 53 N 1 0 0 1 0 0 2 +Refer: 4 49 N 1.36603 0.5 0.365967 0.865967 237 258 2 +Validated: 1 +EndChar EndChars EndSplineFont diff --git a/font/testdata/glyfTest.ttf b/font/testdata/glyfTest.ttf index 587b3fe0bab9d652501f82f4cf3881f5e4a98608..2ae24f8e218a4dcb057b3a83104b8558b607a681 100644 GIT binary patch delta 872 zcmYjQO-NKx6#nk}9~0k{nrSAlun>omKrWtjD8E0rz6pCq;1ul#S zK@bRS3ThD~)FQ$~iwZ#{jaIdls6|2x37o$BW+?CD+;hM0{M>WS@{2)afY;gr@JBbM5rdq` z|7Cc|i?E{*CnJT&b@HU}q$you20ARgS$~K&QA6$C5)Hm~V`y^-ug!UPPSl;I&(_81 z$qAy`%LQ~3u^M6xb<_s6VE!hwbJjorExBCoQ*KFmxn;_6T{le2=blqO9Q59Xb<3}n znflO=IL2{@aSAb%n0|@*O-7EWmF_(?oRxQhHN|8VO)Y!N#Y`*)cy~crHT(Pr*c1FF z>qy~yo)B{MF@ud`R+PILw}pkuxvEOflC_pv-gxhcn?`N;W|=Pw^*@a3}VK+xBmta})+2rp5+8pi@3-~CShh%JC3j4y* R$BSgJGCTXt)9bH#{{ps8nD_ty delta 724 zcmX|9O-vI(7=5$5vs(mg6(liMvIhAk#56(_>Q922h#ri_E^U`$D6O`VYA|r} zM2yMk!Hd;+^k68&aKxL59!&J$fuQl^L2r66F|Kcy#+`gS``(-R=6&Dnr`Y@GA_Rb) zSb~mhCNnv4YvJpCz*-|4KRGs@K@`2j4~cuvT}Td2y_j(TQ6$dhN^S*F^9%7N<9Keq zW@Ak50(6_YG3{0>zR%3CmWd)xwr$G(*wPuVZ_7z zK$?gS5a+=*XM-caDRvideBb{7q58EERnuOpC9QKJyag581#HmDTqOsJiZ|tHzmVOncJuWg^1!UK!(2 zTU!V`8f`EU(_XIbkV#DrV*n|2%<9vJ2U4nFjds!erNYhXOnJ_BoK(Vb99vzt_P4WH u{?85g0-m~|?MX?NC1|=UY_edPTI