diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-05-31 09:11:52 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-06-02 10:48:44 +0000 |
commit | 5823d676e99f7536fca2cee774e2f8d805866668 (patch) | |
tree | 5e25d3eb83b2ad750ad6ad83d10ce17a834fe13e /writerfilter | |
parent | 66a3295a0b87617e912eacb4e1bec390385fee38 (diff) |
tdf#77349 RTF import: automatically generate names for images if needed
The DOC/ODT import can call SwDoc::SetAllUniqueFlyNames() at the end of
the process to assign unique names to fly frames which lack a name.
Add a similar (but much simpler) feature to the domain mapper to avoid
empty image names in the DOCX/RTF import result, so it's easier to click
on the items in Writer's navigator.
(cherry picked from commit 526ed1f7dbd9150734edcb03727d49e1b1306f56)
Change-Id: I432fc741f8d75d735e1dfe88daba50ba0797042d
Reviewed-on: https://gerrit.libreoffice.org/25812
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 7 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.hxx | 3 | ||||
-rw-r--r-- | writerfilter/source/dmapper/GraphicHelpers.cxx | 24 | ||||
-rw-r--r-- | writerfilter/source/dmapper/GraphicHelpers.hxx | 11 | ||||
-rw-r--r-- | writerfilter/source/dmapper/GraphicImport.cxx | 11 |
5 files changed, 51 insertions, 5 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 5eb24e9472b3..b7403ea2936d 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -3605,6 +3605,13 @@ GraphicZOrderHelper* DomainMapper::graphicZOrderHelper() return zOrderHelper.get(); } +GraphicNamingHelper& DomainMapper::GetGraphicNamingHelper() +{ + if (m_pGraphicNamingHelper.get() == nullptr) + m_pGraphicNamingHelper.reset(new GraphicNamingHelper()); + return *m_pGraphicNamingHelper; +} + uno::Reference<drawing::XShape> DomainMapper::PopPendingShape() { return m_pImpl->PopPendingShape(); diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx index fee11b17c1aa..2abaf1233656 100644 --- a/writerfilter/source/dmapper/DomainMapper.hxx +++ b/writerfilter/source/dmapper/DomainMapper.hxx @@ -62,6 +62,7 @@ class DomainMapper_Impl; class ListsManager; class StyleSheetTable; class GraphicZOrderHelper; +class GraphicNamingHelper; // different context types require different sprm handling (e.g. names) enum SprmType @@ -107,6 +108,7 @@ public: OUString getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, bool bAlwaysCreate ); std::shared_ptr< StyleSheetTable > GetStyleSheetTable( ); GraphicZOrderHelper* graphicZOrderHelper(); + GraphicNamingHelper& GetGraphicNamingHelper(); /// Return the first from the pending (not inserted to the document) shapes, if there are any. css::uno::Reference<css::drawing::XShape> PopPendingShape(); @@ -169,6 +171,7 @@ private: static sal_Unicode getFillCharFromValue(const sal_Int32 nIntValue); bool mbIsSplitPara; std::unique_ptr< GraphicZOrderHelper > zOrderHelper; + std::unique_ptr<GraphicNamingHelper> m_pGraphicNamingHelper; }; } // namespace dmapper diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx index 7e21f0f2dfb1..3d410b2e809a 100644 --- a/writerfilter/source/dmapper/GraphicHelpers.cxx +++ b/writerfilter/source/dmapper/GraphicHelpers.cxx @@ -29,8 +29,12 @@ #include <com/sun/star/text/WrapTextMode.hpp> #include <oox/drawingml/drawingmltypes.hxx> +#include <tools/resmgr.hxx> +#include <vcl/svapp.hxx> +#include <svx/svdstr.hrc> #include <iostream> +#include <memory> namespace writerfilter { namespace dmapper { @@ -284,6 +288,26 @@ sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight, bool bOldSt return 0; // this should not(?) happen } +GraphicNamingHelper::GraphicNamingHelper() + : m_nCounter(0) +{ +} + +OUString GraphicNamingHelper::NameGraphic(const OUString& rTemplate) +{ + OUString aRet = rTemplate; + + if (aRet.isEmpty()) + { + // Empty template: then auto-generate a unique name. + std::unique_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILanguageTag())); + OUString aPrefix(ResId(STR_ObjNameSingulGRAF, *pResMgr).toString()); + aRet += aPrefix + OUString::number(++m_nCounter); + } + + return aRet; +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/GraphicHelpers.hxx b/writerfilter/source/dmapper/GraphicHelpers.hxx index cd1778d7a977..a1ca90990bfd 100644 --- a/writerfilter/source/dmapper/GraphicHelpers.hxx +++ b/writerfilter/source/dmapper/GraphicHelpers.hxx @@ -65,6 +65,17 @@ public: virtual void lcl_sprm( Sprm& rSprm ) override; }; +/// Keeps track of the next available unique automatic name. +class GraphicNamingHelper +{ + int m_nCounter; + +public: + GraphicNamingHelper(); + /// Name a graphic based on rTemplate. + OUString NameGraphic(const OUString& rTemplate); +}; + } } #endif diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index 04849c1bbbc4..79b46c77c29c 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -388,11 +388,12 @@ public: { try { - if( !sName.isEmpty() ) - { - uno::Reference< container::XNamed > xNamed( xGraphicObjectProperties, uno::UNO_QUERY_THROW ); - xNamed->setName( sName ); - } + // Ask the graphic naming helper to find out the name for this + // object: It's around till the end of the import, so it remembers + // what's the first free name. + uno::Reference< container::XNamed > xNamed( xGraphicObjectProperties, uno::UNO_QUERY_THROW ); + xNamed->setName(rDomainMapper.GetGraphicNamingHelper().NameGraphic(sName)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_DESCRIPTION ), uno::makeAny( sAlternativeText )); xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_TITLE ), |