summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-12-15 09:57:29 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-12-25 13:39:16 +0100
commit3776b42157461502a82b6851cd517e425e9e0818 (patch)
tree21f37414a593a976aee0ca6f3492f81853d08304
parent7a2661777bd3bdf2be3e553035b2170a2a0f97af (diff)
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
-rw-r--r--sw/source/core/access/AccessibilityCheck.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index d38bba2c19d9..66d47b00095d 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
@@ -145,6 +146,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::AccessibilityCheckResult>& rAccessibilityCheckResultCollection)
+ : NodeCheck(rAccessibilityCheckResultCollection)
+ , 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::AccessibilityCheckResult aResult;
+ OUString sNumbering = rPair.first + " " + rPair.second + "...";
+ aResult.m_aIssueText = sFakeNumbering.replaceAll("%NUMBERING%", sNumbering);
+ m_rResultCollection.push_back(aResult);
+ }
+ }
+ }
+ pPreviousTextNode = pCurrent->GetTextNode();
+ }
+ }
+};
+
// Check Shapes, TextBox
void AccessibilityCheck::checkObject(SdrObject* pObject)
{
@@ -172,6 +213,7 @@ void AccessibilityCheck::check()
std::vector<std::unique_ptr<NodeCheck>> aNodeChecks;
aNodeChecks.push_back(std::make_unique<NoTextNodeAltTextCheck>(m_aResultCollection));
aNodeChecks.push_back(std::make_unique<TableNodeMergeSplitCheck>(m_aResultCollection));
+ aNodeChecks.push_back(std::make_unique<NumberingCheck>(m_aResultCollection));
auto const& pNodes = m_pDoc->GetNodes();
SwNode* pNode = nullptr;