@@ -9,21 +9,12 @@ const {
99 isLongDash,
1010 filterUnicodeRange
1111} = require ( "../common/unicode-kind" ) ;
12- const {
13- sanitizeSymbols,
14- removeUnusedFeatures,
15- toPWID,
16- removeDashCcmp,
17- aliasFeatMap
18- } = require ( "./common" ) ;
12+ const { sanitizeSymbols, removeUnusedFeatures, toPWID, removeDashCcmp } = require ( "./common" ) ;
1913const gc = require ( "../common/gc" ) ;
2014
2115module . exports = async function makeFont ( ctx , config , argv ) {
22- const a = await ctx . run ( introduce , "a" , {
23- from : argv . main ,
24- prefix : "a" ,
25- ignoreHints : true
26- } ) ;
16+ const a = await ctx . run ( introduce , "a" , { from : argv . main , prefix : "a" , ignoreHints : true } ) ;
17+ const b = await ctx . run ( introduce , "b" , { from : argv . lgc , prefix : "b" , ignoreHints : true } ) ;
2718 a . cmap_uvs = null ;
2819 filterUnicodeRange (
2920 a ,
@@ -32,14 +23,21 @@ module.exports = async function makeFont(ctx, config, argv) {
3223 ! isWestern ( c - 0 ) &&
3324 ! isKorean ( c - 0 ) &&
3425 ! isLongDash ( c - 0 , argv . term ) &&
35- ! isWS ( c - 0 , argv . type , argv . term )
26+ ! isWS ( c - 0 )
3627 ) ;
3728
3829 if ( argv . pwid ) {
3930 await ctx . run ( manip . glyph , "a" , toPWID ) ;
4031 }
4132 if ( argv . mono ) {
42- await ctx . run ( manip . glyph , "a" , sanitizeSymbols , argv . type ) ;
33+ await ctx . run ( manip . glyph , "b" , unlinkRefsOfSymbols , argv . term ) ;
34+ transferMonoGeometry ( ctx . items . a , ctx . items . b ) ;
35+ await ctx . run ( manip . glyph , "a" , populatePwidOfMono ) ;
36+ }
37+ if ( ! argv . pwid ) {
38+ await ctx . run ( manip . glyph , "a" , sanitizeSymbols , argv . goth , ! argv . pwid && ! argv . term ) ;
39+ }
40+ if ( argv . mono ) {
4341 removeDashCcmp ( ctx . items . a , argv . mono ) ;
4442 }
4543 removeUnusedFeatures ( ctx . items . a , "AS" , argv . mono ) ;
@@ -49,3 +47,70 @@ module.exports = async function makeFont(ctx, config, argv) {
4947 await ctx . run ( build , "a" , { to : argv . o , optimize : true } ) ;
5048 ctx . remove ( "a" ) ;
5149} ;
50+
51+ // Monospace punctuation transferring
52+ function unlinkRefsOfSymbols ( isTerm ) {
53+ for ( let u = 0x2000 ; u < 0x20a0 ; u ++ ) {
54+ let gn = this . find . gname . unicode ( u ) ;
55+ if ( ! gn ) continue ;
56+ let gnT = gn ;
57+ if ( ! isTerm ) gnT = this . find . gname . subst ( "WWID" , gn ) ;
58+ if ( ! gnT ) continue ;
59+ const g = this . find . glyph ( gn ) ;
60+ const g$ = this . find . glyph$ ( gnT ) ;
61+ HCopy ( g , g$ ) ;
62+ }
63+ }
64+ function transferMonoGeometry ( main , lgc ) {
65+ for ( let u = 0x2000 ; u < 0x20a0 ; u ++ ) {
66+ let gnSrc = main . cmap [ u ] ,
67+ gnDst = lgc . cmap [ u ] ;
68+ if ( gnSrc && gnDst ) {
69+ HCopy ( main . glyf [ gnSrc ] , lgc . glyf [ gnDst ] ) ;
70+ }
71+ }
72+ }
73+ function populatePwidOfMono ( ) {
74+ for ( let u = 0x2000 ; u < 0x20a0 ; u ++ ) {
75+ const gn = this . find . gname . unicode ( u ) ;
76+ if ( ! gn ) continue ;
77+ const gnPwid = this . find . gname . subst ( "pwid" , gn ) ;
78+ if ( ! gnPwid ) continue ;
79+ const g = this . find . glyph ( gnPwid ) ;
80+ const g$ = this . find . glyph$ ( gn ) ;
81+ HCopy ( g , g$ ) ;
82+ }
83+ }
84+
85+ function HCopy ( g , g1 ) {
86+ g . contours = g1 . contours ;
87+ g . references = g1 . references ;
88+ g . advanceWidth = g1 . advanceWidth ;
89+ }
90+
91+ // Feature mapping
92+ function aliasFeatMap ( a , feat , aliases ) {
93+ if ( ! a . GSUB || ! a . GSUB . features || ! a . GSUB . lookups ) return ;
94+ for ( const [ uFrom , uTo ] of aliases ) {
95+ const gidFrom = a . cmap [ uFrom ] ,
96+ gidTo = a . cmap [ uTo ] ;
97+ if ( ! gidFrom || ! gidTo ) continue ;
98+
99+ let affectedLookups = new Set ( ) ;
100+ for ( const fid in a . GSUB . features ) {
101+ if ( fid . slice ( 0 , 4 ) === feat ) {
102+ const feature = a . GSUB . features [ fid ] ;
103+ if ( ! feature ) continue ;
104+ for ( const lid of feature ) affectedLookups . add ( lid ) ;
105+ }
106+ }
107+
108+ for ( const lid of affectedLookups ) {
109+ const lookup = a . GSUB . lookups [ lid ] ;
110+ if ( lookup . type !== "gsub_single" ) continue ;
111+ for ( const subtable of lookup . subtables ) {
112+ subtable [ gidFrom ] = subtable [ gidTo ] ;
113+ }
114+ }
115+ }
116+ }
0 commit comments