DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags) { if (bitmap == NULL || page == NULL) return; CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = new CRenderContext; pPage->SetPrivateData((void*)1, pContext, DropContext); #ifdef _SKIA_SUPPORT_ pContext->m_pDevice = new CFX_SkiaDevice; if (flags & FPDF_REVERSE_BYTE_ORDER) ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); else ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); #else pContext->m_pDevice = new CFX_FxgeDevice; if (flags & FPDF_REVERSE_BYTE_ORDER) ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); else ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); #endif Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL); delete pContext; pPage->RemovePrivateData((void*)1); }
DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, IFSDK_PAUSE * pause ) { if (bitmap == NULL || page == NULL) return FPDF_RENDER_FAILED; if (!pause) return FPDF_RENDER_FAILED; if (pause->version !=1) return FPDF_RENDER_FAILED; CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = new CRenderContext; pPage->SetPrivateData((void*)1, pContext, DropContext); #ifdef _SKIA_SUPPORT_ pContext->m_pDevice = new CFX_SkiaDevice; if (flags & FPDF_REVERSE_BYTE_ORDER) ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); else ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); #else pContext->m_pDevice = new CFX_FxgeDevice; if (flags & FPDF_REVERSE_BYTE_ORDER) ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,TRUE); else ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); #endif IFSDK_PAUSE_Adapter IPauseAdapter(pause); Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,FALSE, &IPauseAdapter); if ( pContext->m_pRenderer ) { CPDF_ProgressiveRenderer::RenderStatus status = CPDF_ProgressiveRenderer::Failed; status = pContext->m_pRenderer->GetStatus(); return status; } return FPDF_RENDER_FAILED; }
DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags) { if (page==NULL) return; CPDF_Page* pPage = (CPDF_Page*)page; CRenderContext* pContext = FX_NEW CRenderContext; pPage->SetPrivateData((void*)1, pContext, DropContext); #ifndef _WIN32_WCE CFX_DIBitmap* pBitmap = NULL; FX_BOOL bBackgroundAlphaNeeded=FALSE; bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); if (bBackgroundAlphaNeeded) { pBitmap = FX_NEW CFX_DIBitmap; pBitmap->Create(size_x, size_y, FXDIB_Argb); pBitmap->Clear(0x00ffffff); #ifdef _SKIA_SUPPORT_ pContext->m_pDevice = FX_NEW CFX_SkiaDevice; ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap); #else pContext->m_pDevice = FX_NEW CFX_FxgeDevice; ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap); #endif } else pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc); if (flags & FPDF_NO_CATCH) Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL); else { try { Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL); } catch (...) { } } if (bBackgroundAlphaNeeded) { if (pBitmap) { CFX_WindowsDevice WinDC(dc); if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap; pDst->Create(pBitmap->GetWidth(), pBitmap->GetHeight(),FXDIB_Rgb32); FXSYS_memcpy(pDst->GetBuffer(), pBitmap->GetBuffer(), pBitmap->GetPitch()*pBitmap->GetHeight()); // WinDC.SetDIBits(pDst,0,0); WinDC.StretchDIBits(pDst,0,0,size_x*2,size_y*2); delete pDst; } else WinDC.SetDIBits(pBitmap,0,0); } } #else // get clip region RECT rect, cliprect; rect.left = start_x; rect.top = start_y; rect.right = start_x + size_x; rect.bottom = start_y + size_y; GetClipBox(dc, &cliprect); IntersectRect(&rect, &rect, &cliprect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; #ifdef DEBUG_TRACE { char str[128]; sprintf(str, "Rendering DIB %d x %d", width, height); CPDF_ModuleMgr::Get()->ReportError(999, str); } #endif // Create a DIB section LPVOID pBuffer; BITMAPINFOHEADER bmih; FXSYS_memset(&bmih, 0, sizeof bmih); bmih.biSize = sizeof bmih; bmih.biBitCount = 24; bmih.biHeight = -height; bmih.biPlanes = 1; bmih.biWidth = width; pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, &pBuffer, NULL, 0); if (pContext->m_hBitmap == NULL) { #if defined(DEBUG) || defined(_DEBUG) char str[128]; sprintf(str, "Error CreateDIBSection: %d x %d, error code = %d", width, height, GetLastError()); CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); #else CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); #endif } FXSYS_memset(pBuffer, 0xff, height*((width*3+3)/4*4)); #ifdef DEBUG_TRACE { CPDF_ModuleMgr::Get()->ReportError(999, "DIBSection created"); } #endif // Create a device with this external buffer pContext->m_pBitmap = FX_NEW CFX_DIBitmap; pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (FX_LPBYTE)pBuffer); pContext->m_pDevice = FX_NEW CPDF_FxgeDevice; ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); #ifdef DEBUG_TRACE CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); #endif // output to bitmap device if (flags & FPDF_NO_CATCH) Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags); else { try { Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags); } catch (...) { } } #ifdef DEBUG_TRACE CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); #endif // Now output to real device HDC hMemDC = CreateCompatibleDC(dc); if (hMemDC == NULL) { #if defined(DEBUG) || defined(_DEBUG) char str[128]; sprintf(str, "Error CreateCompatibleDC. Error code = %d", GetLastError()); CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); #else CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); #endif } HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap); #ifdef DEBUG_TRACE CPDF_ModuleMgr::Get()->ReportError(999, "Ready for screen rendering"); #endif BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOldBitmap); DeleteDC(hMemDC); #ifdef DEBUG_TRACE CPDF_ModuleMgr::Get()->ReportError(999, "Finished screen rendering"); #endif #endif if (bBackgroundAlphaNeeded) { if (pBitmap) delete pBitmap; pBitmap = NULL; } delete pContext; pPage->RemovePrivateData((void*)1); }