LibreOffice Module drawinglayer (master) 1
emfpregion.cxx
Go to the documentation of this file.
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
25#include <sal/log.hxx>
26#include "emfpregion.hxx"
27#include "emfppath.hxx"
28
29namespace emfplushelper
30{
32 {
33 }
34
36 {
37 }
38
40 {
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;
48 s.ReadUInt32(dataType);
49 SAL_INFO("drawinglayer.emf", "EMF+\t Region node data type 0x" << std::hex << dataType << std::dec);
50
51 switch (dataType)
52 {
53 case RegionNodeDataTypeAnd: // CombineModeIntersect
54 case RegionNodeDataTypeOr: // CombineModeUnion
55 case RegionNodeDataTypeXor: // CombineModeXOR
56 case RegionNodeDataTypeExclude: // CombineModeExclude
57 case RegionNodeDataTypeComplement: // CombineModeComplement
58 {
59 ::basegfx::B2DPolyPolygon leftPolygon = ReadRegionNode(s, rR);
60 ::basegfx::B2DPolyPolygon rightPolygon = ReadRegionNode(s, rR);
61 polygon = EmfPlusHelperData::combineClip(leftPolygon, dataType, rightPolygon);
62 break;
63 }
65 {
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);
70
71 const ::basegfx::B2DPoint mappedStartPoint(rR.Map(dx, dy));
72 const ::basegfx::B2DPoint mappedEndPoint(rR.Map(dx + dw, dy + dh));
74 ::basegfx::utils::createPolygonFromRect(
76 mappedStartPoint.getX(),
77 mappedStartPoint.getY(),
78 mappedEndPoint.getX(),
79 mappedEndPoint.getY())));
80 break;
81 }
83 {
84 sal_Int32 pathLength;
85 s.ReadInt32(pathLength);
86 SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypePath, Path Length: " << pathLength << " bytes");
87
88 sal_uInt32 header, pathFlags;
89 sal_Int32 points;
90
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);
94
95 EMFPPath path(points);
96 path.Read(s, pathFlags);
97 polygon = path.GetPolygon(rR);
98 break;
99 }
101 {
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();
105
106 break;
107 }
109 {
110 SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeInfinite");
111 polygon = ::basegfx::B2DPolyPolygon();
112 break;
113 }
114 default:
115 {
116 SAL_WARN("drawinglayer.emf", "EMF+\t\t Unhandled region type: 0x" << std::hex << dataType << std::dec);
117 polygon = ::basegfx::B2DPolyPolygon();
118 }
119 }
120 return polygon;
121 }
122
124 {
125 sal_uInt32 header, 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);
129
131 }
132}
133
134/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_Int8 header[]
SvStream & ReadFloat(float &rFloat)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SvStream & ReadInt32(sal_Int32 &rInt32)
::basegfx::B2DPolyPolygon & GetPolygon(EmfPlusHelperData const &rR, bool bMapIt=true, bool bAddLineToCloseShape=false)
Definition: emfppath.cxx:132
void Read(SvStream &s, sal_uInt32 pathFlags)
Definition: emfppath.cxx:84
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
@ RegionNodeDataTypePath
Definition: emfpregion.hxx:34
@ RegionNodeDataTypeEmpty
Definition: emfpregion.hxx:35
@ RegionNodeDataTypeRect
Definition: emfpregion.hxx:33
@ RegionNodeDataTypeComplement
Definition: emfpregion.hxx:32
@ RegionNodeDataTypeInfinite
Definition: emfpregion.hxx:36
@ RegionNodeDataTypeExclude
Definition: emfpregion.hxx:31
::basegfx::B2DPolyPolygon regionPolyPolygon
Definition: emfpregion.hxx:41
virtual ~EMFPRegion() override
Definition: emfpregion.cxx:35
void ReadRegion(SvStream &s, EmfPlusHelperData &rR)
Definition: emfpregion.cxx:123
::basegfx::B2DPolyPolygon ReadRegionNode(SvStream &s, EmfPlusHelperData &rR)
Definition: emfpregion.cxx:39
::basegfx::B2DPoint Map(double ix, double iy) const
::basegfx::B2DPolyPolygon combineClip(::basegfx::B2DPolyPolygon const &leftPolygon, int combineMode, ::basegfx::B2DPolyPolygon const &rightPolygon)