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 "TagLogger.hxx"
12 #include <ooxml/resourceids.hxx>
13 #include <com/sun/star/beans/PropertyValue.hpp>
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 <comphelper/sequenceashashmap.hxx>
19 namespace writerfilter::dmapper
21 using namespace ::com::sun::star
;
23 TablePositionHandler::TablePositionHandler()
24 : LoggedProperties("TablePositionHandler")
28 TablePositionHandler::~TablePositionHandler() = default;
30 void TablePositionHandler::lcl_attribute(Id nId
, Value
& rVal
)
34 case NS_ooxml::LN_CT_TblPPr_vertAnchor
:
35 m_aVertAnchor
= rVal
.getString();
37 case NS_ooxml::LN_CT_TblPPr_tblpYSpec
:
38 m_aYSpec
= rVal
.getString();
40 case NS_ooxml::LN_CT_TblPPr_horzAnchor
:
41 m_aHorzAnchor
= rVal
.getString();
43 case NS_ooxml::LN_CT_TblPPr_tblpXSpec
:
44 m_aXSpec
= rVal
.getString();
46 case NS_ooxml::LN_CT_TblPPr_tblpY
:
49 case NS_ooxml::LN_CT_TblPPr_tblpX
:
52 case NS_ooxml::LN_CT_TblPPr_leftFromText
:
53 m_nLeftFromText
= rVal
.getInt();
55 case NS_ooxml::LN_CT_TblPPr_rightFromText
:
56 m_nRightFromText
= rVal
.getInt();
58 case NS_ooxml::LN_CT_TblPPr_topFromText
:
59 m_nTopFromText
= rVal
.getInt();
61 case NS_ooxml::LN_CT_TblPPr_bottomFromText
:
62 m_nBottomFromText
= rVal
.getInt();
66 TagLogger::getInstance().element("unhandled");
72 void TablePositionHandler::lcl_sprm(Sprm
& /*rSprm*/) {}
74 uno::Sequence
<beans::PropertyValue
> TablePositionHandler::getTablePosition() const
76 comphelper::SequenceAsHashMap aFrameProperties
;
78 aFrameProperties
["LeftBorderDistance"] <<= sal_Int32(0);
79 aFrameProperties
["RightBorderDistance"] <<= sal_Int32(0);
80 aFrameProperties
["TopBorderDistance"] <<= sal_Int32(0);
81 aFrameProperties
["BottomBorderDistance"] <<= sal_Int32(0);
83 aFrameProperties
["LeftMargin"] <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText
);
84 aFrameProperties
["RightMargin"] <<= ConversionHelper::convertTwipToMM100(m_nRightFromText
);
85 aFrameProperties
["TopMargin"] <<= ConversionHelper::convertTwipToMM100(m_nTopFromText
);
86 aFrameProperties
["BottomMargin"] <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText
);
88 table::BorderLine2 aEmptyBorder
;
89 aFrameProperties
["TopBorder"] <<= aEmptyBorder
;
90 aFrameProperties
["BottomBorder"] <<= aEmptyBorder
;
91 aFrameProperties
["LeftBorder"] <<= aEmptyBorder
;
92 aFrameProperties
["RightBorder"] <<= aEmptyBorder
;
94 // Horizontal positioning
95 sal_Int16 nHoriOrient
= text::HoriOrientation::NONE
;
96 if (m_aXSpec
== "center")
97 nHoriOrient
= text::HoriOrientation::CENTER
;
98 else if (m_aXSpec
== "inside")
99 nHoriOrient
= text::HoriOrientation::INSIDE
;
100 else if (m_aXSpec
== "left")
101 nHoriOrient
= text::HoriOrientation::LEFT
;
102 else if (m_aXSpec
== "outside")
103 nHoriOrient
= text::HoriOrientation::OUTSIDE
;
104 else if (m_aXSpec
== "right")
105 nHoriOrient
= text::HoriOrientation::RIGHT
;
107 sal_Int16 nHoriOrientRelation
;
108 if (m_aHorzAnchor
== "margin")
109 nHoriOrientRelation
= text::RelOrientation::PAGE_PRINT_AREA
;
110 else if (m_aHorzAnchor
== "page")
111 nHoriOrientRelation
= text::RelOrientation::PAGE_FRAME
;
112 else if (m_aHorzAnchor
== "text")
113 nHoriOrientRelation
= text::RelOrientation::FRAME
;
115 aFrameProperties
["HoriOrient"] <<= nHoriOrient
;
116 aFrameProperties
["HoriOrientRelation"] <<= nHoriOrientRelation
;
117 aFrameProperties
["HoriOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nX
);
119 // Vertical positioning
120 sal_Int16 nVertOrient
= text::VertOrientation::NONE
;
121 if (m_aYSpec
== "bottom")
122 nVertOrient
= text::VertOrientation::BOTTOM
;
123 else if (m_aYSpec
== "center")
124 nVertOrient
= text::VertOrientation::CENTER
;
125 else if (m_aYSpec
== "top")
126 nVertOrient
= text::VertOrientation::TOP
;
127 // TODO There are a few cases we can't map ATM.
129 sal_Int16 nVertOrientRelation
;
130 if (m_aVertAnchor
== "margin")
131 nVertOrientRelation
= text::RelOrientation::PAGE_PRINT_AREA
;
132 else if (m_aVertAnchor
== "page")
133 nVertOrientRelation
= text::RelOrientation::PAGE_FRAME
;
134 else if (m_aVertAnchor
== "text")
135 nVertOrientRelation
= text::RelOrientation::FRAME
;
137 aFrameProperties
["VertOrient"] <<= nVertOrient
;
138 aFrameProperties
["VertOrientRelation"] <<= nVertOrientRelation
;
139 aFrameProperties
["VertOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nY
);
140 aFrameProperties
["FillTransparence"] <<= sal_Int32(100);
142 if (m_nTableOverlap
== NS_ooxml::LN_Value_ST_TblOverlap_never
)
144 // NS_ooxml::LN_Value_ST_TblOverlap_overlap is the default, both in OOXML and in Writer.
145 aFrameProperties
["AllowOverlap"] <<= false;
148 return aFrameProperties
.getAsConstPropertyValueList();
151 bool TablePositionHandler::operator==(const TablePositionHandler
& rHandler
) const
153 return m_aVertAnchor
== rHandler
.m_aVertAnchor
&& m_aYSpec
== rHandler
.m_aYSpec
154 && m_aHorzAnchor
== rHandler
.m_aHorzAnchor
&& m_aXSpec
== rHandler
.m_aXSpec
155 && m_nY
== rHandler
.m_nY
&& m_nX
== rHandler
.m_nX
;
158 } // namespace writerfilter::dmapper
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */