|
44 | 44 |
|
45 | 45 |
|
46 | 46 | 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, |
50 | 50 | } |
51 | 51 |
|
| 52 | + |
52 | 53 | class UIATextInfo(textInfos.TextInfo): |
53 | 54 |
|
54 | 55 | _cache_controlFieldNVDAObjectClass=True |
@@ -232,20 +233,7 @@ def _getFormatFieldAtRange(self,textRange,formatConfig,ignoreMixedValues=False): |
232 | 233 | if val!=UIAHandler.handler.reservedNotSupportedValue: |
233 | 234 | formatField["style"]=val |
234 | 235 | 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)) |
249 | 237 | if formatConfig["reportAlignment"]: |
250 | 238 | val=fetcher.getValue(UIAHandler.UIA_HorizontalTextAlignmentAttributeId,ignoreMixedValues=ignoreMixedValues) |
251 | 239 | if val==UIAHandler.HorizontalTextAlignment_Left: |
@@ -311,6 +299,70 @@ def _getFormatFieldAtRange(self,textRange,formatConfig,ignoreMixedValues=False): |
311 | 299 | pass |
312 | 300 | return textInfos.FieldCommand("formatChange",formatField) |
313 | 301 |
|
| 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 | + |
314 | 366 | def __init__(self,obj,position,_rangeObj=None): |
315 | 367 | super(UIATextInfo,self).__init__(obj,position) |
316 | 368 | if _rangeObj: |
|
0 commit comments