a11y: Add check for highlighted text
Add accessibility check and relevant test for a document that has
highlighted text
Change-Id: Ia4303215d9ba3eaf583b38bb5ab33f01370f1607
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141469
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <[email protected]>
diff --git a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
index 75cf071..ead35ac 100644
--- a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
+++ b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
@@ -105,6 +105,17 @@
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::HYPERLINK_IS_TEXT, aIssues[1]->m_eIssueID);
}
CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testCheckHighlightedText)
{
SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "HighlightTest.odt");
CPPUNIT_ASSERT(pDoc);
sw::AccessibilityCheck aCheck(pDoc);
aCheck.check();
auto& aIssues = aCheck.getIssueCollection().getIssues();
CPPUNIT_ASSERT_EQUAL(size_t(1), aIssues.size());
CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::TEXT_FORMATTING, aIssues[0]->m_eIssueID);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/accessibilitycheck/data/HighlightTest.odt b/sw/qa/core/accessibilitycheck/data/HighlightTest.odt
new file mode 100644
index 0000000..da48216
--- /dev/null
+++ b/sw/qa/core/accessibilitycheck/data/HighlightTest.odt
Binary files differ
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index 9195fcf..6d229fa 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -356,8 +356,8 @@
{
private:
void checkTextRange(uno::Reference<text::XTextRange> const& xTextRange,
uno::Reference<text::XTextContent> const& xParagraph,
const SwTextNode* pTextNode)
uno::Reference<text::XTextContent> const& xParagraph, SwTextNode* pTextNode,
sal_Int32 nTextStart)
{
Color nParaBackColor(COL_AUTO);
uno::Reference<beans::XPropertySet> xParagraphProperties(xParagraph, uno::UNO_QUERY);
@@ -378,9 +378,6 @@
SAL_WARN("sw.a11y", "CharColor void");
return;
}
Color aForegroundColor(ColorTransparency, nCharColor);
if (aForegroundColor == COL_AUTO)
return;
const SwPageDesc* pPageDescription = pTextNode->FindPageDesc();
const SwFrameFormat& rPageFormat = pPageDescription->GetMaster();
@@ -411,6 +408,22 @@
// If not character background color, try paragraph background color
if (aBackgroundColor == COL_AUTO)
aBackgroundColor = nParaBackColor;
else
{
auto pIssue
= lclAddIssue(m_rIssueCollection, SwResId(STR_TEXT_FORMATTING_CONVEYS_MEANING),
sfx::AccessibilityIssueID::TEXT_FORMATTING);
pIssue->setIssueObject(IssueObject::TEXT);
pIssue->setNode(pTextNode);
SwDoc& rDocument = pTextNode->GetDoc();
pIssue->setDoc(rDocument);
pIssue->setStart(nTextStart);
pIssue->setEnd(nTextStart + xTextRange->getString().getLength());
}
Color aForegroundColor(ColorTransparency, nCharColor);
if (aForegroundColor == COL_AUTO)
return;
// If not paragraph background color, try page color
if (aBackgroundColor == COL_AUTO)
@@ -446,11 +459,15 @@
uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParagraph, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
sal_Int32 nStart = 0;
while (xRunEnum->hasMoreElements())
{
uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), uno::UNO_QUERY);
if (xRun.is())
checkTextRange(xRun, xParagraph, pTextNode);
{
checkTextRange(xRun, xParagraph, pTextNode, nStart);
nStart += xRun->getString().getLength();
}
}
}
};