1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <basegfx/point/b2dpoint.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
23 #include <sal/log.hxx>
24 #include "emfppath.hxx"
26 namespace emfplushelper
28 EMFPPath::EMFPPath (sal_Int32 _nPoints
, bool bLines
)
30 if (_nPoints
<0 || sal_uInt32(_nPoints
)>SAL_MAX_INT32
/ (2 * sizeof(float)))
32 _nPoints
= SAL_MAX_INT32
/ (2 * sizeof(float));
36 pPoints
.reset( new float [nPoints
*2] );
39 pPointTypes
.reset( new sal_uInt8
[_nPoints
] );
42 EMFPPath::~EMFPPath ()
46 void EMFPPath::Read (SvStream
& s
, sal_uInt32 pathFlags
)
48 for (int i
= 0; i
< nPoints
; i
++)
50 if (pathFlags
& 0x800)
52 // EMFPlusPointR: points are stored in EMFPlusInteger7 or
53 // EMFPlusInteger15 objects, see section 2.2.2.21/22
54 // If 0x800 bit is set, the 0x4000 bit is undefined and must be ignored
55 SAL_WARN("drawinglayer", "EMF+\t\t TODO - parse EMFPlusPointR object (section 2.2.1.6)");
57 else if (pathFlags
& 0x4000)
59 // EMFPlusPoint: stored in signed short 16bit integer format
62 s
.ReadInt16( x
).ReadInt16( y
);
63 SAL_INFO ("drawinglayer", "EMF+\t EMFPlusPoint [x,y]: " << x
<< "," << y
);
65 pPoints
[i
*2 + 1] = y
;
69 // EMFPlusPointF: stored in Single (float) format
70 s
.ReadFloat( pPoints
[i
*2] ).ReadFloat( pPoints
[i
*2 + 1] );
71 SAL_INFO ("drawinglayer", "EMF+\t EMFPlusPointF [x,y]: " << pPoints
[i
*2] << "," << pPoints
[i
*2 + 1]);
77 for (int i
= 0; i
< nPoints
; i
++)
79 s
.ReadUChar(pPointTypes
[i
]);
80 SAL_INFO("drawinglayer", "EMF+\tpoint type: " << static_cast<int>(pPointTypes
[i
]));
87 ::basegfx::B2DPolyPolygon
& EMFPPath::GetPolygon (EmfPlusHelperData
const & rR
, bool bMapIt
, bool bAddLineToCloseShape
)
89 ::basegfx::B2DPolygon polygon
;
91 int last_normal
= 0, p
= 0;
92 ::basegfx::B2DPoint prev
, mapped
;
95 for (int i
= 0; i
< nPoints
; i
++)
97 if (p
&& pPointTypes
&& (pPointTypes
[i
] == 0))
99 aPolygon
.append (polygon
);
106 mapped
= rR
.Map (pPoints
[i
*2], pPoints
[i
*2 + 1]);
108 mapped
= ::basegfx::B2DPoint (pPoints
[i
*2], pPoints
[i
*2 + 1]);
112 if ((pPointTypes
[i
] & 0x07) == 3)
114 if (((i
- last_normal
)% 3) == 1)
116 polygon
.setNextControlPoint (p
- 1, mapped
);
117 SAL_INFO ("drawinglayer", "polygon append next: " << p
- 1 << " mapped: " << mapped
.getX () << "," << mapped
.getY ());
120 else if (((i
- last_normal
) % 3) == 2)
133 polygon
.append (mapped
);
134 SAL_INFO ("drawinglayer", "polygon append point: " << pPoints
[i
*2] << "," << pPoints
[i
*2 + 1] << " mapped: " << mapped
.getX () << ":" << mapped
.getY ());
138 polygon
.setPrevControlPoint (p
, prev
);
139 SAL_INFO ("drawinglayer", "polygon append prev: " << p
<< " mapped: " << prev
.getX () << "," << prev
.getY ());
145 if (pPointTypes
&& (pPointTypes
[i
] & 0x80))
148 polygon
.setClosed (true);
149 aPolygon
.append (polygon
);
150 SAL_INFO ("drawinglayer", "close polygon");
157 // Draw an extra line between the last point and the first point, to close the shape.
158 if (bAddLineToCloseShape
)
160 polygon
.setClosed (true);
163 if (polygon
.count ())
165 aPolygon
.append (polygon
);
167 #if OSL_DEBUG_LEVEL > 1
168 for (unsigned int i
=0; i
<aPolygon
.count(); i
++) {
169 polygon
= aPolygon
.getB2DPolygon(i
);
170 SAL_INFO ("drawinglayer", "polygon: " << i
);
171 for (unsigned int j
=0; j
<polygon
.count(); j
++) {
172 ::basegfx::B2DPoint point
= polygon
.getB2DPoint(j
);
173 SAL_INFO ("drawinglayer", "point: " << point
.getX() << "," << point
.getY());
174 if (polygon
.isPrevControlPointUsed(j
)) {
175 point
= polygon
.getPrevControlPoint(j
);
176 SAL_INFO ("drawinglayer", "prev: " << point
.getX() << "," << point
.getY());
178 if (polygon
.isNextControlPointUsed(j
)) {
179 point
= polygon
.getNextControlPoint(j
);
180 SAL_INFO ("drawinglayer", "next: " << point
.getX() << "," << point
.getY());
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */