diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2023-10-18 13:44:42 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2023-10-19 10:11:23 +0200 |
commit | 2bf88c172c9c9d159344b95fb96073f4891a6c30 (patch) | |
tree | 36030f7f2e55da812bab5cdf887565b2b1be13e6 /winaccessibility | |
parent | d1d5900ca4d15caf3def78e3af8bb0d3fda98cf7 (diff) |
tdf#157696 wina11y: Switch from custom to IA2 text attributes
So far, reporting text attributes on the a11y layer on
Windows did not follow any standard/specification, but
LibreOffice's custom attribute values were mostly reported
as is (i.e. using the LibreOffice-internal attribute names
and values), and assistive tooling had to interpret those in order
to support reporting them to the user in a useful way.
For example, NVDA has custom code in the LibreOffice-specific
app module to do so. [1]
Stop using our custom attributes and switch to the
use of attributes according to the IAccessible2 text
attributes specification [2] instead, which is the applicable
specification for `IAccessibleText::get_attributes` that
is implemented here.
This implies that by reporting more IAccessible2 text attributes,
those should "automatically" work if assistive tooling handles
those, as is e.g. the case for NVDA and the the "invalid:spelling;"
attribute for spelling errors, for which bridging to IA2 has
been iplemented in
Change-Id I54e5bcbb4bef4c73068243f91a3ee69c10326460
tdf#157696 a11y: Report spelling error via IA2 "invalid:spelling" attr
(See also the other tdf#135922 commits preparing for this
change.)
A change in NVDA is still needed in addition to switch from only
handling the custom values for LO to use the existing code
path for handling IA2 text attrs instead.
Pending pull request that implents this: [3]
[1] https://github.com/nvaccess/nvda/blob/9878248c217156de4defe244d2df797d6b3bd0ca/source/appModules/soffice.py#L35-L137
[2] https://wiki.linuxfoundation.org/accessibility/iaccessible2/textattributes
[3] https://github.com/nvaccess/nvda/pull/15649
Change-Id: I11492bb5d09d64fd153db1b73d97a331a98ee535
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158090
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'winaccessibility')
-rw-r--r-- | winaccessibility/source/UAccCOM/AccTextBase.cxx | 90 |
1 files changed, 3 insertions, 87 deletions
diff --git a/winaccessibility/source/UAccCOM/AccTextBase.cxx b/winaccessibility/source/UAccCOM/AccTextBase.cxx index 37eb1d6fcf70..858504395a6f 100644 --- a/winaccessibility/source/UAccCOM/AccTextBase.cxx +++ b/winaccessibility/source/UAccCOM/AccTextBase.cxx @@ -26,6 +26,7 @@ #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> +#include <vcl/accessibility/AccessibleTextAttributeHelper.hxx> #include <vcl/svapp.hxx> #include <o3tl/char16_t2wchar_t.hxx> @@ -140,97 +141,12 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_attributes(long offset, long if (offset < 0 || offset > pRXText->getCharacterCount() ) return E_FAIL; - OUStringBuffer strAttrs("Version:1;"); - Sequence <css::beans::PropertyValue> pValues = pRXText->getCharacterAttributes(offset, Sequence<OUString>()); - int nCount = pValues.getLength(); - - sal_Int16 numberingLevel = 0; - OUString numberingPrefix; - Any anyNumRule; - bool bHaveNumberingPrefixAttr = false; - bool bHaveNumberingLevel = false; - bool bHaveNumberingRules = false; - for(int i =0; i<nCount; i++) - { - - const css::beans::PropertyValue &pValue = pValues[i]; - if(pValue.Name == "NumberingLevel") - { - if (pValue.Value != Any()) - pValue.Value >>= numberingLevel; - else - numberingLevel = -1; - bHaveNumberingLevel = true; - continue; - } - if(pValue.Name == "NumberingPrefix") - { - pValue.Value >>=numberingPrefix; - bHaveNumberingPrefixAttr = true; - continue; - } - if(pValue.Name == "NumberingRules") - { - bHaveNumberingRules = true; - anyNumRule = pValue.Value; - continue; - } - if (bHaveNumberingLevel && bHaveNumberingRules && bHaveNumberingPrefixAttr) - { - strAttrs.append(';'); - numberingPrefix = numberingPrefix.replaceAll(u"\\", u"\\\\") - .replaceAll(u";", u"\\;") - .replaceAll(u"=", u"\\=") - .replaceAll(u",", u"\\,") - .replaceAll(u":", u"\\:"); - - strAttrs.append(CMAccessible::get_String4Numbering(anyNumRule,numberingLevel,numberingPrefix)); - bHaveNumberingLevel = false; - bHaveNumberingRules = false; - } - if( (bHaveNumberingPrefixAttr && i > 1 ) || - (!bHaveNumberingPrefixAttr && i > 0 ) ) //element 0 is NumberingPrefix, not write alone - { - strAttrs.append(';'); - } - strAttrs.append(pValue.Name + ":"); - - if (pValue.Name == "CharBackColor" || - pValue.Name == "CharColor" || - pValue.Name == "CharUnderlineColor" ) - { - unsigned long nColor; - pValue.Value >>= nColor; - strAttrs.append('#'); - OUString const hex = OUString::number(nColor, 16).toAsciiUpperCase(); - for (sal_Int32 j = hex.getLength(); j < 8; ++j) { - strAttrs.append('0'); - } - strAttrs.append(hex); - } - else - { - strAttrs.append(CMAccessible::get_StringFromAny(pValue.Value)); - } - } - strAttrs.append(';'); + const OUString sAttrs = AccessibleTextAttributeHelper::GetIAccessible2TextAttributes(pRXText, offset, *startOffset, *endOffset); if(*textAttributes) SysFreeString(*textAttributes); - *textAttributes = SysAllocString(o3tl::toW(strAttrs.makeStringAndClear().getStr())); - - if (offset < pRXText->getCharacterCount()) - { - TextSegment textSeg = pRXText->getTextAtIndex(offset, AccessibleTextType::ATTRIBUTE_RUN); - *startOffset = textSeg.SegmentStart; - *endOffset = textSeg.SegmentEnd; - } - else - { - *startOffset = offset; - *endOffset = offset; - } + *textAttributes = SysAllocString(o3tl::toW(sAttrs.getStr())); return S_OK; |