1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <o3tl/any.hxx>
#include <osl/thread.h>
#include <svtools/htmlcfg.hxx>
#include <svtools/parhtml.hxx>
#include <unotools/syslocale.hxx>
#include <tools/debug.hxx>
#include <rtl/instance.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <com/sun/star/uno/Sequence.hxx>
namespace {
enum class HtmlCfgFlags {
NONE = 0x000,
UnknownTags = 0x001,
StarBasic = 0x008,
LocalGrf = 0x010,
PrintLayoutExtension = 0x020,
IgnoreFontFamily = 0x040,
IsBasicWarning = 0x080,
NumbersEnglishUS = 0x100,
};
}
namespace o3tl {
template<> struct typed_flags<HtmlCfgFlags> : is_typed_flags<HtmlCfgFlags, 0x1f9> {};
}
using namespace utl;
using namespace com::sun::star::uno;
struct HtmlOptions_Impl
{
HtmlCfgFlags nFlags;
sal_Int32 nExportMode;
sal_Int32 aFontSizeArr[HTML_FONT_COUNT];
sal_Int32 eEncoding;
bool bIsEncodingDefault;
HtmlOptions_Impl() :
nFlags(HtmlCfgFlags::LocalGrf|HtmlCfgFlags::IsBasicWarning),
nExportMode(HTML_CFG_NS40),
eEncoding( osl_getThreadTextEncoding() ),
bIsEncodingDefault(true)
{
aFontSizeArr[0] = HTMLFONTSZ1_DFLT;
aFontSizeArr[1] = HTMLFONTSZ2_DFLT;
aFontSizeArr[2] = HTMLFONTSZ3_DFLT;
aFontSizeArr[3] = HTMLFONTSZ4_DFLT;
aFontSizeArr[4] = HTMLFONTSZ5_DFLT;
aFontSizeArr[5] = HTMLFONTSZ6_DFLT;
aFontSizeArr[6] = HTMLFONTSZ7_DFLT;
}
};
const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
{
static Sequence<OUString> const aNames
{
"Import/UnknownTag", // 0
"Import/FontSetting", // 1
"Import/FontSize/Size_1", // 2
"Import/FontSize/Size_2", // 3
"Import/FontSize/Size_3", // 4
"Import/FontSize/Size_4", // 5
"Import/FontSize/Size_5", // 6
"Import/FontSize/Size_6", // 7
"Import/FontSize/Size_7", // 8
"Export/Browser", // 9
"Export/Basic", // 0
"Export/PrintLayout", // 11
"Export/LocalGraphic", // 12
"Export/Warning", // 13
"Export/Encoding", // 14
"Import/NumbersEnglishUS" // 15
};
return aNames;
}
SvxHtmlOptions::SvxHtmlOptions() :
ConfigItem("Office.Common/Filter/HTML"),
pImpl( new HtmlOptions_Impl )
{
Load( GetPropertyNames() );
}
SvxHtmlOptions::~SvxHtmlOptions()
{
}
void SvxHtmlOptions::Load( const Sequence< OUString >& aNames )
{
Sequence<Any> aValues = GetProperties(aNames);
const Any* pValues = aValues.getConstArray();
DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
if(aValues.getLength() != aNames.getLength())
return;
pImpl->nFlags = HtmlCfgFlags::NONE;
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
if(pValues[nProp].hasValue())
{
switch(nProp)
{
case 0:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::UnknownTags;
break;//"Import/UnknownTag",
case 1:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::IgnoreFontFamily;
break;//"Import/FontSetting",
case 2: pValues[nProp] >>= pImpl->aFontSizeArr[0]; break;//"Import/FontSize/Size_1",
case 3: pValues[nProp] >>= pImpl->aFontSizeArr[1]; break;//"Import/FontSize/Size_2",
case 4: pValues[nProp] >>= pImpl->aFontSizeArr[2]; break;//"Import/FontSize/Size_3",
case 5: pValues[nProp] >>= pImpl->aFontSizeArr[3]; break;//"Import/FontSize/Size_4",
case 6: pValues[nProp] >>= pImpl->aFontSizeArr[4]; break;//"Import/FontSize/Size_5",
case 7: pValues[nProp] >>= pImpl->aFontSizeArr[5]; break;//"Import/FontSize/Size_6",
case 8: pValues[nProp] >>= pImpl->aFontSizeArr[6]; break;//"Import/FontSize/Size_7",
case 9://"Export/Browser",
{
sal_Int32 nExpMode = 0;
pValues[nProp] >>= nExpMode;
switch( nExpMode )
{
case 1: nExpMode = HTML_CFG_MSIE; break;
case 3: nExpMode = HTML_CFG_WRITER; break;
case 4: nExpMode = HTML_CFG_NS40; break;
default: nExpMode = HTML_CFG_NS40; break;
}
pImpl->nExportMode = nExpMode;
}
break;
case 10:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::StarBasic;
break;//"Export/Basic",
case 11:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::PrintLayoutExtension;
break;//"Export/PrintLayout",
case 12:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::LocalGrf;
break;//"Export/LocalGraphic",
case 13:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::IsBasicWarning;
break;//"Export/Warning"
case 14: pValues[nProp] >>= pImpl->eEncoding;
pImpl->bIsEncodingDefault = false;
break;//"Export/Encoding"
case 15:
if(*o3tl::doAccess<bool>(pValues[nProp]))
pImpl->nFlags |= HtmlCfgFlags::NumbersEnglishUS;
break;//"Import/NumbersEnglishUS"
}
}
}
}
void SvxHtmlOptions::ImplCommit()
{
const Sequence<OUString>& aNames = GetPropertyNames();
Sequence<Any> aValues(aNames.getLength());
Any* pValues = aValues.getArray();
for(int nProp = 0; nProp < aNames.getLength(); nProp++)
{
bool bSet = false;
switch(nProp)
{
case 0: bSet = bool(pImpl->nFlags & HtmlCfgFlags::UnknownTags);break;//"Import/UnknownTag",
case 1: bSet = bool(pImpl->nFlags & HtmlCfgFlags::IgnoreFontFamily);break;//"Import/FontSetting",
case 2: pValues[nProp] <<= pImpl->aFontSizeArr[0];break;//"Import/FontSize/Size_1",
case 3: pValues[nProp] <<= pImpl->aFontSizeArr[1];break;//"Import/FontSize/Size_2",
case 4: pValues[nProp] <<= pImpl->aFontSizeArr[2];break;//"Import/FontSize/Size_3",
case 5: pValues[nProp] <<= pImpl->aFontSizeArr[3];break;//"Import/FontSize/Size_4",
case 6: pValues[nProp] <<= pImpl->aFontSizeArr[4];break;//"Import/FontSize/Size_5",
case 7: pValues[nProp] <<= pImpl->aFontSizeArr[5];break;//"Import/FontSize/Size_6",
case 8: pValues[nProp] <<= pImpl->aFontSizeArr[6];break;//"Import/FontSize/Size_7",
case 9: //"Export/Browser",
{
sal_Int32 nExpMode = pImpl->nExportMode;
switch( nExpMode )
{
case HTML_CFG_MSIE: nExpMode = 1; break;
case HTML_CFG_WRITER: nExpMode = 3; break;
case HTML_CFG_NS40: nExpMode = 4; break;
default: nExpMode = 4; break; // NS40
}
pValues[nProp] <<= nExpMode;
break;
}
case 10: bSet = bool(pImpl->nFlags & HtmlCfgFlags::StarBasic);break;//"Export/Basic",
case 11: bSet = bool(pImpl->nFlags & HtmlCfgFlags::PrintLayoutExtension);break;//"Export/PrintLayout",
case 12: bSet = bool(pImpl->nFlags & HtmlCfgFlags::LocalGrf);break;//"Export/LocalGraphic",
case 13: bSet = bool(pImpl->nFlags & HtmlCfgFlags::IsBasicWarning);break;//"Export/Warning"
case 14:
if(!pImpl->bIsEncodingDefault)
pValues[nProp] <<= pImpl->eEncoding;
break;//"Export/Encoding",
case 15: bSet = bool(pImpl->nFlags & HtmlCfgFlags::NumbersEnglishUS);break;//"Import/NumbersEnglishUS"
}
if(nProp < 2 || ( nProp > 9 && nProp < 14 ) || nProp == 15)
pValues[nProp] <<= bSet;
}
PutProperties(aNames, aValues);
}
void SvxHtmlOptions::Notify( const css::uno::Sequence< OUString >& )
{
Load( GetPropertyNames() );
}
sal_uInt16 SvxHtmlOptions::GetFontSize(sal_uInt16 nPos) const
{
if(nPos < HTML_FONT_COUNT)
return static_cast<sal_uInt16>(pImpl->aFontSizeArr[nPos]);
return 0;
}
void SvxHtmlOptions::SetFontSize(sal_uInt16 nPos, sal_uInt16 nSize)
{
if(nPos < HTML_FONT_COUNT)
{
pImpl->aFontSizeArr[nPos] = nSize;
SetModified();
}
}
bool SvxHtmlOptions::IsImportUnknown() const
{
return bool(pImpl->nFlags & HtmlCfgFlags::UnknownTags) ;
}
void SvxHtmlOptions::SetImportUnknown(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::UnknownTags;
else
pImpl->nFlags &= ~HtmlCfgFlags::UnknownTags;
SetModified();
}
sal_uInt16 SvxHtmlOptions::GetExportMode() const
{
return static_cast<sal_uInt16>(pImpl->nExportMode);
}
bool SvxHtmlOptions::IsStarBasic() const
{
return bool(pImpl->nFlags & HtmlCfgFlags::StarBasic) ;
}
void SvxHtmlOptions::SetStarBasic(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::StarBasic;
else
pImpl->nFlags &= ~HtmlCfgFlags::StarBasic;
SetModified();
}
bool SvxHtmlOptions::IsSaveGraphicsLocal() const
{
return bool(pImpl->nFlags & HtmlCfgFlags::LocalGrf) ;
}
void SvxHtmlOptions::SetSaveGraphicsLocal(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::LocalGrf;
else
pImpl->nFlags &= ~HtmlCfgFlags::LocalGrf;
SetModified();
}
bool SvxHtmlOptions::IsPrintLayoutExtension() const
{
bool bRet(pImpl->nFlags & HtmlCfgFlags::PrintLayoutExtension);
switch( pImpl->nExportMode )
{
case HTML_CFG_MSIE:
case HTML_CFG_NS40 :
case HTML_CFG_WRITER :
break;
default:
bRet = false;
}
return bRet;
}
void SvxHtmlOptions::SetPrintLayoutExtension(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::PrintLayoutExtension;
else
pImpl->nFlags &= ~HtmlCfgFlags::PrintLayoutExtension;
SetModified();
}
bool SvxHtmlOptions::IsIgnoreFontFamily() const
{
return bool(pImpl->nFlags & HtmlCfgFlags::IgnoreFontFamily) ;
}
void SvxHtmlOptions::SetIgnoreFontFamily(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::IgnoreFontFamily;
else
pImpl->nFlags &= ~HtmlCfgFlags::IgnoreFontFamily;
SetModified();
}
bool SvxHtmlOptions::IsStarBasicWarning() const
{
return bool(pImpl->nFlags & HtmlCfgFlags::IsBasicWarning) ;
}
void SvxHtmlOptions::SetStarBasicWarning(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::IsBasicWarning;
else
pImpl->nFlags &= ~HtmlCfgFlags::IsBasicWarning;
SetModified();
}
rtl_TextEncoding SvxHtmlOptions::GetTextEncoding() const
{
rtl_TextEncoding eRet;
if(pImpl->bIsEncodingDefault)
eRet = SvtSysLocale::GetBestMimeEncoding();
else
eRet = static_cast<rtl_TextEncoding>(pImpl->eEncoding);
return eRet;
}
void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc )
{
pImpl->eEncoding = eEnc;
pImpl->bIsEncodingDefault = false;
SetModified();
}
bool SvxHtmlOptions::IsDefaultTextEncoding() const
{
return pImpl->bIsEncodingDefault;
}
namespace
{
class theSvxHtmlOptions : public rtl::Static<SvxHtmlOptions, theSvxHtmlOptions> {};
}
SvxHtmlOptions& SvxHtmlOptions::Get()
{
return theSvxHtmlOptions::get();
}
bool SvxHtmlOptions::IsNumbersEnglishUS() const
{
return bool(pImpl->nFlags & HtmlCfgFlags::NumbersEnglishUS) ;
}
void SvxHtmlOptions::SetNumbersEnglishUS(bool bSet)
{
if(bSet)
pImpl->nFlags |= HtmlCfgFlags::NumbersEnglishUS;
else
pImpl->nFlags &= ~HtmlCfgFlags::NumbersEnglishUS;
SetModified();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|