Skip to content

Commit ece07fd

Browse files
committed
added space glyph
1 parent 7a8e101 commit ece07fd

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

dist/font.json

+1-1
Large diffs are not rendered by default.

gulpfile.js

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ gulp.task('build', ['copy'], function() {
2323
.pipe(gulp.dest('dist/'));
2424
});
2525

26+
gulp.task('build:free', ['copy'], function() {
27+
return gulp.src('src/**/*.coffee')
28+
.pipe($.coffee({bare: true}).on('error', $.util.log))
29+
.pipe(operation())
30+
.pipe($.concat('font_free.json'))
31+
.pipe(jsufon(true))
32+
.pipe(gulp.dest('dist/'));
33+
});
34+
2635
gulp.task('copy', ['clean-dist'], function() {
2736
return gulp.src('src/**/*.js')
2837
.pipe(gulp.dest('dist'));

jsufonify.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,23 @@ function addComponents( glyph ) {
2727
});
2828
}
2929

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+
3045
// plugin level function (dealing with files)
31-
function jsufonify(/*prefixText*/) {
46+
function jsufonify(/*prefixText*/free) {
3247

3348
// creating a stream through which each file will pass
3449
var stream = through.obj(function(file, enc, cb) {
@@ -41,8 +56,33 @@ function jsufonify(/*prefixText*/) {
4156

4257
var charMap = {};
4358

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+
4480
// WIP: convert ptf object to jsufon
4581
_.forEach(font.glyphs, function( glyph, name ) {
82+
if (glyph === undefined) {
83+
delete font.glyphs[name];
84+
return;
85+
}
4686
glyph.name = name;
4787

4888
if ( glyph.name.length === 1 ) {
@@ -129,6 +169,7 @@ function jsufonify(/*prefixText*/) {
129169
var glyph = _.clone(base, true);
130170

131171
glyph.name = _glyph.name;
172+
glyph.base = base.name;
132173
glyph.unicode = _glyph.unicode;
133174
glyph.tags = _glyph.tags;
134175
glyph.glyphName = _glyph.glyphName;
@@ -141,6 +182,14 @@ function jsufonify(/*prefixText*/) {
141182
font.glyphs[_glyph.name] = glyph;
142183
});
143184

185+
_.forEach(font.glyphs, function(glyph) {
186+
if(glyph.base === undefined) {
187+
return;
188+
}
189+
190+
linkToRelatedGlyphs(glyph, font.glyphs);
191+
})
192+
144193
file.contents = new Buffer( JSON.stringify( sandbox.exports ) );
145194

146195
this.push(file);
@@ -154,3 +203,4 @@ function jsufonify(/*prefixText*/) {
154203

155204
// exporting the plugin main function
156205
module.exports = jsufonify;
206+

src/glyphs/punctuation/space.coffee

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
exports.glyphs['space'] =
2+
unicode: ' '
3+
glyphName: 'space'
4+
characterName: 'SPACE'
5+
ot:
6+
advanceWidth: 200 + 50 * width
7+
transforms: Array(
8+
['skewX', slant + 'deg']
9+
)
10+
tags: [
11+
'all',
12+
'latin',
13+
'punctuation'
14+
]
15+
parameters:
16+
spacingLeft: 50 * spacing + 0
17+
spacingRight: 50 * spacing + 0
18+
contours:
19+
0:
20+
skeleton: false
21+
closed: false
22+
nodes:
23+
0:
24+
x: 0
25+
y: 0

0 commit comments

Comments
 (0)