Chromium Code Reviews| Index: fpdfsdk/fpdfview.cpp |
| diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp |
| index 9bf983974c8e264d925647fb7ad903c2315397a0..1cbace604de0580c2a0086db367cbff5217678f5 100644 |
| --- a/fpdfsdk/fpdfview.cpp |
| +++ b/fpdfsdk/fpdfview.cpp |
| @@ -74,6 +74,10 @@ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
| #endif // PDF_ENABLE_XFA |
| } |
| +CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) { |
| + return static_cast<CFX_DIBitmap*>(bitmap); |
| +} |
| + |
| #ifdef PDF_ENABLE_XFA |
| CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
| m_pFS = pFS; |
| @@ -537,7 +541,6 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
| CRenderContext* pContext = new CRenderContext; |
| pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
| -#if !defined(_WIN32_WCE) |
|
Lei Zhang
2016/05/26 18:11:29
I have separate CL to delete other WinCE code, but
|
| CFX_DIBitmap* pBitmap = nullptr; |
| FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); |
| FX_BOOL bHasImageMask = pPage->HasImageMask(); |
| @@ -546,7 +549,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
| pBitmap->Create(size_x, size_y, FXDIB_Argb); |
| pBitmap->Clear(0x00ffffff); |
| pContext->m_pDevice = new CFX_FxgeDevice; |
| - ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap); |
| + ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach(pBitmap); |
| } else { |
| pContext->m_pDevice = new CFX_WindowsDevice(dc); |
| } |
| @@ -572,50 +575,6 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
| } |
| } |
| } |
| -#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; |
| - |
| - // 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); |
| - FXSYS_memset(pBuffer, 0xff, height * ((width * 3 + 3) / 4 * 4)); |
| - |
| - // Create a device with this external buffer |
| - pContext->m_pBitmap = new CFX_DIBitmap; |
| - pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer); |
| - pContext->m_pDevice = new CPDF_FxgeDevice; |
| - ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); |
| - |
| - // output to bitmap device |
| - FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, |
| - start_y - rect.top, size_x, size_y, rotate, flags); |
| - |
| - // Now output to real device |
| - HDC hMemDC = CreateCompatibleDC(dc); |
| - HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap); |
| - |
| - BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY); |
| - SelectObject(hMemDC, hOldBitmap); |
| - DeleteDC(hMemDC); |
| - |
| -#endif // !defined(_WIN32_WCE) |
| if (bBackgroundAlphaNeeded || bHasImageMask) |
| delete pBitmap; |
| @@ -641,11 +600,12 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
| CRenderContext* pContext = new CRenderContext; |
| pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
| pContext->m_pDevice = new CFX_FxgeDevice; |
| + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); |
| if (flags & FPDF_REVERSE_BYTE_ORDER) { |
| ((CFX_FxgeDevice*)pContext->m_pDevice) |
| - ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
| + ->AttachEx(pBitmap, true, nullptr, false); |
| } else { |
| - ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| + ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach(pBitmap); |
| } |
| FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| @@ -816,32 +776,34 @@ DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, |
| FPDF_DWORD color) { |
| if (!bitmap) |
| return; |
| + |
| CFX_FxgeDevice device; |
| - device.Attach((CFX_DIBitmap*)bitmap); |
| - if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) |
| + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); |
| + device.Attach(pBitmap); |
| + if (!pBitmap->HasAlpha()) |
| color |= 0xFF000000; |
| FX_RECT rect(left, top, left + width, top + height); |
| device.FillRect(&rect, color); |
| } |
| DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) { |
| - return bitmap ? ((CFX_DIBitmap*)bitmap)->GetBuffer() : nullptr; |
| + return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetBuffer() : nullptr; |
| } |
| DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) { |
| - return bitmap ? ((CFX_DIBitmap*)bitmap)->GetWidth() : 0; |
| + return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetWidth() : 0; |
| } |
| DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) { |
| - return bitmap ? ((CFX_DIBitmap*)bitmap)->GetHeight() : 0; |
| + return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetHeight() : 0; |
| } |
| DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { |
| - return bitmap ? ((CFX_DIBitmap*)bitmap)->GetPitch() : 0; |
| + return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetPitch() : 0; |
| } |
| DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { |
| - delete (CFX_DIBitmap*)bitmap; |
| + delete CFXBitmapFromFPDFBitmap(bitmap); |
| } |
| void FPDF_RenderPage_Retail(CRenderContext* pContext, |