Skip to content

Support math content in MS Word build 14326+ via UIA#12977

Merged
michaelDCurran merged 7 commits intomasterfrom
i12946
Oct 27, 2021
Merged

Support math content in MS Word build 14326+ via UIA#12977
michaelDCurran merged 7 commits intomasterfrom
i12946

Conversation

@michaelDCurran
Copy link
Member

Link to issue number:

Fixes #12946
Fixes #12941

Summary of the issue:

NVDA was able to provide rich support of mathematical content in Microsoft Word by making use of MathPlayer, MathType and the MS Word object model.
However, when NVDA only relies on UI Automation to access MS Word docuents, it is no longer possible to fetch mathMl from MathType equations via the MS Word object model.
However, Microsoft very recently added a new UI Automation custom property for fetching raw mathMl from an Office Equation node, thus if NVDa were to fetch this mathMl, then it could pass it along to mathPlayer as usual, then providing rich reading / navigation of math content in MS word again.

Description of how this pull request fixes the issue:

  • Register the mathMl UIA custom property.
  • Fetch the raw mathMl from an MS Word Office Equation node.
  • Expose it for the rest of NVDA to find and use with mathPlayer.

Note that MS Word also provides a basic form of linea symbol navigation in equations, so we make sure that the mathMl is exposed to mathPlayer when moving by line, replacing MS Word's own inner math content. But if moving by word/character, then MS Word's own inner math content is left in tact.

Testing strategy:

  • Opened an MS Word document
  • Started typing a math equation by pressing alt+=
  • Typed an equation like x^2+x+1 and pressed enter.
  • Pressed up arrow to move back up to the equation, confirming that NVDA read out the equation with mathPlayer, and also brailled the equation in Nemeth code.
  • Used the left and right arrow keys to move through the equation by symbol. Confirming that Microsoft Word's own navigation was used, and each symbol was reported.
  • Pressed NvDA+alt+m to interact with the Math using MathPlayer and moved aorund the math tree with the arrows.
  • Pressed escape to exit Math interaction mode.
  • Switched to Browse mode with NVDA+space.
  • Pressed enter to activate the current item in browse mode, ensuring that mat interaction mode was entered.
  • Pressed ecape to exit math interaction mode.
  • Still in browse mode, pressed NvDA+alt+m to enter math interaction mode.
  • Pressed escape to exit math interaction mode.

Known issues with pull request:

Users / authors will have to convert any old MathType equations to Office Equations by selecting each equation, and then choosing Equation Options -> Convert to Office math in the context menu.
The experience for typing math equations is now slightly different in that the user needs to now use Microsoft Word's own math input feature. I.e. pressing alt+= and typing the equation. However, MS Word does now support several input syntaxes, including LateX similar to MathType.

Change log entries:

New features
In Microsoft Word accessed via UI Automation, NVDA will now make use of mathPlayer to read and navigate Office math equations. (#12946)
- For this to work, you must be running Microsoft Word 365/2016 build 14326 or later.
- MathType equations must also be manually converted to Office Math by selecting each and choosing Equation options -> Convert to Office Math in the context menu.
Changes
Bug fixes
For Developers

Code Review Checklist:

  • Pull Request description:
    • description is up to date
    • change log entries
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • API is compatible with existing add-ons.
  • Documentation:
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English

@michaelDCurran michaelDCurran requested review from a team as code owners October 22, 2021 03:50
@michaelDCurran michaelDCurran requested review from Qchristensen and seanbudd and removed request for a team October 22, 2021 03:50
@michaelDCurran
Copy link
Member Author

Assuming that we keep accessing UIA by default in recent builds of MS Word for NvDA 2021.4, it is necessary for this pr to be also included, otherwise users will loose access to mathematical content.

@michaelDCurran michaelDCurran added this to the 2021.3 milestone Oct 22, 2021
@AppVeyorBot
Copy link

See test results for failed build of commit 44ef7b49e4

class WordBrowseModeDocument(UIABrowseModeDocument):

def shouldSetFocusToObj(self,obj):
def _shouldSetFocusToObj(self, obj: NVDAObject) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is changing the name of this function an API breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it was actually incorrectly named in the first place. It should be an override for BrowseModeDocumentTreeInterceptor._shouldSetfocusToObj. In other words, that code never actually ran. It correctly does now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, there may be add-ons that are calling shouldSetFocusToObj directly. If this is going into 2021.3 then I think there should be an alias (then removed in 2022.1)

	def _shouldSetFocusToObj(self, obj: NVDAObject) -> bool:
	...

	if nvdaversion.year < 2022:
		shouldSetFocusToObj = _shouldSetFocusToObj  # deprecated to be removed in 2022.1

seanbudd
seanbudd previously approved these changes Oct 22, 2021
Qchristensen
Qchristensen previously approved these changes Oct 22, 2021
Copy link
Member

@Qchristensen Qchristensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good and will be appreciated by users, great work :)

