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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "MeasureHandler.hxx"
20 #include "PropertyMap.hxx"
21 #include "ConversionHelper.hxx"
22 #include <ooxml/resourceids.hxx>
23 #include <osl/diagnose.h>
24 #include <com/sun/star/text/SizeType.hpp>
25 #include <comphelper/sequence.hxx>
27 namespace writerfilter
{
30 using namespace ::com::sun::star
;
33 MeasureHandler::MeasureHandler() :
34 LoggedProperties("MeasureHandler"),
37 m_nRowHeightSizeType( text::SizeType::MIN
)
42 MeasureHandler::~MeasureHandler()
47 void MeasureHandler::lcl_attribute(Id rName
, Value
& rVal
)
49 sal_Int32 nIntValue
= rVal
.getInt();
52 case NS_ooxml::LN_CT_TblWidth_type
:
54 //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
55 // NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
58 if (!m_aInteropGrabBagName
.isEmpty())
60 beans::PropertyValue aValue
;
64 case NS_ooxml::LN_Value_ST_TblWidth_nil
: aValue
.Value
<<= OUString("nil"); break;
65 case NS_ooxml::LN_Value_ST_TblWidth_pct
: aValue
.Value
<<= OUString("pct"); break;
66 case NS_ooxml::LN_Value_ST_TblWidth_dxa
: aValue
.Value
<<= OUString("dxa"); break;
67 case NS_ooxml::LN_Value_ST_TblWidth_auto
: aValue
.Value
<<= OUString("auto"); break;
69 m_aInteropGrabBag
.push_back(aValue
);
73 case NS_ooxml::LN_CT_Height_hRule
:
75 OUString sHeightType
= rVal
.getString();
76 if ( sHeightType
== "exact" )
77 m_nRowHeightSizeType
= text::SizeType::FIX
;
80 case NS_ooxml::LN_CT_TblWidth_w
:
81 m_nMeasureValue
= nIntValue
;
82 if (!m_aInteropGrabBagName
.isEmpty())
84 beans::PropertyValue aValue
;
86 aValue
.Value
<<= nIntValue
;
87 m_aInteropGrabBag
.push_back(aValue
);
90 case NS_ooxml::LN_CT_Height_val
: // a string value
92 m_nUnit
= NS_ooxml::LN_Value_ST_TblWidth_dxa
;
93 OUString sHeight
= rVal
.getString();
94 m_nMeasureValue
= sHeight
.toInt32();
98 OSL_FAIL( "unknown attribute");
103 void MeasureHandler::lcl_sprm(Sprm
&) {}
106 sal_Int32
MeasureHandler::getMeasureValue() const
109 if( m_nMeasureValue
!= 0 && m_nUnit
>= 0 )
111 // TODO m_nUnit 3 - twip, other values unknown :-(
112 if( m_nUnit
== 3 || sal::static_int_cast
<Id
>(m_nUnit
) == NS_ooxml::LN_Value_ST_TblWidth_dxa
)
114 nRet
= ConversionHelper::convertTwipToMM100( m_nMeasureValue
);
116 //todo: handle additional width types:
117 //NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
118 //NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
123 void MeasureHandler::enableInteropGrabBag(const OUString
& aName
)
125 m_aInteropGrabBagName
= aName
;
128 beans::PropertyValue
MeasureHandler::getInteropGrabBag()
130 beans::PropertyValue aRet
;
131 aRet
.Name
= m_aInteropGrabBagName
;
132 aRet
.Value
<<= comphelper::containerToSequence(m_aInteropGrabBag
);
136 } //namespace dmapper
137 } //namespace writerfilter
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */