1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scfilt.hxx"
26
27
28
29 //------------------------------------------------------------------------
30
31 #include <svx/svditer.hxx>
32 #include <svx/svdograf.hxx>
33 #include <svx/svdoole2.hxx>
34 #include <svx/svdpage.hxx>
35 #include <svx/xoutbmp.hxx>
36 #include <svx/svdxcgv.hxx>
37 #include <sot/exchange.hxx>
38 #include <svtools/htmlkywd.hxx>
39 #include <svtools/htmlout.hxx>
40 #include <svtools/transfer.hxx>
41 #include <svtools/embedtransfer.hxx>
42 #include <svl/urihelper.hxx>
43 #include <tools/urlobj.hxx>
44
45 #include "htmlexp.hxx"
46 #include "global.hxx"
47 #include "document.hxx"
48 #include "drwlayer.hxx"
49 #include "ftools.hxx"
50
51 using namespace com::sun::star;
52
53 //------------------------------------------------------------------------
54
PrepareGraphics(ScDrawLayer * pDrawLayer,SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow)55 void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
56 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
57 {
58 if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
59 {
60 SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
61 if ( pDrawPage )
62 {
63 bTabHasGraphics = sal_True;
64 FillGraphList( pDrawPage, nTab,
65 nStartCol, nStartRow, nEndCol, nEndRow );
66 for ( ScHTMLGraphEntry* pE = aGraphList.First(); pE;
67 pE = aGraphList.Next() )
68 {
69 if ( !pE->bInCell )
70 { // nicht alle in Zellen: einige neben Tabelle
71 bTabAlignedLeft = sal_True;
72 break;
73 }
74 }
75 }
76 }
77 }
78
79
FillGraphList(const SdrPage * pPage,SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow)80 void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
81 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
82 {
83 sal_uLong nObjCount = pPage->GetObjCount();
84 if ( nObjCount )
85 {
86 Rectangle aRect;
87 if ( !bAll )
88 aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
89 SdrObjListIter aIter( *pPage, IM_FLAT );
90 SdrObject* pObject = aIter.Next();
91 while ( pObject )
92 {
93 Rectangle aObjRect = pObject->GetCurrentBoundRect();
94 if ( bAll || aRect.IsInside( aObjRect ) )
95 {
96 Size aSpace;
97 ScRange aR = pDoc->GetRange( nTab, aObjRect );
98 // Rectangle in mm/100
99 Size aSize( MMToPixel( aObjRect.GetSize() ) );
100 // If the image is somewhere in a merged range we must
101 // move the anchor to the upper left (THE span cell).
102 pDoc->ExtendOverlapped( aR );
103 SCCOL nCol1 = aR.aStart.Col();
104 SCROW nRow1 = aR.aStart.Row();
105 SCCOL nCol2 = aR.aEnd.Col();
106 SCROW nRow2 = aR.aEnd.Row();
107 // All cells empty under object?
108 sal_Bool bInCell = (pDoc->GetEmptyLinesInBlock(
109 nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
110 == static_cast< SCSIZE >( nRow2 - nRow1 )); // rows-1 !
111 if ( bInCell )
112 { // Spacing in spanning cell
113 Rectangle aCellRect = pDoc->GetMMRect(
114 nCol1, nRow1, nCol2, nRow2, nTab );
115 aSpace = MMToPixel( Size(
116 aCellRect.GetWidth() - aObjRect.GetWidth(),
117 aCellRect.GetHeight() - aObjRect.GetHeight() ));
118 aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
119 aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
120 aSpace.Width() /= 2;
121 aSpace.Height() /= 2;
122 }
123 ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
124 aR, aSize, bInCell, aSpace );
125 aGraphList.Insert( pE, LIST_APPEND );
126 }
127 pObject = aIter.Next();
128 }
129 }
130 }
131
132
WriteGraphEntry(ScHTMLGraphEntry * pE)133 void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
134 {
135 SdrObject* pObject = pE->pObject;
136 ByteString aOpt;
137 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_width) += '=') +=
138 ByteString::CreateFromInt32( pE->aSize.Width() );
139 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_height) += '=') +=
140 ByteString::CreateFromInt32( pE->aSize.Height() );
141 if ( pE->bInCell )
142 {
143 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_hspace) += '=') +=
144 ByteString::CreateFromInt32( pE->aSpace.Width() );
145 (((aOpt += ' ') += OOO_STRING_SVTOOLS_HTML_O_vspace) += '=') +=
146 ByteString::CreateFromInt32( pE->aSpace.Height() );
147 }
148 switch ( pObject->GetObjIdentifier() )
149 {
150 case OBJ_GRAF:
151 {
152 const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
153 const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
154 sal_uInt16 nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
155 ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
156 sal_Bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
157 sal_Bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
158 sal_uLong nXOutFlags = 0;
159 if ( bHMirr )
160 nXOutFlags |= XOUTBMP_MIRROR_HORZ;
161 if ( bVMirr )
162 nXOutFlags |= XOUTBMP_MIRROR_VERT;
163 String aLinkName;
164 if ( pSGO->IsLinkedGraphic() )
165 aLinkName = pSGO->GetFileName();
166 WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
167 pE->bWritten = sal_True;
168 }
169 break;
170 case OBJ_OLE2:
171 {
172 Graphic* pGraphic = ((SdrOle2Obj*)pObject)->GetGraphic();
173 if ( pGraphic )
174 {
175 String aLinkName;
176 WriteImage( aLinkName, *pGraphic, aOpt );
177 pE->bWritten = sal_True;
178 }
179 }
180 break;
181 default:
182 {
183 Graphic aGraph( SdrExchangeView::GetObjGraphic(
184 pDoc->GetDrawLayer(), pObject ) );
185 String aLinkName;
186 WriteImage( aLinkName, aGraph, aOpt );
187 pE->bWritten = sal_True;
188 }
189 }
190 }
191
192
WriteImage(String & rLinkName,const Graphic & rGrf,const ByteString & rImgOptions,sal_uLong nXOutFlags)193 void ScHTMLExport::WriteImage( String& rLinkName, const Graphic& rGrf,
194 const ByteString& rImgOptions, sal_uLong nXOutFlags )
195 {
196 // embeddete Grafik -> via WriteGraphic schreiben
197 if( !rLinkName.Len() )
198 {
199 if( aStreamPath.Len() > 0 )
200 {
201 // Grafik als (JPG-)File speichern
202 String aGrfNm( aStreamPath );
203 nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
204 sal_uInt16 nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
205 CREATE_STRING( "JPG" ), nXOutFlags );
206 if( !nErr ) // sonst fehlerhaft, da ist nichts auszugeben
207 {
208 rLinkName = URIHelper::SmartRel2Abs(
209 INetURLObject(aBaseURL),
210 aGrfNm,
211 URIHelper::GetMaybeFileHdl());
212 if ( HasCId() )
213 MakeCIdURL( rLinkName );
214 }
215 }
216 }
217 else
218 {
219 if( bCopyLocalFileToINet || HasCId() )
220 {
221 CopyLocalFileToINet( rLinkName, aStreamPath );
222 if ( HasCId() )
223 MakeCIdURL( rLinkName );
224 }
225 else
226 rLinkName = URIHelper::SmartRel2Abs(
227 INetURLObject(aBaseURL),
228 rLinkName,
229 URIHelper::GetMaybeFileHdl());
230 }
231 if( rLinkName.Len() )
232 { // <IMG SRC="..."[ rImgOptions]>
233 rStrm << '<' << OOO_STRING_SVTOOLS_HTML_image << ' ' << OOO_STRING_SVTOOLS_HTML_O_src << "=\"";
234 HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
235 aBaseURL,
236 rLinkName ), eDestEnc ) << '\"';
237 if ( rImgOptions.Len() )
238 rStrm << rImgOptions.GetBuffer();
239 rStrm << '>' << sNewLine << GetIndentStr();
240 }
241 }
242
243
244
245
246