Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Ligature support with based on configuration parameters #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ Default: basename of file

Function that takes path of file and return name of icon.

### ligature

Type: `boolean`
<br>
Default: `false`

Whether ligature function will be used or not.

### ligatureName

Type: `function(string) -> string`
<br>
Default: basename of file

Function that takes name of file and return ligature for that icon.

### startCodepoint

Type: `number`
Expand Down
15 changes: 9 additions & 6 deletions src/generateFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ var generators = {
_.each(options.files, function(file, idx) {
var glyph = fs.createReadStream(file)
var name = options.names[idx]
var unicode = String.fromCharCode(options.codepoints[name])
var ligature = ''
for(var i=0;i<name.length;i++) {
ligature+=String.fromCharCode(name.charCodeAt(i))
}
var unicode;

if (options.ligature) {
unicode = options.ligatureName(name);
} else {
unicode = String.fromCharCode(options.codepoints[name]);
}

glyph.metadata = {
name: name,
unicode: [unicode,ligature]
unicode: [unicode]
}
fontStream.write(glyph)
})
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ var DEFAULT_OPTIONS = {
fontName: 'iconfont',
css: true,
cssTemplate: TEMPLATES.css,
ligature: false,
ligatureName: function (name) {
var ligature = '';
for(var i = 0; i < name.length; i++) {
ligature+=String.fromCharCode(name.charCodeAt(i));
}
return ligature;
},
html: false,
htmlTemplate: TEMPLATES.html,
types: ['eot', 'woff', 'woff2'],
Expand Down