Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit b2feae8

Browse files
committed
Fixes #51
1 parent 2e42058 commit b2feae8

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

src/glyphhanger-script.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
return;
3636
}
3737
}
38-
3938
if( opts.onlyVisible && !(node.offsetWidth || node.offsetHeight || node.getClientRects().length) ) {
4039
return;
4140
}
@@ -132,17 +131,19 @@
132131
}
133132

134133
if( node.parentNode ) {
135-
var textTransform = this.win.getComputedStyle( node.parentNode ).getPropertyValue( "text-transform" );
136-
// console.log( "textTransform:", textTransform );
137-
switch (textTransform) {
138-
case "uppercase":
139-
return value.toUpperCase();
140-
case "lowercase":
141-
return value.toLowerCase();
142-
case "capitalize":
143-
// workaround language specific rules with text-transform
144-
// "ß".toUpperCase() => "SS" in german, for example
145-
return value.toUpperCase() + value.toLowerCase();
134+
var style = this.win.getComputedStyle( node.parentNode );
135+
var textTransform = style.getPropertyValue( "text-transform" );
136+
// More information on small-caps at issue #51
137+
var fontVariant = style.getPropertyValue( "font-variant" );
138+
139+
if( fontVariant === "small-caps" || textTransform === "capitalize" ) {
140+
// workaround language specific rules with text-transform
141+
// "ß".toUpperCase() => "SS" in german, for example
142+
return value.toUpperCase() + value.toLowerCase();
143+
} else if( textTransform === "uppercase" ) {
144+
return value.toUpperCase();
145+
} else if( textTransform === "lowercase" ) {
146+
return value.toLowerCase();
146147
}
147148
}
148149

test/integrationTest.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe( "Integration test", function() {
1414
});
1515
});
1616

17-
it( "should have work with text-transform: uppercase", function( done ) {
17+
it( "should work with text-transform: uppercase", function( done ) {
1818
this.timeout( 10000 );
1919

2020
var gh = new GlyphHanger();
@@ -26,7 +26,7 @@ describe( "Integration test", function() {
2626
});
2727
});
2828

29-
it( "should have work with text-transform: capitalize", function( done ) {
29+
it( "should work with text-transform: capitalize", function( done ) {
3030
this.timeout( 10000 );
3131

3232
var gh = new GlyphHanger();
@@ -38,7 +38,19 @@ describe( "Integration test", function() {
3838
});
3939
});
4040

41-
it( "should have work with onload and DOMContentLoaded content", function( done ) {
41+
it( "should work with font-variant: small-caps", function( done ) {
42+
this.timeout( 10000 );
43+
44+
var gh = new GlyphHanger();
45+
gh.fetchUrls(["test/small-caps.html"]).then(function(result) {
46+
// abc ^d e => abcDe => Dabcde
47+
assert.equal( gh.getUniversalSet().toString(), "Dabcde" );
48+
49+
done();
50+
});
51+
});
52+
53+
it( "should work with onload and DOMContentLoaded content", function( done ) {
4254
this.timeout( 10000 );
4355

4456
var gh = new GlyphHanger();

test/small-caps.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title></title>
7+
</head>
8+
<body>
9+
abc
10+
<span style="font-variant: small-caps;">d</span>
11+
<span style="font-feature-settings: 'smcp' on">e</span>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)