1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 #include "htmlexp.hxx"
36 #include "document.hxx"
37 #include "drwlayer.hxx"
39 #include <rtl/strbuf.hxx>
41 using namespace com::sun::star
;
43 //------------------------------------------------------------------------
45 void ScHTMLExport::PrepareGraphics( ScDrawLayer
* pDrawLayer
, SCTAB nTab
,
46 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
)
48 if ( pDrawLayer
->HasObjectsInRows( nTab
, nStartRow
, nEndRow
) )
50 SdrPage
* pDrawPage
= pDrawLayer
->GetPage( static_cast<sal_uInt16
>(nTab
) );
53 bTabHasGraphics
= true;
54 FillGraphList( pDrawPage
, nTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
);
55 size_t ListSize
= aGraphList
.size();
56 for ( size_t i
= 0; i
< ListSize
; ++i
)
58 ScHTMLGraphEntry
* pE
= &aGraphList
[ i
];
60 { // not all cells: table next to some
61 bTabAlignedLeft
= sal_True
;
70 void ScHTMLExport::FillGraphList( const SdrPage
* pPage
, SCTAB nTab
,
71 SCCOL nStartCol
, SCROW nStartRow
, SCCOL nEndCol
, SCROW nEndRow
)
73 sal_uLong nObjCount
= pPage
->GetObjCount();
78 aRect
= pDoc
->GetMMRect( nStartCol
, nStartRow
, nEndCol
, nEndRow
, nTab
);
79 SdrObjListIter
aIter( *pPage
, IM_FLAT
);
80 SdrObject
* pObject
= aIter
.Next();
83 Rectangle aObjRect
= pObject
->GetCurrentBoundRect();
84 if ( bAll
|| aRect
.IsInside( aObjRect
) )
87 ScRange aR
= pDoc
->GetRange( nTab
, aObjRect
);
88 // Rectangle in mm/100
89 Size
aSize( MMToPixel( aObjRect
.GetSize() ) );
90 // If the image is somewhere in a merged range we must
91 // move the anchor to the upper left (THE span cell).
92 pDoc
->ExtendOverlapped( aR
);
93 SCCOL nCol1
= aR
.aStart
.Col();
94 SCROW nRow1
= aR
.aStart
.Row();
95 SCCOL nCol2
= aR
.aEnd
.Col();
96 SCROW nRow2
= aR
.aEnd
.Row();
97 // All cells empty under object?
98 sal_Bool bInCell
= (pDoc
->GetEmptyLinesInBlock(
99 nCol1
, nRow1
, nTab
, nCol2
, nRow2
, nTab
, DIR_TOP
)
100 == static_cast< SCSIZE
>( nRow2
- nRow1
)); // rows-1 !
102 { // Spacing in spanning cell
103 Rectangle aCellRect
= pDoc
->GetMMRect(
104 nCol1
, nRow1
, nCol2
, nRow2
, nTab
);
105 aSpace
= MMToPixel( Size(
106 aCellRect
.GetWidth() - aObjRect
.GetWidth(),
107 aCellRect
.GetHeight() - aObjRect
.GetHeight() ));
108 aSpace
.Width() += (nCol2
-nCol1
) * (nCellSpacing
+1);
109 aSpace
.Height() += (nRow2
-nRow1
) * (nCellSpacing
+1);
111 aSpace
.Height() /= 2;
113 ScHTMLGraphEntry
* pE
= new ScHTMLGraphEntry( pObject
,
114 aR
, aSize
, bInCell
, aSpace
);
115 aGraphList
.push_back( pE
);
117 pObject
= aIter
.Next();
123 void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry
* pE
)
125 SdrObject
* pObject
= pE
->pObject
;
127 aBuf
.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width
).append('=').
128 append(static_cast<sal_Int32
>(pE
->aSize
.Width()));
129 aBuf
.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height
).append('=').
130 append(static_cast<sal_Int32
>(pE
->aSize
.Height()));
133 aBuf
.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace
).append('=').
134 append(static_cast<sal_Int32
>(pE
->aSpace
.Width()));
135 aBuf
.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace
).append('=').
136 append(static_cast<sal_Int32
>(pE
->aSpace
.Height()));
138 OString aOpt
= aBuf
.makeStringAndClear();
139 switch ( pObject
->GetObjIdentifier() )
143 const SdrGrafObj
* pSGO
= (SdrGrafObj
*)pObject
;
144 const SdrGrafObjGeoData
* pGeo
= (SdrGrafObjGeoData
*)pSGO
->GetGeoData();
145 sal_uInt16 nMirrorCase
= (pGeo
->aGeo
.nDrehWink
== 18000 ?
146 ( pGeo
->bMirrored
? 3 : 4 ) : ( pGeo
->bMirrored
? 2 : 1 ));
147 sal_Bool bHMirr
= ( ( nMirrorCase
== 2 ) || ( nMirrorCase
== 4 ) );
148 sal_Bool bVMirr
= ( ( nMirrorCase
== 3 ) || ( nMirrorCase
== 4 ) );
149 sal_uLong nXOutFlags
= 0;
151 nXOutFlags
|= XOUTBMP_MIRROR_HORZ
;
153 nXOutFlags
|= XOUTBMP_MIRROR_VERT
;
155 if ( pSGO
->IsLinkedGraphic() )
156 aLinkName
= pSGO
->GetFileName();
157 WriteImage( aLinkName
, pSGO
->GetGraphic(), aOpt
, nXOutFlags
);
158 pE
->bWritten
= sal_True
;
163 const Graphic
* pGraphic
= static_cast<SdrOle2Obj
*>(pObject
)->GetGraphic();
167 WriteImage( aLinkName
, *pGraphic
, aOpt
);
168 pE
->bWritten
= sal_True
;
174 Graphic
aGraph( SdrExchangeView::GetObjGraphic(
175 pDoc
->GetDrawLayer(), pObject
) );
177 WriteImage( aLinkName
, aGraph
, aOpt
);
178 pE
->bWritten
= sal_True
;
184 void ScHTMLExport::WriteImage( String
& rLinkName
, const Graphic
& rGrf
,
185 const OString
& rImgOptions
, sal_uLong nXOutFlags
)
187 // Embedded graphic -> create an image file
188 if( !rLinkName
.Len() )
190 if( aStreamPath
.Len() > 0 )
193 String
aGrfNm( aStreamPath
);
194 nXOutFlags
|= XOUTBMP_USE_NATIVE_IF_POSSIBLE
;
195 sal_uInt16 nErr
= XOutBitmap::WriteGraphic( rGrf
, aGrfNm
,
196 String( "PNG" ), nXOutFlags
);
198 // If it worked, create a URL for the IMG tag
201 rLinkName
= URIHelper::SmartRel2Abs(
202 INetURLObject(aBaseURL
),
204 URIHelper::GetMaybeFileHdl());
206 MakeCIdURL( rLinkName
);
212 // Linked graphic - figure out the URL for the IMG tag
213 if( bCopyLocalFileToINet
|| HasCId() )
215 CopyLocalFileToINet( rLinkName
, aStreamPath
);
217 MakeCIdURL( rLinkName
);
220 rLinkName
= URIHelper::SmartRel2Abs(
221 INetURLObject(aBaseURL
),
223 URIHelper::GetMaybeFileHdl());
226 // If a URL was set, output the IMG tag.
227 // <IMG SRC="..."[ rImgOptions]>
228 if( rLinkName
.Len() )
230 rStrm
<< '<' << OOO_STRING_SVTOOLS_HTML_image
<< ' ' << OOO_STRING_SVTOOLS_HTML_O_src
<< "=\"";
231 HTMLOutFuncs::Out_String( rStrm
, URIHelper::simpleNormalizedMakeRelative(
233 rLinkName
), eDestEnc
) << '\"';
234 if ( !rImgOptions
.isEmpty() )
235 rStrm
<< rImgOptions
.getStr();
236 rStrm
<< '>' << sNewLine
<< GetIndentStr();
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */