CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString() { CFX_ByteString dtStr; char tempStr[32]; memset(tempStr, 0, sizeof(tempStr)); FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second); dtStr = CFX_ByteString(tempStr); if (dt.tzHour < 0) dtStr += CFX_ByteString("-"); else dtStr += CFX_ByteString("+"); memset(tempStr, 0, sizeof(tempStr)); FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute); dtStr += CFX_ByteString(tempStr); return dtStr; }
static void _png_load_bmp_attribute(png_structp png_ptr, png_infop info_ptr, CFX_DIBAttribute* pAttribute) { if (pAttribute) { #if defined(PNG_pHYs_SUPPORTED) pAttribute->m_nXDPI = png_get_x_pixels_per_meter(png_ptr, info_ptr); pAttribute->m_nYDPI = png_get_y_pixels_per_meter(png_ptr, info_ptr); png_uint_32 res_x, res_y; int unit_type; png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); switch (unit_type) { case PNG_RESOLUTION_METER: pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER; break; default: pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_NONE; } #endif #if defined(PNG_iCCP_SUPPORTED) png_charp icc_name; png_bytep icc_profile; png_uint_32 icc_proflen; int compress_type; png_get_iCCP(png_ptr, info_ptr, &icc_name, &compress_type, &icc_profile, &icc_proflen); #endif int bTime = 0; #if defined(PNG_tIME_SUPPORTED) png_timep t = nullptr; png_get_tIME(png_ptr, info_ptr, &t); if (t) { FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime)); FXSYS_snprintf((FX_CHAR*)pAttribute->m_strTime, sizeof(pAttribute->m_strTime), "%4u:%2u:%2u %2u:%2u:%2u", t->year, t->month, t->day, t->hour, t->minute, t->second); pAttribute->m_strTime[sizeof(pAttribute->m_strTime) - 1] = 0; bTime = 1; } #endif #if defined(PNG_TEXT_SUPPORTED) int i; FX_STRSIZE len; const FX_CHAR* buf; int num_text; png_textp text = nullptr; png_get_text(png_ptr, info_ptr, &text, &num_text); for (i = 0; i < num_text; i++) { len = FXSYS_strlen(text[i].key); buf = "Time"; if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { if (!bTime) { FXSYS_memset(pAttribute->m_strTime, 0, sizeof(pAttribute->m_strTime)); FXSYS_memcpy( pAttribute->m_strTime, text[i].text, std::min(sizeof(pAttribute->m_strTime) - 1, text[i].text_length)); } } else { buf = "Author"; if (!FXSYS_memcmp(buf, text[i].key, std::min(len, FXSYS_strlen(buf)))) { pAttribute->m_strAuthor = CFX_ByteString(reinterpret_cast<uint8_t*>(text[i].text), static_cast<FX_STRSIZE>(text[i].text_length)); } } } #endif } }
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 = 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 = new CFX_DIBitmap; pBitmap->Create(size_x, size_y, FXDIB_Argb); pBitmap->Clear(0x00ffffff); #ifdef _SKIA_SUPPORT_ pContext->m_pDevice = new CFX_SkiaDevice; ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap); #else pContext->m_pDevice = new CFX_FxgeDevice; ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap); #endif } else pContext->m_pDevice = new CFX_WindowsDevice(dc); Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate, flags,TRUE,NULL); if (bBackgroundAlphaNeeded) { if (pBitmap) { CFX_WindowsDevice WinDC(dc); if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { CFX_DIBitmap* pDst = new CFX_DIBitmap; int pitch = pBitmap->GetPitch(); pDst->Create(size_x, size_y, FXDIB_Rgb32); FXSYS_memset(pDst->GetBuffer(), -1, pitch*size_y); pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, FXDIB_BLEND_NORMAL, NULL, FALSE, NULL); WinDC.StretchDIBits(pDst,0,0,size_x,size_y); 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]; memset(str, 0, sizeof(str)); FXSYS_snprintf(str, sizeof(str) - 1, "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]; memset(str, 0, sizeof(str)); FXSYS_snprintf(str, sizeof(str) - 1, "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 = 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); #ifdef DEBUG_TRACE CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); #endif // output to bitmap device Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top, size_x, size_y, rotate, flags); #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]; memset(str, 0, sizeof(str)); FXSYS_snprintf(str, sizeof(str) - 1, "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) { delete pBitmap; pBitmap = NULL; } delete pContext; pPage->RemovePrivateData((void*)1); }