LibreOffice Module sc (master) 1
htmlexp2.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
20#include <svx/svditer.hxx>
21#include <svx/svdograf.hxx>
22#include <svx/svdoole2.hxx>
23#include <svx/svdpage.hxx>
24#include <svx/xoutbmp.hxx>
25#include <svx/svdxcgv.hxx>
26#include <svtools/htmlkywd.hxx>
27#include <svtools/htmlout.hxx>
28#include <svl/urihelper.hxx>
29#include <tools/stream.hxx>
30#include <tools/urlobj.hxx>
31
32#include <htmlexp.hxx>
33#include <global.hxx>
34#include <document.hxx>
35#include <drwlayer.hxx>
36#include <rtl/strbuf.hxx>
37
38using namespace com::sun::star;
39
41 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
42{
43 if ( !pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
44 return;
45
46 SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
47 if ( !pDrawPage )
48 return;
49
50 bTabHasGraphics = true;
51 FillGraphList( pDrawPage, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
52 size_t ListSize = aGraphList.size();
53 for ( size_t i = 0; i < ListSize; ++i )
54 {
56 if ( !pE->bInCell )
57 { // not all cells: table next to some
58 bTabAlignedLeft = true;
59 break;
60 }
61 }
62}
63
64void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
65 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
66{
67 if ( !pPage->GetObjCount() )
68 return;
69
70 tools::Rectangle aRect;
71 if ( !bAll )
72 aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
73 SdrObjListIter aIter( pPage, SdrIterMode::Flat );
74 SdrObject* pObject = aIter.Next();
75 while ( pObject )
76 {
77 tools::Rectangle aObjRect = pObject->GetCurrentBoundRect();
78 if ( (bAll || aRect.Contains( aObjRect )) && !ScDrawLayer::IsNoteCaption(pObject) )
79 {
80 Size aSpace;
81 ScRange aR = pDoc->GetRange( nTab, aObjRect );
82 // Rectangle in mm/100
83 Size aSize( MMToPixel( aObjRect.GetSize() ) );
84 // If the image is somewhere in a merged range we must
85 // move the anchor to the upper left (THE span cell).
87 SCCOL nCol1 = aR.aStart.Col();
88 SCROW nRow1 = aR.aStart.Row();
89 SCCOL nCol2 = aR.aEnd.Col();
90 SCROW nRow2 = aR.aEnd.Row();
91 // All cells empty under object?
92 bool bInCell = pDoc->IsEmptyData( nCol1, nRow1, nCol2, nRow2, nTab );
93 if ( bInCell )
94 { // Spacing in spanning cell
95 tools::Rectangle aCellRect = pDoc->GetMMRect(
96 nCol1, nRow1, nCol2, nRow2, nTab );
97 aSpace = MMToPixel( Size(
98 aCellRect.GetWidth() - aObjRect.GetWidth(),
99 aCellRect.GetHeight() - aObjRect.GetHeight() ));
100 aSpace.AdjustWidth((nCol2-nCol1) * (nCellSpacing+1) );
101 aSpace.AdjustHeight((nRow2-nRow1) * (nCellSpacing+1) );
102 aSpace.setWidth( aSpace.Width() / 2 );
103 aSpace.setHeight( aSpace.Height() / 2 );
104 }
105 aGraphList.emplace_back( pObject,
106 aR, aSize, bInCell, aSpace );
107 }
108 pObject = aIter.Next();
109 }
110}
111
113{
114 SdrObject* pObject = pE->pObject;
115 OStringBuffer aBuf;
116 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).append('=').
117 append(static_cast<sal_Int32>(pE->aSize.Width()));
118 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).append('=').
119 append(static_cast<sal_Int32>(pE->aSize.Height()));
120 if ( pE->bInCell )
121 {
122 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace).append('=').
123 append(static_cast<sal_Int32>(pE->aSpace.Width()));
124 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace).append('=').
125 append(static_cast<sal_Int32>(pE->aSpace.Height()));
126 }
127 OString aOpt = aBuf.makeStringAndClear();
128 switch ( pObject->GetObjIdentifier() )
129 {
130 case SdrObjKind::Graphic:
131 {
132 const SdrGrafObj* pSGO = static_cast<SdrGrafObj*>(pObject);
133 std::unique_ptr<SdrGrafObjGeoData> pGeo(static_cast<SdrGrafObjGeoData*>(pSGO->GetGeoData().release()));
134 sal_uInt16 nMirrorCase = (pGeo->maGeo.nRotationAngle == 18000_deg100 ?
135 ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
136 bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
137 bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
138 XOutFlags nXOutFlags = XOutFlags::NONE;
139 if ( bHMirr )
140 nXOutFlags |= XOutFlags::MirrorHorz;
141 if ( bVMirr )
142 nXOutFlags |= XOutFlags::MirrorVert;
143 OUString aLinkName;
144 if ( pSGO->IsLinkedGraphic() )
145 aLinkName = pSGO->GetFileName();
146 WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
147 pE->bWritten = true;
148 }
149 break;
150 case SdrObjKind::OLE2:
151 {
152 const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pObject)->GetGraphic();
153 if ( pGraphic )
154 {
155 OUString aLinkName;
156 WriteImage( aLinkName, *pGraphic, aOpt );
157 pE->bWritten = true;
158 }
159 }
160 break;
161 default:
162 {
164 OUString aLinkName;
165 WriteImage( aLinkName, aGraph, aOpt );
166 pE->bWritten = true;
167 }
168 }
169}
170
171void ScHTMLExport::WriteImage( OUString& rLinkName, const Graphic& rGrf,
172 std::string_view rImgOptions, XOutFlags nXOutFlags )
173{
174 // Embedded graphic -> create an image file
175 if( rLinkName.isEmpty() )
176 {
177 if( !aStreamPath.isEmpty() )
178 {
179 // Save as a PNG
180 OUString aGrfNm( aStreamPath );
181 nXOutFlags |= XOutFlags::UseNativeIfPossible;
182 ErrCode nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
183 "PNG", nXOutFlags );
184
185 // If it worked, create a URL for the IMG tag
186 if( !nErr )
187 {
188 rLinkName = URIHelper::SmartRel2Abs(
190 aGrfNm,
192 }
193 }
194 }
195 else
196 {
197 // Linked graphic - figure out the URL for the IMG tag
199 {
200 CopyLocalFileToINet( rLinkName, aStreamPath );
201 }
202 else
203 rLinkName = URIHelper::SmartRel2Abs(
205 rLinkName,
207 }
208
209 // If a URL was set, output the IMG tag.
210 // <IMG SRC="..."[ rImgOptions]>
211 if( !rLinkName.isEmpty() )
212 {
215 aBaseURL,
216 rLinkName ) ).WriteChar( '\"' );
217 if ( !rImgOptions.empty() )
218 rStrm.WriteOString( rImgOptions );
220 }
221}
222
223/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
SC_DLLPUBLIC ScRange GetRange(SCTAB nTab, const tools::Rectangle &rMMRect, bool bHiddenAsZero=true) const
Definition: documen3.cxx:1811
SC_DLLPUBLIC void ExtendOverlapped(SCCOL &rStartCol, SCROW &rStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5585
SC_DLLPUBLIC bool IsEmptyData(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:6179
SC_DLLPUBLIC tools::Rectangle GetMMRect(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: documen3.cxx:2002
static bool IsNoteCaption(SdrObject *pObj)
Returns true, if the passed object is the caption of a cell note.
Definition: drwlayer.cxx:2632
bool HasObjectsInRows(SCTAB nTab, SCROW nStartRow, SCROW nEndRow)
Definition: drwlayer.cxx:1489
SvStream & rStrm
Definition: expbase.hxx:33
ScDocument * pDoc
Definition: expbase.hxx:35
bool bCopyLocalFileToINet
Definition: htmlexp.hxx:126
void WriteGraphEntry(ScHTMLGraphEntry *)
Definition: htmlexp2.cxx:112
OUString aStreamPath
Definition: htmlexp.hxx:115
const char * GetIndentStr() const
Definition: htmlexp.hxx:169
bool bTabAlignedLeft
Definition: htmlexp.hxx:124
void FillGraphList(const SdrPage *, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: htmlexp2.cxx:64
Size MMToPixel(const Size &r100thMMSize)
Definition: htmlexp.cxx:284
bool bTabHasGraphics
Definition: htmlexp.hxx:123
GraphEntryList aGraphList
Definition: htmlexp.hxx:112
OUString aBaseURL
Definition: htmlexp.hxx:114
void PrepareGraphics(ScDrawLayer *, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: htmlexp2.cxx:40
void WriteImage(OUString &rLinkName, const Graphic &, std::string_view rImgOptions, XOutFlags nXOutFlags=XOutFlags::NONE)
Definition: htmlexp2.cxx:171
static const sal_uInt16 nCellSpacing
Definition: htmlexp.hxx:106
void CopyLocalFileToINet(OUString &rFileNm, std::u16string_view rTargetNm)
Definition: htmlexp.cxx:1315
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
static Graphic GetObjGraphic(const SdrObject &rSdrObject)
bool IsLinkedGraphic() const
const OUString & GetFileName() const
const Graphic & GetGraphic() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
SdrObject * Next()
size_t GetObjCount() const
virtual std::unique_ptr< SdrObjGeoData > GetGeoData() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteChar(char nChar)
SvStream & WriteCharPtr(const char *pBuf)
static ErrCode WriteGraphic(const Graphic &rGraphic, OUString &rFileName, const OUString &rFilterName, const XOutFlags nFlags, const Size *pMtfSize_100TH_MM=nullptr, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData=nullptr)
constexpr tools::Long GetWidth() const
bool Contains(const Point &rPOINT) const
constexpr Size GetSize() const
constexpr tools::Long GetHeight() const
#define SAL_NEWLINE_STRING
FormulaCommand pE
EmbeddedObjectRef * pObject
#define OOO_STRING_SVTOOLS_HTML_O_height
#define OOO_STRING_SVTOOLS_HTML_O_src
#define OOO_STRING_SVTOOLS_HTML_image
#define OOO_STRING_SVTOOLS_HTML_O_hspace
#define OOO_STRING_SVTOOLS_HTML_O_vspace
#define OOO_STRING_SVTOOLS_HTML_O_width
aBuf
SVL_DLLPUBLIC Link< OUString *, bool > const & GetMaybeFileHdl()
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
SVL_DLLPUBLIC OUString simpleNormalizedMakeRelative(OUString const &baseUriReference, OUString const &uriReference)
int i
static SVT_DLLPUBLIC SvStream & Out_String(SvStream &, const OUString &, OUString *pNonConvertableChars=nullptr)
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
XOutFlags