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 2 : WrapPolygon::WrapPolygon()
36 : {
37 2 : }
38 :
39 4 : WrapPolygon::~WrapPolygon()
40 : {
41 4 : }
42 :
43 10 : void WrapPolygon::addPoint(const awt::Point & rPoint)
44 : {
45 10 : mPoints.push_back(rPoint);
46 10 : }
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)
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 aScaleSrcX(rSrcSize.Width, nWrap100Percent);
123 0 : Fraction aScaleSrcY(rSrcSize.Height, nWrap100Percent);
124 0 : pResult = pResult->scale(aScaleSrcX, aScaleSrcY);
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 2 : WrapPolygonHandler::WrapPolygonHandler()
150 : : LoggedProperties(dmapper_logger, "WrapPolygonHandler")
151 2 : , mpPolygon(new WrapPolygon)
152 : , mnX(0)
153 4 : , mnY(0)
154 : {
155 2 : }
156 :
157 2 : WrapPolygonHandler::~WrapPolygonHandler()
158 : {
159 2 : }
160 :
161 22 : void WrapPolygonHandler::lcl_attribute(Id Name, Value & val)
162 : {
163 22 : sal_Int32 nIntValue = val.getInt();
164 :
165 22 : switch(Name)
166 : {
167 : case NS_ooxml::LN_CT_Point2D_x:
168 10 : mnX = nIntValue;
169 10 : break;
170 : case NS_ooxml::LN_CT_Point2D_y:
171 10 : mnY = nIntValue;
172 10 : break;
173 : default:
174 : #ifdef DEBUG_WRAP_POLYGON_HANDLER
175 : dmapper_logger->element("unhandled");
176 : #endif
177 2 : break;
178 : }
179 22 : }
180 :
181 10 : void WrapPolygonHandler::lcl_sprm(Sprm & _sprm)
182 : {
183 10 : switch (_sprm.getId())
184 : {
185 : case NS_ooxml::LN_CT_WrapPath_lineTo:
186 : case NS_ooxml::LN_CT_WrapPath_start:
187 : {
188 10 : resolveSprmProps(*this, _sprm);
189 :
190 10 : awt::Point aPoint(mnX, mnY);
191 10 : mpPolygon->addPoint(aPoint);
192 : }
193 10 : break;
194 : default:
195 : #ifdef DEBUG_WRAP_POLYGON_HANDLER
196 : dmapper_logger->element("unhandled");
197 : #endif
198 0 : break;
199 : }
200 10 : }
201 :
202 2 : WrapPolygon::Pointer_t WrapPolygonHandler::getPolygon()
203 : {
204 2 : return mpPolygon;
205 : }
206 :
207 : }}
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|