Merge to XFA: Kill remaining sprintfs
[pdfium.git] / fpdfsdk / src / fpdfview.cpp
index 6a8f890..c0b39ed 100644 (file)
@@ -303,43 +303,40 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY
        return pDocument;
 }
 
-DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int& docType)\r
-{\r
-       if (!document)\r
-               return FALSE;\r
-\r
-       CPDF_Dictionary* pRoot = ((CPDF_Document*)document)->GetRoot();\r
-       if (!pRoot)\r
-               return FALSE;\r
-\r
-       CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");\r
-       if (!pAcroForm)\r
-               return FALSE;\r
-\r
-       CPDF_Object* pXFA = pAcroForm->GetElement("XFA");\r
-       if (!pXFA)\r
-               return FALSE;\r
-\r
-       FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);\r
-\r
-       if (bDynamicXFA)\r
-               docType = DOCTYPE_DYNIMIC_XFA;\r
-       else\r
-               docType = DOCTYPE_STATIC_XFA;\r
-\r
-       return TRUE;\r
-}
-
-DLLEXPORT  FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document)
+DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int& docType)
 {
-       if (!document) 
+       if (!document)
+               return FALSE;
+
+       CPDF_Document *pdfDoc = (static_cast<CPDFXFA_Document *>(document))->GetPDFDoc();
+       if (!pdfDoc)
+               return FALSE;
+
+       CPDF_Dictionary* pRoot = pdfDoc->GetRoot();
+       if (!pRoot)
+               return FALSE;
+
+       CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
+       if (!pAcroForm)
                return FALSE;
 
-       int iDocType = DOCTYPE_PDF;
-       FX_BOOL hasXFAField = FPDF_HasXFAField(document, iDocType);
-       if (!hasXFAField)
+       CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
+       if (!pXFA)
                return FALSE;
-       return ((CPDFXFA_Document*)document)->LoadXFADoc();
+
+       FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
+
+       if (bDynamicXFA)
+               docType = DOCTYPE_DYNIMIC_XFA;
+       else
+               docType = DOCTYPE_STATIC_XFA;
+
+       return TRUE;
+}
+
+DLLEXPORT  FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document)
+{
+       return document && (static_cast<CPDFXFA_Document *>(document))->LoadXFADoc();
 }
 
 
@@ -575,7 +572,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
 #ifdef DEBUG_TRACE
        {
                char str[128];
-               sprintf(str, "Rendering DIB %d x %d", width, height);
+               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
@@ -593,7 +591,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
        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());
+               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);
@@ -629,7 +628,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
        if (hMemDC == NULL) {
 #if defined(DEBUG) || defined(_DEBUG)
                char str[128];
-               sprintf(str, "Error CreateCompatibleDC. Error code = %d", GetLastError());
+               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);