Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: xfa/fxfa/app/xfa_ffapp.cpp

Issue 2430743003: in the attempt to fix 627393, changed IFX_FileRead's readBlock to return the length it reads
Patch Set: remove .tmp files Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "xfa/fxfa/include/xfa_ffapp.h" 7 #include "xfa/fxfa/include/xfa_ffapp.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "xfa/fgas/font/fgas_stdfontmgr.h" 12 #include "xfa/fgas/font/fgas_stdfontmgr.h"
13 #include "xfa/fwl/core/cfwl_widgetmgr.h" 13 #include "xfa/fwl/core/cfwl_widgetmgr.h"
14 #include "xfa/fxfa/app/xfa_fwladapter.h" 14 #include "xfa/fxfa/app/xfa_fwladapter.h"
15 #include "xfa/fxfa/app/xfa_fwltheme.h" 15 #include "xfa/fxfa/app/xfa_fwltheme.h"
16 #include "xfa/fxfa/include/xfa_ffdoc.h" 16 #include "xfa/fxfa/include/xfa_ffdoc.h"
17 #include "xfa/fxfa/include/xfa_ffdochandler.h" 17 #include "xfa/fxfa/include/xfa_ffdochandler.h"
18 #include "xfa/fxfa/include/xfa_ffwidgethandler.h" 18 #include "xfa/fxfa/include/xfa_ffwidgethandler.h"
19 #include "xfa/fxfa/include/xfa_fontmgr.h" 19 #include "xfa/fxfa/include/xfa_fontmgr.h"
20 20
21 CXFA_FileRead::CXFA_FileRead(const CFX_ArrayTemplate<CPDF_Stream*>& streams) { 21 CXFA_FileRead::CXFA_FileRead(const CFX_ArrayTemplate<CPDF_Stream*>& streams) {
22 m_FileSize = 0;
23 m_nCurPos = 0;
22 int32_t iCount = streams.GetSize(); 24 int32_t iCount = streams.GetSize();
23 for (int32_t i = 0; i < iCount; i++) { 25 for (int32_t i = 0; i < iCount; i++) {
24 CPDF_StreamAcc& acc = m_Data.Add(); 26 CPDF_StreamAcc& acc = m_Data.Add();
25 acc.LoadAllData(streams[i]); 27 acc.LoadAllData(streams[i]);
28 m_FileSize += acc.GetSize();
26 } 29 }
27 } 30 }
28 31
29 CXFA_FileRead::~CXFA_FileRead() {} 32 CXFA_FileRead::~CXFA_FileRead() {}
30 33
31 FX_FILESIZE CXFA_FileRead::GetSize() { 34 FX_BOOL CXFA_FileRead::IsEOF() {
32 uint32_t dwSize = 0; 35 return m_nCurPos >= GetSize();
33 int32_t iCount = m_Data.GetSize();
34 for (int32_t i = 0; i < iCount; i++) {
35 CPDF_StreamAcc& acc = m_Data[i];
36 dwSize += acc.GetSize();
37 }
38 return dwSize;
39 } 36 }
40 37
41 FX_BOOL CXFA_FileRead::ReadBlock(void* buffer, 38 FX_FILESIZE CXFA_FileRead::GetSize() {
42 FX_FILESIZE offset, 39 return m_FileSize;
43 size_t size) { 40 }
41
42 size_t CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) {
43 if (offset < 0 || GetSize() < offset) {
44 return 0;
45 }
46 size_t readSize = std::min(static_cast<size_t>(GetSize() - offset), size);
44 int32_t iCount = m_Data.GetSize(); 47 int32_t iCount = m_Data.GetSize();
45 int32_t index = 0; 48 int32_t index = 0;
46 while (index < iCount) { 49 while (index < iCount) {
47 CPDF_StreamAcc& acc = m_Data[index]; 50 CPDF_StreamAcc& acc = m_Data[index];
48 FX_FILESIZE dwSize = acc.GetSize(); 51 FX_FILESIZE dwSize = acc.GetSize();
49 if (offset < dwSize) { 52 if (offset < dwSize) {
50 break; 53 break;
51 } 54 }
52 offset -= dwSize; 55 offset -= dwSize;
53 index++; 56 index++;
54 } 57 }
55 while (index < iCount) { 58 while (index < iCount) {
56 CPDF_StreamAcc& acc = m_Data[index]; 59 CPDF_StreamAcc& acc = m_Data[index];
57 uint32_t dwSize = acc.GetSize(); 60 uint32_t dwSize = acc.GetSize();
58 size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset)); 61 size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset));
59 FXSYS_memcpy(buffer, acc.GetData() + offset, dwRead); 62 FXSYS_memcpy(buffer, acc.GetData() + offset, dwRead);
60 size -= dwRead; 63 size -= dwRead;
61 if (size == 0) { 64 if (size == 0) {
62 return TRUE; 65 break;
63 } 66 }
64 buffer = (uint8_t*)buffer + dwRead; 67 buffer = (uint8_t*)buffer + dwRead;
65 offset = 0; 68 offset = 0;
66 index++; 69 index++;
67 } 70 }
68 return FALSE; 71 return readSize;
69 } 72 }
70 73
71 void CXFA_FileRead::Release() { 74 void CXFA_FileRead::Release() {
72 delete this; 75 delete this;
73 } 76 }
74 77
75 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) 78 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider)
76 : m_pProvider(pProvider), 79 : m_pProvider(pProvider),
77 m_pWidgetMgrDelegate(nullptr), 80 m_pWidgetMgrDelegate(nullptr),
78 m_pFWLApp(IFWL_App::Create(this)) { 81 m_pFWLApp(IFWL_App::Create(this)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 pDelegate->OnSetCapability(FWL_WGTMGR_DisableThread | 152 pDelegate->OnSetCapability(FWL_WGTMGR_DisableThread |
150 FWL_WGTMGR_DisableForm); 153 FWL_WGTMGR_DisableForm);
151 m_pWidgetMgrDelegate = pDelegate; 154 m_pWidgetMgrDelegate = pDelegate;
152 } 155 }
153 return m_pAdapterWidgetMgr.get(); 156 return m_pAdapterWidgetMgr.get();
154 } 157 }
155 158
156 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const { 159 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const {
157 return m_pProvider->GetTimerMgr(); 160 return m_pProvider->GetTimerMgr();
158 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698