Skip to content

Commit 190d4a3

Browse files
authored
Merge 8f46226 into f8df880
2 parents f8df880 + 8f46226 commit 190d4a3

1 file changed

Lines changed: 69 additions & 17 deletions

File tree

source/NVDAObjects/UIA/__init__.py

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444

4545

4646
paragraphIndentIDs = {
47-
UIAHandler.UIA_IndentationFirstLineAttributeId: "first-line-indent",
48-
UIAHandler.UIA_IndentationLeadingAttributeId: "left-indent",
49-
UIAHandler.UIA_IndentationTrailingAttributeId: "right-indent",
47+
UIAHandler.UIA_IndentationFirstLineAttributeId,
48+
UIAHandler.UIA_IndentationLeadingAttributeId,
49+
UIAHandler.UIA_IndentationTrailingAttributeId,
5050
}
5151

52+
5253
class UIATextInfo(textInfos.TextInfo):
5354

5455
_cache_controlFieldNVDAObjectClass=True
@@ -232,20 +233,7 @@ def _getFormatFieldAtRange(self,textRange,formatConfig,ignoreMixedValues=False):
232233
if val!=UIAHandler.handler.reservedNotSupportedValue:
233234
formatField["style"]=val
234235
if formatConfig["reportParagraphIndentation"]:
235-
for ID, fieldAttr in paragraphIndentIDs.items():
236-
val = fetcher.getValue(ID, ignoreMixedValues=ignoreMixedValues)
237-
if isinstance(val, float):
238-
# val is in points (1/72 of an inch)
239-
val /= 72.0
240-
if languageHandler.useImperialMeasurements():
241-
# Translators: a measurement in inches
242-
valText = _("{val:.2f} in").format(val=val)
243-
else:
244-
# Convert from inches to centermetres
245-
val *= 2.54
246-
# Translators: a measurement in centermetres
247-
valText = _("{val:.2f} cm").format(val=val)
248-
formatField[fieldAttr] = valText
236+
formatField.update(self._getFormatFieldIndent(fetcher, ignoreMixedValues=ignoreMixedValues))
249237
if formatConfig["reportAlignment"]:
250238
val=fetcher.getValue(UIAHandler.UIA_HorizontalTextAlignmentAttributeId,ignoreMixedValues=ignoreMixedValues)
251239
if val==UIAHandler.HorizontalTextAlignment_Left:
@@ -311,6 +299,70 @@ def _getFormatFieldAtRange(self,textRange,formatConfig,ignoreMixedValues=False):
311299
pass
312300
return textInfos.FieldCommand("formatChange",formatField)
313301

302+
def _getFormatFieldIndent(self, fetcher, ignoreMixedValues):
303+
"""
304+
Helper function to get indent formatting from the fetcher passed as parameter.
305+
The indent formatting is reported according to MS Word's convention.
306+
@param fetcher: the UIA fetcher used to get all formatting information.
307+
@type fetcher: L{UIATextRangeAttributeValueFetcher}
308+
@param ignoreMixedValues: If True, formatting that is mixed according to UI Automation will not be included.
309+
If False, L{UIAUtils.MixedAttributeError} will be raised if UI Automation gives back a mixed attribute
310+
value signifying that the caller may want to try again with a smaller range.
311+
@type: bool
312+
@return: The indent formatting informations corresponding to what has been retrieved via the fetcher.
313+
@rtype: L{textInfos.FormatField}
314+
"""
315+
316+
formatField = textInfos.FormatField()
317+
val = fetcher.getValue(UIAHandler.UIA_IndentationFirstLineAttributeId, ignoreMixedValues=ignoreMixedValues)
318+
uiaIndentFirstLine = val if isinstance(val, float) else None
319+
val = fetcher.getValue(UIAHandler.UIA_IndentationLeadingAttributeId, ignoreMixedValues=ignoreMixedValues)
320+
uiaIndentLeading = val if isinstance(val, float) else None
321+
val = fetcher.getValue(UIAHandler.UIA_IndentationTrailingAttributeId, ignoreMixedValues=ignoreMixedValues)
322+
uiaIndentTrailing = val if isinstance(val, float) else None
323+
if uiaIndentFirstLine is not None and uiaIndentLeading is not None:
324+
reportedFirstLineIndent = uiaIndentFirstLine - uiaIndentLeading
325+
if reportedFirstLineIndent > 0: # First line positive indent
326+
reportedLeftIndent = uiaIndentLeading
327+
reportedHangingIndent = None
328+
elif reportedFirstLineIndent < 0: # First line negative indent
329+
reportedLeftIndent = uiaIndentFirstLine
330+
reportedHangingIndent = -reportedFirstLineIndent
331+
reportedFirstLineIndent = None
332+
else:
333+
reportedLeftIndent = uiaIndentLeading
334+
reportedFirstLineIndent = None
335+
reportedHangingIndent = None
336+
if reportedLeftIndent:
337+
formatField['left-indent'] = self._getIndentValueDisplayString(reportedLeftIndent)
338+
if reportedFirstLineIndent:
339+
formatField['first-line-indent'] = self._getIndentValueDisplayString(reportedFirstLineIndent)
340+
if reportedHangingIndent:
341+
formatField['hanging-indent'] = self._getIndentValueDisplayString(reportedHangingIndent)
342+
if uiaIndentTrailing:
343+
formatField['right-indent'] = self._getIndentValueDisplayString(uiaIndentTrailing)
344+
return formatField
345+
346+
@staticmethod
347+
def _getIndentValueDisplayString(val: float) -> str:
348+
"""A function returning the string to display in formatting info.
349+
@param val: an indent value measured in points, fetched via an UIAHandler.UIA_Indentation*AttributeId attribute.
350+
@return: The string used in formatting information to report the length of an indentation.
351+
"""
352+
353+
# convert points to inches (1pt = 1/72 in)
354+
val /= 72.0
355+
if languageHandler.useImperialMeasurements():
356+
# Translators: a measurement in inches
357+
valText = _("{val:.2f} in").format(val=val)
358+
else:
359+
# Convert from inches to centimetres
360+
val *= 2.54
361+
# Translators: a measurement in centimetres
362+
valText = _("{val:.2f} cm").format(val=val)
363+
return valText
364+
365+
314366
def __init__(self,obj,position,_rangeObj=None):
315367
super(UIATextInfo,self).__init__(obj,position)
316368
if _rangeObj:

0 commit comments

Comments
 (0)