summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-12-05 22:04:35 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-12-25 13:39:15 +0100
commit32c258887c11e08caadc88f8ede8a5d8ea78c0d8 (patch)
tree9867a2e1cb13051bd6def70802b5def58e7a3bac
parentAdd accessibility check to the Writer menu (diff)
downloadcore-32c258887c11e08caadc88f8ede8a5d8ea78c0d8.tar.gz
core-32c258887c11e08caadc88f8ede8a5d8ea78c0d8.zip
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
-rw-r--r--sw/Library_sw.mk1
-rw-r--r--sw/source/core/access/AccessibilityCheck.cxx75
-rw-r--r--sw/source/core/inc/AccessibilityCheck.hxx38
-rw-r--r--sw/source/uibase/shells/basesh.cxx6
4 files changed, 119 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..a464dbd3e263
--- /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();
+ AccessibilityCheckResult aResult;
+ aResult.m_aIssueText = sNoAlt.replaceAll("%OBJECT_NAME%", sName);
+ m_aAccessibilityCheckResultCollection.push_back(aResult);
+ }
+ }
+ }
+ }
+ }
+
+ // 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();
+ AccessibilityCheckResult aResult;
+ aResult.m_aIssueText = sNoAlt.replaceAll("%OBJECT_NAME%", sName);
+ m_aAccessibilityCheckResultCollection.push_back(aResult);
+ }
+ }
+ }
+ }
+}
+
+/* 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..2fcca0ce9460
--- /dev/null
+++ b/sw/source/core/inc/AccessibilityCheck.hxx
@@ -0,0 +1,38 @@
+/* -*- 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 <svx/AccessibilityCheckDialog.hxx>
+#include <doc.hxx>
+
+class AccessibilityCheck
+{
+ SwDoc* m_pDoc;
+ std::vector<AccessibilityCheckResult> m_aAccessibilityCheckResultCollection;
+
+public:
+ AccessibilityCheck(SwDoc* pDoc)
+ : m_pDoc(pDoc)
+ {
+ }
+
+ std::vector<AccessibilityCheckResult> const& getResultCollecton()
+ {
+ return m_aAccessibilityCheckResultCollection;
+ }
+
+ 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)");
}