-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgdiplustypes.py
More file actions
509 lines (427 loc) · 18.3 KB
/
Copy pathgdiplustypes.py
File metadata and controls
509 lines (427 loc) · 18.3 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
"""
/**************************************************************************\
*
* Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
*
* Module Name:
*
* GdiplusTypes.h
*
* Abstract:
*
* GDI+ Types
*
\**************************************************************************/
"""
from . import cpreproc
from .minwindef import *
from typing import Self
if cpreproc.pragma_once("_GDIPLUSTYPES_H"):
from .gdiplusenums import EmfPlusRecordType
# REGION *** Desktop Family ***
#--------------------------------------------------------------------------
# Callback functions
#--------------------------------------------------------------------------
ImageAbort = CALLBACK(BOOL, PVOID)
DrawImageAbort = ImageAbort
GetThumbnailImageAbort = ImageAbort
# Callback for EnumerateMetafile methods. The parameters are:
# recordType WMF, EMF, or EMF+ record type
# flags (always 0 for WMF/EMF records)
# dataSize size of the record data (in bytes), or 0 if no data
# data pointer to the record data, or NULL if no data
# callbackData pointer to callbackData, if any
# This method can then call Metafile::PlayRecord to play the
# record that was just enumerated. If this method returns
# FALSE, the enumeration process is aborted. Otherwise, it continues.
EnumerateMetafileProc = CALLBACK(BOOL, EmfPlusRecordType, UINT, UINT, PBYTE, PVOID)
# This is the main GDI+ Abort interface
class GdiplusAbort(CStructure):
_pack_ = 8
_fields_ = [
("Abort", WINFUNCTYPE(HRESULT))
]
#--------------------------------------------------------------------------
# Primitive data types
#
# NOTE:
# Types already defined in standard header files:
# INT8
# UINT8
# INT16
# UINT16
# INT32
# UINT32
# INT64
# UINT64
#
# Avoid using the following types:
# LONG - use INT
# ULONG - use UINT
# DWORD - use UINT32
#--------------------------------------------------------------------------
from .ucrt.float import *
REAL = FLOAT
REAL_MAX = FLT_MAX
REAL_MIN = FLT_MIN
REAL_TOLERANCE = (FLT_MIN * 100)
REAL_EPSILON = 1.192092896e-07 # FLT_EPSILON
#--------------------------------------------------------------------------
# Status return values from GDI+ methods
#--------------------------------------------------------------------------
Status = INT
if True:
Ok = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTrueTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
ProfileNotFound = 21
#--------------------------------------------------------------------------
# Represents a dimension in a 2D coordinate system (floating-point coordinates)
#--------------------------------------------------------------------------
class SizeF:
Width: float
Height: float
def __init__(self, varying_type: float | Self = 0.0, height=0.0):
if isinstance(varying_type, self.__class__):
self.Width = varying_type.Width
self.Height = varying_type.Height
else:
self.Width = varying_type
self.Height = height
def __add__(self, sz: Self) -> Self:
return self.__class__(self.Width + sz.Width,
self.Height + sz.Height)
def __sub__(self, sz: Self) -> Self:
return self.__class__(self.Width - sz.Width,
self.Height - sz.Height)
def __eq__(self, sz: Self) -> bool:
return (self.Width == sz.Width) and (self.Height == sz.Height)
def __bool__(self) -> bool:
return (self.Width == 0.0 and self.Height == 0.0)
#--------------------------------------------------------------------------
# Represents a dimension in a 2D coordinate system (integer coordinates)
#--------------------------------------------------------------------------
class Size():
Width: int
Height: int
def __init__(self, varying_type: int | Self = 0, height=0):
if isinstance(varying_type, self.__class__):
self.Width = varying_type.Width
self.Height = varying_type.Height
else:
self.Width = varying_type
self.Height = height
def __add__(self, sz: Self) -> Self:
return self.__class__(self.Width + sz.Width,
self.Height + sz.Height)
def __sub__(self, sz: Self) -> Self:
return self.__class__(self.Width - sz.Width,
self.Height - sz.Height)
def __eq__(self, sz: Self) -> bool:
return (self.Width == sz.Width) and (self.Height == sz.Height)
def __bool__(self) -> bool:
return (self.Width == 0 and self.Height == 0)
#--------------------------------------------------------------------------
# Represents a location in a 2D coordinate system (floating-point coordinates)
#--------------------------------------------------------------------------
class PointF(CStructure):
_pack_ = 8
_fields_ = [
("X", FLOAT),
("Y", FLOAT)
]
X: float
Y: float
def __init__(self, varying_type: float | Self | SizeF = 0.0, y: float = 0.0):
if isinstance(varying_type, self.__class__):
self.X = varying_type.X
self.Y = varying_type.Y
elif isinstance(varying_type, SizeF):
self.X = varying_type.Width
self.Y = varying_type.Height
else:
self.X = varying_type
self.Y = y
def __add__(self, point: Self) -> Self:
return self.__class__(self.X + point.X,
self.Y + point.Y)
def __sub__(self, point: Self) -> Self:
return self.__class__(self.X - point.X,
self.Y - point.Y)
def __eq__(self, point: Self) -> bool:
return (self.X == point.X) and (self.Y == point.Y)
#--------------------------------------------------------------------------
# Represents a location in a 2D coordinate system (integer coordinates)
#--------------------------------------------------------------------------
class Point(CStructure):
_fields_ = [
('X', INT),
('Y', INT)
]
X: int
Y: int
def __init__(self, varying_type: int | Self | Size = 0, y: float = 0):
if isinstance(varying_type, self.__class__):
self.X = varying_type.X
self.Y = varying_type.Y
elif isinstance(varying_type, Size):
self.X = varying_type.Width
self.Y = varying_type.Height
else:
self.X = varying_type
self.Y = y
def __add__(self, point: Self) -> Self:
return self.__class__(self.X + point.X,
self.Y + point.Y)
def __sub__(self, point: Self) -> Self:
return self.__class__(self.X - point.X,
self.Y - point.Y)
def __eq__(self, point: Self) -> bool:
return (self.X == point.X) and (self.Y == point.Y)
#--------------------------------------------------------------------------
# Represents a rectangle in a 2D coordinate system (floating-point coordinates)
#--------------------------------------------------------------------------
class RectF(CStructure):
_fields_ = [
('X', FLOAT),
('Y', FLOAT),
('Width', FLOAT),
('Height', FLOAT)
]
X: float
Y: float
Width: float
Height: float
def __init__(self, varying_type1: float | PointF = 0.0, varying_type2: float | SizeF = 0.0, width: float = 0.0, height: float = 0.0):
if isinstance(varying_type1, PointF):
self.X = varying_type1.X
self.Y = varying_type1.Y
if isinstance(varying_type2, SizeF):
self.Width = varying_type2.Width
self.Height = varying_type2.Height
else:
self.Width = width
self.Height = height
else:
self.X = varying_type1
self.Y = varying_type2
self.Width = width
self.Height = height
def Clone(self) -> Self:
return self.__class__(self.X, self.Y, self.Width, self.Height)
def GetLocation(self, point: PointF) -> None:
point.X = self.X
point.Y = self.Y
def GetSize(self, size: SizeF) -> None:
size.Width = self.Width
size.Height = self.Height
def GetBounds(self, rect: Self) -> None:
rect.X = self.X
rect.Y = self.Y
rect.Width = self.Width
rect.Height = self.Height
def GetLeft(self) -> float:
return self.X
def GetTop(self) -> float:
return self.Y
def GetRight(self) -> float:
return self.X + self.Width
def GetBottom(self) -> float:
return self.Y + self.Height
def IsEmptyArea(self) -> bool:
return (self.Width <= REAL_EPSILON) or (self.Height <= REAL_EPSILON)
def __eq__(self, rect: Self) -> bool:
return (self.X == rect.X ) and (
self.Y == rect.Y ) and (
self.Width == rect.Width ) and (
self.Height == rect.Height)
def Contains(self, varying_type: float | PointF | Self, y: float = 0.0) -> bool:
if isinstance(varying_type, PointF):
return self.Contains(varying_type.X, varying_type.Y)
elif isinstance(varying_type, self.__class__):
return (self.X <= varying_type.X) and (varying_type.GetRight() <= self.GetRight() ) and (
(self.Y <= varying_type.Y) and (varying_type.GetBottom() <= self.GetBottom()) )
else:
return varying_type >= self.X and varying_type < self.X + self.Width and (
y >= self.Y and y < self.Y + self.Height )
def Inflate(self, varying_type: float | PointF | Self, dy: float = 0.0) -> None:
if isinstance(varying_type, PointF):
self.Inflate(varying_type.X, varying_type.Y)
else:
self.X -= varying_type
self.Y -= dy
self.Width += 2 * varying_type
self.Height += 2 * dy
def Intersect(self, c: Self, a: Self = None, b: Self = None) -> bool:
if not a:
return self.Intersect(self, self, c)
right = min(a.GetRight(), b.GetRight())
bottom = min(a.GetBottom(), b.GetBottom())
left = max(a.GetLeft(), b.GetLeft())
top = max(a.GetTop(), b.GetTop())
c.X = left
c.Y = top
c.Width = right - left
c.Height = bottom - top
return not c.IsEmptyArea()
def IntersectsWith(self, rect: Self) -> bool:
return (self.GetLeft() < rect.GetRight() and
self.GetTop() < rect.GetBottom() and
self.GetRight() > rect.GetLeft() and
self.GetBottom() > rect.GetTop() )
def Union(self, c: Self, a: Self, b: Self) -> bool:
right = max(a.GetRight(), b.GetRight())
bottom = max(a.GetBottom(), b.GetBottom())
left = min(a.GetLeft(), b.GetLeft())
top = min(a.GetTop(), b.GetTop())
c.X = left
c.Y = top
c.Width = right - left
c.Height = bottom - top
return not c.IsEmptyArea()
def Offset(self, varying_type: float | PointF, dy: float = 0.0) -> None:
if isinstance(varying_type, PointF):
return self.Offset(varying_type.X, varying_type.Y)
self.X += varying_type
self.Y += dy
#--------------------------------------------------------------------------
# Represents a rectangle in a 2D coordinate system (integer coordinates)
#--------------------------------------------------------------------------
class Rect(CStructure):
_fields_ = [
('X', INT),
('Y', INT),
('Width', INT),
('Height', INT)
]
X: int
Y: int
Width: int
Height: int
def __init__(self, varying_type1: int | Point = 0, varying_type2: int | Size = 0, width: int = 0, height: int = 0):
if isinstance(varying_type1, Point):
self.X = varying_type1.X
self.Y = varying_type1.Y
if isinstance(varying_type2, Size):
self.Width = varying_type2.Width
self.Height = varying_type2.Height
else:
self.Width = width
self.Height = height
else:
self.X = varying_type1
self.Y = varying_type2
self.Width = width
self.Height = height
def Clone(self) -> Self:
return self.__class__(self.X, self.Y, self.Width, self.Height)
def GetLocation(self, point: Point) -> None:
point.X = self.X
point.Y = self.Y
def GetSize(self, size: Size) -> None:
size.Width = self.Width
size.Height = self.Height
def GetBounds(self, rect: Self) -> None:
rect.X = self.X
rect.Y = self.Y
rect.Width = self.Width
rect.Height = self.Height
def GetLeft(self) -> int:
return self.X
def GetTop(self) -> int:
return self.Y
def GetRight(self) -> int:
return self.X + self.Width
def GetBottom(self) -> int:
return self.Y + self.Height
def IsEmptyArea(self) -> bool:
return (self.Width <= 0) or (self.Height <= 0)
def __eq__(self, rect: Self) -> bool:
return (self.X == rect.X ) and (
self.Y == rect.Y ) and (
self.Width == rect.Width ) and (
self.Height == rect.Height)
def Contains(self, varying_type: int | Point | Self, y: int = 0) -> bool:
if isinstance(varying_type, Point):
return self.Contains(varying_type.X, varying_type.Y)
elif isinstance(varying_type, self.__class__):
return (self.X <= varying_type.X) and (varying_type.GetRight() <= self.GetRight() ) and (
(self.Y <= varying_type.Y) and (varying_type.GetBottom() <= self.GetBottom()) )
else:
return varying_type >= self.X and varying_type < self.X + self.Width and (
y >= self.Y and y < self.Y + self.Height )
def Inflate(self, varying_type: int | Point | Self, dy: int = 0) -> None:
if isinstance(varying_type, Point):
self.iInflate(varying_type.X, varying_type.Y)
else:
self.X -= varying_type
self.Y -= dy
self.Width += 2 * varying_type
self.Height += 2 * dy
def Intersect(self, c: Self, a: Self = None, b: Self = None) -> bool:
if not a:
return self.Intersect(self, self, c)
right = min(a.GetRight(), b.GetRight())
bottom = min(a.GetBottom(), b.GetBottom())
left = max(a.GetLeft(), b.GetLeft())
top = max(a.GetTop(), b.GetTop())
c.X = left
c.Y = top
c.Width = right - left
c.Height = bottom - top
return not c.IsEmptyArea()
def IntersectsWith(self, rect: Self) -> bool:
return (self.GetLeft() < rect.GetRight() and
self.GetTop() < rect.GetBottom() and
self.GetRight() > rect.GetLeft() and
self.GetBottom() > rect.GetTop() )
def Union(self, c: Self, a: Self, b: Self) -> bool:
right = max(a.GetRight(), b.GetRight())
bottom = max(a.GetBottom(), b.GetBottom())
left = min(a.GetLeft(), b.GetLeft())
top = min(a.GetTop(), b.GetTop())
c.X = left
c.Y = top
c.Width = right - left
c.Height = bottom - top
return not c.IsEmptyArea()
def Offset(self, varying_type: int | Point, dy: int = 0) -> None:
if isinstance(varying_type, Point):
return self.Offset(varying_type.X, varying_type.Y)
self.X += varying_type
self.Y += dy
class PathData:
def __init__(self):
self.count = 0
self.Points = NULL
self.Types = NULL
def __invert__(self):
if self.Points:
memset(cast(self.Points, PVOID), 0, sizeof(PointF))
if self.Types:
memset(cast(self.Types, PVOID), 0, sizeof(BYTE))
class CharacterRange:
def __init__(self, first = 0, length = 0):
self.First = first
self.Length = length
def toclass(self, rhs):
self.First = rhs.First
self.Length = rhs.Length