update emoji autocorrect entries from po-files
[LibreOffice.git] / writerfilter / source / dmapper / TablePositionHandler.cxx
blob0db1efbbe4aeb375a03a620de68173fa57cd84a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
9 #include <TablePositionHandler.hxx>
10 #include <ConversionHelper.hxx>
11 #include <ooxml/resourceids.hxx>
12 #include <com/sun/star/text/HoriOrientation.hpp>
13 #include <com/sun/star/text/VertOrientation.hpp>
14 #include <com/sun/star/text/RelOrientation.hpp>
15 #include <comphelper/sequenceashashmap.hxx>
17 namespace writerfilter
19 namespace dmapper
22 using namespace ::com::sun::star;
24 TablePositionHandler::TablePositionHandler() :
25 LoggedProperties("TablePositionHandler"),
26 m_aVertAnchor("margin"),
27 m_aYSpec(),
28 m_aHorzAnchor("text"),
29 m_aXSpec(),
30 m_nY(0),
31 m_nX(0),
32 m_nLeftFromText(0),
33 m_nRightFromText(0),
34 m_nTopFromText(0),
35 m_nBottomFromText(0)
39 TablePositionHandler::~TablePositionHandler()
44 void TablePositionHandler::lcl_attribute(Id rName, Value& rVal)
46 switch (rName)
48 case NS_ooxml::LN_CT_TblPPr_vertAnchor:
49 m_aVertAnchor = rVal.getString();
50 break;
51 case NS_ooxml::LN_CT_TblPPr_tblpYSpec:
52 m_aYSpec = rVal.getString();
53 break;
54 case NS_ooxml::LN_CT_TblPPr_horzAnchor:
55 m_aHorzAnchor = rVal.getString();
56 break;
57 case NS_ooxml::LN_CT_TblPPr_tblpXSpec:
58 m_aXSpec = rVal.getString();
59 break;
60 case NS_ooxml::LN_CT_TblPPr_tblpY:
61 m_nY = rVal.getInt();
62 break;
63 case NS_ooxml::LN_CT_TblPPr_tblpX:
64 m_nX = rVal.getInt();
65 break;
66 case NS_ooxml::LN_CT_TblPPr_leftFromText:
67 m_nLeftFromText = rVal.getInt();
68 break;
69 case NS_ooxml::LN_CT_TblPPr_rightFromText:
70 m_nRightFromText = rVal.getInt();
71 break;
72 case NS_ooxml::LN_CT_TblPPr_topFromText:
73 m_nTopFromText = rVal.getInt();
74 break;
75 case NS_ooxml::LN_CT_TblPPr_bottomFromText:
76 m_nBottomFromText = rVal.getInt();
77 break;
78 default:
79 #ifdef DEBUG_WRITERFILTER
80 TagLogger::getInstance().element("unhandled");
81 #endif
82 break;
87 void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/)
92 uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() const
94 comphelper::SequenceAsHashMap aFrameProperties;
96 aFrameProperties["LeftBorderDistance"] <<= sal_Int32(0);
97 aFrameProperties["RightBorderDistance"] <<= sal_Int32(0);
98 aFrameProperties["TopBorderDistance"] <<= sal_Int32(0);
99 aFrameProperties["BottomBorderDistance"] <<= sal_Int32(0);
101 aFrameProperties["LeftMargin"] <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText);
102 aFrameProperties["RightMargin"] <<= ConversionHelper::convertTwipToMM100(m_nRightFromText);
103 aFrameProperties["TopMargin"] <<= ConversionHelper::convertTwipToMM100(m_nTopFromText);
104 aFrameProperties["BottomMargin"] <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText);
106 table::BorderLine2 aEmptyBorder;
107 aFrameProperties["TopBorder"] <<= aEmptyBorder;
108 aFrameProperties["BottomBorder"] <<= aEmptyBorder;
109 aFrameProperties["LeftBorder"] <<= aEmptyBorder;
110 aFrameProperties["RightBorder"] <<= aEmptyBorder;
112 // Horizontal positioning
113 sal_Int16 nHoriOrient = text::HoriOrientation::NONE;
114 if (m_aXSpec == "center")
115 nHoriOrient = text::HoriOrientation::CENTER;
116 else if (m_aXSpec == "inside")
117 nHoriOrient = text::HoriOrientation::INSIDE;
118 else if (m_aXSpec == "left")
119 nHoriOrient = text::HoriOrientation::LEFT;
120 else if (m_aXSpec == "outside")
121 nHoriOrient = text::HoriOrientation::OUTSIDE;
122 else if (m_aXSpec == "right")
123 nHoriOrient = text::HoriOrientation::RIGHT;
125 sal_Int16 nHoriOrientRelation;
126 if (m_aHorzAnchor == "margin")
127 nHoriOrientRelation = text::RelOrientation::PAGE_PRINT_AREA;
128 else if (m_aHorzAnchor == "page")
129 nHoriOrientRelation = text::RelOrientation::PAGE_FRAME;
130 else if (m_aHorzAnchor == "text")
131 nHoriOrientRelation = text::RelOrientation::FRAME;
133 aFrameProperties["HoriOrient"] <<= nHoriOrient;
134 aFrameProperties["HoriOrientRelation"] <<= nHoriOrientRelation;
135 aFrameProperties["HoriOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nX);
137 // Vertical positioning
138 sal_Int16 nVertOrient = text::VertOrientation::NONE;
139 if (m_aYSpec == "bottom")
140 nVertOrient = text::VertOrientation::BOTTOM;
141 else if (m_aYSpec == "center")
142 nVertOrient = text::VertOrientation::CENTER;
143 else if (m_aYSpec == "top")
144 nVertOrient = text::VertOrientation::TOP;
145 // TODO There are a few cases we can't map ATM.
148 sal_Int16 nVertOrientRelation;
149 if (m_aVertAnchor == "margin")
150 nVertOrientRelation = text::RelOrientation::PAGE_PRINT_AREA;
151 else if (m_aVertAnchor == "page")
152 nVertOrientRelation = text::RelOrientation::PAGE_FRAME;
153 else if (m_aVertAnchor == "text")
154 nVertOrientRelation = text::RelOrientation::FRAME;
156 aFrameProperties["VertOrient"] <<= nVertOrient;
157 aFrameProperties["VertOrientRelation"] <<= nVertOrientRelation;
158 aFrameProperties["VertOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nY);
159 aFrameProperties["FillTransparence"] <<= sal_Int32(100);
161 return aFrameProperties.getAsConstPropertyValueList();
164 bool TablePositionHandler::operator== (const TablePositionHandler& rHandler) const
166 return m_aVertAnchor == rHandler.m_aVertAnchor &&
167 m_aYSpec == rHandler.m_aYSpec &&
168 m_aHorzAnchor == rHandler.m_aHorzAnchor &&
169 m_aXSpec == rHandler.m_aXSpec &&
170 m_nY == rHandler.m_nY &&
171 m_nX == rHandler.m_nX;
174 } // namespace dmapper
175 } // namespace writerfilter
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */