Skip to content

Commit 50f7ebf

Browse files
Merge c46af0d into d2d4bfc
2 parents d2d4bfc + c46af0d commit 50f7ebf

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

source/appModules/soffice.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
from controlTypes import TextPosition
1717
import textInfos
1818
import colors
19-
from compoundDocuments import CompoundDocument
19+
from compoundDocuments import CompoundDocument, TreeCompoundTextInfo
2020
from NVDAObjects.IAccessible import IAccessible, IA2TextTextInfo
2121
from NVDAObjects.behaviors import EditableText
2222
from logHandler import log
2323
import speech
2424
import api
2525
import braille
26+
import languageHandler
2627
import vision
2728

2829

@@ -275,6 +276,49 @@ class SymphonyParagraph(SymphonyText):
275276
value=None
276277
description=None
277278

279+
280+
def getDistanceTextForTwips(twips):
281+
"""Returns a text representation of the distance given in twips,
282+
converted to the local measurement unit."""
283+
if languageHandler.useImperialMeasurements():
284+
val = twips / 1440.0
285+
# Translators: a measurement in inches
286+
valText = _("{val:.2f} inches").format(val=val)
287+
else:
288+
val = twips * 0.0017638889
289+
# Translators: a measurement in centimetres
290+
valText = _("{val:.2f} centimetres").format(val=val)
291+
return valText
292+
293+
294+
class SymphonyDocumentTextInfo(TreeCompoundTextInfo):
295+
296+
def __init__(self, obj, position):
297+
super(SymphonyDocumentTextInfo, self).__init__(obj, position)
298+
299+
def _get_locationText(self):
300+
try:
301+
# if present, use document attributes to get cursor position relative to page
302+
docAttribs = self.obj.rootNVDAObject.IA2Attributes
303+
horizontalPos = int(docAttribs["cursor-position-in-page-horizontal"])
304+
horizontalDistanceText = getDistanceTextForTwips(horizontalPos)
305+
verticalPos = int(docAttribs["cursor-position-in-page-vertical"])
306+
verticalDistanceText = getDistanceTextForTwips(verticalPos)
307+
# Translators: LibreOffice, report cursor position in the current page
308+
return _(
309+
"cursor positioned {horizontalDistance} from left edge of page, {verticalDistance} from top edge of page"
310+
).format(horizontalDistance=horizontalDistanceText, verticalDistance=verticalDistanceText)
311+
except (AttributeError, KeyError):
312+
return super(SymphonyDocumentTextInfo, self)._get_locationText()
313+
314+
315+
class SymphonyDocument(CompoundDocument):
316+
TextInfo = SymphonyDocumentTextInfo
317+
318+
def __init__(self, rootNVDAObject):
319+
super(SymphonyDocument, self).__init__(rootNVDAObject)
320+
321+
278322
class AppModule(appModuleHandler.AppModule):
279323

280324
def chooseNVDAObjectOverlayClasses(self, obj, clsList):
@@ -301,4 +345,4 @@ def event_NVDAObject_init(self, obj):
301345
if windowClass in ("SALTMPSUBFRAME", "SALFRAME") and obj.role in (controlTypes.Role.DOCUMENT,controlTypes.Role.TEXTFRAME) and obj.description:
302346
# This is a word processor document.
303347
obj.description = None
304-
obj.treeInterceptorClass = CompoundDocument
348+
obj.treeInterceptorClass = SymphonyDocument

0 commit comments

Comments
 (0)