2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "gdi_private.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
32 /***********************************************************************
33 * MAPPING_FixIsotropic
35 * Fix viewport extensions for isotropic mode.
37 static void MAPPING_FixIsotropic( DC
* dc
)
39 double xdim
= fabs((double)dc
->vportExtX
* dc
->virtual_size
.cx
/
40 (dc
->virtual_res
.cx
* dc
->wndExtX
));
41 double ydim
= fabs((double)dc
->vportExtY
* dc
->virtual_size
.cy
/
42 (dc
->virtual_res
.cy
* dc
->wndExtY
));
46 INT mincx
= (dc
->vportExtX
>= 0) ? 1 : -1;
47 dc
->vportExtX
= floor(dc
->vportExtX
* ydim
/ xdim
+ 0.5);
48 if (!dc
->vportExtX
) dc
->vportExtX
= mincx
;
52 INT mincy
= (dc
->vportExtY
>= 0) ? 1 : -1;
53 dc
->vportExtY
= floor(dc
->vportExtY
* xdim
/ ydim
+ 0.5);
54 if (!dc
->vportExtY
) dc
->vportExtY
= mincy
;
59 /***********************************************************************
60 * null driver fallback implementations
63 BOOL
nulldrv_OffsetViewportOrgEx( PHYSDEV dev
, INT x
, INT y
, POINT
*pt
)
65 DC
*dc
= get_nulldrv_dc( dev
);
69 pt
->x
= dc
->vportOrgX
;
70 pt
->y
= dc
->vportOrgY
;
74 DC_UpdateXforms( dc
);
78 BOOL
nulldrv_OffsetWindowOrgEx( PHYSDEV dev
, INT x
, INT y
, POINT
*pt
)
80 DC
*dc
= get_nulldrv_dc( dev
);
89 DC_UpdateXforms( dc
);
93 BOOL
nulldrv_ScaleViewportExtEx( PHYSDEV dev
, INT x_num
, INT x_denom
, INT y_num
, INT y_denom
, SIZE
*size
)
95 DC
*dc
= get_nulldrv_dc( dev
);
99 size
->cx
= dc
->vportExtX
;
100 size
->cy
= dc
->vportExtY
;
102 if (dc
->MapMode
!= MM_ISOTROPIC
&& dc
->MapMode
!= MM_ANISOTROPIC
) return TRUE
;
103 if (!x_num
|| !x_denom
|| !y_num
|| !y_denom
) return FALSE
;
105 dc
->vportExtX
= (dc
->vportExtX
* x_num
) / x_denom
;
106 dc
->vportExtY
= (dc
->vportExtY
* y_num
) / y_denom
;
107 if (dc
->vportExtX
== 0) dc
->vportExtX
= 1;
108 if (dc
->vportExtY
== 0) dc
->vportExtY
= 1;
109 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
110 DC_UpdateXforms( dc
);
114 BOOL
nulldrv_ScaleWindowExtEx( PHYSDEV dev
, INT x_num
, INT x_denom
, INT y_num
, INT y_denom
, SIZE
*size
)
116 DC
*dc
= get_nulldrv_dc( dev
);
120 size
->cx
= dc
->wndExtX
;
121 size
->cy
= dc
->wndExtY
;
123 if (dc
->MapMode
!= MM_ISOTROPIC
&& dc
->MapMode
!= MM_ANISOTROPIC
) return TRUE
;
124 if (!x_num
|| !x_denom
|| !y_num
|| !y_denom
) return FALSE
;
126 dc
->wndExtX
= (dc
->wndExtX
* x_num
) / x_denom
;
127 dc
->wndExtY
= (dc
->wndExtY
* y_num
) / y_denom
;
128 if (dc
->wndExtX
== 0) dc
->wndExtX
= 1;
129 if (dc
->wndExtY
== 0) dc
->wndExtY
= 1;
130 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
131 DC_UpdateXforms( dc
);
135 INT
nulldrv_SetMapMode( PHYSDEV dev
, INT mode
)
137 DC
*dc
= get_nulldrv_dc( dev
);
138 INT ret
= dc
->MapMode
;
139 INT horzSize
, vertSize
, horzRes
, vertRes
;
141 if (mode
== dc
->MapMode
&& (mode
== MM_ISOTROPIC
|| mode
== MM_ANISOTROPIC
)) return ret
;
143 horzSize
= dc
->virtual_size
.cx
;
144 vertSize
= dc
->virtual_size
.cy
;
145 horzRes
= dc
->virtual_res
.cx
;
146 vertRes
= dc
->virtual_res
.cy
;
157 dc
->wndExtX
= horzSize
* 10;
158 dc
->wndExtY
= vertSize
* 10;
159 dc
->vportExtX
= horzRes
;
160 dc
->vportExtY
= -vertRes
;
163 dc
->wndExtX
= horzSize
* 100;
164 dc
->wndExtY
= vertSize
* 100;
165 dc
->vportExtX
= horzRes
;
166 dc
->vportExtY
= -vertRes
;
169 dc
->wndExtX
= MulDiv(1000, horzSize
, 254);
170 dc
->wndExtY
= MulDiv(1000, vertSize
, 254);
171 dc
->vportExtX
= horzRes
;
172 dc
->vportExtY
= -vertRes
;
175 dc
->wndExtX
= MulDiv(10000, horzSize
, 254);
176 dc
->wndExtY
= MulDiv(10000, vertSize
, 254);
177 dc
->vportExtX
= horzRes
;
178 dc
->vportExtY
= -vertRes
;
181 dc
->wndExtX
= MulDiv(14400, horzSize
, 254);
182 dc
->wndExtY
= MulDiv(14400, vertSize
, 254);
183 dc
->vportExtX
= horzRes
;
184 dc
->vportExtY
= -vertRes
;
191 /* RTL layout is always MM_ANISOTROPIC */
192 if (!(dc
->layout
& LAYOUT_RTL
)) dc
->MapMode
= mode
;
193 DC_UpdateXforms( dc
);
197 BOOL
nulldrv_SetViewportExtEx( PHYSDEV dev
, INT cx
, INT cy
, SIZE
*size
)
199 DC
*dc
= get_nulldrv_dc( dev
);
203 size
->cx
= dc
->vportExtX
;
204 size
->cy
= dc
->vportExtY
;
206 if (dc
->MapMode
!= MM_ISOTROPIC
&& dc
->MapMode
!= MM_ANISOTROPIC
) return TRUE
;
207 if (!cx
|| !cy
) return FALSE
;
210 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
211 DC_UpdateXforms( dc
);
215 BOOL
nulldrv_SetViewportOrgEx( PHYSDEV dev
, INT x
, INT y
, POINT
*pt
)
217 DC
*dc
= get_nulldrv_dc( dev
);
221 pt
->x
= dc
->vportOrgX
;
222 pt
->y
= dc
->vportOrgY
;
226 DC_UpdateXforms( dc
);
230 BOOL
nulldrv_SetWindowExtEx( PHYSDEV dev
, INT cx
, INT cy
, SIZE
*size
)
232 DC
*dc
= get_nulldrv_dc( dev
);
236 size
->cx
= dc
->wndExtX
;
237 size
->cy
= dc
->wndExtY
;
239 if (dc
->MapMode
!= MM_ISOTROPIC
&& dc
->MapMode
!= MM_ANISOTROPIC
) return TRUE
;
240 if (!cx
|| !cy
) return FALSE
;
243 /* The API docs say that you should call SetWindowExtEx before
244 SetViewportExtEx. This advice does not imply that Windows
245 doesn't ensure the isotropic mapping after SetWindowExtEx! */
246 if (dc
->MapMode
== MM_ISOTROPIC
) MAPPING_FixIsotropic( dc
);
247 DC_UpdateXforms( dc
);
251 BOOL
nulldrv_SetWindowOrgEx( PHYSDEV dev
, INT x
, INT y
, POINT
*pt
)
253 DC
*dc
= get_nulldrv_dc( dev
);
262 DC_UpdateXforms( dc
);
266 BOOL
nulldrv_ModifyWorldTransform( PHYSDEV dev
, const XFORM
*xform
, DWORD mode
)
268 DC
*dc
= get_nulldrv_dc( dev
);
273 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
274 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
275 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
276 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
277 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
278 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
280 case MWT_LEFTMULTIPLY
:
281 CombineTransform( &dc
->xformWorld2Wnd
, xform
, &dc
->xformWorld2Wnd
);
283 case MWT_RIGHTMULTIPLY
:
284 CombineTransform( &dc
->xformWorld2Wnd
, &dc
->xformWorld2Wnd
, xform
);
289 DC_UpdateXforms( dc
);
293 BOOL
nulldrv_SetWorldTransform( PHYSDEV dev
, const XFORM
*xform
)
295 DC
*dc
= get_nulldrv_dc( dev
);
297 dc
->xformWorld2Wnd
= *xform
;
298 DC_UpdateXforms( dc
);
302 /***********************************************************************
305 BOOL WINAPI
DPtoLP( HDC hdc
, LPPOINT points
, INT count
)
307 DC
* dc
= get_dc_ptr( hdc
);
308 if (!dc
) return FALSE
;
310 if (dc
->vport2WorldValid
)
314 double x
= points
->x
;
315 double y
= points
->y
;
316 points
->x
= floor( x
* dc
->xformVport2World
.eM11
+
317 y
* dc
->xformVport2World
.eM21
+
318 dc
->xformVport2World
.eDx
+ 0.5 );
319 points
->y
= floor( x
* dc
->xformVport2World
.eM12
+
320 y
* dc
->xformVport2World
.eM22
+
321 dc
->xformVport2World
.eDy
+ 0.5 );
325 release_dc_ptr( dc
);
330 /***********************************************************************
333 BOOL WINAPI
LPtoDP( HDC hdc
, LPPOINT points
, INT count
)
335 DC
* dc
= get_dc_ptr( hdc
);
336 if (!dc
) return FALSE
;
340 double x
= points
->x
;
341 double y
= points
->y
;
342 points
->x
= floor( x
* dc
->xformWorld2Vport
.eM11
+
343 y
* dc
->xformWorld2Vport
.eM21
+
344 dc
->xformWorld2Vport
.eDx
+ 0.5 );
345 points
->y
= floor( x
* dc
->xformWorld2Vport
.eM12
+
346 y
* dc
->xformWorld2Vport
.eM22
+
347 dc
->xformWorld2Vport
.eDy
+ 0.5 );
350 release_dc_ptr( dc
);
355 /***********************************************************************
356 * SetMapMode (GDI32.@)
358 INT WINAPI
SetMapMode( HDC hdc
, INT mode
)
361 DC
* dc
= get_dc_ptr( hdc
);
363 TRACE("%p %d\n", hdc
, mode
);
367 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetMapMode
);
368 ret
= physdev
->funcs
->pSetMapMode( physdev
, mode
);
369 release_dc_ptr( dc
);
375 /***********************************************************************
376 * SetViewportExtEx (GDI32.@)
378 BOOL WINAPI
SetViewportExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
381 DC
* dc
= get_dc_ptr( hdc
);
385 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetViewportExtEx
);
386 ret
= physdev
->funcs
->pSetViewportExtEx( physdev
, x
, y
, size
);
387 release_dc_ptr( dc
);
393 /***********************************************************************
394 * SetViewportOrgEx (GDI32.@)
396 BOOL WINAPI
SetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
399 DC
* dc
= get_dc_ptr( hdc
);
403 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetViewportOrgEx
);
404 ret
= physdev
->funcs
->pSetViewportOrgEx( physdev
, x
, y
, pt
);
405 release_dc_ptr( dc
);
411 /***********************************************************************
412 * SetWindowExtEx (GDI32.@)
414 BOOL WINAPI
SetWindowExtEx( HDC hdc
, INT x
, INT y
, LPSIZE size
)
417 DC
* dc
= get_dc_ptr( hdc
);
421 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetWindowExtEx
);
422 ret
= physdev
->funcs
->pSetWindowExtEx( physdev
, x
, y
, size
);
423 release_dc_ptr( dc
);
429 /***********************************************************************
430 * SetWindowOrgEx (GDI32.@)
432 BOOL WINAPI
SetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
435 DC
* dc
= get_dc_ptr( hdc
);
439 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetWindowOrgEx
);
440 ret
= physdev
->funcs
->pSetWindowOrgEx( physdev
, x
, y
, pt
);
441 release_dc_ptr( dc
);
447 /***********************************************************************
448 * OffsetViewportOrgEx (GDI32.@)
450 BOOL WINAPI
OffsetViewportOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
453 DC
* dc
= get_dc_ptr( hdc
);
457 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pOffsetViewportOrgEx
);
458 ret
= physdev
->funcs
->pOffsetViewportOrgEx( physdev
, x
, y
, pt
);
459 release_dc_ptr( dc
);
465 /***********************************************************************
466 * OffsetWindowOrgEx (GDI32.@)
468 BOOL WINAPI
OffsetWindowOrgEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
471 DC
* dc
= get_dc_ptr( hdc
);
475 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pOffsetWindowOrgEx
);
476 ret
= physdev
->funcs
->pOffsetWindowOrgEx( physdev
, x
, y
, pt
);
477 release_dc_ptr( dc
);
483 /***********************************************************************
484 * ScaleViewportExtEx (GDI32.@)
486 BOOL WINAPI
ScaleViewportExtEx( HDC hdc
, INT xNum
, INT xDenom
,
487 INT yNum
, INT yDenom
, LPSIZE size
)
490 DC
* dc
= get_dc_ptr( hdc
);
494 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pScaleViewportExtEx
);
495 ret
= physdev
->funcs
->pScaleViewportExtEx( physdev
, xNum
, xDenom
, yNum
, yDenom
, size
);
496 release_dc_ptr( dc
);
502 /***********************************************************************
503 * ScaleWindowExtEx (GDI32.@)
505 BOOL WINAPI
ScaleWindowExtEx( HDC hdc
, INT xNum
, INT xDenom
,
506 INT yNum
, INT yDenom
, LPSIZE size
)
509 DC
* dc
= get_dc_ptr( hdc
);
513 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pScaleWindowExtEx
);
514 ret
= physdev
->funcs
->pScaleWindowExtEx( physdev
, xNum
, xDenom
, yNum
, yDenom
, size
);
515 release_dc_ptr( dc
);
521 /****************************************************************************
522 * ModifyWorldTransform (GDI32.@)
524 BOOL WINAPI
ModifyWorldTransform( HDC hdc
, const XFORM
*xform
, DWORD mode
)
529 if (!xform
&& mode
!= MWT_IDENTITY
) return FALSE
;
530 if ((dc
= get_dc_ptr( hdc
)))
532 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pModifyWorldTransform
);
533 if (dc
->GraphicsMode
== GM_ADVANCED
)
534 ret
= physdev
->funcs
->pModifyWorldTransform( physdev
, xform
, mode
);
535 release_dc_ptr( dc
);
541 /***********************************************************************
542 * SetWorldTransform (GDI32.@)
544 BOOL WINAPI
SetWorldTransform( HDC hdc
, const XFORM
*xform
)
549 if (!xform
) return FALSE
;
550 /* The transform must conform to (eM11 * eM22 != eM12 * eM21) requirement */
551 if (xform
->eM11
* xform
->eM22
== xform
->eM12
* xform
->eM21
) return FALSE
;
553 TRACE("eM11 %f eM12 %f eM21 %f eM22 %f eDx %f eDy %f\n",
554 xform
->eM11
, xform
->eM12
, xform
->eM21
, xform
->eM22
, xform
->eDx
, xform
->eDy
);
556 if ((dc
= get_dc_ptr( hdc
)))
558 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetWorldTransform
);
559 if (dc
->GraphicsMode
== GM_ADVANCED
)
560 ret
= physdev
->funcs
->pSetWorldTransform( physdev
, xform
);
561 release_dc_ptr( dc
);
567 /***********************************************************************
568 * SetVirtualResolution (GDI32.@)
570 * Undocumented on msdn.
572 * Changes the values of screen size in pixels and millimeters used by
573 * the mapping mode functions.
576 * hdc [I] Device context
577 * horz_res [I] Width in pixels (equivalent to HORZRES device cap).
578 * vert_res [I] Height in pixels (equivalent to VERTRES device cap).
579 * horz_size [I] Width in mm (equivalent to HORZSIZE device cap).
580 * vert_size [I] Height in mm (equivalent to VERTSIZE device cap).
583 * TRUE if successful.
584 * FALSE if any (but not all) of the last four params are zero.
587 * This doesn't change the values returned by GetDeviceCaps, just the
588 * scaling of the mapping modes.
590 * Calling with the last four params equal to zero sets the values
591 * back to their defaults obtained by calls to GetDeviceCaps.
593 BOOL WINAPI
SetVirtualResolution(HDC hdc
, DWORD horz_res
, DWORD vert_res
,
594 DWORD horz_size
, DWORD vert_size
)
597 TRACE("(%p %d %d %d %d)\n", hdc
, horz_res
, vert_res
, horz_size
, vert_size
);
599 if(horz_res
== 0 && vert_res
== 0 && horz_size
== 0 && vert_size
== 0)
601 horz_res
= GetDeviceCaps(hdc
, HORZRES
);
602 vert_res
= GetDeviceCaps(hdc
, VERTRES
);
603 horz_size
= GetDeviceCaps(hdc
, HORZSIZE
);
604 vert_size
= GetDeviceCaps(hdc
, VERTSIZE
);
606 else if(horz_res
== 0 || vert_res
== 0 || horz_size
== 0 || vert_size
== 0)
609 dc
= get_dc_ptr( hdc
);
610 if (!dc
) return FALSE
;
612 dc
->virtual_res
.cx
= horz_res
;
613 dc
->virtual_res
.cy
= vert_res
;
614 dc
->virtual_size
.cx
= horz_size
;
615 dc
->virtual_size
.cy
= vert_size
;
617 release_dc_ptr( dc
);