1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlexp2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------------
38 #include <svx/svditer.hxx>
39 #include <svx/svdograf.hxx>
40 #include <svx/svdoole2.hxx>
41 #include <svx/svdpage.hxx>
42 #include <svx/xoutbmp.hxx>
43 #include <svx/svdxcgv.hxx>
44 #include <sot/exchange.hxx>
45 #include <svtools/htmlkywd.hxx>
46 #include <svtools/htmlout.hxx>
47 #include <svtools/transfer.hxx>
48 #include <svtools/embedtransfer.hxx>
49 #include <svtools/urihelper.hxx>
50 #include <tools/urlobj.hxx>
52 #include "htmlexp.hxx"
54 #include "document.hxx"
55 #include "drwlayer.hxx"
58 using namespace com::sun::star
;
60 //------------------------------------------------------------------------
62 void ScHTMLExport::PrepareGraphics( ScDrawLayer
* pDrawLayer
, SCTAB nTab
,
63 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
)
65 if ( pDrawLayer
->HasObjectsInRows( nTab
, nStartRow
, nEndRow
) )
67 SdrPage
* pDrawPage
= pDrawLayer
->GetPage( static_cast<sal_uInt16
>(nTab
) );
70 bTabHasGraphics
= TRUE
;
71 FillGraphList( pDrawPage
, nTab
,
72 nStartCol
, nStartRow
, nEndCol
, nEndRow
);
73 for ( ScHTMLGraphEntry
* pE
= aGraphList
.First(); pE
;
74 pE
= aGraphList
.Next() )
77 { // nicht alle in Zellen: einige neben Tabelle
78 bTabAlignedLeft
= TRUE
;
87 void ScHTMLExport::FillGraphList( const SdrPage
* pPage
, SCTAB nTab
,
88 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
)
90 ULONG nObjCount
= pPage
->GetObjCount();
95 aRect
= pDoc
->GetMMRect( nStartCol
, nStartRow
, nEndCol
, nEndRow
, nTab
);
96 SdrObjListIter
aIter( *pPage
, IM_FLAT
);
97 SdrObject
* pObject
= aIter
.Next();
100 Rectangle aObjRect
= pObject
->GetCurrentBoundRect();
101 if ( bAll
|| aRect
.IsInside( aObjRect
) )
104 ScRange aR
= pDoc
->GetRange( nTab
, aObjRect
);
105 // Rectangle in mm/100
106 Size
aSize( MMToPixel( aObjRect
.GetSize() ) );
107 // If the image is somewhere in a merged range we must
108 // move the anchor to the upper left (THE span cell).
109 pDoc
->ExtendOverlapped( aR
);
110 SCCOL nCol1
= aR
.aStart
.Col();
111 SCROW nRow1
= aR
.aStart
.Row();
112 SCCOL nCol2
= aR
.aEnd
.Col();
113 SCROW nRow2
= aR
.aEnd
.Row();
114 // All cells empty under object?
115 BOOL bInCell
= (pDoc
->GetEmptyLinesInBlock(
116 nCol1
, nRow1
, nTab
, nCol2
, nRow2
, nTab
, DIR_TOP
)
117 == static_cast< SCSIZE
>( nRow2
- nRow1
)); // rows-1 !
119 { // Spacing in spanning cell
120 Rectangle aCellRect
= pDoc
->GetMMRect(
121 nCol1
, nRow1
, nCol2
, nRow2
, nTab
);
122 aSpace
= MMToPixel( Size(
123 aCellRect
.GetWidth() - aObjRect
.GetWidth(),
124 aCellRect
.GetHeight() - aObjRect
.GetHeight() ));
125 aSpace
.Width() += (nCol2
-nCol1
) * (nCellSpacing
+1);
126 aSpace
.Height() += (nRow2
-nRow1
) * (nCellSpacing
+1);
128 aSpace
.Height() /= 2;
130 ScHTMLGraphEntry
* pE
= new ScHTMLGraphEntry( pObject
,
131 aR
, aSize
, bInCell
, aSpace
);
132 aGraphList
.Insert( pE
, LIST_APPEND
);
134 pObject
= aIter
.Next();
140 void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry
* pE
)
142 SdrObject
* pObject
= pE
->pObject
;
144 (((aOpt
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_width
) += '=') +=
145 ByteString::CreateFromInt32( pE
->aSize
.Width() );
146 (((aOpt
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_height
) += '=') +=
147 ByteString::CreateFromInt32( pE
->aSize
.Height() );
150 (((aOpt
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_hspace
) += '=') +=
151 ByteString::CreateFromInt32( pE
->aSpace
.Width() );
152 (((aOpt
+= ' ') += OOO_STRING_SVTOOLS_HTML_O_vspace
) += '=') +=
153 ByteString::CreateFromInt32( pE
->aSpace
.Height() );
155 switch ( pObject
->GetObjIdentifier() )
159 const SdrGrafObj
* pSGO
= (SdrGrafObj
*)pObject
;
160 const SdrGrafObjGeoData
* pGeo
= (SdrGrafObjGeoData
*)pSGO
->GetGeoData();
161 USHORT nMirrorCase
= (pGeo
->aGeo
.nDrehWink
== 18000 ?
162 ( pGeo
->bMirrored
? 3 : 4 ) : ( pGeo
->bMirrored
? 2 : 1 ));
163 BOOL bHMirr
= ( ( nMirrorCase
== 2 ) || ( nMirrorCase
== 4 ) );
164 BOOL bVMirr
= ( ( nMirrorCase
== 3 ) || ( nMirrorCase
== 4 ) );
165 ULONG nXOutFlags
= 0;
167 nXOutFlags
|= XOUTBMP_MIRROR_HORZ
;
169 nXOutFlags
|= XOUTBMP_MIRROR_VERT
;
171 if ( pSGO
->IsLinkedGraphic() )
172 aLinkName
= pSGO
->GetFileName();
173 WriteImage( aLinkName
, pSGO
->GetGraphic(), aOpt
, nXOutFlags
);
179 Graphic
* pGraphic
= ((SdrOle2Obj
*)pObject
)->GetGraphic();
183 WriteImage( aLinkName
, *pGraphic
, aOpt
);
190 Graphic
aGraph( SdrExchangeView::GetObjGraphic(
191 pDoc
->GetDrawLayer(), pObject
) );
193 WriteImage( aLinkName
, aGraph
, aOpt
);
200 void ScHTMLExport::WriteImage( String
& rLinkName
, const Graphic
& rGrf
,
201 const ByteString
& rImgOptions
, ULONG nXOutFlags
)
203 // embeddete Grafik -> via WriteGraphic schreiben
204 if( !rLinkName
.Len() )
206 if( aStreamPath
.Len() > 0 )
208 // Grafik als (JPG-)File speichern
209 String
aGrfNm( aStreamPath
);
210 nXOutFlags
|= XOUTBMP_USE_NATIVE_IF_POSSIBLE
;
211 USHORT nErr
= XOutBitmap::WriteGraphic( rGrf
, aGrfNm
,
212 CREATE_STRING( "JPG" ), nXOutFlags
);
213 if( !nErr
) // sonst fehlerhaft, da ist nichts auszugeben
215 rLinkName
= URIHelper::SmartRel2Abs(
216 INetURLObject(aBaseURL
),
218 URIHelper::GetMaybeFileHdl());
220 MakeCIdURL( rLinkName
);
226 if( bCopyLocalFileToINet
|| HasCId() )
228 CopyLocalFileToINet( rLinkName
, aStreamPath
);
230 MakeCIdURL( rLinkName
);
233 rLinkName
= URIHelper::SmartRel2Abs(
234 INetURLObject(aBaseURL
),
236 URIHelper::GetMaybeFileHdl());
238 if( rLinkName
.Len() )
239 { // <IMG SRC="..."[ rImgOptions]>
240 rStrm
<< '<' << OOO_STRING_SVTOOLS_HTML_image
<< ' ' << OOO_STRING_SVTOOLS_HTML_O_src
<< "=\"";
241 HTMLOutFuncs::Out_String( rStrm
, URIHelper::simpleNormalizedMakeRelative(
243 rLinkName
), eDestEnc
) << '\"';
244 if ( rImgOptions
.Len() )
245 rStrm
<< rImgOptions
.GetBuffer();
246 rStrm
<< '>' << sNewLine
<< GetIndentStr();