static BOOL paint_path( PHYSDEV dev, BOOL stroke, BOOL fill ) { POINT *points; BYTE *types; BOOL ret = FALSE; int i, size = GetPath( dev->hdc, NULL, NULL, 0 ); if (size == -1) return FALSE; if (!size) return TRUE; points = HeapAlloc( GetProcessHeap(), 0, size * sizeof(*points) ); types = HeapAlloc( GetProcessHeap(), 0, size * sizeof(*types) ); if (!points || !types) goto done; if (GetPath( dev->hdc, points, types, size ) == -1) goto done; if (stroke) PSDRV_SetPen(dev); PSDRV_SetClip(dev); for (i = 0; i < size; i++) { switch (types[i]) { case PT_MOVETO: PSDRV_WriteMoveTo( dev, points[i].x, points[i].y ); break; case PT_LINETO: case PT_LINETO | PT_CLOSEFIGURE: PSDRV_WriteLineTo( dev, points[i].x, points[i].y ); if (types[i] & PT_CLOSEFIGURE) PSDRV_WriteClosePath( dev ); break; case PT_BEZIERTO: case PT_BEZIERTO | PT_CLOSEFIGURE: PSDRV_WriteCurveTo( dev, points + i ); if (types[i] & PT_CLOSEFIGURE) PSDRV_WriteClosePath( dev ); i += 2; break; } } if (fill) PSDRV_Brush( dev, GetPolyFillMode(dev->hdc) == ALTERNATE ); if (stroke) PSDRV_DrawLine(dev); else PSDRV_WriteNewPath(dev); PSDRV_ResetClip(dev); done: HeapFree( GetProcessHeap(), 0, points ); HeapFree( GetProcessHeap(), 0, types ); return ret; }
void CPreviewDC::MirrorAttributes() { ASSERT(m_hAttribDC != NULL); if (m_hDC != NULL) { // extract and re-set Pen and Brush HGDIOBJ hTemp = ::SelectObject(m_hAttribDC, ::GetStockObject(BLACK_PEN)); ::SelectObject(m_hAttribDC, hTemp); ::SelectObject(m_hDC, hTemp); hTemp = ::SelectObject(m_hAttribDC, ::GetStockObject(BLACK_BRUSH)); ::SelectObject(m_hAttribDC, hTemp); ::SelectObject(m_hDC, hTemp); SetROP2(GetROP2()); SetBkMode(GetBkMode()); SetTextAlign(GetTextAlign()); SetPolyFillMode(GetPolyFillMode()); SetStretchBltMode(GetStretchBltMode()); SetTextColor(GetNearestColor(GetTextColor())); SetBkColor(GetNearestColor(GetBkColor())); } }
/*********************************************************************** * PSDRV_PolyPolygon */ BOOL PSDRV_PolyPolygon( PHYSDEV dev, const POINT* pts, const INT* counts, UINT polygons ) { DWORD polygon, total; INT line; POINT *dev_pts, *pt; TRACE("\n"); for (polygon = total = 0; polygon < polygons; polygon++) total += counts[polygon]; if (!(dev_pts = HeapAlloc( GetProcessHeap(), 0, total * sizeof(*dev_pts) ))) return FALSE; memcpy( dev_pts, pts, total * sizeof(*dev_pts) ); LPtoDP( dev->hdc, dev_pts, total ); pt = dev_pts; PSDRV_WriteSpool(dev, "%PolyPolygon\n",13); PSDRV_SetPen(dev); PSDRV_SetClip(dev); for(polygon = 0; polygon < polygons; polygon++) { PSDRV_WriteMoveTo(dev, pt->x, pt->y); pt++; for(line = 1; line < counts[polygon]; line++, pt++) PSDRV_WriteLineTo(dev, pt->x, pt->y); PSDRV_WriteClosePath(dev); } HeapFree( GetProcessHeap(), 0, dev_pts ); if(GetPolyFillMode( dev->hdc ) == ALTERNATE) PSDRV_Brush(dev, 1); else /* WINDING */ PSDRV_Brush(dev, 0); PSDRV_DrawLine(dev); PSDRV_ResetClip(dev); return TRUE; }
void KDCAttributes::DumpDC(HDC hDC) { POINT pnt; SIZE size; m_List.DeleteAll(); Add(_T("Technology"), _T("%d"), GetDeviceCaps(hDC, TECHNOLOGY)); Add(_T("width"), _T("%d"), GetDeviceCaps(hDC, HORZRES)); Add(_T("height"), _T("%d"), GetDeviceCaps(hDC, VERTRES)); GetDCOrgEx(hDC, & pnt); Add(_T("DC Origin"), _T("{ %d, %d }"), pnt.x, pnt.y); TCHAR szTitle[MAX_PATH]; szTitle[0] = 0; GetWindowText(WindowFromDC(hDC), szTitle, MAX_PATH); Add(_T("Window"), _T("0x%X \"%s\""), WindowFromDC(hDC), szTitle); Add(_T("Bitmap"), _T("0x%X"), GetCurrentObject(hDC, OBJ_BITMAP)); Add(_T("Graphics Mode"), _T("%d"), GetGraphicsMode(hDC)); Add(_T("Mapping Mode"), _T("%d"), GetMapMode(hDC)); GetViewportExtEx(hDC, & size); Add(_T("Viewport Extent"), _T("{ %d, %d }"), size.cx, size.cy); GetViewportOrgEx(hDC, & pnt); Add(_T("Viewport Origin"), _T("{ %d, %d }"), pnt.x, pnt.y); GetWindowExtEx(hDC, & size); Add(_T("Window Extent"), _T("{ %d, %d }"), size.cx, size.cy); GetWindowOrgEx(hDC, & pnt); Add(_T("Window Origin"), _T("{ %d, %d }"), pnt.x, pnt.y); XFORM xform; GetWorldTransform(hDC, & xform); Add(_T("World transformation"), _T("{ %f, %f, %f, %f, %f, %f }"), xform.eM11, xform.eM12, xform.eM21, xform.eM22, xform.eDx, xform.eDy); // transformation Add(_T("Background Color"), _T("0x%X"), GetBkColor(hDC)); Add(_T("Text Color"), _T("0x%X"), GetTextColor(hDC)); Add(_T("Palette"), _T("0x%X"), GetCurrentObject(hDC, OBJ_PAL)); { COLORADJUSTMENT ca; GetColorAdjustment(hDC, & ca); Add(_T("Color Adjustment"), _T("{ %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d }"), ca.caSize, ca.caFlags, ca.caIlluminantIndex, ca.caRedGamma, ca.caGreenGamma, ca.caBlueGamma, ca.caReferenceBlack, ca.caReferenceWhite, ca.caContrast, ca.caBrightness, ca.caColorfulness, ca.caRedGreenTint); } Add(_T("Color Space"), _T("0x%X"), GetColorSpace(hDC)); Add(_T("ICM Mode"), _T("%d"), SetICMMode(hDC, ICM_QUERY)); { TCHAR szProfile[MAX_PATH]; DWORD dwSize = MAX_PATH; szProfile[0] = 0; GetICMProfile(hDC, & dwSize, szProfile); Add(_T("ICM Profile"), _T("%s"), szProfile); } GetCurrentPositionEx(hDC, & pnt); Add(_T("Current Position"), _T("{ %d, %d }"), pnt.x, pnt.y); Add(_T("ROP2"), _T("%d"), GetROP2(hDC)); Add(_T("Background Mode"), _T("%d"), GetBkMode(hDC)); Add(_T("Logical Pen"), _T("0x%X"), GetCurrentObject(hDC, OBJ_PEN)); Add(_T("DC Pen Color"), _T("0x%X"), GetDCPenColor(hDC)); Add(_T("Arc Direction"), _T("%d"), GetArcDirection(hDC)); FLOAT miter; GetMiterLimit(hDC, & miter); Add(_T("Miter Limit"), _T("%f"), miter); Add(_T("Logical Brush"), _T("0x%X"), GetCurrentObject(hDC, OBJ_BRUSH)); Add(_T("DC Brush Color"), _T("0x%X"), GetDCBrushColor(hDC)); GetBrushOrgEx(hDC, & pnt); Add(_T("Brush Origin"), _T("{ %d, %d }"), pnt.x, pnt.y); Add(_T("Polygon Filling Mode"), _T("%d"), GetPolyFillMode(hDC)); Add(_T("Bitmap Stretching Mode"), _T("%d"), GetStretchBltMode(hDC)); Add(_T("Logical Font"), _T("0x%X"), GetCurrentObject(hDC, OBJ_FONT)); Add(_T("Inter-character spacing"), _T("%d"), GetTextCharacterExtra(hDC)); DWORD flag = SetMapperFlags(hDC, 0); SetMapperFlags(hDC, flag); Add(_T("Font Mapper Flags"), _T("0x%X"), flag); Add(_T("Text Alignment"), _T("0x%X"), GetTextAlign(hDC)); Add(_T("Text Justification"), _T("write only"), 0); Add(_T("Layout"), _T("%d"), GetLayout(hDC)); Add(_T("Path"), _T("%d bytes"), GetPath(hDC, NULL, NULL, 0)); RECT rect; int typ = GetClipBox(hDC, & rect); HRGN hRgn = CreateRectRgn(0, 0, 1, 1); GetClipRgn(hDC, hRgn); Add(_T("Clipping"), _T("type %d clip box { %d, %d, %d, %d } size %d bytes"), typ, rect.left, rect.top, rect.right, rect.bottom, GetRegionData(hRgn, 0, NULL) ); GetMetaRgn(hDC, hRgn); GetRgnBox(hRgn, & rect); Add(_T("Meta Region"), _T("size %d bytes, rgn box { %d, %d, %d, %d }"), GetRegionData(hRgn, 0, NULL), rect.left, rect.top, rect.right, rect.bottom); for (int i=1; i<=5; i++) { int rslt = GetRandomRgn(hDC, hRgn, i); if ( rslt==1 ) { GetRgnBox(hRgn, & rect); Add(_T("Random Region"), _T("size %d bytes, rgn box { %d, %d, %d, %d }"), GetRegionData(hRgn, 0, NULL), rect.left, rect.top, rect.right, rect.bottom); } else if ( rslt==0 ) Add(_T("Random Region"), _T("NULL"), 0); else Add(_T("Random Region"), _T("FAIL"), 0); } DeleteObject(hRgn); GetBoundsRect(hDC, & rect, 0); Add(_T("Bounds Rectangle"), _T("{ %d, %d, %d, %d }"), rect.left, rect.top, rect.right, rect.bottom); }
void PolygonTest ( HDC hdc ) { HPEN Pen, OldPen; HBRUSH RedBrush, OldBrush; DWORD Mode; POINT PointsAlternate[] = { { 20, 80 }, { 60, 20 }, { 90, 80 }, { 20, 40 }, { 100, 40 } }; POINT PointsWinding[] = { { 130, 80 }, { 170, 20 }, { 200, 80 }, { 130, 40 }, { 210, 40 } }; POINT Tri1[] = { { 3, 3 }, { 5, 3 }, { 3, 5 } }; POINT Tri2[] = { { 7, 3 }, { 7, 7 }, { 3, 7 }, }; POINT Square1[] = { { 1, 15 }, { 3, 15 }, { 3, 17 }, { 1, 17 } }; POINT Square2[] = { { 5, 15 }, { 7, 15 }, { 7, 17 }, { 5, 17 } }; POINT Square3[] = { { 1, 23 }, { 3, 23 }, { 3, 25 }, { 1, 25 } }; POINT Square4[] = { { 5, 23 }, { 7, 23 }, { 7, 25 }, { 5, 25 } }; POINT Square5[] = { { 1, 31 }, { 3, 31 }, { 3, 33 }, { 1, 33 } }; POINT Square6[] = { { 5, 31 }, { 7, 31 }, { 7, 33 }, { 5, 33 } }; //create a pen to draw the shape Pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0xff)); ASSERT(Pen); RedBrush = CreateSolidBrush(RGB(0xff, 0, 0)); ASSERT(RedBrush); OldPen = (HPEN)SelectObject(hdc, Pen); OldBrush = (HBRUSH)SelectObject(hdc, RedBrush); Mode = GetPolyFillMode(hdc); RoundRect ( hdc, 32, 8, 48, 24, 8, 8 ); SetPolyFillMode(hdc, ALTERNATE); Polygon(hdc,PointsAlternate,nelem(PointsAlternate)); SetPolyFillMode(hdc, WINDING); Polygon(hdc,PointsWinding,nelem(PointsWinding)); Rectangle ( hdc, 1, 1, 10, 10 ); Polygon(hdc,Tri1,nelem(Tri1)); Polygon(hdc,Tri2,nelem(Tri2)); Rectangle ( hdc, 1, 11, 4, 14 ); Rectangle ( hdc, 5, 11, 8, 14 ); Rectangle ( hdc, 9, 11, 12, 14 ); Rectangle ( hdc, 13, 11, 16, 14 ); Polygon(hdc,Square1,nelem(Square1)); Polygon(hdc,Square2,nelem(Square2)); Rectangle ( hdc, 1, 19, 4, 22 ); Rectangle ( hdc, 5, 19, 8, 22 ); Rectangle ( hdc, 9, 19, 12, 22 ); Rectangle ( hdc, 13, 19, 16, 22 ); Polygon(hdc,Square3,nelem(Square3)); Polygon(hdc,Square4,nelem(Square4)); Rectangle ( hdc, 1, 27, 4, 30 ); Rectangle ( hdc, 5, 27, 8, 30 ); Rectangle ( hdc, 9, 27, 12, 30 ); Rectangle ( hdc, 13, 27, 16, 30 ); // switch to null pen to make surey they display correctly DeleteObject ( SelectObject(hdc, OldPen) ); Pen = CreatePen ( PS_NULL, 0, 0 ); ASSERT(Pen); OldPen = (HPEN)SelectObject(hdc, Pen); Polygon(hdc,Square5,nelem(Square5)); Polygon(hdc,Square6,nelem(Square6)); Rectangle ( hdc, 1, 35, 4, 38 ); Rectangle ( hdc, 5, 35, 8, 38 ); Rectangle ( hdc, 9, 35, 12, 38 ); Rectangle ( hdc, 13, 35, 16, 38 ); //cleanup SetPolyFillMode(hdc, Mode); DeleteObject ( SelectObject(hdc, OldPen) ); DeleteObject ( SelectObject(hdc, OldBrush) ); }