Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include <MeasureHandler.hxx>
20 : #include <PropertyMap.hxx>
21 : #include <ConversionHelper.hxx>
22 : #include <ooxml/resourceids.hxx>
23 : #include <com/sun/star/text/SizeType.hpp>
24 : #include "dmapperLoggers.hxx"
25 :
26 : namespace writerfilter {
27 : namespace dmapper {
28 :
29 : using namespace ::com::sun::star;
30 :
31 :
32 :
33 0 : MeasureHandler::MeasureHandler() :
34 : LoggedProperties(dmapper_logger, "MeasureHandler"),
35 : m_nMeasureValue( 0 ),
36 : m_nUnit( -1 ),
37 0 : m_nRowHeightSizeType( text::SizeType::MIN )
38 : {
39 0 : }
40 :
41 :
42 0 : MeasureHandler::~MeasureHandler()
43 : {
44 0 : }
45 :
46 :
47 0 : void MeasureHandler::lcl_attribute(Id rName, Value & rVal)
48 : {
49 0 : sal_Int32 nIntValue = rVal.getInt();
50 : (void)rName;
51 0 : switch( rName )
52 : {
53 : case NS_ooxml::LN_CT_TblWidth_type:// = 90668;
54 : {
55 : //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct,
56 : // NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto;
57 0 : m_nUnit = nIntValue;
58 :
59 0 : if (!m_aInteropGrabBagName.isEmpty())
60 : {
61 0 : beans::PropertyValue aValue;
62 0 : aValue.Name = "type";
63 0 : switch (nIntValue)
64 : {
65 0 : case NS_ooxml::LN_Value_ST_TblWidth_nil: aValue.Value = uno::makeAny(OUString("nil")); break;
66 0 : case NS_ooxml::LN_Value_ST_TblWidth_pct: aValue.Value = uno::makeAny(OUString("pct")); break;
67 0 : case NS_ooxml::LN_Value_ST_TblWidth_dxa: aValue.Value = uno::makeAny(OUString("dxa")); break;
68 0 : case NS_ooxml::LN_Value_ST_TblWidth_auto: aValue.Value = uno::makeAny(OUString("auto")); break;
69 : }
70 0 : m_aInteropGrabBag.push_back(aValue);
71 : }
72 : }
73 0 : break;
74 : case NS_ooxml::LN_CT_Height_hRule: // 90666;
75 : {
76 0 : OUString sHeightType = rVal.getString();
77 0 : if ( sHeightType == "exact" )
78 0 : m_nRowHeightSizeType = text::SizeType::FIX;
79 : }
80 0 : break;
81 : case NS_ooxml::LN_CT_TblWidth_w:// = 90667;
82 0 : m_nMeasureValue = nIntValue;
83 0 : if (!m_aInteropGrabBagName.isEmpty())
84 : {
85 0 : beans::PropertyValue aValue;
86 0 : aValue.Name = "w";
87 0 : aValue.Value = uno::makeAny(nIntValue);
88 0 : m_aInteropGrabBag.push_back(aValue);
89 : }
90 0 : break;
91 : case NS_ooxml::LN_CT_Height_val: // 90665 -- a string value
92 : {
93 0 : m_nUnit = NS_ooxml::LN_Value_ST_TblWidth_dxa;
94 0 : OUString sHeight = rVal.getString();
95 0 : m_nMeasureValue = sHeight.toInt32();
96 : }
97 0 : break;
98 : default:
99 : OSL_FAIL( "unknown attribute");
100 : }
101 0 : }
102 :
103 :
104 0 : void MeasureHandler::lcl_sprm(Sprm & rSprm)
105 : {
106 : (void)rSprm;
107 0 : }
108 :
109 :
110 0 : sal_Int32 MeasureHandler::getMeasureValue() const
111 : {
112 0 : sal_Int32 nRet = 0;
113 0 : if( m_nMeasureValue != 0 && m_nUnit >= 0 )
114 : {
115 : // TODO m_nUnit 3 - twip, other values unknown :-(
116 0 : if( m_nUnit == 3 || sal::static_int_cast<Id>(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_dxa)
117 : {
118 0 : nRet = ConversionHelper::convertTwipToMM100( m_nMeasureValue );
119 : }
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;
123 : }
124 0 : return nRet;
125 : }
126 :
127 0 : void MeasureHandler::enableInteropGrabBag(const OUString& aName)
128 : {
129 0 : m_aInteropGrabBagName = aName;
130 0 : }
131 :
132 0 : beans::PropertyValue MeasureHandler::getInteropGrabBag()
133 : {
134 0 : beans::PropertyValue aRet;
135 0 : aRet.Name = m_aInteropGrabBagName;
136 :
137 0 : uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
138 0 : beans::PropertyValue* pSeq = aSeq.getArray();
139 0 : for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
140 0 : *pSeq++ = *i;
141 :
142 0 : aRet.Value = uno::makeAny(aSeq);
143 0 : return aRet;
144 : }
145 :
146 : } //namespace dmapper
147 : } //namespace writerfilter
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|