From 481138a73d99d7a3c43ae9718d5b84e72a1e2655 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 22 Mar 2016 15:24:58 +0000 Subject: [PATCH] Remove SVGO compression, now done upstream in Mathoid Change-Id: I961eb82722ae161bdf7a3ea945c299244ce321fb Depends-On: I86c1a14ad81d2d252ac73da973274f88153d993c --- modules/ve-math/tools/makeSvgsAndCss.js | 57 +++++++++++-------------- modules/ve-math/tools/package.json | 5 +-- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/modules/ve-math/tools/makeSvgsAndCss.js b/modules/ve-math/tools/makeSvgsAndCss.js index b920ad6..fdaee6e 100755 --- a/modules/ve-math/tools/makeSvgsAndCss.js +++ b/modules/ve-math/tools/makeSvgsAndCss.js @@ -16,12 +16,6 @@ fs = require( 'fs' ), http = require( 'http' ), querystring = require( 'querystring' ), - SVGO = require( 'svgo' ), - svgo = new SVGO( { - plugins: [ - { convertTransform: false } - ] - } ), mathoidMaxConnections = 20, // 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 @@ -74,7 +68,8 @@ } ); res.on( 'end', function () { - var className = texToClass( symbol.tex ), + var cssRule, buttonHeight, height, verticalAlign, heightDifference, offset, + className = texToClass( symbol.tex ), data = JSON.parse( body ), svg = data.svg; @@ -84,34 +79,30 @@ return; } - svgo.optimize( svg, function ( result ) { - var cssRule, buttonHeight, height, verticalAlign, heightDifference, offset; + cssRule = cssPrefix + className + ' {\n' + + '\tbackground-image: url(data:image/svg+xml,' + encodeURIComponentForCSS( svg ) + ');\n'; - cssRule = cssPrefix + className + ' {\n' + - '\tbackground-image: url(data:image/svg+xml,' + encodeURIComponentForCSS( result.data ) + ');\n'; + if ( symbol.alignBaseline ) { + // 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 ) { - // 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; - - cssRule += '\tbackground-position: 50% ' + offset + '%;\n' + - '}'; - cssRules.push( cssRule ); - console.log( symbol.tex + ' -> ' + className ); - } else { - cssRule += '}'; - cssRules.push( cssRule ); - console.log( symbol.tex + ' -> ' + className ); - } - } ); + 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(); } ); diff --git a/modules/ve-math/tools/package.json b/modules/ve-math/tools/package.json index d2032f9..70d37b7 100644 --- a/modules/ve-math/tools/package.json +++ b/modules/ve-math/tools/package.json @@ -1,6 +1,3 @@ { - "name": "math-icons-generator", - "dependencies": { - "svgo": "^0.6.0" - } + "name": "math-icons-generator" }