merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / dmapper / MeasureHandler.cxx
blob4b9d8df5fcebb07f8a562cb58aa891fef532f4d5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MeasureHandler.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <MeasureHandler.hxx>
31 #include <PropertyMap.hxx>
32 #include <doctok/resourceids.hxx>
33 #include <ConversionHelper.hxx>
34 #include <ooxml/resourceids.hxx>
35 #include <com/sun/star/text/SizeType.hpp>
37 namespace writerfilter {
38 namespace dmapper {
40 using namespace ::com::sun::star;
42 /*-- 24.04.2007 09:06:35---------------------------------------------------
44 -----------------------------------------------------------------------*/
45 MeasureHandler::MeasureHandler() :
46 m_nMeasureValue( 0 ),
47 m_nUnit( -1 ),
48 m_nRowHeightSizeType( text::SizeType::MIN )
51 /*-- 24.04.2007 09:06:35---------------------------------------------------
53 -----------------------------------------------------------------------*/
54 MeasureHandler::~MeasureHandler()
57 /*-- 24.04.2007 09:06:35---------------------------------------------------
59 -----------------------------------------------------------------------*/
60 void MeasureHandler::attribute(Id rName, Value & rVal)
62 sal_Int32 nIntValue = rVal.getInt();
63 (void)rName;
64 /* WRITERFILTERSTATUS: table: MeasureHandler_attributedata */
65 switch( rName )
67 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
68 case NS_rtf::LN_unit:
69 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
70 case NS_ooxml::LN_CT_TblWidth_type:// = 90668;
71 //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
72 // NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
73 m_nUnit = nIntValue;
74 break;
75 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
76 case NS_ooxml::LN_CT_Height_hRule: // 90666;
78 ::rtl::OUString sHeightType = rVal.getString();
79 if( sHeightType.equalsAscii( "exact" ) )
80 m_nRowHeightSizeType = text::SizeType::FIX;
82 break;
83 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
84 case NS_rtf::LN_trleft:
85 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
86 case NS_rtf::LN_preferredWidth:
87 case NS_ooxml::LN_CT_TblWidth_w:// = 90667;
88 m_nMeasureValue = nIntValue;
89 break;
90 /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
91 case NS_ooxml::LN_CT_Height_val: // 90665 -- a string value
93 m_nUnit = NS_ooxml::LN_Value_ST_TblWidth_dxa;
94 ::rtl::OUString sHeight = rVal.getString();
95 m_nMeasureValue = sHeight.toInt32();
97 break;
98 default:
99 OSL_ENSURE( false, "unknown attribute");
102 /*-- 24.04.2007 09:06:35---------------------------------------------------
104 -----------------------------------------------------------------------*/
105 void MeasureHandler::sprm(Sprm & rSprm)
107 (void)rSprm;
109 /*-- 24.04.2007 09:09:01---------------------------------------------------
111 -----------------------------------------------------------------------*/
112 sal_Int32 MeasureHandler::getMeasureValue() const
114 sal_Int32 nRet = 0;
115 if( m_nMeasureValue != 0 && m_nUnit >= 0 )
117 // TODO m_nUnit 3 - twip, other values unknown :-(
118 if( m_nUnit == 3 || sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_dxa)
119 nRet = ConversionHelper::convertTwipToMM100( m_nMeasureValue );
120 //todo: handle additional width types:
121 //NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
122 //NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
124 return nRet;
126 /*-- 18.06.2007 10:24:26---------------------------------------------------
128 -----------------------------------------------------------------------*/
129 bool MeasureHandler::isAutoWidth() const
131 return sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_auto;
134 } //namespace dmapper
135 } //namespace writerfilter