1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include <MeasureHandler.hxx>
24 #include <PropertyMap.hxx>
25 #include <doctok/resourceids.hxx>
26 #include <ConversionHelper.hxx>
27 #include <ooxml/resourceids.hxx>
28 #include <com/sun/star/text/SizeType.hpp>
29 #include "dmapperLoggers.hxx"
30 
31 namespace writerfilter {
32 namespace dmapper {
33 
34 using namespace ::com::sun::star;
35 
36 /*-- 24.04.2007 09:06:35---------------------------------------------------
37 
38   -----------------------------------------------------------------------*/
MeasureHandler()39 MeasureHandler::MeasureHandler() :
40 LoggedProperties(dmapper_logger, "MeasureHandler"),
41 m_nMeasureValue( 0 ),
42 m_nUnit( -1 ),
43 m_nRowHeightSizeType( text::SizeType::MIN )
44 {
45 }
46 /*-- 24.04.2007 09:06:35---------------------------------------------------
47 
48   -----------------------------------------------------------------------*/
~MeasureHandler()49 MeasureHandler::~MeasureHandler()
50 {
51 }
52 /*-- 24.04.2007 09:06:35---------------------------------------------------
53 
54   -----------------------------------------------------------------------*/
lcl_attribute(Id rName,Value & rVal)55 void MeasureHandler::lcl_attribute(Id rName, Value & rVal)
56 {
57     sal_Int32 nIntValue = rVal.getInt();
58     (void)rName;
59     /* WRITERFILTERSTATUS: table: MeasureHandler_attributedata */
60     switch( rName )
61     {
62         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
63         case NS_rtf::LN_unit:
64         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
65         case NS_ooxml::LN_CT_TblWidth_type:// = 90668;
66             //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
67             //        NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
68             m_nUnit = nIntValue;
69         break;
70         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
71         case NS_ooxml::LN_CT_Height_hRule: // 90666;
72         {
73             ::rtl::OUString sHeightType = rVal.getString();
74             if( sHeightType.equalsAscii( "exact" ) )
75                 m_nRowHeightSizeType = text::SizeType::FIX;
76         }
77         break;
78         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
79         case NS_rtf::LN_trleft:
80         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
81         case NS_rtf::LN_preferredWidth:
82         case NS_ooxml::LN_CT_TblWidth_w:// = 90667;
83             m_nMeasureValue = nIntValue;
84         break;
85         /* WRITERFILTERSTATUS: done: 1, planned: 0, spent: 0 */
86         case NS_ooxml::LN_CT_Height_val: // 90665 -- a string value
87         {
88             m_nUnit = NS_ooxml::LN_Value_ST_TblWidth_dxa;
89             ::rtl::OUString sHeight = rVal.getString();
90             m_nMeasureValue = sHeight.toInt32();
91         }
92         break;
93         default:
94             OSL_ENSURE( false, "unknown attribute");
95     }
96 }
97 /*-- 24.04.2007 09:06:35---------------------------------------------------
98 
99   -----------------------------------------------------------------------*/
lcl_sprm(Sprm & rSprm)100 void MeasureHandler::lcl_sprm(Sprm & rSprm)
101 {
102     (void)rSprm;
103 }
104 /*-- 24.04.2007 09:09:01---------------------------------------------------
105 
106   -----------------------------------------------------------------------*/
getMeasureValue() const107 sal_Int32 MeasureHandler::getMeasureValue() const
108 {
109     sal_Int32 nRet = 0;
110     if( m_nMeasureValue != 0 && m_nUnit >= 0 )
111     {
112         // TODO m_nUnit 3 - twip, other values unknown :-(
113         if( m_nUnit == 3 || sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_dxa)
114             nRet = ConversionHelper::convertTwipToMM100( m_nMeasureValue );
115         //todo: handle additional width types:
116         //NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
117         //NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
118     }
119     return nRet;
120 }
121 /*-- 18.06.2007 10:24:26---------------------------------------------------
122 
123   -----------------------------------------------------------------------*/
isAutoWidth() const124 bool MeasureHandler::isAutoWidth() const
125 {
126     return sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_auto;
127 }
128 
129 } //namespace dmapper
130 } //namespace writerfilter
131