From 0d7414bda38c4e957d79f3305a35ff0b4f9915a4 Mon Sep 17 00:00:00 2001 From: be5invis Date: Mon, 31 Aug 2015 08:13:54 +0800 Subject: [PATCH] Supported full width forms of ASCII characters (U+FF01 to U+FF5E). --- glyphs/autobuilds.patel | 18 +++++++++++++++++- glyphs/common-shapes.patel | 11 +++++++++++ glyphs/latin-basic-lower.patel | 14 ++++++-------- glyphs/symbol-punctuation.patel | 6 +++--- makefile | 6 +++--- pass1-cleanup.py | 3 +-- pass3-finalize.py => pass3-features.py | 5 +++-- pass4-fixmeta.js => pass4-finalize.js | 0 8 files changed, 44 insertions(+), 19 deletions(-) rename pass3-finalize.py => pass3-features.py (57%) rename pass4-fixmeta.js => pass4-finalize.js (100%) diff --git a/glyphs/autobuilds.patel b/glyphs/autobuilds.patel index 7a91f55..163e9ca 100644 --- a/glyphs/autobuilds.patel +++ b/glyphs/autobuilds.patel @@ -559,6 +559,22 @@ create-glyph 'servicemark' : glyph-construction { include : doubleSuperscript glyphs.supS glyphs.supM } +# CJK double width letters +define [createDoubleWidth records] : if [not recursive] : begin { + local scale 1.3 + local pendingGlyphs : records.map : [record] -> record.1 + local widenFont : Widen pendingGlyphs scale [scale * 1.1] + foreach (unicode glyphid) [items-of records] : create-glyph [suggestName : 'dw' + glyphid] : glyph-construction { + set-width UPM + if unicode : assign-unicode unicode + include widenFont.(glyphid) AS_BASE + apply-transform [Translate [UPM / 2 - [WIDTH * scale] / 2] 0] true + } +} +if [not recursive] : createDoubleWidth : let [a ()] : begin { + foreach [j : range 1 0x5f] : if [not unicodeGlyphs.[0xff00 + j]] : a.push ([0xff00 + j] unicodeGlyphs.[0x20 + j].name) + * a +} ### Generate MARK and MKMK features set font.features.mark (.) @@ -567,7 +583,7 @@ set font.features.markGlyphs (.) set font.features.gdef (.simple () .ligature () .mark ()) define [buildAnchorDescription glyph inserter propx propy prefix th] : begin { local buf '' - foreach key [items-of : Object.keys glyph.anchors] : if [!th || th.(key)] : buf = buf + ' ' + inserter + ' @' + prefix + key + foreach key [items-of : Object.keys glyph.anchors] : if [!th || th.(key)] : buf = buf + ' ' + inserter + ' @' + prefix + key return buf } # mark diff --git a/glyphs/common-shapes.patel b/glyphs/common-shapes.patel index 00c0532..ccf5e47 100644 --- a/glyphs/common-shapes.patel +++ b/glyphs/common-shapes.patel @@ -403,6 +403,17 @@ define [Thinner glyphs p] : begin { local forkFont : buildFont forkedPara shouldBuildList return forkFont.glyfMap } +define [Widen glyphs p psb] : begin { + local forkedPara : Object.create para + forkedPara.upmscale = 1 + forkedPara.width = WIDTH * p + forkedPara.sb = SB * [fallback psb p] + forkedPara.accentx = ACCENTX * p + local shouldBuildList () + foreach glyphid [items-of glyphs] : set shouldBuildList : shouldBuildList.concat (glyphid :: dependencyProfile.(glyphid)) + local forkFont : buildFont forkedPara shouldBuildList + return forkFont.glyfMap +} define [turned newid unicode id x y mark] : create-glyph [fallback newid : 'turn' + id] : glyph-construction { if unicode : assign-unicode unicode include glyphs`id [if mark false AS_BASE] diff --git a/glyphs/latin-basic-lower.patel b/glyphs/latin-basic-lower.patel index a4930e3..da59263 100644 --- a/glyphs/latin-basic-lower.patel +++ b/glyphs/latin-basic-lower.patel @@ -92,12 +92,10 @@ create-glyph 'g' : glyph-construction { local grightx [RIGHTSB + SB * 0.1 - O] local groundy : [mix DESCENDER [XH * GBARPOS] 0.7] + HALFSTROKE include : spiro { - g4 MIDDLE [XH * GBARPOS - O] [widths 0 [STROKE * 0.65]] - #archv - g4 [SB * 1.25 + STROKE] [mix groundy [XH * GBARPOS] 0.5] [widths 0 [STROKE * 0.95]] - #arcvh - flat [MIDDLE + DESCENDER * 0.15] groundy [widths 0 STROKE] - curl [MIDDLE - DESCENDER * 0.15] groundy + g4 [mix SB RIGHTSB 0.3] [mix XH [XH * GBARPOS - O] 0.95] [widths 0 [STROKE * 0.7]] + alsothru [-0.6] 0.5 [widths 0 [STROKE * 0.95]] + flat [mix SB RIGHTSB 0.425] groundy [widths 0 STROKE] + curl [mix RIGHTSB SB 0.425] groundy archv 4 g4 grightx [mix [DESCENDER + O] groundy 0.53] arcvh @@ -105,7 +103,7 @@ create-glyph 'g' : glyph-construction { archv g4 gleftx [mix [DESCENDER + O] groundy 0.53] arcvh - g4 [MIDDLE + DESCENDER * 0.15] groundy + g4 [mix SB RIGHTSB 0.425] groundy } start-from [RIGHTSB + 0.25 * SB] XH line-to [RIGHTSB + 0.25 * SB] [XH - STROKE] @@ -597,7 +595,7 @@ define [SmallKShape] : glyph-construction { local fine : adviceBlackness 3.5 include : spiro { - g4 [RIGHTSB + O] XH [widths.heading 0 [STROKE * 1.05] DOWNWARD] + g4 [RIGHTSB + O] XH [widths.heading 0 [STROKE * 1.05 * [WIDTH * 2 / UPM]] DOWNWARD] #curl RIGHTSB turn [heading DOWNWARD] bezcontrols 0 0.2 0.5 0.65 8 g4 [SB + STROKE] attach [widths 0 fine] diff --git a/glyphs/symbol-punctuation.patel b/glyphs/symbol-punctuation.patel index 26fe290..50c3d87 100644 --- a/glyphs/symbol-punctuation.patel +++ b/glyphs/symbol-punctuation.patel @@ -245,7 +245,7 @@ create-glyph 'doubledagger' : glyph-construction { create-glyph 'onedotLeader' : glyph-construction { set-width FULLWIDTH assign-unicode 0x2024 - local radius : linreg WIDTH [0.5 * [adviceBlackness 3.25] * PERIODSIZE / DOTSIZE] [WIDTH * 2] PERIODRADIUS FULLWIDTH + local radius : linreg WIDTH [0.5 * [adviceBlackness 3.25] * PERIODSIZE / DOTSIZE] UPM PERIODRADIUS FULLWIDTH include : list { Ring [radius * 2 - O] O [FULLWIDTH / 2 - radius + O] [FULLWIDTH / 2 + radius - O] true } @@ -253,7 +253,7 @@ create-glyph 'onedotLeader' : glyph-construction { create-glyph 'twodotsLEader' : glyph-construction { set-width FULLWIDTH assign-unicode 0x2025 - local radius : linreg WIDTH [0.5 * [adviceBlackness 3.25] * PERIODSIZE / DOTSIZE] [WIDTH * 2] PERIODRADIUS FULLWIDTH + local radius : linreg WIDTH [0.5 * [adviceBlackness 3.25] * PERIODSIZE / DOTSIZE] UPM PERIODRADIUS FULLWIDTH local left : mix 0 FULLWIDTH [1 / 4] local right : mix 0 FULLWIDTH [3 / 4] include : list { @@ -264,7 +264,7 @@ create-glyph 'twodotsLEader' : glyph-construction { create-glyph 'ellipsis' : glyph-construction { set-width FULLWIDTH assign-unicode 0x2026 - local radius : linreg WIDTH [0.5 * [adviceBlackness 3.25] * PERIODSIZE / DOTSIZE] [WIDTH * 2] PERIODRADIUS FULLWIDTH + local radius : linreg WIDTH [0.5 * [adviceBlackness 3.25] * PERIODSIZE / DOTSIZE] UPM PERIODRADIUS FULLWIDTH local left : mix 0 FULLWIDTH [1 / 6] local right : mix 0 FULLWIDTH [5 / 6] include : list { diff --git a/makefile b/makefile index 3025fde..52a837b 100644 --- a/makefile +++ b/makefile @@ -46,13 +46,13 @@ $(FEATURE) : $(OBJDIR)/.pass0-%.fea : $(OBJDIR)/.pass0-%.ab.fea features/common. cat $^ > $@ # Pass 1 : Outline cleanup and merge -$(PASS1) : $(OBJDIR)/.pass1-%.ttf : pass1-cleanup.py $(OBJDIR)/.pass0-%.ttf $(OBJDIR)/.pass0-%.fea +$(PASS1) : $(OBJDIR)/.pass1-%.ttf : pass1-cleanup.py $(OBJDIR)/.pass0-%.ttf fontforge -quiet -script $^ $@ $(SUPPRESS_ERRORS) $(PASS2) : $(OBJDIR)/.pass2-%.ttf : pass2-smartround.js $(OBJDIR)/.pass1-%.ttf node $^ $@ --upm $(TARGETUPM) -$(PASS3) : $(OBJDIR)/.pass3-%.ttf : pass3-finalize.py $(OBJDIR)/.pass2-%.ttf +$(PASS3) : $(OBJDIR)/.pass3-%.ttf : pass3-features.py $(OBJDIR)/.pass2-%.ttf $(OBJDIR)/.pass0-%.fea fontforge -quiet -script $^ $@ $(TARGETUPM) -$(PASS4) : $(OBJDIR)/.pass4-%.ttf : pass4-fixmeta.js $(OBJDIR)/.pass3-%.ttf +$(PASS4) : $(OBJDIR)/.pass4-%.ttf : pass4-finalize.js $(OBJDIR)/.pass3-%.ttf @node $^ $@.a.ttf @ttx -o $@.a.ttx $@.a.ttf @ttx -o $@ $@.a.ttx diff --git a/pass1-cleanup.py b/pass1-cleanup.py index e706f20..0d48e6a 100644 --- a/pass1-cleanup.py +++ b/pass1-cleanup.py @@ -43,8 +43,7 @@ font.transform(psMat.skew(-font.italicangle / 180 * math.pi)) # Feature merging and output print "Finalize: ", font.fontname font.em = oldem -font.mergeFeature(sys.argv[2]) font.canonicalContours() font.canonicalStart() -font.generate(sys.argv[3], flags = ("short-post", "opentype")) \ No newline at end of file +font.generate(sys.argv[2]) \ No newline at end of file diff --git a/pass3-finalize.py b/pass3-features.py similarity index 57% rename from pass3-finalize.py rename to pass3-features.py index cbdd6e9..7730dfc 100644 --- a/pass3-finalize.py +++ b/pass3-features.py @@ -5,9 +5,10 @@ import math source = sys.argv[1] font = fontforge.open(source) -font.em = int(sys.argv[3]) +font.em = int(sys.argv[4]) font.selection.all() font.round() font.removeOverlap() font.simplify(0.1) -font.generate(sys.argv[2], flags = ("short-post", "opentype")) \ No newline at end of file +font.mergeFeature(sys.argv[2]) +font.generate(sys.argv[3], flags = ("short-post", "opentype")) \ No newline at end of file diff --git a/pass4-fixmeta.js b/pass4-finalize.js similarity index 100% rename from pass4-fixmeta.js rename to pass4-finalize.js