Skip to content

Commit

Permalink
Merge pull request #17 from l1nknyto/master
Browse files Browse the repository at this point in the history
Passing font width map in settings
  • Loading branch information
adambisek authored Jul 13, 2019
2 parents 8bf5e90 + ed2c671 commit 0e4caf9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const getWidth = (string, settings) => {
const font = sett.font.toLowerCase();
const size = sett.size;
const variant = 0 + (sett.bold ? 1 : 0) + (sett.italic ? 2 : 0);
const available = Object.keys(widthsMap);
const map = sett.map || widthsMap;
const available = Object.keys(map);
if (available.indexOf(font) === -1) {
throw new Error(`This font is not supported. Supported fonts are: ${available.join(', ')}`);
}
Expand All @@ -18,7 +19,7 @@ const getWidth = (string, settings) => {
return true;
}
// use width of 'x' as fallback for unregistered char
const widths = widthsMap[font][char] || widthsMap[font].x;
const widths = map[font][char] || map[font].x;
const width = widths[variant];
totalWidth += width;
return true;
Expand Down

0 comments on commit 0e4caf9

Please sign in to comment.