From 3c1ce46dacc3a8d52e4e2cac6fb2d76bd0caa7fe Mon Sep 17 00:00:00 2001 From: Aditya Bhatt Date: Mon, 18 Feb 2013 23:53:07 +0530 Subject: [PATCH] Add strikethrough support to the style modifier and restore the button in simpleStyles. Also add special CSS handling for it in Style2CSS --- programs/editor/nls/myResources.js | 1 + programs/editor/widgets/simpleStyles.js | 24 ++++++++++++++++++++++-- webodf/lib/odf/Style2CSS.js | 12 ++++++++++-- webodf/lib/ops/Document.js | 2 ++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/programs/editor/nls/myResources.js b/programs/editor/nls/myResources.js index d47366a7..493db68f 100644 --- a/programs/editor/nls/myResources.js +++ b/programs/editor/nls/myResources.js @@ -70,6 +70,7 @@ define({ bold: "Bold", italic: "Italic", underline: "Underline", + strikethrough: "Strikethrough", font: "Font", family: "Family", size: "Size", diff --git a/programs/editor/widgets/simpleStyles.js b/programs/editor/widgets/simpleStyles.js index a26dd3c5..7ab7dfd3 100644 --- a/programs/editor/widgets/simpleStyles.js +++ b/programs/editor/widgets/simpleStyles.js @@ -99,9 +99,27 @@ define("webodf/editor/widgets/simpleStyles", [], function () { } } }); + strikethroughButton = new ToggleButton({ + label: document.translator('strikethrough'), + showLabel: false, + checked: false, + iconClass: "dijitEditorIcon dijitEditorIconStrikethrough", + onChange: function (checked) { + var currentStyleName = editorSession.getCurrentParagraphStyle(); + if (checked) { + editorSession.updateParagraphStyle(currentStyleName, { + textProperties: { strikethrough: 'solid' } + }); + } else { + editorSession.updateParagraphStyle(currentStyleName, { + textProperties: { strikethrough: 'none' } + }); + } + } + }); editorSession.subscribe('paragraphChanged', function (info) { - var currentStyleName, fontWeight, fontStyle, underline, textProperties; + var currentStyleName, fontWeight, fontStyle, underline, strikethrough, textProperties; if (info.type === 'style') { currentStyleName = editorSession.getCurrentParagraphStyle(); textProperties = editorSession.getParagraphStyleAttributes(currentStyleName)['style:text-properties']; @@ -109,14 +127,16 @@ define("webodf/editor/widgets/simpleStyles", [], function () { fontWeight = textProperties['fo:font-weight']; fontStyle = textProperties['fo:font-style']; underline = textProperties['style:text-underline-style']; + strikethrough = textProperties['style:text-line-through-style']; boldButton.set('checked', fontWeight === 'bold' ? true : false); italicButton.set('checked', fontStyle === 'italic' ? true : false); underlineButton.set('checked', underline === 'solid' ? true : false); + strikethroughButton.set('checked', strikethrough === 'solid' ? true : false); } }); - widget.children = [boldButton, italicButton, underlineButton]; + widget.children = [boldButton, italicButton, underlineButton, strikethroughButton]; widget.startup = function () { widget.children.forEach(function (element) { element.startup(); diff --git a/webodf/lib/odf/Style2CSS.js b/webodf/lib/odf/Style2CSS.js index ac2458d8..23941251 100644 --- a/webodf/lib/odf/Style2CSS.js +++ b/webodf/lib/odf/Style2CSS.js @@ -426,12 +426,20 @@ odf.Style2CSS = function Style2CSS() { * @return {!string} */ function getTextProperties(props) { - var rule = '', value; + var rule = '', value, textDecoration = 'text-decoration:'; rule += applySimpleMapping(props, textPropertySimpleMapping); + value = props.getAttributeNS(stylens, 'text-underline-style'); if (value === 'solid') { - rule += 'text-decoration: underline;'; + textDecoration += ' underline'; } + value = props.getAttributeNS(stylens, 'text-line-through-style'); + if (value === 'solid') { + textDecoration += ' line-through'; + } + textDecoration += ';'; + rule += textDecoration; + value = props.getAttributeNS(stylens, 'font-name'); if (value) { value = getFontDeclaration(value); diff --git a/webodf/lib/ops/Document.js b/webodf/lib/ops/Document.js index 5eb44ce6..84bcaeec 100644 --- a/webodf/lib/ops/Document.js +++ b/webodf/lib/ops/Document.js @@ -488,6 +488,8 @@ runtime.log("Setting paragraph style:" + domPosition + " -- " + position + " " + 'fo:font-style', info.textProperties.fontStyle); setRealAttributeNS(textPropertiesNode, stylens, 'style:text-underline-style', info.textProperties.underline); + setRealAttributeNS(textPropertiesNode, stylens, + 'style:text-line-through-style', info.textProperties.strikethrough); } odfCanvas.refreshCSS();