LibreOffice Module reportdesign (master)  1
xmlImage.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #include "xmlImage.hxx"
20 #include "xmlfilter.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmluconv.hxx>
24 #include "xmlHelper.hxx"
25 #include <unotools/pathoptions.hxx>
26 #include <sal/log.hxx>
27 #include <osl/diagnose.h>
28 #include <tools/diagnose_ex.h>
29 
30 #include <com/sun/star/awt/ImageScaleMode.hpp>
31 
32 namespace rptxml
33 {
34  using namespace ::com::sun::star;
35  using namespace ::com::sun::star::uno;
36  using namespace ::com::sun::star::xml::sax;
37 
38 
39 OXMLImage::OXMLImage( ORptFilter& rImport,
40  const Reference< XFastAttributeList > & _xAttrList
41  ,const Reference< XImageControl > & _xComponent
42  ,OXMLTable* _pContainer) :
43  OXMLReportElementBase( rImport,_xComponent,_pContainer)
44 {
45 
46  OSL_ENSURE(m_xReportComponent.is(),"Component is NULL!");
47 
48  try
49  {
50  for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
51  {
52  switch( aIter.getToken() )
53  {
54  case XML_ELEMENT(FORM, XML_IMAGE_DATA):
55  {
56  SvtPathOptions aPathOptions;
57  OUString sValue = aIter.toString();
58  sValue = aPathOptions.SubstituteVariable(sValue);
59  _xComponent->setImageURL(rImport.GetAbsoluteReference( sValue ));
60  break;
61  }
62  case XML_ELEMENT(REPORT, XML_PRESERVE_IRI):
63  _xComponent->setPreserveIRI(IsXMLToken(aIter, XML_TRUE));
64  break;
65  case XML_ELEMENT(REPORT, XML_SCALE):
66  {
67  sal_Int16 nRet = awt::ImageScaleMode::NONE;
68  if ( IsXMLToken(aIter, XML_TRUE) )
69  {
70  nRet = awt::ImageScaleMode::ANISOTROPIC;
71  }
72  else
73  {
75  bool bConvertOk = SvXMLUnitConverter::convertEnum( nRet, aIter.toView(), aXML_EnumMap );
76  SAL_WARN_IF(!bConvertOk, "reportdesign", "convertEnum failed");
77  }
78  _xComponent->setScaleMode( nRet );
79  break;
80  }
81  case XML_ELEMENT(REPORT, XML_FORMULA):
82  _xComponent->setDataField(ORptFilter::convertFormula(aIter.toString()));
83  break;
84  default:
85  XMLOFF_WARN_UNKNOWN("reportdesign", aIter);
86  break;
87  }
88  }
89  }
90  catch(Exception&)
91  {
92  TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the image props");
93  }
94 }
95 
96 
98 {
99 
100 }
101 
102 
103 } // namespace rptxml
104 
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString SubstituteVariable(const OUString &rVar) const
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define TOOLS_WARN_EXCEPTION(area, stream)
OXMLImage(const OXMLImage &)=delete
static const SvXMLEnumMapEntry< sal_Int16 > * GetImageScaleOptions()
Definition: xmlHelper.cxx:370
#define SAL_WARN_IF(condition, area, stream)
#define XML_ELEMENT(prefix, name)
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
XML_TRUE
virtual ~OXMLImage() override
Definition: xmlImage.cxx:97
OUString toString(OptionInfo const *info)