| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../include/fpdfapi/fpdf_module.h" | 7 #include "../../../include/fpdfapi/fpdf_module.h" |
| 8 #include "../../../include/fpdfapi/fpdf_resource.h" | 8 #include "../../../include/fpdfapi/fpdf_resource.h" |
| 9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 #include "font_int.h" | 10 #include "font_int.h" |
| 11 #ifndef _FPDFAPI_MINI_ | 11 #ifndef _FPDFAPI_MINI_ |
| 12 typedef struct { | 12 typedef struct { |
| 13 FXSYS_FILE*»m_pFile; | 13 FXSYS_FILE* m_pFile; |
| 14 int»» m_nFiles; | 14 int m_nFiles; |
| 15 int»» m_IndexSize; | 15 int m_IndexSize; |
| 16 int»» m_IndexOffset; | 16 int m_IndexOffset; |
| 17 } FXFC_PACKAGE; | 17 } FXFC_PACKAGE; |
| 18 FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name) | 18 FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name) { |
| 19 { | 19 FXSYS_FILE* file = FXSYS_fopen(name, (FX_LPCSTR) "rb"); |
| 20 FXSYS_FILE* file = FXSYS_fopen(name, (FX_LPCSTR)"rb"); | 20 if (file == NULL) { |
| 21 if (file == NULL) { | 21 return NULL; |
| 22 return NULL; | 22 } |
| 23 FX_BYTE buf[256]; |
| 24 FXSYS_fread(buf, 1, 20, file); |
| 25 if (*(FX_DWORD*)buf != 0x43465846) { |
| 26 FXSYS_fclose(file); |
| 27 return NULL; |
| 28 } |
| 29 FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1); |
| 30 pPackage->m_pFile = file; |
| 31 pPackage->m_nFiles = *(int*)(buf + 8); |
| 32 pPackage->m_IndexSize = *(int*)(buf + 12); |
| 33 pPackage->m_IndexOffset = *(int*)(buf + 16); |
| 34 return pPackage; |
| 35 } |
| 36 void FXFC_ClosePackage(FX_LPVOID p) { |
| 37 FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; |
| 38 FXSYS_fclose(pPackage->m_pFile); |
| 39 FX_Free(pPackage); |
| 40 } |
| 41 FX_BOOL FXFC_LoadFile(FX_LPVOID p, |
| 42 FX_LPCSTR name, |
| 43 FX_LPBYTE& pBuffer, |
| 44 FX_DWORD& size) { |
| 45 FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; |
| 46 FXSYS_fseek(pPackage->m_pFile, pPackage->m_IndexOffset, FXSYS_SEEK_SET); |
| 47 FX_BYTE buf[128]; |
| 48 for (int i = 0; i < pPackage->m_nFiles; i++) { |
| 49 FXSYS_fread(buf, pPackage->m_IndexSize, 1, pPackage->m_pFile); |
| 50 if (FXSYS_stricmp((FX_LPCSTR)buf, name) == 0) { |
| 51 FX_DWORD offset = *(FX_DWORD*)&buf[64]; |
| 52 size = *(FX_DWORD*)&buf[68]; |
| 53 pBuffer = FX_Alloc(FX_BYTE, size); |
| 54 FXSYS_fseek(pPackage->m_pFile, offset, FXSYS_SEEK_SET); |
| 55 FXSYS_fread(pBuffer, size, 1, pPackage->m_pFile); |
| 56 if (buf[72]) { |
| 57 FX_DWORD orig_size; |
| 58 FX_LPBYTE comp_buf = pBuffer; |
| 59 CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( |
| 60 FALSE, comp_buf, size, FALSE, 0, 0, 0, 0, 0, pBuffer, orig_size); |
| 61 FX_Free(comp_buf); |
| 62 size = orig_size; |
| 63 } |
| 64 return TRUE; |
| 23 } | 65 } |
| 24 FX_BYTE buf[256]; | 66 } |
| 25 FXSYS_fread(buf, 1, 20, file); | 67 return FALSE; |
| 26 if (*(FX_DWORD*)buf != 0x43465846) { | |
| 27 FXSYS_fclose(file); | |
| 28 return NULL; | |
| 29 } | |
| 30 FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1); | |
| 31 pPackage->m_pFile = file; | |
| 32 pPackage->m_nFiles = *(int*)(buf + 8); | |
| 33 pPackage->m_IndexSize = *(int*)(buf + 12); | |
| 34 pPackage->m_IndexOffset = *(int*)(buf + 16); | |
| 35 return pPackage; | |
| 36 } | 68 } |
| 37 void FXFC_ClosePackage(FX_LPVOID p) | 69 FX_BOOL CPDF_FXMP::LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid) { |
| 38 { | 70 if (m_pHeader) { |
| 39 FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; | 71 FX_Free(m_pHeader); |
| 40 FXSYS_fclose(pPackage->m_pFile); | 72 m_pHeader = NULL; |
| 41 FX_Free(pPackage); | 73 } |
| 74 m_pTable = NULL; |
| 75 FX_DWORD size; |
| 76 if (!FXFC_LoadFile(pPackage, fileid, (FX_LPBYTE&)m_pHeader, size)) { |
| 77 return FALSE; |
| 78 } |
| 79 if (FXSYS_memcmp32(m_pHeader, "FXMP", 4)) { |
| 80 return FALSE; |
| 81 } |
| 82 m_pTable = (FX_LPBYTE)m_pHeader + m_pHeader->dwDataOffset; |
| 83 return TRUE; |
| 42 } | 84 } |
| 43 FX_BOOL FXFC_LoadFile(FX_LPVOID p, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD&
size) | 85 FX_LPBYTE CPDF_FXMP::GetRecord(FX_DWORD index) { |
| 44 { | 86 if (m_pTable == NULL) { |
| 45 FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p; | 87 return NULL; |
| 46 FXSYS_fseek(pPackage->m_pFile, pPackage->m_IndexOffset, FXSYS_SEEK_SET); | 88 } |
| 47 FX_BYTE buf[128]; | 89 if ((int)index < (int)m_pHeader->dwStartIndex || |
| 48 for (int i = 0; i < pPackage->m_nFiles; i ++) { | 90 index > m_pHeader->dwEndIndex) { |
| 49 FXSYS_fread(buf, pPackage->m_IndexSize, 1, pPackage->m_pFile); | 91 return NULL; |
| 50 if (FXSYS_stricmp((FX_LPCSTR)buf, name) == 0) { | 92 } |
| 51 FX_DWORD offset = *(FX_DWORD*)&buf[64]; | 93 return m_pTable + (index - m_pHeader->dwStartIndex) * m_pHeader->dwRecordSize; |
| 52 size = *(FX_DWORD*)&buf[68]; | |
| 53 pBuffer = FX_Alloc(FX_BYTE, size); | |
| 54 FXSYS_fseek(pPackage->m_pFile, offset, FXSYS_SEEK_SET); | |
| 55 FXSYS_fread(pBuffer, size, 1, pPackage->m_pFile); | |
| 56 if (buf[72]) { | |
| 57 FX_DWORD orig_size; | |
| 58 FX_LPBYTE comp_buf = pBuffer; | |
| 59 CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(FALSE,
comp_buf, size, FALSE, | |
| 60 0, 0, 0, 0, 0, pBuffer, orig_size); | |
| 61 FX_Free(comp_buf); | |
| 62 size = orig_size; | |
| 63 } | |
| 64 return TRUE; | |
| 65 } | |
| 66 } | |
| 67 return FALSE; | |
| 68 } | |
| 69 FX_BOOL CPDF_FXMP::LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid) | |
| 70 { | |
| 71 if (m_pHeader) { | |
| 72 FX_Free(m_pHeader); | |
| 73 m_pHeader = NULL; | |
| 74 } | |
| 75 m_pTable = NULL; | |
| 76 FX_DWORD size; | |
| 77 if (!FXFC_LoadFile(pPackage, fileid, (FX_LPBYTE&)m_pHeader, size)) { | |
| 78 return FALSE; | |
| 79 } | |
| 80 if (FXSYS_memcmp32(m_pHeader, "FXMP", 4)) { | |
| 81 return FALSE; | |
| 82 } | |
| 83 m_pTable = (FX_LPBYTE)m_pHeader + m_pHeader->dwDataOffset; | |
| 84 return TRUE; | |
| 85 } | |
| 86 FX_LPBYTE CPDF_FXMP::GetRecord(FX_DWORD index) | |
| 87 { | |
| 88 if (m_pTable == NULL) { | |
| 89 return NULL; | |
| 90 } | |
| 91 if ((int)index < (int)m_pHeader->dwStartIndex || index > m_pHeader->dwEndInd
ex) { | |
| 92 return NULL; | |
| 93 } | |
| 94 return m_pTable + (index - m_pHeader->dwStartIndex) * m_pHeader->dwRecordSiz
e; | |
| 95 } | 94 } |
| 96 #endif | 95 #endif |
| OLD | NEW |