path.c
来自「一个类似windows」· C语言 代码 · 共 1,307 行 · 第 1/3 页
C
1,307 行
/*
* ReactOS W32 Subsystem
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: path.c 21292 2006-03-11 23:50:04Z jimtabor $ */
#include <w32k.h>
#include "math.h"
#define NDEBUG
#include <debug.h>
#define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
#define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
#define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
BOOL FASTCALL PATH_AddEntry (GdiPath *pPath, const POINT *pPoint, BYTE flags);
BOOL FASTCALL PATH_AddFlatBezier (GdiPath *pPath, POINT *pt, BOOL closed);
BOOL FASTCALL PATH_DoArcPart (GdiPath *pPath, FLOAT_POINT corners[], double angleStart, double angleEnd, BOOL addMoveTo);
BOOL FASTCALL PATH_FillPath( PDC dc, GdiPath *pPath );
BOOL FASTCALL PATH_FlattenPath (GdiPath *pPath);
VOID FASTCALL PATH_GetPathFromDC (PDC dc, GdiPath **ppPath);
VOID FASTCALL PATH_NormalizePoint (FLOAT_POINT corners[], const FLOAT_POINT *pPoint, double *pX, double *pY);
BOOL FASTCALL PATH_PathToRegion (GdiPath *pPath, INT nPolyFillMode, HRGN *pHrgn);
BOOL FASTCALL PATH_ReserveEntries (GdiPath *pPath, INT numEntries);
VOID FASTCALL PATH_ScaleNormalizedPoint (FLOAT_POINT corners[], double x, double y, POINT *pPoint);
INT FASTCALL
IntGdiGetArcDirection(DC *dc);
BOOL
STDCALL
NtGdiAbortPath(HDC hDC)
{
GdiPath *pPath;
BOOL ret = TRUE;
PDC dc = DC_LockDc ( hDC );
if( !dc ) return FALSE;
/* Get pointer to path */
PATH_GetPathFromDC ( dc, &pPath );
PATH_EmptyPath( pPath );
DC_UnlockDc ( dc );
return ret;
}
BOOL
STDCALL
NtGdiBeginPath( HDC hDC )
{
GdiPath *pPath;
BOOL ret = TRUE;
PDC dc = DC_LockDc ( hDC );
if( !dc ) return FALSE;
/* Get pointer to path */
PATH_GetPathFromDC ( dc, &pPath );
/* If path is already open, do nothing */
if ( pPath->state != PATH_Open )
{
/* Make sure that path is empty */
PATH_EmptyPath( pPath );
/* Initialize variables for new path */
pPath->newStroke = TRUE;
pPath->state = PATH_Open;
}
DC_UnlockDc ( dc );
return ret;
}
BOOL
FASTCALL
IntCloseFigure ( PDC dc )
{
UNIMPLEMENTED;
return FALSE;
}
BOOL
STDCALL
NtGdiCloseFigure ( HDC hDC )
{
PDC dc = DC_LockDc ( hDC );
BOOL ret = FALSE; // default to failure
if ( dc )
{
ret = IntCloseFigure ( dc );
DC_UnlockDc ( dc );
}
return ret;
}
BOOL
STDCALL
NtGdiEndPath(HDC hDC)
{
GdiPath *pPath;
BOOL ret = TRUE;
PDC dc = DC_LockDc ( hDC );
if ( !dc ) return FALSE;
/* Get pointer to path */
PATH_GetPathFromDC ( dc, &pPath );
/* Check that path is currently being constructed */
if( pPath->state != PATH_Open )
{
ret = FALSE;
}
/* Set flag to indicate that path is finished */
else pPath->state = PATH_Closed;
DC_UnlockDc ( dc );
return ret;
}
BOOL
STDCALL
NtGdiFillPath(HDC hDC)
{
GdiPath *pPath;
BOOL ret = TRUE;
PDC dc = DC_LockDc ( hDC );
if ( !dc ) return FALSE;
/* Get pointer to path */
PATH_GetPathFromDC ( dc, &pPath );
ret = PATH_FillPath( dc, pPath );
if( ret )
{
/* FIXME: Should the path be emptied even if conversion
failed? */
PATH_EmptyPath( pPath );
}
DC_UnlockDc ( dc );
return ret;
}
BOOL
STDCALL
NtGdiFlattenPath(HDC hDC)
{
UNIMPLEMENTED;
return FALSE;
}
BOOL
APIENTRY
NtGdiGetMiterLimit(
IN HDC hdc,
OUT PDWORD pdwOut)
{
UNIMPLEMENTED;
return FALSE;
}
INT
STDCALL
NtGdiGetPath(HDC hDC,
LPPOINT Points,
LPBYTE Types,
INT nSize)
{
UNIMPLEMENTED;
return 0;
}
HRGN
STDCALL
NtGdiPathToRegion(HDC hDC)
{
UNIMPLEMENTED;
return 0;
}
BOOL
APIENTRY
NtGdiSetMiterLimit(
IN HDC hdc,
IN DWORD dwNew,
IN OUT OPTIONAL PDWORD pdwOut)
{
UNIMPLEMENTED;
return FALSE;
}
BOOL
STDCALL
NtGdiStrokeAndFillPath(HDC hDC)
{
UNIMPLEMENTED;
return FALSE;
}
BOOL
STDCALL
NtGdiStrokePath(HDC hDC)
{
UNIMPLEMENTED;
return FALSE;
}
BOOL
STDCALL
NtGdiWidenPath(HDC hDC)
{
UNIMPLEMENTED;
return FALSE;
}
BOOL STDCALL NtGdiSelectClipPath(HDC hDC,
int Mode)
{
GdiPath *pPath;
HRGN hrgnPath;
BOOL success = FALSE;
PDC dc = DC_LockDc ( hDC );
if( !dc ) return FALSE;
PATH_GetPathFromDC ( dc, &pPath );
/* Check that path is closed */
if( pPath->state != PATH_Closed )
{
SetLastWin32Error(ERROR_CAN_NOT_COMPLETE);
return FALSE;
}
/* Construct a region from the path */
else if( PATH_PathToRegion( pPath, dc->w.polyFillMode, &hrgnPath ) )
{
success = IntGdiExtSelectClipRgn( dc, hrgnPath, Mode ) != ERROR;
NtGdiDeleteObject( hrgnPath );
/* Empty the path */
if( success )
PATH_EmptyPath( pPath );
/* FIXME: Should this function delete the path even if it failed? */
}
DC_UnlockDc ( dc );
return success;
}
/***********************************************************************
* Exported functions
*/
/* PATH_FillPath
*
*
*/
BOOL
FASTCALL
PATH_FillPath( PDC dc, GdiPath *pPath )
{
INT mapMode, graphicsMode;
SIZE ptViewportExt, ptWindowExt;
POINT ptViewportOrg, ptWindowOrg;
XFORM xform;
HRGN hrgn;
if( pPath->state != PATH_Closed )
{
SetLastWin32Error(ERROR_CAN_NOT_COMPLETE);
return FALSE;
}
if( PATH_PathToRegion( pPath, dc->w.polyFillMode, &hrgn ))
{
/* Since PaintRgn interprets the region as being in logical coordinates
* but the points we store for the path are already in device
* coordinates, we have to set the mapping mode to MM_TEXT temporarily.
* Using SaveDC to save information about the mapping mode / world
* transform would be easier but would require more overhead, especially
* now that SaveDC saves the current path.
*/
/* Save the information about the old mapping mode */
mapMode = NtGdiGetMapMode( dc->hSelf );
NtGdiGetViewportExtEx( dc->hSelf, &ptViewportExt );
NtGdiGetViewportOrgEx( dc->hSelf, &ptViewportOrg );
NtGdiGetWindowExtEx( dc->hSelf, &ptWindowExt );
NtGdiGetWindowOrgEx( dc->hSelf, &ptWindowOrg );
/* Save world transform
* NB: The Windows documentation on world transforms would lead one to
* believe that this has to be done only in GM_ADVANCED; however, my
* tests show that resetting the graphics mode to GM_COMPATIBLE does
* not reset the world transform.
*/
NtGdiGetWorldTransform( dc->hSelf, &xform );
/* Set MM_TEXT */
NtGdiSetMapMode( dc->hSelf, MM_TEXT );
NtGdiSetViewportOrgEx( dc->hSelf, 0, 0, NULL );
NtGdiSetWindowOrgEx( dc->hSelf, 0, 0, NULL );
graphicsMode = NtGdiGetGraphicsMode( dc->hSelf );
NtGdiSetGraphicsMode( dc->hSelf, GM_ADVANCED );
NtGdiModifyWorldTransform( dc->hSelf, &xform, MWT_IDENTITY );
NtGdiSetGraphicsMode( dc->hSelf, graphicsMode );
/* Paint the region */
NtGdiPaintRgn( dc->hSelf, hrgn );
NtGdiDeleteObject( hrgn );
/* Restore the old mapping mode */
NtGdiSetMapMode( dc->hSelf, mapMode );
NtGdiSetViewportExtEx( dc->hSelf, ptViewportExt.cx, ptViewportExt.cy, NULL );
NtGdiSetViewportOrgEx( dc->hSelf, ptViewportOrg.x, ptViewportOrg.y, NULL );
NtGdiSetWindowExtEx( dc->hSelf, ptWindowExt.cx, ptWindowExt.cy, NULL );
NtGdiSetWindowOrgEx( dc->hSelf, ptWindowOrg.x, ptWindowOrg.y, NULL );
/* Go to GM_ADVANCED temporarily to restore the world transform */
graphicsMode = NtGdiGetGraphicsMode( dc->hSelf );
NtGdiSetGraphicsMode( dc->hSelf, GM_ADVANCED );
NtGdiSetWorldTransform( dc->hSelf, &xform );
NtGdiSetGraphicsMode( dc->hSelf, graphicsMode );
return TRUE;
}
return FALSE;
}
/* PATH_InitGdiPath
*
* Initializes the GdiPath structure.
*/
VOID
FASTCALL
PATH_InitGdiPath ( GdiPath *pPath )
{
assert(pPath!=NULL);
pPath->state=PATH_Null;
pPath->pPoints=NULL;
pPath->pFlags=NULL;
pPath->numEntriesUsed=0;
pPath->numEntriesAllocated=0;
}
/* PATH_DestroyGdiPath
*
* Destroys a GdiPath structure (frees the memory in the arrays).
*/
VOID
FASTCALL
PATH_DestroyGdiPath ( GdiPath *pPath )
{
assert(pPath!=NULL);
ExFreePool(pPath->pPoints);
ExFreePool(pPath->pFlags);
}
/* PATH_AssignGdiPath
*
* Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
* performed, i.e. the contents of the pPoints and pFlags arrays are copied,
* not just the pointers. Since this means that the arrays in pPathDest may
* need to be resized, pPathDest should have been initialized using
* PATH_InitGdiPath (in C++, this function would be an assignment operator,
* not a copy constructor).
* Returns TRUE if successful, else FALSE.
*/
BOOL
FASTCALL
PATH_AssignGdiPath ( GdiPath *pPathDest, const GdiPath *pPathSrc )
{
assert(pPathDest!=NULL && pPathSrc!=NULL);
/* Make sure destination arrays are big enough */
if ( !PATH_ReserveEntries(pPathDest, pPathSrc->numEntriesUsed) )
return FALSE;
/* Perform the copy operation */
memcpy(pPathDest->pPoints, pPathSrc->pPoints,
sizeof(POINT)*pPathSrc->numEntriesUsed);
memcpy(pPathDest->pFlags, pPathSrc->pFlags,
sizeof(BYTE)*pPathSrc->numEntriesUsed);
pPathDest->state=pPathSrc->state;
pPathDest->numEntriesUsed=pPathSrc->numEntriesUsed;
pPathDest->newStroke=pPathSrc->newStroke;
return TRUE;
}
/* PATH_MoveTo
*
* Should be called when a MoveTo is performed on a DC that has an
* open path. This starts a new stroke. Returns TRUE if successful, else
* FALSE.
*/
BOOL
FASTCALL
PATH_MoveTo ( PDC dc )
{
GdiPath *pPath;
/* Get pointer to path */
PATH_GetPathFromDC ( dc, &pPath );
/* Check that path is open */
if ( pPath->state != PATH_Open )
/* FIXME: Do we have to call SetLastError? */
return FALSE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?