[CMAKE]
[reactos.git] / subsystems / win32 / win32k / include / gdifloat.h
1 #pragma once
2
3 #include <reactos/win32k/ntgdityp.h>
4 #include <reactos/win32k/ntgdihdl.h>
5 #include "dc.h"
6 #include "math.h"
7 #include <ft2build.h>
8 #include FT_FREETYPE_H
9
10 typedef struct tagFLOAT_POINT
11 {
12 FLOAT x, y;
13 } FLOAT_POINT;
14
15 /* Rounds a floating point number to integer. The world-to-viewport
16 * transformation process is done in floating point internally. This function
17 * is then used to round these coordinates to integer values.
18 */
19 static __inline INT GDI_ROUND(FLOAT val)
20 {
21 return (int)floor(val + 0.5);
22 }
23
24
25 /* FIXME: Do not use the fpu in kernel on x86, use FLOATOBJ_Xxx api instead
26 * Performs a world-to-viewport transformation on the specified point (which
27 * is in floating point format).
28 */
29 static __inline void INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
30 {
31 FLOAT x, y;
32 XFORM xformWorld2Vport;
33
34 MatrixS2XForm(&xformWorld2Vport, &dc->dclevel.mxWorldToDevice);
35
36 /* Perform the transformation */
37 x = point->x;
38 y = point->y;
39 point->x = x * xformWorld2Vport.eM11 +
40 y * xformWorld2Vport.eM21 +
41 xformWorld2Vport.eDx;
42
43 point->y = x * xformWorld2Vport.eM12 +
44 y * xformWorld2Vport.eM22 +
45 xformWorld2Vport.eDy;
46 }
47
48 /* Performs a viewport-to-world transformation on the specified point (which
49 * is in integer format). Returns TRUE if successful, else FALSE.
50 */
51 #if 0
52 static __inline BOOL INTERNAL_DPTOLP(DC *dc, LPPOINT point)
53 {
54 FLOAT_POINT floatPoint;
55
56 /* Perform operation with floating point */
57 floatPoint.x=(FLOAT)point->x;
58 floatPoint.y=(FLOAT)point->y;
59 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
60 return FALSE;
61
62 /* Round to integers */
63 point->x = GDI_ROUND(floatPoint.x);
64 point->y = GDI_ROUND(floatPoint.y);
65
66 return TRUE;
67 }
68
69 /* Performs a world-to-viewport transformation on the specified point (which
70 * is in integer format).
71 */
72 static __inline void INTERNAL_LPTODP(DC *dc, LPPOINT point)
73 {
74 FLOAT_POINT floatPoint;
75
76 /* Perform operation with floating point */
77 floatPoint.x=(FLOAT)point->x;
78 floatPoint.y=(FLOAT)point->y;
79 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
80
81 /* Round to integers */
82 point->x = GDI_ROUND(floatPoint.x);
83 point->y = GDI_ROUND(floatPoint.y);
84 }
85
86 #endif
87
88 #define MulDiv( x, y, z ) EngMulDiv( x, y, z )
89
90 #define XDPTOLP(pdcattr,tx) \
91 (MulDiv(((tx)-(pdcattr)->ptlViewportOrg.x), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx) + (pdcattr)->ptlWindowOrg.x)
92 #define YDPTOLP(pdcattr,ty) \
93 (MulDiv(((ty)-(pdcattr)->ptlViewportOrg.y), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy) + (pdcattr)->ptlWindowOrg.y)
94 #define XLPTODP(pdcattr,tx) \
95 (MulDiv(((tx)-(pdcattr)->ptlWindowOrg.x), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx) + (pdcattr)->ptlViewportOrg.x)
96 #define YLPTODP(pdcattr,ty) \
97 (MulDiv(((ty)-(pdcattr)->ptlWindowOrg.y), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy) + (pdcattr)->ptlViewportOrg.y)
98
99 /* Device <-> logical size conversion */
100
101 #define XDSTOLS(pdcattr,tx) \
102 MulDiv((tx), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx)
103 #define YDSTOLS(DC_Attr,ty) \
104 MulDiv((ty), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy)
105 #define XLSTODS(pdcattr,tx) \
106 MulDiv((tx), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx)
107 #define YLSTODS(pdcattr,ty) \
108 MulDiv((ty), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy)