DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, int* device_x, int* device_y) { if (page == NULL || device_x == NULL || device_y == NULL) return; CPDF_Page* pPage = (CPDF_Page*)page; CPDF_Matrix page2device; pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); FX_FLOAT device_x_f, device_y_f; page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, device_y_f); *device_x = FXSYS_round(device_x_f); *device_y = FXSYS_round(device_y_f); }
DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, double* page_x, double* page_y) { if (page == NULL || page_x == NULL || page_y == NULL) return; CPDF_Page* pPage = (CPDF_Page*)page; CPDF_Matrix page2device; pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate); CPDF_Matrix device2page; device2page.SetReverse(page2device); FX_FLOAT page_x_f, page_y_f; device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, page_y_f); *page_x = (page_x_f); *page_y = (page_y_f); }
static void renderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int destLeft, int destTop, int destRight, int destBottom, SkMatrix* transform, int flags) { // Note: this code ignores the currently unused RENDER_NO_NATIVETEXT, // FPDF_RENDER_LIMITEDIMAGECACHE, FPDF_RENDER_FORCEHALFTONE, FPDF_GRAYSCALE, // and FPDF_ANNOT flags. To add support for that refer to FPDF_RenderPage_Retail // in fpdfview.cpp CRenderContext* pContext = FX_NEW CRenderContext; CPDF_Page* pPage = (CPDF_Page*) page; pPage->SetPrivateData((void*) 1, pContext, DropContext); CFX_FxgeDevice* fxgeDevice = FX_NEW CFX_FxgeDevice; pContext->m_pDevice = fxgeDevice; // Reverse the bytes (last argument TRUE) since the Android // format is ARGB while the renderer uses BGRA internally. fxgeDevice->Attach((CFX_DIBitmap*) bitmap, 0, TRUE); CPDF_RenderOptions* renderOptions = pContext->m_pOptions; if (!renderOptions) { renderOptions = FX_NEW CPDF_RenderOptions; pContext->m_pOptions = renderOptions; } if (flags & FPDF_LCD_TEXT) { renderOptions->m_Flags |= RENDER_CLEARTYPE; } else { renderOptions->m_Flags &= ~RENDER_CLEARTYPE; } const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; renderOptions->m_AddFlags = flags >> 8; renderOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocument, usage); fxgeDevice->SaveState(); FX_RECT clip; clip.left = destLeft; clip.right = destRight; clip.top = destTop; clip.bottom = destBottom; fxgeDevice->SetClip_Rect(&clip); CPDF_RenderContext* pageContext = FX_NEW CPDF_RenderContext; pContext->m_pContext = pageContext; pageContext->Create(pPage); CFX_AffineMatrix matrix; if (!transform) { pPage->GetDisplayMatrix(matrix, destLeft, destTop, destRight - destLeft, destBottom - destTop, 0); } else { // PDF's coordinate system origin is left-bottom while // in graphics it is the top-left, so remap the origin. matrix.Set(1, 0, 0, -1, 0, pPage->GetPageHeight()); SkScalar transformValues[6]; transform->asAffine(transformValues); matrix.Concat(transformValues[SkMatrix::kAScaleX], transformValues[SkMatrix::kASkewY], transformValues[SkMatrix::kASkewX], transformValues[SkMatrix::kAScaleY], transformValues[SkMatrix::kATransX], transformValues[SkMatrix::kATransY]); } pageContext->AppendObjectList(pPage, &matrix); pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer; pContext->m_pRenderer->Start(pageContext, fxgeDevice, renderOptions, NULL); fxgeDevice->RestoreState(); pPage->RemovePrivateData((void*) 1); delete pContext; }
DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags) { if (!hHandle || !page) return ; CPDF_Page* pPage = (CPDF_Page*)page; CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; else options.m_Flags &= ~RENDER_CLEARTYPE; //Grayscale output if (flags & FPDF_GRAYSCALE) { options.m_ColorMode = RENDER_COLOR_GRAY; options.m_ForeColor = 0; options.m_BackColor = 0xffffff; } options.m_AddFlags = flags >> 8; options.m_pOCContext = FX_NEW CPDF_OCContext(pPage->m_pDocument); //FXMT_CSLOCK_OBJ(&pPage->m_PageLock); CFX_AffineMatrix matrix; pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); FX_RECT clip; clip.left = start_x; clip.right = start_x + size_x; clip.top = start_y; clip.bottom = start_y + size_y; #ifdef _SKIA_SUPPORT_ CFX_SkiaDevice* pDevice = FX_NEW CFX_SkiaDevice; #else CFX_FxgeDevice* pDevice = NULL; pDevice = FX_NEW CFX_FxgeDevice; #endif if (!pDevice) return; pDevice->Attach((CFX_DIBitmap*)bitmap); pDevice->SaveState(); pDevice->SetClip_Rect(&clip); CPDF_RenderContext* pContext = NULL; pContext = FX_NEW CPDF_RenderContext; if (!pContext) { delete pDevice; pDevice = NULL; return; } // CPDF_Document* pDoc = pPage->m_pDocument; CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc(); if(!pFXDoc) { delete pContext; delete pDevice; pContext = NULL; pDevice = NULL; return; } if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage)) { pPageView->PageView_OnDraw(pDevice, &matrix, &options); } pDevice->RestoreState(); if(options.m_pOCContext) { delete options.m_pOCContext; options.m_pOCContext = NULL; } if(pContext) { delete pContext; pContext = NULL; } if(pDevice) { delete pDevice; pDevice = NULL; } }
void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause ) { //#ifdef _LICENSED_BUILD_ CPDF_Page* pPage = (CPDF_Page*)page; if (pPage == NULL) return; if (!pContext->m_pOptions) pContext->m_pOptions = new CPDF_RenderOptions; // CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; else pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; if (flags & FPDF_NO_NATIVETEXT) pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; if (flags & FPDF_RENDER_FORCEHALFTONE) pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; //Grayscale output if (flags & FPDF_GRAYSCALE) { pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; pContext->m_pOptions->m_ForeColor = 0; pContext->m_pOptions->m_BackColor = 0xffffff; } const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; pContext->m_pOptions->m_AddFlags = flags >> 8; pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocument, usage); CFX_AffineMatrix matrix; pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); FX_RECT clip; clip.left = start_x; clip.right = start_x + size_x; clip.top = start_y; clip.bottom = start_y + size_y; pContext->m_pDevice->SaveState(); pContext->m_pDevice->SetClip_Rect(&clip); pContext->m_pContext = FX_NEW CPDF_RenderContext; pContext->m_pContext->Create(pPage); pContext->m_pContext->AppendObjectList(pPage, &matrix); if (flags & FPDF_ANNOT) { pContext->m_pAnnots = FX_NEW CPDF_AnnotList(pPage); FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, &matrix, TRUE, NULL); } pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer; pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions, pause); if (bNeedToRestore) { pContext->m_pDevice->RestoreState(); } //#endif }