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 
24 #include <com/sun/star/drawing/PointSequence.hpp>
25 
26 #include <ooxml/resourceids.hxx>
27 #include <resourcemodel/ResourceModelHelper.hxx>
28 
29 #include "ConversionHelper.hxx"
30 #include "WrapPolygonHandler.hxx"
31 #include "dmapperLoggers.hxx"
32 
33 namespace writerfilter {
34 
35 using resourcemodel::resolveSprmProps;
36 
37 namespace dmapper {
38 
WrapPolygon()39 WrapPolygon::WrapPolygon()
40 {
41 }
42 
~WrapPolygon()43 WrapPolygon::~WrapPolygon()
44 {
45 }
46 
addPoint(const awt::Point & rPoint)47 void WrapPolygon::addPoint(const awt::Point & rPoint)
48 {
49     mPoints.push_back(rPoint);
50 }
51 
begin() const52 WrapPolygon::Points_t::const_iterator WrapPolygon::begin() const
53 {
54     return mPoints.begin();
55 }
56 
end() const57 WrapPolygon::Points_t::const_iterator WrapPolygon::end() const
58 {
59     return mPoints.end();
60 }
61 
begin()62 WrapPolygon::Points_t::iterator WrapPolygon::begin()
63 {
64     return mPoints.begin();
65 }
66 
end()67 WrapPolygon::Points_t::iterator WrapPolygon::end()
68 {
69     return mPoints.end();
70 }
71 
size() const72 size_t WrapPolygon::size() const
73 {
74     return mPoints.size();
75 }
76 
move(const awt::Point & rPoint)77 WrapPolygon::Pointer_t WrapPolygon::move(const awt::Point & rPoint)
78 {
79     WrapPolygon::Pointer_t pResult(new WrapPolygon);
80 
81     Points_t::iterator aIt = begin();
82     Points_t::iterator aItEnd = end();
83 
84     while (aIt != aItEnd)
85     {
86         awt::Point aPoint(aIt->X + rPoint.X, aIt->Y + rPoint.Y);
87         pResult->addPoint(aPoint);
88         aIt++;
89     }
90 
91     return pResult;
92 }
93 
scale(const Fraction & rFractionX,const Fraction & rFractionY)94 WrapPolygon::Pointer_t WrapPolygon::scale(const Fraction & rFractionX, const Fraction & rFractionY)
95 {
96     WrapPolygon::Pointer_t pResult(new WrapPolygon);
97 
98     Points_t::iterator aIt = begin();
99     Points_t::iterator aItEnd = end();
100 
101     while (aIt != aItEnd)
102     {
103         awt::Point aPoint(Fraction(aIt->X) * rFractionX, Fraction(aIt->Y) * rFractionY);
104         pResult->addPoint(aPoint);
105         aIt++;
106     }
107 
108     return pResult;
109 }
110 
correctWordWrapPolygon(const awt::Size & rSrcSize,const awt::Size & rDstSize)111 WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSrcSize, const awt::Size & rDstSize)
112 {
113     WrapPolygon::Pointer_t pResult;
114 
115     const sal_uInt32 nWrap100Percent = 21600;
116 
117     Fraction aMove(nWrap100Percent, rSrcSize.Width);
118     aMove = aMove * Fraction(15, 1);
119     awt::Point aMovePoint(aMove, 0);
120     pResult = move(aMovePoint);
121 
122     Fraction aScaleX(nWrap100Percent, Fraction(nWrap100Percent) + aMove);
123     Fraction aScaleY(nWrap100Percent, Fraction(nWrap100Percent) - aMove);
124     pResult = pResult->scale(aScaleX, aScaleY);
125 
126     Fraction aScaleDestX(rDstSize.Width, nWrap100Percent);
127     Fraction aScaleDestY(rDstSize.Height, nWrap100Percent);
128     pResult = pResult->scale(aScaleDestX, aScaleDestY);
129 
130     return pResult;
131 }
132 
getPointSequenceSequence() const133 drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const
134 {
135     drawing::PointSequenceSequence aPolyPolygon(1L);
136     drawing::PointSequence * pPolygon = aPolyPolygon.getArray();
137     pPolygon->realloc(size());
138 
139     sal_uInt32 n = 0;
140     Points_t::const_iterator aIt = begin();
141     Points_t::const_iterator aItEnd = end();
142 
143     while (aIt != aItEnd)
144     {
145         (*pPolygon)[n] = *aIt;
146         ++n;
147         aIt++;
148     }
149 
150     return aPolyPolygon;
151 }
152 
WrapPolygonHandler()153 WrapPolygonHandler::WrapPolygonHandler()
154 : LoggedProperties(dmapper_logger, "WrapPolygonHandler")
155 , mpPolygon(new WrapPolygon)
156 {
157 }
158 
~WrapPolygonHandler()159 WrapPolygonHandler::~WrapPolygonHandler()
160 {
161 }
162 
lcl_attribute(Id Name,Value & val)163 void WrapPolygonHandler::lcl_attribute(Id Name, Value & val)
164 {
165     sal_Int32 nIntValue = val.getInt();
166 
167     switch(Name)
168     {
169     case NS_ooxml::LN_CT_Point2D_x:
170         /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
171         mnX = nIntValue;
172         break;
173     case NS_ooxml::LN_CT_Point2D_y:
174         /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
175         mnY = nIntValue;
176         break;
177     default:
178 #ifdef DEBUG_WRAP_POLYGON_HANDLER
179         dmapper_logger->element("WrapPolygonHandler.unhandled");
180 #endif
181         break;
182     }
183 }
184 
lcl_sprm(Sprm & _sprm)185 void WrapPolygonHandler::lcl_sprm(Sprm & _sprm)
186 {
187     switch (_sprm.getId())
188     {
189     case NS_ooxml::LN_CT_WrapPath_lineTo:
190     case NS_ooxml::LN_CT_WrapPath_start:
191         /* WRITERFILTERSTATUS: done: 100, planned: 0.5, spent: 0 */
192         {
193             resolveSprmProps(*this, _sprm);
194 
195             awt::Point aPoint(mnX, mnY);
196             mpPolygon->addPoint(aPoint);
197         }
198         break;
199     default:
200 #ifdef DEBUG_WRAP_POLYGON_HANDLER
201         dmapper_logger->element("WrapPolygonHandler.unhandled");
202 #endif
203         break;
204     }
205 }
206 
getPolygon()207 WrapPolygon::Pointer_t WrapPolygonHandler::getPolygon()
208 {
209     return mpPolygon;
210 }
211 
212 }}
213