android: Update app-specific/MIME type icons
[LibreOffice.git] / writerfilter / source / dmapper / MeasureHandler.cxx
blob5eea9a5c613b47b5fdb59227ff1fd79a40f0d2fd
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/.
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 "ConversionHelper.hxx"
21 #include <ooxml/resourceids.hxx>
22 #include <osl/diagnose.h>
23 #include <com/sun/star/text/SizeType.hpp>
24 #include <comphelper/sequence.hxx>
26 namespace writerfilter::dmapper {
28 using namespace ::com::sun::star;
31 MeasureHandler::MeasureHandler() :
32 LoggedProperties("MeasureHandler"),
33 m_nMeasureValue( 0 ),
34 m_nUnit( -1 ),
35 m_nRowHeightSizeType( text::SizeType::MIN )
40 MeasureHandler::~MeasureHandler()
45 void MeasureHandler::lcl_attribute(Id rName, Value & rVal)
47 sal_Int32 nIntValue = rVal.getInt();
48 switch( rName )
50 case NS_ooxml::LN_CT_TblWidth_type:
52 //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
53 // NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
54 m_nUnit = nIntValue;
56 if (!m_aInteropGrabBagName.isEmpty())
58 beans::PropertyValue aValue;
59 aValue.Name = "type";
60 switch (nIntValue)
62 case NS_ooxml::LN_Value_ST_TblWidth_nil: aValue.Value <<= OUString("nil"); break;
63 case NS_ooxml::LN_Value_ST_TblWidth_pct: aValue.Value <<= OUString("pct"); break;
64 case NS_ooxml::LN_Value_ST_TblWidth_dxa: aValue.Value <<= OUString("dxa"); break;
65 case NS_ooxml::LN_Value_ST_TblWidth_auto: aValue.Value <<= OUString("auto"); break;
67 m_aInteropGrabBag.push_back(aValue);
70 break;
71 case NS_ooxml::LN_CT_Height_hRule:
73 OUString sHeightType = rVal.getString();
74 if ( sHeightType == "exact" )
75 m_nRowHeightSizeType = text::SizeType::FIX;
77 break;
78 case NS_ooxml::LN_CT_TblWidth_w:
79 m_nMeasureValue = nIntValue;
80 if (!m_aInteropGrabBagName.isEmpty())
82 beans::PropertyValue aValue;
83 aValue.Name = "w";
84 aValue.Value <<= nIntValue;
85 m_aInteropGrabBag.push_back(aValue);
87 break;
88 case NS_ooxml::LN_CT_Height_val: // a string value
90 m_nUnit = NS_ooxml::LN_Value_ST_TblWidth_dxa;
91 OUString sHeight = rVal.getString();
92 m_nMeasureValue = sHeight.toInt32();
94 break;
95 default:
96 OSL_FAIL( "unknown attribute");
101 void MeasureHandler::lcl_sprm(Sprm &) {}
104 sal_Int32 MeasureHandler::getMeasureValue() const
106 sal_Int32 nRet = 0;
107 if( m_nMeasureValue != 0 && m_nUnit >= 0 )
109 // TODO m_nUnit 3 - twip, other values unknown :-(
110 if( m_nUnit == 3 || sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_dxa)
112 nRet = ConversionHelper::convertTwipToMM100( m_nMeasureValue );
114 //todo: handle additional width types:
115 //NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
116 //NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
118 return nRet;
121 void MeasureHandler::enableInteropGrabBag(const OUString& aName)
123 m_aInteropGrabBagName = aName;
126 beans::PropertyValue MeasureHandler::getInteropGrabBag()
128 beans::PropertyValue aRet;
129 aRet.Name = m_aInteropGrabBagName;
130 aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag);
131 return aRet;
134 } //namespace writerfilter::dmapper
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */