summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorColomban Wendling <cwendling@hypra.fr>2023-05-02 20:50:52 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2023-05-23 18:39:08 +0200
commitbd5c3582581f37513f45b518e348f443d5d57334 (patch)
tree6e9bce540afb614154d695b6e3280a198254b089 /starmath
parentdce8d2dbc48eb1c7597afec236dc51b4b8aede9c (diff)
a11y: Fix returning unpaired surrogates when retrieving characters
Fix implementations of XAccessibleText's getTextAtIndex(), getTextBeforeIndex() and getTextBehindIndex() when called with AccessibleTextType::CHARACTER to return the whole code point rather than an unpaired surrogate. This is still not perfect because XAccessibleText::getCharacterCount() will return an incorrect value (code units rather than code points), but it fixes the most useful case of retrieving the character at e.g. the caret offset. This fixes the GTK3 and Windows backends as well without further changes. Qt6 also mostly works according to Michael Weghorn, but for a bug on Qt's side (https://bugreports.qt.io/browse/QTBUG-113438). MacOS backend doesn't seem to be affected in the first place. Change-Id: I53f07bcba78c6b267939257542a521b106101e96 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151303 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/source/accessibility.cxx28
1 files changed, 18 insertions, 10 deletions
diff --git a/starmath/source/accessibility.cxx b/starmath/source/accessibility.cxx
index a2a5641cdfee..055cd0f66ef0 100644
--- a/starmath/source/accessibility.cxx
+++ b/starmath/source/accessibility.cxx
@@ -628,9 +628,12 @@ css::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextAtIndex( sa
aResult.SegmentEnd = -1;
if ( (AccessibleTextType::CHARACTER == aTextType) && (nIndex < aTxt.getLength()) )
{
- aResult.SegmentText = aTxt.copy(nIndex, 1);
+ auto nIndexEnd = nIndex;
+ aTxt.iterateCodePoints(&nIndexEnd);
+
+ aResult.SegmentText = aTxt.copy(nIndex, nIndexEnd - nIndex);
aResult.SegmentStart = nIndex;
- aResult.SegmentEnd = nIndex+1;
+ aResult.SegmentEnd = nIndexEnd;
}
return aResult;
}
@@ -647,11 +650,14 @@ css::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextBeforeIndex
aResult.SegmentStart = -1;
aResult.SegmentEnd = -1;
- if ( (AccessibleTextType::CHARACTER == aTextType) && nIndex )
+ if ( (AccessibleTextType::CHARACTER == aTextType) && nIndex > 0 )
{
- aResult.SegmentText = aTxt.copy(nIndex-1, 1);
- aResult.SegmentStart = nIndex-1;
- aResult.SegmentEnd = nIndex;
+ aTxt.iterateCodePoints(&nIndex, -1);
+ auto nIndexEnd = nIndex;
+ aTxt.iterateCodePoints(&nIndexEnd);
+ aResult.SegmentText = aTxt.copy(nIndex, nIndexEnd - nIndex);
+ aResult.SegmentStart = nIndex;
+ aResult.SegmentEnd = nIndexEnd;
}
return aResult;
}
@@ -668,12 +674,14 @@ css::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextBehindIndex
aResult.SegmentStart = -1;
aResult.SegmentEnd = -1;
- nIndex++; // text *behind*
- if ( (AccessibleTextType::CHARACTER == aTextType) && (nIndex < aTxt.getLength()) )
+ if ( (AccessibleTextType::CHARACTER == aTextType) && (nIndex + 1 < aTxt.getLength()) )
{
- aResult.SegmentText = aTxt.copy(nIndex, 1);
+ aTxt.iterateCodePoints(&nIndex);
+ auto nIndexEnd = nIndex;
+ aTxt.iterateCodePoints(&nIndexEnd);
+ aResult.SegmentText = aTxt.copy(nIndex, nIndexEnd - nIndex);
aResult.SegmentStart = nIndex;
- aResult.SegmentEnd = nIndex+1;
+ aResult.SegmentEnd = nIndexEnd;
}
return aResult;
}