xref: /trunk/main/xmloff/source/style/XMLFootnoteSeparatorExport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLFootnoteSeparatorExport.hxx"
31 #include <tools/debug.hxx>
32 #include <xmloff/xmlexp.hxx>
33 #include "xmloff/xmlnmspe.hxx"
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlprmap.hxx>
37 
38 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
39 #include <xmloff/PageMasterStyleMap.hxx>
40 #endif
41 #include <com/sun/star/text/HorizontalAdjust.hpp>
42 #include <rtl/ustrbuf.hxx>
43 
44 
45 using namespace ::com::sun::star;
46 using namespace ::xmloff::token;
47 using ::rtl::OUStringBuffer;
48 using ::std::vector;
49 
50 XMLFootnoteSeparatorExport::XMLFootnoteSeparatorExport(SvXMLExport& rExp) :
51     rExport(rExp)
52 {
53 }
54 
55 XMLFootnoteSeparatorExport::~XMLFootnoteSeparatorExport()
56 {
57 }
58 
59 
60 void XMLFootnoteSeparatorExport::exportXML(
61     const vector<XMLPropertyState> * pProperties,
62     sal_uInt32
63     #ifdef DBG_UTIL
64     nIdx
65     #endif
66     ,
67     const UniReference<XMLPropertySetMapper> & rMapper)
68 {
69     DBG_ASSERT(NULL != pProperties, "Need property states");
70 
71     // intialize values
72     sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT;
73     sal_Int32 nLineColor = 0;
74     sal_Int32 nLineDistance = 0;
75     sal_Int8 nLineRelWidth = 0;
76     sal_Int32 nLineTextDistance = 0;
77     sal_Int16 nLineWeight = 0;
78 
79     // find indices into property map and get values
80     sal_uInt32 nCount = pProperties->size();
81     for(sal_uInt32 i = 0; i < nCount; i++)
82     {
83         const XMLPropertyState& rState = (*pProperties)[i];
84 
85         if( rState.mnIndex == -1 )
86             continue;
87 
88         switch (rMapper->GetEntryContextId(rState.mnIndex))
89         {
90         case CTF_PM_FTN_LINE_ADJUST:
91             rState.maValue >>= eLineAdjust;
92             break;
93         case CTF_PM_FTN_LINE_COLOR:
94             rState.maValue >>= nLineColor;
95             break;
96         case CTF_PM_FTN_DISTANCE:
97             rState.maValue >>= nLineDistance;
98             break;
99         case CTF_PM_FTN_LINE_WIDTH:
100             rState.maValue >>= nLineRelWidth;
101             break;
102         case CTF_PM_FTN_LINE_DISTANCE:
103             rState.maValue >>= nLineTextDistance;
104             break;
105         case CTF_PM_FTN_LINE_WEIGTH:
106             DBG_ASSERT( i == nIdx,
107                         "received wrong property state index" );
108             rState.maValue >>= nLineWeight;
109             break;
110         }
111     }
112 
113     OUStringBuffer sBuf;
114 
115     // weight/width
116     if (nLineWeight > 0)
117     {
118         rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLineWeight);
119         rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_WIDTH,
120                              sBuf.makeStringAndClear());
121     }
122 
123     // line text distance
124     if (nLineTextDistance > 0)
125     {
126         rExport.GetMM100UnitConverter().convertMeasure(sBuf,nLineTextDistance);
127         rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_DISTANCE_BEFORE_SEP,
128                              sBuf.makeStringAndClear());
129     }
130 
131     // line distance
132     if (nLineDistance > 0)
133     {
134         rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLineDistance);
135         rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_DISTANCE_AFTER_SEP,
136                              sBuf.makeStringAndClear());
137     }
138 
139     // adjustment
140     static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] =
141     {
142         { XML_LEFT,     text::HorizontalAdjust_LEFT },
143         { XML_CENTER,   text::HorizontalAdjust_CENTER },
144         { XML_RIGHT,    text::HorizontalAdjust_RIGHT },
145         { XML_TOKEN_INVALID, 0 }
146     };
147 
148     if (rExport.GetMM100UnitConverter().convertEnum(
149         sBuf, eLineAdjust, aXML_HorizontalAdjust_Enum))
150     {
151         rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_ADJUSTMENT,
152                              sBuf.makeStringAndClear());
153     }
154 
155     // relative line width
156     SvXMLUnitConverter::convertPercent(sBuf, nLineRelWidth);
157     rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_REL_WIDTH,
158                          sBuf.makeStringAndClear());
159 
160     // color
161     rExport.GetMM100UnitConverter().convertColor(sBuf, nLineColor);
162     rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_COLOR,
163                          sBuf.makeStringAndClear());
164 
165     SvXMLElementExport aElem(rExport, XML_NAMESPACE_STYLE,
166                              XML_FOOTNOTE_SEP, sal_True, sal_True);
167 }
168