Line data Source code
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 "xmlexpit.hxx"
21 :
22 : #include <rtl/ustrbuf.hxx>
23 : #include <sax/tools/converter.hxx>
24 : #include <svl/itempool.hxx>
25 : #include <svl/poolitem.hxx>
26 : #include <svl/itemset.hxx>
27 : #include <xmloff/xmluconv.hxx>
28 : #include <xmloff/attrlist.hxx>
29 : #include <xmloff/nmspmap.hxx>
30 : #include <xmloff/xmlnmspe.hxx>
31 : #include <xmloff/prhdlfac.hxx>
32 : #include <xmloff/xmltypes.hxx>
33 : #include <editeng/xmlcnitm.hxx>
34 : #include <xmloff/xmlexp.hxx>
35 : #include <xmloff/xmlprhdl.hxx>
36 : #include <editeng/memberids.hrc>
37 : #include "hintids.hxx"
38 : #include "unomid.h"
39 : #include <svx/unomid.hxx>
40 : #include <editeng/lrspitem.hxx>
41 : #include <editeng/ulspitem.hxx>
42 : #include <editeng/shaditem.hxx>
43 : #include <editeng/boxitem.hxx>
44 : #include <editeng/formatbreakitem.hxx>
45 : #include <editeng/keepitem.hxx>
46 : #include <editeng/brushitem.hxx>
47 : #include "fmtpdsc.hxx"
48 : #include "fmtornt.hxx"
49 : #include "fmtfsize.hxx"
50 :
51 : #include "fmtlsplt.hxx"
52 : #include "xmlithlp.hxx"
53 :
54 : #include "fmtrowsplt.hxx"
55 :
56 : using ::editeng::SvxBorderLine;
57 : using namespace ::com::sun::star;
58 : using namespace ::xmloff::token;
59 : using uno::Any;
60 :
61 : // fills the given attribute list with the items in the given set
62 20 : void SvXMLExportItemMapper::exportXML( const SvXMLExport& rExport,
63 : SvXMLAttributeList& rAttrList,
64 : const SfxItemSet& rSet,
65 : const SvXMLUnitConverter& rUnitConverter,
66 : const SvXMLNamespaceMap& rNamespaceMap,
67 : sal_uInt16 nFlags,
68 : std::vector<sal_uInt16> *pIndexArray ) const
69 : {
70 20 : const sal_uInt16 nCount = mrMapEntries->getCount();
71 20 : sal_uInt16 nIndex = 0;
72 :
73 436 : while( nIndex < nCount )
74 : {
75 396 : SvXMLItemMapEntry* pEntry = mrMapEntries->getByIndex( nIndex );
76 :
77 : // we have a valid map entry here, so lets use it...
78 396 : if( 0 == (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_EXPORT) )
79 : {
80 : const SfxPoolItem* pItem = GetItem( rSet, pEntry->nWhichId,
81 396 : nFlags );
82 : // do we have an item?
83 396 : if(pItem)
84 : {
85 252 : if( 0 != (pEntry->nMemberId & MID_SW_FLAG_ELEMENT_ITEM_EXPORT) )
86 : {
87 : // element items do not add any properties,
88 : // we export it later
89 0 : if( pIndexArray )
90 0 : pIndexArray->push_back( nIndex );
91 :
92 : }
93 : else
94 : {
95 : exportXML( rExport, rAttrList, *pItem, *pEntry, rUnitConverter,
96 252 : rNamespaceMap, nFlags, &rSet );
97 : }
98 : }
99 : }
100 : else
101 : {
102 : handleNoItem( rAttrList, *pEntry, rUnitConverter, rNamespaceMap,
103 0 : rSet );
104 : }
105 396 : nIndex++;
106 : }
107 20 : }
108 :
109 252 : void SvXMLExportItemMapper::exportXML( const SvXMLExport& rExport,
110 : SvXMLAttributeList& rAttrList,
111 : const SfxPoolItem& rItem,
112 : const SvXMLItemMapEntry& rEntry,
113 : const SvXMLUnitConverter& rUnitConverter,
114 : const SvXMLNamespaceMap& rNamespaceMap,
115 : sal_uInt16 /*nFlags*/,
116 : const SfxItemSet *pSet ) const
117 : {
118 252 : if( 0 != (rEntry.nMemberId & MID_SW_FLAG_SPECIAL_ITEM_EXPORT) )
119 : {
120 8 : if( rItem.ISA( SwFmtRowSplit ) )
121 : {
122 0 : OUString aValue;
123 0 : bool bAddAttribute = true;
124 0 : if( rEntry.nNameSpace == XML_NAMESPACE_STYLE )
125 : {
126 0 : if( (rExport.getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE ) == 0 ||
127 : !QueryXMLValue(rItem, aValue,
128 : static_cast< sal_uInt16 >( rEntry.nMemberId & MID_SW_FLAG_MASK ),
129 0 : rUnitConverter ) )
130 : {
131 0 : bAddAttribute = false;
132 : }
133 : }
134 : else
135 : {
136 0 : OUStringBuffer aOut;
137 0 : const SfxBoolItem* pSplit = PTR_CAST(SfxBoolItem, &rItem);
138 : assert(pSplit && "Wrong Which-ID");
139 0 : const unsigned int eEnum = (pSplit && pSplit->GetValue()) ? 1 : 0;
140 0 : SvXMLUnitConverter::convertEnum( aOut, eEnum, aXML_KeepTogetherType );
141 0 : aValue = aOut.makeStringAndClear();
142 : }
143 0 : if( bAddAttribute )
144 : {
145 : const OUString sName( rNamespaceMap.GetQNameByKey( rEntry.nNameSpace,
146 0 : GetXMLToken(rEntry.eLocalName) ) );
147 0 : rAttrList.AddAttribute( sName, aValue );
148 0 : }
149 : }
150 8 : if( rItem.ISA( SvXMLAttrContainerItem ) )
151 : {
152 0 : SvXMLNamespaceMap *pNewNamespaceMap = 0;
153 0 : const SvXMLNamespaceMap *pNamespaceMap = &rNamespaceMap;
154 :
155 : const SvXMLAttrContainerItem *pUnknown =
156 0 : PTR_CAST( SvXMLAttrContainerItem, &rItem );
157 :
158 0 : const sal_uInt16 nCount = pUnknown ? pUnknown->GetAttrCount() : 0;
159 0 : for( sal_uInt16 i=0; i < nCount; i++ )
160 : {
161 0 : const OUString sPrefix( pUnknown->GetAttrPrefix( i ) );
162 0 : if( !sPrefix.isEmpty() )
163 : {
164 0 : const OUString sNamespace( pUnknown->GetAttrNamespace( i ) );
165 :
166 : // if the prefix isn't defined yet or has another meaning,
167 : // we have to redefine it now.
168 0 : const sal_uInt16 nIdx = pNamespaceMap->GetIndexByPrefix( sPrefix );
169 0 : if( USHRT_MAX == nIdx ||
170 0 : pNamespaceMap->GetNameByIndex( nIdx ) != sNamespace )
171 : {
172 0 : if( !pNewNamespaceMap )
173 : {
174 : pNewNamespaceMap =
175 0 : new SvXMLNamespaceMap( rNamespaceMap );
176 0 : pNamespaceMap = pNewNamespaceMap;
177 : }
178 0 : pNewNamespaceMap->Add( sPrefix, sNamespace );
179 :
180 0 : rAttrList.AddAttribute( GetXMLToken(XML_XMLNS) + ":" + sPrefix,
181 0 : sNamespace );
182 : }
183 :
184 0 : rAttrList.AddAttribute( sPrefix + ":" + pUnknown->GetAttrLName(i),
185 0 : pUnknown->GetAttrValue(i) );
186 : }
187 : else
188 : {
189 0 : rAttrList.AddAttribute( pUnknown->GetAttrLName(i),
190 0 : pUnknown->GetAttrValue(i) );
191 : }
192 0 : }
193 :
194 0 : delete pNewNamespaceMap;
195 : }
196 : else
197 : {
198 : handleSpecialItem( rAttrList, rEntry, rItem, rUnitConverter,
199 8 : rNamespaceMap, pSet );
200 : }
201 : }
202 244 : else if( 0 == (rEntry.nMemberId & MID_SW_FLAG_ELEMENT_ITEM_EXPORT) )
203 : {
204 244 : OUString aValue;
205 244 : if( QueryXMLValue(rItem, aValue,
206 : static_cast< sal_uInt16 >(
207 : rEntry.nMemberId & MID_SW_FLAG_MASK ),
208 244 : rUnitConverter ) )
209 : {
210 : const OUString sName(
211 : rNamespaceMap.GetQNameByKey( rEntry.nNameSpace,
212 72 : GetXMLToken(rEntry.eLocalName)));
213 72 : rAttrList.AddAttribute( sName, aValue );
214 244 : }
215 : }
216 252 : }
217 :
218 20 : void SvXMLExportItemMapper::exportElementItems(
219 : SvXMLExport& rExport,
220 : const SvXMLUnitConverter& rUnitConverter,
221 : const SfxItemSet &rSet,
222 : sal_uInt16 nFlags,
223 : const std::vector<sal_uInt16> &rIndexArray ) const
224 : {
225 20 : const size_t nCount = rIndexArray.size();
226 :
227 20 : bool bItemsExported = false;
228 20 : for( size_t nIndex = 0; nIndex < nCount; ++nIndex )
229 : {
230 0 : const sal_uInt16 nElement = rIndexArray[ nIndex ];
231 0 : SvXMLItemMapEntry* pEntry = mrMapEntries->getByIndex( nElement );
232 : OSL_ENSURE( 0 != (pEntry->nMemberId & MID_SW_FLAG_ELEMENT_ITEM_EXPORT),
233 : "wrong mid flag!" );
234 :
235 0 : const SfxPoolItem* pItem = GetItem( rSet, pEntry->nWhichId, nFlags );
236 : // do we have an item?
237 0 : if(pItem)
238 : {
239 0 : rExport.IgnorableWhitespace();
240 : handleElementItem( rExport, *pEntry, *pItem, rUnitConverter,
241 0 : rSet, nFlags);
242 0 : bItemsExported = true;
243 : }
244 : }
245 :
246 20 : if( bItemsExported )
247 0 : rExport.IgnorableWhitespace();
248 20 : }
249 :
250 : /** returns the item with the given WhichId from the given ItemSet if its
251 : set or its default item if its not set and the XML_EXPORT_FLAG_DEEP
252 : is set in the flags
253 : */
254 396 : const SfxPoolItem* SvXMLExportItemMapper::GetItem( const SfxItemSet& rSet,
255 : sal_uInt16 nWhichId,
256 : sal_uInt16 nFlags )
257 : {
258 : // first get item from itemset
259 : const SfxPoolItem* pItem;
260 : SfxItemState eState =
261 : rSet.GetItemState( nWhichId,
262 396 : ( nFlags & XML_EXPORT_FLAG_DEEP ) != 0,
263 396 : &pItem );
264 :
265 396 : if( SfxItemState::SET == eState )
266 : {
267 252 : return pItem;
268 : }
269 144 : else if( (nFlags & XML_EXPORT_FLAG_DEFAULTS) != 0 &&
270 : SFX_WHICH_MAX > nWhichId )
271 : {
272 : // if its not set, try the pool if we export defaults
273 0 : return &rSet.GetPool()->GetDefaultItem(nWhichId);
274 : }
275 : else
276 : {
277 144 : return NULL;
278 : }
279 : }
280 :
281 242 : SvXMLExportItemMapper::SvXMLExportItemMapper( SvXMLItemMapEntriesRef rMapEntries )
282 : {
283 242 : mrMapEntries = rMapEntries;
284 242 : }
285 :
286 242 : SvXMLExportItemMapper::~SvXMLExportItemMapper()
287 : {
288 242 : }
289 :
290 20 : void SvXMLExportItemMapper::exportXML( SvXMLExport& rExport,
291 : const SfxItemSet& rSet,
292 : const SvXMLUnitConverter& rUnitConverter,
293 : XMLTokenEnum ePropToken,
294 : sal_uInt16 nFlags ) const
295 : {
296 20 : std::vector<sal_uInt16> aIndexArray;
297 :
298 20 : exportXML( rExport, rExport.GetAttrList(), rSet, rUnitConverter,
299 40 : rExport.GetNamespaceMap(), nFlags, &aIndexArray );
300 :
301 40 : if( rExport.GetAttrList().getLength() > 0L ||
302 20 : (nFlags & XML_EXPORT_FLAG_EMPTY) != 0 ||
303 0 : !aIndexArray.empty() )
304 : {
305 20 : if( (nFlags & XML_EXPORT_FLAG_IGN_WS) != 0 )
306 : {
307 20 : rExport.IgnorableWhitespace();
308 : }
309 :
310 : SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE, ePropToken,
311 20 : false, false );
312 : exportElementItems( rExport, rUnitConverter,
313 20 : rSet, nFlags, aIndexArray );
314 20 : }
315 20 : }
316 :
317 : /** this method is called for every item that has the
318 : MID_SW_FLAG_SPECIAL_ITEM_EXPORT flag set */
319 0 : void SvXMLExportItemMapper::handleSpecialItem( SvXMLAttributeList& /*rAttrList*/,
320 : const SvXMLItemMapEntry& /*rEntry*/,
321 : const SfxPoolItem& /*rItem*/,
322 : const SvXMLUnitConverter& /*rUnitConverter*/,
323 : const SvXMLNamespaceMap& /*rNamespaceMap*/,
324 : const SfxItemSet* /*pSet*/ /* = NULL */ ) const
325 : {
326 : OSL_FAIL( "special item not handled in xml export" );
327 0 : }
328 :
329 : /** this method is called for every item that has the
330 : MID_SW_FLAG_NO_ITEM_EXPORT flag set */
331 0 : void SvXMLExportItemMapper::handleNoItem( SvXMLAttributeList& /*rAttrList*/,
332 : const SvXMLItemMapEntry& /*rEntry*/,
333 : const SvXMLUnitConverter& /*rUnitConverter*/,
334 : const SvXMLNamespaceMap& /*rNamespaceMap*/,
335 : const SfxItemSet& /*rSet*/ ) const
336 : {
337 : OSL_FAIL( "no item not handled in xml export" );
338 0 : }
339 :
340 : /** this method is called for every item that has the
341 : MID_SW_FLAG_ELEMENT_EXPORT flag set */
342 0 : void SvXMLExportItemMapper::handleElementItem(
343 : SvXMLExport& /*rExport*/,
344 : const SvXMLItemMapEntry& /*rEntry*/,
345 : const SfxPoolItem& /*rItem*/,
346 : const SvXMLUnitConverter& /*rUnitConverter*/,
347 : const SfxItemSet& /*rSet*/,
348 : sal_uInt16 /*nFlags*/ ) const
349 : {
350 : OSL_FAIL( "element item not handled in xml export" );
351 0 : }
352 :
353 0 : static bool lcl_isOdfDoubleLine( const SvxBorderLine* pLine )
354 : {
355 0 : bool bIsOdfDouble = false;
356 0 : switch (pLine->GetBorderLineStyle())
357 : {
358 : case table::BorderLineStyle::DOUBLE:
359 : case table::BorderLineStyle::THINTHICK_SMALLGAP:
360 : case table::BorderLineStyle::THINTHICK_MEDIUMGAP:
361 : case table::BorderLineStyle::THINTHICK_LARGEGAP:
362 : case table::BorderLineStyle::THICKTHIN_SMALLGAP:
363 : case table::BorderLineStyle::THICKTHIN_MEDIUMGAP:
364 : case table::BorderLineStyle::THICKTHIN_LARGEGAP:
365 0 : bIsOdfDouble = true;
366 0 : break;
367 : default:
368 0 : break;
369 : }
370 0 : return bIsOdfDouble;
371 : }
372 :
373 248 : bool SvXMLExportItemMapper::QueryXMLValue(
374 : const SfxPoolItem& rItem,
375 : OUString& rValue,
376 : sal_uInt16 nMemberId,
377 : const SvXMLUnitConverter& rUnitConverter )
378 : {
379 248 : bool bOk = false;
380 248 : OUStringBuffer aOut;
381 :
382 248 : switch ( rItem.Which() )
383 : {
384 :
385 : case RES_LR_SPACE:
386 : {
387 0 : const SvxLRSpaceItem* pLRSpace = PTR_CAST(SvxLRSpaceItem, &rItem);
388 : OSL_ENSURE( pLRSpace != NULL, "Wrong Which-ID!" );
389 :
390 0 : bOk = true;
391 0 : switch( nMemberId )
392 : {
393 : case MID_L_MARGIN:
394 0 : if(pLRSpace->GetPropLeft() != 100)
395 : {
396 : ::sax::Converter::convertPercent(
397 0 : aOut, pLRSpace->GetPropLeft() );
398 : }
399 : else
400 : {
401 : rUnitConverter.convertMeasureToXML(
402 0 : aOut, pLRSpace->GetLeft() );
403 : }
404 0 : break;
405 :
406 : case MID_R_MARGIN:
407 0 : if(pLRSpace->GetPropRight() != 100)
408 : {
409 : ::sax::Converter::convertPercent(
410 0 : aOut, pLRSpace->GetPropRight() );
411 : }
412 : else
413 : {
414 : rUnitConverter.convertMeasureToXML(
415 0 : aOut, pLRSpace->GetRight() );
416 : }
417 0 : break;
418 :
419 : case MID_FIRST_AUTO:
420 0 : if( pLRSpace->IsAutoFirst() )
421 : {
422 : ::sax::Converter::convertBool(
423 0 : aOut, pLRSpace->IsAutoFirst() );
424 : }
425 : else
426 0 : bOk = false;
427 0 : break;
428 :
429 : case MID_FIRST_LINE_INDENT:
430 0 : if( !pLRSpace->IsAutoFirst() )
431 : {
432 0 : if(pLRSpace->GetPropTxtFirstLineOfst() != 100)
433 : {
434 : ::sax::Converter::convertPercent(
435 0 : aOut, pLRSpace->GetPropTxtFirstLineOfst() );
436 : }
437 : else
438 : {
439 : rUnitConverter.convertMeasureToXML(
440 0 : aOut, pLRSpace->GetTxtFirstLineOfst() );
441 : }
442 : }
443 : else
444 0 : bOk = false;
445 0 : break;
446 :
447 : default:
448 : OSL_FAIL( "unknown member id!");
449 0 : bOk = false;
450 0 : break;
451 : }
452 : }
453 0 : break;
454 :
455 : case RES_UL_SPACE:
456 : {
457 0 : const SvxULSpaceItem* pULSpace = PTR_CAST(SvxULSpaceItem, &rItem);
458 : OSL_ENSURE( pULSpace != NULL, "Wrong Which-ID!" );
459 :
460 0 : switch( nMemberId )
461 : {
462 : case MID_UP_MARGIN:
463 0 : if( pULSpace->GetPropUpper() != 100 )
464 : {
465 : ::sax::Converter::convertPercent(
466 0 : aOut, pULSpace->GetPropUpper() );
467 : }
468 : else
469 : {
470 : rUnitConverter.convertMeasureToXML(
471 0 : aOut, pULSpace->GetUpper() );
472 : }
473 0 : break;
474 :
475 : case MID_LO_MARGIN:
476 0 : if( pULSpace->GetPropLower() != 100 )
477 : {
478 : ::sax::Converter::convertPercent(
479 0 : aOut, pULSpace->GetPropLower() );
480 : }
481 : else
482 : {
483 : rUnitConverter.convertMeasureToXML(
484 0 : aOut, pULSpace->GetLower() );
485 : }
486 0 : break;
487 :
488 : default:
489 : OSL_FAIL("unknown MemberId");
490 : };
491 :
492 0 : bOk = true;
493 : }
494 0 : break;
495 :
496 : case RES_SHADOW:
497 : {
498 0 : const SvxShadowItem* pShadow = PTR_CAST(SvxShadowItem, &rItem);
499 : assert(pShadow && "Wrong Which-ID");
500 0 : if (pShadow)
501 : {
502 0 : sal_Int32 nX = 1, nY = 1;
503 0 : switch( pShadow->GetLocation() )
504 : {
505 : case SVX_SHADOW_TOPLEFT:
506 0 : nX = -1;
507 0 : nY = -1;
508 0 : break;
509 : case SVX_SHADOW_TOPRIGHT:
510 0 : nY = -1;
511 0 : break;
512 : case SVX_SHADOW_BOTTOMLEFT:
513 0 : nX = -1;
514 0 : break;
515 : case SVX_SHADOW_BOTTOMRIGHT:
516 0 : break;
517 : case SVX_SHADOW_NONE:
518 : default:
519 0 : rValue = GetXMLToken(XML_NONE);
520 0 : return true;
521 : }
522 :
523 0 : nX *= pShadow->GetWidth();
524 0 : nY *= pShadow->GetWidth();
525 :
526 0 : ::sax::Converter::convertColor(aOut, pShadow->GetColor().GetColor());
527 0 : aOut.append( ' ' );
528 0 : rUnitConverter.convertMeasureToXML( aOut, nX );
529 0 : aOut.append( ' ' );
530 0 : rUnitConverter.convertMeasureToXML( aOut, nY );
531 :
532 0 : bOk = true;
533 : }
534 : }
535 0 : break;
536 :
537 : case RES_BOX:
538 : {
539 240 : const SvxBoxItem* pBox = PTR_CAST(SvxBoxItem, &rItem);
540 : assert(pBox && "Wrong Which-ID");
541 240 : if (pBox)
542 : {
543 : /**
544 : xml -> MemberId
545 :
546 : border-padding ALL_BORDER_PADDING
547 : border-padding-before LEFT_BORDER_PADDING
548 : border-padding-after RIGHT_BORDER_PADDING
549 : border-padding-start TOP_BORDER_PADDING
550 : border-padding-end BOTTOM_BORDER_PADDING
551 :
552 : border ALL_BORDER
553 : border-before LEFT_BORDER
554 : border-after RIGHT_BORDER
555 : border-start TOP_BORDER
556 : border-end BOTTOM_BORDER
557 :
558 : border-line-width ALL_BORDER_LINE_WIDTH
559 : border-line-width-before LEFT_BORDER_LINE_WIDTH
560 : border-line-width-after RIGHT_BORDER_LINE_WIDTH
561 : border-line-width-start TOP_BORDER_LINE_WIDTH
562 : border-line-width-end BOTTOM_BORDER_LINE_WIDTH
563 : */
564 :
565 240 : const SvxBorderLine* pLeft = pBox->GetLeft();
566 240 : const SvxBorderLine* pRight = pBox->GetRight();
567 240 : const SvxBorderLine* pTop = pBox->GetTop();
568 240 : const SvxBorderLine* pBottom = pBox->GetBottom();
569 240 : const sal_uInt16 nTopDist = pBox->GetDistance( BOX_LINE_TOP );
570 240 : const sal_uInt16 nBottomDist = pBox->GetDistance( BOX_LINE_BOTTOM );
571 240 : const sal_uInt16 nLeftDist = pBox->GetDistance( BOX_LINE_LEFT );
572 240 : const sal_uInt16 nRightDist = pBox->GetDistance( BOX_LINE_RIGHT );
573 :
574 : // check if we need to export it
575 240 : switch( nMemberId )
576 : {
577 : case ALL_BORDER_PADDING:
578 : case LEFT_BORDER_PADDING:
579 : case RIGHT_BORDER_PADDING:
580 : case TOP_BORDER_PADDING:
581 : case BOTTOM_BORDER_PADDING:
582 : {
583 80 : bool bEqual = nLeftDist == nRightDist &&
584 160 : nLeftDist == nTopDist &&
585 80 : nLeftDist == nBottomDist;
586 : // don't export individual paddings if all paddings are equal and
587 : // don't export all padding if some paddings are not equal
588 96 : if( (bEqual && ALL_BORDER_PADDING != nMemberId) ||
589 16 : (!bEqual && ALL_BORDER_PADDING == nMemberId) )
590 64 : return false;
591 : }
592 16 : break;
593 : case ALL_BORDER:
594 : case LEFT_BORDER:
595 : case RIGHT_BORDER:
596 : case TOP_BORDER:
597 : case BOTTOM_BORDER:
598 : {
599 40 : bool bEqual = ( NULL == pTop && NULL == pBottom &&
600 100 : NULL == pLeft && NULL == pRight ) ||
601 60 : ( pTop && pBottom && pLeft && pRight &&
602 60 : *pTop == *pBottom && *pTop == *pLeft &&
603 100 : *pTop == *pRight );
604 :
605 : // don't export individual borders if all are the same and
606 : // don't export all borders if some are not equal
607 144 : if( (bEqual && ALL_BORDER != nMemberId) ||
608 124 : (!bEqual && ALL_BORDER == nMemberId) )
609 28 : return false;
610 : }
611 52 : break;
612 : case ALL_BORDER_LINE_WIDTH:
613 : case LEFT_BORDER_LINE_WIDTH:
614 : case RIGHT_BORDER_LINE_WIDTH:
615 : case TOP_BORDER_LINE_WIDTH:
616 : case BOTTOM_BORDER_LINE_WIDTH:
617 : {
618 : // if no line is set, there is nothing to export
619 80 : if( !pTop && !pBottom && !pLeft && !pRight )
620 0 : return false;
621 :
622 40 : bool bEqual = NULL != pTop &&
623 40 : NULL != pBottom &&
624 120 : NULL != pLeft &&
625 80 : NULL != pRight;
626 :
627 80 : if( bEqual )
628 : {
629 20 : const sal_uInt16 nDistance = pTop->GetDistance();
630 20 : const sal_uInt16 nInWidth = pTop->GetInWidth();
631 20 : const sal_uInt16 nOutWidth = pTop->GetOutWidth();
632 20 : const long nWidth = pTop->GetWidth();
633 :
634 40 : bEqual = nDistance == pLeft->GetDistance() &&
635 40 : nInWidth == pLeft->GetInWidth() &&
636 40 : nOutWidth == pLeft->GetOutWidth() &&
637 40 : nWidth == pLeft->GetWidth() &&
638 40 : nDistance == pRight->GetDistance() &&
639 40 : nInWidth == pRight->GetInWidth() &&
640 40 : nOutWidth == pRight->GetOutWidth() &&
641 40 : nWidth == pRight->GetWidth() &&
642 40 : nDistance == pBottom->GetDistance() &&
643 40 : nInWidth == pBottom->GetInWidth() &&
644 60 : nOutWidth == pBottom->GetOutWidth() &&
645 40 : nWidth == pBottom->GetWidth();
646 : }
647 :
648 80 : switch( nMemberId )
649 : {
650 : case ALL_BORDER_LINE_WIDTH:
651 16 : if( !bEqual || pTop->GetDistance() == 0 ||
652 0 : !lcl_isOdfDoubleLine( pTop ) )
653 16 : return false;
654 0 : break;
655 : case LEFT_BORDER_LINE_WIDTH:
656 40 : if( bEqual || NULL == pLeft ||
657 28 : 0 == pLeft->GetDistance() ||
658 0 : !lcl_isOdfDoubleLine( pLeft ) )
659 16 : return false;
660 0 : break;
661 : case RIGHT_BORDER_LINE_WIDTH:
662 32 : if( bEqual || NULL == pRight ||
663 20 : 0 == pRight->GetDistance() ||
664 0 : !lcl_isOdfDoubleLine( pRight ) )
665 16 : return false;
666 0 : break;
667 : case TOP_BORDER_LINE_WIDTH:
668 32 : if( bEqual || NULL == pTop ||
669 20 : 0 == pTop->GetDistance() ||
670 0 : !lcl_isOdfDoubleLine( pTop ) )
671 16 : return false;
672 0 : break;
673 : case BOTTOM_BORDER_LINE_WIDTH:
674 40 : if( bEqual || NULL == pBottom ||
675 28 : 0 == pBottom->GetDistance() ||
676 0 : !lcl_isOdfDoubleLine( pBottom ) )
677 16 : return false;
678 0 : break;
679 : }
680 : }
681 0 : break;
682 : }
683 :
684 : // now export it export
685 68 : switch( nMemberId )
686 : {
687 : // padding
688 : case ALL_BORDER_PADDING:
689 : case LEFT_BORDER_PADDING:
690 16 : rUnitConverter.convertMeasureToXML( aOut, nLeftDist );
691 16 : break;
692 : case RIGHT_BORDER_PADDING:
693 0 : rUnitConverter.convertMeasureToXML( aOut, nRightDist );
694 0 : break;
695 : case TOP_BORDER_PADDING:
696 0 : rUnitConverter.convertMeasureToXML( aOut, nTopDist );
697 0 : break;
698 : case BOTTOM_BORDER_PADDING:
699 0 : rUnitConverter.convertMeasureToXML( aOut, nBottomDist );
700 0 : break;
701 :
702 : // border
703 : case ALL_BORDER:
704 : case LEFT_BORDER:
705 : case RIGHT_BORDER:
706 : case TOP_BORDER:
707 : case BOTTOM_BORDER:
708 : {
709 : const SvxBorderLine* pLine;
710 52 : switch( nMemberId )
711 : {
712 : case ALL_BORDER:
713 : case LEFT_BORDER:
714 16 : pLine = pLeft;
715 16 : break;
716 : case RIGHT_BORDER:
717 12 : pLine = pRight;
718 12 : break;
719 : case TOP_BORDER:
720 12 : pLine = pTop;
721 12 : break;
722 : case BOTTOM_BORDER:
723 12 : pLine = pBottom;
724 12 : break;
725 : default:
726 0 : pLine = NULL;
727 0 : break;
728 : }
729 :
730 52 : if( NULL != pLine )
731 : {
732 36 : sal_Int32 nWidth = pLine->GetWidth();
733 :
734 36 : enum XMLTokenEnum eStyle = XML_SOLID;
735 36 : bool bNoBorder = false;
736 36 : switch (pLine->GetBorderLineStyle())
737 : {
738 : case table::BorderLineStyle::SOLID:
739 36 : eStyle = XML_SOLID;
740 36 : break;
741 : case table::BorderLineStyle::DOTTED:
742 0 : eStyle = XML_DOTTED;
743 0 : break;
744 : case table::BorderLineStyle::DASHED:
745 0 : eStyle = XML_DASHED;
746 0 : break;
747 : case table::BorderLineStyle::DOUBLE:
748 : case table::BorderLineStyle::THINTHICK_SMALLGAP:
749 : case table::BorderLineStyle::THINTHICK_MEDIUMGAP:
750 : case table::BorderLineStyle::THINTHICK_LARGEGAP:
751 : case table::BorderLineStyle::THICKTHIN_SMALLGAP:
752 : case table::BorderLineStyle::THICKTHIN_MEDIUMGAP:
753 : case table::BorderLineStyle::THICKTHIN_LARGEGAP:
754 0 : eStyle = XML_DOUBLE;
755 0 : break;
756 : case table::BorderLineStyle::EMBOSSED:
757 0 : eStyle = XML_RIDGE;
758 0 : break;
759 : case table::BorderLineStyle::ENGRAVED:
760 0 : eStyle = XML_GROOVE;
761 0 : break;
762 : case table::BorderLineStyle::INSET:
763 0 : eStyle = XML_INSET;
764 0 : break;
765 : case table::BorderLineStyle::OUTSET:
766 0 : eStyle = XML_OUTSET;
767 0 : break;
768 : default:
769 0 : bNoBorder = true;
770 : }
771 :
772 36 : if ( !bNoBorder )
773 : {
774 : ::sax::Converter::convertMeasure(aOut, nWidth,
775 : util::MeasureUnit::TWIP,
776 36 : util::MeasureUnit::POINT);
777 36 : aOut.append( ' ' );
778 36 : aOut.append( GetXMLToken( eStyle ) );
779 36 : aOut.append( ' ' );
780 : ::sax::Converter::convertColor(aOut,
781 36 : pLine->GetColor().GetColor());
782 : }
783 : }
784 : else
785 : {
786 16 : aOut.append( GetXMLToken(XML_NONE) );
787 : }
788 : }
789 52 : break;
790 :
791 : // width
792 : case ALL_BORDER_LINE_WIDTH:
793 : case LEFT_BORDER_LINE_WIDTH:
794 : case RIGHT_BORDER_LINE_WIDTH:
795 : case TOP_BORDER_LINE_WIDTH:
796 : case BOTTOM_BORDER_LINE_WIDTH:
797 : const SvxBorderLine* pLine;
798 0 : switch( nMemberId )
799 : {
800 : case ALL_BORDER_LINE_WIDTH:
801 : case LEFT_BORDER_LINE_WIDTH:
802 0 : pLine = pLeft;
803 0 : break;
804 : case RIGHT_BORDER_LINE_WIDTH:
805 0 : pLine = pRight;
806 0 : break;
807 : case TOP_BORDER_LINE_WIDTH:
808 0 : pLine = pTop;
809 0 : break;
810 : case BOTTOM_BORDER_LINE_WIDTH:
811 0 : pLine = pBottom;
812 0 : break;
813 : default:
814 0 : return false;
815 : }
816 0 : rUnitConverter.convertMeasureToXML( aOut, pLine->GetInWidth() );
817 0 : aOut.append( ' ' );
818 0 : rUnitConverter.convertMeasureToXML( aOut, pLine->GetDistance() );
819 0 : aOut.append( ' ' );
820 0 : rUnitConverter.convertMeasureToXML( aOut, pLine->GetOutWidth() );
821 0 : break;
822 : }
823 68 : bOk = true;
824 : }
825 : }
826 68 : break;
827 :
828 : case RES_BREAK:
829 : {
830 0 : const SvxFmtBreakItem* pFmtBreak = PTR_CAST(SvxFmtBreakItem, &rItem);
831 : OSL_ENSURE( pFmtBreak != NULL, "Wrong Which-ID" );
832 :
833 0 : unsigned int eEnum = 0;
834 :
835 0 : switch( nMemberId )
836 : {
837 : case MID_BREAK_BEFORE:
838 0 : switch( pFmtBreak->GetValue() )
839 : {
840 : case SVX_BREAK_COLUMN_BEFORE:
841 0 : eEnum = 1;
842 0 : break;
843 : case SVX_BREAK_PAGE_BEFORE:
844 0 : eEnum = 2;
845 0 : break;
846 : case SVX_BREAK_NONE:
847 0 : eEnum = 0;
848 0 : break;
849 : default:
850 0 : return false;
851 : }
852 0 : break;
853 : case MID_BREAK_AFTER:
854 0 : switch( pFmtBreak->GetValue() )
855 : {
856 : case SVX_BREAK_COLUMN_AFTER:
857 0 : eEnum = 1;
858 0 : break;
859 : case SVX_BREAK_PAGE_AFTER:
860 0 : eEnum = 2;
861 0 : break;
862 : case SVX_BREAK_NONE:
863 0 : eEnum = 0;
864 0 : break;
865 : default:
866 0 : return false;
867 : }
868 0 : break;
869 : }
870 :
871 0 : bOk = SvXMLUnitConverter::convertEnum( aOut, eEnum, psXML_BreakType );
872 : }
873 0 : break;
874 :
875 : case RES_KEEP:
876 : {
877 0 : const SvxFmtKeepItem* pFmtKeep = PTR_CAST(SvxFmtKeepItem, &rItem);
878 : assert(pFmtKeep && "Wrong Which-ID");
879 0 : if (pFmtKeep)
880 : {
881 0 : aOut.append( pFmtKeep->GetValue()
882 : ? GetXMLToken( XML_ALWAYS )
883 0 : : GetXMLToken( XML_AUTO ) );
884 0 : bOk = true;
885 : }
886 : }
887 0 : break;
888 :
889 : case RES_BACKGROUND:
890 : {
891 0 : const SvxBrushItem* pBrush = PTR_CAST(SvxBrushItem, &rItem);
892 : OSL_ENSURE( pBrush != NULL, "Wrong Which-ID" );
893 :
894 : // note: the graphic is only exported if nMemberId equals
895 : // MID_GRAPHIC..
896 : // If not, only the color or transparency is exported
897 :
898 0 : switch( nMemberId )
899 : {
900 : case MID_BACK_COLOR:
901 0 : if ( pBrush->GetColor().GetTransparency() )
902 0 : aOut.append( GetXMLToken(XML_TRANSPARENT) );
903 : else
904 : {
905 : ::sax::Converter::convertColor(aOut,
906 0 : pBrush->GetColor().GetColor());
907 : }
908 0 : bOk = true;
909 0 : break;
910 :
911 : case MID_GRAPHIC_LINK:
912 0 : if( pBrush->GetGraphicPos() != GPOS_NONE )
913 : {
914 0 : uno::Any aAny;
915 0 : pBrush->QueryValue( aAny, MID_GRAPHIC_URL );
916 0 : OUString sTmp;
917 0 : aAny >>= sTmp;
918 0 : aOut.append( sTmp );
919 0 : bOk = true;
920 : }
921 0 : break;
922 :
923 : case MID_GRAPHIC_POSITION:
924 0 : switch( pBrush->GetGraphicPos() )
925 : {
926 : case GPOS_LT:
927 : case GPOS_MT:
928 : case GPOS_RT:
929 0 : aOut.append( GetXMLToken(XML_TOP) );
930 0 : bOk = true;
931 0 : break;
932 : case GPOS_LM:
933 : case GPOS_MM:
934 : case GPOS_RM:
935 0 : aOut.append( GetXMLToken(XML_CENTER) );
936 0 : bOk = true;
937 0 : break;
938 : case GPOS_LB:
939 : case GPOS_MB:
940 : case GPOS_RB:
941 0 : aOut.append( GetXMLToken(XML_BOTTOM) );
942 0 : bOk = true;
943 0 : break;
944 : default:
945 : ;
946 : }
947 :
948 0 : if( bOk )
949 : {
950 0 : aOut.append( ' ' );
951 :
952 0 : switch( pBrush->GetGraphicPos() )
953 : {
954 : case GPOS_LT:
955 : case GPOS_LB:
956 : case GPOS_LM:
957 0 : aOut.append( GetXMLToken(XML_LEFT) );
958 0 : break;
959 : case GPOS_MT:
960 : case GPOS_MM:
961 : case GPOS_MB:
962 0 : aOut.append( GetXMLToken(XML_CENTER) );
963 0 : break;
964 : case GPOS_RM:
965 : case GPOS_RT:
966 : case GPOS_RB:
967 0 : aOut.append( GetXMLToken(XML_RIGHT) );
968 0 : break;
969 : default:
970 : ;
971 : }
972 : }
973 0 : break;
974 :
975 : case MID_GRAPHIC_REPEAT:
976 : {
977 0 : SvxGraphicPosition eGraphicPos = pBrush->GetGraphicPos();
978 0 : if( GPOS_AREA == eGraphicPos )
979 : {
980 0 : aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
981 0 : bOk = true;
982 : }
983 0 : else if( GPOS_NONE != eGraphicPos && GPOS_TILED != eGraphicPos )
984 : {
985 0 : aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
986 0 : bOk = true;
987 : }
988 : }
989 0 : break;
990 :
991 : case MID_GRAPHIC_FILTER:
992 0 : if( pBrush->GetGraphicPos() != GPOS_NONE &&
993 0 : !pBrush->GetGraphicFilter().isEmpty() )
994 : {
995 0 : aOut.append( pBrush->GetGraphicFilter() );
996 0 : bOk = true;
997 : }
998 0 : break;
999 : }
1000 : }
1001 0 : break;
1002 :
1003 : case RES_PAGEDESC:
1004 : {
1005 0 : const SwFmtPageDesc* pPageDesc = PTR_CAST(SwFmtPageDesc, &rItem);
1006 : OSL_ENSURE( pPageDesc != NULL, "Wrong Which-ID" );
1007 :
1008 0 : if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
1009 : {
1010 0 : ::boost::optional<sal_uInt16> oNumOffset = pPageDesc->GetNumOffset();
1011 0 : if (oNumOffset && oNumOffset.get() > 0)
1012 : {
1013 : // #i114163# positiveInteger only!
1014 0 : sal_Int32 const number(oNumOffset.get());
1015 0 : ::sax::Converter::convertNumber(aOut, number);
1016 : }
1017 : else
1018 : {
1019 0 : aOut.append(GetXMLToken(XML_AUTO));
1020 : }
1021 0 : bOk = true;
1022 : }
1023 : }
1024 0 : break;
1025 :
1026 : case RES_LAYOUT_SPLIT:
1027 : case RES_ROW_SPLIT:
1028 : {
1029 0 : const SfxBoolItem* pSplit = PTR_CAST(SfxBoolItem, &rItem);
1030 : assert(pSplit && "Wrong Which-ID");
1031 0 : if (pSplit)
1032 : {
1033 0 : ::sax::Converter::convertBool( aOut, pSplit->GetValue() );
1034 0 : bOk = true;
1035 : }
1036 : }
1037 0 : break;
1038 :
1039 : case RES_HORI_ORIENT:
1040 : {
1041 4 : const SwFmtHoriOrient* pHoriOrient = PTR_CAST(SwFmtHoriOrient, &rItem);
1042 : assert(pHoriOrient && "Wrong Which-ID");
1043 4 : if (pHoriOrient)
1044 : {
1045 4 : SvXMLUnitConverter::convertEnum( aOut, pHoriOrient->GetHoriOrient(),
1046 4 : aXMLTableAlignMap );
1047 4 : bOk = true;
1048 : }
1049 : }
1050 4 : break;
1051 :
1052 : case RES_VERT_ORIENT:
1053 : {
1054 0 : const SwFmtVertOrient* pVertOrient = PTR_CAST(SwFmtVertOrient, &rItem);
1055 : assert(pVertOrient && "Wrong Which-ID");
1056 :
1057 0 : SvXMLUnitConverter::convertEnum( aOut, pVertOrient->GetVertOrient(),
1058 0 : aXMLTableVAlignMap );
1059 0 : bOk = true;
1060 : }
1061 0 : break;
1062 :
1063 : case RES_FRM_SIZE:
1064 : {
1065 4 : const SwFmtFrmSize* pFrmSize = PTR_CAST(SwFmtFrmSize, &rItem);
1066 : OSL_ENSURE( pFrmSize != NULL, "Wrong Which-ID" );
1067 :
1068 4 : bool bOutHeight = false;
1069 4 : switch( nMemberId )
1070 : {
1071 : case MID_FRMSIZE_REL_WIDTH:
1072 4 : if( pFrmSize->GetWidthPercent() )
1073 : {
1074 : ::sax::Converter::convertPercent(
1075 0 : aOut, pFrmSize->GetWidthPercent() );
1076 0 : bOk = true;
1077 : }
1078 4 : break;
1079 : case MID_FRMSIZE_MIN_HEIGHT:
1080 0 : if( ATT_MIN_SIZE == pFrmSize->GetHeightSizeType() )
1081 0 : bOutHeight = true;
1082 0 : break;
1083 : case MID_FRMSIZE_FIX_HEIGHT:
1084 0 : if( ATT_FIX_SIZE == pFrmSize->GetHeightSizeType() )
1085 0 : bOutHeight = true;
1086 0 : break;
1087 : }
1088 :
1089 4 : if( bOutHeight )
1090 : {
1091 0 : rUnitConverter.convertMeasureToXML(aOut, pFrmSize->GetHeight());
1092 0 : bOk = true;
1093 : }
1094 : }
1095 4 : break;
1096 :
1097 : case RES_FRAMEDIR:
1098 : {
1099 0 : Any aAny;
1100 0 : bOk = rItem.QueryValue( aAny );
1101 0 : if( bOk )
1102 : {
1103 : const XMLPropertyHandler* pWritingModeHandler =
1104 : XMLPropertyHandlerFactory::CreatePropertyHandler(
1105 0 : XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT );
1106 0 : OUString sValue;
1107 : bOk = pWritingModeHandler->exportXML( sValue, aAny,
1108 0 : rUnitConverter );
1109 0 : if( bOk )
1110 0 : aOut.append( sValue );
1111 :
1112 0 : delete pWritingModeHandler;
1113 0 : }
1114 : }
1115 0 : break;
1116 :
1117 : case RES_COLLAPSING_BORDERS:
1118 : {
1119 0 : const SfxBoolItem* pBorders = PTR_CAST(SfxBoolItem, &rItem);
1120 : assert(pBorders && "Wrong RES-ID");
1121 0 : if (pBorders)
1122 : {
1123 0 : aOut.append( pBorders->GetValue()
1124 : ? GetXMLToken( XML_COLLAPSING )
1125 0 : : GetXMLToken( XML_SEPARATING ) );
1126 0 : bOk = true;
1127 : }
1128 : }
1129 0 : break;
1130 :
1131 : default:
1132 : OSL_FAIL("GetXMLValue not implemented for this item.");
1133 0 : break;
1134 : }
1135 :
1136 76 : if ( bOk )
1137 72 : rValue = aOut.makeStringAndClear();
1138 :
1139 76 : return bOk;
1140 270 : }
1141 :
1142 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|