Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLTextMasterPageExport.cxx
Line
Count
Source
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 <xmloff/xmlnamespace.hxx>
21
#include <xmloff/xmltoken.hxx>
22
#include <com/sun/star/text/XText.hpp>
23
#include <com/sun/star/beans/XPropertySet.hpp>
24
#include <xmloff/xmlexp.hxx>
25
#include <xmloff/XMLTextMasterPageExport.hxx>
26
#include <sal/log.hxx>
27
28
29
using namespace ::com::sun::star;
30
using namespace ::com::sun::star::uno;
31
using namespace ::com::sun::star::text;
32
using namespace ::com::sun::star::beans;
33
using namespace ::xmloff::token;
34
35
constexpr OUStringLiteral gsHeaderText( u"HeaderText" );
36
constexpr OUStringLiteral gsHeaderOn( u"HeaderIsOn" );
37
constexpr OUStringLiteral gsHeaderShareContent( u"HeaderIsShared" );
38
constexpr OUStringLiteral gsHeaderTextFirst( u"HeaderTextFirst" );
39
constexpr OUStringLiteral gsHeaderTextLeft( u"HeaderTextLeft" );
40
constexpr OUString gsFirstShareContent( u"FirstIsShared"_ustr );
41
constexpr OUStringLiteral gsFooterText( u"FooterText" );
42
constexpr OUStringLiteral gsFooterOn( u"FooterIsOn" );
43
constexpr OUStringLiteral gsFooterShareContent( u"FooterIsShared" );
44
constexpr OUStringLiteral gsFooterTextFirst( u"FooterTextFirst" );
45
constexpr OUStringLiteral gsFooterTextLeft( u"FooterTextLeft" );
46
47
XMLTextMasterPageExport::XMLTextMasterPageExport( SvXMLExport& rExp ) :
48
0
    XMLPageExport( rExp )
49
0
{
50
0
}
51
52
XMLTextMasterPageExport::~XMLTextMasterPageExport()
53
0
{
54
0
}
55
56
57
void XMLTextMasterPageExport::exportHeaderFooterContent(
58
            const Reference< XText >& rText,
59
            bool bAutoStyles, bool bExportParagraph )
60
0
{
61
0
    SAL_WARN_IF( !rText.is(), "xmloff", "There is the text" );
62
63
    // tracked changes (autostyles + changes list)
64
0
    GetExport().GetTextParagraphExport()->recordTrackedChangesForXText(rText);
65
0
    GetExport().GetTextParagraphExport()->exportTrackedChanges(rText,
66
0
                                                               bAutoStyles);
67
0
    if( bAutoStyles )
68
0
        GetExport().GetTextParagraphExport()
69
0
                ->collectTextAutoStyles( rText, true, bExportParagraph );
70
0
    else
71
0
    {
72
0
        GetExport().GetTextParagraphExport()->exportTextDeclarations( rText );
73
0
        GetExport().GetTextParagraphExport()->exportText( rText, true, bExportParagraph );
74
0
    }
75
76
    // tracked changes (end of XText)
77
0
    GetExport().GetTextParagraphExport()->recordTrackedChangesNoXText();
78
0
}
79
80
void XMLTextMasterPageExport::exportMasterPageContent(
81
                const Reference < XPropertySet > & rPropSet,
82
                bool bAutoStyles )
83
0
{
84
0
    Any aAny;
85
86
0
    Reference < XText > xHeaderText;
87
0
    aAny = rPropSet->getPropertyValue( gsHeaderText );
88
0
    aAny >>= xHeaderText;
89
90
0
    Reference < XText > xHeaderTextFirst;
91
0
    aAny = rPropSet->getPropertyValue( gsHeaderTextFirst );
92
0
    aAny >>= xHeaderTextFirst;
93
94
0
    Reference < XText > xHeaderTextLeft;
95
0
    aAny = rPropSet->getPropertyValue( gsHeaderTextLeft );
96
0
    aAny >>= xHeaderTextLeft;
97
98
0
    Reference < XText > xFooterText;
99
0
    aAny = rPropSet->getPropertyValue( gsFooterText );
100
0
    aAny >>= xFooterText;
101
102
0
    Reference < XText > xFooterTextFirst;
103
0
    aAny = rPropSet->getPropertyValue( gsFooterTextFirst );
104
0
    aAny >>= xFooterTextFirst;
105
106
0
    Reference < XText > xFooterTextLeft;
107
0
    aAny = rPropSet->getPropertyValue( gsFooterTextLeft );
108
0
    aAny >>= xFooterTextLeft;
109
110
0
    if( bAutoStyles )
111
0
    {
112
0
        if( xHeaderText.is() )
113
0
            exportHeaderFooterContent( xHeaderText, true );
114
0
        if( xHeaderTextFirst.is() && xHeaderTextFirst != xHeaderText )
115
0
            exportHeaderFooterContent( xHeaderTextFirst, true );
116
0
        if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
117
0
            exportHeaderFooterContent( xHeaderTextLeft, true );
118
0
        if( xFooterText.is() )
119
0
            exportHeaderFooterContent( xFooterText, true );
120
0
        if( xFooterTextFirst.is() && xFooterTextFirst != xFooterText )
121
0
            exportHeaderFooterContent( xFooterTextFirst, true );
122
0
        if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
123
0
            exportHeaderFooterContent( xFooterTextLeft, true );
124
0
    }
125
0
    else
126
0
    {
127
0
        auto const nVersion(GetExport().getSaneDefaultVersion());
128
129
0
        aAny = rPropSet->getPropertyValue( gsHeaderOn );
130
0
        bool bHeader = false;
131
0
        aAny >>= bHeader;
132
133
0
        bool bHeaderFirstShared = false;
134
0
        if( bHeader )
135
0
        {
136
0
            aAny = rPropSet->getPropertyValue( gsFirstShareContent );
137
0
            aAny >>= bHeaderFirstShared;
138
0
        }
139
140
0
        bool bHeaderLeftShared = false;
141
0
        if( bHeader )
142
0
        {
143
0
            aAny = rPropSet->getPropertyValue( gsHeaderShareContent );
144
0
            aAny >>= bHeaderLeftShared;
145
0
        }
146
147
0
        if( xHeaderText.is() )
148
0
        {
149
0
            if( !bHeader )
150
0
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
151
0
                                          XML_DISPLAY, XML_FALSE );
152
0
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
153
0
                                        XML_HEADER, true, true );
154
0
            exportHeaderFooterContent( xHeaderText, false );
155
0
        }
