Implement thousand-digit grouping under THND feature. #453

This commit is contained in:
Belleve Invis 2020-03-20 04:51:46 -07:00
parent c72069af29
commit 19e7a1a5db
6 changed files with 85 additions and 2 deletions

View file

@ -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.
* Cancelled ligation around regex look-around.
* Implement thousand-digit grouping under `THND` feature.

View file

@ -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'
}

View file

@ -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

View file

@ -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

52
otl/gsub-thousands.ptl Normal file
View file

@ -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

View file

@ -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