1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <sal/log.hxx>
#include "emfpregion.hxx"
#include "emfppath.hxx"
namespace emfplushelper
{
EMFPRegion::EMFPRegion()
{
}
EMFPRegion::~EMFPRegion()
{
}
::basegfx::B2DPolyPolygon EMFPRegion::ReadRegionNode(SvStream& s, EmfPlusHelperData& rR)
{
// Regions are specified as a binary tree of region nodes, and each node must either be a terminal node
// (RegionNodeDataTypeRect, RegionNodeDataTypePath, RegionNodeDataTypeEmpty, RegionNodeDataTypeInfinite)
// or specify one or two child nodes
// (RegionNodeDataTypeAnd, RegionNodeDataTypeOr, RegionNodeDataTypeXor,
// RegionNodeDataTypeExclude, RegionNodeDataTypeComplement).
sal_uInt32 dataType;
::basegfx::B2DPolyPolygon polygon;
s.ReadUInt32(dataType);
SAL_INFO("drawinglayer.emf", "EMF+\t Region node data type 0x" << std::hex << dataType << std::dec);
switch (dataType)
{
case RegionNodeDataTypeAnd: // CombineModeIntersect
case RegionNodeDataTypeOr: // CombineModeUnion
case RegionNodeDataTypeXor: // CombineModeXOR
case RegionNodeDataTypeExclude: // CombineModeExclude
case RegionNodeDataTypeComplement: // CombineModeComplement
{
::basegfx::B2DPolyPolygon leftPolygon = ReadRegionNode(s, rR);
::basegfx::B2DPolyPolygon rightPolygon = ReadRegionNode(s, rR);
polygon = EmfPlusHelperData::combineClip(leftPolygon, dataType, rightPolygon);
break;
}
case RegionNodeDataTypeRect:
{
float dx, dy, dw, dh;
s.ReadFloat(dx).ReadFloat(dy).ReadFloat(dw).ReadFloat(dh);
SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeRect x:" << dx << ", y:" << dy <<
", width:" << dw << ", height:" << dh);
const ::basegfx::B2DPoint mappedStartPoint(rR.Map(dx, dy));
const ::basegfx::B2DPoint mappedEndPoint(rR.Map(dx + dw, dy + dh));
polygon = ::basegfx::B2DPolyPolygon(
::basegfx::utils::createPolygonFromRect(
::basegfx::B2DRectangle(
mappedStartPoint.getX(),
mappedStartPoint.getY(),
mappedEndPoint.getX(),
mappedEndPoint.getY())));
break;
}
case RegionNodeDataTypePath:
{
sal_Int32 pathLength;
s.ReadInt32(pathLength);
SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypePath, Path Length: " << pathLength << " bytes");
sal_uInt32 header, pathFlags;
sal_Int32 points;
s.ReadUInt32(header).ReadInt32(points).ReadUInt32(pathFlags);
SAL_INFO("drawinglayer.emf", "EMF+\t\t header: 0x" << std::hex << header <<
" points: " << std::dec << points << " additional flags: 0x" << std::hex << pathFlags << std::dec);
EMFPPath path(points);
path.Read(s, pathFlags);
polygon = path.GetPolygon(rR);
break;
}
case RegionNodeDataTypeEmpty:
{
SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeEmpty");
SAL_WARN("drawinglayer.emf", "EMF+\t\t TODO we need to set empty polygon here");
polygon = ::basegfx::B2DPolyPolygon();
break;
}
case RegionNodeDataTypeInfinite:
{
SAL_INFO("drawinglayer.emf", "EMF+\t\t RegionNodeDataTypeInfinite");
polygon = ::basegfx::B2DPolyPolygon();
break;
}
default:
{
SAL_WARN("drawinglayer.emf", "EMF+\t\t Unhandled region type: 0x" << std::hex << dataType << std::dec);
polygon = ::basegfx::B2DPolyPolygon();
}
}
return polygon;
}
void EMFPRegion::ReadRegion(SvStream& s, EmfPlusHelperData& rR)
{
sal_uInt32 header, count;
s.ReadUInt32(header).ReadUInt32(count);
// An array should be RegionNodeCount+1 of EmfPlusRegionNode objects.
SAL_INFO("drawinglayer.emf", "EMF+\t version: 0x" << std::hex << header << std::dec << ", region node count: " << count);
regionPolyPolygon = ReadRegionNode(s, rR);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|