void IW::CRender::DrawToDC(HDC hdc, const Page &page, const CRect & rectDstIn) { CRect rDst, rSrc; ::GetClipBox(hdc, &rDst); const CRect rectSrc(0, 0, page.GetWidth(), page.GetHeight()); if (rDst.IsRectEmpty()) { rDst = rectDstIn; } else { rDst.IntersectRect(&rDst, &rectDstIn); } int cxIn = rectDstIn.right - rectDstIn.left; int cyIn = rectDstIn.bottom - rectDstIn.top; int cxImage = page.GetWidth(); int cyImage = page.GetHeight(); rSrc.left = MulDiv(rDst.left - rectDstIn.left, cxImage, cxIn); rSrc.top = MulDiv(rDst.top - rectDstIn.top, cyImage, cyIn); rSrc.right = MulDiv(rDst.right - rectDstIn.left, cxImage, cxIn); rSrc.bottom = MulDiv(rDst.bottom - rectDstIn.top, cyImage, cyIn); const CSize sizeDst(rDst.Size()); const CSize sizeSrc(rSrc.Size()); if (sizeDst.cx < 1 || sizeDst.cy < 1) return; int nNewMode = COLORONCOLOR; // If the imageOut is large dont Stretch if (!App.Options.m_bDontUseHalfTone && sizeSrc.cx > sizeDst.cx && sizeSrc.cy > sizeDst.cy && (sizeSrc.cx * sizeSrc.cy) < 2000000) { nNewMode = HALFTONE; } int nOldMode = SetStretchBltMode(hdc, nNewMode); DWORD dwFlags = page.GetFlags(); IW::PixelFormat pf = page.GetPixelFormat(); if (pf.HasAlpha() || dwFlags & IW::PageFlags::HasTransparent) { IW::CRender render; if (render.Create(hdc, rDst)) { render.Fill(page.GetBackGround()); render.DrawImage(page, rDst); render.Flip(); } } else { IW::CImageBitmapInfoHeader info(page); const BITMAPINFO *pbmi = info; LONG lAdjustedSourceTop = rSrc.top; // if the origin of bitmap is bottom-left, adjust soruce_rect_top // to be the bottom-left corner instead of the top-left. if (pbmi->bmiHeader.biHeight > 0) { lAdjustedSourceTop = pbmi->bmiHeader.biHeight - rSrc.bottom; } ::StretchDIBits(hdc, rDst.left, // Destination x rDst.top, // Destination y sizeDst.cx, // Destination nWidth sizeDst.cy, // Destination nHeight rSrc.left, // Source x lAdjustedSourceTop, // Source y sizeSrc.cx, // Source nWidth sizeSrc.cy, // Source nHeight page.GetBitmap(), // Pointer to bits pbmi, // BITMAPINFO DIB_RGB_COLORS, // Options SRCCOPY); // Raster operation code (ROP) } SetStretchBltMode(hdc, nOldMode); }