Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/table/tableautofmt.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
/*
21
There are two different Autoformat classes for Writer and Calc
22
(SwTableAutoFormatTable & ScAutoFormat). This SvxAutoFormat unifies the
23
common functionality of SwTableAutoFormatTable and ScAutoFormat
24
*/
25
26
#include <comphelper/processfactory.hxx>
27
#include <sfx2/docfile.hxx>
28
#include <unotools/streamwrap.hxx>
29
#include <com/sun/star/awt/FontSlant.hpp>
30
#include <com/sun/star/beans/PropertyAttribute.hpp>
31
#include <config_folders.h>
32
#include <editeng/memberids.h>
33
#include <rtl/bootstrap.hxx>
34
#include <svl/intitem.hxx>
35
#include <svx/rotmodit.hxx>
36
#include <svx/svxtableitems.hxx>
37
#include <com/sun/star/xml/sax/Writer.hpp>
38
#include <editeng/adjustitem.hxx>
39
#include <svx/TableAutoFmt.hxx>
40
#include <editeng/justifyitem.hxx>
41
#include <editeng/svxenum.hxx>
42
#include <svl/typedwhich.hxx>
43
#include <svx/TableStylesParser.hxx>
44
45
using namespace com::sun::star::beans;
46
using namespace com::sun::star;
47
48
const SfxItemPropertySet& SvxAutoFormat::GetTablePropertySet()
49
0
{
50
0
    static const SfxItemPropertyMapEntry aSvxTablePropertyMap[] =
51
52
0
        {
53
            // SvxBrushItem
54
0
            { u"BackColor"_ustr, SVX_TABLE_BACKGROUND, cppu::UnoType<sal_Int32>::get(),
55
0
              PROPERTY_NONE, MID_BACK_COLOR },
56
            // SvxBoxItem
57
0
            { u"Border"_ustr, SVX_TABLE_BOX, cppu::UnoType<css::table::BorderLine>::get(),
58
0
              PROPERTY_NONE, LEFT_BORDER | CONVERT_TWIPS },
59
0
            { u"LeftBorder"_ustr, SVX_TABLE_BOX, cppu::UnoType<css::table::BorderLine>::get(),
60
0
              PROPERTY_NONE, LEFT_BORDER | CONVERT_TWIPS },
61
0
            { u"RightBorder"_ustr, SVX_TABLE_BOX, cppu::UnoType<css::table::BorderLine>::get(),
62
0
              PROPERTY_NONE, RIGHT_BORDER | CONVERT_TWIPS },
63
0
            { u"TopBorder"_ustr, SVX_TABLE_BOX, cppu::UnoType<css::table::BorderLine>::get(),
64
0
              PROPERTY_NONE, TOP_BORDER | CONVERT_TWIPS },
65
0
            { u"BottomBorder"_ustr, SVX_TABLE_BOX, cppu::UnoType<css::table::BorderLine>::get(),
66
0
              PROPERTY_NONE, BOTTOM_BORDER | CONVERT_TWIPS },
67
0
            { u"BorderDistance"_ustr, SVX_TABLE_BOX, cppu::UnoType<sal_Int32>::get(), PROPERTY_NONE,
68
0
              BORDER_DISTANCE | CONVERT_TWIPS },
69
0
            { u"LeftBorderDistance"_ustr, SVX_TABLE_BOX, cppu::UnoType<sal_Int32>::get(),
70
0
              PROPERTY_NONE, LEFT_BORDER_DISTANCE | CONVERT_TWIPS },
71
0
            { u"RightBorderDistance"_ustr, SVX_TABLE_BOX, cppu::UnoType<sal_Int32>::get(),
72
0
              PROPERTY_NONE, RIGHT_BORDER_DISTANCE | CONVERT_TWIPS },
73
0
            { u"TopBorderDistance"_ustr, SVX_TABLE_BOX, cppu::UnoType<sal_Int32>::get(),
74
0
              PROPERTY_NONE, TOP_BORDER_DISTANCE | CONVERT_TWIPS },
75
0
            { u"BottomBorderDistance"_ustr, SVX_TABLE_BOX, cppu::UnoType<sal_Int32>::get(),
76
0
              PROPERTY_NONE, BOTTOM_BORDER_DISTANCE | CONVERT_TWIPS },
77
            // SvxFormatOrient
78
0
            { u"VertOrient"_ustr, SVX_TABLE_VER_JUSTIFY, cppu::UnoType<sal_Int16>::get(),
79
0
              PROPERTY_NONE, 0 },
80
            // SvxColorItem
81
0
            { u"CharColor"_ustr, SVX_TABLE_FONT_COLOR, cppu::UnoType<sal_Int32>::get(),
82
0
              PROPERTY_NONE, 0 },
83
0
            { u"CharUnderline"_ustr, SVX_TABLE_FONT_UNDERLINE, cppu::UnoType<sal_Int32>::get(),
84
0
              PROPERTY_NONE, MID_TL_STYLE },
85
            //Font
86
0
            { u"CharHeight"_ustr, SVX_TABLE_FONT_HEIGHT, cppu::UnoType<float>::get(),
87
0
              PropertyAttribute::MAYBEVOID, MID_FONTHEIGHT | CONVERT_TWIPS },
88
0
            { u"CharWeight"_ustr, SVX_TABLE_FONT_WEIGHT, cppu::UnoType<float>::get(),
89
0
              PropertyAttribute::MAYBEVOID, MID_WEIGHT },
90
0
            { u"CharPosture"_ustr, SVX_TABLE_FONT_POSTURE,
91
0
              cppu::UnoType<css::awt::FontSlant>::get(), PropertyAttribute::MAYBEVOID,
92
0
              MID_POSTURE },
93
0
            { u"CharFontName"_ustr, SVX_TABLE_FONT, cppu::UnoType<OUString>::get(),
94
0
              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY_NAME },
95
0
            { u"CharFontStyleName"_ustr, SVX_TABLE_FONT, cppu::UnoType<OUString>::get(),
96
0
              PropertyAttribute::MAYBEVOID, MID_FONT_STYLE_NAME },
97
0
            { u"CharFontFamily"_ustr, SVX_TABLE_FONT, cppu::UnoType<sal_Int16>::get(),
98
0
              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY },
99
0
            { u"CharFontCharSet"_ustr, SVX_TABLE_FONT, cppu::UnoType<sal_Int16>::get(),
100
0
              PropertyAttribute::MAYBEVOID, MID_FONT_CHAR_SET },
101
0
            { u"CharFontPitch"_ustr, SVX_TABLE_FONT, cppu::UnoType<sal_Int16>::get(),
102
0
              PropertyAttribute::MAYBEVOID, MID_FONT_PITCH },
103
            // CJK Font
104
0
            { u"CharHeightAsian"_ustr, SVX_TABLE_CJK_FONT_HEIGHT, cppu::UnoType<float>::get(),
105
0
              PropertyAttribute::MAYBEVOID, MID_FONTHEIGHT | CONVERT_TWIPS },
106
0
            { u"CharWeightAsian"_ustr, SVX_TABLE_CJK_FONT_WEIGHT, cppu::UnoType<float>::get(),
107
0
              PropertyAttribute::MAYBEVOID, MID_WEIGHT },
108
0
            { u"CharPostureAsian"_ustr, SVX_TABLE_CJK_FONT_POSTURE,
109
0
              cppu::UnoType<css::awt::FontSlant>::get(), PropertyAttribute::MAYBEVOID,
110
0
              MID_POSTURE },
111
0
            { u"CharFontNameAsian"_ustr, SVX_TABLE_CJK_FONT, cppu::UnoType<OUString>::get(),
112
0
              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY_NAME },
113
0
            { u"CharFontStyleNameAsian"_ustr, SVX_TABLE_CJK_FONT, cppu::UnoType<OUString>::get(),
114
0
              PropertyAttribute::MAYBEVOID, MID_FONT_STYLE_NAME },
115
0
            { u"CharFontFamilyAsian"_ustr, SVX_TABLE_CJK_FONT, cppu::UnoType<sal_Int16>::get(),
116
0
              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY },
117
0
            { u"CharFontCharSetAsian"_ustr, SVX_TABLE_CJK_FONT, cppu::UnoType<sal_Int16>::get(),
118
0
              PropertyAttribute::MAYBEVOID, MID_FONT_CHAR_SET },
119
0
            { u"CharFontPitchAsian"_ustr, SVX_TABLE_CJK_FONT, cppu::UnoType<sal_Int16>::get(),
120
0
              PropertyAttribute::MAYBEVOID, MID_FONT_PITCH },
121
            // CTL Font
122
0
            { u"CharHeightComplex"_ustr, SVX_TABLE_CTL_FONT_HEIGHT, cppu::UnoType<float>::get(),
123
0
              PropertyAttribute::MAYBEVOID, MID_FONTHEIGHT | CONVERT_TWIPS },
124
0
            { u"CharWeightComplex"_ustr, SVX_TABLE_CTL_FONT_WEIGHT, cppu::UnoType<float>::get(),
125
0
              PropertyAttribute::MAYBEVOID, MID_WEIGHT },
126
0
            { u"CharPostureComplex"_ustr, SVX_TABLE_CTL_FONT_POSTURE,
127
0
              cppu::UnoType<css::awt::FontSlant>::get(), PropertyAttribute::MAYBEVOID,
128
0
              MID_POSTURE },
129
0
            { u"CharFontNameComplex"_ustr, SVX_TABLE_CTL_FONT, cppu::UnoType<OUString>::get(),
130
0
              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY_NAME },
131
0
            { u"CharFontStyleNameComplex"_ustr, SVX_TABLE_CTL_FONT, cppu::UnoType<OUString>::get(),
132
0
              PropertyAttribute::MAYBEVOID, MID_FONT_STYLE_NAME },
133
0
            { u"CharFontFamilyComplex"_ustr, SVX_TABLE_CTL_FONT, cppu::UnoType<sal_Int16>::get(),
134
0
              PropertyAttribute::MAYBEVOID, MID_FONT_FAMILY },
135
0
            { u"CharFontCharSetComplex"_ustr, SVX_TABLE_CTL_FONT, cppu::UnoType<sal_Int16>::get(),
136
0
              PropertyAttribute::MAYBEVOID, MID_FONT_CHAR_SET },
137
0
            { u"CharFontPitchComplex"_ustr, SVX_TABLE_CTL_FONT, cppu::UnoType<sal_Int16>::get(),
138
0
              PropertyAttribute::MAYBEVOID, MID_FONT_PITCH },
139
            // Paragraph Properties
140
0
            { u"ParaAdjust"_ustr, SVX_TABLE_PARA_ADJUST, cppu::UnoType<sal_Int16>::get(),
141
0
              PropertyAttribute::MAYBEVOID, MID_PARA_ADJUST },
142
0
        };
143
0
    static SfxItemPropertySet aSvxTablePropertySet(aSvxTablePropertyMap);
144
0
    return aSvxTablePropertySet;
145
0
}
146
147
SvxAutoFormatDataField::SvxAutoFormatDataField(const SvxAutoFormatDataField& rCopy)
148
1.61k
    : AutoFormatBase(rCopy)
149
1.61k
    , mSetProperties(rCopy.mSetProperties)
150
1.61k
{
151
1.61k
}
152
153
void SvxAutoFormatDataField::GetValueFormat(OUString& rFormat, LanguageType& rLng,
154
                                            LanguageType& rSys) const
155
4.98k
{
156
4.98k
    rFormat = maNumFormatString;
157
4.98k
    rLng = meNumFormatLanguage;
158
4.98k
    rSys = meSysLanguage;
159
4.98k
}
160
161
void SvxAutoFormatDataField::SetValueFormat(const OUString& rFormat, LanguageType eLng,
162
                                            LanguageType eSys)
163
34
{
164
34
    maNumFormatString = rFormat;
165
34
    meNumFormatLanguage = eLng;
166
34
    meSysLanguage = eSys;
167
34
}
168
169
SvxAutoFormatData::SvxAutoFormatData()
170
0
    : mbInclFont(true)
171
0
    , mbInclJustify(true)
172
0
    , mbInclFrame(true)
173
0
    , mbInclBackground(true)
174
0
    , mbInclValueFormat(true)
175
0
    , mbInclWidthHeight(true)
176
0
    , mbUseFirstRowStyles(true)
177
0
    , mbUseLastRowStyles(true)
178
0
    , mbUseFirstColStyles(true)
