Skip to content

Commit 4b7c71a

Browse files
committed
font builder: rewrite to promises, moved to internal method
1 parent 56f4901 commit 4b7c71a

File tree

8 files changed

+231
-351
lines changed

8 files changed

+231
-351
lines changed

Diff for: server/fontello/font/_lib/config.js renamed to internal/fontello/font_build/_lib/config.js

+20-25
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,25 @@
5151
// font:
5252
// meta:
5353
//
54-
55-
5654
'use strict';
5755

5856

59-
var _ = require('lodash');
60-
var svgpath = require('svgpath');
57+
const _ = require('lodash');
58+
const svgpath = require('svgpath');
59+
const fontConfigs = require('../../../../lib/embedded_fonts/server_config');
6160

6261

63-
var fontConfigs = require('../../../../lib/embedded_fonts/server_config');
64-
6562
function collectGlyphsInfo(clientConfig) {
66-
var result = [];
67-
var scale = clientConfig.units_per_em / 1000;
63+
let result = [];
64+
let scale = clientConfig.units_per_em / 1000;
6865

69-
_.forEach(clientConfig.glyphs, function (glyph) {
70-
var sp;
66+
_.forEach(clientConfig.glyphs, glyph => {
67+
let sp;
7168

7269
if (glyph.src === 'custom_icons') {
7370

7471
// for custom glyphs use only selected ones
75-
if (!glyph.selected) { return; }
72+
if (!glyph.selected) return;
7673

7774
sp = svgpath(glyph.svg.path)
7875
.scale(scale, -scale)
@@ -93,8 +90,9 @@ function collectGlyphsInfo(clientConfig) {
9390

9491
// For exmbedded fonts take pregenerated info
9592

96-
var glyphEmbedded = fontConfigs.uids[glyph.uid];
97-
if (!glyphEmbedded) { return; }
93+
let glyphEmbedded = fontConfigs.uids[glyph.uid];
94+
95+
if (!glyphEmbedded) return;
9896

9997
sp = svgpath(glyphEmbedded.svg.d)
10098
.scale(scale, -scale)
@@ -115,32 +113,31 @@ function collectGlyphsInfo(clientConfig) {
115113
});
116114

117115
// Sort result by original codes.
118-
result.sort(function (a, b) { return a.code - b.code; });
116+
result.sort((a, b) => a.code - b.code);
119117

120118
return result;
121119
}
122120

123121
// collect fonts metadata required to build license info
124122

125123
function collectFontsInfo(glyphs) {
126-
var result = [];
124+
let result = [];
127125

128-
_(glyphs).map('src').uniq().forEach(function (fontname) {
129-
var font = fontConfigs.fonts[fontname];
130-
var meta = fontConfigs.metas[fontname];
126+
_(glyphs).map('src').uniq().forEach(fontname => {
127+
let font = fontConfigs.fonts[fontname];
128+
let meta = fontConfigs.metas[fontname];
131129

132130
if (font && meta) {
133131
result.push({ font, meta });
134132
}
135-
136133
});
134+
137135
return result;
138136
}
139137

140138

141139
module.exports = function fontConfig(clientConfig) {
142-
143-
var fontname, glyphsInfo, fontsInfo;
140+
let fontname, glyphsInfo, fontsInfo;
144141

145142
//
146143
// Patch broken data to fix original config
@@ -172,11 +169,9 @@ module.exports = function fontConfig(clientConfig) {
172169
glyphsInfo = collectGlyphsInfo(clientConfig);
173170
fontsInfo = collectFontsInfo(glyphsInfo);
174171

175-
if (_.isEmpty(glyphsInfo)) {
176-
return null;
177-
}
172+
if (_.isEmpty(glyphsInfo)) return null;
178173

179-
var defaultCopyright = 'Copyright (C) ' + new Date().getFullYear() + ' by original authors @ fontello.com';
174+
let defaultCopyright = 'Copyright (C) ' + new Date().getFullYear() + ' by original authors @ fontello.com';
180175

181176
return {
182177
font: {

0 commit comments

Comments
 (0)