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