summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-05-31 09:11:52 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-05-31 08:56:09 +0000
commit526ed1f7dbd9150734edcb03727d49e1b1306f56 (patch)
treee92571cc2d0d7cb9815be2574fa0f43e73aaf032
parent9bfae70fcb91f15ecc0a58a0f5eb3e5f3c8d89d9 (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. Change-Id: I432fc741f8d75d735e1dfe88daba50ba0797042d Reviewed-on: https://gerrit.libreoffice.org/25705 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r--sw/qa/extras/rtfimport/data/tdf77349.rtf3
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx7
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx7
-rw-r--r--writerfilter/source/dmapper/DomainMapper.hxx3
-rw-r--r--writerfilter/source/dmapper/GraphicHelpers.cxx24
-rw-r--r--writerfilter/source/dmapper/GraphicHelpers.hxx11
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx11
7 files changed, 61 insertions, 5 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf77349.rtf b/sw/qa/extras/rtfimport/data/tdf77349.rtf
new file mode 100644
index 000000000000..1451b367823a
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf77349.rtf
@@ -0,0 +1,3 @@
+{\rtf1
+{\pict \pngblip \picw-64 \pich-1061137057 \picwgoal0 \pichgoal0 47494638396110001000d5ff00000000ffffffc0c0c0555f00ffffaafcfcfcf6f6f6eaeaeae6e6e6e4e4e4e3e3e3c2c2c2c1c1c1bcbcbcb5b5b5b3b3b3b0b0b0adadada5a5a5a2a2a2a1a1a19f9f9f9494948a8a8a8888888686867b7b7b6c6c6c5c5c5c4e4e4e4b4b4b4747474646463d3d3d3c3c3c2e2e2e2525251b1b1b18181810101009090906060603030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021f90401000002002c0000000010001000000684408170482c0a06c8a4728924389f506833b281302a8e6b164b18103024c52111504cca67332102e0042e9a40d9319f8300a343c1200f54e47f7e2a00001e0b0a7d0d728a010d838400261a7c0d94947784252700127e9d159f6c8411140019080ea7a9a85f842122281612b1b3b25d6b1f29291d0fbbbdbc5d5e51c34e4cc64a46c94341003b}
+\par }
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 2af36e6755ee..390079cf687a 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -2619,6 +2619,13 @@ DECLARE_RTFIMPORT_TEST(testTdf74795, "tdf74795.rtf")
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(xCell, "LeftBorderDistance"));
}
+DECLARE_RTFIMPORT_TEST(testTdf77349, "tdf77349.rtf")
+{
+ uno::Reference<container::XNamed> xImage(getShape(1), uno::UNO_QUERY);
+ // This was empty: imported image wasn't named automatically.
+ CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xImage->getName());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 ),