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 #include "TablePositionHandler.hxx"
10 #include "ConversionHelper.hxx"
11 #include <ooxml/resourceids.hxx>
12 #include <com/sun/star/beans/PropertyValue.hpp>
13 #include <com/sun/star/text/HoriOrientation.hpp>
14 #include <com/sun/star/text/VertOrientation.hpp>
15 #include <com/sun/star/text/RelOrientation.hpp>
16 #include <comphelper/sequenceashashmap.hxx>
18 namespace writerfilter
23 using namespace ::com::sun::star
;
25 TablePositionHandler::TablePositionHandler() :
26 LoggedProperties("TablePositionHandler"),
27 m_aVertAnchor("margin"),
32 TablePositionHandler::~TablePositionHandler() = default;
34 void TablePositionHandler::lcl_attribute(Id nId
, Value
& rVal
)
38 case NS_ooxml::LN_CT_TblPPr_vertAnchor
:
39 m_aVertAnchor
= rVal
.getString();
41 case NS_ooxml::LN_CT_TblPPr_tblpYSpec
:
42 m_aYSpec
= rVal
.getString();
44 case NS_ooxml::LN_CT_TblPPr_horzAnchor
:
45 m_aHorzAnchor
= rVal
.getString();
47 case NS_ooxml::LN_CT_TblPPr_tblpXSpec
:
48 m_aXSpec
= rVal
.getString();
50 case NS_ooxml::LN_CT_TblPPr_tblpY
:
53 case NS_ooxml::LN_CT_TblPPr_tblpX
:
56 case NS_ooxml::LN_CT_TblPPr_leftFromText
:
57 m_nLeftFromText
= rVal
.getInt();
59 case NS_ooxml::LN_CT_TblPPr_rightFromText
:
60 m_nRightFromText
= rVal
.getInt();
62 case NS_ooxml::LN_CT_TblPPr_topFromText
:
63 m_nTopFromText
= rVal
.getInt();
65 case NS_ooxml::LN_CT_TblPPr_bottomFromText
:
66 m_nBottomFromText
= rVal
.getInt();
69 #ifdef DEBUG_WRITERFILTER
70 TagLogger::getInstance().element("unhandled");
77 void TablePositionHandler::lcl_sprm(Sprm
& /*rSprm*/)
82 uno::Sequence
<beans::PropertyValue
> TablePositionHandler::getTablePosition() const
84 comphelper::SequenceAsHashMap aFrameProperties
;
86 aFrameProperties
["LeftBorderDistance"] <<= sal_Int32(0);
87 aFrameProperties
["RightBorderDistance"] <<= sal_Int32(0);
88 aFrameProperties
["TopBorderDistance"] <<= sal_Int32(0);
89 aFrameProperties
["BottomBorderDistance"] <<= sal_Int32(0);
91 aFrameProperties
["LeftMargin"] <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText
);
92 aFrameProperties
["RightMargin"] <<= ConversionHelper::convertTwipToMM100(m_nRightFromText
);
93 aFrameProperties
["TopMargin"] <<= ConversionHelper::convertTwipToMM100(m_nTopFromText
);
94 aFrameProperties
["BottomMargin"] <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText
);
96 table::BorderLine2 aEmptyBorder
;
97 aFrameProperties
["TopBorder"] <<= aEmptyBorder
;
98 aFrameProperties
["BottomBorder"] <<= aEmptyBorder
;
99 aFrameProperties
["LeftBorder"] <<= aEmptyBorder
;
100 aFrameProperties
["RightBorder"] <<= aEmptyBorder
;
102 // Horizontal positioning
103 sal_Int16 nHoriOrient
= text::HoriOrientation::NONE
;
104 if (m_aXSpec
== "center")
105 nHoriOrient
= text::HoriOrientation::CENTER
;
106 else if (m_aXSpec
== "inside")
107 nHoriOrient
= text::HoriOrientation::INSIDE
;
108 else if (m_aXSpec
== "left")
109 nHoriOrient
= text::HoriOrientation::LEFT
;
110 else if (m_aXSpec
== "outside")
111 nHoriOrient
= text::HoriOrientation::OUTSIDE
;
112 else if (m_aXSpec
== "right")
113 nHoriOrient
= text::HoriOrientation::RIGHT
;
115 sal_Int16 nHoriOrientRelation
;
116 if (m_aHorzAnchor
== "margin")
117 nHoriOrientRelation
= text::RelOrientation::PAGE_PRINT_AREA
;
118 else if (m_aHorzAnchor
== "page")
119 nHoriOrientRelation
= text::RelOrientation::PAGE_FRAME
;
120 else if (m_aHorzAnchor
== "text")
121 nHoriOrientRelation
= text::RelOrientation::FRAME
;
123 aFrameProperties
["HoriOrient"] <<= nHoriOrient
;
124 aFrameProperties
["HoriOrientRelation"] <<= nHoriOrientRelation
;
125 aFrameProperties
["HoriOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nX
);
127 // Vertical positioning
128 sal_Int16 nVertOrient
= text::VertOrientation::NONE
;
129 if (m_aYSpec
== "bottom")
130 nVertOrient
= text::VertOrientation::BOTTOM
;
131 else if (m_aYSpec
== "center")
132 nVertOrient
= text::VertOrientation::CENTER
;
133 else if (m_aYSpec
== "top")
134 nVertOrient
= text::VertOrientation::TOP
;
135 // TODO There are a few cases we can't map ATM.
138 sal_Int16 nVertOrientRelation
;
139 if (m_aVertAnchor
== "margin")
140 nVertOrientRelation
= text::RelOrientation::PAGE_PRINT_AREA
;
141 else if (m_aVertAnchor
== "page")
142 nVertOrientRelation
= text::RelOrientation::PAGE_FRAME
;
143 else if (m_aVertAnchor
== "text")
144 nVertOrientRelation
= text::RelOrientation::FRAME
;
146 aFrameProperties
["VertOrient"] <<= nVertOrient
;
147 aFrameProperties
["VertOrientRelation"] <<= nVertOrientRelation
;
148 aFrameProperties
["VertOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nY
);
149 aFrameProperties
["FillTransparence"] <<= sal_Int32(100);
151 return aFrameProperties
.getAsConstPropertyValueList();
154 bool TablePositionHandler::operator== (const TablePositionHandler
& rHandler
) const
156 return m_aVertAnchor
== rHandler
.m_aVertAnchor
&&
157 m_aYSpec
== rHandler
.m_aYSpec
&&
158 m_aHorzAnchor
== rHandler
.m_aHorzAnchor
&&
159 m_aXSpec
== rHandler
.m_aXSpec
&&
160 m_nY
== rHandler
.m_nY
&&
161 m_nX
== rHandler
.m_nX
;
164 } // namespace dmapper
165 } // namespace writerfilter
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */