summaryrefslogtreecommitdiff
path: root/sw/source/filter/html/htmlfldw.cxx
blob: dfa4ae71bb3aaff43033c03e93f7b72ab95c6e3a (plain)
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/* -*- 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 <com/sun/star/i18n/ScriptType.hpp>
#include <comphelper/string.hxx>
#include <svtools/htmlkywd.hxx>
#include <svtools/htmlout.hxx>
#include <svtools/htmltokn.h>
#include <fmtfld.hxx>
#include <doc.hxx>
#include <breakit.hxx>
#include <ndtxt.hxx>
#include <txtfld.hxx>
#include "fldbas.hxx"
#include "docufld.hxx"
#include "flddat.hxx"
#include <viewopt.hxx>
#include "htmlfld.hxx"
#include "wrthtml.hxx"
#include <rtl/strbuf.hxx>
#include <css1atr.hxx>
#include "css1kywd.hxx"

using namespace nsSwDocInfoSubType;

const sal_Char *SwHTMLWriter::GetNumFormat( sal_uInt16 nFormat )
{
    const sal_Char *pFormatStr = nullptr;

    switch( (SvxNumType)nFormat )
    {
    case SVX_NUM_CHARS_UPPER_LETTER:    pFormatStr = OOO_STRING_SW_HTML_FF_uletter;    break;
    case SVX_NUM_CHARS_LOWER_LETTER:    pFormatStr = OOO_STRING_SW_HTML_FF_lletter;    break;
    case SVX_NUM_ROMAN_UPPER:           pFormatStr = OOO_STRING_SW_HTML_FF_uroman;         break;
    case SVX_NUM_ROMAN_LOWER:           pFormatStr = OOO_STRING_SW_HTML_FF_lroman;         break;
    case SVX_NUM_ARABIC:                pFormatStr = OOO_STRING_SW_HTML_FF_arabic;     break;
    case SVX_NUM_NUMBER_NONE:           pFormatStr = OOO_STRING_SW_HTML_FF_none;       break;
    case SVX_NUM_CHAR_SPECIAL:          pFormatStr = OOO_STRING_SW_HTML_FF_char;       break;
    case SVX_NUM_PAGEDESC:              pFormatStr = OOO_STRING_SW_HTML_FF_page;       break;
    case SVX_NUM_CHARS_UPPER_LETTER_N:  pFormatStr = OOO_STRING_SW_HTML_FF_ulettern;   break;
    case SVX_NUM_CHARS_LOWER_LETTER_N:  pFormatStr = OOO_STRING_SW_HTML_FF_llettern;   break;
    default:
        ;
    }

    return pFormatStr;
}

static Writer& OutHTML_SwField( Writer& rWrt, const SwField* pField,
                                 const SwTextNode& rTextNd, sal_Int32 nFieldPos )
{
    SwHTMLWriter & rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);

    const SwFieldType* pFieldTyp = pField->GetTyp();
    SwFieldIds nField = pFieldTyp->Which();
    sal_uLong nFormat = pField->GetFormat();

    const sal_Char *pTypeStr=nullptr, // TYPE
                      *pSubStr=nullptr,   // SUBTYPE
                   *pFormatStr=nullptr;  // FORMAT (SW)
    OUString aValue;              // VALUE (SW)
    bool bNumFormat=false;         // SDNUM (Number-Formatter-Format)
    bool bNumValue=false;       // SDVAL (Number-Formatter-Value)
    double dNumValue = 0.0;     // SDVAL (Number-Formatter-Value)
    bool bFixed=false;          // SDFIXED
    OUString aName;               // NAME (CUSTOM)

    switch( nField )
    {
        case SwFieldIds::ExtUser:
            pTypeStr = OOO_STRING_SW_HTML_FT_sender;
            switch( (SwExtUserSubType)pField->GetSubType() )
            {
                case EU_COMPANY:    pSubStr = OOO_STRING_SW_HTML_FS_company;        break;
                case EU_FIRSTNAME:  pSubStr = OOO_STRING_SW_HTML_FS_firstname;  break;
                case EU_NAME:       pSubStr = OOO_STRING_SW_HTML_FS_name;       break;
                case EU_SHORTCUT:   pSubStr = OOO_STRING_SW_HTML_FS_shortcut;   break;
                case EU_STREET:     pSubStr = OOO_STRING_SW_HTML_FS_street;     break;
                case EU_COUNTRY:    pSubStr = OOO_STRING_SW_HTML_FS_country;     break;
                case EU_ZIP:        pSubStr = OOO_STRING_SW_HTML_FS_zip;         break;
                case EU_CITY:       pSubStr = OOO_STRING_SW_HTML_FS_city;        break;
                case EU_TITLE:      pSubStr = OOO_STRING_SW_HTML_FS_title;       break;
                case EU_POSITION:   pSubStr = OOO_STRING_SW_HTML_FS_position;    break;
                case EU_PHONE_PRIVATE:  pSubStr = OOO_STRING_SW_HTML_FS_pphone;      break;
                case EU_PHONE_COMPANY:  pSubStr = OOO_STRING_SW_HTML_FS_cphone;      break;
                case EU_FAX:        pSubStr = OOO_STRING_SW_HTML_FS_fax;         break;
                case EU_EMAIL:      pSubStr = OOO_STRING_SW_HTML_FS_email;       break;
                case EU_STATE:      pSubStr = OOO_STRING_SW_HTML_FS_state;       break;
                default:
                    ;
            }
            OSL_ENSURE( pSubStr, "ubekannter Subtyp fuer SwExtUserField" );
            bFixed = static_cast<const SwExtUserField*>(pField)->IsFixed();
            break;

        case SwFieldIds::Author:
            pTypeStr = OOO_STRING_SW_HTML_FT_author;
            switch( (SwAuthorFormat)nFormat & 0xff)
            {
                case AF_NAME:     pFormatStr = OOO_STRING_SW_HTML_FF_name;     break;
                case AF_SHORTCUT:  pFormatStr = OOO_STRING_SW_HTML_FF_shortcut;    break;
            }
            OSL_ENSURE( pFormatStr, "ubekanntes Format fuer SwAuthorField" );
            bFixed = static_cast<const SwAuthorField*>(pField)->IsFixed();
            break;

        case SwFieldIds::DateTime:
            pTypeStr = OOO_STRING_SW_HTML_FT_datetime;
            bNumFormat = true;
            if( static_cast<const SwDateTimeField*>(pField)->IsFixed() )
            {
                bNumValue = true;
                dNumValue = static_cast<const SwDateTimeField*>(pField)->GetValue();
            }
            break;

        case SwFieldIds::PageNumber:
            {
                pTypeStr = OOO_STRING_SW_HTML_FT_page;
                SwPageNumSubType eSubType = (SwPageNumSubType)pField->GetSubType();
                switch( eSubType )
                {
                    case PG_RANDOM:     pSubStr = OOO_STRING_SW_HTML_FS_random;     break;
                    case PG_NEXT:       pSubStr = OOO_STRING_SW_HTML_FS_next;       break;
                    case PG_PREV:       pSubStr = OOO_STRING_SW_HTML_FS_prev;       break;
                }
                OSL_ENSURE( pSubStr, "ubekannter Subtyp fuer SwPageNumberField" );
                pFormatStr = SwHTMLWriter::GetNumFormat( static_cast< sal_uInt16 >(nFormat) );

                if( (SvxNumType)nFormat==SVX_NUM_CHAR_SPECIAL )
                {
                    aValue = static_cast<const SwPageNumberField *>(pField)->GetUserString();
                }
                else
                {
                    const OUString& rValue = pField->GetPar2();
                    short nValue = (short)rValue.toInt32();
                    if( (eSubType == PG_NEXT && nValue!=1) ||
                        (eSubType == PG_PREV && nValue!=-1) ||
                        (eSubType == PG_RANDOM && nValue!=0) )
                    {
                        aValue = rValue;
                    }
                }
            }
            break;
        case SwFieldIds::DocInfo:
            {
                sal_uInt16 nSubType = pField->GetSubType();
                pTypeStr = OOO_STRING_SW_HTML_FT_docinfo;
                sal_uInt16 nExtSubType = nSubType & 0x0f00;
                nSubType &= 0x00ff;

                switch( nSubType )
                {
                    case DI_TITEL:      pSubStr = OOO_STRING_SW_HTML_FS_title;  break;
                    case DI_THEMA:      pSubStr = OOO_STRING_SW_HTML_FS_theme;  break;
                    case DI_KEYS:       pSubStr = OOO_STRING_SW_HTML_FS_keys;   break;
                    case DI_COMMENT:    pSubStr = OOO_STRING_SW_HTML_FS_comment; break;
                    case DI_CREATE:     pSubStr = OOO_STRING_SW_HTML_FS_create;     break;
                    case DI_CHANGE:     pSubStr = OOO_STRING_SW_HTML_FS_change;     break;
                    case DI_CUSTOM:     pSubStr = OOO_STRING_SW_HTML_FS_custom;     break;
                    default:            pTypeStr = nullptr;               break;
                }

                if( DI_CUSTOM == nSubType ) {
                    aName = static_cast<const SwDocInfoField*>(pField)->GetName();
                }

                if( DI_CREATE == nSubType || DI_CHANGE == nSubType )
                {
                    switch( nExtSubType )
                    {
                        case DI_SUB_AUTHOR:
                            pFormatStr = OOO_STRING_SW_HTML_FF_author;
                            break;
                        case DI_SUB_TIME:
                            pFormatStr = OOO_STRING_SW_HTML_FF_time;
                            bNumFormat = true;
                            break;
                        case DI_SUB_DATE:
                            pFormatStr = OOO_STRING_SW_HTML_FF_date;
                            bNumFormat = true;
                            break;
                    }
                }
                bFixed = static_cast<const SwDocInfoField*>(pField)->IsFixed();
                if( bNumFormat )
                {
                    if( bFixed )
                    {
                        // For a fixed field output the num value too.
                        // Fixed fields without number format shouldn't
                        // exist. See below for OSL_ENSURE().
                        dNumValue = static_cast<const SwDocInfoField*>(pField)->GetValue();
                        bNumValue = true;
                    }
                    else if( !nFormat  )
                    {
                        // Non-fixed fields may not have a number format, when
                        // they come from a 4.0-document.
                        bNumFormat = false;
                    }
                }
            }
            break;

        case SwFieldIds::DocStat:
            {
                pTypeStr = OOO_STRING_SW_HTML_FT_docstat;
                sal_uInt16 nSubType = pField->GetSubType();
                switch( nSubType )
                {
                    case DS_PAGE:       pSubStr = OOO_STRING_SW_HTML_FS_page;   break;
                    case DS_PARA:       pSubStr = OOO_STRING_SW_HTML_FS_para;   break;
                    case DS_WORD:       pSubStr = OOO_STRING_SW_HTML_FS_word;   break;
                    case DS_CHAR:       pSubStr = OOO_STRING_SW_HTML_FS_char;   break;
                    case DS_TBL:        pSubStr = OOO_STRING_SW_HTML_FS_tbl;    break;
                    case DS_GRF:        pSubStr = OOO_STRING_SW_HTML_FS_grf;    break;
                    case DS_OLE:        pSubStr = OOO_STRING_SW_HTML_FS_ole;    break;
                    default:            pTypeStr = nullptr;               break;
                }
                pFormatStr = SwHTMLWriter::GetNumFormat( static_cast< sal_uInt16 >(nFormat) );
            }
            break;

        case SwFieldIds::Filename:
            pTypeStr = OOO_STRING_SW_HTML_FT_filename;
            switch( (SwFileNameFormat)(nFormat & ~FF_FIXED) )
            {
                case FF_NAME:       pFormatStr = OOO_STRING_SW_HTML_FF_name;       break;
                case FF_PATHNAME:   pFormatStr = OOO_STRING_SW_HTML_FF_pathname;   break;
                case FF_PATH:       pFormatStr = OOO_STRING_SW_HTML_FF_path;       break;
                case FF_NAME_NOEXT: pFormatStr = OOO_STRING_SW_HTML_FF_name_noext; break;
                default:
                    ;
            }
            bFixed = static_cast<const SwFileNameField*>(pField)->IsFixed();
            OSL_ENSURE( pFormatStr, "unbekanntes Format fuer SwFileNameField" );
            break;
        default: break;
    }

    // ReqIF-XHTML doesn't allow <sdfield>.
    if (rHTMLWrt.mbReqIF && pTypeStr)
    {
        pTypeStr = nullptr;
    }

    // Output the <sdfield> tag.
    if( pTypeStr )
    {
        OStringBuffer sOut;
        sOut.append('<');
        sOut.append(rHTMLWrt.GetNamespace());
        sOut.append(OOO_STRING_SVTOOLS_HTML_sdfield).append(' ').
            append(OOO_STRING_SVTOOLS_HTML_O_type).append('=').
            append(pTypeStr);
        if( pSubStr )
        {
            sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_subtype).
                append('=').append(pSubStr);
        }
        if( pFormatStr )
        {
            sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_format).
                append('=').append(pFormatStr);
        }
        if( !aName.isEmpty() )
        {
            sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name).
                append("=\"");
            rWrt.Strm().WriteCharPtr( sOut.makeStringAndClear().getStr() );
            HTMLOutFuncs::Out_String( rWrt.Strm(), aName, rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
            sOut.append('\"');
        }
        if( !aValue.isEmpty() )
        {
            sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_value).
                append("=\"");
            rWrt.Strm().WriteCharPtr( sOut.makeStringAndClear().getStr() );
            HTMLOutFuncs::Out_String( rWrt.Strm(), aValue, rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
            sOut.append('\"');
        }
        if( bNumFormat )
        {
            OSL_ENSURE( nFormat, "number format is 0" );
            sOut.append(HTMLOutFuncs::CreateTableDataOptionsValNum(
                bNumValue, dNumValue, nFormat,
                *rHTMLWrt.pDoc->GetNumberFormatter(), rHTMLWrt.m_eDestEnc,
                &rHTMLWrt.m_aNonConvertableCharacters));
        }
        if( bFixed )
        {
            sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_sdfixed);
        }
        sOut.append('>');
        rWrt.Strm().WriteCharPtr( sOut.makeStringAndClear().getStr() );
    }

    // output content of the field
    OUString const sExpand( pField->ExpandField(true) );
    bool bNeedsCJKProcessing = false;
    if( !sExpand.isEmpty() )
    {
        sal_uInt16 nScriptType = g_pBreakIt->GetBreakIter()->getScriptType( sExpand, 0 );
        sal_Int32 nPos = g_pBreakIt->GetBreakIter()->endOfScript( sExpand, 0,
                                                          nScriptType );

        sal_uInt16 nScript =
            SwHTMLWriter::GetCSS1ScriptForScriptType( nScriptType );
        if( (nPos < sExpand.getLength() && nPos >= 0) || nScript != rHTMLWrt.m_nCSS1Script )
        {
            bNeedsCJKProcessing = true;
        }
    }

    if( bNeedsCJKProcessing )
    {
        //sequence of (start, end) property ranges we want to
        //query
        SfxItemSet aScriptItemSet( rWrt.pDoc->GetAttrPool(),
                                   RES_CHRATR_FONT, RES_CHRATR_FONTSIZE,
                                   RES_CHRATR_POSTURE, RES_CHRATR_POSTURE,
                                   RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT,
                                   RES_CHRATR_CJK_FONT, RES_CHRATR_CTL_WEIGHT,
                                   0 );
        rTextNd.GetAttr( aScriptItemSet, nFieldPos, nFieldPos+1 );

        sal_uInt16 aWesternWhichIds[4] =
            { RES_CHRATR_FONT, RES_CHRATR_FONTSIZE,
              RES_CHRATR_POSTURE, RES_CHRATR_WEIGHT };
        sal_uInt16 aCJKWhichIds[4] =
            { RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONTSIZE,
              RES_CHRATR_CJK_POSTURE, RES_CHRATR_CJK_WEIGHT };
        sal_uInt16 aCTLWhichIds[4] =
            { RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONTSIZE,
              RES_CHRATR_CTL_POSTURE, RES_CHRATR_CTL_WEIGHT };

        sal_uInt16 *pRefWhichIds = nullptr;
        switch( rHTMLWrt.m_nCSS1Script )
        {
        case CSS1_OUTMODE_WESTERN:
            pRefWhichIds = aWesternWhichIds;
            break;
        case CSS1_OUTMODE_CJK:
            pRefWhichIds = aCJKWhichIds;
            break;
        case CSS1_OUTMODE_CTL:
            pRefWhichIds = aCTLWhichIds;
            break;
        }

        sal_Int32 nPos = 0;
        do
        {
            sal_uInt16 nScriptType = g_pBreakIt->GetBreakIter()->getScriptType( sExpand, nPos );
            sal_uInt16 nScript =
                SwHTMLWriter::GetCSS1ScriptForScriptType( nScriptType );
            sal_Int32 nEndPos = g_pBreakIt->GetBreakIter()->endOfScript(
                                    sExpand, nPos, nScriptType );
            sal_Int32 nChunkLen = nEndPos - nPos;
            if( nScript != CSS1_OUTMODE_ANY_SCRIPT &&
                /* #108791# */ nScript != rHTMLWrt.m_nCSS1Script )
            {
                sal_uInt16 *pWhichIds = nullptr;
                switch( nScript )
                {
                case CSS1_OUTMODE_WESTERN:  pWhichIds = aWesternWhichIds; break;
                case CSS1_OUTMODE_CJK:      pWhichIds = aCJKWhichIds; break;
                case CSS1_OUTMODE_CTL:      pWhichIds = aCTLWhichIds; break;
                }

                rHTMLWrt.m_bTagOn = true;

                const SfxPoolItem *aItems[5];
                int nItems = 0;

                assert(pWhichIds && pRefWhichIds);
                if (pWhichIds && pRefWhichIds)
                {
                    for( int i=0; i<4; i++ )
                    {
                        const SfxPoolItem *pRefItem =
                            aScriptItemSet.GetItem( pRefWhichIds[i] );
                        const SfxPoolItem *pItem =
                            aScriptItemSet.GetItem( pWhichIds[i] );
                        if( pRefItem && pItem &&
                            !(0==i ? swhtml_css1atr_equalFontItems( *pRefItem, *pItem )
                                   : *pRefItem == *pItem) )
                        {
                            Out( aHTMLAttrFnTab, *pItem, rHTMLWrt );
                            aItems[nItems++] = pItem;
                        }
                    }
                }

                HTMLOutFuncs::Out_String( rWrt.Strm(), sExpand.copy( nPos, nChunkLen ),
                    rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );

                rHTMLWrt.m_bTagOn = false;
                while( nItems )
                    Out( aHTMLAttrFnTab, *aItems[--nItems], rHTMLWrt );

            }
            else
            {
                HTMLOutFuncs::Out_String( rWrt.Strm(), sExpand.copy( nPos, nChunkLen ),
                    rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
            }
            nPos = nEndPos;
        }
        while( nPos < sExpand.getLength() );
    }
    else
    {
        HTMLOutFuncs::Out_String( rWrt.Strm(), sExpand,
              rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
    }

    // Output the closing tag.
    if( pTypeStr )
        HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_sdfield, false );

    return rWrt;
}

