LibreOffice Module sc (master)  1
htmlexp.hxx
Go to the documentation of this file.
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 #pragma once
21 
22 #include <rtl/textenc.h>
23 #include <tools/gen.hxx>
24 #include <tools/color.hxx>
25 #include <vcl/vclptr.hxx>
26 #include <vector>
27 #include <memory>
28 #include <map>
29 #include <svx/xoutbmp.hxx>
30 
31 #include "expbase.hxx"
32 
33 class ScDocument;
34 class SfxItemSet;
35 class SdrPage;
36 class Graphic;
37 class SdrObject;
38 class OutputDevice;
39 class ScDrawLayer;
40 class EditTextObject;
41 enum class SvtScriptType;
42 namespace editeng { class SvxBorderLine; }
43 
44 namespace sc {
45 struct ColumnBlockPosition;
46 }
47 
49 { // Defaults from stylesheet
51  OUString aFontFamilyName;
52  sal_uInt32 nFontHeight; // Item-Value
53  sal_uInt16 nFontSizeNumber; // HTML value 1-7
54  SvtScriptType nDefaultScriptType; // Font values are valid for the default script type
56 
58  nFontHeight(0),
59  nFontSizeNumber(2),
60  nDefaultScriptType(),
61  bInitialized(false)
62  {}
63 
64  const ScHTMLStyle& operator=( const ScHTMLStyle& rScHTMLStyle )
65  {
66  aBackgroundColor = rScHTMLStyle.aBackgroundColor;
67  aFontFamilyName = rScHTMLStyle.aFontFamilyName;
68  nFontHeight = rScHTMLStyle.nFontHeight;
69  nFontSizeNumber = rScHTMLStyle.nFontSizeNumber;
70  nDefaultScriptType = rScHTMLStyle.nDefaultScriptType;
71  bInitialized = rScHTMLStyle.bInitialized;
72  return *this;
73  }
74 };
75 
77 {
78  ScRange aRange; // mapped range
79  Size aSize; // size in pixels
80  Size aSpace; // spacing in pixels
82  bool bInCell; // if output is in cell
83  bool bWritten;
84 
85  ScHTMLGraphEntry( SdrObject* pObj, const ScRange& rRange,
86  const Size& rSize, bool bIn, const Size& rSpace ) :
87  aRange( rRange ),
88  aSize( rSize ),
89  aSpace( rSpace ),
90  pObject( pObj ),
91  bInCell( bIn ),
92  bWritten( false )
93  {}
94 };
95 
96 #define SC_HTML_FONTSIZES 7
97 const short nIndentMax = 23;
98 
99 class ScHTMLExport : public ScExportBase
100 {
101  // default HtmlFontSz[1-7]
102  static const sal_uInt16 nDefaultFontSize[SC_HTML_FONTSIZES];
103  // HtmlFontSz[1-7] in s*3.ini [user]
104  static sal_uInt16 nFontSize[SC_HTML_FONTSIZES];
105  static const char* pFontSizeCss[SC_HTML_FONTSIZES];
106  static const sal_uInt16 nCellSpacing;
107  static const char sIndentSource[];
108 
109  typedef std::unique_ptr<std::map<OUString, OUString> > FileNameMapPtr;
110  typedef std::vector<ScHTMLGraphEntry> GraphEntryList;
111 
112  GraphEntryList aGraphList;
114  OUString aBaseURL;
115  OUString aStreamPath;
116  VclPtr<OutputDevice> pAppWin; // for Pixel-work
117  FileNameMapPtr pFileNameMap; // for CopyLocalFileToINet
118  OUString aNonConvertibleChars; // collect nonconvertible characters
119  rtl_TextEncoding eDestEnc;
121  short nIndent;
123  bool bAll; // whole document
132 
133  const SfxItemSet& PageDefaults( SCTAB nTab );
134 
135  void WriteBody();
136  void WriteHeader();
137  void WriteOverview();
138  void WriteTables();
139  void WriteCell( sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SCROW nRow, SCTAB nTab );
141  void WriteImage( OUString& rLinkName,
142  const Graphic&, const OString& rImgOptions,
143  XOutFlags nXOutFlags = XOutFlags::NONE );
144  // nXOutFlags for XOutBitmap::WriteGraphic
145 
146  // write to stream if and only if URL fields in edit cell
147  bool WriteFieldText( const EditTextObject* pData );
148 
149  // copy a local file to internet if needed
150  void CopyLocalFileToINet( OUString& rFileNm, const OUString& rTargetNm );
151 
152  void PrepareGraphics( ScDrawLayer*, SCTAB nTab,
153  SCCOL nStartCol, SCROW nStartRow,
154  SCCOL nEndCol, SCROW nEndRow );
155 
156  void FillGraphList( const SdrPage*, SCTAB nTab,
157  SCCOL nStartCol, SCROW nStartRow,
158  SCCOL nEndCol, SCROW nEndRow );
159 
160  static OString BorderToStyle(const char* pBorderName,
161  const editeng::SvxBorderLine* pLine,
162  bool& bInsertSemicolon);
163 
164  static sal_uInt16 GetFontSizeNumber( sal_uInt16 nHeight );
165  static const char* GetFontSizeCss( sal_uInt16 nHeight );
166  sal_uInt16 ToPixel( sal_uInt16 nTwips );
167  Size MMToPixel( const Size& r100thMMSize );
168  void IncIndent( short nVal );
169 
170  const char* GetIndentStr() const
171  {
172  return sIndent;
173  }
174 
175 public:
176  ScHTMLExport( SvStream&, const OUString&, ScDocument*, const ScRange&,
177  bool bAll, const OUString& aStreamPath, std::u16string_view rFilterOptions );
178  virtual ~ScHTMLExport() override;
179  void Write();
180  const OUString& GetNonConvertibleChars() const
181  {
182  return aNonConvertibleChars;
183  }
184 };
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB nUsedTables
Definition: htmlexp.hxx:120
static const char sIndentSource[]
Definition: htmlexp.hxx:107
static const sal_uInt16 nDefaultFontSize[SC_HTML_FONTSIZES]
Definition: htmlexp.hxx:102
ScHTMLStyle aHTMLStyle
Definition: htmlexp.hxx:113
const short nIndentMax
Definition: htmlexp.hxx:97
virtual ~ScHTMLExport() override
Definition: htmlexp.cxx:247
FileNameMapPtr pFileNameMap
Definition: htmlexp.hxx:117
sal_uInt16 nFontSizeNumber
Definition: htmlexp.hxx:53
SdrObject * pObject
Definition: htmlexp.hxx:81
void WriteGraphEntry(ScHTMLGraphEntry *)
Definition: htmlexp2.cxx:114
void WriteBody()
Definition: htmlexp.cxx:554
std::unique_ptr< std::map< OUString, OUString > > FileNameMapPtr
Definition: htmlexp.hxx:109
void IncIndent(short nVal)
Definition: htmlexp.cxx:1325
bool mbSkipImages
Definition: htmlexp.hxx:129
Store position data for column array storage.
bool bCalcAsShown
Definition: htmlexp.hxx:126
void WriteImage(OUString &rLinkName, const Graphic &, const OString &rImgOptions, XOutFlags nXOutFlags=XOutFlags::NONE)
Definition: htmlexp2.cxx:173
sal_uInt16 ToPixel(sal_uInt16 nTwips)
Definition: htmlexp.cxx:272
Color aBackgroundColor
Definition: htmlexp.hxx:50
bool bTabAlignedLeft
Definition: htmlexp.hxx:125
SvtScriptType nDefaultScriptType
Definition: htmlexp.hxx:54
sal_uInt32 nFontHeight
Definition: htmlexp.hxx:52
static const char * GetFontSizeCss(sal_uInt16 nHeight)
Definition: htmlexp.cxx:266
const ScHTMLStyle & operator=(const ScHTMLStyle &rScHTMLStyle)
Definition: htmlexp.hxx:64
void WriteHeader()
Definition: htmlexp.cxx:311
void CopyLocalFileToINet(OUString &rFileNm, const OUString &rTargetNm)
Definition: htmlexp.cxx:1272
#define SC_HTML_FONTSIZES
Definition: htmlexp.hxx:96
GraphEntryList aGraphList
Definition: htmlexp.hxx:112
bool mbSkipHeaderFooter
If HTML header and footer should be written as well, or just the content itself.
Definition: htmlexp.hxx:131
bool bTabHasGraphics
Definition: htmlexp.hxx:124
const char * GetIndentStr() const
Definition: htmlexp.hxx:170
SvtScriptType
Size MMToPixel(const Size &r100thMMSize)
Definition: htmlexp.cxx:284
OUString aFontFamilyName
Definition: htmlexp.hxx:51
sal_Int16 SCCOL
Definition: types.hxx:21
bool WriteFieldText(const EditTextObject *pData)
Definition: htmlexp.cxx:1213
OUString aNonConvertibleChars
Definition: htmlexp.hxx:118
bool bTableDataHeight
Definition: htmlexp.hxx:128
sal_Int32 SCROW
Definition: types.hxx:17
ScHTMLGraphEntry(SdrObject *pObj, const ScRange &rRange, const Size &rSize, bool bIn, const Size &rSpace)
Definition: htmlexp.hxx:85
XOutFlags
OUString aStreamPath
Definition: htmlexp.hxx:115
ScRange aRange
Definition: htmlexp.hxx:78
static const char * pFontSizeCss[SC_HTML_FONTSIZES]
Definition: htmlexp.hxx:105
std::vector< ScHTMLGraphEntry > GraphEntryList
Definition: htmlexp.hxx:110
short nIndent
Definition: htmlexp.hxx:121
static sal_uInt16 GetFontSizeNumber(sal_uInt16 nHeight)
Definition: htmlexp.cxx:252
bool bCopyLocalFileToINet
Definition: htmlexp.hxx:127
bool bInitialized
Definition: htmlexp.hxx:55
rtl_TextEncoding eDestEnc
Definition: htmlexp.hxx:119
void WriteCell(sc::ColumnBlockPosition &rBlockPos, SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: htmlexp.cxx:834
static const sal_uInt16 nCellSpacing
Definition: htmlexp.hxx:106
const OUString & GetNonConvertibleChars() const
Definition: htmlexp.hxx:180
void FillGraphList(const SdrPage *, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: htmlexp2.cxx:64
void Write()
Definition: htmlexp.cxx:295
VclPtr< OutputDevice > pAppWin
Definition: htmlexp.hxx:116
OUString aBaseURL
Definition: htmlexp.hxx:114
ScHTMLExport(SvStream &, const OUString &, ScDocument *, const ScRange &, bool bAll, const OUString &aStreamPath, std::u16string_view rFilterOptions)
Definition: htmlexp.cxx:195
void WriteOverview()
Definition: htmlexp.cxx:404
void WriteTables()
Definition: htmlexp.cxx:633
void PrepareGraphics(ScDrawLayer *, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
Definition: htmlexp2.cxx:40
static OString BorderToStyle(const char *pBorderName, const editeng::SvxBorderLine *pLine, bool &bInsertSemicolon)
Definition: htmlexp.cxx:482
char sIndent[nIndentMax+1]
Definition: htmlexp.hxx:122
const SfxItemSet & PageDefaults(SCTAB nTab)
Definition: htmlexp.cxx:437
static sal_uInt16 nFontSize[SC_HTML_FONTSIZES]
Definition: htmlexp.hxx:104
sal_Int16 SCTAB
Definition: types.hxx:22