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>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{\rtf1
|
||||
{\pict \pngblip \picw-64 \pich-1061137057 \picwgoal0 \pichgoal0 47494638396110001000d5ff00000000ffffffc0c0c0555f00ffffaafcfcfcf6f6f6eaeaeae6e6e6e4e4e4e3e3e3c2c2c2c1c1c1bcbcbcb5b5b5b3b3b3b0b0b0adadada5a5a5a2a2a2a1a1a19f9f9f9494948a8a8a8888888686867b7b7b6c6c6c5c5c5c4e4e4e4b4b4b4747474646463d3d3d3c3c3c2e2e2e2525251b1b1b18181810101009090906060603030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021f90401000002002c0000000010001000000684408170482c0a06c8a4728924389f506833b281302a8e6b164b18103024c52111504cca67332102e0042e9a40d9319f8300a343c1200f54e47f7e2a00001e0b0a7d0d728a010d838400261a7c0d94947784252700127e9d159f6c8411140019080ea7a9a85f842122281612b1b3b25d6b1f29291d0fbbbdbc5d5e51c34e4cc64a46c94341003b}
|
||||
\par }
|
||||
@@ -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: */
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ),
|
||||
|
||||
Reference in New Issue
Block a user