179
0
    , mbUseLastColStyles(true)
180
0
    , mbUseBandedRowStyles(true)
181
0
    , mbUseBandedColStyles(true)
182
0
{
183
0
}
184
185
SvxAutoFormatData::SvxAutoFormatData(const SvxAutoFormatData& rData)
186
0
    : maName(rData.maName)
187
0
    , mbInclFont(rData.mbInclFont)
188
0
    , mbInclJustify(rData.mbInclJustify)
189
0
    , mbInclFrame(rData.mbInclFrame)
190
0
    , mbInclBackground(rData.mbInclBackground)
191
0
    , mbInclValueFormat(rData.mbInclValueFormat)
192
0
    , mbInclWidthHeight(rData.mbInclWidthHeight)
193
0
    , mbUseFirstRowStyles(rData.mbUseFirstRowStyles)
194
0
    , mbUseLastRowStyles(rData.mbUseLastRowStyles)
195
0
    , mbUseFirstColStyles(rData.mbUseFirstColStyles)
196
0
    , mbUseLastColStyles(rData.mbUseLastColStyles)
197
0
    , mbUseBandedRowStyles(rData.mbUseBandedRowStyles)
198
0
    , mbUseBandedColStyles(rData.mbUseBandedColStyles)
199
0
    , maParent(rData.maParent)
