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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Dec 25 23:15:30 UTC 2019


 sw/Library_sw.mk                             |    1 
 sw/source/core/access/AccessibilityCheck.cxx |   75 +++++++++++++++++++++++++++
 sw/source/core/inc/AccessibilityCheck.hxx    |   43 +++++++++++++++
 sw/source/uibase/shells/basesh.cxx           |    6 +-
 4 files changed, 124 insertions(+), 1 deletion(-)

New commits:
commit 53d20484f4c9d5dc152e35a871b03d097d6ad41f
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Dec 5 22:04:35 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Dec 26 00:15:00 2019 +0100

    Accessibility check base functionality
    
    This adds AccessibilityCheck class to writer, which perfors the
    accessibility check of the current document to make the document
    conform to PDF/UA requirements.
    
    The first check this adds is check for the "alt" (sometimes also
    called "title") to be present for graphics, OLE objects (charts)
    and shapes.
    
    Change-Id: I98dcca787099bdb17cab9291546074cdde2ae5a8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85820
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 7999ece93c3d..acab4210994b 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -95,6 +95,7 @@ $(eval $(call gb_Library_use_externals,sw,\
 $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/core/SwNumberTree/SwNodeNum \
     sw/source/core/SwNumberTree/SwNumberTree \
+    sw/source/core/access/AccessibilityCheck \
     sw/source/core/access/acccell \
     sw/source/core/access/acccontext \
     sw/source/core/access/accdoc \
diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx
new file mode 100644
index 000000000000..64c51e131d45
--- /dev/null
+++ b/sw/source/core/access/AccessibilityCheck.cxx
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <AccessibilityCheck.hxx>
+#include <ndgrf.hxx>
+#include <ndole.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <drawdoc.hxx>
+#include <svx/svdpage.hxx>
+
+void AccessibilityCheck::check()
+{
+    if (m_pDoc == nullptr)
+        return;
+
+    OUString sNoAlt("No alt text for graphic '%OBJECT_NAME%'");
+
+    // Check NoTextNodes: Graphic, OLE
+    auto const& pNodes = m_pDoc->GetNodes();
+    for (sal_uLong n = 0; n < pNodes.Count(); ++n)
+    {
+        SwNode* pNode = pNodes[n];
+        if (pNode)
+        {
+            if (pNode->GetNodeType() & SwNodeType::NoTextMask)
+            {
+                SwNoTextNode* pNoTextNode = pNode->GetNoTextNode();
+                if (pNoTextNode)
+                {
+                    OUString sAlternative = pNoTextNode->GetTitle();
+                    if (sAlternative.isEmpty())
+                    {
+                        OUString sName = pNoTextNode->GetFlyFormat()->GetName();
+                        AccessibilityIssue aIssue;
+                        aIssue.m_aIssueText = sNoAlt.replaceAll("%OBJECT_NAME%", sName);
+                        m_aAccessibilityIssueCollection.push_back(aIssue);
+                    }
+                }
+            }
+        }
+    }
+
+    // Check Shapes, TextBox
+    IDocumentDrawModelAccess& rDrawModelAccess = m_pDoc->getIDocumentDrawModelAccess();
+    auto* pModel = rDrawModelAccess.GetDrawModel();
+    for (sal_uInt16 nPage = 0; nPage < pModel->GetPageCount(); ++nPage)
+    {
+        SdrPage* pPage = pModel->GetPage(nPage);
+        for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject)
+        {
+            SdrObject* pObject = pPage->GetObj(nObject);
+            if (pObject->GetObjIdentifier() == OBJ_CUSTOMSHAPE
+                || pObject->GetObjIdentifier() == OBJ_TEXT)
+            {
+                OUString sAlternative = pObject->GetTitle();
+                if (sAlternative.isEmpty())
+                {
+                    OUString sName = pObject->GetName();
+                    AccessibilityIssue aIssue;
+                    aIssue.m_aIssueText = sNoAlt.replaceAll("%OBJECT_NAME%", sName);
+                    m_aAccessibilityIssueCollection.push_back(aIssue);
+                }
+            }
+        }
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/AccessibilityCheck.hxx b/sw/source/core/inc/AccessibilityCheck.hxx
new file mode 100644
index 000000000000..800f6cb9da2f
--- /dev/null
+++ b/sw/source/core/inc/AccessibilityCheck.hxx
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_SW_SOURCE_CORE_ACCESSIBILITYCHECK_HXX
+#define INCLUDED_SW_SOURCE_CORE_ACCESSIBILITYCHECK_HXX
+
+#include <doc.hxx>
+
+class AccessibilityIssue
+{
+public:
+    OUString m_aIssueText;
+};
+
+class AccessibilityCheck
+{
+    SwDoc* m_pDoc;
+    std::vector<AccessibilityIssue> m_aAccessibilityIssueCollection;
+
+public:
+    AccessibilityCheck(SwDoc* pDoc)
+        : m_pDoc(pDoc)
+    {
+    }
+
+    std::vector<AccessibilityIssue> const& getIssueCollecton()
+    {
+        return m_aAccessibilityIssueCollection;
+    }
+
+    void check();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index d7f19331e1f7..80514a60aeb7 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -140,6 +140,7 @@ static sal_uInt8 nFooterPos;
 #include <sfx2/msg.hxx>
 #include <swslots.hxx>
 
+#include <AccessibilityCheck.hxx>
 namespace
 {
     SvxContourDlg* GetContourDlg(SwView const &rView)
@@ -2677,7 +2678,10 @@ void SwBaseShell::ExecDlg(SfxRequest &rReq)
         }
         break;
         case SID_ACCESSIBILITY_CHECK:
-        {}
+        {
+            AccessibilityCheck aCheck(rSh.GetDoc());
+            aCheck.check();
+        }
         break;
         default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
     }


More information about the Libreoffice-commits mailing list