diff --git a/webodf/lib/odf/OdfUtils.js b/webodf/lib/odf/OdfUtils.js index 4f6cfd02..9e2da4ae 100644 --- a/webodf/lib/odf/OdfUtils.js +++ b/webodf/lib/odf/OdfUtils.js @@ -356,7 +356,7 @@ odf.OdfUtils = function OdfUtils() { * @param {!string} positiveLength * @return {?{value:!number,unit:!string}} */ - function parseFontSize(positiveLength) { + function parseLength(positiveLength) { var re = /-?([0-9]*[1-9][0-9]*(\.[0-9]*)?|0+\.[0-9]*[1-9][0-9]*|\.[0-9]*[1-9][0-9]*)((cm)|(mm)|(in)|(pt)|(pc)|(px)|(%))/, m = re.exec(positiveLength); if (!m) { @@ -364,5 +364,5 @@ odf.OdfUtils = function OdfUtils() { } return {value: parseFloat(m[1]), unit: m[3]}; } - this.parseFontSize = parseFontSize; + this.parseLength = parseLength; }; diff --git a/webodf/lib/odf/Style2CSS.js b/webodf/lib/odf/Style2CSS.js index a84fa628..7020db80 100644 --- a/webodf/lib/odf/Style2CSS.js +++ b/webodf/lib/odf/Style2CSS.js @@ -438,7 +438,7 @@ odf.Style2CSS = function Style2CSS() { function getFontSize(styleNode) { var props = getDirectChild(/**@type{Element}*/(styleNode), stylens, 'text-properties'); if (props) { - return utils.parseFontSize(props.getAttributeNS(fons, 'font-size')); + return utils.parseLength(props.getAttributeNS(fons, 'font-size')); } return null; } @@ -539,7 +539,7 @@ odf.Style2CSS = function Style2CSS() { * @return {!string} */ function getParagraphProperties(props) { - var rule = '', imageProps, url, element, value; + var rule = '', imageProps, url, element, lineHeight; rule += applySimpleMapping(props, paragraphPropertySimpleMapping); imageProps = props.getElementsByTagNameNS(stylens, 'background-image'); if (imageProps.length > 0) { @@ -552,12 +552,13 @@ odf.Style2CSS = function Style2CSS() { } } - value = props.getAttributeNS(fons, 'line-height'); - if (value && value !== 'normal') { - if (value.indexOf('%') === -1) { - rule += 'line-height: ' + value + ';'; + lineHeight = props.getAttributeNS(fons, 'line-height'); + if (lineHeight && lineHeight !== 'normal') { + lineHeight = utils.parseLength(lineHeight); + if (lineHeight.unit !== '%') { + rule += 'line-height: ' + lineHeight.value + ';'; } else { - rule += 'line-height: ' + parseFloat(value) / 100 + ';'; + rule += 'line-height: ' + lineHeight.value / 100 + ';'; } }