Bump version to 4.3-4
[LibreOffice.git] / writerfilter / source / dmapper / WrapPolygonHandler.cxx
blob0b25ca2eec3c41c87168fdfcd1576fbb8433ec6f
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 .
20 #include <com/sun/star/drawing/PointSequence.hpp>
22 #include <ooxml/resourceids.hxx>
23 #include <resourcemodel/ResourceModelHelper.hxx>
25 #include "ConversionHelper.hxx"
26 #include "WrapPolygonHandler.hxx"
27 #include "dmapperLoggers.hxx"
29 namespace writerfilter {
31 using resourcemodel::resolveSprmProps;
32 using namespace com::sun::star;
34 namespace dmapper {
36 WrapPolygon::WrapPolygon()
40 WrapPolygon::~WrapPolygon()
44 void WrapPolygon::addPoint(const awt::Point & rPoint)
46 mPoints.push_back(rPoint);
49 WrapPolygon::Points_t::const_iterator WrapPolygon::begin() const
51 return mPoints.begin();
54 WrapPolygon::Points_t::const_iterator WrapPolygon::end() const
56 return mPoints.end();
59 WrapPolygon::Points_t::iterator WrapPolygon::begin()
61 return mPoints.begin();
64 WrapPolygon::Points_t::iterator WrapPolygon::end()
66 return mPoints.end();
69 size_t WrapPolygon::size() const
71 return mPoints.size();
74 WrapPolygon::Pointer_t WrapPolygon::move(const awt::Point & rPoint)
76 WrapPolygon::Pointer_t pResult(new WrapPolygon);
78 Points_t::iterator aIt = begin();
79 Points_t::iterator aItEnd = end();
81 while (aIt != aItEnd)
83 awt::Point aPoint(aIt->X + rPoint.X, aIt->Y + rPoint.Y);
84 pResult->addPoint(aPoint);
85 ++aIt;
88 return pResult;
91 WrapPolygon::Pointer_t WrapPolygon::scale(const resourcemodel::Fraction & rFractionX, const resourcemodel::Fraction & rFractionY)
93 WrapPolygon::Pointer_t pResult(new WrapPolygon);
95 Points_t::iterator aIt = begin();
96 Points_t::iterator aItEnd = end();
98 while (aIt != aItEnd)
100 awt::Point aPoint(resourcemodel::Fraction(aIt->X) * rFractionX, resourcemodel::Fraction(aIt->Y) * rFractionY);
101 pResult->addPoint(aPoint);
102 ++aIt;
105 return pResult;
108 WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSrcSize)
110 WrapPolygon::Pointer_t pResult;
112 const sal_uInt32 nWrap100Percent = 21600;
114 resourcemodel::Fraction aMove(nWrap100Percent, rSrcSize.Width);
115 aMove = aMove * resourcemodel::Fraction(15, 1);
116 awt::Point aMovePoint(aMove, 0);
117 pResult = move(aMovePoint);
119 resourcemodel::Fraction aScaleX(nWrap100Percent, resourcemodel::Fraction(nWrap100Percent) + aMove);
120 resourcemodel::Fraction aScaleY(nWrap100Percent, resourcemodel::Fraction(nWrap100Percent) - aMove);
121 pResult = pResult->scale(aScaleX, aScaleY);
123 resourcemodel::Fraction aScaleSrcX(rSrcSize.Width, nWrap100Percent);
124 resourcemodel::Fraction aScaleSrcY(rSrcSize.Height, nWrap100Percent);
125 pResult = pResult->scale(aScaleSrcX, aScaleSrcY);
127 return pResult;
130 drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const
132 drawing::PointSequenceSequence aPolyPolygon(1L);
133 drawing::PointSequence * pPolygon = aPolyPolygon.getArray();
134 pPolygon->realloc(size());
136 sal_uInt32 n = 0;
137 Points_t::const_iterator aIt = begin();
138 Points_t::const_iterator aItEnd = end();
140 while (aIt != aItEnd)
142 (*pPolygon)[n] = *aIt;
143 ++n;
144 ++aIt;
147 return aPolyPolygon;
150 WrapPolygonHandler::WrapPolygonHandler()
151 : LoggedProperties(dmapper_logger, "WrapPolygonHandler")
152 , mpPolygon(new WrapPolygon)
153 , mnX(0)
154 , mnY(0)
158 WrapPolygonHandler::~WrapPolygonHandler()
162 void WrapPolygonHandler::lcl_attribute(Id Name, Value & val)
164 sal_Int32 nIntValue = val.getInt();
166 switch(Name)
168 case NS_ooxml::LN_CT_Point2D_x:
169 mnX = nIntValue;
170 break;
171 case NS_ooxml::LN_CT_Point2D_y:
172 mnY = nIntValue;
173 break;
174 default:
175 #ifdef DEBUG_WRAP_POLYGON_HANDLER
176 dmapper_logger->element("unhandled");
177 #endif
178 break;
182 void WrapPolygonHandler::lcl_sprm(Sprm & _sprm)
184 switch (_sprm.getId())
186 case NS_ooxml::LN_CT_WrapPath_lineTo:
187 case NS_ooxml::LN_CT_WrapPath_start:
189 resolveSprmProps(*this, _sprm);
191 awt::Point aPoint(mnX, mnY);
192 mpPolygon->addPoint(aPoint);
194 break;
195 default:
196 #ifdef DEBUG_WRAP_POLYGON_HANDLER
197 dmapper_logger->element("unhandled");
198 #endif
199 break;
203 WrapPolygon::Pointer_t WrapPolygonHandler::getPolygon()
205 return mpPolygon;
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */