old version of files no longer required
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/4b3e346b Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/4b3e346b Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/4b3e346b Branch: refs/heads/develop Commit: 4b3e346b74c3248ba581ad850e5115d0aa127709 Parents: 776010a Author: Justin Mclean <jmcl...@apache.org> Authored: Thu Oct 9 14:04:05 2014 +1100 Committer: Justin Mclean <jmcl...@apache.org> Committed: Thu Oct 9 14:04:05 2014 +1100 ---------------------------------------------------------------------- .../linguistics/spelling/ui/HaloHighlighter.as | 126 ---------- .../spelling/ui/HaloWordProcessor.as | 112 --------- .../linguistics/spelling/ui/IHighlighter.as | 67 ----- .../linguistics/spelling/ui/IWordProcessor.as | 30 --- .../linguistics/spelling/ui/SparkHighlighter.as | 229 ----------------- .../spelling/ui/SparkWordProcessor.as | 133 ---------- .../spelling/ui/SpellingHighlighter.as | 196 --------------- .../linguistics/spelling/ui/TLFHighlighter.as | 252 ------------------- .../linguistics/spelling/ui/TLFWordProcessor.as | 159 ------------ 9 files changed, 1304 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloHighlighter.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloHighlighter.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloHighlighter.as deleted file mode 100644 index 91b0d5f..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloHighlighter.as +++ /dev/null @@ -1,126 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import __AS3__.vec.Vector; - - import com.adobe.linguistics.utils.Token; - - import flash.geom.Point; - import flash.text.TextField; - - import mx.core.IUITextField; - import com.adobe.linguistics.spelling.ui.IHighlighter; - import com.adobe.linguistics.spelling.ui.SpellingHighlighter; - - /** - * <p>This class facilitates drawing of squiggly lines below words for TextField class. TextField class is used to create display objects for text display - * and input for Halo TextArea and TextInput components. HaloHighlighter could therefore be used for drawing squiggly lines in these Halo components.</p> - * - * @playerversion Flash 10 - * @langversion 3.0 - */ - - public class HaloHighlighter implements IHighlighter - { - private var mTextField:TextField; - private var mHighlighter:SpellingHighlighter; - /* - * offset point: - */ - private var _offsetPoint:Point; - - /** - * The constructor for HaloHighlighter. - * @param textField <code>TextField</code> in which to enable highlighting. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function HaloHighlighter( textField:TextField ) - { - if (textField == null ) throw new Error("illegal argument."); - mTextField = textField; - mHighlighter = null; - this._offsetPoint = new Point(0,0); - } - /** - * Draw squiggly lines below a given token. - * @param token <code>Token</code> information of the word to be highlighted. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function drawSquiggleAt(token:Token):void - { - squiggleWord(token); - } - - /** - * Clear all squiggly lines in the TextField. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function clearSquiggles():void - { - if (mHighlighter) { - mTextField.parent.removeChild(mHighlighter); - mHighlighter=null; - } - - } - - /** - * Set offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function set offsetPoint(op:Point):void{ - _offsetPoint = op; - } - - /** - * Get offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function get offsetPoint():Point{ - return _offsetPoint; - } - - - private function squiggleWord(token:Token):void { - - if (!mHighlighter) { - mHighlighter= new SpellingHighlighter( mTextField as IUITextField); - mTextField.parent.addChild(mHighlighter); - } - - mHighlighter.drawSquigglyLine(token.first, token.last); - - - //mTextField.parent.addChild(mHighlighter); - mHighlighter.move(_offsetPoint.x, _offsetPoint.y); - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloWordProcessor.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloWordProcessor.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloWordProcessor.as deleted file mode 100644 index 9c05b3b..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/HaloWordProcessor.as +++ /dev/null @@ -1,112 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.ITokenizer; - import com.adobe.linguistics.utils.TextTokenizer; - import com.adobe.linguistics.utils.Token; - - import flash.text.TextField; - import flash.text.TextFormat; - - import mx.controls.TextArea; - import mx.controls.TextInput; - import com.adobe.linguistics.spelling.ui.IWordProcessor; - - - public class HaloWordProcessor implements IWordProcessor - { - private var mTextField:TextField; - - public function HaloWordProcessor(textField:TextField) - { - if (textField == null ) throw new Error("illegal argument."); - mTextField = textField; - } - - - public function replaceText(token:Token, replacement:String):void { - var startIndex:int = token.first; - var endIndex:int = token.last; - - if ( replacement == null ) return; - - if (mTextField.text.length<endIndex || startIndex<0) { - return; - } - - var _misspellStart:int = startIndex; - var _misspellEnd:int = endIndex; - // Try to preserve the format, this works if the whole misspelled word is the same format - var tf:TextFormat = mTextField.getTextFormat(_misspellStart, _misspellEnd); - mTextField.replaceText(_misspellStart, _misspellEnd, replacement); - mTextField.setTextFormat(tf, _misspellStart, _misspellStart+replacement.length); - - var ta:TextArea = mTextField.parent as TextArea; - var ti:TextInput = mTextField.parent as TextInput; - - if (ta != null) { - ta.selectionBeginIndex = _misspellStart + replacement.length; - ta.selectionEndIndex = _misspellStart + replacement.length; - } - else if (ti != null) { - ti.selectionBeginIndex = _misspellStart + replacement.length; - ti.selectionEndIndex = _misspellStart + replacement.length; - } - else { - // Do nothing if it's not a valid text component - } - } - - - public function getWordAtPoint(x:uint, y:uint, externalTokenizer:ITokenizer=null):Token - { - var _token:Token = tryGetWordAtPoint(x,y, externalTokenizer); - return _token; - } - - private function tryGetWordAtPoint(x:uint, y:uint, externalTokenizer:ITokenizer=null):Token { - // TODO: use a better alternative than _misspellStart, end - var index:uint = mTextField.getCharIndexAtPoint(x + mTextField.scrollH, y); - if (index >= mTextField.text.length) return null; - - var tmpToken:Token = new Token(index,index); - var tokenizer:ITokenizer; - if ( externalTokenizer == null ) { - tokenizer = new TextTokenizer(mTextField.text); - }else { - tokenizer = externalTokenizer; - } - - var result:Token = new Token(0,0); - - var preToken:Token = tokenizer.getPreviousToken(tmpToken); - var nextToken:Token = tokenizer.getNextToken(tmpToken); - if ( preToken.last == nextToken.first ) { - result.first = preToken.first; - result.last = nextToken.last; - return result; - }else { - return null; - } - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IHighlighter.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IHighlighter.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IHighlighter.as deleted file mode 100644 index 3b5a309..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IHighlighter.as +++ /dev/null @@ -1,67 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.Token; - import __AS3__.vec.Vector; - import flash.geom.Point; - - /** - * The <code>IHighlighter</code> Interface. - * This interface defines default methods which will be used for highlighting text in UI components. - * - * @playerversion Flash 10 - * @langversion 3.0 - */ - - public interface IHighlighter - { - /** - * Draw squiggly lines below a given token. - * @param token <code>Token</code> information of the word to be highlighted. - * @playerversion Flash 10 - * @langversion 3.0 - */ - function drawSquiggleAt(token:Token):void; - /** - * Clear all squiggly lines in the UI. - * @playerversion Flash 10 - * @langversion 3.0 - */ - function clearSquiggles():void; - /** - * Set offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - function set offsetPoint(op:Point):void; - /** - * Get offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - function get offsetPoint():Point; - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IWordProcessor.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IWordProcessor.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IWordProcessor.as deleted file mode 100644 index 8196691..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/IWordProcessor.as +++ /dev/null @@ -1,30 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.ITokenizer; - import com.adobe.linguistics.utils.Token; - - public interface IWordProcessor - { - function getWordAtPoint(x:uint, y:uint, externalTokenizer:ITokenizer=null):Token; - function replaceText(token:Token, replacement:String):void; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkHighlighter.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkHighlighter.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkHighlighter.as deleted file mode 100644 index ffe9653..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkHighlighter.as +++ /dev/null @@ -1,229 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.Token; - import com.adobe.linguistics.utils.TextTokenizer; - import flash.geom.Point; - - import flash.display.Shape; - import flash.geom.Rectangle; - import flash.text.engine.TextLine; - - import flashx.textLayout.compose.TextFlowLine; - import flashx.textLayout.edit.SelectionManager; - import flashx.textLayout.elements.TextFlow; - import flashx.textLayout.tlf_internal; - - import spark.components.RichEditableText; - import com.adobe.linguistics.spelling.ui.IHighlighter; - - use namespace tlf_internal; - - /** - * <p>This class facilitates drawing of squiggly lines below words for RichEditableText class. RichEditableText is a low-level UIComponent for displaying, - * scrolling, selecting, and editing richly-formatted text. This class is used in the skins of the Spark versions of TextInput and TextArea. - * SparkHighlighter could therefore be used for drawing squiggly lines in these Spark components.</p> - * - * @playerversion Flash 10 - * @langversion 3.0 - */ - public class SparkHighlighter implements IHighlighter - { - - private var mTextField:RichEditableText; - private var mHighlighter:Shape; - /* - * offset point: - */ - private var _offsetPoint:Point; - - /** - * The constructor for SparkHighlighter. - * @param richEditableText <code>RichEditableText</code> in which to enable highlighting. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function SparkHighlighter( richEditableText:RichEditableText ) - { - if (richEditableText == null ) throw new Error("illegal argument."); - mTextField = richEditableText; - mHighlighter = null; - this._offsetPoint = new Point(0,0); - } - - /** - * Draw squiggly lines below a given token. - * @param token <code>Token</code> information of the word to be highlighted. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function drawSquiggleAt(token:Token):void - { - squiggleWord(token); - } - - /** - * Clear all squiggly lines in the component. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function clearSquiggles():void - { - if (mHighlighter) { - mTextField.removeChild(mHighlighter); - mHighlighter=null; - } - } - - /** - * Set offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function set offsetPoint(op:Point):void{ - _offsetPoint = op; - } - - /** - * Get offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function get offsetPoint():Point{ - return _offsetPoint; - } - - - - // TODO: refactor this code to share with halo components, and support words that cross lines - private function squiggleWord(token:Token):void { - - var ta:RichEditableText = mTextField; - if (!ta) return; - - if (!mHighlighter) { - mHighlighter= new Shape(); - mHighlighter.graphics.clear(); - mTextField.addChild(mHighlighter); - } - - drawSquigglyLineForRange(token.first, token.last); - - // Just adjust the left padding, top padding is not an issue - //var pleft:uint = mTextField.getStyle("paddingLeft"); - //mHighlighter.x += pleft; - } - - // Draw squiggly line - private function drawSquigglyLineForRange(start:Number, end:Number):void - { - // draw squiggly line - var tf:TextFlow = mTextField.textFlow; - var tflFirst:TextFlowLine = tf.flowComposer.findLineAtPosition(start); - var tflLast:TextFlowLine = tf.flowComposer.findLineAtPosition(end); - var tflIndexFirst:int = tf.flowComposer.findLineIndexAtPosition(start); - var tflIndexLast:int = tf.flowComposer.findLineIndexAtPosition(end); - - // Pointer - var tflIndex:int = tflIndexFirst; - var tfl:TextFlowLine = tflFirst; - - if (tflIndexFirst == tflIndexLast) { - // Draw one line - drawSquigglyLineAtIndex(tflIndexFirst, start - tflFirst.absoluteStart, end - tflFirst.absoluteStart); - } else { - // Multiple lines (very long word) - drawSquigglyLineAtIndex(tflIndexFirst, start - tflFirst.absoluteStart); - - tflIndex++; - while (tflIndex != tflIndexLast) { - drawSquigglyLineAtIndex(tflIndex); - tflIndex++; - } - - drawSquigglyLineAtIndex(tflIndexLast, 0, end - tflLast.absoluteStart); - } - } - - // Draw a squiggly line at specific line for specific index range - private function drawSquigglyLineAtIndex(lineIndex:Number, startIndex:Number=0, endIndex:Number=0x7FFFFFFF):void - { - var tf:TextFlow = mTextField.textFlow; - var tfl:TextFlowLine = tf.flowComposer.getLineAt(lineIndex); - var rectLine:Rectangle = tfl.getBounds(); - if (endIndex == 0x7FFFFFFF) { - drawSquigglyLineAtPoint(rectLine.left, rectLine.bottom, rectLine.right - rectLine.left); - } - else { - // Force to have a valid TextLine - var tl:TextLine = tfl.getTextLine(true); - if(tl==null) return; - var atomStartIndex:int= tl.getAtomIndexAtCharIndex(startIndex+ tl.textBlockBeginIndex);//fix for diacritic characters bug#2854971(adding textBlockBeginIndex since getAtomIndexAtCharIndex is relative to beginning of block) - var atomEndIndex:int= tl.getAtomIndexAtCharIndex(endIndex+tl.textBlockBeginIndex);//fix for diacritic characters bug#2854971 - // TODO: atom index and char index is not matching for some chars, use try/catch to avoid crash - try { - var rectFirst:Rectangle = tl.getAtomBounds(atomStartIndex); - var rectLast:Rectangle = tl.getAtomBounds(atomEndIndex); - drawSquigglyLineAtPoint(rectFirst.left + tfl.x, rectLine.bottom, rectLast.right - rectFirst.left); - } catch (err:Error) - { - trace(err); - } - } - - } - // Draw a squiggly from point x,y with given width, the line is drew in mHighlighter - private function drawSquigglyLineAtPoint(x:Number, y:Number, width:Number):void - { - mHighlighter.graphics.lineStyle(1, 0xfa0707, .65); - mHighlighter.graphics.moveTo(x, y); - var upDirection:Boolean = false; - var offset:uint = 0; - var stepLength:uint = 2; - for ( var i:uint = 1; offset <= width; i++) { - offset = offset + stepLength; - if ( upDirection ) - mHighlighter.graphics.lineTo(x+offset,y); - else - mHighlighter.graphics.lineTo(x+offset,y+stepLength); - upDirection = !upDirection; - } - } - - private function getValidFirstWordIndex():int{ - var index:int = SelectionManager.computeSelectionIndex(mTextField.textFlow, mTextField, mTextField, 0 + mTextField.horizontalScrollPosition, 0 + mTextField.verticalScrollPosition); - return index; - - - } - - private function getValidLastWordIndex():int{ - var index:int = SelectionManager.computeSelectionIndex(mTextField.textFlow, mTextField, mTextField, mTextField.width+mTextField.horizontalScrollPosition, mTextField.height+mTextField.verticalScrollPosition); - return index; - - } - - } -} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkWordProcessor.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkWordProcessor.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkWordProcessor.as deleted file mode 100644 index 3ae7a88..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SparkWordProcessor.as +++ /dev/null @@ -1,133 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.ITokenizer; - import com.adobe.linguistics.utils.TextTokenizer; - import com.adobe.linguistics.utils.Token; - - import flashx.textLayout.edit.SelectionManager; - import flashx.textLayout.tlf_internal; - - import spark.components.RichEditableText; - import com.adobe.linguistics.spelling.ui.IWordProcessor; - - use namespace tlf_internal; - - public class SparkWordProcessor implements IWordProcessor - { - private var mTextField:RichEditableText; - - public function SparkWordProcessor(textField:RichEditableText) - { - if (textField == null ) throw new Error("illegal argument."); - mTextField = textField; - } - - - public function replaceText(token:Token, replacement:String):void { - var startIndex:int = token.first; - var endIndex:int = token.last; - - var ta:RichEditableText = mTextField; - var end:int = getValidLastWordIndex(); - - if ( replacement == null ) return; - - if (mTextField.text.length<endIndex || startIndex<0) { - return; - } - - var _misspellStart:int = startIndex; - var _misspellEnd:int = endIndex; - - // Workaround for Spark: changes in inactive components will trigger strange behavior - //var selectedElementRange:ElementRange = ElementRange.createElementRange(ta.textFlow, _misspellStart, _misspellEnd); - //var selectedCharacterFormat:ITextLayoutFormat = ta.textFlow.interactionManager.activePosition == ta.textFlow.interactionManager.anchorPosition ? ta.textFlow.interactionManager.getCommonCharacterFormat() : selectedElementRange.characterFormat; - //var selectedParagraphFormat:ITextLayoutFormat = selectedElementRange.paragraphFormat; - //var selectedContainerFormat:ITextLayoutFormat = selectedElementRange.containerFormat; - - - - //var selectedCharacterFormat:ITextLayoutFormat = ta.textFlow.interactionManager.getCommonCharacterFormat(); - //var selectedContainerFormat:ITextLayoutFormat = ta.textFlow.interactionManager.getCommonContainerFormat(); - //var selectedParagraphFormat:ITextLayoutFormat = ta.textFlow.interactionManager.getCommonParagraphFormat(); - - /*var tem:EditManager = new EditManager(); - ta.textFlow.interactionManager = tem; */ - - - ta.setFocus(); - //ta.text = ta.text.substr(0, _misspellStart) + replacement + ta.text.substr(_misspellEnd); - - //tem.applyFormat(selectedCharacterFormat,selectedParagraphFormat,selectedContainerFormat); - //ta.textFlow.flowComposer.updateAllControllers(); - - ta.textFlow; - //ta.selectRange(_misspellStart + replacement.length, _misspellStart + replacement.length); - ta.selectRange(_misspellStart+1, _misspellEnd); - ta.insertText(replacement); - ta.selectRange(_misspellStart, _misspellStart+1); - ta.insertText(""); - - //ta.textFlow.interactionManager.applyFormat(selectedCharacterFormat,null,null); - - // Workaround for unexpected jump - ta.scrollToRange(end, end); - } - - public function getWordAtPoint(x:uint, y:uint, externalTokenizer:ITokenizer=null):Token - { - // TODO: use a better alternative than _misspellStart, end - var ta:RichEditableText = mTextField; - var index:int = SelectionManager.computeSelectionIndex(ta.textFlow, ta, ta, x, y); - - if (index >= ta.text.length) return null; - - var tmpToken:Token = new Token(index,index); - var tokenizer:ITokenizer; - if ( externalTokenizer == null ) { - tokenizer = new TextTokenizer(mTextField.text); - }else { - tokenizer = externalTokenizer; - } - - var result:Token = new Token(0,0); - var preToken:Token = tokenizer.getPreviousToken(tmpToken); - var nextToken:Token = tokenizer.getNextToken(tmpToken); - if ( preToken.last == nextToken.first ) { - result.first = preToken.first; - result.last = nextToken.last; - return result; - }else { - return null; - } - - } - - // TODO: workaround for unexpected jump when word replaced, to be refactored for code sharing - private function getValidLastWordIndex():int{ - var index:int = SelectionManager.computeSelectionIndex(mTextField.textFlow, mTextField, mTextField, mTextField.width+mTextField.horizontalScrollPosition, mTextField.height+mTextField.verticalScrollPosition); - return index; - } - - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SpellingHighlighter.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SpellingHighlighter.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SpellingHighlighter.as deleted file mode 100644 index 27cd2fb..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/SpellingHighlighter.as +++ /dev/null @@ -1,196 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import flash.display.Shape; - import flash.geom.Point; - import flash.geom.Rectangle; - import flash.text.TextLineMetrics; - - import mx.core.IUITextField; - import mx.flash.UIMovieClip; - - - public class SpellingHighlighter extends UIMovieClip - { - /* - * offset point: - */ - private var _offsetPoint:Point; - - /* - * Target TextField. - */ - private var _textField:IUITextField; - private static var InvalidIndexValue:int = -2; - public function SpellingHighlighter(textField:IUITextField) { - super(); - this._textField = textField; - this._offsetPoint = new Point(0,0); - } - - public function drawSquigglyLine(firstCharIndex:int, lastCharIndex:int ):void { - var validFirstCharIndex:int = getValidFirstCharIndex(firstCharIndex); - var validLastCharIndex:int = getValidLastCharIndex(lastCharIndex); - if ( validFirstCharIndex == InvalidIndexValue || validLastCharIndex == InvalidIndexValue ){ - return; - } - /* draw squiggly line here. */ - if ( validFirstCharIndex <= validLastCharIndex ) { - var firstLine:int = _textField.getLineIndexOfChar(validFirstCharIndex); - var lastLine:int = _textField.getLineIndexOfChar(validLastCharIndex); - //only one line case. - if(lastLine==firstLine) - { - drawSingleSquigglyLine(validFirstCharIndex, validLastCharIndex); - return; - } - //more than one line. - //first line - drawSingleSquigglyLine(validFirstCharIndex, _textField.getLineOffset(firstLine)+_textField.getLineLength(firstLine)-1); - //middle.... - for(var i:int=firstLine+1;i<lastLine;i++) - { - drawSingleSquigglyLine(_textField.getLineOffset(i), _textField.getLineOffset(i)+_textField.getLineLength(i)-1); - } - //last lines. - drawSingleSquigglyLine(_textField.getLineOffset(lastLine), validLastCharIndex); - } - } - - public function drawSingleSquigglyLine(firstCharIndex:int, lastCharIndex:int ):void { - var firstLine:int = _textField.getLineIndexOfChar(firstCharIndex); - var lastLine:int = _textField.getLineIndexOfChar(lastCharIndex); - if ( firstLine != lastLine ) { - return; - }else { - var rect1:Rectangle = _textField.getCharBoundaries(firstCharIndex); - var rect2:Rectangle = _textField.getCharBoundaries(lastCharIndex); - var line:int; - while(rect1==null){ - line=_textField.getLineIndexOfChar(firstCharIndex); - if( (firstCharIndex+1)>(_textField.getLineOffset(line)+_textField.getLineLength(line)-1)||(firstCharIndex+1)>lastCharIndex) return;// go till the last character - firstCharIndex++; - rect1= _textField.getCharBoundaries(firstCharIndex); - } - - while(rect2==null){//this case appears for diacritic characters made using Decomposed chars - line=_textField.getLineIndexOfChar(lastCharIndex); - if( lastCharIndex-1 < (_textField.getLineOffset(line))||firstCharIndex>(lastCharIndex-1) ) return; //go till the first character - lastCharIndex--;// check for the previos character - rect2= _textField.getCharBoundaries(lastCharIndex); - } - - - var x:Number = rect1.x+_offsetPoint.x - _textField.scrollH; - var y:Number = rect1.y + rect1.height + 2; - var width:Number = rect2.x+rect2.width-rect1.x; - - // Avoid drawing outside the textField - if (x<0) - { - if (x+width > 0) { - width += x; - x = 0; - } - else - return; - } - if (x+width > _textField.width) - { - if (x < _textField.width) { - width = textField.width - x; - } - else - return; - } - - // The rectangle that bound the string you want - // actual work here. - var myShape:Shape = new Shape(); - myShape.graphics.clear(); - //myShape.graphics.beginFill(0x0099CC, .35); - myShape.graphics.lineStyle(1, 0xfa0707, .65); - //myShape.graphics.moveTo(0,0); - myShape.graphics.moveTo(x, y); - var upDirection:Boolean = false; - var offset:uint = 0; - var stepLength:uint = 2; - for ( var i:uint = 1; offset <= width; i++) { - offset = offset + stepLength; - if ( upDirection ) - myShape.graphics.lineTo(x+offset,y); - else - myShape.graphics.lineTo(x+offset,y+stepLength); - upDirection = !upDirection; - } - //myShape.graphics.endFill(); - this.addChild(myShape); - } - } - - private function getValidFirstCharIndex(firstCharIndex:int):int{ - if(firstCharIndex<0 || firstCharIndex>_textField.text.length-1) - { - return InvalidIndexValue; - } - var firstLine:Number = _textField.getLineIndexOfChar(firstCharIndex); - - if(firstLine<_textField.scrollV-1) - { - firstLine = _textField.scrollV-1; - return _textField.getLineOffset(firstLine); - } - return firstCharIndex; - } - - private function getValidLastCharIndex(lastCharIndex:int):int{ - if(lastCharIndex<0 || lastCharIndex>_textField.text.length-1) - { - return InvalidIndexValue; - } - var lastLine:Number = _textField.getLineIndexOfChar(lastCharIndex); - if(lastLine>_textField.bottomScrollV-1) - { - lastLine = _textField.bottomScrollV-1; - return _textField.getLineOffset(lastLine)+_textField.getLineLength(lastLine)-1; - } - return lastCharIndex; - } - - public function set textField(tf:IUITextField):void{ - _textField = tf; - } - - public function get textField():IUITextField{ - return _textField; - } - - public function set offsetPoint(op:Point):void{ - _offsetPoint = op; - } - - public function get offsetPoint():Point{ - return _offsetPoint; - } - - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFHighlighter.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFHighlighter.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFHighlighter.as deleted file mode 100644 index 92b7c71..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFHighlighter.as +++ /dev/null @@ -1,252 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.TextTokenizer; - import com.adobe.linguistics.utils.Token; - - import flash.display.Graphics; - import flash.display.Shape; - import flash.display.Sprite; - import flash.geom.Point; - import flash.geom.Rectangle; - import flash.text.engine.TextLine; - import flash.utils.Dictionary; - - import flashx.textLayout.compose.TextFlowLine; - import flashx.textLayout.container.ContainerController; - import flashx.textLayout.edit.SelectionManager; - import flashx.textLayout.elements.TextFlow; - import flashx.textLayout.tlf_internal; - import com.adobe.linguistics.spelling.ui.IHighlighter; - - - use namespace tlf_internal; - - /** - * <p>This class facilitates drawing of squiggly lines below words for TLF TextFlow class.</p> - * <p>The TextFlow class is responsible for managing all - * the text content of a story. In TextLayout, text is stored in a hierarchical tree of elements. TextFlow is the root object of the element tree. - * All elements on the tree derive from the base class, FlowElement. </p> - * TLFHighlighter could be used for drawing squiggly lines in any of the custom visual components(probably based on <code>Sprite</code>) which make use - * of TextFlow to display text. - * - * @playerversion Flash 10 - * @langversion 3.0 - */ - public class TLFHighlighter implements IHighlighter - { - - private var mTextFlow:TextFlow; - private var mHighlighter:Dictionary; - - //private var mHighlighter:Shape; - private var ccindex:int; - private var cc:ContainerController; - /* - * offset point: - */ - private var _offsetPoint:Point; - - /** - * The constructor for TLFHighlighter. - * @param textFlow <code>TextFlow</code> in which to enable highlighting. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function TLFHighlighter( textFlow:TextFlow ) - { - if (textFlow == null ) throw new Error("illegal argument."); - mTextFlow = textFlow; - //mHighlighter = null; - mHighlighter = new Dictionary(true); - this._offsetPoint = new Point(0,0); - } - /** - * Draw squiggly lines below a given token. - * @param token <code>Token</code> information of the word to be highlighted. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function drawSquiggleAt(token:Token):void - { - squiggleWord(token); - } - /** - * Clear all squiggly lines in the component. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function clearSquiggles():void - { - - for (var idx:int = 0; idx < mTextFlow.flowComposer.numControllers; idx++) - { - var cctmp:ContainerController = mTextFlow.flowComposer.getControllerAt(idx); - if (!cctmp) return; - if (mHighlighter[cctmp.container] != null) { - - //ToDO: This assumes single container for whole of mTextFlow. Need to implement for multiple container case. - cctmp.container.removeChild((mHighlighter[cctmp.container] as Shape)); - - mHighlighter[cctmp.container] = null; - } - } - } - - /** - * Set offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function set offsetPoint(op:Point):void{ - _offsetPoint = op; - } - /** - * Get offset point information for scrollable controls. This is used by the highlighter to move - * the squiggly lines as the text scrolls inside the control. - * @param op offset information as a <code>Point</code> instance. - * @playerversion Flash 10 - * @langversion 3.0 - */ - public function get offsetPoint():Point{ - return _offsetPoint; - } - - - - // TODO: refactor this code to share with halo components, and support words that cross lines - private function squiggleWord(token:Token):void { - var ta:TextFlow = mTextFlow; - - if (!ta) return; - ccindex = ta.flowComposer.findControllerIndexAtPosition(token.first); - - cc = ta.flowComposer.getControllerAt(ccindex); - if (!cc) return; - if (mHighlighter[cc.container] == null ) { - mHighlighter[cc.container]= new Shape(); - (mHighlighter[cc.container] as Shape).graphics.clear(); - //ccindex = ta.flowComposer.findControllerIndexAtPosition(token.first); - - //var cc:ContainerController = ta.flowComposer.getControllerAt(ccindex); - //ToDO: This assumes single container for whole of mTextFlow. Need to implement for multiple container case. - cc.container.addChild((mHighlighter[cc.container] as Shape)); - } - - drawSquigglyLineForRange(token.first, token.last); - - // Just adjust the left padding, top padding is not an issue - //var pleft:uint = mTextFlow.getStyle("paddingLeft"); - //mHighlighter.x += pleft; - } - - // Draw squiggly line - private function drawSquigglyLineForRange(start:Number, end:Number):void - { - // draw squiggly line - var tf:TextFlow = mTextFlow; - var tflFirst:TextFlowLine = tf.flowComposer.findLineAtPosition(start); - var tflLast:TextFlowLine = tf.flowComposer.findLineAtPosition(end); - var tflIndexFirst:int = tf.flowComposer.findLineIndexAtPosition(start); - var tflIndexLast:int = tf.flowComposer.findLineIndexAtPosition(end); - - // Pointer - var tflIndex:int = tflIndexFirst; - var tfl:TextFlowLine = tflFirst; - - if (tflIndexFirst == tflIndexLast) { - // Draw one line - drawSquigglyLineAtIndex(tflIndexFirst, start - tflFirst.absoluteStart, end - tflFirst.absoluteStart); - } else { - // Multiple lines (very long word) - drawSquigglyLineAtIndex(tflIndexFirst, start - tflFirst.absoluteStart); - - tflIndex++; - while (tflIndex != tflIndexLast) { - drawSquigglyLineAtIndex(tflIndex); - tflIndex++; - } - - drawSquigglyLineAtIndex(tflIndexLast, 0, end - tflLast.absoluteStart); - } - } - - // Draw a squiggly line at specific line for specific index range - private function drawSquigglyLineAtIndex(lineIndex:Number, startIndex:Number=0, endIndex:Number=0x7FFFFFFF):void - { - var tf:TextFlow = mTextFlow; - var tfl:TextFlowLine = tf.flowComposer.getLineAt(lineIndex); - var rectLine:Rectangle = tfl.getBounds(); - if (endIndex == 0x7FFFFFFF) { - drawSquigglyLineAtPoint(rectLine.left, rectLine.bottom, rectLine.right - rectLine.left, lineIndex); - } - else { - // Force to have a valid TextLine - var tl:TextLine = tfl.getTextLine(true); - if(tl==null)return; - var atomStartIndex:int= tl.getAtomIndexAtCharIndex(startIndex+ tl.textBlockBeginIndex);//fix for diacritic characters bug#2854971 - var atomEndIndex:int= tl.getAtomIndexAtCharIndex(endIndex+ tl.textBlockBeginIndex);//fix for diacritic characters bug#2854971 - // TODO: atom index and char index is not matching for some chars, use try/catch to avoid crash - try { - var rectFirst:Rectangle = tl.getAtomBounds(atomStartIndex); - var rectLast:Rectangle = tl.getAtomBounds(atomEndIndex); - drawSquigglyLineAtPoint(rectFirst.left + tfl.x, rectLine.bottom, rectLast.right - rectFirst.left, lineIndex); - } catch (err:Error) - { - trace(err); - } - } - - } - // Draw a squiggly from point x,y with given width, the line is drawn in mHighlighter - private function drawSquigglyLineAtPoint(x:Number, y:Number, width:Number, lineIndex:Number):void - { - var tf:TextFlow = mTextFlow; - var tfl:TextFlowLine = tf.flowComposer.getLineAt(lineIndex); - var tl:TextLine = tfl.getTextLine(true); - - (mHighlighter[cc.container] as Shape).graphics.lineStyle(1, 0xfa0707, .65); - (mHighlighter[cc.container] as Shape).graphics.moveTo(x, y); - var upDirection:Boolean = false; - var offset:uint = 0; - var stepLength:uint = 2; - for ( var i:uint = 1; offset <= width; i++) { - offset = offset + stepLength; - if ( upDirection ) - (mHighlighter[cc.container] as Shape).graphics.lineTo(x+offset,y); - else - (mHighlighter[cc.container] as Shape).graphics.lineTo(x+offset,y+stepLength); - upDirection = !upDirection; - } - - //tl.addChild(mHighlighter); - - //tf.flowComposer.updateToController(ccindex); - - } - - - } - -} - http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/4b3e346b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFWordProcessor.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFWordProcessor.as b/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFWordProcessor.as deleted file mode 100644 index 749e218..0000000 --- a/Squiggly/main/SpellingUI/src/com/adobe/linguistics/spelling/ui/TLFWordProcessor.as +++ /dev/null @@ -1,159 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package com.adobe.linguistics.spelling.ui -{ - import com.adobe.linguistics.utils.ITokenizer; - import com.adobe.linguistics.utils.TextTokenizer; - import com.adobe.linguistics.utils.Token; - - import flashx.textLayout.edit.SelectionManager; - import flashx.textLayout.edit.EditManager; - import flashx.textLayout.tlf_internal; - import flashx.textLayout.elements.TextFlow; - - import flashx.textLayout.container.ContainerController; - import flashx.textLayout.elements.FlowLeafElement; - import flashx.textLayout.elements.ParagraphElement; - import com.adobe.linguistics.spelling.ui.IWordProcessor; - - use namespace tlf_internal; - - public class TLFWordProcessor implements IWordProcessor - { - private var mTextFlow:TextFlow; - private var _containerController:ContainerController; - - public function TLFWordProcessor(textFlow:TextFlow) - { - if (textFlow == null ) throw new Error("illegal argument."); - mTextFlow = textFlow; - } - - - public function replaceText(token:Token, replacement:String):void { - var startIndex:int = token.first; - var endIndex:int = token.last; - - var ta:TextFlow = mTextFlow; - //var end:int = getValidLastWordIndex(); - - if ( replacement == null ) return; - - /*if (mTextFlow.text.length<endIndex || startIndex<0) { - return; - }*/ - - var _misspellStart:int = startIndex; - var _misspellEnd:int = endIndex; - - // Workaround for Spark: changes in inactive components will trigger strange behavior - //var selectedElementRange:ElementRange = ElementRange.createElementRange(ta.textFlow, _misspellStart, _misspellEnd); - //var selectedCharacterFormat:ITextLayoutFormat = ta.textFlow.interactionManager.activePosition == ta.textFlow.interactionManager.anchorPosition ? ta.textFlow.interactionManager.getCommonCharacterFormat() : selectedElementRange.characterFormat; - //var selectedParagraphFormat:ITextLayoutFormat = selectedElementRange.paragraphFormat; - //var selectedContainerFormat:ITextLayoutFormat = selectedElementRange.containerFormat; - - - - //var selectedCharacterFormat:ITextLayoutFormat = ta.textFlow.interactionManager.getCommonCharacterFormat(); - //var selectedContainerFormat:ITextLayoutFormat = ta.textFlow.interactionManager.getCommonContainerFormat(); - //var selectedParagraphFormat:ITextLayoutFormat = ta.textFlow.interactionManager.getCommonParagraphFormat(); - - var tem:EditManager = ta.interactionManager as EditManager; - - - - //ta.setFocus(); - //ta.text = ta.text.substr(0, _misspellStart) + replacement + ta.text.substr(_misspellEnd); - - //tem.applyFormat(selectedCharacterFormat,selectedParagraphFormat,selectedContainerFormat); - //ta.textFlow.flowComposer.updateAllControllers(); - - //ta.textFlow; - //ta.selectRange(_misspellStart + replacement.length, _misspellStart + replacement.length); - - - tem.selectRange(_misspellStart, _misspellEnd-1); - //tem.insertText(replacement); - //tem.selectRange(_misspellStart, _misspellStart+1); - //tem.insertText(""); - tem.overwriteText(replacement); - - //ta.textFlow.interactionManager.applyFormat(selectedCharacterFormat,null,null); - - // Workaround for unexpected jump - //ta.scrollToRange(end, end); - } - - /** - @private - (This property is for Squiggly Developer use only.) - */ - public function set textFlowContainerController(value:ContainerController):void { - _containerController = value; - } - - public function getWordAtPoint(x:uint, y:uint, externalTokenizer:ITokenizer=null):Token - { - // TODO: use a better alternative than _misspellStart, end - var ta:TextFlow = mTextFlow; - - var index:int = SelectionManager.computeSelectionIndex(ta, _containerController.container, _containerController.container, x, y); - - if (index >= ta.textLength) return null; - - var currentLeaf:FlowLeafElement = ta.findLeaf(index); - var currentParagraph:ParagraphElement = currentLeaf ? currentLeaf.getParagraph() : null; - - if (currentParagraph == null) return null; - var paraStart:uint = currentParagraph.getAbsoluteStart(); - - //tokenizer = new TextTokenizer(currentParagraph.getText().substring()); - - var tmpToken:Token = new Token(index - paraStart,index - paraStart); - var tokenizer:ITokenizer; - if ( externalTokenizer == null ) { - tokenizer = new TextTokenizer(currentParagraph.getText().substring()); - }else { - tokenizer = externalTokenizer; - } - - var result:Token = new Token(0,0); - var preToken:Token = tokenizer.getPreviousToken(tmpToken); - var nextToken:Token = tokenizer.getNextToken(tmpToken); - if ( preToken.last == nextToken.first ) { - result.first = preToken.first + paraStart; - result.last = nextToken.last + paraStart; - return result; - }else { - return null; - } - - } - - // TODO: workaround for unexpected jump when word replaced, to be refactored for code sharing - private function getValidLastWordIndex():int{ - var index:int = 0; - //var index:int = SelectionManager.computeSelectionIndex(mTextFlow.textFlow, mTextFlow, mTextFlow, mTextFlow.width+mTextFlow.horizontalScrollPosition, mTextFlow.height+mTextFlow.verticalScrollPosition); - return index; - } - - - } -} \ No newline at end of file