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 "scitems.hxx"
21 : #include <comphelper/string.hxx>
22 : #include <editeng/eeitem.hxx>
23 :
24 : #include <rtl/tencinfo.h>
25 :
26 : #include <vcl/svapp.hxx>
27 : #include <svx/algitem.hxx>
28 : #include <editeng/boxitem.hxx>
29 : #include <editeng/brushitem.hxx>
30 : #include <editeng/colritem.hxx>
31 : #include <editeng/fhgtitem.hxx>
32 : #include <editeng/fontitem.hxx>
33 : #include <editeng/postitem.hxx>
34 : #include <editeng/udlnitem.hxx>
35 : #include <editeng/wghtitem.hxx>
36 : #include <editeng/justifyitem.hxx>
37 : #include <svx/xoutbmp.hxx>
38 : #include <editeng/editeng.hxx>
39 : #include <svtools/htmlcfg.hxx>
40 : #include <sfx2/docfile.hxx>
41 : #include <sfx2/frmhtmlw.hxx>
42 : #include <sfx2/objsh.hxx>
43 : #include <svl/stritem.hxx>
44 : #include <svl/urihelper.hxx>
45 : #include <svl/zforlist.hxx>
46 : #include <svtools/htmlkywd.hxx>
47 : #include <svtools/htmlout.hxx>
48 : #include <svtools/parhtml.hxx>
49 : #include <vcl/outdev.hxx>
50 : #include <stdio.h>
51 :
52 : #include "htmlexp.hxx"
53 : #include "filter.hxx"
54 : #include "global.hxx"
55 : #include "document.hxx"
56 : #include "attrib.hxx"
57 : #include "patattr.hxx"
58 : #include "stlpool.hxx"
59 : #include "scresid.hxx"
60 : #include "formulacell.hxx"
61 : #include "cellform.hxx"
62 : #include "docoptio.hxx"
63 : #include "editutil.hxx"
64 : #include "ftools.hxx"
65 : #include "cellvalue.hxx"
66 :
67 : #include <editeng/flditem.hxx>
68 : #include <editeng/borderline.hxx>
69 : #include <unotools/syslocale.hxx>
70 :
71 : // Without sc.hrc: error C2679: binary '=' : no operator defined which takes a
72 : // right-hand operand of type 'const class String (__stdcall *)(class ScResId)'
73 : // at
74 : // const String aStrTable( ScResId( SCSTR_TABLE ) ); aStrOut = aStrTable;
75 : // ?!???
76 : #include "sc.hrc"
77 : #include "globstr.hrc"
78 :
79 : #include <com/sun/star/uno/Reference.h>
80 : #include <com/sun/star/document/XDocumentProperties.hpp>
81 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
82 : #include <rtl/strbuf.hxx>
83 :
84 : using ::editeng::SvxBorderLine;
85 : using namespace ::com::sun::star;
86 :
87 : const static sal_Char sMyBegComment[] = "<!-- ";
88 : const static sal_Char sMyEndComment[] = " -->";
89 : const static sal_Char sFontFamily[] = "font-family:";
90 : const static sal_Char sFontSize[] = "font-size:";
91 :
92 : const sal_uInt16 ScHTMLExport::nDefaultFontSize[SC_HTML_FONTSIZES] =
93 : {
94 : HTMLFONTSZ1_DFLT, HTMLFONTSZ2_DFLT, HTMLFONTSZ3_DFLT, HTMLFONTSZ4_DFLT,
95 : HTMLFONTSZ5_DFLT, HTMLFONTSZ6_DFLT, HTMLFONTSZ7_DFLT
96 : };
97 :
98 : sal_uInt16 ScHTMLExport::nFontSize[SC_HTML_FONTSIZES] = { 0 };
99 :
100 : const char* ScHTMLExport::pFontSizeCss[SC_HTML_FONTSIZES] =
101 : {
102 : "xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"
103 : };
104 :
105 : const sal_uInt16 ScHTMLExport::nCellSpacing = 0;
106 : const sal_Char ScHTMLExport::sIndentSource[nIndentMax+1] =
107 : "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
108 :
109 : // Macros for HTML export
110 :
111 : #define TAG_ON( tag ) HTMLOutFuncs::Out_AsciiTag( rStrm, tag )
112 : #define TAG_OFF( tag ) HTMLOutFuncs::Out_AsciiTag( rStrm, tag, false )
113 : #define OUT_STR( str ) HTMLOutFuncs::Out_String( rStrm, str, eDestEnc, &aNonConvertibleChars )
114 : #define OUT_LF() rStrm.WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() )
115 : #define TAG_ON_LF( tag ) (TAG_ON( tag ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() ))
116 : #define TAG_OFF_LF( tag ) (TAG_OFF( tag ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() ))
117 : #define OUT_HR() TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_horzrule )
118 : #define OUT_COMMENT( comment ) (rStrm.WriteCharPtr( sMyBegComment ), OUT_STR( comment ) \
119 : .WriteCharPtr( sMyEndComment ).WriteCharPtr( SAL_NEWLINE_STRING ) \
120 : .WriteCharPtr( GetIndentStr() ))
121 :
122 : #define OUT_SP_CSTR_ASS( s ) rStrm.WriteChar( ' ').WriteCharPtr( s ).WriteChar( '=' )
123 :
124 : #define GLOBSTR(id) ScGlobal::GetRscString( id )
125 :
126 6 : FltError ScFormatFilterPluginImpl::ScExportHTML( SvStream& rStrm, const OUString& rBaseURL, ScDocument* pDoc,
127 : const ScRange& rRange, const rtl_TextEncoding /*eNach*/, bool bAll,
128 : const OUString& rStreamPath, OUString& rNonConvertibleChars, const OUString& rFilterOptions )
129 : {
130 6 : ScHTMLExport aEx( rStrm, rBaseURL, pDoc, rRange, bAll, rStreamPath, rFilterOptions );
131 6 : FltError nErr = aEx.Write();
132 6 : rNonConvertibleChars = aEx.GetNonConvertibleChars();
133 6 : return nErr;
134 : }
135 :
136 6 : static OString lcl_getColGroupString(sal_Int32 nSpan, sal_Int32 nWidth)
137 : {
138 6 : OStringBuffer aByteStr(OOO_STRING_SVTOOLS_HTML_colgroup);
139 6 : aByteStr.append(' ');
140 6 : if( nSpan > 1 )
141 : {
142 6 : aByteStr.append(OOO_STRING_SVTOOLS_HTML_O_span);
143 6 : aByteStr.append("=\"");
144 6 : aByteStr.append(nSpan);
145 6 : aByteStr.append("\" ");
146 : }
147 6 : aByteStr.append(OOO_STRING_SVTOOLS_HTML_O_width);
148 6 : aByteStr.append("=\"");
149 6 : aByteStr.append(nWidth);
150 6 : aByteStr.append('"');
151 6 : return aByteStr.makeStringAndClear();
152 : }
153 :
154 0 : static void lcl_AddStamp( OUString& rStr, const OUString& rName,
155 : const ::com::sun::star::util::DateTime& rDateTime,
156 : const LocaleDataWrapper& rLoc )
157 : {
158 0 : Date aD(rDateTime.Day, rDateTime.Month, rDateTime.Year);
159 : tools::Time aT(rDateTime.Hours, rDateTime.Minutes, rDateTime.Seconds,
160 0 : rDateTime.NanoSeconds);
161 0 : DateTime aDateTime(aD,aT);
162 :
163 0 : OUString aStrDate = rLoc.getDate( aDateTime );
164 0 : OUString aStrTime = rLoc.getTime( aDateTime );
165 :
166 0 : rStr += GLOBSTR( STR_BY ) + " ";
167 0 : if (!rName.isEmpty())
168 0 : rStr += rName;
169 : else
170 0 : rStr += "???";
171 0 : rStr += " " + GLOBSTR( STR_ON ) + " ";
172 0 : if (!aStrDate.isEmpty())
173 0 : rStr += aStrDate;
174 : else
175 0 : rStr += "???";
176 0 : rStr += ", ";
177 0 : if (!aStrTime.isEmpty())
178 0 : rStr += aStrTime;
179 : else
180 0 : rStr += "???";
181 0 : }
182 :
183 8 : static OString lcl_makeHTMLColorTriplet(const Color& rColor)
184 : {
185 8 : OStringBuffer aStr( "\"#" );
186 : // <font COLOR="#00FF40">hello</font>
187 : sal_Char buf[64];
188 8 : sal_Char* p = buf;
189 8 : p += sprintf( p, "%02X", rColor.GetRed() );
190 8 : p += sprintf( p, "%02X", rColor.GetGreen() );
191 8 : p += sprintf( p, "%02X", rColor.GetBlue() );
192 8 : aStr.append(buf);
193 8 : aStr.append('\"');
194 8 : return aStr.makeStringAndClear();
195 : }
196 :
197 6 : ScHTMLExport::ScHTMLExport( SvStream& rStrmP, const OUString& rBaseURL, ScDocument* pDocP,
198 : const ScRange& rRangeP, bool bAllP,
199 : const OUString& rStreamPathP, const OUString& rFilterOptions ) :
200 : ScExportBase( rStrmP, pDocP, rRangeP ),
201 : aBaseURL( rBaseURL ),
202 : aStreamPath( rStreamPathP ),
203 : aFilterOptions( rFilterOptions ),
204 6 : pAppWin( Application::GetDefaultDevice() ),
205 : nUsedTables( 0 ),
206 : nIndent( 0 ),
207 : bAll( bAllP ),
208 : bTabHasGraphics( false ),
209 : bTabAlignedLeft( false ),
210 6 : bCalcAsShown( pDocP->GetDocOptions().IsCalcAsShown() ),
211 : bTableDataWidth( true ),
212 : bTableDataHeight( true ),
213 : mbSkipImages ( false ),
214 18 : mbSkipHeaderFooter( false )
215 : {
216 6 : strcpy( sIndent, sIndentSource );
217 6 : sIndent[0] = 0;
218 :
219 : // set HTML configuration
220 6 : SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
221 6 : eDestEnc = (pDoc->IsClipOrUndo() ? RTL_TEXTENCODING_UTF8 : rHtmlOptions.GetTextEncoding());
222 6 : bCopyLocalFileToINet = rHtmlOptions.IsSaveGraphicsLocal();
223 :
224 6 : if (rFilterOptions == "SkipImages")
225 : {
226 2 : mbSkipImages = true;
227 : }
228 4 : else if (rFilterOptions == "SkipHeaderFooter")
229 : {
230 2 : mbSkipHeaderFooter = true;
231 : }
232 :
233 48 : for ( sal_uInt16 j=0; j < SC_HTML_FONTSIZES; j++ )
234 : {
235 42 : sal_uInt16 nSize = rHtmlOptions.GetFontSize( j );
236 : // remember in Twips, like our SvxFontHeightItem
237 42 : if ( nSize )
238 42 : nFontSize[j] = nSize * 20;
239 : else
240 0 : nFontSize[j] = nDefaultFontSize[j] * 20;
241 : }
242 :
243 6 : const SCTAB nCount = pDoc->GetTableCount();
244 12 : for ( SCTAB nTab = 0; nTab < nCount; nTab++ )
245 : {
246 6 : if ( !IsEmptyTable( nTab ) )
247 6 : nUsedTables++;
248 : }
249 :
250 : // Content-Id for Mail export?
251 6 : SfxObjectShell* pDocSh = pDoc->GetDocumentShell();
252 6 : if ( pDocSh )
253 : {
254 6 : const SfxPoolItem* pItem = pDocSh->GetItem( SID_ORIGURL );
255 6 : if( pItem )
256 : {
257 0 : aCId = static_cast<const SfxStringItem *>(pItem)->GetValue();
258 : OSL_ENSURE( !aCId.isEmpty(), "CID without length!" );
259 : }
260 : }
261 6 : }
262 :
263 12 : ScHTMLExport::~ScHTMLExport()
264 : {
265 6 : aGraphList.clear();
266 6 : }
267 :
268 10 : sal_uInt16 ScHTMLExport::GetFontSizeNumber( sal_uInt16 nHeight )
269 : {
270 10 : sal_uInt16 nSize = 1;
271 60 : for ( sal_uInt16 j=SC_HTML_FONTSIZES-1; j>0; j-- )
272 : {
273 60 : if( nHeight > (nFontSize[j] + nFontSize[j-1]) / 2 )
274 : { // The one next to it
275 10 : nSize = j+1;
276 10 : break;
277 : }
278 : }
279 10 : return nSize;
280 : }
281 :
282 4 : const char* ScHTMLExport::GetFontSizeCss( sal_uInt16 nHeight )
283 : {
284 4 : sal_uInt16 nSize = GetFontSizeNumber( nHeight );
285 4 : return pFontSizeCss[ nSize-1 ];
286 : }
287 :
288 180 : sal_uInt16 ScHTMLExport::ToPixel( sal_uInt16 nVal )
289 : {
290 180 : if( nVal )
291 : {
292 : nVal = (sal_uInt16)pAppWin->LogicToPixel(
293 180 : Size( nVal, nVal ), MapMode( MAP_TWIP ) ).Width();
294 180 : if( !nVal ) // If there's a Twip there should also be a Pixel
295 0 : nVal = 1;
296 : }
297 180 : return nVal;
298 : }
299 :
300 8 : Size ScHTMLExport::MMToPixel( const Size& rSize )
301 : {
302 8 : Size aSize( rSize );
303 8 : aSize = pAppWin->LogicToPixel( rSize, MapMode( MAP_100TH_MM ) );
304 : // If there's something there should also be a Pixel
305 8 : if ( !aSize.Width() && rSize.Width() )
306 0 : aSize.Width() = 1;
307 8 : if ( !aSize.Height() && rSize.Height() )
308 0 : aSize.Height() = 1;
309 8 : return aSize;
310 : }
311 :
312 6 : sal_uLong ScHTMLExport::Write()
313 : {
314 6 : if (!mbSkipHeaderFooter)
315 : {
316 4 : rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_doctype ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_doctype40 ).WriteChar( '>' )
317 4 : .WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( SAL_NEWLINE_STRING );
318 4 : TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_html );
319 4 : WriteHeader();
320 4 : OUT_LF();
321 : }
322 6 : WriteBody();
323 6 : OUT_LF();
324 6 : if (!mbSkipHeaderFooter)
325 4 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_html );
326 :
327 6 : return rStrm.GetError();
328 : }
329 :
330 4 : void ScHTMLExport::WriteHeader()
331 : {
332 4 : IncIndent(1); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_head );
333 :
334 4 : if ( pDoc->IsClipOrUndo() )
335 : { // no real DocInfo available, but some META information like charset needed
336 0 : SfxFrameHTMLWriter::Out_DocInfo( rStrm, aBaseURL, NULL, sIndent, eDestEnc, &aNonConvertibleChars );
337 : }
338 : else
339 : {
340 : using namespace ::com::sun::star;
341 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
342 4 : pDoc->GetDocumentShell()->GetModel(), uno::UNO_QUERY_THROW);
343 : uno::Reference<document::XDocumentProperties> xDocProps
344 8 : = xDPS->getDocumentProperties();
345 : SfxFrameHTMLWriter::Out_DocInfo( rStrm, aBaseURL, xDocProps,
346 4 : sIndent, eDestEnc, &aNonConvertibleChars );
347 4 : OUT_LF();
348 :
349 4 : if (!xDocProps->getPrintedBy().isEmpty())
350 : {
351 0 : OUT_COMMENT( GLOBSTR( STR_DOC_INFO ) );
352 0 : OUString aStrOut = ( GLOBSTR( STR_DOC_PRINTED ) ) + ": ";
353 0 : lcl_AddStamp( aStrOut, xDocProps->getPrintedBy(),
354 0 : xDocProps->getPrintDate(), *ScGlobal::pLocaleData );
355 0 : OUT_COMMENT( aStrOut );
356 4 : }
357 :
358 : }
359 4 : OUT_LF();
360 :
361 : // CSS1 StyleSheet
362 4 : PageDefaults( bAll ? 0 : aRange.aStart.Tab() );
363 4 : IncIndent(1);
364 4 : rStrm.WriteCharPtr( "<" ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_style ).WriteCharPtr( " " ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_type ).WriteCharPtr( "=\"text/css\">" );
365 :
366 4 : OUT_LF();
367 4 : rStrm.WriteCharPtr( OOO_STRING_SVTOOLS_HTML_body ).WriteCharPtr( "," ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_division ).WriteCharPtr( "," ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_table ).WriteCharPtr( "," )
368 4 : .WriteCharPtr( OOO_STRING_SVTOOLS_HTML_thead ).WriteCharPtr( "," ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_tbody ).WriteCharPtr( "," ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_tfoot ).WriteCharPtr( "," )
369 4 : .WriteCharPtr( OOO_STRING_SVTOOLS_HTML_tablerow ).WriteCharPtr( "," ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_tableheader ).WriteCharPtr( "," )
370 4 : .WriteCharPtr( OOO_STRING_SVTOOLS_HTML_tabledata ).WriteCharPtr( "," ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_parabreak ).WriteCharPtr( " { " ).WriteCharPtr( sFontFamily );
371 4 : sal_Int32 nFonts = comphelper::string::getTokenCount(aHTMLStyle.aFontFamilyName, ';');
372 4 : if ( nFonts == 1 )
373 : {
374 4 : rStrm.WriteChar( '\"' );
375 4 : OUT_STR( aHTMLStyle.aFontFamilyName );
376 4 : rStrm.WriteChar( '\"' );
377 : }
378 : else
379 : { // Fontlist, VCL: Semicolon as separator
380 : // CSS1: Comma as separator and every single font name quoted
381 0 : const OUString& rList = aHTMLStyle.aFontFamilyName;
382 0 : for ( sal_Int32 j = 0, nPos = 0; j < (sal_Int32) nFonts; j++ )
383 : {
384 0 : rStrm.WriteChar( '\"' );
385 0 : OUT_STR( rList.getToken( 0, ';', nPos ) );
386 0 : rStrm.WriteChar( '\"' );
387 0 : if ( j < nFonts-1 )
388 0 : rStrm.WriteCharPtr( ", " );
389 : }
390 : }
391 4 : rStrm.WriteCharPtr( "; " ).WriteCharPtr( sFontSize )
392 8 : .WriteCharPtr( GetFontSizeCss( ( sal_uInt16 ) aHTMLStyle.nFontHeight ) ).WriteCharPtr( " }" );
393 4 : IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_style );
394 :
395 4 : IncIndent(-1); OUT_LF(); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_head );
396 4 : }
397 :
398 6 : void ScHTMLExport::WriteOverview()
399 : {
400 6 : if ( nUsedTables > 1 )
401 : {
402 0 : IncIndent(1);
403 0 : OUT_HR();
404 0 : IncIndent(1); TAG_ON( OOO_STRING_SVTOOLS_HTML_parabreak ); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_center );
405 0 : TAG_ON( OOO_STRING_SVTOOLS_HTML_head1 );
406 0 : OUT_STR( ScGlobal::GetRscString( STR_OVERVIEW ) );
407 0 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_head1 );
408 :
409 0 : OUString aStr;
410 :
411 0 : const SCTAB nCount = pDoc->GetTableCount();
412 0 : for ( SCTAB nTab = 0; nTab < nCount; nTab++ )
413 : {
414 0 : if ( !IsEmptyTable( nTab ) )
415 : {
416 0 : pDoc->GetName( nTab, aStr );
417 0 : rStrm.WriteCharPtr( "<A HREF=\"#table" )
418 0 : .WriteCharPtr( OString::number(nTab).getStr() )
419 0 : .WriteCharPtr( "\">" );
420 0 : OUT_STR( aStr );
421 0 : rStrm.WriteCharPtr( "</A>" );
422 0 : TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_linebreak );
423 : }
424 : }
425 :
426 0 : IncIndent(-1); OUT_LF();
427 0 : IncIndent(-1); TAG_OFF( OOO_STRING_SVTOOLS_HTML_center ); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_parabreak );
428 : }
429 6 : }
430 :
431 10 : const SfxItemSet& ScHTMLExport::PageDefaults( SCTAB nTab )
432 : {
433 10 : SfxStyleSheetBasePool* pStylePool = pDoc->GetStyleSheetPool();
434 10 : SfxStyleSheetBase* pStyleSheet = NULL;
435 : OSL_ENSURE( pStylePool, "StylePool not found! :-(" );
436 :
437 : // remember defaults for compare in WriteCell
438 10 : if ( !aHTMLStyle.bInitialized )
439 : {
440 6 : pStylePool->SetSearchMask( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
441 : pStyleSheet = pStylePool->Find(
442 6 : ScGlobal::GetRscString(STR_STYLENAME_STANDARD),
443 12 : SFX_STYLE_FAMILY_PARA );
444 : OSL_ENSURE( pStyleSheet, "ParaStyle not found! :-(" );
445 6 : if (!pStyleSheet)
446 0 : pStyleSheet = pStylePool->First();
447 6 : const SfxItemSet& rSetPara = pStyleSheet->GetItemSet();
448 :
449 6 : aHTMLStyle.nDefaultScriptType = ScGlobal::GetDefaultScriptType();
450 6 : aHTMLStyle.aFontFamilyName = static_cast<const SvxFontItem&>((rSetPara.Get(
451 : ScGlobal::GetScriptedWhichID(
452 : aHTMLStyle.nDefaultScriptType, ATTR_FONT
453 12 : )))).GetFamilyName();
454 : aHTMLStyle.nFontHeight = static_cast<const SvxFontHeightItem&>((rSetPara.Get(
455 : ScGlobal::GetScriptedWhichID(
456 : aHTMLStyle.nDefaultScriptType, ATTR_FONT_HEIGHT
457 6 : )))).GetHeight();
458 6 : aHTMLStyle.nFontSizeNumber = GetFontSizeNumber( static_cast< sal_uInt16 >( aHTMLStyle.nFontHeight ) );
459 : }
460 :
461 : // Page style sheet printer settings, e.g. for background graphics.
462 : // There's only one background graphic in HTML!
463 10 : pStylePool->SetSearchMask( SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL );
464 10 : pStyleSheet = pStylePool->Find( pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE );
465 : OSL_ENSURE( pStyleSheet, "PageStyle not found! :-(" );
466 10 : if (!pStyleSheet)
467 0 : pStyleSheet = pStylePool->First();
468 10 : const SfxItemSet& rSet = pStyleSheet->GetItemSet();
469 10 : if ( !aHTMLStyle.bInitialized )
470 : {
471 6 : const SvxBrushItem* pBrushItem = static_cast<const SvxBrushItem*>(&rSet.Get( ATTR_BACKGROUND ));
472 6 : aHTMLStyle.aBackgroundColor = pBrushItem->GetColor();
473 6 : aHTMLStyle.bInitialized = true;
474 : }
475 10 : return rSet;
476 : }
477 :
478 0 : OString ScHTMLExport::BorderToStyle(const char* pBorderName,
479 : const SvxBorderLine* pLine, bool& bInsertSemicolon)
480 : {
481 0 : OStringBuffer aOut;
482 :
483 0 : if ( pLine )
484 : {
485 0 : if ( bInsertSemicolon )
486 0 : aOut.append("; ");
487 :
488 : // which border
489 0 : aOut.append("border-").append(pBorderName).append(": ");
490 :
491 : // thickness
492 0 : int nWidth = pLine->GetWidth();
493 : int nPxWidth = (nWidth > 0) ?
494 0 : std::max(int(nWidth / TWIPS_PER_PIXEL), 1) : 0;
495 0 : aOut.append(static_cast<sal_Int32>(nPxWidth)).
496 0 : append("px ");
497 0 : switch (pLine->GetBorderLineStyle())
498 : {
499 : case table::BorderLineStyle::SOLID:
500 0 : aOut.append("solid");
501 0 : break;
502 : case table::BorderLineStyle::DOTTED:
503 0 : aOut.append("dotted");
504 0 : break;
505 : case table::BorderLineStyle::DASHED:
506 : case table::BorderLineStyle::DASH_DOT:
507 : case table::BorderLineStyle::DASH_DOT_DOT:
508 0 : aOut.append("dashed");
509 0 : break;
510 : case table::BorderLineStyle::DOUBLE:
511 : case table::BorderLineStyle::DOUBLE_THIN:
512 : case table::BorderLineStyle::THINTHICK_SMALLGAP:
513 : case table::BorderLineStyle::THINTHICK_MEDIUMGAP:
514 : case table::BorderLineStyle::THINTHICK_LARGEGAP:
515 : case table::BorderLineStyle::THICKTHIN_SMALLGAP:
516 : case table::BorderLineStyle::THICKTHIN_MEDIUMGAP:
517 : case table::BorderLineStyle::THICKTHIN_LARGEGAP:
518 0 : aOut.append("double");
519 0 : break;
520 : case table::BorderLineStyle::EMBOSSED:
521 0 : aOut.append("ridge");
522 0 : break;
523 : case table::BorderLineStyle::ENGRAVED:
524 0 : aOut.append("groove");
525 0 : break;
526 : case table::BorderLineStyle::OUTSET:
527 0 : aOut.append("outset");
528 0 : break;
529 : case table::BorderLineStyle::INSET:
530 0 : aOut.append("inset");
531 0 : break;
532 : default:
533 0 : aOut.append("hidden");
534 : }
535 0 : aOut.append(" #");
536 :
537 : // color
538 : char hex[7];
539 0 : snprintf( hex, 7, "%06x", static_cast< unsigned int >( pLine->GetColor().GetRGBColor() ) );
540 0 : hex[6] = 0;
541 :
542 0 : aOut.append(hex);
543 :
544 0 : bInsertSemicolon = true;
545 : }
546 :
547 0 : return aOut.makeStringAndClear();
548 : }
549 :
550 6 : void ScHTMLExport::WriteBody()
551 : {
552 6 : const SfxItemSet& rSet = PageDefaults( bAll ? 0 : aRange.aStart.Tab() );
553 6 : const SvxBrushItem* pBrushItem = static_cast<const SvxBrushItem*>(&rSet.Get( ATTR_BACKGROUND ));
554 :
555 : // default text color black
556 6 : if (!mbSkipHeaderFooter)
557 : {
558 4 : rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_body );
559 :
560 4 : if (!mbSkipImages)
561 : {
562 2 : if ( bAll && GPOS_NONE != pBrushItem->GetGraphicPos() )
563 : {
564 0 : OUString aLink = pBrushItem->GetGraphicLink();
565 0 : OUString aGrfNm;
566 :
567 : // Embedded graphic -> write using WriteGraphic
568 0 : if( aLink.isEmpty() )
569 : {
570 0 : const Graphic* pGrf = pBrushItem->GetGraphic();
571 0 : if( pGrf )
572 : {
573 : // Save graphic as (JPG) file
574 0 : aGrfNm = aStreamPath;
575 : sal_uInt16 nErr = XOutBitmap::WriteGraphic( *pGrf, aGrfNm,
576 0 : "JPG", XOUTBMP_USE_NATIVE_IF_POSSIBLE );
577 0 : if( !nErr ) // Contains errors, as we have nothing to output
578 : {
579 0 : aGrfNm = URIHelper::SmartRel2Abs(
580 : INetURLObject(aBaseURL),
581 0 : aGrfNm, URIHelper::GetMaybeFileHdl(), true, false);
582 0 : if ( HasCId() )
583 0 : MakeCIdURL( aGrfNm );
584 0 : aLink = aGrfNm;
585 : }
586 : }
587 : }
588 : else
589 : {
590 0 : aGrfNm = aLink;
591 0 : if( bCopyLocalFileToINet || HasCId() )
592 : {
593 0 : CopyLocalFileToINet( aGrfNm, aStreamPath );
594 0 : if ( HasCId() )
595 0 : MakeCIdURL( aGrfNm );
596 : }
597 : else
598 0 : aGrfNm = URIHelper::SmartRel2Abs(
599 : INetURLObject(aBaseURL),
600 0 : aGrfNm, URIHelper::GetMaybeFileHdl(), true, false);
601 0 : aLink = aGrfNm;
602 : }
603 0 : if( !aLink.isEmpty() )
604 : {
605 0 : rStrm.WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_background ).WriteCharPtr( "=\"" );
606 0 : OUT_STR( URIHelper::simpleNormalizedMakeRelative(
607 : aBaseURL,
608 0 : aLink ) ).WriteChar( '\"' );
609 0 : }
610 : }
611 : }
612 4 : if ( !aHTMLStyle.aBackgroundColor.GetTransparency() )
613 : { // A transparent background color should always result in default
614 : // background of the browser. Also, HTMLOutFuncs::Out_Color() writes
615 : // black #000000 for COL_AUTO which is the same as white #ffffff with
616 : // transparency set to 0xff, our default background.
617 0 : OUT_SP_CSTR_ASS( OOO_STRING_SVTOOLS_HTML_O_bgcolor );
618 0 : HTMLOutFuncs::Out_Color( rStrm, aHTMLStyle.aBackgroundColor );
619 : }
620 :
621 4 : rStrm.WriteChar( '>' ); OUT_LF();
622 : }
623 :
624 6 : if ( bAll )
625 6 : WriteOverview();
626 :
627 6 : WriteTables();
628 :
629 6 : if (!mbSkipHeaderFooter)
630 4 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_body );
631 6 : }
632 :
633 6 : void ScHTMLExport::WriteTables()
634 : {
635 6 : const SCTAB nTabCount = pDoc->GetTableCount();
636 6 : const OUString aStrTable( ScResId( SCSTR_TABLE ) );
637 12 : OUString aStr;
638 12 : OUString aStrOut;
639 : SCCOL nStartCol;
640 : SCROW nStartRow;
641 : SCTAB nStartTab;
642 : SCCOL nEndCol;
643 : SCROW nEndRow;
644 : SCTAB nEndTab;
645 6 : SCCOL nStartColFix = 0;
646 6 : SCROW nStartRowFix = 0;
647 6 : SCCOL nEndColFix = 0;
648 6 : SCROW nEndRowFix = 0;
649 6 : ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
650 6 : if ( bAll )
651 : {
652 6 : nStartTab = 0;
653 6 : nEndTab = nTabCount - 1;
654 : }
655 : else
656 : {
657 0 : nStartCol = nStartColFix = aRange.aStart.Col();
658 0 : nStartRow = nStartRowFix = aRange.aStart.Row();
659 0 : nStartTab = aRange.aStart.Tab();
660 0 : nEndCol = nEndColFix = aRange.aEnd.Col();
661 0 : nEndRow = nEndRowFix = aRange.aEnd.Row();
662 0 : nEndTab = aRange.aEnd.Tab();
663 : }
664 6 : SCTAB nTableStrNum = 1;
665 12 : for ( SCTAB nTab=nStartTab; nTab<=nEndTab; nTab++ )
666 : {
667 6 : if ( !pDoc->IsVisible( nTab ) )
668 0 : continue; // for
669 :
670 6 : if ( bAll )
671 : {
672 6 : if ( !GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow ) )
673 0 : continue; // for
674 :
675 6 : if ( nUsedTables > 1 )
676 : {
677 0 : aStrOut = aStrTable + " " + OUString::number( nTableStrNum++ ) + ": ";
678 :
679 0 : OUT_HR();
680 :
681 : // Write anchor
682 0 : rStrm.WriteCharPtr( "<A NAME=\"table" )
683 0 : .WriteCharPtr( OString::number(nTab).getStr() )
684 0 : .WriteCharPtr( "\">" );
685 0 : TAG_ON( OOO_STRING_SVTOOLS_HTML_head1 );
686 0 : OUT_STR( aStrOut );
687 0 : TAG_ON( OOO_STRING_SVTOOLS_HTML_emphasis );
688 :
689 0 : pDoc->GetName( nTab, aStr );
690 0 : OUT_STR( aStr );
691 :
692 0 : TAG_OFF( OOO_STRING_SVTOOLS_HTML_emphasis );
693 0 : TAG_OFF( OOO_STRING_SVTOOLS_HTML_head1 );
694 0 : rStrm.WriteCharPtr( "</A>" ); OUT_LF();
695 : }
696 : }
697 : else
698 : {
699 0 : nStartCol = nStartColFix;
700 0 : nStartRow = nStartRowFix;
701 0 : nEndCol = nEndColFix;
702 0 : nEndRow = nEndRowFix;
703 0 : if ( !TrimDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow ) )
704 0 : continue; // for
705 : }
706 :
707 : // <TABLE ...>
708 6 : OStringBuffer aByteStrOut(OOO_STRING_SVTOOLS_HTML_table);
709 :
710 6 : bTabHasGraphics = bTabAlignedLeft = false;
711 6 : if ( bAll && pDrawLayer )
712 : PrepareGraphics( pDrawLayer, nTab, nStartCol, nStartRow,
713 6 : nEndCol, nEndRow );
714 :
715 : // more <TABLE ...>
716 6 : if ( bTabAlignedLeft )
717 : {
718 0 : aByteStrOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_align).
719 0 : append("=\"").
720 0 : append(OOO_STRING_SVTOOLS_HTML_AL_left).append('"');
721 : }
722 : // ALIGN=LEFT allow text and graphics to flow around
723 : // CELLSPACING
724 6 : aByteStrOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_cellspacing).
725 6 : append("=\"").
726 6 : append(static_cast<sal_Int32>(nCellSpacing)).append('"');
727 :
728 : // BORDER=0, we do the styling of the cells in <TD>
729 6 : aByteStrOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_border).
730 6 : append("=\"0\"");
731 6 : IncIndent(1); TAG_ON_LF( aByteStrOut.makeStringAndClear().getStr() );
732 :
733 : // --- <COLGROUP> ----
734 : {
735 6 : SCCOL nCol = nStartCol;
736 6 : sal_Int32 nWidth = 0;
737 6 : sal_Int32 nSpan = 0;
738 36 : while( nCol <= nEndCol )
739 : {
740 24 : if( pDoc->ColHidden(nCol, nTab) )
741 : {
742 0 : ++nCol;
743 0 : continue;
744 : }
745 :
746 24 : if( nWidth != ToPixel( pDoc->GetColWidth( nCol, nTab ) ) )
747 : {
748 6 : if( nSpan != 0 )
749 : {
750 0 : TAG_ON(lcl_getColGroupString(nSpan, nWidth).getStr());
751 0 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_colgroup );
752 : }
753 6 : nWidth = ToPixel( pDoc->GetColWidth( nCol, nTab ) );
754 6 : nSpan = 1;
755 : }
756 : else
757 18 : nSpan++;
758 24 : nCol++;
759 : }
760 6 : if( nSpan )
761 : {
762 6 : TAG_ON(lcl_getColGroupString(nSpan, nWidth).getStr());
763 6 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_colgroup );
764 : }
765 : }
766 :
767 : // <TBODY> // Re-enable only when THEAD and TFOOT are exported
768 : // IncIndent(1); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tbody );
769 : // At least old (3.x, 4.x?) Netscape doesn't follow <TABLE COLS=n> and
770 : // <COL WIDTH=x> specified, but needs a width at every column.
771 6 : bTableDataWidth = true; // widths in first row
772 6 : bool bHasHiddenRows = pDoc->HasHiddenRows(nStartRow, nEndRow, nTab);
773 42 : for ( SCROW nRow=nStartRow; nRow<=nEndRow; nRow++ )
774 : {
775 36 : if ( bHasHiddenRows && pDoc->RowHidden(nRow, nTab) )
776 : {
777 0 : nRow = pDoc->FirstVisibleRow(nRow+1, nEndRow, nTab);
778 0 : --nRow;
779 0 : continue; // for
780 : }
781 :
782 36 : IncIndent(1); TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
783 36 : bTableDataHeight = true; // height at every first cell of each row
784 204 : for ( SCCOL nCol2=nStartCol; nCol2<=nEndCol; nCol2++ )
785 : {
786 168 : if ( pDoc->ColHidden(nCol2, nTab) )
787 0 : continue; // for
788 :
789 168 : if ( nCol2 == nEndCol )
790 36 : IncIndent(-1);
791 168 : WriteCell( nCol2, nRow, nTab );
792 168 : bTableDataHeight = false;
793 : }
794 36 : bTableDataWidth = false; // widths only in first row
795 :
796 36 : if ( nRow == nEndRow )
797 6 : IncIndent(-1);
798 36 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tablerow );
799 : }
800 : // TODO: Uncomment later
801 : // IncIndent(-1); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tbody );
802 :
803 6 : IncIndent(-1); TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_table );
804 :
805 6 : if ( bTabHasGraphics && !mbSkipImages )
806 : {
807 : // the rest that is not in a cell
808 2 : size_t ListSize = aGraphList.size();
809 4 : for ( size_t i = 0; i < ListSize; ++i )
810 : {
811 2 : ScHTMLGraphEntry* pE = &aGraphList[ i ];
812 2 : if ( !pE->bWritten )
813 0 : WriteGraphEntry( pE );
814 : }
815 2 : aGraphList.clear();
816 2 : if ( bTabAlignedLeft )
817 : {
818 : // clear <TABLE ALIGN=LEFT> with <BR CLEAR=LEFT>
819 0 : aByteStrOut.append(OOO_STRING_SVTOOLS_HTML_linebreak);
820 0 : aByteStrOut.append(' ').
821 0 : append(OOO_STRING_SVTOOLS_HTML_O_clear).append('=').
822 0 : append(OOO_STRING_SVTOOLS_HTML_AL_left);
823 0 : TAG_ON_LF( aByteStrOut.makeStringAndClear().getStr() );
824 : }
825 : }
826 :
827 6 : if ( bAll )
828 6 : OUT_COMMENT( OUString("**************************************************************************") );
829 12 : }
830 6 : }
831 :
832 168 : void ScHTMLExport::WriteCell( SCCOL nCol, SCROW nRow, SCTAB nTab )
833 : {
834 168 : const ScPatternAttr* pAttr = pDoc->GetPattern( nCol, nRow, nTab );
835 168 : const SfxItemSet* pCondItemSet = pDoc->GetCondResult( nCol, nRow, nTab );
836 :
837 168 : const ScMergeFlagAttr& rMergeFlagAttr = static_cast<const ScMergeFlagAttr&>( pAttr->GetItem( ATTR_MERGE_FLAG, pCondItemSet ) );
838 168 : if ( rMergeFlagAttr.IsOverlapped() )
839 18 : return ;
840 :
841 168 : ScAddress aPos( nCol, nRow, nTab );
842 168 : ScHTMLGraphEntry* pGraphEntry = NULL;
843 168 : if ( bTabHasGraphics && !mbSkipImages )
844 : {
845 80 : size_t ListSize = aGraphList.size();
846 140 : for ( size_t i = 0; i < ListSize; ++i )
847 : {
848 80 : ScHTMLGraphEntry* pE = &aGraphList[ i ];
849 80 : if ( pE->bInCell && pE->aRange.In( aPos ) )
850 : {
851 20 : if ( pE->aRange.aStart == aPos )
852 : {
853 2 : pGraphEntry = pE;
854 2 : break; // for
855 : }
856 : else
857 18 : return ; // Is a Col/RowSpan, Overlapped
858 : }
859 : }
860 : }
861 :
862 150 : ScRefCellValue aCell;
863 150 : aCell.assign(*pDoc, aPos);
864 :
865 150 : sal_uLong nFormat = pAttr->GetNumberFormat( pFormatter );
866 150 : bool bValueData = aCell.hasNumeric();
867 150 : sal_uInt8 nScriptType = 0;
868 150 : if (!aCell.isEmpty())
869 80 : nScriptType = pDoc->GetScriptType(nCol, nRow, nTab);
870 :
871 150 : if ( nScriptType == 0 )
872 70 : nScriptType = aHTMLStyle.nDefaultScriptType;
873 :
874 300 : OStringBuffer aStrTD(OOO_STRING_SVTOOLS_HTML_tabledata);
875 :
876 : // border of the cells
877 150 : const SvxBoxItem* pBorder = static_cast<const SvxBoxItem*>( pDoc->GetAttr( nCol, nRow, nTab, ATTR_BORDER ) );
878 150 : if ( pBorder && (pBorder->GetTop() || pBorder->GetBottom() || pBorder->GetLeft() || pBorder->GetRight()) )
879 : {
880 0 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_style).
881 0 : append("=\"");
882 :
883 0 : bool bInsertSemicolon = false;
884 : aStrTD.append(BorderToStyle("top", pBorder->GetTop(),
885 0 : bInsertSemicolon));
886 : aStrTD.append(BorderToStyle("bottom", pBorder->GetBottom(),
887 0 : bInsertSemicolon));
888 : aStrTD.append(BorderToStyle("left", pBorder->GetLeft(),
889 0 : bInsertSemicolon));
890 : aStrTD.append(BorderToStyle("right", pBorder->GetRight(),
891 0 : bInsertSemicolon));
892 :
893 0 : aStrTD.append('"');
894 : }
895 :
896 : const sal_Char* pChar;
897 : sal_uInt16 nHeightPixel;
898 :
899 150 : const ScMergeAttr& rMergeAttr = static_cast<const ScMergeAttr&>( pAttr->GetItem( ATTR_MERGE, pCondItemSet ) );
900 150 : if ( pGraphEntry || rMergeAttr.IsMerged() )
901 : {
902 : SCCOL nC, jC;
903 : SCROW nR;
904 : sal_uLong v;
905 2 : if ( pGraphEntry )
906 2 : nC = std::max( SCCOL(pGraphEntry->aRange.aEnd.Col() - nCol + 1),
907 4 : SCCOL(rMergeAttr.GetColMerge()) );
908 : else
909 0 : nC = rMergeAttr.GetColMerge();
910 2 : if ( nC > 1 )
911 : {
912 2 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_colspan).
913 4 : append('=').append(static_cast<sal_Int32>(nC));
914 2 : nC = nC + nCol;
915 6 : for ( jC=nCol, v=0; jC<nC; jC++ )
916 4 : v += pDoc->GetColWidth( jC, nTab );
917 : }
918 :
919 2 : if ( pGraphEntry )
920 2 : nR = std::max( SCROW(pGraphEntry->aRange.aEnd.Row() - nRow + 1),
921 4 : SCROW(rMergeAttr.GetRowMerge()) );
922 : else
923 0 : nR = rMergeAttr.GetRowMerge();
924 2 : if ( nR > 1 )
925 : {
926 2 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_rowspan).
927 2 : append('=').append(static_cast<sal_Int32>(nR));
928 2 : nR += nRow;
929 2 : v = pDoc->GetRowHeight( nRow, nR-1, nTab );
930 2 : nHeightPixel = ToPixel( static_cast< sal_uInt16 >( v ) );
931 : }
932 : else
933 0 : nHeightPixel = ToPixel( pDoc->GetRowHeight( nRow, nTab ) );
934 : }
935 : else
936 148 : nHeightPixel = ToPixel( pDoc->GetRowHeight( nRow, nTab ) );
937 :
938 150 : if ( bTableDataHeight )
939 : {
940 36 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).
941 36 : append("=\"").
942 72 : append(static_cast<sal_Int32>(nHeightPixel)).append('"');
943 : }
944 :
945 : const SvxFontItem& rFontItem = static_cast<const SvxFontItem&>( pAttr->GetItem(
946 150 : ScGlobal::GetScriptedWhichID( nScriptType, ATTR_FONT),
947 150 : pCondItemSet) );
948 :
949 : const SvxFontHeightItem& rFontHeightItem = static_cast<const SvxFontHeightItem&>(
950 : pAttr->GetItem( ScGlobal::GetScriptedWhichID( nScriptType,
951 150 : ATTR_FONT_HEIGHT), pCondItemSet) );
952 :
953 : const SvxWeightItem& rWeightItem = static_cast<const SvxWeightItem&>( pAttr->GetItem(
954 150 : ScGlobal::GetScriptedWhichID( nScriptType, ATTR_FONT_WEIGHT),
955 150 : pCondItemSet) );
956 :
957 : const SvxPostureItem& rPostureItem = static_cast<const SvxPostureItem&>(
958 : pAttr->GetItem( ScGlobal::GetScriptedWhichID( nScriptType,
959 150 : ATTR_FONT_POSTURE), pCondItemSet) );
960 :
961 : const SvxUnderlineItem& rUnderlineItem = static_cast<const SvxUnderlineItem&>(
962 150 : pAttr->GetItem( ATTR_FONT_UNDERLINE, pCondItemSet ) );
963 :
964 : const SvxColorItem& rColorItem = static_cast<const SvxColorItem&>( pAttr->GetItem(
965 150 : ATTR_FONT_COLOR, pCondItemSet ) );
966 :
967 : const SvxHorJustifyItem& rHorJustifyItem = static_cast<const SvxHorJustifyItem&>(
968 150 : pAttr->GetItem( ATTR_HOR_JUSTIFY, pCondItemSet ) );
969 :
970 : const SvxVerJustifyItem& rVerJustifyItem = static_cast<const SvxVerJustifyItem&>(
971 150 : pAttr->GetItem( ATTR_VER_JUSTIFY, pCondItemSet ) );
972 :
973 : const SvxBrushItem& rBrushItem = static_cast<const SvxBrushItem&>( pAttr->GetItem(
974 150 : ATTR_BACKGROUND, pCondItemSet ) );
975 :
976 150 : Color aBgColor;
977 150 : if ( rBrushItem.GetColor().GetTransparency() == 255 )
978 150 : aBgColor = aHTMLStyle.aBackgroundColor; // No unwanted background color
979 : else
980 0 : aBgColor = rBrushItem.GetColor();
981 :
982 150 : bool bBold = ( WEIGHT_BOLD <= rWeightItem.GetWeight() );
983 150 : bool bItalic = ( ITALIC_NONE != rPostureItem.GetPosture() );
984 150 : bool bUnderline = ( UNDERLINE_NONE != rUnderlineItem.GetLineStyle() );
985 150 : bool bSetFontColor = ( COL_AUTO != rColorItem.GetValue().GetColor() ); // default is AUTO now
986 150 : bool bSetFontName = ( aHTMLStyle.aFontFamilyName != rFontItem.GetFamilyName() );
987 150 : sal_uInt16 nSetFontSizeNumber = 0;
988 150 : sal_uInt32 nFontHeight = rFontHeightItem.GetHeight();
989 150 : if ( nFontHeight != aHTMLStyle.nFontHeight )
990 : {
991 0 : nSetFontSizeNumber = GetFontSizeNumber( (sal_uInt16) nFontHeight );
992 0 : if ( nSetFontSizeNumber == aHTMLStyle.nFontSizeNumber )
993 0 : nSetFontSizeNumber = 0; // no difference, don't set
994 : }
995 :
996 150 : bool bSetFont = (bSetFontColor || bSetFontName || nSetFontSizeNumber);
997 :
998 : //! TODO: we could entirely use CSS1 here instead, but that would exclude
999 : //! Netscape 3.0 and Netscape 4.x without JavaScript enabled.
1000 : //! Do we want that?
1001 :
1002 150 : switch( rHorJustifyItem.GetValue() )
1003 : {
1004 : case SVX_HOR_JUSTIFY_STANDARD:
1005 150 : pChar = (bValueData ? OOO_STRING_SVTOOLS_HTML_AL_right : OOO_STRING_SVTOOLS_HTML_AL_left);
1006 150 : break;
1007 0 : case SVX_HOR_JUSTIFY_CENTER: pChar = OOO_STRING_SVTOOLS_HTML_AL_center; break;
1008 0 : case SVX_HOR_JUSTIFY_BLOCK: pChar = OOO_STRING_SVTOOLS_HTML_AL_justify; break;
1009 0 : case SVX_HOR_JUSTIFY_RIGHT: pChar = OOO_STRING_SVTOOLS_HTML_AL_right; break;
1010 : case SVX_HOR_JUSTIFY_LEFT:
1011 : case SVX_HOR_JUSTIFY_REPEAT:
1012 0 : default: pChar = OOO_STRING_SVTOOLS_HTML_AL_left; break;
1013 : }
1014 :
1015 150 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_align).
1016 150 : append("=\"").append(pChar).append('"');
1017 :
1018 150 : switch( rVerJustifyItem.GetValue() )
1019 : {
1020 0 : case SVX_VER_JUSTIFY_TOP: pChar = OOO_STRING_SVTOOLS_HTML_VA_top; break;
1021 0 : case SVX_VER_JUSTIFY_CENTER: pChar = OOO_STRING_SVTOOLS_HTML_VA_middle; break;
1022 0 : case SVX_VER_JUSTIFY_BOTTOM: pChar = OOO_STRING_SVTOOLS_HTML_VA_bottom; break;
1023 : case SVX_VER_JUSTIFY_STANDARD:
1024 150 : default: pChar = NULL;
1025 : }
1026 150 : if ( pChar )
1027 : {
1028 0 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_valign).
1029 0 : append('=').append(pChar);
1030 : }
1031 :
1032 150 : if ( aHTMLStyle.aBackgroundColor != aBgColor )
1033 : {
1034 0 : aStrTD.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_bgcolor).
1035 0 : append('=');
1036 0 : aStrTD.append(lcl_makeHTMLColorTriplet(aBgColor));
1037 : }
1038 :
1039 150 : double fVal = 0.0;
1040 150 : if ( bValueData )
1041 : {
1042 20 : switch (aCell.meType)
1043 : {
1044 : case CELLTYPE_VALUE:
1045 20 : fVal = aCell.mfValue;
1046 20 : if ( bCalcAsShown && fVal != 0.0 )
1047 0 : fVal = pDoc->RoundValueAsShown( fVal, nFormat );
1048 20 : break;
1049 : case CELLTYPE_FORMULA:
1050 0 : fVal = aCell.mpFormula->GetValue();
1051 0 : break;
1052 : default:
1053 : OSL_FAIL( "value data with unsupported cell type" );
1054 : }
1055 : }
1056 :
1057 : aStrTD.append(HTMLOutFuncs::CreateTableDataOptionsValNum(bValueData, fVal,
1058 150 : nFormat, *pFormatter, eDestEnc, &aNonConvertibleChars));
1059 :
1060 150 : TAG_ON(aStrTD.makeStringAndClear().getStr());
1061 :
1062 150 : if ( bBold ) TAG_ON( OOO_STRING_SVTOOLS_HTML_bold );
1063 150 : if ( bItalic ) TAG_ON( OOO_STRING_SVTOOLS_HTML_italic );
1064 150 : if ( bUnderline ) TAG_ON( OOO_STRING_SVTOOLS_HTML_underline );
1065 :
1066 150 : if ( bSetFont )
1067 : {
1068 8 : OStringBuffer aStr(OOO_STRING_SVTOOLS_HTML_font);
1069 8 : if ( bSetFontName )
1070 : {
1071 0 : aStr.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_face).
1072 0 : append("=\"");
1073 0 : sal_Int32 nFonts = comphelper::string::getTokenCount(rFontItem.GetFamilyName(), ';');
1074 0 : if ( nFonts == 1 )
1075 : {
1076 : OString aTmpStr = HTMLOutFuncs::ConvertStringToHTML(
1077 0 : rFontItem.GetFamilyName(), eDestEnc, &aNonConvertibleChars);
1078 0 : aStr.append(aTmpStr);
1079 : }
1080 : else
1081 : { // Font list, VCL: Semicolon as separator, HTML: Comma
1082 0 : const OUString& rList = rFontItem.GetFamilyName();
1083 0 : for ( sal_Int32 j = 0, nPos = 0; j < (sal_Int32)nFonts; j++ )
1084 : {
1085 : OString aTmpStr = HTMLOutFuncs::ConvertStringToHTML(
1086 : rList.getToken( 0, ';', nPos ), eDestEnc,
1087 0 : &aNonConvertibleChars);
1088 0 : aStr.append(aTmpStr);
1089 0 : if ( j < nFonts-1 )
1090 0 : aStr.append(',');
1091 0 : }
1092 : }
1093 0 : aStr.append('\"');
1094 : }
1095 8 : if ( nSetFontSizeNumber )
1096 : {
1097 0 : aStr.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_size).
1098 0 : append('=').append(static_cast<sal_Int32>(nSetFontSizeNumber));
1099 : }
1100 8 : if ( bSetFontColor )
1101 : {
1102 8 : Color aColor = rColorItem.GetValue();
1103 :
1104 : // always export automatic text color as black
1105 8 : if ( aColor.GetColor() == COL_AUTO )
1106 0 : aColor.SetColor( COL_BLACK );
1107 :
1108 8 : aStr.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_color).
1109 16 : append('=').append(lcl_makeHTMLColorTriplet(aColor));
1110 : }
1111 8 : TAG_ON(aStr.makeStringAndClear().getStr());
1112 : }
1113 :
1114 150 : OUString aStrOut;
1115 150 : bool bFieldText = false;
1116 :
1117 : Color* pColor;
1118 150 : switch (aCell.meType)
1119 : {
1120 : case CELLTYPE_EDIT :
1121 0 : bFieldText = WriteFieldText(aCell.mpEditText);
1122 0 : if ( bFieldText )
1123 0 : break;
1124 : //! else: fallthru
1125 : default:
1126 150 : ScCellFormat::GetString(aCell, nFormat, aStrOut, &pColor, *pFormatter, pDoc);
1127 : }
1128 :
1129 150 : if ( !bFieldText )
1130 : {
1131 150 : if ( aStrOut.isEmpty() )
1132 : {
1133 70 : TAG_ON( OOO_STRING_SVTOOLS_HTML_linebreak ); // No completely empty line
1134 : }
1135 : else
1136 : {
1137 80 : OUString aStr = aStrOut;
1138 80 : sal_Int32 nPos = aStr.indexOf( '\n' );
1139 80 : if ( nPos == -1 )
1140 : {
1141 80 : OUT_STR( aStrOut );
1142 : }
1143 : else
1144 : {
1145 0 : sal_Int32 nStartPos = 0;
1146 0 : do
1147 : {
1148 0 : OUString aSingleLine = aStr.copy( nStartPos, nPos - nStartPos );
1149 0 : OUT_STR( aSingleLine );
1150 0 : TAG_ON( OOO_STRING_SVTOOLS_HTML_linebreak );
1151 0 : nStartPos = nPos + 1;
1152 : }
1153 : while( ( nPos = aStr.indexOf( '\n', nStartPos ) ) != -1 );
1154 0 : OUString aSingleLine = aStr.copy( nStartPos, aStr.getLength() - nStartPos );
1155 0 : OUT_STR( aSingleLine );
1156 80 : }
1157 : }
1158 : }
1159 150 : if ( pGraphEntry )
1160 2 : WriteGraphEntry( pGraphEntry );
1161 :
1162 150 : if ( bSetFont ) TAG_OFF( OOO_STRING_SVTOOLS_HTML_font );
1163 150 : if ( bUnderline ) TAG_OFF( OOO_STRING_SVTOOLS_HTML_underline );
1164 150 : if ( bItalic ) TAG_OFF( OOO_STRING_SVTOOLS_HTML_italic );
1165 150 : if ( bBold ) TAG_OFF( OOO_STRING_SVTOOLS_HTML_bold );
1166 :
1167 300 : TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_tabledata );
1168 : }
1169 :
1170 0 : bool ScHTMLExport::WriteFieldText( const EditTextObject* pData )
1171 : {
1172 0 : bool bFields = false;
1173 : // text and anchor of URL fields, Doc-Engine is a ScFieldEditEngine
1174 0 : EditEngine& rEngine = pDoc->GetEditEngine();
1175 0 : rEngine.SetText( *pData );
1176 0 : sal_Int32 nParas = rEngine.GetParagraphCount();
1177 0 : if ( nParas )
1178 : {
1179 0 : ESelection aSel( 0, 0, nParas-1, rEngine.GetTextLen( nParas-1 ) );
1180 0 : SfxItemSet aSet( rEngine.GetAttribs( aSel ) );
1181 0 : SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, false );
1182 0 : if ( eFieldState == SfxItemState::DONTCARE || eFieldState == SfxItemState::SET )
1183 0 : bFields = true;
1184 : }
1185 0 : if ( bFields )
1186 : {
1187 0 : bool bOldUpdateMode = rEngine.GetUpdateMode();
1188 0 : rEngine.SetUpdateMode( true ); // no portions if not formatted
1189 0 : for ( sal_Int32 nPar=0; nPar < nParas; nPar++ )
1190 : {
1191 0 : if ( nPar > 0 )
1192 0 : TAG_ON( OOO_STRING_SVTOOLS_HTML_linebreak );
1193 0 : std::vector<sal_Int32> aPortions;
1194 0 : rEngine.GetPortions( nPar, aPortions );
1195 0 : sal_Int32 nStart = 0;
1196 0 : for ( std::vector<sal_Int32>::const_iterator it(aPortions.begin()); it != aPortions.end(); ++it )
1197 : {
1198 0 : sal_Int32 nEnd = *it;
1199 0 : ESelection aSel( nPar, nStart, nPar, nEnd );
1200 0 : bool bUrl = false;
1201 : // fields are single characters
1202 0 : if ( nEnd == nStart+1 )
1203 : {
1204 : const SfxPoolItem* pItem;
1205 0 : SfxItemSet aSet = rEngine.GetAttribs( aSel );
1206 0 : if ( aSet.GetItemState( EE_FEATURE_FIELD, false, &pItem ) == SfxItemState::SET )
1207 : {
1208 0 : const SvxFieldData* pField = static_cast<const SvxFieldItem*>(pItem)->GetField();
1209 0 : if ( pField && pField->ISA(SvxURLField) )
1210 : {
1211 0 : bUrl = true;
1212 0 : const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
1213 : // String aFieldText = rEngine.GetText( aSel );
1214 0 : rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_anchor ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_href ).WriteCharPtr( "=\"" );
1215 0 : OUT_STR( pURLField->GetURL() );
1216 0 : rStrm.WriteCharPtr( "\">" );
1217 0 : OUT_STR( pURLField->GetRepresentation() );
1218 0 : rStrm.WriteCharPtr( "</" ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_anchor ).WriteChar( '>' );
1219 : }
1220 0 : }
1221 : }
1222 0 : if ( !bUrl )
1223 0 : OUT_STR( rEngine.GetText( aSel ) );
1224 0 : nStart = nEnd;
1225 : }
1226 0 : }
1227 0 : rEngine.SetUpdateMode( bOldUpdateMode );
1228 : }
1229 0 : return bFields;
1230 : }
1231 :
1232 0 : bool ScHTMLExport::CopyLocalFileToINet( OUString& rFileNm,
1233 : const OUString& rTargetNm, bool bFileToFile )
1234 : {
1235 0 : bool bRet = false;
1236 0 : INetURLObject aFileUrl, aTargetUrl;
1237 0 : aFileUrl.SetSmartURL( rFileNm );
1238 0 : aTargetUrl.SetSmartURL( rTargetNm );
1239 0 : if( INET_PROT_FILE == aFileUrl.GetProtocol() &&
1240 0 : ( (bFileToFile && INET_PROT_FILE == aTargetUrl.GetProtocol()) ||
1241 0 : (!bFileToFile && INET_PROT_FILE != aTargetUrl.GetProtocol() &&
1242 0 : INET_PROT_FTP <= aTargetUrl.GetProtocol() &&
1243 0 : INET_PROT_NEWS >= aTargetUrl.GetProtocol()) ) )
1244 : {
1245 0 : if( pFileNameMap )
1246 : {
1247 : // Did we already move the file?
1248 0 : std::map<OUString, OUString>::iterator it = pFileNameMap->find( rFileNm );
1249 0 : if( it != pFileNameMap->end() )
1250 : {
1251 0 : rFileNm = it->second;
1252 0 : return true;
1253 : }
1254 : }
1255 : else
1256 : {
1257 0 : pFileNameMap.reset( new std::map<OUString, OUString>() );
1258 : }
1259 :
1260 0 : SvFileStream aTmp( aFileUrl.PathToFileName(), STREAM_READ );
1261 :
1262 0 : OUString aSrc = rFileNm;
1263 0 : OUString aDest = aTargetUrl.GetPartBeforeLastName();
1264 0 : aDest += aFileUrl.GetName();
1265 :
1266 0 : if( bFileToFile )
1267 : {
1268 0 : INetURLObject aCpyURL( aDest );
1269 0 : SvFileStream aCpy( aCpyURL.PathToFileName(), STREAM_WRITE );
1270 0 : aCpy.WriteStream( aTmp );
1271 :
1272 0 : aCpy.Close();
1273 0 : bRet = SVSTREAM_OK == aCpy.GetError();
1274 : }
1275 : else
1276 : {
1277 0 : SfxMedium aMedium( aDest, STREAM_WRITE | STREAM_SHARE_DENYNONE );
1278 :
1279 : {
1280 0 : SvFileStream aCpy( aMedium.GetPhysicalName(), STREAM_WRITE );
1281 0 : aCpy.WriteStream( aTmp );
1282 : }
1283 :
1284 : // Take over
1285 0 : aMedium.Close();
1286 0 : aMedium.Commit();
1287 :
1288 0 : bRet = 0 == aMedium.GetError();
1289 : }
1290 :
1291 0 : if( bRet )
1292 : {
1293 0 : pFileNameMap->insert( std::make_pair( aSrc, aDest ) );
1294 0 : rFileNm = aDest;
1295 0 : }
1296 : }
1297 :
1298 0 : return bRet;
1299 : }
1300 :
1301 0 : void ScHTMLExport::MakeCIdURL( OUString& rURL )
1302 : {
1303 0 : if( aCId.isEmpty() )
1304 0 : return;
1305 :
1306 0 : INetURLObject aURLObj( rURL );
1307 0 : if( INET_PROT_FILE != aURLObj.GetProtocol() )
1308 0 : return;
1309 :
1310 0 : OUString aLastName( aURLObj.GetLastName().toAsciiLowerCase() );
1311 : OSL_ENSURE( !aLastName.isEmpty(), "filename without length!" );
1312 :
1313 0 : rURL = "cid:" + aLastName + "." + aCId;
1314 : }
1315 :
1316 106 : void ScHTMLExport::IncIndent( short nVal )
1317 : {
1318 106 : sIndent[nIndent] = '\t';
1319 106 : nIndent = nIndent + nVal;
1320 106 : if ( nIndent < 0 )
1321 6 : nIndent = 0;
1322 100 : else if ( nIndent > nIndentMax )
1323 0 : nIndent = nIndentMax;
1324 106 : sIndent[nIndent] = 0;
1325 154 : }
1326 :
1327 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|