Files
Iosevka/glyphs/autobuild-accents.ptl
T
Belleve Invis e44d8471e7 Fix substitution of i-ogonek and upper combining marks.
Fix broken cup (`∪`) and cap (`∩`) symbol
Fix Fix broken degree-C and degree-F ligature.
Closes #449, #450.
2020-03-16 21:06:13 -07:00

284 lines
8.7 KiB
Plaintext

###### Automatic builds
$$include '../meta/macros.ptl'
import 'unorm' as unorm
import [fallback suggestGC] from '../support/utils'
glyph-module
glyph-block AutoBuild-Accents : begin
# Build accented glyphs
define [isAboveMark mark] : mark && mark.anchors && mark.anchors.above && mark.anchors.above.type === MARK
define [iotaBelowToLF p j parts] : if (p === glyphs.iotaBelow) : set parts.(j) glyphs.iotaLF
define [ogonekBelowToTR p j parts] : if (p === glyphs.ogonekBelow) : set parts.(j) glyphs.ogonekTR
define [subParts parts] : begin
local hasMarkAbove false
foreach p [items-of parts] : if [isAboveMark p] : set hasMarkAbove true
# replace dotted-i and dotted-j with dotless equalivents
if (hasMarkAbove && parts.0.related && parts.0.related.dotless) : begin
local dotless glyphs.(parts.0.related.dotless)
if dotless : set parts.0 dotless
# replace below marks with trailing marks
if parts.0.anchors.lf : parts.forEach iotaBelowToLF
if parts.0.anchors.trailing : parts.forEach ogonekBelowToTR
# composite greek Overmarks
for [local j 0] (j < parts.length) [inc j] : piecewise
(parts.(j) === glyphs.commaAbove) : begin
piecewise
(parts.(j + 1) === glyphs.graveAbove) : begin
set parts.(j) null; set parts.(j + 1) glyphs.psilivaria
(parts.(j + 1) === glyphs.acuteAbove) : begin
set parts.(j) null; set parts.(j + 1) glyphs.psilioxia
(parts.(j + 1) === glyphs.perispomeniAbove) : begin
set parts.(j) null; set parts.(j + 1) glyphs.psiliperispomeni
(parts.(j) === glyphs.revCommaAbove) : begin
piecewise
(parts.(j + 1) === glyphs.graveAbove) : begin
set parts.(j) null; set parts.(j + 1) glyphs.dasiavaria
(parts.(j + 1) === glyphs.acuteAbove) : begin
set parts.(j) null; set parts.(j + 1) glyphs.dasiaoxia
(parts.(j + 1) === glyphs.perispomeniAbove) : begin
set parts.(j) null; set parts.(j + 1) glyphs.dasiaperispomeni
return parts
define [pad _s n] : begin
local s _s
while (s.length < n) : s = '0' + s
return s
local foundDecompositions {.}
define [decideName namingParts parts code] : begin
local baseName namingParts.0.name
local glyphName baseName
foreach [part : namingParts.slice 1] : if part : glyphName = glyphName + [fallback part.shortName part.name]
if foundDecompositions.(glyphName) : begin
local j 2
while foundDecompositions.(glyphName + j) [inc j]
set glyphName (glyphName + j)
if (glyphName.length > 27) : set glyphName ('uni' + [pad [[code.toString 16].toUpperCase] 4])
return glyphName
local [buildForCode code] : if [not unicodeGlyphs.(code)] : begin
local str : String.fromCharCode code
local nfd : fallback customDecompositions.(str) : unorm.nfd str
if (nfd.length > 1) : begin
local parts {}
local allFound true
foreach j [range 0 nfd.length] : begin
local part unicodeGlyphs.([nfd.charCodeAt j])
if [not part] : then : set allFound false
: else : set parts.(j) unicodeGlyphs.([nfd.charCodeAt j])
if allFound : begin
local namingParts : parts.slice 0
set parts : subParts parts
local glyphName : decideName namingParts parts code
set foundDecompositions.(glyphName) {glyphName code parts}
if recursiveCodes : recursiveCodes.forEach buildForCode
: else : foreach code [range 0x0000 0xFFFF] : buildForCode code
suggestGC
local s_code nothing
local s_parts nothing
define construction : glyph-construction
if s_code : assign-unicode s_code
include s_parts.0 AS_BASE
set-width s_parts.0.advanceWidth
local names {s_parts.0.name}
foreach part [items-of : s_parts.slice 1] : if part : begin
include part
names.push part.name
if (part.name === 'rtailBR') : eject-contour 'serifRB'
define [GlyphProcShared origGlyphName relation parts] : begin
local base parts.0
local origBase base
local marks : parts.slice 1
local targetGlyphName : origGlyphName + [if relation ("." + relation) ""]
if (relation && base.related && base.related.(relation))
set base glyphs.(base.related.(relation))
return { origBase base marks targetGlyphName }
define [RootGlyphProc origGlyphName relation code parts] : begin
local { origBase base marks targetGlyphName } : GlyphProcShared origGlyphName relation parts
if (relation && base === origBase) : return nothing
set s_code : if relation null code
set s_parts { base :: marks }
create-glyph targetGlyphName construction
define [VariantGlyphProc origGlyphName relation _pa] : if (!recursive) : begin
local { origBase base marks targetGlyphName } : GlyphProcShared origGlyphName relation parts
if (relation && base === origBase) : return nothing
if [not base.featureSelector] : return nothing
local h {.}
foreach [feature : items-of : Object.keys base.featureSelector] : begin
local variant base.featureSelector.(feature)
local variantRoot glyphs.(variant)
if variantRoot : begin
set s_code null
set s_parts { variantRoot :: marks }
create-glyph (targetGlyphName + '.' + feature) construction
set h.(feature) (targetGlyphName + '.' + feature)
if glyphs.(targetGlyphName) : set glyphs.(targetGlyphName).featureSelector h
define [LinkRelatedGlyph origGlyphName relation] : begin
if [not relation] : return nothing
if [not glyphs.(origGlyphName)] : return nothing
local targetGlyphName : origGlyphName + [if relation ("." + relation) ""]
if [not glyphs.(targetGlyphName)] : return nothing
if [not glyphs.(origGlyphName).related] : set glyphs.(origGlyphName).related {.}
set glyphs.(origGlyphName).related.(relation) targetGlyphName
foreach [_id : items-of : Object.keys foundDecompositions] : begin
local {glyphName code parts} foundDecompositions.(_id)
foreach [relation : items-of {null 'dotless'}] : begin
RootGlyphProc glyphName relation code parts
VariantGlyphProc glyphName relation parts
LinkRelatedGlyph glyphName relation
suggestGC
define customDecompositions : object
# Latvians use comma instead of cedillas in several letters.
# Record them as custom decomposition.
."\u0156" "R\u0326"
."\u0157" "r\u0326"
."\u0136" "K\u0326"
."\u0137" "k\u0326"
."\u0145" "N\u0326"
."\u0146" "n\u0326"
."\u013B" "L\u0326"
."\u013C" "l\u0326"
."\u0122" "G\u0326"
."\u0123" "g\u0312"
# autobuild Latin glyphs
."\u0197" "I\u0335"
."\u019A" "l\u0335"
."\u0248" "J\u0335"
."\u0249" "j\u0335"
."\u0268" "i\u0335"
."\u024C" "R\u0335"
."\u024D" "r\u0335"
."\u01B5" "Z\u0335"
."\u01B6" "z\u0335"
."\u1D7B" "\u026A\u0335"
."\u1D7C" "\u0269\u0335"
."\u1D7F" "\u028A\uE091"
."\u0289" "u\uE091"
."\u0244" "U\uE091"
."\u01E5" "g\uE091"
."\u01BB" "2\uE091"
."\u024E" "Y\uE091"
."\u04B0" "\u04AE\u0335"
."\u04B1" "\u04AF\u0335"
."\u024F" "y\uE091"
."\uAB30" "\uAB64\uE091"
."\u1D7D" "p\uE091"
."\u0142" "l\uE090"
."\u013E" "l\u0315"
."\u0165" "t\u0315"
."\u023A" "A\u0338"
."\u023B" "C\u0338"
."\u023C" "c\u0337"
."\u023E" "T\u0338"
."\u0246" "E\u0338"
."\u0247" "e\u0337"
."\u0290" "z\u0322"
."\u0256" "d\u0322"
."\u0273" "n\u0322"
."\u01AE" "T\u0322"
."\u1D8F" "a\u0322"
."\u1D90" "\u0251\u0322"
."\u1D91" "\u0257\u0322"
."\u1D99" "u\u0322"
."\u1E10" "D\u0326"
."\u1E11" "d\u0326"
."\u1E9A" "a\u0357"
."\u1E9C" "\u017F\uE090"
."\u1E9D" "\u017F\u0335"
."\u1EDC" "\u01A0\u0300"
."\u1EDD" "\u01A1\u0300"
."\u1EDA" "\u01A0\u0301"
."\u1EDB" "\u01A1\u0301"
."\u1EDE" "\u01A0\u0309"
."\u1EDF" "\u01A1\u0309"
."\u1EE0" "\u01A0\u0303"
."\u1EE1" "\u01A1\u0303"
."\u1EE2" "\u01A0\u0323"
."\u1EE3" "\u01A1\u0323"
# Cyrillic composite characters
."\u0498" "\u0417\u0327"
."\u0499" "\u0437\u0327"
."\u04AA" "\u0421\u0327"
."\u04AB" "\u0441\u0327"
# Spacing modifers
."\u02CB" "\uE09D\u0300"
."\u02CA" "\uE09D\u0301"
."\u02C6" "\uE09D\u0302"
."\u02DC" "\uE09D\u0303"
."\u00AF" "\uE09D\u0304"
."\u02C9" "\uE09D\u0304"
."\u02D8" "\uE09D\u0306"
."\u02D9" "\uE09D\u0307"
."\u00A8" "\uE09D\u0308"
."\u02DA" "\uE09D\u030A"
."\u02C7" "\uE09D\u030C"
."\u00B8" "\uE09D\u0327"
."\u02CD" "\uE09D\u0331"
."\u02CE" "\uE09D\u0316"
."\u02CF" "\uE09D\u0317"
."\u02D2" "\uE09D\u0339"
."\u02D3" "\uE09D\u031C"
."\u02D4" "\uE09D\u031D"
."\u02D5" "\uE09D\u031E"
."\u02D6" "\uE09D\u031F"
."\u02D7" "\uE09D\u0320"
."\u02DB" "\uE09D\u0328"
."\u02DD" "\uE09D\u030B"
."\u02DF" "\uE09D\u033D"
."\u02EC" "\uE09D\u032C"
."\u02ED" "\uE09D\u033F"
."\u02F3" "\uE09D\u0325"
."\u02F7" "\uE09D\u0330"
."\u1FED" "\uE09D\u0308\u0300"
."\u1FEE" "\uE09D\u0308\u0301"
."\u1FEF" "\uE09D\u0300"
."\u1FFD" "\uE09D\u0301"
."\u1FFE" "\uE09D\u0314"
."\u1FBD" "\uE09D\u0313"
."\u1FBE" "\uE09D\u0345"
."\u1FBF" "\uE09D\u0313"
."\u1FC0" "\uE09D\u0342"
."\u1FC1" "\uE09D\u0308\u0342"
."\u0384" "\uE09D\u0301"
."\u0385" "\uE09D\u0308\u0301"
."\u037A" "\uE09D\u0345"
# Suppress incorrect slashed arrows... so far
."\u219A" ""
."\u219B" ""
."\u21AE" ""