fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / html / htmlexp2.cxx
blobc96388db77ab8525562dfaa237b7ece3ae6eaab8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <sot/exchange.hxx>
27 #include <svtools/htmlkywd.hxx>
28 #include <svtools/htmlout.hxx>
29 #include <svtools/transfer.hxx>
30 #include <svtools/embedtransfer.hxx>
31 #include <svl/urihelper.hxx>
32 #include <tools/urlobj.hxx>
34 #include "htmlexp.hxx"
35 #include "global.hxx"
36 #include "document.hxx"
37 #include "drwlayer.hxx"
38 #include "ftools.hxx"
39 #include <rtl/strbuf.hxx>
41 using namespace com::sun::star;
43 void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
44 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
46 if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
48 SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
49 if ( pDrawPage )
51 bTabHasGraphics = true;
52 FillGraphList( pDrawPage, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
53 size_t ListSize = aGraphList.size();
54 for ( size_t i = 0; i < ListSize; ++i )
56 ScHTMLGraphEntry* pE = &aGraphList[ i ];
57 if ( !pE->bInCell )
58 { // not all cells: table next to some
59 bTabAlignedLeft = true;
60 break;
67 void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
68 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
70 if ( pPage->GetObjCount() )
72 Rectangle aRect;
73 if ( !bAll )
74 aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
75 SdrObjListIter aIter( *pPage, IM_FLAT );
76 SdrObject* pObject = aIter.Next();
77 while ( pObject )
79 Rectangle aObjRect = pObject->GetCurrentBoundRect();
80 if ( bAll || aRect.IsInside( aObjRect ) )
82 Size aSpace;
83 ScRange aR = pDoc->GetRange( nTab, aObjRect );
84 // Rectangle in mm/100
85 Size aSize( MMToPixel( aObjRect.GetSize() ) );
86 // If the image is somewhere in a merged range we must
87 // move the anchor to the upper left (THE span cell).
88 pDoc->ExtendOverlapped( aR );
89 SCCOL nCol1 = aR.aStart.Col();
90 SCROW nRow1 = aR.aStart.Row();
91 SCCOL nCol2 = aR.aEnd.Col();
92 SCROW nRow2 = aR.aEnd.Row();
93 // All cells empty under object?
94 bool bInCell = (pDoc->GetEmptyLinesInBlock(
95 nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
96 == static_cast< SCSIZE >( nRow2 - nRow1 )); // rows-1 !
97 if ( bInCell )
98 { // Spacing in spanning cell
99 Rectangle aCellRect = pDoc->GetMMRect(
100 nCol1, nRow1, nCol2, nRow2, nTab );
101 aSpace = MMToPixel( Size(
102 aCellRect.GetWidth() - aObjRect.GetWidth(),
103 aCellRect.GetHeight() - aObjRect.GetHeight() ));
104 aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
105 aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
106 aSpace.Width() /= 2;
107 aSpace.Height() /= 2;
109 ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
110 aR, aSize, bInCell, aSpace );
111 aGraphList.push_back( pE );
113 pObject = aIter.Next();
118 void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
120 SdrObject* pObject = pE->pObject;
121 OStringBuffer aBuf;
122 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).append('=').
123 append(static_cast<sal_Int32>(pE->aSize.Width()));
124 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).append('=').
125 append(static_cast<sal_Int32>(pE->aSize.Height()));
126 if ( pE->bInCell )
128 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace).append('=').
129 append(static_cast<sal_Int32>(pE->aSpace.Width()));
130 aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace).append('=').
131 append(static_cast<sal_Int32>(pE->aSpace.Height()));
133 OString aOpt = aBuf.makeStringAndClear();
134 switch ( pObject->GetObjIdentifier() )
136 case OBJ_GRAF:
138 const SdrGrafObj* pSGO = static_cast<SdrGrafObj*>(pObject);
139 const SdrGrafObjGeoData* pGeo = static_cast<SdrGrafObjGeoData*>(pSGO->GetGeoData());
140 sal_uInt16 nMirrorCase = (pGeo->aGeo.nRotationAngle == 18000 ?
141 ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
142 bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
143 bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
144 sal_uLong nXOutFlags = 0;
145 if ( bHMirr )
146 nXOutFlags |= XOUTBMP_MIRROR_HORZ;
147 if ( bVMirr )
148 nXOutFlags |= XOUTBMP_MIRROR_VERT;
149 OUString aLinkName;
150 if ( pSGO->IsLinkedGraphic() )
151 aLinkName = pSGO->GetFileName();
152 WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
153 pE->bWritten = true;
155 break;
156 case OBJ_OLE2:
158 const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pObject)->GetGraphic();
159 if ( pGraphic )
161 OUString aLinkName;
162 WriteImage( aLinkName, *pGraphic, aOpt );
163 pE->bWritten = true;
166 break;
167 default:
169 Graphic aGraph( SdrExchangeView::GetObjGraphic(
170 pDoc->GetDrawLayer(), pObject ) );
171 OUString aLinkName;
172 WriteImage( aLinkName, aGraph, aOpt );
173 pE->bWritten = true;
178 void ScHTMLExport::WriteImage( OUString& rLinkName, const Graphic& rGrf,
179 const OString& rImgOptions, sal_uLong nXOutFlags )
181 // Embedded graphic -> create an image file
182 if( rLinkName.isEmpty() )
184 if( !aStreamPath.isEmpty() )
186 // Save as a PNG
187 OUString aGrfNm( aStreamPath );
188 nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
189 sal_uInt16 nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
190 "PNG", nXOutFlags );
192 // If it worked, create a URL for the IMG tag
193 if( !nErr )
195 rLinkName = URIHelper::SmartRel2Abs(
196 INetURLObject(aBaseURL),
197 aGrfNm,
198 URIHelper::GetMaybeFileHdl());
199 if ( HasCId() )
200 MakeCIdURL( rLinkName );
204 else
206 // Linked graphic - figure out the URL for the IMG tag
207 if( bCopyLocalFileToINet || HasCId() )
209 CopyLocalFileToINet( rLinkName, aStreamPath );
210 if ( HasCId() )
211 MakeCIdURL( rLinkName );
213 else
214 rLinkName = URIHelper::SmartRel2Abs(
215 INetURLObject(aBaseURL),
216 rLinkName,
217 URIHelper::GetMaybeFileHdl());
220 // If a URL was set, output the IMG tag.
221 // <IMG SRC="..."[ rImgOptions]>
222 if( !rLinkName.isEmpty() )
224 rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_image ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_src ).WriteCharPtr( "=\"" );
225 HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
226 aBaseURL,
227 rLinkName ), eDestEnc ).WriteChar( '\"' );
228 if ( !rImgOptions.isEmpty() )
229 rStrm.WriteCharPtr( rImgOptions.getStr() );
230 rStrm.WriteChar( '>' ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() );
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */