Skip to content

Commit 82b9181

Browse files
committed
do not include font styling options in svg when set to normal
1 parent f4d4f4c commit 82b9181

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/snapshot/tosvg.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ module.exports = function toSVG(gd, format, scale) {
104104
if(ff && ff.indexOf('"') !== -1) {
105105
txt.style('font-family', ff.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
106106
}
107+
108+
// Drop normal font-weight, font-style and font-variant to reduce the size
109+
var fw = this.style.fontWeight;
110+
if(fw && fw === 'normal') {
111+
txt.style('font-weight', undefined);
112+
}
113+
var fs = this.style.fontStyle;
114+
if(fs && fs === 'normal') {
115+
txt.style('font-style', undefined);
116+
}
117+
var fv = this.style.fontVariant;
118+
if(fv && fv === 'normal') {
119+
txt.style('font-variant', undefined);
120+
}
107121
});
108122

109123
svg.selectAll('.gradient_filled,.pattern_filled').each(function() {

test/jasmine/tests/toimage_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe('Plotly.toImage', function() {
179179
.then(function() { return Plotly.toImage(gd, {format: 'svg', imageDataOnly: true}); })
180180
.then(function(d) {
181181
expect(d.indexOf('data:image/')).toBe(-1);
182-
expect(d.length).toBeWithin(35149, 1e3, 'svg image length');
182+
expect(d.length).toBeWithin(32062, 1e3, 'svg image length');
183183
})
184184
.then(function() { return Plotly.toImage(gd, {format: 'webp', imageDataOnly: true}); })
185185
.then(function(d) {

0 commit comments

Comments
 (0)