summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorParis Oplopoios <paris.oplopoios@collabora.com>2022-10-24 14:12:44 +0300
committerTomaž Vajngerl <quikee@gmail.com>2022-11-09 23:54:58 +0100
commit3c0be5564afe1b9cc843a49aba88b72af74c43ab (patch)
treee071abd91735906b01d2e3a0aacae46eca387381 /sw/source
parent2e55962e5d07e425560592b016baff4964436be0 (diff)
a11y: Add check for tabs used for formatting
Add accessibility check and relevant test for a document that uses tabs for formatting Useful to detect fake tables made of tabs Change-Id: Ief765f25c8dc67405d0671e257cf0ba7aec9f16c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141732 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/access/AccessibilityCheck.cxx68
1 files changed, 49 insertions, 19 deletions
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index ce0409d6ba5b..897ee0d43c58 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -791,33 +791,63 @@ public:
const OUString& sParagraphText = pTextNode->GetText();
sal_Int32 nSpaceCount = 0;
sal_Int32 nSpaceStart = 0;
+ sal_Int32 nTabCount = 0;
bool bNonSpaceFound = false;
+ bool bPreviousWasChar = false;
for (sal_Int32 i = 0; i < nParagraphLength; i++)
{
- if (sParagraphText[i] == ' ')
+ switch (sParagraphText[i])
{
- if (bNonSpaceFound)
+ case ' ':
{
- nSpaceCount++;
- if (nSpaceCount == 2)
- nSpaceStart = i;
+ if (bNonSpaceFound)
+ {
+ nSpaceCount++;
+ if (nSpaceCount == 2)
+ nSpaceStart = i;
+ }
+ break;
}
- }
- else
- {
- if (nSpaceCount >= 2)
+ case '\t':
{
- auto pIssue = lclAddIssue(m_rIssueCollection, SwResId(STR_AVOID_SPACES_SPACE),
- sfx::AccessibilityIssueID::TEXT_FORMATTING);
- pIssue->setIssueObject(IssueObject::TEXT);
- pIssue->setNode(pTextNode);
- SwDoc& rDocument = pTextNode->GetDoc();
- pIssue->setDoc(rDocument);
- pIssue->setStart(nSpaceStart);
- pIssue->setEnd(nSpaceStart + nSpaceCount - 1);
+ if (bPreviousWasChar)
+ {
+ ++nTabCount;
+ bPreviousWasChar = false;
+ if (nTabCount == 2)
+ {
+ auto pIssue = lclAddIssue(m_rIssueCollection,
+ SwResId(STR_AVOID_TABS_FORMATTING),
+ sfx::AccessibilityIssueID::TEXT_FORMATTING);
+ pIssue->setIssueObject(IssueObject::TEXT);
+ pIssue->setNode(pTextNode);
+ SwDoc& rDocument = pTextNode->GetDoc();
+ pIssue->setDoc(rDocument);
+ pIssue->setStart(0);
+ pIssue->setEnd(nParagraphLength);
+ }
+ }
+ break;
+ }
+ default:
+ {
+ if (nSpaceCount >= 2)
+ {
+ auto pIssue
+ = lclAddIssue(m_rIssueCollection, SwResId(STR_AVOID_SPACES_SPACE),
+ sfx::AccessibilityIssueID::TEXT_FORMATTING);
+ pIssue->setIssueObject(IssueObject::TEXT);
+ pIssue->setNode(pTextNode);
+ SwDoc& rDocument = pTextNode->GetDoc();
+ pIssue->setDoc(rDocument);
+ pIssue->setStart(nSpaceStart);
+ pIssue->setEnd(nSpaceStart + nSpaceCount - 1);
+ }
+ bNonSpaceFound = true;
+ bPreviousWasChar = true;
+ nSpaceCount = 0;
+ break;
}
- bNonSpaceFound = true;
- nSpaceCount = 0;
}
}
}