From 65b7a0c8dd14a8e648712fba2a5f70988e12d138 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 5 Feb 2015 17:39:07 -0800 Subject: Merge to XFA: Kill off some more unreachable fopen's. Original Review URL: https://codereview.chromium.org/902943003 TBR=jam@chromium.org Review URL: https://codereview.chromium.org/895903005 --- core/include/fxcrt/fx_string.h | 1 - core/src/fpdfapi/fpdf_font/font_int.h | 26 ------- core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 77 +------------------ core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp | 94 ------------------------ core/src/fxcrt/fx_basic_bstring.cpp | 16 ---- fpdfsdk/src/javascript/Document.cpp | 23 ------ pdfium.gyp | 1 - 7 files changed, 3 insertions(+), 235 deletions(-) delete mode 100644 core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h index 33634f8379..e4546a0b7c 100644 --- a/core/include/fxcrt/fx_string.h +++ b/core/include/fxcrt/fx_string.h @@ -348,7 +348,6 @@ public: FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; - static CFX_ByteString LoadFromFile(FX_BSTR file_path); #define FXFORMAT_SIGNED 1 #define FXFORMAT_HEX 2 #define FXFORMAT_CAPITAL 4 diff --git a/core/src/fpdfapi/fpdf_font/font_int.h b/core/src/fpdfapi/fpdf_font/font_int.h index 2922ed2308..6048ba981d 100644 --- a/core/src/fpdfapi/fpdf_font/font_int.h +++ b/core/src/fpdfapi/fpdf_font/font_int.h @@ -19,7 +19,6 @@ private: CPDF_CID2UnicodeMap* LoadCID2UnicodeMap(int charset, FX_BOOL bPrompt); void DropAll(FX_BOOL bReload); FX_BOOL m_bPrompted; - FX_LPVOID m_pPackage; CFX_MapByteStringToPtr m_CMaps; CPDF_CID2UnicodeMap* m_CID2UnicodeMaps[6]; }; @@ -139,30 +138,6 @@ typedef struct _FileHeader { FX_DWORD dwDataOffset; FX_DWORD dwRecordSize; } FXMP_FILEHEADER; -class CPDF_FXMP : public CFX_Object -{ -public: - CPDF_FXMP() - { - m_pHeader = NULL; - m_pTable = NULL; - } - ~CPDF_FXMP() - { - if (m_pHeader) { - FX_Free(m_pHeader); - } - } - FX_BOOL IsLoaded() - { - return m_pTable != NULL; - } - FX_BOOL LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid); - FX_LPBYTE GetRecord(FX_DWORD index); -private: - FXMP_FILEHEADER* m_pHeader; - FX_LPBYTE m_pTable; -}; class CPDF_CID2UnicodeMap : public CFX_Object { public: @@ -176,7 +151,6 @@ protected: int m_Charset; const FX_WORD* m_pEmbeddedMap; FX_DWORD m_EmbeddedCount; - CPDF_FXMP* m_pExternalMap; }; class CPDF_ToUnicodeMap : public CFX_Object { diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp index 766fd352b4..cbfa19d084 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -11,28 +11,17 @@ #include "../../../include/fxge/fx_ge.h" #include "../../../include/fxge/fx_freetype.h" extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode); -extern FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name); -extern FX_BOOL FXFC_LoadFile(FX_LPVOID pPackage, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size); -extern void FXFC_ClosePackage(FX_LPVOID pPackage); extern short TT2PDF(int m, FXFT_Face face); extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id); extern FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode); CPDF_CMapManager::CPDF_CMapManager() { m_bPrompted = FALSE; - m_pPackage = NULL; FXSYS_memset32(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); } CPDF_CMapManager::~CPDF_CMapManager() { DropAll(FALSE); - if (m_pPackage) { - FXFC_ClosePackage(m_pPackage); - } -} -FX_LPVOID CPDF_CMapManager::GetPackage(FX_BOOL bPrompt) -{ - return m_pPackage; } CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPromptCJK) { @@ -399,50 +388,7 @@ FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, FX_LPCSTR pName, FX_BO m_bLoaded = TRUE; return TRUE; } - FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK); - FX_LPBYTE pBuffer; - FX_DWORD size; - if (pPackage == NULL || !FXFC_LoadFile(pPackage, m_PredefinedCMap, pBuffer, size)) { - return FALSE; - } - m_pMapping = FX_Alloc(FX_WORD, 65536); - FX_DWORD dwRecodeEndPos = 0; - if (pBuffer[5] == 0) { - FX_DWORD dwStartIndex = *(FX_DWORD*)(pBuffer + 8); - FX_DWORD dwRecordCount = *(FX_DWORD*)(pBuffer + 16); - FX_DWORD dwDataOffset = *(FX_DWORD*)(pBuffer + 20); - if (dwRecordCount * 2 + dwStartIndex * 2 < 65536) { - FXSYS_memcpy32(m_pMapping + dwStartIndex * 2, pBuffer + dwDataOffset, dwRecordCount * 2); - } - dwRecodeEndPos = dwDataOffset + dwRecordCount * 2; - } else if (pBuffer[5] == 2) { - FX_DWORD nSegments = *(FX_DWORD*)(pBuffer + 16); - FX_DWORD dwDataOffset = *(FX_DWORD*)(pBuffer + 20); - dwRecodeEndPos = dwDataOffset + 6 * nSegments; - for (FX_DWORD i = 0; i < nSegments; i ++) { - FX_LPBYTE pRecord = pBuffer + dwDataOffset + i * 6; - FX_WORD IndexStart = *(FX_WORD*)pRecord; - FX_WORD IndexCount = *(FX_WORD*)(pRecord + 2); - FX_WORD CodeStart = *(FX_WORD*)(pRecord + 4); - if (IndexStart + IndexCount < 65536) - for (FX_DWORD j = 0; j < IndexCount; j ++) { - m_pMapping[IndexStart + j ] = (FX_WORD)(CodeStart + j); - } - } - } - if (dwRecodeEndPos < size) { - FX_DWORD dwMapLen = *(FX_DWORD*)(pBuffer + dwRecodeEndPos); - if (dwMapLen) { - m_pUseMap = FX_NEW CPDF_CMap; - CFX_ByteString bsName(pBuffer + dwRecodeEndPos + 4 , dwMapLen); - if (m_pUseMap) { - m_pUseMap->LoadPredefined(pMgr, bsName, bPromptCJK); - } - } - } - FX_Free(pBuffer); - m_bLoaded = TRUE; - return TRUE; + return FALSE; } extern "C" { static int compare_dword(const void* data1, const void* data2) @@ -718,22 +664,17 @@ int CPDF_CMap::AppendChar(FX_LPSTR str, FX_DWORD charcode) const CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() { m_EmbeddedCount = 0; - m_pExternalMap = NULL; } CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() { - if (m_pExternalMap) { - delete m_pExternalMap; - } } FX_BOOL CPDF_CID2UnicodeMap::Initialize() { - m_pExternalMap = FX_NEW CPDF_FXMP; return TRUE; } FX_BOOL CPDF_CID2UnicodeMap::IsLoaded() { - return m_EmbeddedCount != 0 || (m_pExternalMap != NULL && m_pExternalMap->IsLoaded()); + return m_EmbeddedCount != 0; } FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) { @@ -743,25 +684,13 @@ FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID) if (CID < m_EmbeddedCount) { return m_pEmbeddedMap[CID]; } - FX_LPCBYTE record = m_pExternalMap->GetRecord(CID); - if (record == NULL) { - return 0; - } - return *(FX_WORD*)record; + return 0; } void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& count); void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK) { m_Charset = charset; FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); - if (m_EmbeddedCount) { - return; - } - FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK); - if (pPackage == NULL) { - return; - } - m_pExternalMap->LoadFile(pPackage, FX_BSTRC("CIDInfo_") + g_CharsetNames[charset]); } #include "ttgsubtable.h" CPDF_CIDFont::CPDF_CIDFont() diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp deleted file mode 100644 index 08aada2a9c..0000000000 --- a/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "../../../include/fpdfapi/fpdf_module.h" -#include "../../../include/fpdfapi/fpdf_resource.h" -#include "../../../include/fxcodec/fx_codec.h" -#include "font_int.h" -typedef struct { - FXSYS_FILE* m_pFile; - int m_nFiles; - int m_IndexSize; - int m_IndexOffset; -} FXFC_PACKAGE; -FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name) -{ - FXSYS_FILE* file = FXSYS_fopen(name, "rb"); - if (file == NULL) { - return NULL; - } - FX_BYTE buf[256]; - FXSYS_fread(buf, 1, 20, file); - if (*(FX_DWORD*)buf != 0x43465846) { - FXSYS_fclose(file); - return NULL; - } - FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1); - pPackage->m_pFile = file; - pPackage->m_nFiles = *(int*)(buf + 8); - pPackage->m_IndexSize = *(int*)(buf + 12); - pPackage->m_IndexOffset = *(int*)(buf + 16); - return pPackage; -} -void FXFC_ClosePackage(FX_LPVOID p) -{ - FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; - FXSYS_fclose(pPackage->m_pFile); - FX_Free(pPackage); -} -FX_BOOL FXFC_LoadFile(FX_LPVOID p, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size) -{ - FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; - FXSYS_fseek(pPackage->m_pFile, pPackage->m_IndexOffset, FXSYS_SEEK_SET); - FX_BYTE buf[128]; - for (int i = 0; i < pPackage->m_nFiles; i ++) { - FXSYS_fread(buf, pPackage->m_IndexSize, 1, pPackage->m_pFile); - if (FXSYS_stricmp((FX_LPCSTR)buf, name) == 0) { - FX_DWORD offset = *(FX_DWORD*)&buf[64]; - size = *(FX_DWORD*)&buf[68]; - pBuffer = FX_Alloc(FX_BYTE, size); - FXSYS_fseek(pPackage->m_pFile, offset, FXSYS_SEEK_SET); - FXSYS_fread(pBuffer, size, 1, pPackage->m_pFile); - if (buf[72]) { - FX_DWORD orig_size; - FX_LPBYTE comp_buf = pBuffer; - CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(FALSE, comp_buf, size, FALSE, - 0, 0, 0, 0, 0, pBuffer, orig_size); - FX_Free(comp_buf); - size = orig_size; - } - return TRUE; - } - } - return FALSE; -} -FX_BOOL CPDF_FXMP::LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid) -{ - if (m_pHeader) { - FX_Free(m_pHeader); - m_pHeader = NULL; - } - m_pTable = NULL; - FX_DWORD size; - if (!FXFC_LoadFile(pPackage, fileid, (FX_LPBYTE&)m_pHeader, size)) { - return FALSE; - } - if (FXSYS_memcmp32(m_pHeader, "FXMP", 4)) { - return FALSE; - } - m_pTable = (FX_LPBYTE)m_pHeader + m_pHeader->dwDataOffset; - return TRUE; -} -FX_LPBYTE CPDF_FXMP::GetRecord(FX_DWORD index) -{ - if (m_pTable == NULL) { - return NULL; - } - if ((int)index < (int)m_pHeader->dwStartIndex || index > m_pHeader->dwEndIndex) { - return NULL; - } - return m_pTable + (index - m_pHeader->dwStartIndex) * m_pHeader->dwRecordSize; -} diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp index 39104e29f6..5c8a2fa8f3 100644 --- a/core/src/fxcrt/fx_basic_bstring.cpp +++ b/core/src/fxcrt/fx_basic_bstring.cpp @@ -936,22 +936,6 @@ void CFX_ByteString::SetAt(FX_STRSIZE nIndex, FX_CHAR ch) CopyBeforeWrite(); m_pData->m_String[nIndex] = ch; } -CFX_ByteString CFX_ByteString::LoadFromFile(FX_BSTR filename) -{ - FXSYS_FILE* file = FXSYS_fopen(CFX_ByteString(filename), "rb"); - if (file == NULL) { - return CFX_ByteString(); - } - FXSYS_fseek(file, 0, FXSYS_SEEK_END); - int len = FXSYS_ftell(file); - FXSYS_fseek(file, 0, FXSYS_SEEK_SET); - CFX_ByteString str; - FX_LPSTR buf = str.GetBuffer(len); - FXSYS_fread(buf, 1, len, file); - str.ReleaseBuffer(len); - FXSYS_fclose(file); - return str; -} CFX_WideString CFX_ByteString::UTF8Decode() const { CFX_UTF8Decoder decoder; diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index 8a5ab6b454..107ce86731 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -1158,29 +1158,6 @@ FX_BOOL Document::filesize(OBJ_PROP_PARAMS) { if (!vp.IsGetting())return FALSE; - ASSERT(m_pDocument != NULL); - -// CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone); -// vp << (double)file.GetLength(); -// file.Close(); - - if ( m_pDocument->GetPath().IsEmpty() == FALSE) - { - CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() ); - FILE * pFile = NULL; - pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" ); - if ( pFile ) - { - fseek( pFile, 0, SEEK_END ); - long lSize = ftell( pFile ); - fclose( pFile ); - pFile = NULL; - - vp << (FX_INT32)(lSize); - return TRUE; - } - } - vp << 0; return TRUE; } diff --git a/pdfium.gyp b/pdfium.gyp index 96f0e5ce1f..426306d2d0 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -273,7 +273,6 @@ 'core/src/fpdfapi/fpdf_font/fpdf_font.cpp', 'core/src/fpdfapi/fpdf_font/fpdf_font_charset.cpp', 'core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp', - 'core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp', 'core/src/fpdfapi/fpdf_font/ttgsubtable.cpp', 'core/src/fpdfapi/fpdf_font/ttgsubtable.h', 'core/src/fpdfapi/fpdf_page/fpdf_page.cpp', -- cgit v1.2.3