diff --git a/include/sfx2/AccessibilityIssue.hxx b/include/sfx2/AccessibilityIssue.hxx index ac9ad6adb73b..92bef3d7d6a2 100644 --- a/include/sfx2/AccessibilityIssue.hxx +++ b/include/sfx2/AccessibilityIssue.hxx @@ -27,6 +27,7 @@ enum class AccessibilityIssueID DOCUMENT_LANGUAGE, DOCUMENT_BACKGROUND, STYLE_LANGUAGE, + LINKED_GRAPHIC, NO_ALT_OLE, NO_ALT_GRAPHIC, NO_ALT_SHAPE, diff --git a/sw/inc/AccessibilityCheckStrings.hrc b/sw/inc/AccessibilityCheckStrings.hrc index 44dd7217dc04..8073f9cc1c73 100644 --- a/sw/inc/AccessibilityCheckStrings.hrc +++ b/sw/inc/AccessibilityCheckStrings.hrc @@ -14,6 +14,7 @@ #define NC_(Context, String) TranslateId(Context, u8##String) #define STR_NO_ALT NC_("STR_NO_ALT", "%OBJECT_NAME%") +#define STR_LINKED_GRAPHIC NC_("STR_LINKED_GRAPHIC", "“%OBJECT_NAME%” referenced as “%LINK%”.") #define STR_TABLE_MERGE_SPLIT NC_("STR_TABLE_MERGE_SPLIT", "Table “%OBJECT_NAME%” contains merges or splits.") #define STR_FAKE_NUMBERING NC_("STR_FAKE_NUMBERING", "Simulated numbering “%NUMBERING%”.") #define STR_HYPERLINK_TEXT_IS_LINK NC_("STR_HYPERLINK_TEXT_IS_LINK", "Hyperlink text is the same as the link address “%LINK%”.") diff --git a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx index 72337e62d6e0..117b48d01661 100644 --- a/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx +++ b/sw/qa/core/accessibilitycheck/AccessibilityCheckTest.cxx @@ -84,6 +84,18 @@ CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testCheckBackgroundImage) CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::DOCUMENT_BACKGROUND, aIssues[0]->m_eIssueID); } +CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testCheckLinkedImage) +{ + createSwDoc("LinkedImageTest.fodt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + sw::AccessibilityCheck aCheck(pDoc); + aCheck.check(); + auto& aIssues = aCheck.getIssueCollection().getIssues(); + CPPUNIT_ASSERT_EQUAL(size_t(4), aIssues.size()); + CPPUNIT_ASSERT_EQUAL(sfx::AccessibilityIssueID::LINKED_GRAPHIC, aIssues[1]->m_eIssueID); +} + CPPUNIT_TEST_FIXTURE(AccessibilityCheckTest, testCheckNewlineSpace) { createSwDoc("NewlineTest.odt"); diff --git a/sw/qa/core/accessibilitycheck/data/LinkedImageTest.fodt b/sw/qa/core/accessibilitycheck/data/LinkedImageTest.fodt new file mode 100644 index 000000000000..c73162b18372 --- /dev/null +++ b/sw/qa/core/accessibilitycheck/data/LinkedImageTest.fodt @@ -0,0 +1,18 @@ + + + + + Linked graphic + + + Embedded graphic + + R0lGODlhAgACAPABAAAAAP///yH5BAAAAAAAIf4tIFRoaXMgaXMgYW4gZXhhbXBsZSBiaXRt + YXAgb2YgdGhlIGxldHRlciAiSiIKACH/C0ltYWdlTWFnaWNrDmdhbW1hPTAuNDU0NTQ1ACwA + AAAAAgACAAACA0QCBQA7 + + + + + + diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx index 63443bcb89bd..2e3219765e22 100644 --- a/sw/source/core/access/AccessibilityCheck.cxx +++ b/sw/source/core/access/AccessibilityCheck.cxx @@ -44,6 +44,9 @@ #include #include #include +#include +#include +#include namespace sw { @@ -98,13 +101,46 @@ class NoTextNodeAltTextCheck : public NodeCheck if (!pNoTextNode) return; - if (!pNoTextNode->GetTitle().isEmpty() || !pNoTextNode->GetDescription().isEmpty()) - return; - const SwFrameFormat* pFrameFormat = pNoTextNode->GetFlyFormat(); if (!pFrameFormat) return; + // linked graphic with broken link + if (pNoTextNode->IsGrfNode() && pNoTextNode->GetGrfNode()->IsLinkedFile()) + { + OUString sURL(pNoTextNode->GetGrfNode()->GetGraphic().getOriginURL()); + if (!FStatHelper::IsDocument(sURL)) + { + INetURLObject aURL(sURL); + OUString aSystemPath = sURL; + + // abbreviate URL + if (aURL.GetProtocol() == INetProtocol::File) + { + OUString aAbbreviatedPath; + aSystemPath = aURL.getFSysPath(FSysStyle::Detect); + osl_abbreviateSystemPath(aSystemPath.pData, &aAbbreviatedPath.pData, 46, + nullptr); + sURL = aAbbreviatedPath; + } + + OUString sIssueText = SwResId(STR_LINKED_GRAPHIC) + .replaceAll("%OBJECT_NAME%", pFrameFormat->GetName()) + .replaceFirst("%LINK%", sURL); + + auto pIssue = lclAddIssue(m_rIssueCollection, sIssueText, + sfx::AccessibilityIssueID::LINKED_GRAPHIC); + pIssue->setDoc(pNoTextNode->GetDoc()); + pIssue->setIssueObject(IssueObject::LINKED); + pIssue->setObjectID(pNoTextNode->GetFlyFormat()->GetName()); + pIssue->setNode(pNoTextNode); + pIssue->setAdditionalInfo({ aSystemPath }); + } + } + + if (!pNoTextNode->GetTitle().isEmpty() || !pNoTextNode->GetDescription().isEmpty()) + return; + OUString sIssueText = SwResId(STR_NO_ALT).replaceAll("%OBJECT_NAME%", pFrameFormat->GetName()); diff --git a/sw/source/core/access/AccessibilityIssue.cxx b/sw/source/core/access/AccessibilityIssue.cxx index d3a4a1754240..075fa15ceb51 100644 --- a/sw/source/core/access/AccessibilityIssue.cxx +++ b/sw/source/core/access/AccessibilityIssue.cxx @@ -78,6 +78,7 @@ void AccessibilityIssue::gotoIssue() const switch (TempIssueObject.m_eIssueObject) { + case IssueObject::LINKED: case IssueObject::GRAPHIC: case IssueObject::OLE: case IssueObject::TEXTFRAME: diff --git a/sw/source/core/inc/AccessibilityIssue.hxx b/sw/source/core/inc/AccessibilityIssue.hxx index 151d565399f1..5fe9857b9941 100644 --- a/sw/source/core/inc/AccessibilityIssue.hxx +++ b/sw/source/core/inc/AccessibilityIssue.hxx @@ -31,6 +31,7 @@ enum class IssueObject LANGUAGE_NOT_SET, FOOTENDNOTE, TEXTFRAME, + LINKED, }; class SW_DLLPUBLIC AccessibilityIssue final : public sfx::AccessibilityIssue diff --git a/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx index 338b0f1f7cac..a1907c9b6306 100644 --- a/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx +++ b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.cxx @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -44,17 +45,25 @@ AccessibilityCheckEntry::AccessibilityCheckEntry( { m_xGotoButton->set_label(m_pAccessibilityIssue->m_aIssueText); - // int nPrefWidth(m_xGotoButton->get_preferred_size().Width()); + // tdf#156137 allow LinkButton label to wrap int nMaxWidth = m_xGotoButton->get_approximate_digit_width() * 10; - // if (nPrefWidth > nMaxWidth) - { - // tdf#156137 allow LinkButton label to wrap - m_xGotoButton->set_label_wrap(true); - m_xGotoButton->set_size_request(nMaxWidth, -1); - } + m_xGotoButton->set_label_wrap(true); + m_xGotoButton->set_size_request(nMaxWidth, -1); m_xGotoButton->connect_activate_link( LINK(this, AccessibilityCheckEntry, GotoButtonClicked)); + + // add full path of linked graphic as tooltip, + if (m_pAccessibilityIssue->m_eIssueID == sfx::AccessibilityIssueID::LINKED_GRAPHIC) + { + auto pSwIssue = std::static_pointer_cast(m_pAccessibilityIssue); + auto aInfo = pSwIssue->getAdditionalInfo(); + if (aInfo.size() > 0) + { + m_xGotoButton->set_tooltip_text(aInfo[0]); + } + } + m_xLabel->set_visible(false); } else @@ -93,6 +102,7 @@ A11yCheckIssuesPanel::A11yCheckIssuesPanel(weld::Widget* pParent, SfxBindings* p : PanelLayout(pParent, "A11yCheckIssuesPanel", "modules/swriter/ui/a11ycheckissuespanel.ui") , m_xExpanderDocument(m_xBuilder->weld_expander("expand_document")) , m_xExpanderStyles(m_xBuilder->weld_expander("expand_styles")) + , m_xExpanderLinked(m_xBuilder->weld_expander("expand_linked")) , m_xExpanderNoAlt(m_xBuilder->weld_expander("expand_no_alt")) , m_xExpanderTable(m_xBuilder->weld_expander("expand_table")) , m_xExpanderFormatting(m_xBuilder->weld_expander("expand_formatting")) @@ -102,6 +112,7 @@ A11yCheckIssuesPanel::A11yCheckIssuesPanel(weld::Widget* pParent, SfxBindings* p , m_xExpanderOther(m_xBuilder->weld_expander("expand_other")) , m_xBoxDocument(m_xBuilder->weld_box("box_document")) , m_xBoxStyles(m_xBuilder->weld_box("box_styles")) + , m_xBoxLinked(m_xBuilder->weld_box("box_linked")) , m_xBoxNoAlt(m_xBuilder->weld_box("box_no_alt")) , m_xBoxTable(m_xBuilder->weld_box("box_table")) , m_xBoxFormatting(m_xBuilder->weld_box("box_formatting")) @@ -149,6 +160,7 @@ void A11yCheckIssuesPanel::ImplDestroy() } m_xExpanderDocument.reset(); m_xExpanderStyles.reset(); + m_xExpanderLinked.reset(); m_xExpanderNoAlt.reset(); m_xExpanderTable.reset(); m_xExpanderFormatting.reset(); @@ -158,6 +170,7 @@ void A11yCheckIssuesPanel::ImplDestroy() m_xExpanderOther.reset(); m_xBoxDocument.reset(); m_xBoxStyles.reset(); + m_xBoxLinked.reset(); m_xBoxNoAlt.reset(); m_xBoxTable.reset(); m_xBoxFormatting.reset(); @@ -179,6 +192,10 @@ void A11yCheckIssuesPanel::removeOldWidgets() m_xBoxStyles->move(xEntry->get_widget(), nullptr); m_xExpanderStyles->set_visible(false); + for (auto const& xEntry : m_aLinkedEntries) + m_xBoxLinked->move(xEntry->get_widget(), nullptr); + m_xExpanderLinked->set_visible(false); + for (auto const& xEntry : m_aNoAltEntries) m_xBoxNoAlt->move(xEntry->get_widget(), nullptr); m_xExpanderNoAlt->set_visible(false); @@ -220,6 +237,7 @@ void A11yCheckIssuesPanel::populateIssues() sal_Int32 iDocument = 0; sal_Int32 iStyles = 0; + sal_Int32 iLinked = 0; sal_Int32 iNoAlt = 0; sal_Int32 iTable = 0; sal_Int32 iFormatting = 0; @@ -250,6 +268,14 @@ void A11yCheckIssuesPanel::populateIssues() m_aStylesEntries.push_back(std::move(xEntry)); } break; + case sfx::AccessibilityIssueID::LINKED_GRAPHIC: + { + auto xEntry = std::make_unique(m_xBoxLinked.get(), pIssue); + m_xBoxLinked->reorder_child(xEntry->get_widget(), iLinked++); + m_xExpanderLinked->set_visible(true); + m_aLinkedEntries.push_back(std::move(xEntry)); + } + break; case sfx::AccessibilityIssueID::NO_ALT_OLE: case sfx::AccessibilityIssueID::NO_ALT_GRAPHIC: case sfx::AccessibilityIssueID::NO_ALT_SHAPE: diff --git a/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx index 41e769946b72..7f569e16ef85 100644 --- a/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx +++ b/sw/source/uibase/sidebar/A11yCheckIssuesPanel.hxx @@ -62,6 +62,7 @@ public: private: std::vector> m_aDocumentEntries; std::vector> m_aStylesEntries; + std::vector> m_aLinkedEntries; std::vector> m_aNoAltEntries; std::vector> m_aTableEntries; std::vector> m_aFormattingEntries; @@ -71,6 +72,7 @@ private: std::vector> m_aOtherEntries; std::unique_ptr m_xExpanderDocument; std::unique_ptr m_xExpanderStyles; + std::unique_ptr m_xExpanderLinked; std::unique_ptr m_xExpanderNoAlt; std::unique_ptr m_xExpanderTable; std::unique_ptr m_xExpanderFormatting; @@ -80,6 +82,7 @@ private: std::unique_ptr m_xExpanderOther; std::unique_ptr m_xBoxDocument; std::unique_ptr m_xBoxStyles; + std::unique_ptr m_xBoxLinked; std::unique_ptr m_xBoxNoAlt; std::unique_ptr m_xBoxTable; std::unique_ptr m_xBoxFormatting; diff --git a/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui b/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui index cef9c692178f..6657b8c80c4b 100644 --- a/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui +++ b/sw/uiconfig/swriter/ui/a11ycheckissuespanel.ui @@ -77,6 +77,36 @@ 1 + + + True + True + + + True + False + 6 + True + vertical + + + + + + + + True + False + Missing linked graphic + + + + + False + True + 2 + + True @@ -104,7 +134,7 @@ False True - 2 + 3 @@ -133,7 +163,7 @@ False True - 3 + 4 @@ -162,7 +192,7 @@ False True - 4 + 5 @@ -191,7 +221,7 @@ False True - 5 + 6 @@ -220,7 +250,7 @@ False True - 6 + 7 @@ -249,7 +279,7 @@ False True - 7 + 8 @@ -278,7 +308,7 @@ False True - 8 + 9