sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx |   11 +++++
 sw/qa/core/accessibilitycheck/data/HighlightTest.odt     |binary
 sw/source/core/access/AccessibilityCheck.cxx             |   29 +++++++++++----
 3 files changed, 34 insertions(+), 6 deletions(-)

New commits:
commit 043f0b53aa1734af17fd12a5b07075d965f28730
Author:     Paris Oplopoios <paris.oplopo...@collabora.com>
AuthorDate: Mon Oct 17 19:32:47 2022 +0300
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Oct 21 08:53:46 2022 +0200

    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 <qui...@gmail.com>

diff --git a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx 
b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
index 75cf071c1e69..ead35acfb4ca 100644
--- a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
+++ b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx
@@ -105,6 +105,17 @@ CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, 
testHyperlinks)
     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 000000000000..da4821681502
Binary files /dev/null and 
b/sw/qa/core/accessibilitycheck/data/HighlightTest.odt differ
diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 9195fcfcbd52..6d229fa40a16 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -356,8 +356,8 @@ class TextContrastCheck : public NodeCheck
 {
 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 @@ private:
             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 @@ private:
         // 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 @@ public:
 
         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();
+            }
         }
     }
 };

Reply via email to