156
157
0
        if( xHeaderTextLeft.is() && xHeaderTextLeft != xHeaderText )
158
0
        {
159
0
            if (bHeaderLeftShared)
160
0
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
161
0
                                          XML_DISPLAY, XML_FALSE );
162
0
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
163
0
                                        XML_HEADER_LEFT, true, true );
164
0
            exportHeaderFooterContent( xHeaderTextLeft, false );
165
0
        }
166
167
0
        if (xHeaderTextFirst.is() && xHeaderTextFirst != xHeaderText
168
0
            && SvtSaveOptions::ODFSVER_012 < nVersion)
169
0
        {
170
0
            if (bHeaderFirstShared)
171
0
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
172
0
                                          XML_DISPLAY, XML_FALSE );
173
            // ODF 1.3 OFFICE-3789
174
0
            SvXMLElementExport aElem( GetExport(),
175
0
                                        SvtSaveOptions::ODFSVER_013 <= nVersion
176
0
                                            ? XML_NAMESPACE_STYLE
177
0
                                            : XML_NAMESPACE_LO_EXT,
178
0
                                        XML_HEADER_FIRST, true, true );
179
0
            exportHeaderFooterContent( xHeaderTextFirst, false );
180
0
        }
181
182
0
        aAny = rPropSet->getPropertyValue( gsFooterOn );
183
0
        bool bFooter = false;
184
0
        aAny >>= bFooter;
185
186
0
        bool bFooterFirstShared = false;
187
0
        if( bFooter )
188
0
        {
189
0
            aAny = rPropSet->getPropertyValue( gsFirstShareContent );
190
0
            aAny >>= bFooterFirstShared;
191
0
        }
192
193
0
        bool bFooterLeftShared = false;
194
0
        if( bFooter )
195
0
        {
196
0
            aAny = rPropSet->getPropertyValue( gsFooterShareContent );
197
0
            aAny >>= bFooterLeftShared;
198
0
        }
199
200
0
        if( xFooterText.is() )
201
0
        {
202
0
            if( !bFooter )
203
0
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
204
0
                                          XML_DISPLAY, XML_FALSE );
205
0
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
206
0
                                        XML_FOOTER, true, true );
207
0
            exportHeaderFooterContent( xFooterText, false );
208
0
        }
209
210
0
        if( xFooterTextLeft.is() && xFooterTextLeft != xFooterText )
211
0
        {
212
0
            if (bFooterLeftShared)
213
0
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
214
0
                                          XML_DISPLAY, XML_FALSE );
215
0
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
216
0
                                        XML_FOOTER_LEFT, true, true );
217
0
            exportHeaderFooterContent( xFooterTextLeft, false );
218
0
        }
219
220
0
        if (xFooterTextFirst.is() && xFooterTextFirst != xFooterText
221
0
            && SvtSaveOptions::ODFSVER_012 < nVersion)
222
0
        {
223
0
            if (bFooterFirstShared)
224
0
                GetExport().AddAttribute( XML_NAMESPACE_STYLE,
225
0
                                          XML_DISPLAY, XML_FALSE );
226
            // ODF 1.3 OFFICE-3789
227
0
            SvXMLElementExport aElem( GetExport(),
228
0
                                        SvtSaveOptions::ODFSVER_013 <= nVersion
229
0
                                            ? XML_NAMESPACE_STYLE
230
0
                                            : XML_NAMESPACE_LO_EXT,
231
0
                                        XML_FOOTER_FIRST, true, true );
232
0
            exportHeaderFooterContent( xFooterTextFirst, false );
233
0
        }
234
0
    }
235
0
}
236
237
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */