cmd: DIR command outputs free space for the path.
[wine.git] / dlls / win32u / emfdrv.c
blob069ad9d1297dc26f01ecfbcf050313cf6761ef0b
1 /*
2 * Enhanced MetaFile driver
4 * Copyright 1999 Huw D M Davies
5 * Copyright 2021 Jacek Caban for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #if 0
23 #pragma makedep unix
24 #endif
26 #include "ntgdi_private.h"
29 typedef struct
31 struct gdi_physdev dev;
32 INT dev_caps[COLORMGMTCAPS + 1];
33 } EMFDRV_PDEVICE;
35 static inline EMFDRV_PDEVICE *get_emf_physdev( PHYSDEV dev )
37 return CONTAINING_RECORD( dev, EMFDRV_PDEVICE, dev );
40 static void emfdrv_update_bounds( DC *dc, RECTL *rect )
42 RECTL *bounds = &dc->attr->emf_bounds;
43 RECTL vport_rect = *rect;
45 lp_to_dp( dc, (POINT *)&vport_rect, 2 );
47 /* The coordinate systems may be mirrored
48 (LPtoDP handles points, not rectangles) */
49 if (vport_rect.left > vport_rect.right)
51 LONG temp = vport_rect.right;
52 vport_rect.right = vport_rect.left;
53 vport_rect.left = temp;
55 if (vport_rect.top > vport_rect.bottom)
57 LONG temp = vport_rect.bottom;
58 vport_rect.bottom = vport_rect.top;
59 vport_rect.top = temp;
62 if (bounds->left > bounds->right)
64 /* first bounding rectangle */
65 *bounds = vport_rect;
67 else
69 bounds->left = min( bounds->left, vport_rect.left );
70 bounds->top = min( bounds->top, vport_rect.top );
71 bounds->right = max( bounds->right, vport_rect.right );
72 bounds->bottom = max( bounds->bottom, vport_rect.bottom );
76 static BOOL EMFDRV_LineTo( PHYSDEV dev, INT x, INT y )
78 DC *dc = get_physdev_dc( dev );
79 RECTL bounds;
80 POINT pt;
82 pt = dc->attr->cur_pos;
84 bounds.left = min( x, pt.x );
85 bounds.top = min( y, pt.y );
86 bounds.right = max( x, pt.x );
87 bounds.bottom = max( y, pt.y );
88 emfdrv_update_bounds( dc, &bounds );
89 return TRUE;
92 static BOOL EMFDRV_RoundRect( PHYSDEV dev, INT left, INT top, INT right,
93 INT bottom, INT ell_width, INT ell_height )
95 DC *dc = get_physdev_dc( dev );
96 RECTL bounds;
98 if (left == right || top == bottom) return FALSE;
100 bounds.left = min( left, right );
101 bounds.top = min( top, bottom );
102 bounds.right = max( left, right );
103 bounds.bottom = max( top, bottom );
104 if (dc->attr->graphics_mode == GM_COMPATIBLE)
106 bounds.right--;
107 bounds.bottom--;
110 emfdrv_update_bounds( dc, &bounds );
111 return TRUE;
114 static BOOL EMFDRV_ArcChordPie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
115 INT xstart, INT ystart, INT xend, INT yend, DWORD type )
117 DC *dc = get_physdev_dc( dev );
118 INT temp, x_centre, y_centre, i;
119 double angle_start, angle_end;
120 double xinter_start, yinter_start, xinter_end, yinter_end;
121 EMRARC emr;
122 RECTL bounds;
124 if (left == right || top == bottom) return FALSE;
126 if (left > right) { temp = left; left = right; right = temp; }
127 if (top > bottom) { temp = top; top = bottom; bottom = temp; }
129 if (dc->attr->graphics_mode == GM_COMPATIBLE)
131 right--;
132 bottom--;
135 emr.emr.iType = type;
136 emr.emr.nSize = sizeof(emr);
137 emr.rclBox.left = left;
138 emr.rclBox.top = top;
139 emr.rclBox.right = right;
140 emr.rclBox.bottom = bottom;
141 emr.ptlStart.x = xstart;
142 emr.ptlStart.y = ystart;
143 emr.ptlEnd.x = xend;
144 emr.ptlEnd.y = yend;
146 /* Now calculate the BBox */
147 x_centre = (left + right + 1) / 2;
148 y_centre = (top + bottom + 1) / 2;
150 xstart -= x_centre;
151 ystart -= y_centre;
152 xend -= x_centre;
153 yend -= y_centre;
155 /* invert y co-ords to get angle anti-clockwise from x-axis */
156 angle_start = atan2( -(double)ystart, (double)xstart );
157 angle_end = atan2( -(double)yend, (double)xend );
159 /* These are the intercepts of the start/end lines with the arc */
160 xinter_start = (right - left + 1)/2 * cos(angle_start) + x_centre;
161 yinter_start = -(bottom - top + 1)/2 * sin(angle_start) + y_centre;
162 xinter_end = (right - left + 1)/2 * cos(angle_end) + x_centre;
163 yinter_end = -(bottom - top + 1)/2 * sin(angle_end) + y_centre;
165 if (angle_start < 0) angle_start += 2 * M_PI;
166 if (angle_end < 0) angle_end += 2 * M_PI;
167 if (angle_end < angle_start) angle_end += 2 * M_PI;
169 bounds.left = min( xinter_start, xinter_end );
170 bounds.top = min( yinter_start, yinter_end );
171 bounds.right = max( xinter_start, xinter_end );
172 bounds.bottom = max( yinter_start, yinter_end );
174 for (i = 0; i <= 8; i++)
176 if(i * M_PI / 2 < angle_start) /* loop until we're past start */
177 continue;
178 if(i * M_PI / 2 > angle_end) /* if we're past end we're finished */
179 break;
181 /* the arc touches the rectangle at the start of quadrant i, so adjust
182 BBox to reflect this. */
184 switch(i % 4) {
185 case 0:
186 bounds.right = right;
187 break;
188 case 1:
189 bounds.top = top;
190 break;
191 case 2:
192 bounds.left = left;
193 break;
194 case 3:
195 bounds.bottom = bottom;
196 break;
200 /* If we're drawing a pie then make sure we include the centre */
201 if (type == EMR_PIE)
203 if (bounds.left > x_centre) bounds.left = x_centre;
204 else if (bounds.right < x_centre) bounds.right = x_centre;
205 if (bounds.top > y_centre) bounds.top = y_centre;
206 else if (bounds.bottom < y_centre) bounds.bottom = y_centre;
208 else if (type == EMR_ARCTO)
210 POINT pt;
211 pt = dc->attr->cur_pos;
212 bounds.left = min( bounds.left, pt.x );
213 bounds.top = min( bounds.top, pt.y );
214 bounds.right = max( bounds.right, pt.x );
215 bounds.bottom = max( bounds.bottom, pt.y );
217 emfdrv_update_bounds( dc, &bounds );
218 return TRUE;
221 static BOOL EMFDRV_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
222 INT xstart, INT ystart, INT xend, INT yend )
224 return EMFDRV_ArcChordPie( dev, left, top, right, bottom, xstart, ystart,
225 xend, yend, EMR_ARC );
228 static BOOL EMFDRV_ArcTo( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
229 INT xstart, INT ystart, INT xend, INT yend )
231 return EMFDRV_ArcChordPie( dev, left, top, right, bottom, xstart, ystart,
232 xend, yend, EMR_ARCTO );
235 static BOOL EMFDRV_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
236 INT xstart, INT ystart, INT xend, INT yend )
238 return EMFDRV_ArcChordPie( dev, left, top, right, bottom, xstart, ystart,
239 xend, yend, EMR_PIE );
242 static BOOL EMFDRV_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
243 INT xstart, INT ystart, INT xend, INT yend )
245 return EMFDRV_ArcChordPie( dev, left, top, right, bottom, xstart, ystart,
246 xend, yend, EMR_CHORD );
249 static BOOL EMFDRV_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
251 DC *dc = get_physdev_dc( dev );
252 RECTL bounds;
254 if (left == right || top == bottom) return FALSE;
256 bounds.left = min( left, right );
257 bounds.top = min( top, bottom );
258 bounds.right = max( left, right );
259 bounds.bottom = max( top, bottom );
260 if (dc->attr->graphics_mode == GM_COMPATIBLE)
262 bounds.right--;
263 bounds.bottom--;
266 emfdrv_update_bounds( dc, &bounds );
267 return TRUE;
270 static BOOL EMFDRV_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom )
272 DC *dc = get_physdev_dc( dev );
273 RECTL bounds;
275 if (left == right || top == bottom) return FALSE;
277 bounds.left = min( left, right );
278 bounds.top = min( top, bottom );
279 bounds.right = max( left, right );
280 bounds.bottom = max( top, bottom );
281 if (dc->attr->graphics_mode == GM_COMPATIBLE)
283 bounds.right--;
284 bounds.bottom--;
287 emfdrv_update_bounds( dc, &bounds );
288 return TRUE;
291 static COLORREF EMFDRV_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color )
293 DC *dc = get_physdev_dc( dev );
294 RECTL bounds;
296 bounds.left = bounds.right = x;
297 bounds.top = bounds.bottom = y;
298 emfdrv_update_bounds( dc, &bounds );
299 return CLR_INVALID;
302 static BOOL EMFDRV_PolylineTo( PHYSDEV dev, const POINT *pt, INT count )
304 /* FIXME: update bounding rect */
305 return TRUE;
308 static BOOL EMFDRV_PolyBezier( PHYSDEV dev, const POINT *pts, DWORD count )
310 /* FIXME: update bounding rect */
311 return TRUE;
314 static BOOL EMFDRV_PolyBezierTo( PHYSDEV dev, const POINT *pts, DWORD count )
316 /* FIXME: update bounding rect */
317 return TRUE;
320 static BOOL EMFDRV_PolyPolyline( PHYSDEV dev, const POINT *pt, const DWORD *counts, DWORD polys )
322 /* FIXME: update bounding rect */
323 return TRUE;
326 static BOOL EMFDRV_PolyPolygon( PHYSDEV dev, const POINT *pt, const INT *counts, UINT polys )
328 /* FIXME: update bounding rect */
329 return TRUE;
332 static BOOL EMFDRV_PolyDraw( PHYSDEV dev, const POINT *pts, const BYTE *types, DWORD count )
334 /* FIXME: update bounding rect */
335 return TRUE;
338 static BOOL EMFDRV_FillRgn( PHYSDEV dev, HRGN hrgn, HBRUSH hbrush )
340 /* FIXME: update bounding rect */
341 return TRUE;
344 static BOOL EMFDRV_FrameRgn( PHYSDEV dev, HRGN hrgn, HBRUSH hbrush, INT width, INT height )
346 /* FIXME: update bounding rect */
347 return TRUE;
350 static BOOL EMFDRV_InvertRgn( PHYSDEV dev, HRGN hrgn )
352 /* FIXME: update bounding rect */
353 return TRUE;
356 static BOOL EMFDRV_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *lprect,
357 LPCWSTR str, UINT count, const INT *lpDx )
359 /* FIXME: update bounding rect */
360 return TRUE;
363 static BOOL EMFDRV_GradientFill( PHYSDEV dev, TRIVERTEX *vert_array, ULONG nvert,
364 void *grad_array, ULONG ngrad, ULONG mode )
366 /* FIXME: update bounding rect */
367 return TRUE;
370 static BOOL EMFDRV_FillPath( PHYSDEV dev )
372 /* FIXME: update bound rect */
373 return TRUE;
376 static BOOL EMFDRV_StrokeAndFillPath( PHYSDEV dev )
378 /* FIXME: update bound rect */
379 return TRUE;
382 static BOOL EMFDRV_StrokePath( PHYSDEV dev )
384 /* FIXME: update bound rect */
385 return TRUE;
388 static BOOL EMFDRV_AlphaBlend( PHYSDEV dev_dst, struct bitblt_coords *dst,
389 PHYSDEV dev_src, struct bitblt_coords *src,
390 BLENDFUNCTION func )
392 /* FIXME: update bound rect */
393 return TRUE;
396 static BOOL EMFDRV_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop )
398 /* FIXME: update bound rect */
399 return TRUE;
402 static HBITMAP EMFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
404 return 0;
407 static HFONT EMFDRV_SelectFont( PHYSDEV dev, HFONT font, UINT *aa_flags )
409 *aa_flags = GGO_BITMAP; /* no point in anti-aliasing on metafiles */
411 dev = GET_NEXT_PHYSDEV( dev, pSelectFont );
412 return dev->funcs->pSelectFont( dev, font, aa_flags );
415 static INT EMFDRV_GetDeviceCaps( PHYSDEV dev, INT cap )
417 EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
419 if (cap >= 0 && cap < ARRAY_SIZE( physDev->dev_caps ))
420 return physDev->dev_caps[cap];
421 return 0;
424 static BOOL EMFDRV_DeleteDC( PHYSDEV dev )
426 EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
427 free( physDev );
428 return TRUE;
431 static const struct gdi_dc_funcs emfdrv_driver =
433 NULL, /* pAbortDoc */
434 NULL, /* pAbortPath */
435 EMFDRV_AlphaBlend, /* pAlphaBlend */
436 NULL, /* pAngleArc */
437 EMFDRV_Arc, /* pArc */
438 EMFDRV_ArcTo, /* pArcTo */
439 NULL, /* pBeginPath */
440 NULL, /* pBlendImage */
441 EMFDRV_Chord, /* pChord */
442 NULL, /* pCloseFigure */
443 NULL, /* pCreateCompatibleDC */
444 NULL, /* pCreateDC */
445 EMFDRV_DeleteDC, /* pDeleteDC */
446 NULL, /* pDeleteObject */
447 EMFDRV_Ellipse, /* pEllipse */
448 NULL, /* pEndDoc */
449 NULL, /* pEndPage */
450 NULL, /* pEndPath */
451 NULL, /* pEnumFonts */
452 NULL, /* pExtEscape */
453 NULL, /* pExtFloodFill */
454 EMFDRV_ExtTextOut, /* pExtTextOut */
455 EMFDRV_FillPath, /* pFillPath */
456 EMFDRV_FillRgn, /* pFillRgn */
457 NULL, /* pFontIsLinked */
458 EMFDRV_FrameRgn, /* pFrameRgn */
459 NULL, /* pGetBoundsRect */
460 NULL, /* pGetCharABCWidths */
461 NULL, /* pGetCharABCWidthsI */
462 NULL, /* pGetCharWidth */
463 NULL, /* pGetCharWidthInfo */
464 EMFDRV_GetDeviceCaps, /* pGetDeviceCaps */
465 NULL, /* pGetDeviceGammaRamp */
466 NULL, /* pGetFontData */
467 NULL, /* pGetFontRealizationInfo */
468 NULL, /* pGetFontUnicodeRanges */
469 NULL, /* pGetGlyphIndices */
470 NULL, /* pGetGlyphOutline */
471 NULL, /* pGetICMProfile */
472 NULL, /* pGetImage */
473 NULL, /* pGetKerningPairs */
474 NULL, /* pGetNearestColor */
475 NULL, /* pGetOutlineTextMetrics */
476 NULL, /* pGetPixel */
477 NULL, /* pGetSystemPaletteEntries */
478 NULL, /* pGetTextCharsetInfo */
479 NULL, /* pGetTextExtentExPoint */
480 NULL, /* pGetTextExtentExPointI */
481 NULL, /* pGetTextFace */
482 NULL, /* pGetTextMetrics */
483 EMFDRV_GradientFill, /* pGradientFill */
484 EMFDRV_InvertRgn, /* pInvertRgn */
485 EMFDRV_LineTo, /* pLineTo */
486 NULL, /* pMoveTo */
487 NULL, /* pPaintRgn */
488 EMFDRV_PatBlt, /* pPatBlt */
489 EMFDRV_Pie, /* pPie */
490 EMFDRV_PolyBezier, /* pPolyBezier */
491 EMFDRV_PolyBezierTo, /* pPolyBezierTo */
492 EMFDRV_PolyDraw, /* pPolyDraw */
493 EMFDRV_PolyPolygon, /* pPolyPolygon */
494 EMFDRV_PolyPolyline, /* pPolyPolyline */
495 EMFDRV_PolylineTo, /* pPolylineTo */
496 NULL, /* pPutImage */
497 NULL, /* pRealizeDefaultPalette */
498 NULL, /* pRealizePalette */
499 EMFDRV_Rectangle, /* pRectangle */
500 NULL, /* pResetDC */
501 EMFDRV_RoundRect, /* pRoundRect */
502 EMFDRV_SelectBitmap, /* pSelectBitmap */
503 NULL, /* pSelectBrush */
504 EMFDRV_SelectFont, /* pSelectFont */
505 NULL, /* pSelectPen */
506 NULL, /* pSetBkColor */
507 NULL, /* pSetBoundsRect */
508 NULL, /* pSetDCBrushColor*/
509 NULL, /* pSetDCPenColor*/
510 NULL, /* pSetDIBitsToDevice */
511 NULL, /* pSetDeviceClipping */
512 NULL, /* pSetDeviceGammaRamp */
513 EMFDRV_SetPixel, /* pSetPixel */
514 NULL, /* pSetTextColor */
515 NULL, /* pStartDoc */
516 NULL, /* pStartPage */
517 NULL, /* pStretchBlt */
518 NULL, /* pStretchDIBits */
519 EMFDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
520 EMFDRV_StrokePath, /* pStrokePath */
521 NULL, /* pUnrealizePalette */
522 NULL, /* pD3DKMTCheckVidPnExclusiveOwnership */
523 NULL, /* pD3DKMTCloseAdapter */
524 NULL, /* pD3DKMTOpenAdapterFromLuid */
525 NULL, /* pD3DKMTQueryVideoMemoryInfo */
526 NULL, /* pD3DKMTSetVidPnSourceOwner */
527 GDI_PRIORITY_GRAPHICS_DRV /* priority */
531 static BOOL devcap_is_valid( int cap )
533 if (cap >= 0 && cap <= ASPECTXY) return !(cap & 1);
534 if (cap >= PHYSICALWIDTH && cap <= COLORMGMTCAPS) return TRUE;
535 switch (cap)
537 case LOGPIXELSX:
538 case LOGPIXELSY:
539 case CAPS1:
540 case SIZEPALETTE:
541 case NUMRESERVED:
542 case COLORRES:
543 return TRUE;
545 return FALSE;
548 /**********************************************************************
549 * NtGdiCreateMetafileDC (win32u.@)
551 HDC WINAPI NtGdiCreateMetafileDC( HDC hdc )
553 EMFDRV_PDEVICE *physDev;
554 HDC ref_dc, ret;
555 int cap;
556 DC *dc;
558 if (!(dc = alloc_dc_ptr( NTGDI_OBJ_ENHMETADC ))) return 0;
560 physDev = malloc( sizeof(*physDev) );
561 if (!physDev)
563 free_dc_ptr( dc );
564 return 0;
567 push_dc_driver( &dc->physDev, &physDev->dev, &emfdrv_driver );
569 if (hdc) /* if no ref, use current display */
570 ref_dc = hdc;
571 else
572 ref_dc = NtGdiOpenDCW( NULL, NULL, NULL, 0, TRUE, NULL, NULL, NULL );
574 memset( physDev->dev_caps, 0, sizeof(physDev->dev_caps) );
575 for (cap = 0; cap < ARRAY_SIZE( physDev->dev_caps ); cap++)
576 if (devcap_is_valid( cap ))
577 physDev->dev_caps[cap] = NtGdiGetDeviceCaps( ref_dc, cap );
579 if (!hdc) NtGdiDeleteObjectApp( ref_dc );
581 NtGdiSetVirtualResolution( dc->hSelf, 0, 0, 0, 0 );
583 ret = dc->hSelf;
584 release_dc_ptr( dc );
585 return ret;