Remove SVGO compression, now done upstream in Mathoid

Change-Id: I961eb82722ae161bdf7a3ea945c299244ce321fb
Depends-On: I86c1a14ad81d2d252ac73da973274f88153d993c
This commit is contained in:
Ed Sanders 2016-03-22 15:24:58 +00:00
parent 49fc247004
commit 481138a73d
2 changed files with 25 additions and 37 deletions

View File

@ -16,12 +16,6 @@
fs = require( 'fs' ), fs = require( 'fs' ),
http = require( 'http' ), http = require( 'http' ),
querystring = require( 'querystring' ), querystring = require( 'querystring' ),
SVGO = require( 'svgo' ),
svgo = new SVGO( {
plugins: [
{ convertTransform: false }
]
} ),
mathoidMaxConnections = 20, mathoidMaxConnections = 20,
// If symbol.alignBaseline is true, a background-position property will be added to the // If symbol.alignBaseline is true, a background-position property will be added to the
// CSS rule to shift the baseline of the SVG to be a certain proportion of the way up the // CSS rule to shift the baseline of the SVG to be a certain proportion of the way up the
@ -74,7 +68,8 @@
} ); } );
res.on( 'end', function () { res.on( 'end', function () {
var className = texToClass( symbol.tex ), var cssRule, buttonHeight, height, verticalAlign, heightDifference, offset,
className = texToClass( symbol.tex ),
data = JSON.parse( body ), data = JSON.parse( body ),
svg = data.svg; svg = data.svg;
@ -84,34 +79,30 @@
return; return;
} }
svgo.optimize( svg, function ( result ) { cssRule = cssPrefix + className + ' {\n' +
var cssRule, buttonHeight, height, verticalAlign, heightDifference, offset; '\tbackground-image: url(data:image/svg+xml,' + encodeURIComponentForCSS( svg ) + ');\n';
cssRule = cssPrefix + className + ' {\n' + if ( symbol.alignBaseline ) {
'\tbackground-image: url(data:image/svg+xml,' + encodeURIComponentForCSS( result.data ) + ');\n'; // Convert buttonHeight from em to ex, because SVG height is given in ex. (This is an
// approximation, since the em:ex ratio differs from font to font.)
buttonHeight = symbol.largeLayout ? singleButtonHeight * 4 : singleButtonHeight * 1.9931;
// height and verticalAlign rely on the format of the SVG parameters
// HACK: Adjust these by a factor of 0.8 to match VE's default font size of 0.8em
height = parseFloat( data.mathoidStyle.match( /height\:\s*(.*)ex/ )[ 1 ] ) * 0.8;
verticalAlign = -parseFloat( data.mathoidStyle.match( /vertical-align\:\s*(.*)ex/ )[ 1 ] ) * 0.8;
// CSS percentage positioning is based on the difference between the image and container sizes
heightDifference = buttonHeight - height;
offset = 100 * ( verticalAlign - height + ( baseline * buttonHeight ) ) / heightDifference;
if ( symbol.alignBaseline ) { cssRule += '\tbackground-position: 50% ' + offset + '%;\n' +
// Convert buttonHeight from em to ex, because SVG height is given in ex. (This is an '}';
// approximation, since the em:ex ratio differs from font to font.) cssRules.push( cssRule );
buttonHeight = symbol.largeLayout ? singleButtonHeight * 4 : singleButtonHeight * 1.9931; console.log( symbol.tex + ' -> ' + className );
// height and verticalAlign rely on the format of the SVG parameters } else {
// HACK: Adjust these by a factor of 0.8 to match VE's default font size of 0.8em cssRule += '}';
height = parseFloat( data.mathoidStyle.match( /height\:\s*(.*)ex/ )[ 1 ] ) * 0.8; cssRules.push( cssRule );
verticalAlign = -parseFloat( data.mathoidStyle.match( /vertical-align\:\s*(.*)ex/ )[ 1 ] ) * 0.8; console.log( symbol.tex + ' -> ' + className );
// CSS percentage positioning is based on the difference between the image and container sizes }
heightDifference = buttonHeight - height;
offset = 100 * ( verticalAlign - height + ( baseline * buttonHeight ) ) / heightDifference;
cssRule += '\tbackground-position: 50% ' + offset + '%;\n' +
'}';
cssRules.push( cssRule );
console.log( symbol.tex + ' -> ' + className );
} else {
cssRule += '}';
cssRules.push( cssRule );
console.log( symbol.tex + ' -> ' + className );
}
} );
onEnd(); onEnd();
} ); } );

View File

@ -1,6 +1,3 @@
{ {
"name": "math-icons-generator", "name": "math-icons-generator"
"dependencies": {
"svgo": "^0.6.0"
}
} }