From bdfa6b678bc0cc22f983a0c23187a8ba9d2e6730 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 15 Aug 2019 15:47:42 +0200 Subject: embeddedobj: allow controlling if PDF documents are converted to Draw or not This is a bit custom, since it's not a Microsoft filter. At the moment this affects only Insert -> Object -> OLE Object -> from file. Change-Id: If79602742a533db1b04e11a90890f8768186046d Reviewed-on: https://gerrit.libreoffice.org/77520 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- cui/inc/strings.hrc | 1 + cui/source/options/optfltr.cxx | 26 +++++++++++++++- cui/source/options/optfltr.hxx | 3 +- embeddedobj/qa/cppunit/data/insert-file-config.pdf | Bin 0 -> 11157 bytes embeddedobj/qa/cppunit/general.cxx | 33 +++++++++++++++++++++ embeddedobj/source/general/xcreator.cxx | 7 +++++ .../schema/org/openoffice/Office/Common.xcs | 17 +++++++++++ 7 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 embeddedobj/qa/cppunit/data/insert-file-config.pdf diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc index e6edf6cca478..9b70cbf55301 100644 --- a/cui/inc/strings.hrc +++ b/cui/inc/strings.hrc @@ -257,6 +257,7 @@ #define RID_SVXSTR_CHG_IMPRESS NC_("RID_SVXSTR_CHG_IMPRESS", "PowerPoint to %PRODUCTNAME Impress or reverse") #define RID_SVXSTR_CHG_SMARTART NC_("RID_SVXSTR_CHG_SMARTART", "SmartArt to %PRODUCTNAME shapes or reverse") #define RID_SVXSTR_CHG_VISIO NC_("RID_SVXSTR_CHG_VISIO", "Visio to %PRODUCTNAME Draw or reverse") +#define RID_SVXSTR_CHG_PDF NC_("RID_SVXSTR_CHG_PDF", "PDF to %PRODUCTNAME Draw or reverse") #define RID_SVXSTR_OPT_DOUBLE_DICTS NC_("RID_SVXSTR_OPT_DOUBLE_DICTS", "The specified name already exists.\nPlease enter a new name.") #define RID_SVXSTR_OPT_INVALID_DICT_NAME NC_("RID_SVXSTR_OPT_INVALID_DICT_NAME", "The specified name is invalid.\nPlease enter a new name.") diff --git a/cui/source/options/optfltr.cxx b/cui/source/options/optfltr.cxx index 925c0c7981d4..85abc803b07e 100644 --- a/cui/source/options/optfltr.cxx +++ b/cui/source/options/optfltr.cxx @@ -35,6 +35,7 @@ enum class MSFltrPg2_CheckBoxEntries { Impress, SmartArt, Visio, + PDF, InvalidCBEntry }; @@ -134,6 +135,7 @@ OfaMSFilterTabPage2::OfaMSFilterTabPage2(TabPageParent pParent, const SfxItemSet , sChgToFromImpress(CuiResId(RID_SVXSTR_CHG_IMPRESS)) , sChgToFromSmartArt(CuiResId(RID_SVXSTR_CHG_SMARTART)) , sChgToFromVisio(CuiResId(RID_SVXSTR_CHG_VISIO)) + , sChgToFromPDF(CuiResId(RID_SVXSTR_CHG_PDF)) , m_xCheckLB(m_xBuilder->weld_tree_view("checklbcontainer")) , m_xHighlightingRB(m_xBuilder->weld_radio_button("highlighting")) , m_xShadingRB(m_xBuilder->weld_radio_button("shading")) @@ -209,6 +211,15 @@ bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* ) bFirstCol = !bFirstCol; } } + int nPDFEntry = GetEntry4Type(MSFltrPg2_CheckBoxEntries::PDF); + bool bPDFCheck = m_xCheckLB->get_toggle(nPDFEntry, 0); + if (bPDFCheck != officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get()) + { + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(bPDFCheck, pBatch); + pBatch->commit(); + } if( m_xHighlightingRB->get_state_changed_from_saved() ) { @@ -246,7 +257,10 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) InsertEntry( sChgToFromImpress, MSFltrPg2_CheckBoxEntries::Impress ); InsertEntry( sChgToFromSmartArt, MSFltrPg2_CheckBoxEntries::SmartArt, false ); if (aModuleOpt.IsModuleInstalled(SvtModuleOptions::EModule::DRAW)) + { InsertEntry(sChgToFromVisio, MSFltrPg2_CheckBoxEntries::Visio, false); + InsertEntry(sChgToFromPDF, MSFltrPg2_CheckBoxEntries::PDF, false); + } static struct ChkCBoxEntries{ MSFltrPg2_CheckBoxEntries eType; @@ -262,6 +276,7 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) { MSFltrPg2_CheckBoxEntries::Impress, &SvtFilterOptions::IsImpress2PowerPoint }, { MSFltrPg2_CheckBoxEntries::SmartArt, &SvtFilterOptions::IsSmartArt2Shape }, { MSFltrPg2_CheckBoxEntries::Visio, &SvtFilterOptions::IsVisio2Draw }, + { MSFltrPg2_CheckBoxEntries::PDF, nullptr }, }; bool bFirstCol = true; @@ -275,7 +290,16 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) int nEntry = GetEntry4Type( rArr.eType ); if (nEntry != -1) { - bool bCheck = (rOpt.*rArr.FnIs)(); + bool bCheck = false; + if (rArr.eType != MSFltrPg2_CheckBoxEntries::PDF) + { + bCheck = (rOpt.*rArr.FnIs)(); + } + else + { + bCheck = officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get(); + nCol = 0; + } m_xCheckLB->set_toggle(nEntry, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE, nCol); } if (rArr.eType == MSFltrPg2_CheckBoxEntries::SmartArt) diff --git a/cui/source/options/optfltr.hxx b/cui/source/options/optfltr.hxx index 0495b8c49514..db954aa4684b 100644 --- a/cui/source/options/optfltr.hxx +++ b/cui/source/options/optfltr.hxx @@ -56,7 +56,8 @@ class OfaMSFilterTabPage2 : public SfxTabPage sChgToFromCalc, sChgToFromImpress, sChgToFromSmartArt, - sChgToFromVisio; + sChgToFromVisio, + sChgToFromPDF; std::unique_ptr m_xCheckLB; std::unique_ptr m_xHighlightingRB; diff --git a/embeddedobj/qa/cppunit/data/insert-file-config.pdf b/embeddedobj/qa/cppunit/data/insert-file-config.pdf new file mode 100644 index 000000000000..6302457402fe Binary files /dev/null and b/embeddedobj/qa/cppunit/data/insert-file-config.pdf differ diff --git a/embeddedobj/qa/cppunit/general.cxx b/embeddedobj/qa/cppunit/general.cxx index bbab17440fe3..ba862d3a86f0 100644 --- a/embeddedobj/qa/cppunit/general.cxx +++ b/embeddedobj/qa/cppunit/general.cxx @@ -118,6 +118,39 @@ CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigVsdx) CPPUNIT_ASSERT(!xObject.is()); } +CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigPdf) +{ + // Explicitly disable Word->Writer mapping for this test. + std::shared_ptr pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(false, pBatch); + pBatch->commit(); + comphelper::ScopeGuard g([]() { + std::shared_ptr pBatchReset( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(true, pBatchReset); + pBatchReset->commit(); + }); + getComponent().set( + loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument")); + + // Insert a PDF file as an embedded object. + uno::Reference xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); + comphelper::EmbeddedObjectContainer aContainer(xStorage); + OUString aFileName + = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.pdf"); + uno::Sequence aMedium{ comphelper::makePropertyValue("URL", aFileName) }; + OUString aName("Object 1"); + uno::Reference xObject + = aContainer.InsertEmbeddedObject(aMedium, aName); + + // Make sure that the insertion fails: + // 1) the user explicitly requested that the data is not loaded into Writer + // 2) this is non-Windows, so OLE embedding is not an option + // so silently still loading the data into Writer would be bad. + CPPUNIT_ASSERT(!xObject.is()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/source/general/xcreator.cxx b/embeddedobj/source/general/xcreator.cxx index 640244d1134c..fe6c79d73da5 100644 --- a/embeddedobj/source/general/xcreator.cxx +++ b/embeddedobj/source/general/xcreator.cxx @@ -249,6 +249,13 @@ static OUString HandleFilter(const uno::Reference& xComp aRet.clear(); } } + if (!officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get(xComponentContext)) + { + if (rFilter == "draw_pdf_import") + { + aRet.clear(); + } + } return aRet; } diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index af847483bb7a..8d4f26fc6cab 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -3792,6 +3792,23 @@ Specifies default settings of Microsoft-, Graphic- and HTML filters. + + + Specifies default settings of Adobe filters. + + + + Specifies default settings of Adobe import filters. + + + + Specifies if convertible PDF OLE objects are converted + into Draw objects. + + true + + + Specifies default settings of Microsoft filters. -- cgit