Writer& OutHTML_SwFormatField( Writer& rWrt, const SfxPoolItem& rHt )
{
    const SwFormatField & rField = static_cast<const SwFormatField&>(rHt);
    const SwField* pField = rField.GetField();
    const SwFieldType* pFieldTyp = pField->GetTyp();

    if( SwFieldIds::SetExp == pFieldTyp->Which() &&
        (nsSwGetSetExpType::GSE_STRING & pField->GetSubType()) )
    {
        const bool bOn = pFieldTyp->GetName() == "HTML_ON";
        if (!bOn && pFieldTyp->GetName() != "HTML_OFF")
            return rWrt;

        OUString rText(comphelper::string::strip(pField->GetPar2(), ' '));
        rWrt.Strm().WriteChar( '<' );
        if( !bOn )
            rWrt.Strm().WriteChar( '/' );
        // TODO: HTML-Tags are written without entities, that for, characters
        // not contained in the destination encoding are lost!
        OString sTmp(OUStringToOString(rText,
            static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc));
        rWrt.Strm().WriteCharPtr( sTmp.getStr() ).WriteChar( '>' );
    }
    else if( SwFieldIds::Postit == pFieldTyp->Which() )
    {
        // Comments will be written in ANSI character set, but with system
        // line breaks.
        const OUString& rComment = pField->GetPar2();
        bool bWritten = false;

        if( (rComment.getLength() >= 6 && rComment.startsWith("<") && rComment.endsWith(">") &&
             rComment.copy( 1, 4 ).equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_meta) ) ||
            (rComment.getLength() >= 7 &&
             rComment.startsWith( "<!--" ) &&
             rComment.endsWith( "-->" )) )
        {
            // directly output META tags
            OUString sComment(convertLineEnd(rComment, GetSystemLineEnd()));
            // TODO: HTML-Tags are written without entities, that for,
            // characters not contained in the destination encoding are lost!
            OString sTmp(OUStringToOString(sComment,
                static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc));
            rWrt.Strm().WriteCharPtr( sTmp.getStr() );
            bWritten = true;
        }
        else if( rComment.getLength() >= 7 &&
                 rComment.endsWith(">") &&
                 rComment.startsWithIgnoreAsciiCase( "HTML:" ) )
        {
            OUString sComment(comphelper::string::stripStart(rComment.copy(5), ' '));
            if( '<' == sComment[0] )
            {
                sComment = convertLineEnd(sComment, GetSystemLineEnd());
                // TODO: HTML-Tags are written without entities, that for,
                // characters not contained in the destination encoding are
                // lost!
                OString sTmp(OUStringToOString(sComment,
                    static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc));
                rWrt.Strm().WriteCharPtr( sTmp.getStr() );
                bWritten = true;
            }

        }

        if( !bWritten )
        {
            OUString sComment(convertLineEnd(rComment, GetSystemLineEnd()));
            OStringBuffer sOut;
            // TODO: ???
            sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_comment)
                .append(' ').append(OUStringToOString(sComment,
                    static_cast<SwHTMLWriter&>(rWrt).m_eDestEnc)).append(" -->");
            rWrt.Strm().WriteCharPtr( sOut.getStr() );
        }
    }
    else if( SwFieldIds::Script == pFieldTyp->Which() )
    {
        SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
        if( rHTMLWrt.m_bLFPossible )
            rHTMLWrt.OutNewLine( true );

        bool bURL = static_cast<const SwScriptField *>(pField)->IsCodeURL();
        const OUString& rType = pField->GetPar1();
        OUString aContents, aURL;
        if(bURL)
            aURL = pField->GetPar2();
        else
            aContents = pField->GetPar2();

        // otherwise is the script content itself. Since only JavaScript
        // is in fields, it must be JavaScript ...:)
        HTMLOutFuncs::OutScript( rWrt.Strm(), rWrt.GetBaseURL(), aContents, rType, JAVASCRIPT,
                                 aURL, nullptr, nullptr, rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );

        if( rHTMLWrt.m_bLFPossible )
            rHTMLWrt.OutNewLine( true );
    }
    else
    {
        const SwTextField *pTextField = rField.GetTextField();
        OSL_ENSURE( pTextField, "Where is the txt fld?" );
        if( pTextField )
        {
            SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
            // ReqIF-XHTML doesn't allow specifying a background color.
            bool bFieldShadings = SwViewOption::IsFieldShadings() && !rHTMLWrt.mbReqIF;
            if (bFieldShadings)
            {
                // If there is a text portion background started already, that should have priority.
                auto it = rHTMLWrt.maStartedAttributes.find(RES_CHRATR_BACKGROUND);
                if (it != rHTMLWrt.maStartedAttributes.end())
                    bFieldShadings = it->second <= 0;
            }

            if (bFieldShadings)
            {
                OStringBuffer sOut;
                sOut.append("<" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span);
                sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_style "=\"");
                sOut.append(sCSS1_P_background);
                sOut.append(": ");

                Color& rColor = SwViewOption::GetFieldShadingsColor();
                sOut.append(GetCSS1_Color(rColor));
                sOut.append("\">");
                rWrt.Strm().WriteCharPtr(sOut.getStr());
            }

            OutHTML_SwField( rWrt, pField, pTextField->GetTextNode(),
                             pTextField->GetStart()  );

            if (bFieldShadings)
                HTMLOutFuncs::Out_AsciiTag(
                    rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span, false);
        }
    }
    return rWrt;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */