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>
49 using ::com::sun::star::beans::XPropertySet;
50 using ::com::sun::star::beans::XPropertySetInfo;
51 using ::com::sun::star::container::XIndexContainer;
52 using ::com::sun::star::lang::XMultiServiceFactory;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::UNO_QUERY;
55 using ::com::sun::star::xml::sax::XAttributeList;
56 using ::com::sun::star::uno::XInterface;
57 using ::com::sun::star::uno::Any;
58 using ::com::sun::star::document::XEventsSupplier;
67 Reference<XIndexContainer> xImageMap;
72 OUStringBuffer sDescriptionBuffer;
73 OUStringBuffer sTitleBuffer;
81 XMLImageMapObjectContext(
83 css::uno::Reference<css::container::XIndexContainer>
const & xMap,
84 const char* pServiceName);
87 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
override;
93 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList )
override;
100 css::uno::Reference<css::beans::XPropertySet> & rPropertySet);
105 XMLImageMapObjectContext::XMLImageMapObjectContext(
107 Reference<XIndexContainer>
const & xMap,
108 const char* pServiceName) :
115 "Please supply the image map object service name");
117 Reference<XMultiServiceFactory>
xFactory(GetImport().GetModel(),UNO_QUERY);
121 Reference<XInterface> xIfc =
xFactory->createInstance(
122 OUString::createFromAscii(pServiceName));
123 DBG_ASSERT(xIfc.is(),
"can't create image map object!");
128 xMapEntry = xPropertySet;
134 void XMLImageMapObjectContext::startFastElement( sal_Int32 ,
135 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
138 ProcessAttribute(aIter);
141 void XMLImageMapObjectContext::endFastElement(sal_Int32 )
145 if ( bValid && xImageMap.is() && xMapEntry.is() )
151 xImageMap->insertByIndex( xImageMap->getCount(),
Any(xMapEntry) );
156 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLImageMapObjectContext::createFastChildContext(
158 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
164 Reference<XEventsSupplier> xEvents( xMapEntry, UNO_QUERY );
166 GetImport(), xEvents);
171 GetImport(), sTitleBuffer);
175 GetImport(), sDescriptionBuffer);
181 void XMLImageMapObjectContext::ProcessAttribute(
187 sUrl = GetImport().GetAbsoluteReference(aIter.
toString());
208 void XMLImageMapObjectContext::Prepare(
211 rPropertySet->setPropertyValue(
"URL",
Any( sUrl ) );
212 rPropertySet->setPropertyValue(
"Title",
Any( sTitleBuffer.makeStringAndClear() ) );
213 rPropertySet->setPropertyValue(
"Description",
Any( sDescriptionBuffer.makeStringAndClear() ) );
214 rPropertySet->setPropertyValue(
"Target",
Any( sTargt ) );
215 rPropertySet->setPropertyValue(
"IsActive",
Any( bIsActive ) );
216 rPropertySet->setPropertyValue(
"Name",
Any( sNam ) );
221 class XMLImageMapRectangleContext :
public XMLImageMapObjectContext
223 awt::Rectangle aRectangle;
232 XMLImageMapRectangleContext(
234 css::uno::Reference<css::container::XIndexContainer>
const & xMap);
237 virtual void ProcessAttribute(
241 css::uno::Reference<css::beans::XPropertySet> & rPropertySet)
override;
246 XMLImageMapRectangleContext::XMLImageMapRectangleContext(
248 Reference<XIndexContainer>
const & xMap) :
249 XMLImageMapObjectContext(rImport, xMap,
250 "com.sun.star.image.ImageMapRectangleObject"),
258 void XMLImageMapRectangleContext::ProcessAttribute(
266 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
275 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
284 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
287 aRectangle.Width = nTmp;
293 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
296 aRectangle.Height = nTmp;
301 XMLImageMapObjectContext::ProcessAttribute(aIter);
304 bValid = bHeightOK && bXOK && bYOK && bWidthOK;
307 void XMLImageMapRectangleContext::Prepare(
310 rPropertySet->setPropertyValue(
"Boundary",
uno::Any(aRectangle) );
313 XMLImageMapObjectContext::Prepare(rPropertySet);
318 class XMLImageMapPolygonContext :
public XMLImageMapObjectContext
320 OUString sViewBoxString;
321 OUString sPointsString;
328 XMLImageMapPolygonContext(
330 css::uno::Reference<css::container::XIndexContainer>
const & xMap);
336 css::uno::Reference<css::beans::XPropertySet> & rPropertySet)
override;
341 XMLImageMapPolygonContext::XMLImageMapPolygonContext(
343 Reference<XIndexContainer>
const & xMap) :
344 XMLImageMapObjectContext(rImport, xMap,
345 "com.sun.star.image.ImageMapPolygonObject"),
351 void XMLImageMapPolygonContext::ProcessAttribute(
366 XMLImageMapObjectContext::ProcessAttribute(aIter);
370 bValid = bViewBoxOK && bPointsOK;
376 SdXMLImExViewBox aViewBox(sViewBoxString, GetImport().GetMM100UnitConverter());
385 css::drawing::PointSequence aPointSequence;
387 rPropertySet->setPropertyValue(
"Polygon",
Any(aPointSequence));
392 XMLImageMapObjectContext::Prepare(rPropertySet);
397 class XMLImageMapCircleContext :
public XMLImageMapObjectContext
408 XMLImageMapCircleContext(
410 css::uno::Reference<css::container::XIndexContainer>
const & xMap);
413 virtual void ProcessAttribute(
417 css::uno::Reference<css::beans::XPropertySet> & rPropertySet)
override;
422 XMLImageMapCircleContext::XMLImageMapCircleContext(
424 Reference<XIndexContainer>
const & xMap)
425 : XMLImageMapObjectContext(rImport, xMap,
426 "com.sun.star.image.ImageMapCircleObject")
434 void XMLImageMapCircleContext::ProcessAttribute(
442 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
451 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
460 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(nTmp,
468 XMLImageMapObjectContext::ProcessAttribute(aIter);
471 bValid = bRadiusOK && bXOK && bYOK;
474 void XMLImageMapCircleContext::Prepare(
478 rPropertySet->setPropertyValue(
"Center",
uno::Any(aCenter) );
480 rPropertySet->setPropertyValue(
"Radius",
uno::Any(nRadius) );
483 XMLImageMapObjectContext::Prepare(rPropertySet);
487 constexpr OUStringLiteral
gsImageMap(u
"ImageMap");
493 xPropertySet(rPropertySet)
497 Reference < XPropertySetInfo > xInfo =
499 if( xInfo.is() && xInfo->hasPropertyByName(
gsImageMap ) )
502 catch(
const css::uno::Exception& e)
504 uno::Sequence<OUString>
aSeq(0);
515 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
520 return new XMLImageMapRectangleContext(
523 return new XMLImageMapPolygonContext(
526 return new XMLImageMapCircleContext(
537 Reference < XPropertySetInfo > xInfo =
539 if( xInfo.is() && xInfo->hasPropertyByName(
gsImageMap ) )
bool importFromSvgPoints(B2DPolygon &o_rPoly, const OUString &rSvgPointsAttribute)
void B2DPolygonToUnoPointSequence(const B2DPolygon &rPolygon, css::drawing::PointSequence &rPointSequenceRetval)
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
SvXMLImport & GetImport()
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
css::uno::Reference< css::container::XIndexContainer > xImageMap
the image map to be imported
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XMLERROR_FLAG_WARNING
sal_Int32 getToken() const
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
#define DBG_ASSERT(sCon, aError)
XMLImageMapContext(SvXMLImport &rImport, css::uno::Reference< css::beans::XPropertySet > const &rPropertySet)
virtual ~XMLImageMapContext() override
Import all text into a string buffer.
This class deliberately does not support XWeak, to improve performance when loading large documents...
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during import.
Sequence< sal_Int8 > aSeq
Reference< XSingleServiceFactory > xFactory
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
css::uno::Reference< css::beans::XPropertySet > xPropertySet
the property set from which to get and where eventually to set the image map
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
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 ...
OUString toString(OptionInfo const *info)
constexpr OUStringLiteral gsImageMap(u"ImageMap")
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override