2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-11-11 22:30:35 -06:00
|
|
|
#include <xmloff/ImageStyle.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <com/sun/star/awt/XBitmap.hpp>
|
2007-06-27 14:24:59 +00:00
|
|
|
#include <xmloff/attrlist.hxx>
|
|
|
|
#include <xmloff/nmspmap.hxx>
|
|
|
|
#include <xmloff/xmluconv.hxx>
|
2010-04-16 23:04:00 +02:00
|
|
|
#include"xmloff/xmlnmspe.hxx"
|
2007-06-27 14:24:59 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#include <xmloff/xmlexp.hxx>
|
|
|
|
#include <xmloff/xmlimp.hxx>
|
2001-06-29 20:07:26 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2006-06-19 17:25:20 +00:00
|
|
|
#include <rtl/ustring.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <tools/debug.hxx>
|
2007-06-27 14:24:59 +00:00
|
|
|
#include <xmloff/xmltkmap.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2008-03-12 09:42:50 +00:00
|
|
|
|
2001-06-15 16:16:59 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
enum SvXMLTokenMapAttrs
|
|
|
|
{
|
|
|
|
XML_TOK_IMAGE_NAME,
|
2004-07-13 07:19:27 +00:00
|
|
|
XML_TOK_IMAGE_DISPLAY_NAME,
|
2000-09-18 16:07:07 +00:00
|
|
|
XML_TOK_IMAGE_URL,
|
|
|
|
XML_TOK_IMAGE_TYPE,
|
|
|
|
XML_TOK_IMAGE_SHOW,
|
|
|
|
XML_TOK_IMAGE_ACTUATE,
|
|
|
|
XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-12-01 10:16:41 +00:00
|
|
|
XMLImageStyle::XMLImageStyle()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLImageStyle::~XMLImageStyle()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-26 08:43:00 +02:00
|
|
|
void XMLImageStyle::exportXML( const OUString& rStrName, const css::uno::Any& rValue, SvXMLExport& rExport )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2014-03-27 14:39:19 +02:00
|
|
|
ImpExportXML( rStrName, rValue, rExport );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 14:39:19 +02:00
|
|
|
void XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-08-09 13:09:49 +00:00
|
|
|
OUString sImageURL;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2012-01-25 21:59:48 -02:00
|
|
|
if( !rStrName.isEmpty() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-08-09 13:09:49 +00:00
|
|
|
if( rValue >>= sImageURL )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// Name
|
2014-03-31 11:47:05 +02:00
|
|
|
bool bEncoded = false;
|
2004-07-13 07:19:27 +00:00
|
|
|
rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME,
|
|
|
|
rExport.EncodeStyleName( rStrName,
|
|
|
|
&bEncoded ) );
|
|
|
|
if( bEncoded )
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME,
|
|
|
|
rStrName );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// uri
|
2001-08-09 13:09:49 +00:00
|
|
|
const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) );
|
2012-01-25 21:59:48 -02:00
|
|
|
if( !aStr.isEmpty() )
|
2001-08-09 13:09:49 +00:00
|
|
|
{
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr );
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
|
|
|
|
rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
|
|
|
|
}
|
2011-03-08 11:57:24 +01:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// Do Write
|
2014-03-28 16:28:51 +02:00
|
|
|
SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, true, true );
|
2001-08-09 13:09:49 +00:00
|
|
|
|
2012-01-25 21:59:48 -02:00
|
|
|
if( !sImageURL.isEmpty() )
|
2001-08-09 13:09:49 +00:00
|
|
|
{
|
|
|
|
// optional office:binary-data
|
|
|
|
rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 09:36:20 +02:00
|
|
|
void XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport )
|
2001-07-24 16:06:10 +00:00
|
|
|
{
|
2016-01-15 09:36:20 +02:00
|
|
|
ImpImportXML( xAttrList, rValue, rStrName, rImport );
|
2001-07-24 16:06:10 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 14:39:19 +02:00
|
|
|
bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
|
2000-12-01 10:16:41 +00:00
|
|
|
uno::Any& rValue, OUString& rStrName,
|
|
|
|
SvXMLImport& rImport )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2014-03-27 14:39:19 +02:00
|
|
|
static const SvXMLTokenMapEntry aHatchAttrTokenMap[] =
|
|
|
|
{
|
|
|
|
{ XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME },
|
|
|
|
{ XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME },
|
|
|
|
{ XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL },
|
|
|
|
{ XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE },
|
|
|
|
{ XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW },
|
|
|
|
{ XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE },
|
|
|
|
XML_TOKEN_MAP_END
|
|
|
|
};
|
|
|
|
|
|
|
|
bool bHasHRef = false;
|
|
|
|
bool bHasName = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
OUString aStrURL;
|
2004-07-13 07:19:27 +00:00
|
|
|
OUString aDisplayName;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
SvXMLTokenMap aTokenMap( aHatchAttrTokenMap );
|
|
|
|
|
|
|
|
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
|
|
|
|
for( sal_Int16 i=0; i < nAttrCount; i++ )
|
|
|
|
{
|
|
|
|
const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
|
|
|
|
OUString aStrAttrName;
|
2000-12-01 10:16:41 +00:00
|
|
|
sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName );
|
2000-09-18 16:07:07 +00:00
|
|
|
const OUString& rStrValue = xAttrList->getValueByIndex( i );
|
|
|
|
|
|
|
|
switch( aTokenMap.Get( nPrefix, aStrAttrName ) )
|
|
|
|
{
|
|
|
|
case XML_TOK_IMAGE_NAME:
|
|
|
|
{
|
|
|
|
rStrName = rStrValue;
|
2014-03-27 14:39:19 +02:00
|
|
|
bHasName = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-07-13 07:19:27 +00:00
|
|
|
case XML_TOK_IMAGE_DISPLAY_NAME:
|
|
|
|
{
|
|
|
|
aDisplayName = rStrValue;
|
|
|
|
}
|
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
case XML_TOK_IMAGE_URL:
|
|
|
|
{
|
2014-03-31 09:05:32 +02:00
|
|
|
aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, false );
|
2014-03-27 14:39:19 +02:00
|
|
|
bHasHRef = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XML_TOK_IMAGE_TYPE:
|
|
|
|
// ignore
|
|
|
|
break;
|
|
|
|
case XML_TOK_IMAGE_SHOW:
|
|
|
|
// ignore
|
|
|
|
break;
|
|
|
|
case XML_TOK_IMAGE_ACTUATE:
|
|
|
|
// ignore
|
|
|
|
break;
|
|
|
|
default:
|
2015-02-09 18:08:39 +01:00
|
|
|
SAL_INFO("xmloff.style", "Unknown token at import fill bitmap style");
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rValue <<= aStrURL;
|
|
|
|
|
2012-01-25 21:59:48 -02:00
|
|
|
if( !aDisplayName.isEmpty() )
|
2004-07-13 07:19:27 +00:00
|
|
|
{
|
|
|
|
rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID,
|
|
|
|
rStrName, aDisplayName );
|
|
|
|
rStrName = aDisplayName;
|
|
|
|
}
|
|
|
|
|
2014-03-27 14:39:19 +02:00
|
|
|
bool bRet = bHasName && bHasHRef;
|
2009-04-23 10:42:05 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
return bRet;
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|