calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / tools / emfpregion.cxx
blob9fcced337733e73f7303fc4594a9a90750c96bd9
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 <basegfx/point/b2dpoint.hxx>
21 #include <basegfx/range/b2drectangle.hxx>
22 #include <basegfx/polygon/b2dpolygon.hxx>
23 #include <basegfx/polygon/b2dpolygontools.hxx>
24 #include <basegfx/polygon/b2dpolypolygon.hxx>
25 #include <sal/log.hxx>
26 #include "emfpregion.hxx"
27 #include "emfppath.hxx"
29 namespace emfplushelper
31 EMFPRegion::EMFPRegion()
35 EMFPRegion::~EMFPRegion()
39 ::basegfx::B2DPolyPolygon EMFPRegion::ReadRegionNode(SvStream& s, EmfPlusHelperData& rR)
41 // Regions are specified as a binary tree of region nodes, and each node must either be a terminal node
42 // (RegionNodeDataTypeRect, RegionNodeDataTypePath, RegionNodeDataTypeEmpty, RegionNodeDataTypeInfinite)
43 // or specify one or two child nodes
44 // (RegionNodeDataTypeAnd, RegionNodeDataTypeOr, RegionNodeDataTypeXor,
45 // RegionNodeDataTypeExclude, RegionNodeDataTypeComplement).
46 sal_uInt32 dataType;
47 ::basegfx::B2DPolyPolygon polygon;
48 s.ReadUInt32(dataType);
49 SAL_INFO("drawinglayer.emf", "EMF+\t Region node data type 0x" << std::hex << dataType << std::dec);
51 switch (dataType)
53 case RegionNodeDataTypeAnd: // CombineModeIntersect
54 case RegionNodeDataTypeOr: // CombineModeUnion
55 case RegionNodeDataTypeXor: // CombineModeXOR
56 case RegionNodeDataTypeExclude: // CombineModeExclude
57 case RegionNodeDataTypeComplement: // CombineModeComplement
59 ::basegfx::B2DPolyPolygon leftPolygon = ReadRegionNode(s, rR);
60 ::basegfx::B2DPolyPolygon rightPolygon = ReadRegionNode(s, rR);
61 polygon = EmfPlusHelperData::combineClip(leftPolygon, dataType, rightPolygon);
62 break;
64 case RegionNodeDataTypeRect:
66 float dx, dy, dw, dh;
67 s.ReadFloat(dx).ReadFloat(dy).ReadFloat(dw).ReadFloat(dh);
68 SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeRect x:" << dx << ", y:" << dy <<
69 ", width:" << dw << ", height:" << dh);
71 const ::basegfx::B2DPoint mappedStartPoint(rR.Map(dx, dy));
72 const ::basegfx::B2DPoint mappedEndPoint(rR.Map(dx + dw, dy + dh));
73 polygon = ::basegfx::B2DPolyPolygon(
74 ::basegfx::utils::createPolygonFromRect(
75 ::basegfx::B2DRectangle(
76 mappedStartPoint.getX(),
77 mappedStartPoint.getY(),
78 mappedEndPoint.getX(),
79 mappedEndPoint.getY())));
80 break;
82 case RegionNodeDataTypePath:
84 sal_Int32 pathLength;
85 s.ReadInt32(pathLength);
86 SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypePath, Path Length: " << pathLength << " bytes");
88 sal_uInt32 header, pathFlags;
89 sal_Int32 points;
91 s.ReadUInt32(header).ReadInt32(points).ReadUInt32(pathFlags);
92 SAL_INFO("drawinglayer.emf", "EMF+\t\t header: 0x" << std::hex << header <<
93 " points: " << std::dec << points << " additional flags: 0x" << std::hex << pathFlags << std::dec);
95 EMFPPath path(points);
96 path.Read(s, pathFlags);
97 polygon = path.GetPolygon(rR);
98 break;
100 case RegionNodeDataTypeEmpty:
102 SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeEmpty");
103 SAL_WARN("drawinglayer.emf", "EMF+\t\t TODO we need to set empty polygon here");
104 polygon = ::basegfx::B2DPolyPolygon();
106 break;
108 case RegionNodeDataTypeInfinite:
110 SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeInfinite");
111 polygon = ::basegfx::B2DPolyPolygon();
112 break;
114 default:
116 SAL_WARN("drawinglayer.emf", "EMF+\t\t Unhandled region type: 0x" << std::hex << dataType << std::dec);
117 polygon = ::basegfx::B2DPolyPolygon();
120 return polygon;
123 void EMFPRegion::ReadRegion(SvStream& s, EmfPlusHelperData& rR)
125 sal_uInt32 header, count;
126 s.ReadUInt32(header).ReadUInt32(count);
127 // An array should be RegionNodeCount+1 of EmfPlusRegionNode objects.
128 SAL_INFO("drawinglayer.emf", "EMF+\t version: 0x" << std::hex << header << std::dec << ", region node count: " << count);
130 regionPolyPolygon = ReadRegionNode(s, rR);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */