diff --git a/CMakeLists.txt b/CMakeLists.txt index f87f24b8..f42ad7f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -293,13 +293,13 @@ set(TYPEDLIBJSFILES lib/odf/ObjectNameGenerator.js lib/odf/TextStyleApplicator.js lib/odf/Formatting.js + lib/gui/StyleHelper.js ) # This list is generated automatically, do not edit this list by hand. set(UNTYPEDLIBJSFILES # These files depend only on files that are 100% typed. lib/core/RawDeflate.js lib/gui/SelectionMover.js - lib/gui/StyleHelper.js lib/odf/OdfCanvas.js lib/ops/Member.js lib/ops/StepsTranslator.js diff --git a/webodf/lib/gui/StyleHelper.js b/webodf/lib/gui/StyleHelper.js index 3fa002d4..061447b0 100644 --- a/webodf/lib/gui/StyleHelper.js +++ b/webodf/lib/gui/StyleHelper.js @@ -106,14 +106,13 @@ gui.StyleHelper = function StyleHelper(formatting) { /** * Returns true if all the node within given range have the same value for * the property; otherwise false. - * @param {!Array.} appliedStyles - * @param {!string} propertyName - * @param {!string} propertyValue - * @return {!boolean} + * @param {!Array.>>} appliedStyles + * @param {string} propertyName + * @param {string} propertyValue + * @return {boolean} */ function hasTextPropertyValue(appliedStyles, propertyName, propertyValue) { - var hasOtherValue = true, - properties, i; + var hasOtherValue = true, properties, i; for (i = 0; i < appliedStyles.length; i += 1) { properties = appliedStyles[i]['style:text-properties']; @@ -170,10 +169,11 @@ gui.StyleHelper = function StyleHelper(formatting) { * @return {!boolean} */ function hasParagraphPropertyValue(range, propertyName, propertyValues) { - var nodes = odfUtils.getParagraphElements(range), + var paragraphStyleName, paragraphStyleElement, paragraphStyleAttributes, + properties, + nodes = odfUtils.getParagraphElements(range), isStyleChecked = {}, - isDefaultParagraphStyleChecked = false, - paragraphStyleName, paragraphStyleElement, paragraphStyleAttributes, properties; + isDefaultParagraphStyleChecked = false; function pickDefaultParagraphStyleElement() { isDefaultParagraphStyleChecked = true; @@ -188,14 +188,14 @@ gui.StyleHelper = function StyleHelper(formatting) { paragraphStyleName = nodes[0].getAttributeNS(textns, 'style-name'); if (paragraphStyleName) { if (!isStyleChecked[paragraphStyleName]) { - paragraphStyleElement = formatting.getStyleElement(paragraphStyleName, 'paragraph') ; + paragraphStyleElement = formatting.getStyleElement(paragraphStyleName, 'paragraph'); isStyleChecked[paragraphStyleName] = true; // in no such style node exists, fallback to default style if (!paragraphStyleElement && !isDefaultParagraphStyleChecked) { pickDefaultParagraphStyleElement(); } } - } else if(!isDefaultParagraphStyleChecked) { + } else if (!isDefaultParagraphStyleChecked) { pickDefaultParagraphStyleElement(); } else { paragraphStyleElement = undefined; @@ -206,7 +206,7 @@ gui.StyleHelper = function StyleHelper(formatting) { if (paragraphStyleElement === null) { paragraphStyleAttributes = formatting.getSystemDefaultStyleAttributes('paragraph'); } else { - paragraphStyleAttributes = formatting.getInheritedStyleAttributes(/**@type {!Element}*/(paragraphStyleElement), true); + paragraphStyleAttributes = formatting.getInheritedStyleAttributes(/**@type{!Element}*/(paragraphStyleElement), true); } properties = paragraphStyleAttributes['style:paragraph-properties']; if (properties && propertyValues.indexOf(properties[propertyName]) === -1) { @@ -224,7 +224,7 @@ gui.StyleHelper = function StyleHelper(formatting) { * @param {!Range} range * @return {!boolean} */ - this.isAlignedLeft = function(range) { + this.isAlignedLeft = function (range) { return hasParagraphPropertyValue(range, 'fo:text-align', ['left', 'start']); }; @@ -233,7 +233,7 @@ gui.StyleHelper = function StyleHelper(formatting) { * @param {!Range} range * @return {!boolean} */ - this.isAlignedCenter = function(range) { + this.isAlignedCenter = function (range) { return hasParagraphPropertyValue(range, 'fo:text-align', ['center']); }; @@ -242,7 +242,7 @@ gui.StyleHelper = function StyleHelper(formatting) { * @param {!Range} range * @return {!boolean} */ - this.isAlignedRight = function(range) { + this.isAlignedRight = function (range) { return hasParagraphPropertyValue(range, 'fo:text-align', ['right', 'end']); }; @@ -251,7 +251,7 @@ gui.StyleHelper = function StyleHelper(formatting) { * @param {!Range} range * @return {!boolean} */ - this.isAlignedJustified = function(range) { + this.isAlignedJustified = function (range) { return hasParagraphPropertyValue(range, 'fo:text-align', ['justify']); }; }; diff --git a/webodf/lib/odf/Formatting.js b/webodf/lib/odf/Formatting.js index 478b7a7f..a27d60dc 100644 --- a/webodf/lib/odf/Formatting.js +++ b/webodf/lib/odf/Formatting.js @@ -91,8 +91,8 @@ odf.Formatting = function Formatting() { * of a given style family. * Creates a deep copy, so the result can be modified by the callee. * If there are no such attributes, null is returned. - * @param {!string} styleFamily - * @return {?Object} + * @param {string} styleFamily + * @return {!Object.>} */ function getSystemDefaultStyleAttributes(styleFamily) { var result, @@ -103,7 +103,7 @@ odf.Formatting = function Formatting() { // reusing mergeObjects to copy builtInDefaultStyleAttributes into the result result = utils.mergeObjects({}, builtInDefaultStyleAttributes); } else { - result = null; + result = {}; } return result; @@ -314,7 +314,7 @@ odf.Formatting = function Formatting() { * inherited from it's ancestry - up to and including the default style for the family. * @param {!Element} styleNode * @param {!boolean=} includeSystemDefault - * @return {!Object} + * @return {!Object.>} */ function getInheritedStyleAttributes(styleNode, includeSystemDefault) { var styleListElement = odfContainer.rootElement.styles, diff --git a/webodf/tools/updateJS.js b/webodf/tools/updateJS.js index 1a26a28f..30c391b2 100644 --- a/webodf/tools/updateJS.js +++ b/webodf/tools/updateJS.js @@ -308,6 +308,7 @@ function Main() { "gui/Clipboard.js", "gui/EditInfoHandle.js", "gui/KeyboardHandler.js", + "gui/StyleHelper.js", "odf/FontLoader.js", "odf/Formatting.js", "odf/MetadataManager.js",