Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/svditer.hxx>
30 : : #include <svx/svdograf.hxx>
31 : : #include <svx/svdoole2.hxx>
32 : : #include <svx/svdpage.hxx>
33 : : #include <svx/xoutbmp.hxx>
34 : : #include <svx/svdxcgv.hxx>
35 : : #include <sot/exchange.hxx>
36 : : #include <svtools/htmlkywd.hxx>
37 : : #include <svtools/htmlout.hxx>
38 : : #include <svtools/transfer.hxx>
39 : : #include <svtools/embedtransfer.hxx>
40 : : #include <svl/urihelper.hxx>
41 : : #include <tools/urlobj.hxx>
42 : :
43 : : #include "htmlexp.hxx"
44 : : #include "global.hxx"
45 : : #include "document.hxx"
46 : : #include "drwlayer.hxx"
47 : : #include "ftools.hxx"
48 : : #include <rtl/strbuf.hxx>
49 : :
50 : : using namespace com::sun::star;
51 : :
52 : : //------------------------------------------------------------------------
53 : :
54 : 0 : void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
55 : : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
56 : : {
57 [ # # ]: 0 : if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
58 : : {
59 : 0 : SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
60 [ # # ]: 0 : if ( pDrawPage )
61 : : {
62 : 0 : bTabHasGraphics = true;
63 : 0 : FillGraphList( pDrawPage, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
64 : 0 : size_t ListSize = aGraphList.size();
65 [ # # ]: 0 : for ( size_t i = 0; i < ListSize; ++i )
66 : : {
67 : 0 : ScHTMLGraphEntry* pE = &aGraphList[ i ];
68 [ # # ]: 0 : if ( !pE->bInCell )
69 : : { // not all cells: table next to some
70 : 0 : bTabAlignedLeft = sal_True;
71 : 0 : break;
72 : : }
73 : : }
74 : : }
75 : : }
76 : 0 : }
77 : :
78 : :
79 : 0 : void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
80 : : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
81 : : {
82 : 0 : sal_uLong nObjCount = pPage->GetObjCount();
83 [ # # ]: 0 : if ( nObjCount )
84 : : {
85 [ # # ]: 0 : Rectangle aRect;
86 [ # # ]: 0 : if ( !bAll )
87 [ # # ]: 0 : aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
88 [ # # ]: 0 : SdrObjListIter aIter( *pPage, IM_FLAT );
89 [ # # ]: 0 : SdrObject* pObject = aIter.Next();
90 [ # # ]: 0 : while ( pObject )
91 : : {
92 [ # # ]: 0 : Rectangle aObjRect = pObject->GetCurrentBoundRect();
93 [ # # ][ # # ]: 0 : if ( bAll || aRect.IsInside( aObjRect ) )
[ # # ][ # # ]
94 : : {
95 : 0 : Size aSpace;
96 [ # # ]: 0 : ScRange aR = pDoc->GetRange( nTab, aObjRect );
97 : : // Rectangle in mm/100
98 [ # # ][ # # ]: 0 : Size aSize( MMToPixel( aObjRect.GetSize() ) );
99 : : // If the image is somewhere in a merged range we must
100 : : // move the anchor to the upper left (THE span cell).
101 [ # # ]: 0 : pDoc->ExtendOverlapped( aR );
102 : 0 : SCCOL nCol1 = aR.aStart.Col();
103 : 0 : SCROW nRow1 = aR.aStart.Row();
104 : 0 : SCCOL nCol2 = aR.aEnd.Col();
105 : 0 : SCROW nRow2 = aR.aEnd.Row();
106 : : // All cells empty under object?
107 : : sal_Bool bInCell = (pDoc->GetEmptyLinesInBlock(
108 [ # # ]: 0 : nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
109 : 0 : == static_cast< SCSIZE >( nRow2 - nRow1 )); // rows-1 !
110 [ # # ]: 0 : if ( bInCell )
111 : : { // Spacing in spanning cell
112 : : Rectangle aCellRect = pDoc->GetMMRect(
113 [ # # ]: 0 : nCol1, nRow1, nCol2, nRow2, nTab );
114 : : aSpace = MMToPixel( Size(
115 [ # # ][ # # ]: 0 : aCellRect.GetWidth() - aObjRect.GetWidth(),
116 [ # # ][ # # ]: 0 : aCellRect.GetHeight() - aObjRect.GetHeight() ));
[ # # ]
117 : 0 : aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
118 : 0 : aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
119 : 0 : aSpace.Width() /= 2;
120 : 0 : aSpace.Height() /= 2;
121 : : }
122 : : ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
123 [ # # ]: 0 : aR, aSize, bInCell, aSpace );
124 [ # # ]: 0 : aGraphList.push_back( pE );
125 : : }
126 [ # # ]: 0 : pObject = aIter.Next();
127 : 0 : }
128 : : }
129 : 0 : }
130 : :
131 : :
132 : 0 : void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
133 : : {
134 : 0 : SdrObject* pObject = pE->pObject;
135 : 0 : rtl::OStringBuffer aBuf;
136 [ # # ][ # # ]: 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).append('=').
[ # # ]
137 [ # # ]: 0 : append(static_cast<sal_Int32>(pE->aSize.Width()));
138 [ # # ][ # # ]: 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).append('=').
[ # # ]
139 [ # # ]: 0 : append(static_cast<sal_Int32>(pE->aSize.Height()));
140 [ # # ]: 0 : if ( pE->bInCell )
141 : : {
142 [ # # ][ # # ]: 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace).append('=').
[ # # ]
143 [ # # ]: 0 : append(static_cast<sal_Int32>(pE->aSpace.Width()));
144 [ # # ][ # # ]: 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace).append('=').
[ # # ]
145 [ # # ]: 0 : append(static_cast<sal_Int32>(pE->aSpace.Height()));
146 : : }
147 : 0 : rtl::OString aOpt = aBuf.makeStringAndClear();
148 [ # # # ]: 0 : switch ( pObject->GetObjIdentifier() )
[ # # ]
149 : : {
150 : : case OBJ_GRAF:
151 : : {
152 : 0 : const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
153 [ # # ]: 0 : const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
154 : : sal_uInt16 nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
155 [ # # ][ # # ]: 0 : ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
[ # # ]
156 [ # # ][ # # ]: 0 : sal_Bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
157 [ # # ][ # # ]: 0 : sal_Bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
158 : 0 : sal_uLong nXOutFlags = 0;
159 [ # # ]: 0 : if ( bHMirr )
160 : 0 : nXOutFlags |= XOUTBMP_MIRROR_HORZ;
161 [ # # ]: 0 : if ( bVMirr )
162 : 0 : nXOutFlags |= XOUTBMP_MIRROR_VERT;
163 [ # # ]: 0 : String aLinkName;
164 [ # # ][ # # ]: 0 : if ( pSGO->IsLinkedGraphic() )
165 [ # # ][ # # ]: 0 : aLinkName = pSGO->GetFileName();
166 [ # # ][ # # ]: 0 : WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
167 [ # # ]: 0 : pE->bWritten = sal_True;
168 : : }
169 : 0 : break;
170 : : case OBJ_OLE2:
171 : : {
172 [ # # ]: 0 : Graphic* pGraphic = ((SdrOle2Obj*)pObject)->GetGraphic();
173 [ # # ]: 0 : if ( pGraphic )
174 : : {
175 [ # # ]: 0 : String aLinkName;
176 [ # # ]: 0 : WriteImage( aLinkName, *pGraphic, aOpt );
177 [ # # ]: 0 : pE->bWritten = sal_True;
178 : : }
179 : : }
180 : 0 : break;
181 : : default:
182 : : {
183 : : Graphic aGraph( SdrExchangeView::GetObjGraphic(
184 [ # # ][ # # ]: 0 : pDoc->GetDrawLayer(), pObject ) );
185 [ # # ]: 0 : String aLinkName;
186 [ # # ]: 0 : WriteImage( aLinkName, aGraph, aOpt );
187 [ # # ][ # # ]: 0 : pE->bWritten = sal_True;
188 : : }
189 : 0 : }
190 : 0 : }
191 : :
192 : :
193 : 0 : void ScHTMLExport::WriteImage( String& rLinkName, const Graphic& rGrf,
194 : : const rtl::OString& rImgOptions, sal_uLong nXOutFlags )
195 : : {
196 : : // Embedded graphic -> create an image file
197 [ # # ]: 0 : if( !rLinkName.Len() )
198 : : {
199 [ # # ]: 0 : if( aStreamPath.Len() > 0 )
200 : : {
201 : : // Save as a PNG
202 [ # # ]: 0 : String aGrfNm( aStreamPath );
203 : 0 : nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
204 : : sal_uInt16 nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
205 [ # # ][ # # ]: 0 : CREATE_STRING( "PNG" ), nXOutFlags );
[ # # ]
206 : :
207 : : // If it worked, create a URL for the IMG tag
208 [ # # ]: 0 : if( !nErr )
209 : : {
210 : : rLinkName = URIHelper::SmartRel2Abs(
211 : : INetURLObject(aBaseURL),
212 : : aGrfNm,
213 [ # # ][ # # ]: 0 : URIHelper::GetMaybeFileHdl());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
214 [ # # ]: 0 : if ( HasCId() )
215 [ # # ]: 0 : MakeCIdURL( rLinkName );
216 [ # # ]: 0 : }
217 : : }
218 : : }
219 : : else
220 : : {
221 : : // Linked graphic - figure out the URL for the IMG tag
222 [ # # ][ # # ]: 0 : if( bCopyLocalFileToINet || HasCId() )
[ # # ]
223 : : {
224 : 0 : CopyLocalFileToINet( rLinkName, aStreamPath );
225 [ # # ]: 0 : if ( HasCId() )
226 : 0 : MakeCIdURL( rLinkName );
227 : : }
228 : : else
229 : : rLinkName = URIHelper::SmartRel2Abs(
230 : : INetURLObject(aBaseURL),
231 : : rLinkName,
232 [ # # ][ # # ]: 0 : URIHelper::GetMaybeFileHdl());
[ # # ][ # # ]
[ # # ][ # # ]
233 : : }
234 : :
235 : : // If a URL was set, output the IMG tag.
236 : : // <IMG SRC="..."[ rImgOptions]>
237 [ # # ]: 0 : if( rLinkName.Len() )
238 : : {
239 : 0 : rStrm << '<' << OOO_STRING_SVTOOLS_HTML_image << ' ' << OOO_STRING_SVTOOLS_HTML_O_src << "=\"";
240 : : HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
241 : : aBaseURL,
242 [ # # ][ # # ]: 0 : rLinkName ), eDestEnc ) << '\"';
[ # # ][ # # ]
[ # # ][ # # ]
243 [ # # ]: 0 : if ( !rImgOptions.isEmpty() )
244 : 0 : rStrm << rImgOptions.getStr();
245 : 0 : rStrm << '>' << sNewLine << GetIndentStr();
246 : : }
247 : 0 : }
248 : :
249 : :
250 : :
251 : :
252 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|