From: <nor...@nv...> - 2014-07-31 04:46:06
|
The branch mathPlayer2014 has been updated From 7e7f43d to 1448df6 New revisions: - Log ----------------------------------------------------------------- commit 1448df66d610b66f12447b03e4ea79dfaa0942cb Author: James Teh <ja...@nv...> Date: Thu Jul 31 14:45:55 2014 +1000 Handle equations that aren't at the caret in Microsoft Word. commit 17b06a6ca0051b939e4177932af592b2e01f16e3 Author: James Teh <ja...@nv...> Date: Thu Jul 31 14:44:52 2014 +1000 Move getMathMlForEquation to TextInfos, as it may need something specific to the range. VirtualBufferTextInfo's implementation calls an implementation on VirtualBuffer, as this is easier than subclassing VirtualBufferTextInfo for each buffer type that supports math. ----------------------------------------------------------------------- Summary of changes: nvdaHelper/remote/winword.cpp | 5 +++-- source/NVDAObjects/window/winword.py | 15 +++++++-------- source/speech.py | 4 ++-- source/virtualBuffers/__init__.py | 3 +++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/nvdaHelper/remote/winword.cpp b/nvdaHelper/remote/winword.cpp index 95a2887..a54fa9f 100644 --- a/nvdaHelper/remote/winword.cpp +++ b/nvdaHelper/remote/winword.cpp @@ -669,7 +669,7 @@ inline int getInlineShapesCount(IDispatch* pDispatchRange) { * Generates an opening tag for the first inline shape in this range if one exists. * If the function is successful, the total number of inline shapes for this range is returned allowing the caller to then perhaps move the range forward a character and try again. */ -inline int generateInlineShapeXML(IDispatch* pDispatchRange, wostringstream& XMLStream) { +inline int generateInlineShapeXML(IDispatch* pDispatchRange, int offset, wostringstream& XMLStream) { IDispatchPtr pDispatchShapes=NULL; IDispatchPtr pDispatchShape=NULL; int count=0; @@ -703,6 +703,7 @@ inline int generateInlineShapeXML(IDispatch* pDispatchRange, wostringstream& XML } XMLStream<<L"<control _startOfNode=\"1\" role=\""<<(shapeType==wdInlineShapePicture?L"graphic":L"object")<<L"\" value=\""<<altTextStr<<L"\""; if(shapeType==wdInlineShapeEmbeddedOLEObject) { + XMLStream<<L" shapeoffset=\""<<offset<<L"\""; IDispatchPtr pOLEFormat=NULL; if(_com_dispatch_raw_propget(pDispatchShape,wdDISPID_INLINESHAPE_OLEFORMAT,VT_DISPATCH,&pOLEFormat)==S_OK) { BSTR progId=NULL; @@ -876,7 +877,7 @@ void winword_getTextInRange_helper(HWND hwnd, winword_getTextInRange_args* args) } //If there are inline shapes somewhere, try getting and generating info for the first one hear. //We also get the over all count of shapes for this word so we know whether we need to check for more within this word - int inlineShapesCount=hasInlineShapes?generateInlineShapeXML(pDispatchRange,XMLStream):0; + int inlineShapesCount=hasInlineShapes?generateInlineShapeXML(pDispatchRange,chunkStartOffset,XMLStream):0; if(inlineShapesCount>1) { _com_dispatch_raw_method(pDispatchRange,wdDISPID_RANGE_COLLAPSE,DISPATCH_METHOD,VT_EMPTY,NULL,L"\x0003",wdCollapseStart); if(_com_dispatch_raw_method(pDispatchRange,wdDISPID_RANGE_MOVEEND,DISPATCH_METHOD,VT_I4,&unitsMoved,L"\x0003\x0003",wdCharacter,1)!=S_OK||unitsMoved<=0) { diff --git a/source/NVDAObjects/window/winword.py b/source/NVDAObjects/window/winword.py index d6a8d07..ce5477f 100755 --- a/source/NVDAObjects/window/winword.py +++ b/source/NVDAObjects/window/winword.py @@ -531,6 +531,13 @@ class WordDocumentTextInfo(textInfos.TextInfo): self.obj.WinwordWindowObject.ScrollIntoView(self._rangeObj) self.obj.WinwordSelectionObject.SetRange(self._rangeObj.Start,self._rangeObj.End) + def getMathMlForEquation(self, field): + import mathType + range = self._rangeObj.Duplicate + range.Start = int(field["shapeoffset"]) + obj = range.InlineShapes[0].OLEFormat + return mathType.getMathMl(obj) + class WordDocument(EditableTextWithoutAutoSelectDetection, Window): TextInfo=WordDocumentTextInfo @@ -967,14 +974,6 @@ class WordDocument(EditableTextWithoutAutoSelectDetection, Window): def script_previousColumn(self,gesture): self._moveInTable(row=False,forward=False) - def getMathMlForEquation(self, field): - import mathType - # fixme: Don't assume the equation at the caret. - ti = self.makeTextInfo(textInfos.POSITION_CARET) - ti.expand(textInfos.UNIT_CHARACTER) - obj = ti._rangeObj.InlineShapes[0].OLEFormat - return mathType.getMathMl(obj) - __gestures = { "kb:control+[":"increaseDecreaseFontSize", "kb:control+]":"increaseDecreaseFontSize", diff --git a/source/speech.py b/source/speech.py index 5831a11..f947a37 100755 --- a/source/speech.py +++ b/source/speech.py @@ -700,7 +700,7 @@ def speakTextInfo(info,useCache=True,formatConfig=None,unit=None,reason=controlT if field.get("role") == controlTypes.ROLE_EQUATION: import mathPlayer if mathPlayer.ensureInit(): - speechSequence.extend(mathPlayer.getSpeechForMathMl(info.obj.getMathMlForEquation(field))) + speechSequence.extend(mathPlayer.getSpeechForMathMl(info.getMathMlForEquation(field))) commonFieldCount+=1 #Fetch the text for format field attributes that have changed between what was previously cached, and this textInfo's initialFormatField. @@ -780,7 +780,7 @@ def speakTextInfo(info,useCache=True,formatConfig=None,unit=None,reason=controlT if command.command == "controlStart" and command.field.get("role") == controlTypes.ROLE_EQUATION: import mathPlayer if mathPlayer.ensureInit(): - relativeSpeechSequence.extend(mathPlayer.getSpeechForMathMl(info.obj.getMathMlForEquation(command.field))) + relativeSpeechSequence.extend(mathPlayer.getSpeechForMathMl(info.getMathMlForEquation(command.field))) if autoLanguageSwitching and newLanguage!=lastLanguage: relativeSpeechSequence.append(LangChangeCommand(newLanguage)) lastLanguage=newLanguage diff --git a/source/virtualBuffers/__init__.py b/source/virtualBuffers/__init__.py index 860422a..647f2e8 100644 --- a/source/virtualBuffers/__init__.py +++ b/source/virtualBuffers/__init__.py @@ -323,6 +323,9 @@ class VirtualBufferTextInfo(textInfos.offsets.OffsetsTextInfo): def activate(self): self.obj._activatePosition(self) + def getMathMlForEquation(self, field): + return self.obj.getMathMlForEquation(field) + class ElementsListDialog(wx.Dialog): ELEMENT_TYPES = ( # Translators: The label of a radio button to select the type of element |