200
0
{
201
0
}
202
203
SvxAutoFormatData& SvxAutoFormatData::operator=(const SvxAutoFormatData& rCopy)
204
0
{
205
0
    if (this == &rCopy)
206
0
        return *this;
207
208
0
    maName = rCopy.maName;
209
0
    mbInclFont = rCopy.mbInclFont;
210
0
    mbInclJustify = rCopy.mbInclJustify;
211
0
    mbInclFrame = rCopy.mbInclFrame;
212
0
    mbInclBackground = rCopy.mbInclBackground;
213
0
    mbInclValueFormat = rCopy.mbInclValueFormat;
214
0
    mbInclWidthHeight = rCopy.mbInclWidthHeight;
215
0
    mbUseFirstRowStyles = rCopy.mbUseFirstRowStyles;
216
0
    mbUseLastRowStyles = rCopy.mbUseLastRowStyles;
217
0
    mbUseFirstColStyles = rCopy.mbUseFirstColStyles;
218
0
    mbUseLastColStyles = rCopy.mbUseLastColStyles;
219
0
    mbUseBandedRowStyles = rCopy.mbUseBandedRowStyles;
220
0
    mbUseBandedColStyles = rCopy.mbUseBandedColStyles;
221
222
0
    return *this;
223
0
}
224
225
void SvxAutoFormatData::FillToItemSet(size_t nIndex, SfxItemSet& rItemSet) const
226
0
{
227
0
    if (nIndex >= ELEMENT_COUNT)
228
0
    {
229
0
        SAL_WARN("svx", "SvxAutoFormatData::FillToItemSet - index out of bounds: " << nIndex);
230
0
        return;
231
0
    }
232
233
0
    const SvxAutoFormatDataField& rField = *GetField(nIndex);
234
0
    const SvxAutoFormatDataField& rDefault = *GetDefaultField();
235
236
0
    if (IsFont())
237
0
    {
238
        // regular font
239
0
        if (rField.GetFont() != rDefault.GetFont())
240
0
            rItemSet.Put(rField.GetFont());
241
242
0
        if (rField.GetHeight() != rDefault.GetHeight())
243
0
            rItemSet.Put(rField.GetHeight());
244
245
0
        if (rField.GetWeight() != rDefault.GetWeight())
246
0
            rItemSet.Put(rField.GetWeight());
247
248
0
        if (rField.GetPosture() != rDefault.GetPosture())
249
0
            rItemSet.Put(rField.GetPosture());
250
251
        // CJK Font
252
0
        if (rField.GetCJKFont() != rDefault.GetCJKFont())
253
0
            rItemSet.Put(rField.GetCJKFont());
254
255
0
        if (rField.GetCJKHeight() != rDefault.GetCJKHeight())
256
0
            rItemSet.Put(rField.GetCJKHeight());
257
0
        if (rField.GetCJKWeight() != rDefault.GetCJKWeight())
258
0
            rItemSet.Put(rField.GetCJKWeight());
259
260
0
        if (rField.GetCJKPosture() != rDefault.GetCJKPosture())
261
0
            rItemSet.Put(rField.GetCJKPosture());
262
263
        // CTL font
264
0
        if (rField.GetCTLFont() != rDefault.GetCTLFont())
265
0
            rItemSet.Put(rField.GetCTLFont());
266
267
0
        if (rField.GetCTLHeight() != rDefault.GetCTLHeight())
268
0
            rItemSet.Put(rField.GetCTLHeight());
269
270
0
        if (rField.GetCTLWeight() != rDefault.GetCTLWeight())
271
0
            rItemSet.Put(rField.GetCTLWeight());
272
273
0
        if (rField.GetCTLPosture() != rDefault.GetCTLPosture())
274
0
            rItemSet.Put(rField.GetCTLPosture());
275
276
        // Font properties
277
0
        if (rField.GetUnderline() != rDefault.GetUnderline())
278
0
            rItemSet.Put(rField.GetUnderline());
279
280
0
        if (rField.GetColor() != rDefault.GetColor())
281
0
            rItemSet.Put(rField.GetColor());
282
0
    }
283
284
0
    if (IsJustify())
285
0
    {
286
0
        if (rField.GetHorJustify() != rDefault.GetHorJustify())
287
0
            rItemSet.Put(rField.GetHorJustify());
288
289
0
        if (rField.GetVerJustify() != rDefault.GetVerJustify())
290
0
            rItemSet.Put(rField.GetVerJustify());
291
0
    }
292
293
0
    if (IsBackground())
294
0
    {
295
0
        if (rField.GetBackground() != rDefault.GetBackground())
296
0
            rItemSet.Put(rField.GetBackground());
297
0
    }
298
0
}
299
300
void SvxAutoFormatData::MergeStyle(const SvxAutoFormatData& pParent)
301
0
{
302
0
    for (sal_uInt8 i = 0; i < ELEMENT_COUNT; i++)
303
0
    {
304
0
        if ((!UseFirstRowStyles()
305
0
             && (i == FIRST_ROW || i == FIRST_ROW_START_COL || i == FIRST_ROW_END_COL
306
0
                 || i == FIRST_ROW_EVEN_COL))
307
0
            || (!UseLastRowStyles()
308
0
                && (i == LAST_ROW || i == LAST_ROW_START_COL || i == LAST_ROW_END_COL
309
0
                    || i == LAST_ROW_EVEN_COL))
310
0
            || (!UseFirstColStyles() && i == FIRST_COL) || (!UseLastColStyles() && i == LAST_COL)
311
0
            || (!UseBandedRowStyles() && (i == EVEN_ROW || i == ODD_ROW))
312
0
            || (!UseBandedColStyles() && (i == EVEN_COL || i == ODD_COL)))
313
0
        {
314
0
            continue;
315
0
        }
316
317
0
        SvxAutoFormatDataField& pField = *GetField(i);
318
0
        const SvxAutoFormatDataField& pNew = *pParent.GetField(i);
319
320
        // regular font
321
0
        if (!pField.IsPropertySet(PROP_FONT))
322
0
            pField.SetFont(pNew.GetFont());
323
0
        if (!pField.IsPropertySet(PROP_HEIGHT))
324
0
            pField.SetHeight(pNew.GetHeight());
325
0
        if (!pField.IsPropertySet(PROP_WEIGHT))
326
0
            pField.SetWeight(pNew.GetWeight());
327
0
        if (!pField.IsPropertySet(PROP_POSTURE))
328
0
            pField.SetPosture(pNew.GetPosture());
329
330
        // CJK font
331
0
        if (!pField.IsPropertySet(PROP_CJK_FONT))
332
0
            pField.SetCJKFont(pNew.GetCJKFont());
333
0
        if (!pField.IsPropertySet(PROP_CJK_HEIGHT))
334
0
            pField.SetCJKHeight(pNew.GetCJKHeight());
335
0
        if (!pField.IsPropertySet(PROP_CJK_WEIGHT))
336
0
            pField.SetCJKWeight(pNew.GetCJKWeight());
337
0
        if (!pField.IsPropertySet(PROP_CJK_POSTURE))
338
0
            pField.SetCJKPosture(pNew.GetCJKPosture());
339
340
        // CTL font
341
0
        if (!pField.IsPropertySet(PROP_CTL_FONT))
342
0
            pField.SetCTLFont(pNew.GetCTLFont());
343
0
        if (!pField.IsPropertySet(PROP_CTL_HEIGHT))
344
0
            pField.SetCTLHeight(pNew.GetCTLHeight());
345
0
        if (!pField.IsPropertySet(PROP_CTL_WEIGHT))
346
0
            pField.SetCTLWeight(pNew.GetCTLWeight());
347
0
        if (!pField.IsPropertySet(PROP_CTL_POSTURE))
348
0
            pField.SetCTLPosture(pNew.GetCTLPosture());
349
350
        // Font properties
351
0
        if (!pField.IsPropertySet(PROP_UNDERLINE))
352
0
            pField.SetUnderline(pNew.GetUnderline());
353
354
0
        if (!pField.IsPropertySet(PROP_COLOR))
355
0
            pField.SetColor(pNew.GetColor());
356
0
        if (!pField.IsPropertySet(PROP_HOR_JUSTIFY))
357
0
        {
358
0
            pField.SetAdjust(pNew.GetAdjust());
359
0
            pField.SetHorJustify(pNew.GetHorJustify());
360
0
        }
361
0
        if (!pField.IsPropertySet(PROP_VER_JUSTIFY))
362
0
            pField.SetVerJustify(pNew.GetVerJustify());
363
364
0
        SvxBoxItem aBox = pField.IsPropertySet(PROP_BOX) ? pField.GetBox() : pNew.GetBox();
365
0
        sal_Int16 nPadding = pField.IsPropertySet(PROP_BOX)
366
0
                                 ? pField.GetBox().GetDistance(SvxBoxItemLine::RIGHT)
367
0
                                 : pNew.GetBox().GetDistance(SvxBoxItemLine::RIGHT);
368
369
0
        aBox.SetDistance(nPadding, SvxBoxItemLine::RIGHT);
370
0
        pField.SetBox(aBox);
371
372
0
        if (!pField.IsPropertySet(PROP_BACKGROUND))
373
0
            pField.SetBackground(pNew.GetBackground());
374
0
    }
375
0
}
376
377
void SvxAutoFormatData::ResetAutoFormat(SvxAutoFormatData& pOld)
378
0
{
379
0
    for (int i = 0; i < ELEMENT_COUNT; i++)
380
0
    {
381
0
        SvxAutoFormatDataField& pField = *GetField(i);
382
0
        const SvxAutoFormatDataField& pNew = *pOld.GetField(i);
383
0
        pField.SetPropertySet(pNew.GetPropertySet());
384
        // regular font
385
0
        pField.SetFont(pNew.GetFont());
386
0
        pField.SetHeight(pNew.GetHeight());
387
0
        pField.SetWeight(pNew.GetWeight());
388
0
        pField.SetPosture(pNew.GetPosture());
389
390
        // CJK font
391
0
        pField.SetCJKFont(pNew.GetCJKFont());
392
0
        pField.SetCJKHeight(pNew.GetCJKHeight());
393
0
        pField.SetCJKWeight(pNew.GetCJKWeight());
394
0
        pField.SetCJKPosture(pNew.GetCJKPosture());
395
396
        // CTL font
397
0
        pField.SetCTLFont(pNew.GetCTLFont());
398
0
        pField.SetCTLHeight(pNew.GetCTLHeight());
399
0
        pField.SetCTLWeight(pNew.GetCTLWeight());
400
0
        pField.SetCTLPosture(pNew.GetCTLPosture());
401
402
        // Font properties
403
0
        pField.SetUnderline(pNew.GetUnderline());
404
0
        pField.SetColor(pNew.GetColor());
405
406
0
        pField.SetAdjust(pNew.GetAdjust());
407
0
        pField.SetHorJustify(pNew.GetHorJustify());
408
0
        pField.SetVerJustify(pNew.GetVerJustify());
409
410
0
        pField.SetBox(pNew.GetBox());
411
0
        pField.SetBackground(pNew.GetBackground());
412
0
    }
413
0
}
414
415
367
SvxAutoFormat::~SvxAutoFormat() = default;
416
417
void SvxAutoFormat::ResetParent(const OUString& rName)
418
0
{
419
0
    OUString sParent;
420
0
    if (size())
421
0
        sParent = GetData(0)->GetName();
422
423
0
    for (size_t i = 0; i < size(); i++)
424
0
    {
425
0
        if (GetData(i)->GetParent() == rName)
426
0
        {
427
0
            GetData(i)->SetParent(sParent);
428
0
        }
429
0
    }
430
0
}
431
432
bool SvxAutoFormat::Load(bool bWriter)
433
367
{
434
367
    OUString sStyles = "/svx/tablestyles.xml";
435
367
    if (!bWriter)
436
0
        sStyles = "/calc/tablestyles.xml";
437
438
367
    try
439
367
    {
440
367
        OUString sPath(u"$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER + sStyles);
441
367
        rtl::Bootstrap::expandMacros(sPath);
442
367
        SfxMedium aMedium(sPath, StreamMode::STD_READ);
443
444
367
        SvStream* pStream = aMedium.GetInStream();
445
367
        if (!pStream || pStream->GetError() != ERRCODE_NONE)
446
367
        {
447
367
            SAL_WARN("svx", "Cannot open table styles file: " << sPath);
448
367
            return false;
449
367
        }
450
451
0
        uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
452
0
        if (!xContext.is())
453
0
        {
454
0
            SAL_WARN("svx", "No component context available");
455
0
            return false;
456
0
        }
457
458
0
        uno::Reference<io::XInputStream> xInputStream = new utl::OInputStreamWrapper(*pStream);
459
0
        rtl::Reference<SvxTableStylesImport> xImport = new SvxTableStylesImport(xContext, *this);
460
461
0
        xml::sax::InputSource aInputSource;
462
0
        aInputSource.aInputStream = xInputStream;
463
0
        aInputSource.sSystemId = sPath;
464
465
0
        xImport->parseStream(aInputSource);
466
0
        return true;
467
0
    }
468
367
    catch (const uno::Exception& e)
469
367
    {
470
0
        SAL_WARN("svx", "Error loading auto formats: " << e.Message);
471
0
        return false;
472
0
    }
473
367
}
474
475
// This method is only called by calc. In writer tables styles are stored at document level
476
bool SvxAutoFormat::Save()
477
0
{
478
0
    try
479
0
    {
480
0
        OUString sPath(u"$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/calc/tablestyles.xml"_ustr);
481
0
        rtl::Bootstrap::expandMacros(sPath);
482
0
        SfxMedium aMedium(sPath, StreamMode::STD_WRITE);
483
484
0
        SvStream* pStream = aMedium.GetOutStream();
485
0
        if (!pStream || pStream->GetError() != ERRCODE_NONE)
486
0
        {
487
0
            SAL_WARN("svx", "Cannot save table styles to file: " << sPath);
488
0
            return false;
489
0
        }
490
491
0
        uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
492
0
        if (!xContext.is())
493
0
        {
494
0
            SAL_WARN("svx", "No component context available");
495
0
            return false;
496
0
        }
497
498
0
        uno::Reference<io::XOutputStream> const xOutStream(new utl::OOutputStreamWrapper(*pStream));
499
0
        uno::Reference<xml::sax::XWriter> const xWriter(xml::sax::Writer::create(xContext));
500
0
        rtl::Reference<SvxTableStylesExport> xExport
501
0
            = new SvxTableStylesExport(xContext, sPath, xWriter, *this);
502
503
0
        xWriter->setOutputStream(xOutStream);
504
0
        xExport->ExportStyles();
505
506
0
        pStream->FlushBuffer();
507
0
        aMedium.Commit();
508
0
        return true;
509
0
    }
510
0
    catch (const uno::Exception& e)
511
0
    {
512
0
        SAL_WARN("svx", "Error saving auto formats: " << e.Message);
513
0
        return false;
514
0
    }
515
0
}
516
517
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */