[Libreoffice-commits] core.git: sw/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Fri Dec 27 21:56:39 UTC 2019


 sw/source/core/access/AccessibilityCheck.cxx |   76 +++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 3 deletions(-)

New commits:
commit 77e7d43c67c69dcc1cba574c04773b3cca1794b1
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Dec 15 10:19:24 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Dec 27 22:56:07 2019 +0100

    acc. check: check document default language and style language
    
    This checks hat the defualt language of the document is set and
    in addition that the used styles also have the default language
    set. Accessibility requires the language always be set.
    
    Change-Id: I6ea36e6e8b30289cdb35311da9470f856a847b38
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85854
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
index 400e4edd5087..e9cb9e898326 100644
--- a/sw/source/core/access/AccessibilityCheck.cxx
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -19,6 +19,8 @@
 #include <com/sun/star/text/XTextContent.hpp>
 #include <unoparagraph.hxx>
 #include <tools/urlobj.hxx>
+#include <editeng/langitem.hxx>
+#include <charatr.hxx>
 
 namespace sw
 {
@@ -29,18 +31,30 @@ OUString sNoAlt("No alt text for graphic '%OBJECT_NAME%'");
 OUString sTableMergeSplit("Table '%OBJECT_NAME%' contains merges or splits");
 OUString sFakeNumbering("Fake numbering '%NUMBERING%'");
 OUString sHyperlinkTextIsLink("Hyperlink text is the same as the link address '%LINK%'");
+OUString sDocumentDefaultLanguage("Document default language is not set");
+OUString sStyleNoLanguage("Style '%STYLE_NAME%' has no language set");
 
-class NodeCheck
+class BaseCheck
 {
 protected:
     std::vector<svx::AccessibilityIssue>& m_rIssueCollection;
 
 public:
-    NodeCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
+    BaseCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
         : m_rIssueCollection(rIssueCollection)
     {
     }
-    virtual ~NodeCheck() {}
+    virtual ~BaseCheck() {}
+};
+
+class NodeCheck : public BaseCheck
+{
+public:
+    NodeCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
+        : BaseCheck(rIssueCollection)
+    {
+    }
+
     virtual void check(SwNode* pCurrent) = 0;
 };
 
@@ -243,6 +257,54 @@ public:
     }
 };
 
+class DocumentCheck : public BaseCheck
+{
+public:
+    DocumentCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
+        : BaseCheck(rIssueCollection)
+    {
+    }
+
+    virtual void check(SwDoc* pDoc) = 0;
+};
+
+// Check default language
+class DocumentDefaultLanguageCheck : public DocumentCheck
+{
+public:
+    DocumentDefaultLanguageCheck(std::vector<svx::AccessibilityIssue>& rIssueCollection)
+        : DocumentCheck(rIssueCollection)
+    {
+    }
+
+    void check(SwDoc* pDoc) override
+    {
+        // TODO maybe - also check RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE if CJK or CTL are enabled
+        const SvxLanguageItem& rLang = pDoc->GetDefault(RES_CHRATR_LANGUAGE);
+        LanguageType eLanguage = rLang.GetLanguage();
+        if (eLanguage == LANGUAGE_NONE)
+        {
+            svx::AccessibilityIssue aIssue;
+            aIssue.m_aIssueText = sDocumentDefaultLanguage;
+            m_rIssueCollection.push_back(aIssue);
+        }
+        else
+        {
+            for (SwTextFormatColl* pTextFormatCollection : *pDoc->GetTextFormatColls())
+            {
+                const SwAttrSet& rAttrSet = pTextFormatCollection->GetAttrSet();
+                if (rAttrSet.GetLanguage(false).GetLanguage() == LANGUAGE_NONE)
+                {
+                    svx::AccessibilityIssue aIssue;
+                    OUString sName = pTextFormatCollection->GetName();
+                    aIssue.m_aIssueText = sStyleNoLanguage.replaceAll("%STYLE_NAME%", sName);
+                    m_rIssueCollection.push_back(aIssue);
+                }
+            }
+        }
+    }
+};
+
 } // end anonymous namespace
 
 // Check Shapes, TextBox
@@ -269,6 +331,14 @@ void AccessibilityCheck::check()
     if (m_pDoc == nullptr)
         return;
 
+    std::vector<std::unique_ptr<DocumentCheck>> aDocumentChecks;
+    aDocumentChecks.push_back(std::make_unique<DocumentDefaultLanguageCheck>(m_aIssueCollection));
+
+    for (std::unique_ptr<DocumentCheck>& rpDocumentCheck : aDocumentChecks)
+    {
+        rpDocumentCheck->check(m_pDoc);
+    }
+
     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));


More information about the Libreoffice-commits mailing list