@@ -27,8 +27,23 @@ function addComponents( glyph ) {
27
27
} ) ;
28
28
}
29
29
30
+ function linkToRelatedGlyphs ( glyph , glyphsByName ) {
31
+ var base = glyphsByName [ glyph . base ] ;
32
+
33
+ base . relatedGlyphs = base . relatedGlyphs || [ ] ;
34
+ glyph . relatedGlyphs = glyph . relatedGlyphs || [ ] ;
35
+
36
+ base . relatedGlyphs . forEach ( function ( name ) {
37
+ glyphsByName [ name ] . relatedGlyphs = glyphsByName [ name ] . relatedGlyphs || [ ] ;
38
+ glyphsByName [ name ] . relatedGlyphs . push ( glyph . name ) ;
39
+ } ) ;
40
+ glyph . relatedGlyphs = glyph . relatedGlyphs . concat ( base . name , base . relatedGlyphs ) ;
41
+
42
+ base . relatedGlyphs . push ( glyph . name ) ;
43
+ }
44
+
30
45
// plugin level function (dealing with files)
31
- function jsufonify ( /*prefixText*/ ) {
46
+ function jsufonify ( /*prefixText*/ free ) {
32
47
33
48
// creating a stream through which each file will pass
34
49
var stream = through . obj ( function ( file , enc , cb ) {
@@ -41,8 +56,33 @@ function jsufonify(/*prefixText*/) {
41
56
42
57
var charMap = { } ;
43
58
59
+ if ( free ) {
60
+ font . glyphs = _ . mapValues ( font . glyphs , ( glyph ) => {
61
+ if ( glyph . unicode === undefined ) {
62
+ return glyph ;
63
+ }
64
+ else {
65
+ if ( typeof glyph . unicode === 'number' ) {
66
+ return ( glyph . unicode >= 65 && glyph . unicode <= 90 ) ||
67
+ ( glyph . unicode >= 87 && glyph . unicode <= 122 ) ? glyph : undefined ;
68
+ }
69
+ else {
70
+ return ( glyph . unicode . charCodeAt ( 0 ) >= 65 && glyph . unicode . charCodeAt ( 0 ) <= 90 ) ||
71
+ ( glyph . unicode . charCodeAt ( 0 ) >= 87 && glyph . unicode . charCodeAt ( 0 ) <= 122 ) ? glyph : undefined ;
72
+ }
73
+ }
74
+ return glyph . unicode === undefined ||
75
+ ( glyph . unicode . charCodeAt ( 0 ) >= 65 && glyph . unicode . charCodeAt ( 0 ) <= 90 ) ||
76
+ ( glyph . unicode . charCodeAt ( 0 ) >= 87 && glyph . unicode . charCodeAt ( 0 ) <= 122 ) ? glyph : undefined ;
77
+ } ) ;
78
+ }
79
+
44
80
// WIP: convert ptf object to jsufon
45
81
_ . forEach ( font . glyphs , function ( glyph , name ) {
82
+ if ( glyph === undefined ) {
83
+ delete font . glyphs [ name ] ;
84
+ return ;
85
+ }
46
86
glyph . name = name ;
47
87
48
88
if ( glyph . name . length === 1 ) {
@@ -129,6 +169,7 @@ function jsufonify(/*prefixText*/) {
129
169
var glyph = _ . clone ( base , true ) ;
130
170
131
171
glyph . name = _glyph . name ;
172
+ glyph . base = base . name ;
132
173
glyph . unicode = _glyph . unicode ;
133
174
glyph . tags = _glyph . tags ;
134
175
glyph . glyphName = _glyph . glyphName ;
@@ -141,6 +182,14 @@ function jsufonify(/*prefixText*/) {
141
182
font . glyphs [ _glyph . name ] = glyph ;
142
183
} ) ;
143
184
185
+ _ . forEach ( font . glyphs , function ( glyph ) {
186
+ if ( glyph . base === undefined ) {
187
+ return ;
188
+ }
189
+
190
+ linkToRelatedGlyphs ( glyph , font . glyphs ) ;
191
+ } )
192
+
144
193
file . contents = new Buffer ( JSON . stringify ( sandbox . exports ) ) ;
145
194
146
195
this . push ( file ) ;
@@ -154,3 +203,4 @@ function jsufonify(/*prefixText*/) {
154
203
155
204
// exporting the plugin main function
156
205
module . exports = jsufonify ;
206
+
0 commit comments