21#include <rtl/ustrbuf.hxx>
22#include <com/sun/star/uno/Reference.h>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/beans/XPropertySetInfo.hpp>
25#include <com/sun/star/frame/XModel.hpp>
26#include <com/sun/star/xml/sax/XAttributeList.hpp>
27#include <com/sun/star/container/XIndexContainer.hpp>
28#include <com/sun/star/lang/XMultiServiceFactory.hpp>
29#include <com/sun/star/document/XEventsSupplier.hpp>
30#include <com/sun/star/awt/Rectangle.hpp>
49using ::com::sun::star::beans::XPropertySet;
50using ::com::sun::star::beans::XPropertySetInfo;
51using ::com::sun::star::container::XIndexContainer;
52using ::com::sun::star::lang::XMultiServiceFactory;
53using ::com::sun::star::uno::Reference;
54using ::com::sun::star::uno::UNO_QUERY;
55using ::com::sun::star::uno::XInterface;
56using ::com::sun::star::uno::Any;
57using ::com::sun::star::document::XEventsSupplier;
66 Reference<XIndexContainer> xImageMap;
67 Reference<XPropertySet> xMapEntry;
71 OUStringBuffer sDescriptionBuffer;
72 OUStringBuffer sTitleBuffer;
80 XMLImageMapObjectContext(
82 css::uno::Reference<css::container::XIndexContainer>
const & xMap,
83 const char* pServiceName);
86 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
override;
92 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
99 css::uno::Reference<css::beans::XPropertySet> & rPropertySet);
104XMLImageMapObjectContext::XMLImageMapObjectContext(
105 SvXMLImport& rImport,
106 Reference<XIndexContainer>
const & xMap,
107 const char* pServiceName) :
114 "Please supply the image map object service name");
116 Reference<XMultiServiceFactory>
xFactory(GetImport().GetModel(),UNO_QUERY);
120 Reference<XInterface> xIfc =
xFactory->createInstance(
121 OUString::createFromAscii(pServiceName));
122 DBG_ASSERT(xIfc.is(),
"can't create image map object!");
125 Reference<XPropertySet> xPropertySet( xIfc, UNO_QUERY );
127 xMapEntry = xPropertySet;
133void XMLImageMapObjectContext::startFastElement( sal_Int32 ,
134 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
137 ProcessAttribute(aIter);
140void XMLImageMapObjectContext::endFastElement(sal_Int32 )
144 if ( bValid && xImageMap.is() && xMapEntry.is() )
150 xImageMap->insertByIndex( xImageMap->getCount(),
Any(xMapEntry) );
155css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImageMapObjectContext::createFastChildContext(
157 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
163 Reference<XEventsSupplier> xEvents( xMapEntry, UNO_QUERY );
165 GetImport(), xEvents);
170 GetImport(), sTitleBuffer);
174 GetImport(), sDescriptionBuffer);
180void XMLImageMapObjectContext::ProcessAttribute(
186 sUrl = GetImport().GetAbsoluteReference(aIter.
toString());
207void XMLImageMapObjectContext::Prepare(
208 Reference<XPropertySet> & rPropertySet)
210 rPropertySet->setPropertyValue(
"URL",
Any( sUrl ) );
211 rPropertySet->setPropertyValue(
"Title",
Any( sTitleBuffer.makeStringAndClear() ) );
212 rPropertySet->setPropertyValue(
"Description",
Any( sDescriptionBuffer.makeStringAndClear() ) );
213 rPropertySet->setPropertyValue(
"Target",
Any( sTargt ) );
214 rPropertySet->setPropertyValue(
"IsActive",
Any( bIsActive ) );
215 rPropertySet->setPropertyValue(
"Name",
Any( sNam ) );
220class XMLImageMapRectangleContext :
public XMLImageMapObjectContext
222 awt::Rectangle aRectangle;
231 XMLImageMapRectangleContext(
232 SvXMLImport& rImport,
233 css::uno::Reference<css::container::XIndexContainer>
const & xMap);
236 virtual void ProcessAttribute(
240 css::uno::Reference<css::beans::XPropertySet> & rPropertySet)
override;
245XMLImageMapRectangleContext::XMLImageMapRectangleContext(
246 SvXMLImport& rImport,
247 Reference<XIndexContainer>
const & xMap) :
248 XMLImageMapObjectContext(rImport, xMap,
249 "com.sun.star.image.ImageMapRectangleObject"),
257void XMLImageMapRectangleContext::ProcessAttribute(
265 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
274 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
283 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
286 aRectangle.Width = nTmp;
292 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
295 aRectangle.Height = nTmp;
300 XMLImageMapObjectContext::ProcessAttribute(aIter);
303 bValid = bHeightOK && bXOK && bYOK && bWidthOK;
306void XMLImageMapRectangleContext::Prepare(
307 Reference<XPropertySet> & rPropertySet)
309 rPropertySet->setPropertyValue(
"Boundary",
uno::Any(aRectangle) );
312 XMLImageMapObjectContext::Prepare(rPropertySet);
317class XMLImageMapPolygonContext :
public XMLImageMapObjectContext
319 OUString sViewBoxString;
320 OUString sPointsString;
327 XMLImageMapPolygonContext(
328 SvXMLImport& rImport,
329 css::uno::Reference<css::container::XIndexContainer>
const & xMap);
335 css::uno::Reference<css::beans::XPropertySet> & rPropertySet)
override;
340XMLImageMapPolygonContext::XMLImageMapPolygonContext(
341 SvXMLImport& rImport,
342 Reference<XIndexContainer>
const & xMap) :
343 XMLImageMapObjectContext(rImport, xMap,
344 "com.sun.star.image.ImageMapPolygonObject"),
350void XMLImageMapPolygonContext::ProcessAttribute(
365 XMLImageMapObjectContext::ProcessAttribute(aIter);
369 bValid = bViewBoxOK && bPointsOK;
372void XMLImageMapPolygonContext::Prepare(Reference<XPropertySet> & rPropertySet)
375 SdXMLImExViewBox aViewBox(sViewBoxString, GetImport().GetMM100UnitConverter());
384 css::drawing::PointSequence aPointSequence;
386 rPropertySet->setPropertyValue(
"Polygon",
Any(aPointSequence));
391 XMLImageMapObjectContext::Prepare(rPropertySet);
396class XMLImageMapCircleContext :
public XMLImageMapObjectContext
407 XMLImageMapCircleContext(
408 SvXMLImport& rImport,
409 css::uno::Reference<css::container::XIndexContainer>
const & xMap);
412 virtual void ProcessAttribute(
416 css::uno::Reference<css::beans::XPropertySet> & rPropertySet)
override;
421XMLImageMapCircleContext::XMLImageMapCircleContext(
422 SvXMLImport& rImport,
423 Reference<XIndexContainer>
const & xMap)
424 : XMLImageMapObjectContext(rImport, xMap,
425 "com.sun.star.image.ImageMapCircleObject")
433void XMLImageMapCircleContext::ProcessAttribute(
441 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
450 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
459 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
467 XMLImageMapObjectContext::ProcessAttribute(aIter);
470 bValid = bRadiusOK && bXOK && bYOK;
473void XMLImageMapCircleContext::Prepare(
474 Reference<XPropertySet> & rPropertySet)
477 rPropertySet->setPropertyValue(
"Center",
uno::Any(aCenter) );
479 rPropertySet->setPropertyValue(
"Radius",
uno::Any(nRadius) );
482 XMLImageMapObjectContext::Prepare(rPropertySet);
489 SvXMLImport& rImport,
490 Reference<XPropertySet>
const & rPropertySet) :
492 xPropertySet(rPropertySet)
496 Reference < XPropertySetInfo > xInfo =
498 if( xInfo.is() && xInfo->hasPropertyByName(
gsImageMap ) )
501 catch(
const css::uno::Exception& e)
513 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
518 return new XMLImageMapRectangleContext(
521 return new XMLImageMapPolygonContext(
524 return new XMLImageMapCircleContext(
535 Reference < XPropertySetInfo > xInfo =
537 if( xInfo.is() && xInfo->hasPropertyByName(
gsImageMap ) )
constexpr OUStringLiteral gsImageMap(u"ImageMap")
This class deliberately does not support XWeak, to improve performance when loading large documents.
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
SvXMLImport & GetImport()
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Import <script:events> element.
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
virtual ~XMLImageMapContext() override
css::uno::Reference< css::container::XIndexContainer > xImageMap
the image map to be imported
css::uno::Reference< css::beans::XPropertySet > xPropertySet
the property set from which to get and where eventually to set the image map
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
XMLImageMapContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > const &rPropertySet)
Import all text into a string buffer.
sal_Int32 getToken() const
#define DBG_ASSERT(sCon, aError)
Reference< XSingleServiceFactory > xFactory
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
bool importFromSvgPoints(B2DPolygon &o_rPoly, std::u16string_view rSvgPointsAttribute)
void B2DPolygonToUnoPointSequence(const B2DPolygon &rPolygon, css::drawing::PointSequence &rPointSequenceRetval)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
#define XMLERROR_FLAG_WARNING
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)