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