Repository: nvaccess/nvda

Issue:
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
### Is your feature request related to a problem? Please describe.
In the paragraph formatting dialog in MS Word, we set the first line indent to be XX characters, but NVDA reports XX centimeters, which confuses users.

Use the object model to access Word documents, press NVDA + F to get formatting information:
> style 正文 楷体 16 pt default color align default first line indent 2 characters line spacing 1.5 lines
Use the UIA to access Word documents, press NVDA + F to get formatting information:
> style 正文 楷体 16.0 pt black on white align justify first line indent 1.13 cm line spacing 1/.5 倍行距
### Describe the solution you'd like

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.

### Describe alternatives you've considered

### Additional context
None


Discussion:
As discussed on #14553 , this should only happen for a known set of locales. What languages do you think this is appropriate for @cary-rowen ?
Hi @seanbudd 
According to my test, this happens at least in the zh-CN and zh-TW locales. For Chinese users, it is a strange behavior to express the indentation size in inches and centimeters, We are more used to following the options in the MS Word Paragraph Settings dialog.

Btw, if this is a bug, do I need to turn this into a bug report, not a feature request?
I think there is enough information now to work on this problem. Thanks.
@cary-rowen could you check your Word options:
* Open Word options (alt, F, V on my system)
* Select "Advanced options" category
* Tab to the checkbox "Show measurements in character width"
Is this checkbox checked. On French MS Word, it is not by default. I guess it is checked by default on East-Asian versions of Word; could you confirm this?

More generally, I am a bit reluctant to make such specific processing according to locale. If possible, I will try to base how things are reported upon Word option if and when it is available via object model.

@CyrilleB79 
I checked the option you mentioned, it is checked by default, when I uncheck it, NVDA behaves the same as MSWord option,
It would probably be nice if NVDA depended on this option.
> @CyrilleB79 I checked the option you mentioned, it is checked by default, when I uncheck it, NVDA behaves the same as MSWord option, It would probably be nice if NVDA depended on this option.

Could you confirm this test is done with UIA? With object model, the options is honored on my side.


Hi @CyrilleB79 
More detailed test results are as follows:
## In the UIA enabled state, not checked "Show measurements in character width":
style 正文 等线 10.0 pt black on white align justify first line indent 0.90 cm line spacing 单倍行距

## In the UIA disabled state, not checked "Show measurements in character width":
style 正文 等线 10.5 pt default color align default first line indent 0.899 centimeters line spacing single

## In the UIA enabled state, checked "Show measurements in character width":
style 正文 等线 10.0 pt black on white align justify first line indent 0.90 cm line spacing 单倍行距

## In the UIA disabled state, checked "Show measurements in character width":
style 正文 等线 10.5 pt default color align default first line indent 2.43 characters line spacing single


Resolving patch:
diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py
--- a/source/NVDAObjects/UIA/__init__.py
+++ b/source/NVDAObjects/UIA/__init__.py
@@ -1,8 +1,8 @@
 # A part of NonVisual Desktop Access (NVDA)
 # This file is covered by the GNU General Public License.
 # See the file COPYING for more details.
-# Copyright (C) 2009-2022 NV Access Limited, Joseph Lee, Mohammad Suliman,
-# Babbage B.V., Leonard de Ruijter, Bill Dengler
+# Copyright (C) 2009-2023 NV Access Limited, Joseph Lee, Mohammad Suliman, Babbage B.V., Leonard de Ruijter,
+# Bill Dengler, Cyrille Bougot
 
 """Support for UI Automation (UIA) controls."""
 import typing
@@ -388,8 +388,7 @@ def _getFormatFieldIndent(
 			formatField['right-indent'] = self._getIndentValueDisplayString(uiaIndentTrailing)
 		return formatField
 	
-	@staticmethod
-	def _getIndentValueDisplayString(val: float) -> str:
+	def _getIndentValueDisplayString(self, val: float) -> str:
 		"""A function returning the string to display in formatting info.
 		@param val: an indent value measured in points, fetched via
 			an UIAHandler.UIA_Indentation*AttributeId attribute.
diff --git a/source/NVDAObjects/UIA/wordDocument.py b/source/NVDAObjects/UIA/wordDocument.py
--- a/source/NVDAObjects/UIA/wordDocument.py
+++ b/source/NVDAObjects/UIA/wordDocument.py
@@ -1,7 +1,7 @@
 # This file is covered by the GNU General Public License.
 # A part of NonVisual Desktop Access (NVDA)
 # See the file COPYING for more details.
-# Copyright (C) 2016-2022 NV Access Limited, Joseph Lee, Jakub Lukowicz
+# Copyright (C) 2016-2023 NV Access Limited, Joseph Lee, Jakub Lukowicz, Cyrille Bougot
 
 from typing import (
 	Optional,
@@ -448,6 +448,24 @@ def _getFormatFieldAtRange(self, textRange, formatConfig, ignoreMixedValues=Fals
 					if isinstance(textColumnNumber, int):
 						formatField.field['text-column-number'] = textColumnNumber
 		return formatField
+	
+	def _getIndentValueDisplayString(self, val: float) -> str:
+		"""A function returning the string to display in formatting info in Word documents.
+		@param val: an indent value measured in points, fetched via
+			an UIAHandler.UIA_Indentation*AttributeId attribute.
+		@return: The string used in formatting information to report the length of an indentation.
+		"""
+		
+		if self.obj.WinwordApplicationObject:
+			# When Word object model is available we honour Word's options to report distances so that what is
+			# reported by NVDA matches Word's UI (rulers, paragraph formatting dialog, etc.)
+			# Default seem to be inch or centimeters for Western countries localization of Word and characters for
+			# east Asian localisations.
+			return self.obj.getLocalizedMeasurementTextForPointSize(val)
+		
+		# If Word object model is not available, we just fallback to general UIA case, i.e. use Windows regional
+		# settings.
+		return super()._getIndentValueDisplayString(val)
 
 
 class WordBrowseModeDocument(UIABrowseModeDocument):


Test patch: