sw/source/core/access/AccessibilityCheck.cxx |   42 +++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

New commits:
commit 2d736e1a0a2bbd41fe7793d52bbcc7bfc89c7da3
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sun Dec 15 09:57:29 2019 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Dec 26 22:50:07 2019 +0100

    acc. check: detect fake numbering
    
    Detect fake numbering, where numbering is not done using the
    Writer integrated numbering. This is done by checking the pattern
    how the paragraphs start. If paragraph starts with "2." (for
    example) and previous paragraph starts with "1.", then this is
    possible a fake numbering.
    
    Currently checking "1.", "(1)", "1)", "a.", "a)", "(a)".
    
    Change-Id: Ibdb725d944f50208c6c951531e291183244f38e8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85847
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sw/source/core/access/AccessibilityCheck.cxx 
b/sw/source/core/access/AccessibilityCheck.cxx
index 84a4772ecba2..24f11fd0ffa3 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -24,6 +24,7 @@ namespace
 // TODO move these to string file and look for a better name.
 OUString sNoAlt("No alt text for graphic '%OBJECT_NAME%'");
 OUString sTableMergeSplit("Table '%OBJECT_NAME%' contains merges or splits");
+OUString sFakeNumbering("Fake numbering '%NUMBERING%'");
 
 class NodeCheck
 {
@@ -143,6 +144,46 @@ public:
     }
 };
 
+class NumberingCheck : public NodeCheck
+{
+private:
+    SwTextNode* pPreviousTextNode;
+
+    const std::vector<std::pair<OUString, OUString>> 
constNumberingCombinations{
+        { "1.", "2." }, { "(1)", "(2)" }, { "1)", "2)" },   { "a.", "b." }, { 
"(a)", "(b)" },
+        { "a)", "b)" }, { "A.", "B." },   { "(A)", "(B)" }, { "A)", "B)" }
+    };
+
+public:
+    NumberingCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
+        : NodeCheck(rIssueCollection)
+        , pPreviousTextNode(nullptr)
+    {
+    }
+
+    void check(SwNode* pCurrent) override
+    {
+        if (pCurrent->IsTextNode())
+        {
+            if (pPreviousTextNode)
+            {
+                for (auto& rPair : constNumberingCombinations)
+                {
+                    if 
(pCurrent->GetTextNode()->GetText().startsWith(rPair.second)
+                        && 
pPreviousTextNode->GetText().startsWith(rPair.first))
+                    {
+                        svx::AccessibilityIssue aIssue;
+                        OUString sNumbering = rPair.first + " " + rPair.second 
+ "...";
+                        aIssue.m_aIssueText = 
sFakeNumbering.replaceAll("%NUMBERING%", sNumbering);
+                        m_rIssueCollection.push_back(aIssue);
+                    }
+                }
+            }
+            pPreviousTextNode = pCurrent->GetTextNode();
+        }
+    }
+};
+
 } // end anonymous namespace
 
 // Check Shapes, TextBox
@@ -172,6 +213,7 @@ void AccessibilityCheck::check()
     std::vector<std::unique_ptr<NodeCheck>> aNodeChecks;
     
aNodeChecks.push_back(std::make_unique<NoTextNodeAltTextCheck>(m_aIssueCollection));
     
aNodeChecks.push_back(std::make_unique<TableNodeMergeSplitCheck>(m_aIssueCollection));
+    
aNodeChecks.push_back(std::make_unique<NumberingCheck>(m_aIssueCollection));
 
     auto const& pNodes = m_pDoc->GetNodes();
     SwNode* pNode = nullptr;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to