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 : #include <TablePositionHandler.hxx>
10 : #include <DomainMapperTableHandler.hxx>
11 : #include <PropertyMap.hxx>
12 : #include <ConversionHelper.hxx>
13 : #include <ooxml/resourceids.hxx>
14 : #include <com/sun/star/text/HoriOrientation.hpp>
15 : #include <com/sun/star/text/VertOrientation.hpp>
16 : #include <com/sun/star/text/RelOrientation.hpp>
17 : #include "dmapperLoggers.hxx"
18 :
19 : namespace writerfilter
20 : {
21 : namespace dmapper
22 : {
23 :
24 : using namespace ::com::sun::star;
25 :
26 244 : TablePositionHandler::TablePositionHandler() :
27 : LoggedProperties(dmapper_logger, "TablePositionHandler"),
28 : m_aVertAnchor("margin"),
29 : m_aYSpec(),
30 : m_aHorzAnchor("text"),
31 : m_aXSpec(),
32 : m_nY(0),
33 : m_nX(0),
34 : m_nLeftFromText(0),
35 : m_nRightFromText(0),
36 : m_nTopFromText(0),
37 244 : m_nBottomFromText(0)
38 : {
39 244 : }
40 :
41 488 : TablePositionHandler::~TablePositionHandler()
42 : {
43 488 : }
44 :
45 :
46 1084 : void TablePositionHandler::lcl_attribute(Id rName, Value& rVal)
47 : {
48 1084 : switch (rName)
49 : {
50 : case NS_ooxml::LN_CT_TblPPr_vertAnchor:
51 105 : m_aVertAnchor = rVal.getString();
52 105 : break;
53 : case NS_ooxml::LN_CT_TblPPr_tblpYSpec:
54 8 : m_aYSpec = rVal.getString();
55 8 : break;
56 : case NS_ooxml::LN_CT_TblPPr_horzAnchor:
57 196 : m_aHorzAnchor = rVal.getString();
58 196 : break;
59 : case NS_ooxml::LN_CT_TblPPr_tblpXSpec:
60 20 : m_aXSpec = rVal.getString();
61 20 : break;
62 : case NS_ooxml::LN_CT_TblPPr_tblpY:
63 236 : m_nY = rVal.getInt();
64 236 : break;
65 : case NS_ooxml::LN_CT_TblPPr_tblpX:
66 25 : m_nX = rVal.getInt();
67 25 : break;
68 : case NS_ooxml::LN_CT_TblPPr_leftFromText:
69 241 : m_nLeftFromText = rVal.getInt();
70 241 : break;
71 : case NS_ooxml::LN_CT_TblPPr_rightFromText:
72 241 : m_nRightFromText = rVal.getInt();
73 241 : break;
74 : case NS_ooxml::LN_CT_TblPPr_topFromText:
75 6 : m_nTopFromText = rVal.getInt();
76 6 : break;
77 : case NS_ooxml::LN_CT_TblPPr_bottomFromText:
78 6 : m_nBottomFromText = rVal.getInt();
79 6 : break;
80 : default:
81 : #ifdef DEBUG_DOMAINMAPPER
82 : dmapper_logger->element("unhandled");
83 : #endif
84 0 : break;
85 : }
86 1084 : }
87 :
88 :
89 0 : void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/)
90 : {
91 0 : }
92 :
93 :
94 31 : uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() const
95 : {
96 31 : uno::Sequence< beans::PropertyValue > aFrameProperties(18);
97 31 : beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
98 :
99 31 : pFrameProperties[0].Name = "LeftBorderDistance";
100 31 : pFrameProperties[0].Value <<= sal_Int32(0);
101 31 : pFrameProperties[1].Name = "RightBorderDistance";
102 31 : pFrameProperties[1].Value <<= sal_Int32(0);
103 31 : pFrameProperties[2].Name = "TopBorderDistance";
104 31 : pFrameProperties[2].Value <<= sal_Int32(0);
105 31 : pFrameProperties[3].Name = "BottomBorderDistance";
106 31 : pFrameProperties[3].Value <<= sal_Int32(0);
107 :
108 31 : pFrameProperties[4].Name = "LeftMargin";
109 31 : pFrameProperties[4].Value <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText);
110 31 : pFrameProperties[5].Name = "RightMargin";
111 31 : pFrameProperties[5].Value <<= ConversionHelper::convertTwipToMM100(m_nRightFromText);
112 31 : pFrameProperties[6].Name = "TopMargin";
113 31 : pFrameProperties[6].Value <<= ConversionHelper::convertTwipToMM100(m_nTopFromText);
114 31 : pFrameProperties[7].Name = "BottomMargin";
115 31 : pFrameProperties[7].Value <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText);
116 :
117 31 : table::BorderLine2 aEmptyBorder;
118 31 : pFrameProperties[8].Name = "TopBorder";
119 31 : pFrameProperties[8].Value <<= aEmptyBorder;
120 31 : pFrameProperties[9].Name = "BottomBorder";
121 31 : pFrameProperties[9].Value <<= aEmptyBorder;
122 31 : pFrameProperties[10].Name = "LeftBorder";
123 31 : pFrameProperties[10].Value <<= aEmptyBorder;
124 31 : pFrameProperties[11].Name = "RightBorder";
125 31 : pFrameProperties[11].Value <<= aEmptyBorder;
126 :
127 : // Horizontal positioning
128 31 : sal_Int16 nHoriOrient = text::HoriOrientation::NONE;
129 31 : if (m_aXSpec == "center")
130 4 : nHoriOrient = text::HoriOrientation::CENTER;
131 27 : else if (m_aXSpec == "inside")
132 0 : nHoriOrient = text::HoriOrientation::INSIDE;
133 27 : else if (m_aXSpec == "left")
134 0 : nHoriOrient = text::HoriOrientation::LEFT;
135 27 : else if (m_aXSpec == "outside")
136 0 : nHoriOrient = text::HoriOrientation::OUTSIDE;
137 27 : else if (m_aXSpec == "right")
138 6 : nHoriOrient = text::HoriOrientation::RIGHT;
139 :
140 : sal_Int16 nHoriOrientRelation;
141 31 : if (m_aHorzAnchor == "margin")
142 13 : nHoriOrientRelation = text::RelOrientation::PAGE_PRINT_AREA;
143 18 : else if (m_aHorzAnchor == "page")
144 3 : nHoriOrientRelation = text::RelOrientation::PAGE_FRAME;
145 15 : else if (m_aHorzAnchor == "text")
146 15 : nHoriOrientRelation = text::RelOrientation::FRAME;
147 :
148 31 : pFrameProperties[12].Name = "HoriOrient";
149 31 : pFrameProperties[12].Value <<= nHoriOrient;
150 31 : pFrameProperties[13].Name = "HoriOrientRelation";
151 31 : pFrameProperties[13].Value <<= nHoriOrientRelation;
152 31 : pFrameProperties[14].Name = "HoriOrientPosition";
153 31 : pFrameProperties[14].Value <<= ConversionHelper::convertTwipToMM100(m_nX);
154 :
155 :
156 : // Vertical positioning
157 31 : sal_Int16 nVertOrient = text::VertOrientation::NONE;
158 31 : if (m_aYSpec == "bottom")
159 1 : nVertOrient = text::VertOrientation::BOTTOM;
160 30 : else if (m_aYSpec == "center")
161 6 : nVertOrient = text::VertOrientation::CENTER;
162 24 : else if (m_aYSpec == "top")
163 0 : nVertOrient = text::VertOrientation::TOP;
164 : // TODO There are a few cases we can't map ATM.
165 :
166 :
167 : sal_Int16 nVertOrientRelation;
168 31 : if (m_aVertAnchor == "margin")
169 2 : nVertOrientRelation = text::RelOrientation::PAGE_PRINT_AREA;
170 29 : else if (m_aVertAnchor == "page")
171 2 : nVertOrientRelation = text::RelOrientation::PAGE_FRAME;
172 27 : else if (m_aVertAnchor == "text")
173 27 : nVertOrientRelation = text::RelOrientation::FRAME;
174 :
175 31 : pFrameProperties[15].Name = "VertOrient";
176 31 : pFrameProperties[15].Value <<= nVertOrient;
177 31 : pFrameProperties[16].Name = "VertOrientRelation";
178 31 : pFrameProperties[16].Value <<= nVertOrientRelation;
179 31 : pFrameProperties[17].Name = "VertOrientPosition";
180 31 : pFrameProperties[17].Value <<= ConversionHelper::convertTwipToMM100(m_nY);
181 :
182 31 : return aFrameProperties;
183 : }
184 :
185 214 : bool TablePositionHandler::operator== (const TablePositionHandler& rHandler) const
186 : {
187 428 : return m_aVertAnchor == rHandler.m_aVertAnchor &&
188 428 : m_aYSpec == rHandler.m_aYSpec &&
189 428 : m_aHorzAnchor == rHandler.m_aHorzAnchor &&
190 428 : m_aXSpec == rHandler.m_aXSpec &&
191 641 : m_nY == rHandler.m_nY &&
192 427 : m_nX == rHandler.m_nX;
193 : }
194 :
195 : } // namespace dmapper
196 : } // namespace writerfilter
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|