merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / source / filter / html / htmlexp2.cxx
blob341f9afbc739427b582d225e529a4404d28cf0f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
33 //------------------------------------------------------------------------
35 #include <svx/svditer.hxx>
36 #include <svx/svdograf.hxx>
37 #include <svx/svdoole2.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/xoutbmp.hxx>
40 #include <svx/svdxcgv.hxx>
41 #include <sot/exchange.hxx>
42 #include <svtools/htmlkywd.hxx>
43 #include <svtools/htmlout.hxx>
44 #include <svtools/transfer.hxx>
45 #include <svtools/embedtransfer.hxx>
46 #include <svl/urihelper.hxx>
47 #include <tools/urlobj.hxx>
49 #include "htmlexp.hxx"
50 #include "global.hxx"
51 #include "document.hxx"
52 #include "drwlayer.hxx"
53 #include "ftools.hxx"
55 using namespace com::sun::star;
57 //------------------------------------------------------------------------
59 void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
60 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
62 if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
64 SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
65 if ( pDrawPage )
67 bTabHasGraphics = TRUE;
68 FillGraphList( pDrawPage, nTab,
69 nStartCol, nStartRow, nEndCol, nEndRow );
70 for ( ScHTMLGraphEntry* pE = aGraphList.First(); pE;
71 pE = aGraphList.Next() )
73 if ( !pE->bInCell )
74 { // nicht alle in Zellen: einige neben Tabelle
75 bTabAlignedLeft = TRUE;
76 break;
84 void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
85 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
87 ULONG nObjCount = pPage->GetObjCount();
88 if ( nObjCount )
90 Rectangle aRect;
91 if ( !bAll )
92 aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
93 SdrObjListIter aIter( *pPage, IM_FLAT );
94 SdrObject* pObject = aIter.Next();
95 while ( pObject )
97 Rectangle aObjRect = pObject->GetCurrentBoundRect();
98 if ( bAll || aRect.IsInside( aObjRect ) )
100 Size aSpace;
101 ScRange aR = pDoc->GetRange( nTab, aObjRect );
102 // Rectangle in mm/100
103 Size aSize( MMToPixel( aObjRect.GetSize() ) );
104 // If the image is somewhere in a merged range we must
105 // move the anchor to the upper left (THE span cell).
106 pDoc->ExtendOverlapped( aR );
107 SCCOL nCol1 = aR.aStart.Col();
108 SCROW nRow1 = aR.aStart.Row();
109 SCCOL nCol2 = aR.aEnd.Col();
110 SCROW nRow2 = aR.aEnd.Row();
111 // All cells empty under object?
112 BOOL bInCell = (pDoc->GetEmptyLinesInBlock(
113 nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
114 == static_cast< SCSIZE >( nRow2 - nRow1 )); // rows-1 !
115 if ( bInCell )
116 { // Spacing in spanning cell
117 Rectangle aCellRect = pDoc->GetMMRect(
118 nCol1, nRow1, nCol2, nRow2, nTab );
119 aSpace = MMToPixel( Size(
120 aCellRect.GetWidth() - aObjRect.GetWidth(),
121 aCellRect.GetHeight() - aObjRect.GetHeight() ));
122 aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
123 aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
124 aSpace.Width() /= 2;
125 aSpace.Height() /= 2;
127 ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
128 aR, aSize, bInCell, aSpace );
129 aGraphList.Insert( pE, LIST_APPEND );
131 pObject = aIter.Next();
137 void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
139 SdrObject* pObject = pE->pObject;
140 ByteString aOpt;
141 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_width) += '=') +=
142 ByteString::CreateFromInt32( pE->aSize.Width() );
143 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_height) += '=') +=
144 ByteString::CreateFromInt32( pE->aSize.Height() );
145 if ( pE->bInCell )
147 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_hspace) += '=') +=
148 ByteString::CreateFromInt32( pE->aSpace.Width() );
149 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_vspace) += '=') +=
150 ByteString::CreateFromInt32( pE->aSpace.Height() );
152 switch ( pObject->GetObjIdentifier() )
154 case OBJ_GRAF:
156 const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
157 const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
158 USHORT nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
159 ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
160 BOOL bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
161 BOOL bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
162 ULONG nXOutFlags = 0;
163 if ( bHMirr )
164 nXOutFlags |= XOUTBMP_MIRROR_HORZ;
165 if ( bVMirr )
166 nXOutFlags |= XOUTBMP_MIRROR_VERT;
167 String aLinkName;
168 if ( pSGO->IsLinkedGraphic() )
169 aLinkName = pSGO->GetFileName();
170 WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
171 pE->bWritten = TRUE;
173 break;
174 case OBJ_OLE2:
176 Graphic* pGraphic = ((SdrOle2Obj*)pObject)->GetGraphic();
177 if ( pGraphic )
179 String aLinkName;
180 WriteImage( aLinkName, *pGraphic, aOpt );
181 pE->bWritten = TRUE;
184 break;
185 default:
187 Graphic aGraph( SdrExchangeView::GetObjGraphic(
188 pDoc->GetDrawLayer(), pObject ) );
189 String aLinkName;
190 WriteImage( aLinkName, aGraph, aOpt );
191 pE->bWritten = TRUE;
197 void ScHTMLExport::WriteImage( String& rLinkName, const Graphic& rGrf,
198 const ByteString& rImgOptions, ULONG nXOutFlags )
200 // embeddete Grafik -> via WriteGraphic schreiben
201 if( !rLinkName.Len() )
203 if( aStreamPath.Len() > 0 )
205 // Grafik als (JPG-)File speichern
206 String aGrfNm( aStreamPath );
207 nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
208 USHORT nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
209 CREATE_STRING( "JPG" ), nXOutFlags );
210 if( !nErr ) // sonst fehlerhaft, da ist nichts auszugeben
212 rLinkName = URIHelper::SmartRel2Abs(
213 INetURLObject(aBaseURL),
214 aGrfNm,
215 URIHelper::GetMaybeFileHdl());
216 if ( HasCId() )
217 MakeCIdURL( rLinkName );
221 else
223 if( bCopyLocalFileToINet || HasCId() )
225 CopyLocalFileToINet( rLinkName, aStreamPath );
226 if ( HasCId() )
227 MakeCIdURL( rLinkName );
229 else
230 rLinkName = URIHelper::SmartRel2Abs(
231 INetURLObject(aBaseURL),
232 rLinkName,
233 URIHelper::GetMaybeFileHdl());
235 if( rLinkName.Len() )
236 { // <IMG SRC="..."[ rImgOptions]>
237 rStrm << '<' << OOO_STRING_SVTOOLS_HTML_image << ' ' << OOO_STRING_SVTOOLS_HTML_O_src << "=\"";
238 HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
239 aBaseURL,
240 rLinkName ), eDestEnc ) << '\"';
241 if ( rImgOptions.Len() )
242 rStrm << rImgOptions.GetBuffer();
243 rStrm << '>' << sNewLine << GetIndentStr();