Skip to content

Use Word object model to report distances when available#14575

Merged
michaelDCurran merged 5 commits into
nvaccess:masterfrom
CyrilleB79:wordMeasurements
Feb 15, 2023
Merged

Use Word object model to report distances when available#14575
michaelDCurran merged 5 commits into
nvaccess:masterfrom
CyrilleB79:wordMeasurements

Conversation

@CyrilleB79

@CyrilleB79 CyrilleB79 commented Jan 19, 2023

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #14542

Summary of the issue:

When pressing NVDA+F, for Chinese people, paragraph indent is reported in number of characters by default when NVDA is using Word object model to access Word documents. But it is reported in centimeter when NVDA is using UIA to access Word documents.

When using object model, the way NVDA reports indent in Word honours the two following advanced options of Word:

  • "Show measurements in" (centimeters, inches, etc.)
  • "Show measurements in character width" (Note: for this option to be available, you need to have an East-Asian language installed in Word's languages)

These options should be also honoured when using UIA for Word documents. Especially, Chinese people are used to express measurements in characters, what NVDA does not when using UIA for Word documents.

Description of user facing changes

Word's advanced options are now used instead of system options also when using UIA to access Word documents. Thus, the option "Show measurements in character width" in Word advanced options is now honoured also when using UIA for Word documents.

Description of development approach

The only way I've found to know how distances are reported in Word (according to this option) is to use Word object model. Thus, if possible, we use Word object model to access Word's options, even if NVDA uses UIA to access Word document.

When object model is not available however, Windows regional setting is used as a fallback as it was before this PR.

Testing strategy:

Manual tests:
In a paragraph having indentation, press NVDA+F in the 4 following combined cases:

  • object model / UIA to access Word document
  • "Show measurements in character width" in Word's advanced option enabled / disabled

Known issues with pull request:

None

Change log entries:

Changes
Distance reported in Word will now honour the unit defined in Word's advanced options even when using UIA to access Word documents. (#14542)

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
  • Security precautions taken.

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@cary-rowen would you mind using the test build of this PR when it is ready to check if it fixes #14542? Thanks.

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 3b72d100ad

@cary-rowen

Copy link
Copy Markdown
Contributor

Hi @CyrilleB79
Thanks for trying to fix this, the CI build seems to be failing, I'll be the first to test it if it works, thanks.

@cary-rowen

Copy link
Copy Markdown
Contributor

@CyrilleB79
I tested the build of this PR and it can follow MS Word's "Show measurements in character widt" located in the advanced settings.
But I found another situation, I don't know if I should discuss it separately at the moment:
Checked "Show measurements in character widt": NVDA +F is still reported as characters when the user manually specifies the first line indent as XX cm instead of xx characters in the paragraph formatting dialog.
Ideally, should it also be reported as a manually specified value by the user - XX cm, Because manually changing the unit is allowed for ms Word.

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@CyrilleB79 I tested the build of this PR and it can follow MS Word's "Show measurements in character widt" located in the advanced settings. But I found another situation, I don't know if I should discuss it separately at the moment: Checked "Show measurements in character widt": NVDA +F is still reported as characters when the user manually specifies the first line indent as XX cm instead of xx characters in the paragraph formatting dialog. Ideally, should it also be reported as a manually specified value by the user - XX cm, Because manually changing the unit is allowed for ms Word.

I confirm that the user can use any unit in the paragraph formatting dialog. But internally Word stores it in the preferred unit, i.e. the one defined in Word's advanced options. To view an evidence of it, you can do as follows:

  • While your unit is set to "character" in Word's advanced options, open paragraph formatting options
  • Enter a value in "cm" and validate
  • Reopen the paragraph formatting options.
    You will see that the unit in this dialog is in the unit of Word's advanced options, i.e. character for you.

So IMO, this makes no sense for NVDA to report the distance with a unit other than the preferred option in any case. Also, keep in mind that the preferred unit option is the one that sighted people will see on the rulers on the side of the pages when Word is in page mode.

@CyrilleB79 CyrilleB79 marked this pull request as ready for review January 20, 2023 21:57
@CyrilleB79 CyrilleB79 requested a review from a team as a code owner January 20, 2023 21:57
@CyrilleB79 CyrilleB79 requested a review from seanbudd January 20, 2023 21:57
@cary-rowen

Copy link
Copy Markdown
Contributor

Hello, I saw the following two setting items in the advanced options of MS Word:

Show measurements in units of:

  • Centimeters
  • Millimeters
  • Points
  • Picas

This option includes the following items, Centimeters is selected by default but does not contain the character (ch)

Show measurements in width of characters

The checkbox is checked


  1. Enter a value in "cm" and validate
  2. Reopen the paragraph formatting options.
    You will see that the unit in this dialog is in the unit of Word's advanced options, i.e. character for you.

No, since the units in the advanced options don't contain characters, it still shows centimeters even though I also ticked "Show measurements in width of characters".

@CyrilleB79

CyrilleB79 commented Jan 22, 2023

Copy link
Copy Markdown
Contributor Author

(note: edited to be still clearer)

OK, I have not been extra clear. Let me try to rephrase the explanations and the steps.

Word uses only one unit internally to store distances such as the one shown in paragraph formatting dialog. The unit in paragraph formatting dialog can be: characters, inches, centimeters, millimeters, points or picas.
This unit is controlled by 2 options in Word advanced options:

  • "Show measurements in width of characters": if this checkbox is checked, the paragraph formatting settings show indent in characters. If it is unchecked (or not present if no east Asian language is installed), "Show measurements in units of:" option is looked at.
  • "Show measurements in units of:": it is used in paragraph formatting dialog only if "Show measurements in width of characters" is unchecked. In this case, the value in paragraph formatting dialog may be in inches, centimeters, millimeters, points or picas.

Now, here are steps to see which unit Word uses internally without looking at the options:

  • While "Show measurements in width of characters" is checked in Word's advanced options, open paragraph formatting options
  • Enter a value in "cm" and validate
  • Reopen the paragraph formatting options.
    You will see that the unit in this dialog is in character, which match the checkbox "Show measurements in width of characters" in Word's advanced options.

So it makes sense for NVDA to report distances in the units as defined in Word's advanced option. That is, In case the checkbox "Show measurements in width of characters" is checked in the advanced options, the preferred unit is characters and not the one defined in "Show measurements in units of:", which has no effect in the paragraph formatting dialog when the checkbox "Show measurements in width of characters" is checked.

@cary-rowen

Copy link
Copy Markdown
Contributor

Hi,

Thanks for your patience in clarifying.
But it seems something different in my case, please let me explain.
You wrote:

  1. While "Show measurements in width of characters" is checked in Word's advanced options, open paragraph formatting options
  2. Enter a value in "cm" and validate
  3. Reopen the paragraph formatting options.
  4. You will see that the unit in this dialog is in character, which match the checkbox "Show measurements in width of characters" in Word's advanced options.

The actual situation:

  • I can successfully set to cm when I perform step 2.
  • When I do step 4, I still see 'cm' instead of 'character' in the paragraph formatting options.

A question arises from this:

  • If I set the first line indent to 1.8 cm
  • When I tested with this snapshot from that PR, NVDA reported 4.86 characters, which is so confusing.
  • Please note, Now the first line indent in the paragraph format option is displayed as 1.8cm

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

@cary-rowen thanks for these details.

I am a bit confused. I am now able to reproduce your result with the same steps as you on Microsoft® Word 2016 (16.0.5369.1000) MSO (16.0.5366.1000) 32 bits. I will try to confirm tonight that I can also reproduce on a newer version of Office 2016.

The only situation where the unit is not kept in memory is when you enter "0 cm"; it is memorized as 0 character. Not problematic for NVDA reporting however.

If we want the information of the unit from the paragraph formatting dialog, it's probably available via the document's object model. When the user selects UIA to access Word document, getting this information would mean using the document objet model anyway if available. In any case, if object model is not available, the application will use the unit defined in the system regional settings.

Before going further, I would like to hear NVAccess point of view before getting information from the document object model while in UIA.

@cary-rowen

Copy link
Copy Markdown
Contributor

Thank you for your efforts, Let's wait for what NV Access thinks.
I should add that my Office version information is as follows:
Microsoft 365MSO (version 2212 Build 16.0.15928.20196) 64 Bit

@ABuffEr

ABuffEr commented Jan 24, 2023

Copy link
Copy Markdown
Contributor

Hi,

I'm heavily working on Word in these days, with object model and even with C++ part. So, this discussion caught my curiosity

The point, I think, is that method getLocalizedMeasurementTextForPointSize takes care of Word options, but has no check on current paragraph in any way. I won't suggest a coded solution (I appreciate a lot Cyrille's participation), but observe this test:

  1. ensure to have UIA disabled, a language like simplified Chinese of Taiwan installed in Word, "Show measurements in character width" checked, "Show measurements in units of:" set on centimeters (for testing, it should not matter);
  2. close and re-open a new Word document, and write something, i.e. "Test";
  3. open NVDA Python console with NVDA+ctrl+z;
  4. write following instructions:
p=focus.WinwordSelectionObject.Paragraphs(1)
p.CharacterUnitFirstLineIndent
# it should be 0.0
p.FirstLineIndent
# 0.0 again
  1. now, without closing console, return to document, open paragraph settings, and set first line indent to 2 (without measure) or 2 characters;
  2. return to console and re-check:
p.CharacterUnitFirstLineIndent
# it should be 2.0
p.FirstLineIndent
# it should be 22.0
  1. again, document, paragraph settings, but this time set 3 cm;
  2. again, from console:
p.CharacterUnitFirstLineIndent
# it should be 0.0
p.FirstLineIndent
# oh yes, it should be 85 and cents

So, with a bit of if-elif-else to decide whether a conversion is needed, there could be a solution.

If this will be considered too slow, I could look to get these information via C++ component.

Hth.

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

Yes I agree that there is a solution and that's what I had in mind when writing:

If we want the information of the unit from the paragraph formatting dialog, it's probably available via the document's object model.

On my side, the questions still open are:

  • Does it make sense to use Word document object model when UIA is checked (and will NVAccess accept it) ?
  • Does it make sense to use the unit specified in the paragraph formatting dialog to report indent? Especially when (I guess) sighted people do not have it; I guess that sighted people just have the rulers on the side of the page graduated with the unit defined by both Word's advanced options; to be checked by good eyes if possible.

