vfs: check userland buffers before reading them.
[haiku.git] / headers / private / interface / ShapePrivate.h
blob31e201e2d5f45c861adece3972eb3ed56ba4e253
1 /*
2 * Copyright 2003-2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 * Adrian Oanca, adioanca@cotty.iren.ro
8 */
9 #ifndef SHAPE_PRIVATE_H
10 #define SHAPE_PRIVATE_H
12 #include <Point.h>
13 #include <Rect.h>
14 #include <Referenceable.h>
16 #include <string.h>
17 #include <stdio.h>
20 #define OP_LINETO 0x10000000
21 #define OP_BEZIERTO 0x20000000
22 #define OP_CLOSE 0x40000000
23 #define OP_MOVETO 0x80000000
24 #define OP_LARGE_ARC_TO_CW 0x01000000
25 #define OP_LARGE_ARC_TO_CCW 0x02000000
26 #define OP_SMALL_ARC_TO_CW 0x04000000
27 #define OP_SMALL_ARC_TO_CCW 0x08000000
30 struct shape_data : public BReferenceable {
31 uint32* opList;
32 BPoint* ptList;
33 int32 opCount;
34 int32 opSize;
35 int32 ptCount;
36 int32 ptSize;
38 bool fOwnsMemory;
40 shape_data()
42 fOwnsMemory(false)
46 ~shape_data()
48 if (fOwnsMemory) {
49 delete[] opList;
50 delete[] ptList;
54 shape_data(const shape_data& other)
56 opList = new(std::nothrow) uint32[other.opCount];
57 ptList = new(std::nothrow) BPoint[other.ptCount];
58 fOwnsMemory = true;
59 opCount = other.opCount;
60 opSize = other.opSize;
61 ptCount = other.ptCount;
62 ptSize = other.ptSize;
63 memcpy(opList, other.opList, opSize);
64 memcpy(ptList, other.ptList, ptSize);
67 BRect DetermineBoundingBox() const
69 BRect bounds;
71 if (ptCount == 0)
72 return bounds;
74 // TODO: This implementation doesn't take into account curves at all.
75 bounds.left = ptList[0].x;
76 bounds.top = ptList[0].y;
77 bounds.right = ptList[0].x;
78 bounds.bottom = ptList[0].y;
80 for (int32 i = 1; i < ptCount; i++) {
81 if (bounds.left > ptList[i].x)
82 bounds.left = ptList[i].x;
84 if (bounds.top > ptList[i].y)
85 bounds.top = ptList[i].y;
87 if (bounds.right < ptList[i].x)
88 bounds.right = ptList[i].x;
90 if (bounds.bottom < ptList[i].y)
91 bounds.bottom = ptList[i].y;
94 return bounds;
99 #endif // SHAPE_PRIVATE_H