From 19e7a1a5db577d3ee952d0b3d75dbfaac4a56076 Mon Sep 17 00:00:00 2001 From: Belleve Invis Date: Fri, 20 Mar 2020 04:51:46 -0700 Subject: [PATCH] Implement thousand-digit grouping under `THND` feature. #453 --- changes/3.0.0-rc.4.md | 3 +- glyphs/autobuild-transformed.ptl | 22 ++++++++++++++ glyphs/common-shapes.ptl | 3 +- glyphs/symbol-mosaic.ptl | 5 +++ otl/gsub-thousands.ptl | 52 ++++++++++++++++++++++++++++++++ otl/index.ptl | 2 ++ 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 otl/gsub-thousands.ptl diff --git a/changes/3.0.0-rc.4.md b/changes/3.0.0-rc.4.md index c428ab8ac..baabb1bd2 100644 --- a/changes/3.0.0-rc.4.md +++ b/changes/3.0.0-rc.4.md @@ -2,4 +2,5 @@ * Add large brackets (U+239B ... U+23AD) and extensible integral symbols (U+2320, U+2321, U+23AE). * Add arrow U+21DE, U+21DF, U+2908, U+2909. * Add logical symbol U+22A9, U+22AA, U+22AB, U+22AE, U+22AF. - * Cancelled ligation around regex look-around. \ No newline at end of file + * Cancelled ligation around regex look-around. + * Implement thousand-digit grouping under `THND` feature. \ No newline at end of file diff --git a/glyphs/autobuild-transformed.ptl b/glyphs/autobuild-transformed.ptl index ef1855f18..e27eb2d66 100644 --- a/glyphs/autobuild-transformed.ptl +++ b/glyphs/autobuild-transformed.ptl @@ -536,3 +536,25 @@ glyph-block Autobuild-Transformed : begin list 0x225F "equal" {"question"} if [not recursive] : createAccentedEquals 8 0.3 : list list 0x225d "equal" {"d" "e" "f"} + + define [createGroupedDigits shrink crowd numberEntries] : begin + define numberGlyphIDs {} + foreach [gid : items-of numberEntries] : if glyphs.(gid) : begin + numberGlyphIDs.push gid + if glyphs.(gid).featureSelector : begin + foreach [{k v} : pairs-of glyphs.(gid).featureSelector] : begin + numberGlyphIDs.push v + + local derivedFont : Thinner numberGlyphIDs shrink crowd + foreach [nd : items-of {0 1 2 3 4 5 6}] + foreach [gid : items-of numberGlyphIDs] : create-glyph (gid + ".nd" + nd) : glyph-construction + include glyphs.(gid) + define underlineExt : WIDTH * 0.4 + if (nd >= 3 && nd <= 5) : include : intersection + HBarBottom (MIDDLE - underlineExt) (MIDDLE + underlineExt) (DESCENDER * 0.75) [adviceBlackness 4] + begin glyphs.'denseShade.hwid' + + if [not recursive] : createGroupedDigits 0.9 3.0 { + 'zero.lnum' 'one.lnum' 'two.lnum' 'three.lnum' 'four.lnum' + 'five.lnum' 'six.lnum' 'seven.lnum' 'eight.lnum' 'nine.lnum' + } diff --git a/glyphs/common-shapes.ptl b/glyphs/common-shapes.ptl index 5ca2f136a..40282bda9 100644 --- a/glyphs/common-shapes.ptl +++ b/glyphs/common-shapes.ptl @@ -667,8 +667,9 @@ glyph-block CommonShapes : begin forkedPara.diversityM = 1 return : Fork glyphs forkedPara - define [Thinner glyphs p] : begin + define [Thinner glyphs p crowd] : begin local forkedPara : Object.create para + forkedPara.stroke = [adviceBlackness : fallback crowd 1] forkedPara.width = WIDTH * p forkedPara.accentx = ACCENTX * p forkedPara.jut = JUT * p diff --git a/glyphs/symbol-mosaic.ptl b/glyphs/symbol-mosaic.ptl index f7daac77f..1b385682b 100644 --- a/glyphs/symbol-mosaic.ptl +++ b/glyphs/symbol-mosaic.ptl @@ -345,6 +345,11 @@ glyph-block Symbol-Mosaic : begin include : Shade 4 FillLight save [MangleName 'lightShade'] [MangleUnicode 0x2591] + sketch # denseShade + set-width MosaicWidth + include : Shade 16 FillHeavy + save [MangleName 'denseShade'] + define [MediumShade unicode bits] : sketch set-width MosaicWidth include : Shade 8 FillMedium : PatternPolygon22 bits diff --git a/otl/gsub-thousands.ptl b/otl/gsub-thousands.ptl new file mode 100644 index 000000000..28c802758 --- /dev/null +++ b/otl/gsub-thousands.ptl @@ -0,0 +1,52 @@ +import [add-common-feature add-feature add-lookup ChainRuleBuilder] from "./table-util" + +define-operator "~>" 880 'right' : syntax-rules + `(@l ~> @r) `{.left @l .right @r} + +export : define [buildGsubThousands sink glyphs] : begin + define Thousand : add-feature sink 'THND' + define chain-rule : ChainRuleBuilder sink + define numberEntries { + 'zero.lnum' 'one.lnum' 'two.lnum' 'three.lnum' 'four.lnum' + 'five.lnum' 'six.lnum' 'seven.lnum' 'eight.lnum' 'nine.lnum' + } + define numberGlyphIDs {} + foreach [gid : items-of numberEntries] : if glyphs.(gid) : begin + numberGlyphIDs.push gid + if glyphs.(gid).featureSelector : begin + foreach [{k v} : pairs-of glyphs.(gid).featureSelector] : begin + numberGlyphIDs.push v + + define [nd s] : numberGlyphIDs.map : lambda [x] "\(x).nd\(s)" + + define lookupThousand1 : add-lookup sink : object + .type 'gsub_chaining' + .subtables : list + chain-rule ({'period'} ~> null) (numberGlyphIDs ~> [nd 2]) (numberGlyphIDs ~> null) (numberGlyphIDs ~> null) + chain-rule ([nd 2] ~> null) (numberGlyphIDs ~> [nd 1]) + chain-rule ([nd 1] ~> null) (numberGlyphIDs ~> [nd 6]) + chain-rule ([nd 6] ~> null) (numberGlyphIDs ~> [nd 5]) + chain-rule ([nd 5] ~> null) (numberGlyphIDs ~> [nd 4]) + chain-rule ([nd 4] ~> null) (numberGlyphIDs ~> [nd 3]) + chain-rule ([nd 3] ~> null) (numberGlyphIDs ~> [nd 2]) + + define lookupThousand2 : add-lookup sink : object + .type 'gsub_chaining' + .subtables : list + chain-rule (numberGlyphIDs ~> [nd 0]) (numberGlyphIDs ~> null) (numberGlyphIDs ~> null) (numberGlyphIDs ~> null) + chain-rule ([nd 0] ~> null) (numberGlyphIDs ~> [nd 0]) + + define lookupThousand3 : add-lookup sink : object + .type 'gsub_reverse' + .subtables : list + object [match {[nd 0] [nd 0]}] [to [nd 1]] [inputIndex 0] + object [match {[nd 0] [nd 1]}] [to [nd 2]] [inputIndex 0] + object [match {[nd 0] [nd 2]}] [to [nd 3]] [inputIndex 0] + object [match {[nd 0] [nd 3]}] [to [nd 4]] [inputIndex 0] + object [match {[nd 0] [nd 4]}] [to [nd 5]] [inputIndex 0] + object [match {[nd 0] [nd 5]}] [to [nd 6]] [inputIndex 0] + object [match {[nd 0] [nd 6]}] [to [nd 1]] [inputIndex 0] + + + Thousand.lookups.push lookupThousand1 lookupThousand2 lookupThousand3 + add-common-feature sink Thousand \ No newline at end of file diff --git a/otl/index.ptl b/otl/index.ptl index e088c7018..dae05710c 100644 --- a/otl/index.ptl +++ b/otl/index.ptl @@ -10,6 +10,7 @@ import [buildCCMP] from './gsub-ccmp' import [buildPairFeature] from './gsub-pairing' import [buildCVSS] from './gsub-cv-ss' import [buildLOCL] from './gsub-locl' +import [buildGsubThousands] from './gsub-thousands' import [buildMarkMkmk] from "./gpos-mark-mkmk" import [BuildCompatLigatures] from './compat-ligature' @@ -39,6 +40,7 @@ define [buildGSUB para glyphs glyphList markGlyphs] : begin buildLigations gsub plm glyphs buildCVSS gsub para glyphList + buildGsubThousands gsub glyphs set gsub.lookupOrder : topsort gsub.lookupDep return gsub