I can still change my mind in the future, but for now, I would answer "No" to these two questions and keep this PR as is.

@ABuffEr

ABuffEr commented Jan 24, 2023

Copy link
Copy Markdown
Contributor
* Does it make sense to use Word document object model when UIA is checked (and will NVAccess accept it) ?

Sure, this is a good point, and I'm interested too.

Personally, now I discovered it, I'd like to keep measurements in character width even with UIA enabled, so I'm favorable to this PR effects, regardless of the second question or technical details.

Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
Comment thread source/NVDAObjects/UIA/__init__.py Outdated
Co-authored-by: Michael Curran <mick@nvaccess.org>
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 97e48089cb

@CyrilleB79

Copy link
Copy Markdown
Contributor Author

Thanks @michaelDCurran for your review. I have accepted your modifications and tested the case when Word object model is unavailable (on commit 63a5319) by forcing manually the if statement of _getIndentValueDisplayString to be False. I have no opportunity to test real-life use case where object model is unavailable.

@michaelDCurran michaelDCurran merged commit 82a5a07 into nvaccess:master Feb 15, 2023
@nvaccessAuto nvaccessAuto added this to the 2023.2 milestone Feb 15, 2023
@CyrilleB79 CyrilleB79 deleted the wordMeasurements branch February 27, 2023 20:18
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.

When using UIA to access Word documents, replace the XX centimeters of the indent value with xx characters to ensure the consistency of user experience

6 participants