Skip to content

Commit ab0121d

Browse files
authored
Merge pull request #16 from openlayers/primary-font
Use style and weight from primary font
2 parents 81eaf9c + 0ef5432 commit ab0121d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ module.exports = function(fonts, size, lineHeight) {
4545
var maybeWeight = parts[parts.length - 1].toLowerCase();
4646
if (maybeWeight == 'normal' || maybeWeight == 'italic' || maybeWeight == 'oblique') {
4747
style = haveStyle ? style : maybeWeight;
48+
haveStyle = true;
4849
parts.pop();
4950
maybeWeight = parts[parts.length - 1].toLowerCase();
5051
} else if (italicRE.test(maybeWeight)) {
5152
maybeWeight = maybeWeight.replace(italicRE, '');
5253
style = haveStyle ? style : parts[parts.length - 1].replace(maybeWeight, '');
54+
haveStyle = true;
5355
}
5456
for (var w in fontWeights) {
5557
var previousPart = parts.length > 1 ? parts[parts.length - 2].toLowerCase() : '';
@@ -64,6 +66,7 @@ module.exports = function(fonts, size, lineHeight) {
6466
}
6567
if (!haveWeight && typeof maybeWeight == 'number') {
6668
weight = maybeWeight;
69+
haveWeight = true;
6770
}
6871
var fontFamily = parts.join(sp)
6972
.replace('Klokantech Noto Sans', 'Noto Sans');

test/index.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe('mapbox-to-css-font', function() {
1717
should(parseFont('monospace', 16, 3.5)).eql('normal 400 16px/3.5 monospace');
1818
should(parseFont('monospace', 16, '3em')).eql('normal 400 16px/3em monospace');
1919
});
20+
21+
it('use style and weight from primary font', function() {
22+
should(parseFont(['monospace medium Italic', 'sans-serif Normal'], 16)).eql('italic 500 16px monospace,sans-serif');
23+
});
2024
});
2125

2226
});

0 commit comments

Comments
 (0)