summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-12-05 22:04:35 +0100
committerTomaž Vajngerl <quikee@gmail.com>2019-12-26 00:15:00 +0100
commit53d20484f4c9d5dc152e35a871b03d097d6ad41f (patch)
tree317b46afcb522f9f5c255a36325921afc6e7b676
parentef6e2b50376ada302958bc982e3dd73d2e0821ca (diff)
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@gmail.com>
-rw-r--r--sw/Library_sw.mk1
-rw-r--r--sw/source/core/access/AccessibilityCheck.cxx75
-rw-r--r--sw/source/core/inc/AccessibilityCheck.hxx43
-rw-r--r--sw/source/uibase/shells/basesh.cxx6
4 files changed, 124 insertions, 1 deletions
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)");
}