1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmlithlp.hxx"
21 #include "hintids.hxx"
23 #include <sax/tools/converter.hxx>
24 #include <svx/unomid.hxx>
25 #include <editeng/lrspitem.hxx>
26 #include <editeng/ulspitem.hxx>
27 #include <editeng/shaditem.hxx>
28 #include <editeng/boxitem.hxx>
29 #include <editeng/formatbreakitem.hxx>
30 #include <editeng/keepitem.hxx>
31 #include <editeng/brushitem.hxx>
32 #include "fmtpdsc.hxx"
33 #include "fmtornt.hxx"
34 #include "fmtfsize.hxx"
36 #include "fmtlsplt.hxx"
37 #include <xmloff/xmluconv.hxx>
39 using ::editeng::SvxBorderLine
;
40 using namespace ::xmloff::token
;
41 using namespace ::com::sun::star
;
44 #define API_LINE_NONE 0x7FFF
45 #define API_LINE_SOLID 0
46 #define API_LINE_DOTTED 1
47 #define API_LINE_DASHED 2
48 #define API_LINE_DOUBLE 3
49 #define API_LINE_EMBOSSED 10
50 #define API_LINE_ENGRAVED 11
51 #define API_LINE_OUTSET 12
52 #define API_LINE_INSET 13
54 #define SVX_XML_BORDER_WIDTH_THIN 0
55 #define SVX_XML_BORDER_WIDTH_MIDDLE 1
56 #define SVX_XML_BORDER_WIDTH_THICK 2
59 const struct SvXMLEnumMapEntry psXML_BorderStyles
[] =
61 { XML_NONE
, API_LINE_NONE
},
62 { XML_HIDDEN
, API_LINE_NONE
},
63 { XML_SOLID
, API_LINE_SOLID
},
64 { XML_DOUBLE
, API_LINE_DOUBLE
},
65 { XML_DOTTED
, API_LINE_DOTTED
},
66 { XML_DASHED
, API_LINE_DASHED
},
67 { XML_GROOVE
, API_LINE_ENGRAVED
},
68 { XML_RIDGE
, API_LINE_EMBOSSED
},
69 { XML_INSET
, API_LINE_INSET
},
70 { XML_OUTSET
, API_LINE_OUTSET
},
71 { XML_TOKEN_INVALID
, 0 }
74 const struct SvXMLEnumMapEntry psXML_NamedBorderWidths
[] =
76 { XML_THIN
, SVX_XML_BORDER_WIDTH_THIN
},
77 { XML_MIDDLE
, SVX_XML_BORDER_WIDTH_MIDDLE
},
78 { XML_THICK
, SVX_XML_BORDER_WIDTH_THICK
},
79 { XML_TOKEN_INVALID
, 0 }
81 // mapping tables to map external xml input to intarnal box line widths
84 const sal_uInt16 aBorderWidths
[] =
91 bool sw_frmitems_parseXMLBorder( const OUString
& rValue
,
92 const SvXMLUnitConverter
& rUnitConverter
,
93 bool& rHasStyle
, sal_uInt16
& rStyle
,
94 bool& rHasWidth
, sal_uInt16
& rWidth
,
95 sal_uInt16
& rNamedWidth
,
96 bool& rHasColor
, Color
& rColor
)
99 SvXMLTokenEnumerator
aTokens( rValue
);
107 rNamedWidth
= USHRT_MAX
;
110 while( aTokens
.getNextToken( aToken
) && !aToken
.isEmpty() )
113 rUnitConverter
.convertEnum( rNamedWidth
, aToken
,
114 psXML_NamedBorderWidths
) )
118 else if( !rHasStyle
&&
119 rUnitConverter
.convertEnum( rStyle
, aToken
,
120 psXML_BorderStyles
) )
124 else if (!rHasColor
&& ::sax::Converter::convertColor(nTemp
, aToken
))
126 rColor
.SetColor(nTemp
);
129 else if( !rHasWidth
&&
130 rUnitConverter
.convertMeasureToCore(nTemp
, aToken
, 0, USHRT_MAX
))
132 rWidth
= (sal_uInt16
)nTemp
;
142 return rHasStyle
|| rHasWidth
|| rHasColor
;
145 void sw_frmitems_setXMLBorderStyle( SvxBorderLine
& rLine
, sal_uInt16 nStyle
)
147 ::editeng::SvxBorderStyle eStyle
= table::BorderLineStyle::NONE
;
148 if ( nStyle
!= API_LINE_NONE
)
149 eStyle
= ::editeng::SvxBorderStyle( nStyle
);
150 rLine
.SetBorderLineStyle(eStyle
);
153 bool sw_frmitems_setXMLBorder( SvxBorderLine
*& rpLine
,
154 bool bHasStyle
, sal_uInt16 nStyle
,
155 bool bHasWidth
, sal_uInt16 nWidth
,
156 sal_uInt16 nNamedWidth
,
157 bool bHasColor
, const Color
& rColor
)
159 // first of all, delete an empty line
160 if( (bHasStyle
&& API_LINE_NONE
== nStyle
) ||
161 (bHasWidth
&& USHRT_MAX
== nNamedWidth
&& 0 == nWidth
) )
163 bool bRet
= 0 != rpLine
;
173 // if there is no line and no style and no with, there will never be a line
174 if( !rpLine
&& !(bHasStyle
&& bHasWidth
) )
177 // We now do know that there will be a line
179 rpLine
= new SvxBorderLine
;
183 (USHRT_MAX
!= nNamedWidth
|| (nWidth
!= rpLine
->GetWidth() ) ) ) ||
185 ((API_LINE_SOLID
== nStyle
&& rpLine
->GetDistance()) ||
186 (API_LINE_DOUBLE
== nStyle
&& !rpLine
->GetDistance())) ) )
188 bool bDouble
= (bHasWidth
&& API_LINE_DOUBLE
== nStyle
) ||
189 rpLine
->GetDistance();
191 // fdo#38542: for double borders, do not override the width
192 // set via style:border-line-width{,-left,-right,-top,-bottom}
193 if (!bDouble
|| !rpLine
->GetWidth())
195 // The width has to be changed
196 if (bHasWidth
&& USHRT_MAX
!= nNamedWidth
)
200 rpLine
->SetBorderLineStyle( table::BorderLineStyle::DOUBLE
);
202 rpLine
->SetWidth( aBorderWidths
[nNamedWidth
] );
207 nWidth
= rpLine
->GetInWidth() + rpLine
->GetDistance() +
208 rpLine
->GetOutWidth();
210 rpLine
->SetWidth( nWidth
);
213 sw_frmitems_setXMLBorderStyle( *rpLine
, nStyle
);
218 rpLine
->SetColor( rColor
);
223 void sw_frmitems_setXMLBorder( SvxBorderLine
*& rpLine
,
224 sal_uInt16 nWidth
, sal_uInt16 nOutWidth
,
225 sal_uInt16 nInWidth
, sal_uInt16 nDistance
)
228 rpLine
= new SvxBorderLine
;
231 rpLine
->SetWidth( nWidth
);
233 rpLine
->GuessLinesWidths(table::BorderLineStyle::DOUBLE
,
234 nOutWidth
, nInWidth
, nDistance
);
237 const struct SvXMLEnumMapEntry psXML_BrushRepeat
[] =
239 { XML_BACKGROUND_REPEAT
, GPOS_TILED
},
240 { XML_BACKGROUND_NO_REPEAT
, GPOS_MM
},
241 { XML_BACKGROUND_STRETCH
, GPOS_AREA
},
242 { XML_TOKEN_INVALID
, 0 }
245 const struct SvXMLEnumMapEntry psXML_BrushHoriPos
[] =
247 { XML_LEFT
, GPOS_LM
},
248 { XML_RIGHT
, GPOS_RM
},
249 { XML_TOKEN_INVALID
, 0 }
252 const struct SvXMLEnumMapEntry psXML_BrushVertPos
[] =
254 { XML_TOP
, GPOS_MT
},
255 { XML_BOTTOM
, GPOS_MB
},
256 { XML_TOKEN_INVALID
, 0 }
259 void sw_frmitems_MergeXMLHoriPos( SvxGraphicPosition
& ePos
,
260 SvxGraphicPosition eHori
)
262 OSL_ENSURE( GPOS_LM
==eHori
|| GPOS_MM
==eHori
|| GPOS_RM
==eHori
,
263 "sw_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
270 ePos
= GPOS_LM
==eHori
? GPOS_LT
: (GPOS_MM
==eHori
? GPOS_MT
: GPOS_RT
);
282 ePos
= GPOS_LM
==eHori
? GPOS_LB
: (GPOS_MM
==eHori
? GPOS_MB
: GPOS_RB
);
289 void sw_frmitems_MergeXMLVertPos( SvxGraphicPosition
& ePos
,
290 SvxGraphicPosition eVert
)
292 OSL_ENSURE( GPOS_MT
==eVert
|| GPOS_MM
==eVert
|| GPOS_MB
==eVert
,
293 "sw_frmitems_MergeXMLVertPos: horizontal pos must be middle" );
300 ePos
= GPOS_MT
==eVert
? GPOS_LT
: (GPOS_MM
==eVert
? GPOS_LM
: GPOS_LB
);
313 ePos
= GPOS_MT
==eVert
? GPOS_RT
: (GPOS_MM
==eVert
? GPOS_RM
: GPOS_RB
);
321 const struct SvXMLEnumMapEntry psXML_BreakType
[] =
326 { XML_EVEN_PAGE
, 2 },
328 { XML_TOKEN_INVALID
, 0}
331 const struct SvXMLEnumMapEntry aXMLTableAlignMap
[] =
333 { XML_LEFT
, text::HoriOrientation::LEFT
},
334 { XML_LEFT
, text::HoriOrientation::LEFT_AND_WIDTH
},
335 { XML_CENTER
, text::HoriOrientation::CENTER
},
336 { XML_RIGHT
, text::HoriOrientation::RIGHT
},
337 { XML_MARGINS
, text::HoriOrientation::FULL
},
338 { XML_MARGINS
, text::HoriOrientation::NONE
},
339 { XML_TOKEN_INVALID
, 0 }
342 const struct SvXMLEnumMapEntry aXMLTableVAlignMap
[] =
344 { XML_TOP
, text::VertOrientation::TOP
},
345 { XML_MIDDLE
, text::VertOrientation::CENTER
},
346 { XML_BOTTOM
, text::VertOrientation::BOTTOM
},
347 { XML_TOKEN_INVALID
, 0 }
350 const struct SvXMLEnumMapEntry aXML_KeepTogetherType
[] =
354 { XML_TOKEN_INVALID
, 0}
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */