diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-02-05 17:33:27 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-02-05 17:33:27 -0800 |
commit | 68ee086a1f61dd9a886c96dae8d30de7c9d535fb (patch) | |
tree | 9d59ba1958663bd204cf64d484afe94d8e5feaf0 /core/src/fpdfapi/fpdf_font | |
parent | e3dbe4db199586bee83f7db3ace142d4c71d0a18 (diff) | |
download | pdfium-68ee086a1f61dd9a886c96dae8d30de7c9d535fb.tar.xz |
Kill off some more unreachable fopen's.
The bstring's read from file is unused.
The load from file paths aren't taken.
R=jam@chromium.org
Review URL: https://codereview.chromium.org/902943003
Diffstat (limited to 'core/src/fpdfapi/fpdf_font')
-rw-r--r-- | core/src/fpdfapi/fpdf_font/font_int.h | 26 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 77 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp | 94 |
3 files changed, 3 insertions, 194 deletions
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; -} |