diff options
author | Daniel Vogelheim <dvo@openoffice.org> | 2001-03-29 13:40:26 +0000 |
---|---|---|
committer | Daniel Vogelheim <dvo@openoffice.org> | 2001-03-29 13:40:26 +0000 |
commit | cff064bdbf3d39351ff2527b010cbd5188ce0f76 (patch) | |
tree | b532a77d2860c8d3dd9953a310a6688795534675 | |
parent | c1745ad6f668047d7f765b9f9eaaafe8af0efa1e (diff) |
#81839# image map import and export added
-rw-r--r-- | xmloff/inc/XMLImageMapContext.hxx | 118 | ||||
-rw-r--r-- | xmloff/inc/XMLImageMapExport.hxx | 11 | ||||
-rw-r--r-- | xmloff/inc/xmlkywd.hxx | 9 | ||||
-rw-r--r-- | xmloff/source/draw/XMLImageMapContext.cxx | 797 | ||||
-rw-r--r-- | xmloff/source/draw/XMLImageMapExport.cxx | 178 | ||||
-rw-r--r-- | xmloff/source/draw/makefile.mk | 5 |
6 files changed, 1084 insertions, 34 deletions
diff --git a/xmloff/inc/XMLImageMapContext.hxx b/xmloff/inc/XMLImageMapContext.hxx new file mode 100644 index 000000000000..2cb84bc76988 --- /dev/null +++ b/xmloff/inc/XMLImageMapContext.hxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * $RCSfile: XMLImageMapContext.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dvo $ $Date: 2001-03-29 14:40:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLIMAGEMAPCONTEXT_HXX_ +#define _XMLOFF_XMLIMAGEMAPCONTEXT_HXX_ + +#ifndef _XMLOFF_XMLICTXT_HXX +#include "xmlictxt.hxx" +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif + +namespace com { namespace sun { namespace star { + namespace container { class XIndexContainer; } + namespace beans { class XPropertySet; } + namespace xml { namespace sax { class XAttributeList; } } +} } } + + +class XMLImageMapContext : public SvXMLImportContext +{ + const ::rtl::OUString sImageMap; + + /// the image map to be imported + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexContainer> xImageMap; + + /// the property set from which to get and where eventually to set the + /// image map + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> xPropertySet; + +public: + TYPEINFO(); + + XMLImageMapContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropertySet); + + virtual ~XMLImageMapContext(); + + virtual SvXMLImportContext *CreateChildContext( + USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + virtual void EndElement(); +}; + +#endif diff --git a/xmloff/inc/XMLImageMapExport.hxx b/xmloff/inc/XMLImageMapExport.hxx index 9db16b75a915..7eeeb5cd0f4e 100644 --- a/xmloff/inc/XMLImageMapExport.hxx +++ b/xmloff/inc/XMLImageMapExport.hxx @@ -2,9 +2,9 @@ * * $RCSfile: XMLImageMapExport.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: dvo $ $Date: 2001-03-28 10:28:15 $ + * last change: $Author: dvo $ $Date: 2001-03-29 14:40:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -104,15 +104,16 @@ public: * export the map (if present). */ void Export( + /// the property set containing the ImageMap property const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet> & rPropertySet ); - + ::com::sun::star::beans::XPropertySet> & rPropertySet); /** * Export an ImageMap (XIndexContainer). */ void Export( + /// the container containing the image map elements const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XIndexContainer> & rContainer ); + ::com::sun::star::container::XIndexContainer> & rContainer); protected: diff --git a/xmloff/inc/xmlkywd.hxx b/xmloff/inc/xmlkywd.hxx index f63447bad430..01497303f8d8 100644 --- a/xmloff/inc/xmlkywd.hxx +++ b/xmloff/inc/xmlkywd.hxx @@ -2,9 +2,9 @@ * * $RCSfile: xmlkywd.hxx,v $ * - * $Revision: 1.136 $ + * $Revision: 1.137 $ * - * last change: $Author: mib $ $Date: 2001-03-28 09:00:37 $ + * last change: $Author: dvo $ $Date: 2001-03-29 14:40:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -234,6 +234,9 @@ XML_CONSTASCII_ACTION( sXML_archive, "archive" ); XML_CONSTASCII_ACTION( sXML_arcsin, "arcsin" ); XML_CONSTASCII_ACTION( sXML_arctan, "arctan" ); XML_CONSTASCII_ACTION( sXML_area, "area" ); +XML_CONSTASCII_ACTION( sXML_area_circle, "area-circle" ); +XML_CONSTASCII_ACTION( sXML_area_polygon, "area-polygon" ); +XML_CONSTASCII_ACTION( sXML_area_rectangle, "area-rectangle" ); XML_CONSTASCII_ACTION( sXML_article, "article" ); XML_CONSTASCII_ACTION( sXML_as_char, "as-char" ); XML_CONSTASCII_ACTION( sXML_ascending, "ascending"); @@ -879,6 +882,7 @@ XML_CONSTASCII_ACTION( sXML_illustration_index_entry_template, "illustration-ind XML_CONSTASCII_ACTION( sXML_illustration_index_source, "illustration-index-source" ); XML_CONSTASCII_ACTION( sXML_image, "image" ); XML_CONSTASCII_ACTION( sXML_image_count, "image-count" ); +XML_CONSTASCII_ACTION( sXML_image_map, "image-map" ); XML_CONSTASCII_ACTION( sXML_implies, "implies" ); XML_CONSTASCII_ACTION( sXML_in, "in"); XML_CONSTASCII_ACTION( sXML_in_range, "in-range"); @@ -1133,6 +1137,7 @@ XML_CONSTASCII_ACTION( sXML_new, "new" ); XML_CONSTASCII_ACTION( sXML_next, "next" ); XML_CONSTASCII_ACTION( sXML_next_page, "next-page" ); XML_CONSTASCII_ACTION( sXML_next_style_name, "next-style-name" ); +XML_CONSTASCII_ACTION( sXML_nohref, "nohref" ); XML_CONSTASCII_ACTION( sXML_no_limit, "no-limit" ); XML_CONSTASCII_ACTION( sXML_no_wrap, "no-wrap" ); XML_CONSTASCII_ACTION( sXML_noempty, "!empty"); diff --git a/xmloff/source/draw/XMLImageMapContext.cxx b/xmloff/source/draw/XMLImageMapContext.cxx new file mode 100644 index 000000000000..482539651362 --- /dev/null +++ b/xmloff/source/draw/XMLImageMapContext.cxx @@ -0,0 +1,797 @@ +/************************************************************************* + * + * $RCSfile: XMLImageMapContext.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dvo $ $Date: 2001-03-29 14:40:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLIMAGEMAPCONTEXT_HXX_ +#include "XMLImageMapContext.hxx" +#endif + +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif + +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif + +#ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_ +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XINDEXCONTAINER_HPP_ +#include <com/sun/star/container/XIndexContainer.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_DRAWING_POINTSEQUENCESEQUENCE_HPP_ +#include <com/sun/star/drawing/PointSequenceSequence.hpp> +#endif + +#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP +#include <com/sun/star/document/XEventsSupplier.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_RECTANGLE_HPP_ +#include <com/sun/star/awt/Rectangle.hpp> +#endif + +#ifndef _XMLOFF_XMLKYWD_HXX +#include "xmlkywd.hxx" +#endif + +#ifndef _XMLOFF_XMLIMP_HXX +#include "xmlimp.hxx" +#endif + +#ifndef _XMLOFF_XMLTKMAP_HXX +#include "xmltkmap.hxx" +#endif + +#ifndef _XMLOFF_XMLNMSPE_HXX +#include "xmlnmspe.hxx" +#endif + +#ifndef _XMLOFF_NMSPMAP_HXX +#include "nmspmap.hxx" +#endif + +#ifndef _XMLOFF_XMLUCONV_HXX +#include "xmluconv.hxx" +#endif + +#ifndef _XEXPTRANSFORM_HXX +#include "xexptran.hxx" +#endif + +#ifndef _XMLOFF_XMLEVENTSIMPORTCONTEXT_HXX +#include "XMLEventsImportContext.hxx" +#endif + +#ifndef _XMLOFF_XMLSTRINGBUFFERIMPORTCONTEXT_HXX +#include "XMLStringBufferImportContext.hxx" +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::container::XIndexContainer; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::xml::sax::XAttributeList; +using ::com::sun::star::uno::XInterface; +using ::com::sun::star::uno::Any; +using ::com::sun::star::drawing::PointSequenceSequence; +using ::com::sun::star::document::XEventsSupplier; + + +enum XMLImageMapToken +{ + XML_TOK_IMAP_URL, + XML_TOK_IMAP_DESCRIPTION, + XML_TOK_IMAP_X, + XML_TOK_IMAP_Y, + XML_TOK_IMAP_CENTER_X, + XML_TOK_IMAP_CENTER_Y, + XML_TOK_IMAP_WIDTH, + XML_TOK_IMAP_HEIGTH, + XML_TOK_IMAP_POINTS, + XML_TOK_IMAP_VIEWBOX, + XML_TOK_IMAP_NOHREF, + XML_TOK_IMAP_NAME, + XML_TOK_IMAP_RADIUS, + XML_TOK_IMAP_TARGET +}; + +static __FAR_DATA SvXMLTokenMapEntry aImageMapObjectTokenMap[] = +{ + { XML_NAMESPACE_XLINK, sXML_href, XML_TOK_IMAP_URL }, + { XML_NAMESPACE_OFFICE, sXML_name, XML_TOK_IMAP_NAME }, + { XML_NAMESPACE_DRAW, sXML_nohref, XML_TOK_IMAP_NOHREF }, + { XML_NAMESPACE_SVG, sXML_x, XML_TOK_IMAP_X }, + { XML_NAMESPACE_SVG, sXML_y, XML_TOK_IMAP_Y }, + { XML_NAMESPACE_SVG, sXML_cx, XML_TOK_IMAP_CENTER_X }, + { XML_NAMESPACE_SVG, sXML_cy, XML_TOK_IMAP_CENTER_Y }, + { XML_NAMESPACE_SVG, sXML_width, XML_TOK_IMAP_WIDTH }, + { XML_NAMESPACE_SVG, sXML_height, XML_TOK_IMAP_HEIGTH }, + { XML_NAMESPACE_SVG, sXML_r, XML_TOK_IMAP_RADIUS }, + { XML_NAMESPACE_SVG, sXML_viewBox, XML_TOK_IMAP_VIEWBOX }, + { XML_NAMESPACE_DRAW, sXML_points, XML_TOK_IMAP_POINTS }, + { XML_NAMESPACE_OFFICE, sXML_target_frame_name, XML_TOK_IMAP_TARGET }, + XML_TOKEN_MAP_END +}; + + + +class XMLImageMapObjectContext : public SvXMLImportContext +{ + +protected: + + const ::rtl::OUString sBoundary; + const ::rtl::OUString sCenter; + const ::rtl::OUString sDescription; + const ::rtl::OUString sImageMap; + const ::rtl::OUString sIsActive; + const ::rtl::OUString sName; + const ::rtl::OUString sPolygon; + const ::rtl::OUString sRadius; + const ::rtl::OUString sTarget; + const ::rtl::OUString sURL; + + ::rtl::OUString sServiceName; + + Reference<XIndexContainer> xImageMap; /// the image map + Reference<XPropertySet> xMapEntry; /// one map-entry (one area) + + ::rtl::OUString sUrl; + ::rtl::OUString sTargt; + ::rtl::OUStringBuffer sDescriptionBuffer; + ::rtl::OUString sNam; + sal_Bool bIsActive; + + sal_Bool bValid; + +public: + TYPEINFO(); + + XMLImageMapObjectContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexContainer> xMap, + const sal_Char* pServiceName); + + void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + void EndElement(); + + SvXMLImportContext *CreateChildContext( + USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); + +protected: + + virtual void ProcessAttribute( + enum XMLImageMapToken eToken, + const ::rtl::OUString& rValue); + + virtual void Prepare( + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropertySet); +}; + + +TYPEINIT1( XMLImageMapObjectContext, SvXMLImportContext ); + +XMLImageMapObjectContext::XMLImageMapObjectContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + Reference<XIndexContainer> xMap, + const sal_Char* pServiceName) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + xImageMap(xMap), + bIsActive(sal_True), + bValid(sal_False), + sBoundary(RTL_CONSTASCII_USTRINGPARAM("Boundary")), + sCenter(RTL_CONSTASCII_USTRINGPARAM("Center")), + sDescription(RTL_CONSTASCII_USTRINGPARAM("Description")), + sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")), + sIsActive(RTL_CONSTASCII_USTRINGPARAM("IsActive")), + sName(RTL_CONSTASCII_USTRINGPARAM("Name")), + sPolygon(RTL_CONSTASCII_USTRINGPARAM("Polygon")), + sRadius(RTL_CONSTASCII_USTRINGPARAM("Radius")), + sTarget(RTL_CONSTASCII_USTRINGPARAM("Target")), + sURL(RTL_CONSTASCII_USTRINGPARAM("URL")) +{ + DBG_ASSERT(NULL != pServiceName, + "Please supply the image map object service name"); + + Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY); + if( xFactory.is() ) + { + Reference<XInterface> xIfc = xFactory->createInstance( + OUString::createFromAscii(pServiceName)); + DBG_ASSERT(xIfc.is(), "can't create image map object!"); + if( xIfc.is() ) + { + Reference<XPropertySet> xPropertySet( xIfc, UNO_QUERY ); + + xMapEntry = xPropertySet; + } + // else: can't create service -> ignore + } + // else: can't even get factory -> ignore +} + +void XMLImageMapObjectContext::StartElement( + const Reference<XAttributeList >& xAttrList ) +{ + SvXMLTokenMap aMap(aImageMapObjectTokenMap); + + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + OUString sValue = xAttrList->getValueByIndex(nAttr); + + ProcessAttribute( + (enum XMLImageMapToken)aMap.Get(nPrefix, sLocalName), sValue); + } +} + +void XMLImageMapObjectContext::EndElement() +{ + // only create and insert image map object if validity flag is set + // (and we actually have an image map) + if ( bValid && xImageMap.is() && xMapEntry.is() ) + { + // set values + Prepare( xMapEntry ); + + // insert into image map + Any aAny; + aAny <<= xMapEntry; + xImageMap->insertByIndex( xImageMap->getCount(), aAny ); + } + // else: not valid -> don't create and insert +} + +SvXMLImportContext* XMLImageMapObjectContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + if ( (XML_NAMESPACE_OFFICE == nPrefix) && + (rLocalName.equalsAsciiL(sXML_events, sizeof(sXML_events)-1)) ) + { + Reference<XEventsSupplier> xEvents( xMapEntry, UNO_QUERY ); + return new XMLEventsImportContext( + GetImport(), nPrefix, rLocalName, xEvents); + } + else if ( (XML_NAMESPACE_SVG == nPrefix) && + (rLocalName.equalsAsciiL(sXML_desc, sizeof(sXML_desc)-1)) ) + { + return new XMLStringBufferImportContext( + GetImport(), nPrefix, rLocalName, sDescriptionBuffer); + } + else + return SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + +} + +void XMLImageMapObjectContext::ProcessAttribute( + enum XMLImageMapToken eToken, + const OUString& rValue) +{ + switch (eToken) + { + case XML_TOK_IMAP_URL: + sUrl = rValue; + break; + + case XML_TOK_IMAP_TARGET: + sTargt = rValue; + break; + + case XML_TOK_IMAP_NOHREF: + bIsActive = ! rValue.equalsAsciiL(sXML_nohref, + sizeof(sXML_nohref)-1); + break; + + case XML_TOK_IMAP_NAME: + sNam = rValue; + break; + } +} + +void XMLImageMapObjectContext::Prepare( + Reference<XPropertySet> & rPropertySet) +{ + Any aAny; + + aAny <<= sUrl; + rPropertySet->setPropertyValue( sURL, aAny ); + + aAny <<= sDescriptionBuffer.makeStringAndClear(); + rPropertySet->setPropertyValue( sDescription, aAny ); + + aAny <<= sTargt; + rPropertySet->setPropertyValue( sTarget, aAny ); + + aAny.setValue( &bIsActive, ::getBooleanCppuType() ); + rPropertySet->setPropertyValue( sIsActive, aAny ); + + aAny <<= sNam; + rPropertySet->setPropertyValue( sName, aAny ); +} + + + +class XMLImageMapRectangleContext : public XMLImageMapObjectContext +{ + awt::Rectangle aRectangle; + + sal_Bool bXOK; + sal_Bool bYOK; + sal_Bool bWidthOK; + sal_Bool bHeightOK; + +public: + TYPEINFO(); + + XMLImageMapRectangleContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexContainer> xMap); + + virtual ~XMLImageMapRectangleContext(); + +protected: + virtual void ProcessAttribute( + enum XMLImageMapToken eToken, + const ::rtl::OUString& rValue); + + virtual void Prepare( + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropertySet); +}; + + + +TYPEINIT1(XMLImageMapRectangleContext, XMLImageMapObjectContext); + +XMLImageMapRectangleContext::XMLImageMapRectangleContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + Reference<XIndexContainer> xMap) : + XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap, + "com.sun.star.image.ImageMapRectangleObject"), + bXOK(sal_False), + bYOK(sal_False), + bWidthOK(sal_False), + bHeightOK(sal_False) +{ +} + +XMLImageMapRectangleContext::~XMLImageMapRectangleContext() +{ +} + +void XMLImageMapRectangleContext::ProcessAttribute( + enum XMLImageMapToken eToken, + const OUString& rValue) +{ + sal_Int32 nTmp; + switch (eToken) + { + case XML_TOK_IMAP_X: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + aRectangle.X = nTmp; + bXOK = sal_True; + } + break; + case XML_TOK_IMAP_Y: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + aRectangle.Y = nTmp; + bYOK = sal_True; + } + break; + case XML_TOK_IMAP_WIDTH: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + aRectangle.Width = nTmp; + bWidthOK = sal_True; + } + break; + case XML_TOK_IMAP_HEIGTH: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + aRectangle.Height = nTmp; + bHeightOK = sal_True; + } + break; + default: + XMLImageMapObjectContext::ProcessAttribute(eToken, rValue); + } + + bValid = bHeightOK && bXOK && bYOK && bWidthOK; +} + +void XMLImageMapRectangleContext::Prepare( + Reference<XPropertySet> & rPropertySet) +{ + Any aAny; + aAny <<= aRectangle; + rPropertySet->setPropertyValue( sBoundary, aAny ); + + // common properties handled by super class + XMLImageMapObjectContext::Prepare(rPropertySet); +} + + +class XMLImageMapPolygonContext : public XMLImageMapObjectContext +{ + ::rtl::OUString sViewBoxString; + ::rtl::OUString sPointsString; + + sal_Bool bViewBoxOK; + sal_Bool bPointsOK; + +public: + TYPEINFO(); + + XMLImageMapPolygonContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexContainer> xMap); + + virtual ~XMLImageMapPolygonContext(); + +protected: + virtual void ProcessAttribute( + enum XMLImageMapToken eToken, + const ::rtl::OUString& rValue); + + virtual void Prepare( + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropertySet); +}; + + + +TYPEINIT1(XMLImageMapPolygonContext, XMLImageMapObjectContext); + +XMLImageMapPolygonContext::XMLImageMapPolygonContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + Reference<XIndexContainer> xMap) : + XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap, + "com.sun.star.image.ImageMapPolygonObject"), + bViewBoxOK(sal_False), + bPointsOK(sal_False) +{ +} + +XMLImageMapPolygonContext::~XMLImageMapPolygonContext() +{ +} + +void XMLImageMapPolygonContext::ProcessAttribute( + enum XMLImageMapToken eToken, + const OUString& rValue) +{ + switch (eToken) + { + case XML_TOK_IMAP_POINTS: + sPointsString = rValue; + bPointsOK = sal_True; + break; + case XML_TOK_IMAP_VIEWBOX: + sViewBoxString = rValue; + bViewBoxOK = sal_True; + break; + default: + XMLImageMapObjectContext::ProcessAttribute(eToken, rValue); + break; + } + + bValid = bViewBoxOK && bPointsOK; +} + +void XMLImageMapPolygonContext::Prepare( + Reference<XPropertySet> & rPropertySet) +{ + // process view box + SdXMLImExViewBox aViewBox(sViewBoxString, + GetImport().GetMM100UnitConverter()); + + // get polygon sequence + awt::Point aPoint(aViewBox.GetX(), aViewBox.GetY()); + awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight()); + SdXMLImExPointsElement aPoints( sPointsString, aViewBox, aPoint, aSize, + GetImport().GetMM100UnitConverter() ); + PointSequenceSequence aPointSeqSeq = aPoints.GetPointSequenceSequence(); + + // only use first element of sequence-sequence + if (aPointSeqSeq.getLength() > 0) + { + Any aAny; + aAny <<= aPointSeqSeq[0]; + rPropertySet->setPropertyValue(sPolygon, aAny); + } + + // parent properties + XMLImageMapObjectContext::Prepare(rPropertySet); +} + + + +class XMLImageMapCircleContext : public XMLImageMapObjectContext +{ + awt::Point aCenter; + sal_Int32 nRadius; + + sal_Bool bXOK; + sal_Bool bYOK; + sal_Bool bRadiusOK; + +public: + TYPEINFO(); + + XMLImageMapCircleContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XIndexContainer> xMap); + + virtual ~XMLImageMapCircleContext(); + +protected: + virtual void ProcessAttribute( + enum XMLImageMapToken eToken, + const ::rtl::OUString& rValue); + + virtual void Prepare( + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet> & rPropertySet); +}; + +TYPEINIT1(XMLImageMapCircleContext, XMLImageMapObjectContext); + +XMLImageMapCircleContext::XMLImageMapCircleContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + Reference<XIndexContainer> xMap) : + XMLImageMapObjectContext(rImport, nPrefix, rLocalName, xMap, + "com.sun.star.image.ImageMapCircleObject"), + bXOK(sal_False), + bYOK(sal_False), + bRadiusOK(sal_False) +{ +} + +XMLImageMapCircleContext::~XMLImageMapCircleContext() +{ +} + +void XMLImageMapCircleContext::ProcessAttribute( + enum XMLImageMapToken eToken, + const OUString& rValue) +{ + sal_Int32 nTmp; + switch (eToken) + { + case XML_TOK_IMAP_CENTER_X: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + aCenter.X = nTmp; + bXOK = sal_True; + } + break; + case XML_TOK_IMAP_CENTER_Y: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + aCenter.Y = nTmp; + bYOK = sal_True; + } + break; + case XML_TOK_IMAP_RADIUS: + if (GetImport().GetMM100UnitConverter().convertMeasure(nTmp, + rValue)) + { + nRadius = nTmp; + bRadiusOK = sal_True; + } + break; + default: + XMLImageMapObjectContext::ProcessAttribute(eToken, rValue); + } + + bValid = bRadiusOK && bXOK && bYOK; +} + +void XMLImageMapCircleContext::Prepare( + Reference<XPropertySet> & rPropertySet) +{ + // center (x,y) + Any aAny; + aAny <<= aCenter; + rPropertySet->setPropertyValue( sCenter, aAny ); + + // radius + aAny <<= nRadius; + rPropertySet->setPropertyValue( sRadius, aAny ); + + // common properties handled by super class + XMLImageMapObjectContext::Prepare(rPropertySet); +} + + + + + + + + + + +TYPEINIT1(XMLImageMapContext, SvXMLImportContext); + +XMLImageMapContext::XMLImageMapContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + Reference<XPropertySet> & rPropertySet) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + sImageMap(RTL_CONSTASCII_USTRINGPARAM("ImageMap")), + xPropertySet(rPropertySet) + +{ + Any aAny = xPropertySet->getPropertyValue(sImageMap); + aAny >>= xImageMap; +} + +XMLImageMapContext::~XMLImageMapContext() +{ +} + +SvXMLImportContext *XMLImageMapContext::CreateChildContext( + USHORT nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList> & xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + if ( XML_NAMESPACE_DRAW == nPrefix ) + { + if ( rLocalName.equalsAsciiL(sXML_area_rectangle, + sizeof(sXML_area_rectangle)-1) ) + { + pContext = new XMLImageMapRectangleContext( + GetImport(), nPrefix, rLocalName, xImageMap); + } + else if ( rLocalName.equalsAsciiL(sXML_area_polygon, + sizeof(sXML_area_polygon)-1) ) + { + pContext = new XMLImageMapPolygonContext( + GetImport(), nPrefix, rLocalName, xImageMap); + } + else if ( rLocalName.equalsAsciiL(sXML_area_circle, + sizeof(sXML_area_circle)-1) ) + { + pContext = new XMLImageMapCircleContext( + GetImport(), nPrefix, rLocalName, xImageMap); + } + } + else + pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, + xAttrList); + + return pContext; +} + +void XMLImageMapContext::EndElement() +{ + Any aAny; + aAny <<= xImageMap; + xPropertySet->setPropertyValue(sImageMap, aAny); +} + diff --git a/xmloff/source/draw/XMLImageMapExport.cxx b/xmloff/source/draw/XMLImageMapExport.cxx index e7c8d9ae6350..4333b40a47b3 100644 --- a/xmloff/source/draw/XMLImageMapExport.cxx +++ b/xmloff/source/draw/XMLImageMapExport.cxx @@ -2,9 +2,9 @@ * * $RCSfile: XMLImageMapExport.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: dvo $ $Date: 2001-03-28 10:28:15 $ + * last change: $Author: dvo $ $Date: 2001-03-29 14:40:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,6 +67,10 @@ #include <rtl/ustring.hxx> #endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif + #ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> #endif @@ -95,6 +99,22 @@ #include <com/sun/star/document/XEventsSupplier.hpp> #endif +#ifndef _COM_SUN_STAR_AWT_RECTANGLE_HPP_ +#include <com/sun/star/awt/Rectangle.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_POINT_HPP_ +#include <com/sun/star/awt/Point.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_SIZE_HPP_ +#include <com/sun/star/awt/Size.hpp> +#endif + +#ifndef _COM_SUN_STAR_DRAWING_POINTSEQUENCE_HPP_ +#include <com/sun/star/drawing/PointSequence.hpp> +#endif + #ifndef _XMLOFF_XMLEXP_HXX #include "xmlexp.hxx" #endif @@ -111,9 +131,20 @@ #include "XMLEventExport.hxx" #endif +#ifndef _XMLOFF_XMLUCONV_HXX +#include "xmluconv.hxx" +#endif + +#ifndef _XEXPTRANSFORM_HXX +#include "xexptran.hxx" +#endif + + +using namespace ::com::sun::star; using ::rtl::OUString; +using ::rtl::OUStringBuffer; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::uno::Sequence; @@ -122,17 +153,13 @@ using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::container::XIndexContainer; using ::com::sun::star::document::XEventsSupplier; using ::com::sun::star::lang::XServiceInfo; +using ::com::sun::star::drawing::PointSequence; const sal_Char sAPI_ImageMapRectangleObject[] = "com.sun.star.image.ImageMapRectangleObject"; const sal_Char sAPI_ImageMapCircleObject[] = "com.sun.star.image.ImageMapCircleObject"; const sal_Char sAPI_ImageMapPolygonObject[] = "com.sun.star.image.ImageMapPolygonObject"; -const sal_Char sXML_image_map[] = "image-map"; -const sal_Char sXML_area_rectangle[] = "area-rectangle"; -const sal_Char sXML_area_circle[] = "area-circle"; -const sal_Char sXML_area_polygon[] = "area-polygon"; - XMLImageMapExport::XMLImageMapExport(SvXMLExport& rExp) : rExport(rExp), bWhiteSpace(sal_True), @@ -155,7 +182,7 @@ XMLImageMapExport::~XMLImageMapExport() } void XMLImageMapExport::Export( - const Reference<XPropertySet> & rPropertySet ) + const Reference<XPropertySet> & rPropertySet) { if (rPropertySet->getPropertySetInfo()->hasPropertyByName(sImageMap)) { @@ -169,7 +196,7 @@ void XMLImageMapExport::Export( } void XMLImageMapExport::Export( - const Reference<XIndexContainer> & rContainer ) + const Reference<XIndexContainer> & rContainer) { if (rContainer.is()) { @@ -261,7 +288,7 @@ void XMLImageMapExport::ExportMapEntry( // now: handle ImageMapObject properties (those for all types) - // URL property + // XLINK (URL property) Any aAny = rPropertySet->getPropertyValue(sURL); OUString sHref; aAny >>= sHref; @@ -269,32 +296,39 @@ void XMLImageMapExport::ExportMapEntry( { rExport.AddAttribute(XML_NAMESPACE_XLINK, sXML_href, sHref); } - - // description property - aAny = rPropertySet->getPropertyValue(sDescription); - OUString sDescription; - aAny >>= sDescription; - if (sDescription.getLength() > 0) + rExport.AddAttributeASCII( XML_NAMESPACE_XLINK, sXML_type, + sXML_simple ); + + // Target property (and xlink:show) + aAny = rPropertySet->getPropertyValue(sTarget); + OUString sTargt; + aAny >>= sTargt; + if (sTargt.getLength() > 0) { - rExport.AddAttribute(XML_NAMESPACE_DRAW, sXML_description, - sDescription); + rExport.AddAttribute( + XML_NAMESPACE_OFFICE, sXML_target_frame_name, sTargt); + + rExport.AddAttributeASCII( + XML_NAMESPACE_XLINK, sXML_show, + sTargt.equalsAsciiL( "_blank", sizeof("_blank")-1 ) + ? sXML_new : sXML_replace ); } - // handle name + // name aAny = rPropertySet->getPropertyValue(sName); OUString sItemName; aAny >>= sItemName; if (sItemName.getLength() > 0) { - rExport.AddAttribute(XML_NAMESPACE_DRAW, sXML_name, sItemName); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, sXML_name, sItemName); } // is-active aAny = rPropertySet->getPropertyValue(sIsActive); if (! *(sal_Bool*)aAny.getValue()) { - rExport.AddAttributeASCII(XML_NAMESPACE_DRAW, sXML_active, - sXML_false); + rExport.AddAttributeASCII(XML_NAMESPACE_DRAW, sXML_nohref, + sXML_nohref); } // call specific rectangle/circle/... method @@ -322,6 +356,17 @@ void XMLImageMapExport::ExportMapEntry( XML_NAMESPACE_DRAW, *pElementName, bWhiteSpace, bWhiteSpace); + // description property (as <svg:desc> element) + aAny = rPropertySet->getPropertyValue(sDescription); + OUString sDescription; + aAny >>= sDescription; + if (sDescription.getLength() > 0) + { + SvXMLElementExport aDesc(rExport, XML_NAMESPACE_SVG, sXML_desc, + bWhiteSpace, sal_False); + rExport.GetDocHandler()->characters(sDescription); + } + // export events attached to this Reference<XEventsSupplier> xSupplier(rPropertySet, UNO_QUERY); rExport.GetEventExport().Export(xSupplier, bWhiteSpace); @@ -332,17 +377,100 @@ void XMLImageMapExport::ExportMapEntry( void XMLImageMapExport::ExportRectangle( const Reference<XPropertySet> & rPropertySet) { - // TODO + // get boundary rectangle + Any aAny = rPropertySet->getPropertyValue(sBoundary); + awt::Rectangle aRectangle; + aAny >>= aRectangle; + + // parameters svg:x, svg:y, svg:width, svg:height + OUStringBuffer aBuffer; + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.X); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_x, + aBuffer.makeStringAndClear() ); + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.Y); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_y, + aBuffer.makeStringAndClear() ); + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.Width); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_width, + aBuffer.makeStringAndClear() ); + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, aRectangle.Height); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_height, + aBuffer.makeStringAndClear() ); } void XMLImageMapExport::ExportCircle( const Reference<XPropertySet> & rPropertySet) { - // TODO + // get boundary rectangle + Any aAny = rPropertySet->getPropertyValue(sCenter); + awt::Point aCenter; + aAny >>= aCenter; + + // parameters svg:cx, svg:cy + OUStringBuffer aBuffer; + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, aCenter.X); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_cx, + aBuffer.makeStringAndClear() ); + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, aCenter.Y); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_cy, + aBuffer.makeStringAndClear() ); + + // radius + aAny = rPropertySet->getPropertyValue(sRadius); + sal_Int32 nRadius; + aAny >>= nRadius; + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, nRadius); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_r, + aBuffer.makeStringAndClear() ); } void XMLImageMapExport::ExportPolygon( const Reference<XPropertySet> & rPropertySet) { - // TODO + // polygons get exported as bounding box, viewbox, and coordinate + // pair sequence. The bounding box is always the entire image. + + // get polygon point sequence + Any aAny = rPropertySet->getPropertyValue(sPolygon); + PointSequence aPoly; + aAny >>= aPoly; + + // get bounding box (assume top-left to be 0,0) + sal_Int32 nWidth = 0; + sal_Int32 nHeight = 0; + sal_Int32 nLength = aPoly.getLength(); + for (sal_Int32 i = 0; i < nLength; i++) + { + sal_Int32 nPolyX = aPoly[i].X; + sal_Int32 nPolyY = aPoly[i].Y; + + nWidth = (nPolyX > nWidth ) ? nPolyX : nWidth; + nHeight = (nPolyY > nHeight ) ? nPolyY : nHeight; + } + DBG_ASSERT(nWidth > 0, "impossible Polygon found"); + DBG_ASSERT(nHeight > 0, "impossible Polygon found"); + + // parameters svg:x, svg:y, svg:width, svg:height + OUStringBuffer aBuffer; + rExport.AddAttributeASCII( XML_NAMESPACE_SVG, sXML_x, "0" ); + rExport.AddAttributeASCII( XML_NAMESPACE_SVG, sXML_y, "0" ); + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, nWidth); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_width, + aBuffer.makeStringAndClear() ); + rExport.GetMM100UnitConverter().convertMeasure(aBuffer, nHeight); + rExport.AddAttribute( XML_NAMESPACE_SVG, sXML_height, + aBuffer.makeStringAndClear() ); + + // svg:viewbox + SdXMLImExViewBox aViewBox(0, 0, nWidth, nHeight); + rExport.AddAttribute(XML_NAMESPACE_SVG, sXML_viewBox, + aViewBox.GetExportString(rExport.GetMM100UnitConverter())); + + // export point sequence + awt::Point aPoint(0, 0); + awt::Size aSize(nWidth, nHeight); + SdXMLImExPointsElement aPoints( &aPoly, aViewBox, aPoint, aSize, + rExport.GetMM100UnitConverter() ); + rExport.AddAttribute( XML_NAMESPACE_DRAW, sXML_points, + aPoints.GetExportString()); } diff --git a/xmloff/source/draw/makefile.mk b/xmloff/source/draw/makefile.mk index 3b31bf763f64..7e1733723c7e 100644 --- a/xmloff/source/draw/makefile.mk +++ b/xmloff/source/draw/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.12 $ +# $Revision: 1.13 $ # -# last change: $Author: dvo $ $Date: 2001-03-28 10:28:15 $ +# last change: $Author: dvo $ $Date: 2001-03-29 14:40:26 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -101,6 +101,7 @@ SLOFILES = \ $(SLO)$/shapeexport3.obj \ $(SLO)$/shapeimport.obj \ $(SLO)$/XMLImageMapExport.obj \ + $(SLO)$/XMLImageMapContext.obj \ $(SLO)$/XMLShapePropertySetContext.obj \ $(SLO)$/XMLShapeStyleContext.obj \ $(SLO)$/ximppage.obj |