Line data Source code
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 <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>
33 :
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>
40 :
41 : using namespace com::sun::star;
42 :
43 0 : void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
44 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
45 : {
46 0 : if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
47 : {
48 0 : SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
49 0 : if ( pDrawPage )
50 : {
51 0 : bTabHasGraphics = true;
52 0 : FillGraphList( pDrawPage, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
53 0 : size_t ListSize = aGraphList.size();
54 0 : for ( size_t i = 0; i < ListSize; ++i )
55 : {
56 0 : ScHTMLGraphEntry* pE = &aGraphList[ i ];
57 0 : if ( !pE->bInCell )
58 : { // not all cells: table next to some
59 0 : bTabAlignedLeft = true;
60 0 : break;
61 : }
62 : }
63 : }
64 : }
65 0 : }
66 :
67 :
68 0 : void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
69 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
70 : {
71 0 : sal_uLong nObjCount = pPage->GetObjCount();
72 0 : if ( nObjCount )
73 : {
74 0 : Rectangle aRect;
75 0 : if ( !bAll )
76 0 : aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
77 0 : SdrObjListIter aIter( *pPage, IM_FLAT );
78 0 : SdrObject* pObject = aIter.Next();
79 0 : while ( pObject )
80 : {
81 0 : Rectangle aObjRect = pObject->GetCurrentBoundRect();
82 0 : if ( bAll || aRect.IsInside( aObjRect ) )
83 : {
84 0 : Size aSpace;
85 0 : ScRange aR = pDoc->GetRange( nTab, aObjRect );
86 : // Rectangle in mm/100
87 0 : Size aSize( MMToPixel( aObjRect.GetSize() ) );
88 : // If the image is somewhere in a merged range we must
89 : // move the anchor to the upper left (THE span cell).
90 0 : pDoc->ExtendOverlapped( aR );
91 0 : SCCOL nCol1 = aR.aStart.Col();
92 0 : SCROW nRow1 = aR.aStart.Row();
93 0 : SCCOL nCol2 = aR.aEnd.Col();
94 0 : SCROW nRow2 = aR.aEnd.Row();
95 : // All cells empty under object?
96 : sal_Bool bInCell = (pDoc->GetEmptyLinesInBlock(
97 0 : nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
98 0 : == static_cast< SCSIZE >( nRow2 - nRow1 )); // rows-1 !
99 0 : if ( bInCell )
100 : { // Spacing in spanning cell
101 : Rectangle aCellRect = pDoc->GetMMRect(
102 0 : nCol1, nRow1, nCol2, nRow2, nTab );
103 : aSpace = MMToPixel( Size(
104 0 : aCellRect.GetWidth() - aObjRect.GetWidth(),
105 0 : aCellRect.GetHeight() - aObjRect.GetHeight() ));
106 0 : aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
107 0 : aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
108 0 : aSpace.Width() /= 2;
109 0 : aSpace.Height() /= 2;
110 : }
111 : ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
112 0 : aR, aSize, bInCell, aSpace );
113 0 : aGraphList.push_back( pE );
114 : }
115 0 : pObject = aIter.Next();
116 0 : }
117 : }
118 0 : }
119 :
120 :
121 0 : void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
122 : {
123 0 : SdrObject* pObject = pE->pObject;
124 0 : OStringBuffer aBuf;
125 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).append('=').
126 0 : append(static_cast<sal_Int32>(pE->aSize.Width()));
127 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).append('=').
128 0 : append(static_cast<sal_Int32>(pE->aSize.Height()));
129 0 : if ( pE->bInCell )
130 : {
131 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace).append('=').
132 0 : append(static_cast<sal_Int32>(pE->aSpace.Width()));
133 0 : aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace).append('=').
134 0 : append(static_cast<sal_Int32>(pE->aSpace.Height()));
135 : }
136 0 : OString aOpt = aBuf.makeStringAndClear();
137 0 : switch ( pObject->GetObjIdentifier() )
138 : {
139 : case OBJ_GRAF:
140 : {
141 0 : const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
142 0 : const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
143 0 : sal_uInt16 nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
144 0 : ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
145 0 : sal_Bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
146 0 : sal_Bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
147 0 : sal_uLong nXOutFlags = 0;
148 0 : if ( bHMirr )
149 0 : nXOutFlags |= XOUTBMP_MIRROR_HORZ;
150 0 : if ( bVMirr )
151 0 : nXOutFlags |= XOUTBMP_MIRROR_VERT;
152 0 : OUString aLinkName;
153 0 : if ( pSGO->IsLinkedGraphic() )
154 0 : aLinkName = pSGO->GetFileName();
155 0 : WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
156 0 : pE->bWritten = true;
157 : }
158 0 : break;
159 : case OBJ_OLE2:
160 : {
161 0 : const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pObject)->GetGraphic();
162 0 : if ( pGraphic )
163 : {
164 0 : OUString aLinkName;
165 0 : WriteImage( aLinkName, *pGraphic, aOpt );
166 0 : pE->bWritten = true;
167 : }
168 : }
169 0 : break;
170 : default:
171 : {
172 : Graphic aGraph( SdrExchangeView::GetObjGraphic(
173 0 : pDoc->GetDrawLayer(), pObject ) );
174 0 : OUString aLinkName;
175 0 : WriteImage( aLinkName, aGraph, aOpt );
176 0 : pE->bWritten = true;
177 : }
178 0 : }
179 0 : }
180 :
181 :
182 0 : void ScHTMLExport::WriteImage( OUString& rLinkName, const Graphic& rGrf,
183 : const OString& rImgOptions, sal_uLong nXOutFlags )
184 : {
185 : // Embedded graphic -> create an image file
186 0 : if( rLinkName.isEmpty() )
187 : {
188 0 : if( !aStreamPath.isEmpty() )
189 : {
190 : // Save as a PNG
191 0 : OUString aGrfNm( aStreamPath );
192 0 : nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
193 : sal_uInt16 nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
194 0 : "PNG", nXOutFlags );
195 :
196 : // If it worked, create a URL for the IMG tag
197 0 : if( !nErr )
198 : {
199 0 : rLinkName = URIHelper::SmartRel2Abs(
200 : INetURLObject(aBaseURL),
201 : aGrfNm,
202 0 : URIHelper::GetMaybeFileHdl());
203 0 : if ( HasCId() )
204 0 : MakeCIdURL( rLinkName );
205 0 : }
206 : }
207 : }
208 : else
209 : {
210 : // Linked graphic - figure out the URL for the IMG tag
211 0 : if( bCopyLocalFileToINet || HasCId() )
212 : {
213 0 : CopyLocalFileToINet( rLinkName, aStreamPath );
214 0 : if ( HasCId() )
215 0 : MakeCIdURL( rLinkName );
216 : }
217 : else
218 0 : rLinkName = URIHelper::SmartRel2Abs(
219 : INetURLObject(aBaseURL),
220 : rLinkName,
221 0 : URIHelper::GetMaybeFileHdl());
222 : }
223 :
224 : // If a URL was set, output the IMG tag.
225 : // <IMG SRC="..."[ rImgOptions]>
226 0 : if( !rLinkName.isEmpty() )
227 : {
228 0 : rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_image ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_src ).WriteCharPtr( "=\"" );
229 : HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
230 : aBaseURL,
231 0 : rLinkName ), eDestEnc ).WriteChar( '\"' );
232 0 : if ( !rImgOptions.isEmpty() )
233 0 : rStrm.WriteCharPtr( rImgOptions.getStr() );
234 0 : rStrm.WriteChar( '>' ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() );
235 : }
236 0 : }
237 :
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|