@cary-rowen
Copy link
Contributor

Oh, cool!

elif obj.role == controlTypes.Role.MATH:
# Don't set focus to math equations otherwise they cannot be interacted with mathPlayer.
return False
return super(WordBrowseModeDocument,self).shouldSetFocusToObj(obj)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget this one

Suggested change
return super(WordBrowseModeDocument,self).shouldSetFocusToObj(obj)
return super()._shouldSetFocusToObj(obj)


def shouldSetFocusToObj(self,obj):
def _shouldSetFocusToObj(self, obj: NVDAObject) -> bool:
# Ignore strange editable text fields surrounding most inner fields (links, table cells etc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the below lines into a helper function and call that in both _shouldSetFocusToObj and shouldPassThrough? That way it's easier to see equal logic is used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is worth doing as it is really just two lines in each. An elif and a return False. Also, just because the lines do seem to look the same, they are of course representing slightly different questions.

try:
return self._getUIACacheablePropertyValue(self._UIACustomProps.word_mathml.id)
except COMError:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than passing (i.e. returning None implicitly), I think it's nicer to return None explicitly here.

Note however that any previously created MathType equations must be first converted to Office Math by selecting each and choosing Equation Options -> Convert to Office Math in the context menu. Ensure your version of MathType is the latest version before doing this.
Microsoft Word also now provides linea symbol-based navigation through the equations itself, and supports inputting math using several syntaxes, including LateX. For further details, please see [Linear format equations using UnicodeMath and LaTeX in Word https://support.microsoft.com/en-us/office/linear-format-equations-using-unicodemath-and-latex-in-word-2e00618d-b1fd-49d8-8cb4-8d17f25754f8]
- Microsoft Powerpoint, and older versions of Microsoft Word:
NVDA can read and navigate MathType equations in both Microsoft Powerpoint and Microsoft word.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, have you verified that this is formatted nicely?

@michaelDCurran michaelDCurran changed the base branch from beta to master October 26, 2021 02:34
@michaelDCurran
Copy link
Member Author

This has been rebased to master and will be not in NVDA 2021.3.

@michaelDCurran michaelDCurran removed this from the 2021.3 milestone Oct 26, 2021
@michaelDCurran michaelDCurran added this to the 2022.1 milestone Oct 26, 2021
@cary-rowen
Copy link
Contributor

It's a shame not to include this pr in 2021.3.

@CyrilleB79
Copy link
Contributor

@cary-rowen please note also that UIA will not be forced by default in 2021.3 according to #12989. So this shouldn't be a problem not to have this PR included.

@michaelDCurran michaelDCurran merged commit 9f8fff8 into master Oct 27, 2021
@michaelDCurran michaelDCurran deleted the i12946 branch October 27, 2021 03:01
@codeofdusk
Copy link
Contributor

This PR is still listed under 2021.3 changes. Is this a mistake?

CyrilleB79 added a commit to CyrilleB79/nvda that referenced this pull request Nov 25, 2021
…21.3 to 2022.1; the PR (nvaccess#12977) has been retargetted from beta to master but the change log item has been forgotten.
@CyrilleB79
Copy link
Contributor

Yes it's a mistake due to retargetting from beta to master. Good catch!
I have submitted #13095 to fix this.

michaelDCurran pushed a commit that referenced this pull request Nov 25, 2021
…2022.1; the PR (#12977) has been retargetted from beta to master but the change log item has been forgotten. (#13095)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support mathML UIA custom property in MS Word nvda alpha no longer works with math player

9 participants