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