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

Side by Side Diff: fpdfsdk/src/fpdfview.cpp

Issue 1233453014: Refactor progressive renderer class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits. Created 5 years, 5 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
« no previous file with comments | « fpdfsdk/src/fpdf_progressive.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "../../core/include/fxcodec/fx_codec.h" 7 #include "../../core/include/fxcodec/fx_codec.h"
8 #include "../../core/include/fxcrt/fx_safe_types.h" 8 #include "../../core/include/fxcrt/fx_safe_types.h"
9 #include "../../public/fpdf_ext.h" 9 #include "../../public/fpdf_ext.h"
10 #include "../../public/fpdf_progressive.h" 10 #include "../../public/fpdf_progressive.h"
11 #include "../../public/fpdfview.h" 11 #include "../../public/fpdfview.h"
12 #include "../../third_party/base/nonstd_unique_ptr.h" 12 #include "../../third_party/base/nonstd_unique_ptr.h"
13 #include "../../third_party/base/numerics/safe_conversions_impl.h" 13 #include "../../third_party/base/numerics/safe_conversions_impl.h"
14 #include "../include/fsdk_define.h" 14 #include "../include/fsdk_define.h"
15 #include "../include/fsdk_mgr.h" 15 #include "../include/fsdk_mgr.h"
16 #include "../include/fsdk_rendercontext.h" 16 #include "../include/fsdk_rendercontext.h"
17 17
18 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) 18 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
19 { 19 {
20 » if (pFileAccess) 20 if (pFileAccess)
21 » » m_FileAccess = *pFileAccess; 21 m_FileAccess = *pFileAccess;
22 } 22 }
23 23
24 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si ze) 24 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si ze)
25 { 25 {
26 if (offset < 0) { 26 if (offset < 0) {
27 return FALSE; 27 return FALSE;
28 } 28 }
29 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, size_t>(si ze); 29 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, size_t>(si ze);
30 newPos += offset; 30 newPos += offset;
31 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { 31 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) {
32 return FALSE; 32 return FALSE;
33 } 33 }
34 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(uint8_t*) buffe r, size); 34 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,(uint8_t*) buffe r, size);
35 } 35 }
36 36
37 //0 bit: FPDF_POLICY_MACHINETIME_ACCESS 37 //0 bit: FPDF_POLICY_MACHINETIME_ACCESS
38 static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF; 38 static FX_DWORD foxit_sandbox_policy = 0xFFFFFFFF;
39 39
40 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) 40 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable)
41 { 41 {
42 » switch(policy) 42 switch(policy)
43 » { 43 {
44 » case FPDF_POLICY_MACHINETIME_ACCESS: 44 case FPDF_POLICY_MACHINETIME_ACCESS:
45 » » { 45 {
46 » » » if(enable) 46 if(enable)
47 » » » » foxit_sandbox_policy |= 0x01; 47 foxit_sandbox_policy |= 0x01;
48 » » » else 48 else
49 » » » » foxit_sandbox_policy &= 0xFFFFFFFE; 49 foxit_sandbox_policy &= 0xFFFFFFFE;
50 » » } 50 }
51 » » break; 51 break;
52 » default: 52 default:
53 » » break; 53 break;
54 » } 54 }
55 } 55 }
56 56
57 FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy) 57 FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy)
58 { 58 {
59 » switch(policy) 59 switch(policy)
60 » { 60 {
61 » case FPDF_POLICY_MACHINETIME_ACCESS: 61 case FPDF_POLICY_MACHINETIME_ACCESS:
62 » » { 62 return (foxit_sandbox_policy & 0x01) ? TRUE : FALSE;
Tom Sepez 2015/07/17 16:58:22 Note: There are important philosophical points to
63 » » » if(foxit_sandbox_policy&0x01) 63 default:
64 » » » » return TRUE; 64 return FALSE;
65 » » » else 65 }
66 » » » » return FALSE;
67 » » }
68 » » break;
69 » default:
70 » » break;
71 » }
72 » return FALSE;
73 } 66 }
74 67
75
76 #ifndef _T 68 #ifndef _T
77 #define _T(x) x 69 #define _T(x) x
78 #endif 70 #endif
79 71
80 CCodec_ModuleMgr* g_pCodecModule = nullptr; 72 CCodec_ModuleMgr* g_pCodecModule = nullptr;
81 73
82 #if _FX_OS_ == _FX_LINUX_EMBEDDED_ 74 #if _FX_OS_ == _FX_LINUX_EMBEDDED_
83 class CFontMapper : public IPDF_FontMapper 75 class CFontMapper : public IPDF_FontMapper
84 { 76 {
85 public: 77 public:
86 » CFontMapper(); 78 CFontMapper();
87 » virtual ~CFontMapper(); 79 virtual ~CFontMapper();
88 80
89 » virtual FT_Face FindSubstFont( 81 virtual FT_Face FindSubstFont(
90 » » » » » » » CPDF_Document* pDoc,» » » » // [IN] The PDF document 82 CPDF_Document* pDoc, // [IN] The PDF document
91 » » » » » » » const CFX_ByteString& fa ce_name,» // [IN] Original name 83 const CFX_ByteString& face_name, // [IN] Original name
92 » » » » » » » FX_BOOL bTrueType,» » » » » // [IN] TrueType or Type1 84 FX_BOOL bTrueType, // [IN] TrueType or Type1
93 » » » » » » » FX_DWORD flags,»» » » » » // [IN] PDF font flags (see PDF Reference sectio n 5.7.1) 85 FX_DWORD flags, // [IN] PDF font flags (see PDF Reference section 5.7.1)
94 » » » » » » » int font_weight,» » » » » // [IN] original font weight. 0 for not specifie d 86 int font_weight, // [IN] original font weight. 0 for not specified
95 » » » » » » » int CharsetCP,» » » » » » // [IN] code page for charset (see Win32 GetACP( )) 87 int CharsetCP, // [IN] code pag e for charset (see Win32 GetACP())
96 » » » » » » » FX_BOOL bVertical, 88 FX_BOOL bVertical,
97 » » » » » » » CPDF_SubstFont* pSubstFo nt» » » // [OUT] Subst font data 89 CPDF_SubstFont* pSubstFont // [OUT] Subst f ont data
98 » » » » » » ); 90 );
99 91
100 » FT_Face m_SysFace; 92 FT_Face m_SysFace;
101 }; 93 };
102 94
103 CFontMapper* g_pFontMapper = NULL; 95 CFontMapper* g_pFontMapper = NULL;
104 #endif» » // #if _FX_OS_ == _FX_LINUX_EMBEDDED_ 96 #endif // #if _FX_OS_ == _FX_LINUX_EMBEDDED_
105 97
106 DLLEXPORT void STDCALL FPDF_InitLibrary() 98 DLLEXPORT void STDCALL FPDF_InitLibrary()
107 { 99 {
108 » g_pCodecModule = new CCodec_ModuleMgr(); 100 g_pCodecModule = new CCodec_ModuleMgr();
109 101
110 » CFX_GEModule::Create(); 102 CFX_GEModule::Create();
111 » CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); 103 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule);
112 104
113 » CPDF_ModuleMgr::Create(); 105 CPDF_ModuleMgr::Create();
114 » CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule); 106 CPDF_ModuleMgr::Get()->SetCodecModule(g_pCodecModule);
115 » CPDF_ModuleMgr::Get()->InitPageModule(); 107 CPDF_ModuleMgr::Get()->InitPageModule();
116 » CPDF_ModuleMgr::Get()->InitRenderModule(); 108 CPDF_ModuleMgr::Get()->InitRenderModule();
117 » CPDF_ModuleMgr * pModuleMgr = CPDF_ModuleMgr::Get(); 109 CPDF_ModuleMgr * pModuleMgr = CPDF_ModuleMgr::Get();
118 » if ( pModuleMgr ) 110 if ( pModuleMgr )
119 » { 111 {
120 » » pModuleMgr->LoadEmbeddedGB1CMaps(); 112 pModuleMgr->LoadEmbeddedGB1CMaps();
121 » » pModuleMgr->LoadEmbeddedJapan1CMaps(); 113 pModuleMgr->LoadEmbeddedJapan1CMaps();
122 » » pModuleMgr->LoadEmbeddedCNS1CMaps(); 114 pModuleMgr->LoadEmbeddedCNS1CMaps();
123 » » pModuleMgr->LoadEmbeddedKorea1CMaps(); 115 pModuleMgr->LoadEmbeddedKorea1CMaps();
124 » } 116 }
125 } 117 }
126 118
127 119
128 DLLEXPORT void STDCALL FPDF_DestroyLibrary() 120 DLLEXPORT void STDCALL FPDF_DestroyLibrary()
129 { 121 {
130 122
131 #if _FX_OS_ == _FX_LINUX_EMBEDDED_ 123 #if _FX_OS_ == _FX_LINUX_EMBEDDED_
132 » delete g_pFontMapper; 124 delete g_pFontMapper;
133 » g_pFontMapper = nullptr; 125 g_pFontMapper = nullptr;
134 #endif 126 #endif
135 » CPDF_ModuleMgr::Destroy(); 127 CPDF_ModuleMgr::Destroy();
136 » CFX_GEModule::Destroy(); 128 CFX_GEModule::Destroy();
137 » delete g_pCodecModule; 129 delete g_pCodecModule;
138 » g_pCodecModule = nullptr; 130 g_pCodecModule = nullptr;
139 } 131 }
140 132
141 #ifndef _WIN32 133 #ifndef _WIN32
142 int g_LastError; 134 int g_LastError;
143 void SetLastError(int err) 135 void SetLastError(int err)
144 { 136 {
145 » g_LastError = err; 137 g_LastError = err;
146 } 138 }
147 139
148 int GetLastError() 140 int GetLastError()
149 { 141 {
150 » return g_LastError; 142 return g_LastError;
151 } 143 }
152 #endif 144 #endif
153 145
154 void ProcessParseError(FX_DWORD err_code) 146 void ProcessParseError(FX_DWORD err_code)
155 { 147 {
156 » // Translate FPDFAPI error code to FPDFVIEW error code 148 // Translate FPDFAPI error code to FPDFVIEW error code
157 » switch (err_code) { 149 switch (err_code) {
158 » » case PDFPARSE_ERROR_FILE: 150 case PDFPARSE_ERROR_FILE:
159 » » » err_code = FPDF_ERR_FILE; 151 err_code = FPDF_ERR_FILE;
160 » » » break; 152 break;
161 » » case PDFPARSE_ERROR_FORMAT: 153 case PDFPARSE_ERROR_FORMAT:
162 » » » err_code = FPDF_ERR_FORMAT; 154 err_code = FPDF_ERR_FORMAT;
163 » » » break; 155 break;
164 » » case PDFPARSE_ERROR_PASSWORD: 156 case PDFPARSE_ERROR_PASSWORD:
165 » » » err_code = FPDF_ERR_PASSWORD; 157 err_code = FPDF_ERR_PASSWORD;
166 » » » break; 158 break;
167 » » case PDFPARSE_ERROR_HANDLER: 159 case PDFPARSE_ERROR_HANDLER:
168 » » » err_code = FPDF_ERR_SECURITY; 160 err_code = FPDF_ERR_SECURITY;
169 » » » break; 161 break;
170 » } 162 }
171 » SetLastError(err_code); 163 SetLastError(err_code);
172 } 164 }
173 165
174 DLLEXPORT void» STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enabl e) 166 DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enabl e)
175 { 167 {
176 » return FSDK_SetSandBoxPolicy(policy, enable); 168 return FSDK_SetSandBoxPolicy(policy, enable);
177 } 169 }
178 170
179 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY TESTRING password) 171 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY TESTRING password)
180 { 172 {
181 » CPDF_Parser* pParser = new CPDF_Parser; 173 CPDF_Parser* pParser = new CPDF_Parser;
182 » pParser->SetPassword(password); 174 pParser->SetPassword(password);
183 175
184 » FX_DWORD err_code = pParser->StartParse((const FX_CHAR*)file_path); 176 FX_DWORD err_code = pParser->StartParse((const FX_CHAR*)file_path);
185 » if (err_code) { 177 if (err_code) {
186 » » delete pParser; 178 delete pParser;
187 » » ProcessParseError(err_code); 179 ProcessParseError(err_code);
188 » » return NULL; 180 return NULL;
189 » } 181 }
190 » return pParser->GetDocument(); 182 return pParser->GetDocument();
191 } 183 }
192 184
193 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code); 185 extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
194 186
195 class CMemFile final: public IFX_FileRead 187 class CMemFile final: public IFX_FileRead
196 { 188 {
197 public: 189 public:
198 » CMemFile(uint8_t* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {} 190 CMemFile(uint8_t* pBuf, FX_FILESIZE size):m_pBuf(pBuf),m_size(size) {}
199 191
200 » virtual void» » » Release() {delete this;} 192 virtual void Release() {delete this;}
201 » virtual FX_FILESIZE» » GetSize() {return m_size;} 193 virtual FX_FILESIZE GetSize() {return m_size;}
202 » virtual FX_BOOL»» » ReadBlock(void* buffer, FX_FILESIZE offs et, size_t size) 194 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t s ize)
203 » { 195 {
204 if (offset < 0) { 196 if (offset < 0) {
205 return FALSE; 197 return FALSE;
206 } 198 }
207 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, si ze_t>(size); 199 FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE, si ze_t>(size);
208 newPos += offset; 200 newPos += offset;
209 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) { 201 if (!newPos.IsValid() || newPos.ValueOrDie() > (FX_DWORD)m_size) {
210 return FALSE; 202 return FALSE;
211 } 203 }
212 » FXSYS_memcpy(buffer, m_pBuf+offset, size); 204 FXSYS_memcpy(buffer, m_pBuf+offset, size);
213 » return TRUE; 205 return TRUE;
214 » } 206 }
215 private: 207 private:
216 » uint8_t* m_pBuf; 208 uint8_t* m_pBuf;
217 » FX_FILESIZE m_size; 209 FX_FILESIZE m_size;
218 }; 210 };
219 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s ize, FPDF_BYTESTRING password) 211 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s ize, FPDF_BYTESTRING password)
220 { 212 {
221 » CPDF_Parser* pParser = new CPDF_Parser; 213 CPDF_Parser* pParser = new CPDF_Parser;
222 » pParser->SetPassword(password); 214 pParser->SetPassword(password);
223 » CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); 215 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size);
224 » FX_DWORD err_code = pParser->StartParse(pMemFile); 216 FX_DWORD err_code = pParser->StartParse(pMemFile);
225 » if (err_code) { 217 if (err_code) {
226 » » delete pParser; 218 delete pParser;
227 » » ProcessParseError(err_code); 219 ProcessParseError(err_code);
228 » » return NULL; 220 return NULL;
229 » } 221 }
230 » CPDF_Document * pDoc = NULL; 222 CPDF_Document * pDoc = NULL;
231 » pDoc = pParser?pParser->GetDocument():NULL; 223 pDoc = pParser?pParser->GetDocument():NULL;
232 » CheckUnSupportError(pDoc, err_code); 224 CheckUnSupportError(pDoc, err_code);
233 » return pParser->GetDocument(); 225 return pParser->GetDocument();
234 } 226 }
235 227
236 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAc cess, FPDF_BYTESTRING password) 228 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAc cess, FPDF_BYTESTRING password)
237 { 229 {
238 » CPDF_Parser* pParser = new CPDF_Parser; 230 CPDF_Parser* pParser = new CPDF_Parser;
239 » pParser->SetPassword(password); 231 pParser->SetPassword(password);
240 » CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); 232 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess);
241 » FX_DWORD err_code = pParser->StartParse(pFile); 233 FX_DWORD err_code = pParser->StartParse(pFile);
242 » if (err_code) { 234 if (err_code) {
243 » » delete pParser; 235 delete pParser;
244 » » ProcessParseError(err_code); 236 ProcessParseError(err_code);
245 » » return NULL; 237 return NULL;
246 » } 238 }
247 » CPDF_Document * pDoc = NULL; 239 CPDF_Document * pDoc = NULL;
248 » pDoc = pParser?pParser->GetDocument():NULL; 240 pDoc = pParser?pParser->GetDocument():NULL;
249 » CheckUnSupportError(pDoc, err_code); 241 CheckUnSupportError(pDoc, err_code);
250 » return pParser->GetDocument(); 242 return pParser->GetDocument();
251 } 243 }
252 244
253 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVers ion) 245 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVers ion)
254 { 246 {
255 » if(!doc||!fileVersion) return FALSE; 247 if(!doc||!fileVersion) return FALSE;
256 » *fileVersion = 0; 248 *fileVersion = 0;
257 » CPDF_Document* pDoc = (CPDF_Document*)doc; 249 CPDF_Document* pDoc = (CPDF_Document*)doc;
258 » CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 250 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
259 » if(!pParser) 251 if(!pParser)
260 » » return FALSE; 252 return FALSE;
261 » *fileVersion = pParser->GetFileVersion(); 253 *fileVersion = pParser->GetFileVersion();
262 » return TRUE; 254 return TRUE;
263 } 255 }
264 256
265 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match h eader). 257 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match h eader).
266 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) 258 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document)
267 { 259 {
268 » if (document == NULL) return 0; 260 if (document == NULL) return 0;
269 » CPDF_Document*pDoc = (CPDF_Document*)document; 261 CPDF_Document*pDoc = (CPDF_Document*)document;
270 » CPDF_Parser* pParser = »(CPDF_Parser*)pDoc->GetParser(); 262 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
271 » CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 263 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
272 » if (pDict == NULL) return (FX_DWORD)-1; 264 if (pDict == NULL) return (FX_DWORD)-1;
273 265
274 » return pDict->GetInteger("P"); 266 return pDict->GetInteger("P");
275 } 267 }
276 268
277 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) 269 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document)
278 { 270 {
279 if (document == NULL) return -1; 271 if (document == NULL) return -1;
280 CPDF_Document*pDoc = (CPDF_Document*)document; 272 CPDF_Document*pDoc = (CPDF_Document*)document;
281 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 273 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
282 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 274 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
283 if (pDict == NULL) return -1; 275 if (pDict == NULL) return -1;
284 276
285 return pDict->GetInteger("R"); 277 return pDict->GetInteger("R");
286 } 278 }
287 279
288 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) 280 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document)
289 { 281 {
290 » if (document == NULL) return 0; 282 if (document == NULL) return 0;
291 » return ((CPDF_Document*)document)->GetPageCount(); 283 return ((CPDF_Document*)document)->GetPageCount();
292 } 284 }
293 285
294 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index ) 286 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index )
295 { 287 {
296 » if (document == NULL) return NULL; 288 if (document == NULL) return NULL;
297 » if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL; 289 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL ;
298 290
299 » CPDF_Document* pDoc = (CPDF_Document*)document; 291 CPDF_Document* pDoc = (CPDF_Document*)document;
300 » if (pDoc == NULL) return NULL; 292 if (pDoc == NULL) return NULL;
301 » CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 293 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
302 » if (pDict == NULL) return NULL; 294 if (pDict == NULL) return NULL;
303 » CPDF_Page* pPage = new CPDF_Page; 295 CPDF_Page* pPage = new CPDF_Page;
304 » pPage->Load(pDoc, pDict); 296 pPage->Load(pDoc, pDict);
305 » pPage->ParseContent(); 297 pPage->ParseContent();
306 » return pPage; 298 return pPage;
307 } 299 }
308 300
309 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) 301 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page)
310 { 302 {
311 » if (!page) 303 if (!page)
312 » » return 0.0; 304 return 0.0;
313 » return ((CPDF_Page*)page)->GetPageWidth(); 305 return ((CPDF_Page*)page)->GetPageWidth();
314 } 306 }
315 307
316 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) 308 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page)
317 { 309 {
318 » if (!page) return 0.0; 310 if (!page) return 0.0;
319 » return ((CPDF_Page*)page)->GetPageHeight(); 311 return ((CPDF_Page*)page)->GetPageHeight();
320 } 312 }
321 313
322 void DropContext(void* data) 314 void DropContext(void* data)
323 { 315 {
324 » delete (CRenderContext*)data; 316 delete (CRenderContext*)data;
325 } 317 }
326 318
327 #if defined(_DEBUG) || defined(DEBUG) 319 #if defined(_DEBUG) || defined(DEBUG)
328 #define DEBUG_TRACE 320 #define DEBUG_TRACE
329 #endif 321 #endif
330 322
331 #if defined(_WIN32) 323 #if defined(_WIN32)
332 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, 324 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
333 » » » » » » int rotate, int flags) 325 int rotate, int flags)
334 { 326 {
335 » if (page==NULL) return; 327 if (page==NULL) return;
336 » CPDF_Page* pPage = (CPDF_Page*)page; 328 CPDF_Page* pPage = (CPDF_Page*)page;
337 329
338 » CRenderContext* pContext = new CRenderContext; 330 CRenderContext* pContext = new CRenderContext;
339 » pPage->SetPrivateData((void*)1, pContext, DropContext); 331 pPage->SetPrivateData((void*)1, pContext, DropContext);
340 332
341 #ifndef _WIN32_WCE 333 #ifndef _WIN32_WCE
342 » CFX_DIBitmap* pBitmap = NULL; 334 CFX_DIBitmap* pBitmap = NULL;
343 » FX_BOOL bBackgroundAlphaNeeded=FALSE; 335 FX_BOOL bBackgroundAlphaNeeded=FALSE;
344 » bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); 336 bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded();
345 » if (bBackgroundAlphaNeeded) 337 if (bBackgroundAlphaNeeded)
346 » { 338 {
347 339
348 » » pBitmap = new CFX_DIBitmap; 340 pBitmap = new CFX_DIBitmap;
349 » » pBitmap->Create(size_x, size_y, FXDIB_Argb); 341 pBitmap->Create(size_x, size_y, FXDIB_Argb);
350 » » pBitmap->Clear(0x00ffffff); 342 pBitmap->Clear(0x00ffffff);
351 #ifdef _SKIA_SUPPORT_ 343 #ifdef _SKIA_SUPPORT_
352 » » pContext->m_pDevice = new CFX_SkiaDevice; 344 pContext->m_pDevice = new CFX_SkiaDevice;
353 » » ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB itmap); 345 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
354 #else 346 #else
355 » » pContext->m_pDevice = new CFX_FxgeDevice; 347 pContext->m_pDevice = new CFX_FxgeDevice;
356 » » ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB itmap); 348 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pBitmap);
357 #endif 349 #endif
358 » } 350 }
359 » else 351 else
360 » pContext->m_pDevice = new CFX_WindowsDevice(dc); 352 pContext->m_pDevice = new CFX_WindowsDevice(dc);
361 353
362 » FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, 354 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
363 rotate, flags, TRUE, NULL); 355 rotate, flags, TRUE, NULL);
364 356
365 » if (bBackgroundAlphaNeeded) 357 if (bBackgroundAlphaNeeded)
366 » { 358 {
367 » » if (pBitmap) 359 if (pBitmap)
368 » » { 360 {
369 » » » CFX_WindowsDevice WinDC(dc); 361 CFX_WindowsDevice WinDC(dc);
370 362
371 » » » if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT ER) 363 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER)
372 » » » { 364 {
373 » » » » CFX_DIBitmap* pDst = new CFX_DIBitmap; 365 CFX_DIBitmap* pDst = new CFX_DIBitmap;
374 » » » » int pitch = pBitmap->GetPitch(); 366 int pitch = pBitmap->GetPitch();
375 » » » » pDst->Create(size_x, size_y, FXDIB_Rgb32); 367 pDst->Create(size_x, size_y, FXDIB_Rgb32);
376 » » » » FXSYS_memset(pDst->GetBuffer(), -1, pitch*size_y ); 368 FXSYS_memset(pDst->GetBuffer(), -1, pitch*size_y);
377 » » » » pDst->CompositeBitmap(0, 0, size_x, size_y, pBit map, 0, 0, FXDIB_BLEND_NORMAL, NULL, FALSE, NULL); 369 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, FXDIB _BLEND_NORMAL, NULL, FALSE, NULL);
378 » » » » WinDC.StretchDIBits(pDst,0,0,size_x,size_y); 370 WinDC.StretchDIBits(pDst,0,0,size_x,size_y);
379 » » » » delete pDst; 371 delete pDst;
380 » » » } 372 }
381 » » » else 373 else
382 » » » » WinDC.SetDIBits(pBitmap,0,0); 374 WinDC.SetDIBits(pBitmap,0,0);
383 375
384 » » } 376 }
385 » } 377 }
386 #else 378 #else
387 » // get clip region 379 // get clip region
388 » RECT rect, cliprect; 380 RECT rect, cliprect;
389 » rect.left = start_x; 381 rect.left = start_x;
390 » rect.top = start_y; 382 rect.top = start_y;
391 » rect.right = start_x + size_x; 383 rect.right = start_x + size_x;
392 » rect.bottom = start_y + size_y; 384 rect.bottom = start_y + size_y;
393 » GetClipBox(dc, &cliprect); 385 GetClipBox(dc, &cliprect);
394 » IntersectRect(&rect, &rect, &cliprect); 386 IntersectRect(&rect, &rect, &cliprect);
395 » int width = rect.right - rect.left; 387 int width = rect.right - rect.left;
396 » int height = rect.bottom - rect.top; 388 int height = rect.bottom - rect.top;
397 389
398 #ifdef DEBUG_TRACE 390 #ifdef DEBUG_TRACE
399 » { 391 {
400 » » char str[128]; 392 char str[128];
401 » » memset(str, 0, sizeof(str)); 393 memset(str, 0, sizeof(str));
402 » » FXSYS_snprintf(str, sizeof(str) - 1, "Rendering DIB %d x %d", wi dth, height); 394 FXSYS_snprintf(str, sizeof(str) - 1, "Rendering DIB %d x %d", width, hei ght);
403 » » CPDF_ModuleMgr::Get()->ReportError(999, str); 395 CPDF_ModuleMgr::Get()->ReportError(999, str);
404 » } 396 }
405 #endif 397 #endif
406 398
407 » // Create a DIB section 399 // Create a DIB section
408 » LPVOID pBuffer; 400 LPVOID pBuffer;
409 » BITMAPINFOHEADER bmih; 401 BITMAPINFOHEADER bmih;
410 » FXSYS_memset(&bmih, 0, sizeof bmih); 402 FXSYS_memset(&bmih, 0, sizeof bmih);
411 » bmih.biSize = sizeof bmih; 403 bmih.biSize = sizeof bmih;
412 » bmih.biBitCount = 24; 404 bmih.biBitCount = 24;
413 » bmih.biHeight = -height; 405 bmih.biHeight = -height;
414 » bmih.biPlanes = 1; 406 bmih.biPlanes = 1;
415 » bmih.biWidth = width; 407 bmih.biWidth = width;
416 » pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_C OLORS, &pBuffer, NULL, 0); 408 pContext->m_hBitmap = CreateDIBSection(dc, (BITMAPINFO*)&bmih, DIB_RGB_COLOR S, &pBuffer, NULL, 0);
417 » if (pContext->m_hBitmap == NULL) { 409 if (pContext->m_hBitmap == NULL) {
418 #if defined(DEBUG) || defined(_DEBUG) 410 #if defined(DEBUG) || defined(_DEBUG)
419 » » char str[128]; 411 char str[128];
420 » » memset(str, 0, sizeof(str)); 412 memset(str, 0, sizeof(str));
421 » » FXSYS_snprintf(str, sizeof(str) - 1, "Error CreateDIBSection: %d x %d, error code = %d", width, height, GetLastError()); 413 FXSYS_snprintf(str, sizeof(str) - 1, "Error CreateDIBSection: %d x %d, e rror code = %d", width, height, GetLastError());
422 » » CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); 414 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
423 #else 415 #else
424 » » CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); 416 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
425 #endif 417 #endif
426 » } 418 }
427 » FXSYS_memset(pBuffer, 0xff, height*((width*3+3)/4*4)); 419 FXSYS_memset(pBuffer, 0xff, height*((width*3+3)/4*4));
428 420
429 #ifdef DEBUG_TRACE 421 #ifdef DEBUG_TRACE
430 » { 422 {
431 » » CPDF_ModuleMgr::Get()->ReportError(999, "DIBSection created"); 423 CPDF_ModuleMgr::Get()->ReportError(999, "DIBSection created");
432 » } 424 }
433 #endif 425 #endif
434 426
435 » // Create a device with this external buffer 427 // Create a device with this external buffer
436 » pContext->m_pBitmap = new CFX_DIBitmap; 428 pContext->m_pBitmap = new CFX_DIBitmap;
437 » pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer) ; 429 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer);
438 » pContext->m_pDevice = new CPDF_FxgeDevice; 430 pContext->m_pDevice = new CPDF_FxgeDevice;
439 » ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); 431 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap);
440 432
441 #ifdef DEBUG_TRACE 433 #ifdef DEBUG_TRACE
442 » CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); 434 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering");
443 #endif 435 #endif
444 436
445 » // output to bitmap device 437 // output to bitmap device
446 » FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, 438 FPDF_RenderPage_Retail(pContext, page, start_x - rect.left,
447 start_y - rect.top, size_x, size_y, rotate, flags); 439 start_y - rect.top, size_x, size_y, rotate, flags);
448 440
449 #ifdef DEBUG_TRACE 441 #ifdef DEBUG_TRACE
450 » CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); 442 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering");
451 #endif 443 #endif
452 444
453 » // Now output to real device 445 // Now output to real device
454 » HDC hMemDC = CreateCompatibleDC(dc); 446 HDC hMemDC = CreateCompatibleDC(dc);
455 » if (hMemDC == NULL) { 447 if (hMemDC == NULL) {
456 #if defined(DEBUG) || defined(_DEBUG) 448 #if defined(DEBUG) || defined(_DEBUG)
457 » » char str[128]; 449 char str[128];
458 » » memset(str, 0, sizeof(str)); 450 memset(str, 0, sizeof(str));
459 » » FXSYS_snprintf(str, sizeof(str) - 1, "Error CreateCompatibleDC. Error code = %d", GetLastError()); 451 FXSYS_snprintf(str, sizeof(str) - 1, "Error CreateCompatibleDC. Error co de = %d", GetLastError());
460 » » CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str); 452 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, str);
461 #else 453 #else
462 » » CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL); 454 CPDF_ModuleMgr::Get()->ReportError(FPDFERR_OUT_OF_MEMORY, NULL);
463 #endif 455 #endif
464 » } 456 }
465 457
466 » HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap); 458 HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap);
467 459
468 #ifdef DEBUG_TRACE 460 #ifdef DEBUG_TRACE
469 » CPDF_ModuleMgr::Get()->ReportError(999, "Ready for screen rendering"); 461 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for screen rendering");
470 #endif 462 #endif
471 463
472 » BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY); 464 BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY);
473 » SelectObject(hMemDC, hOldBitmap); 465 SelectObject(hMemDC, hOldBitmap);
474 » DeleteDC(hMemDC); 466 DeleteDC(hMemDC);
475 467
476 #ifdef DEBUG_TRACE 468 #ifdef DEBUG_TRACE
477 » CPDF_ModuleMgr::Get()->ReportError(999, "Finished screen rendering"); 469 CPDF_ModuleMgr::Get()->ReportError(999, "Finished screen rendering");
478 #endif 470 #endif
479 471
480 #endif 472 #endif
481 if (bBackgroundAlphaNeeded) { 473 if (bBackgroundAlphaNeeded) {
482 delete pBitmap; 474 delete pBitmap;
483 pBitmap = NULL; 475 pBitmap = NULL;
484 } 476 }
485 delete pContext; 477 delete pContext;
486 pPage->RemovePrivateData((void*)1); 478 pPage->RemovePrivateData((void*)1);
487 } 479 }
488 #endif 480 #endif
489 481
490 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, 482 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y,
491 » » » » » » int size_x, int size_y, int rota te, int flags) 483 int size_x, int size_y, int rotate, int flags)
492 { 484 {
493 » if (bitmap == NULL || page == NULL) return; 485 if (bitmap == NULL || page == NULL) return;
494 » CPDF_Page* pPage = (CPDF_Page*)page; 486 CPDF_Page* pPage = (CPDF_Page*)page;
495 487
496 488
497 » CRenderContext* pContext = new CRenderContext; 489 CRenderContext* pContext = new CRenderContext;
498 » pPage->SetPrivateData((void*)1, pContext, DropContext); 490 pPage->SetPrivateData((void*)1, pContext, DropContext);
499 #ifdef _SKIA_SUPPORT_ 491 #ifdef _SKIA_SUPPORT_
500 » pContext->m_pDevice = new CFX_SkiaDevice; 492 pContext->m_pDevice = new CFX_SkiaDevice;
501 493
502 » if (flags & FPDF_REVERSE_BYTE_ORDER) 494 if (flags & FPDF_REVERSE_BYTE_ORDER)
503 » » ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap,0,TRUE); 495 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,T RUE);
504 » else 496 else
505 » » ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap); 497 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
506 #else 498 #else
507 » pContext->m_pDevice = new CFX_FxgeDevice; 499 pContext->m_pDevice = new CFX_FxgeDevice;
508 500
509 » if (flags & FPDF_REVERSE_BYTE_ORDER) 501 if (flags & FPDF_REVERSE_BYTE_ORDER)
510 » » ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap,0,TRUE); 502 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap,0,T RUE);
511 » else 503 else
512 » » ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi tmap); 504 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap);
513 #endif 505 #endif
514 506
515 » FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, 507 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
516 rotate, flags, TRUE, NULL); 508 rotate, flags, TRUE, NULL);
517 509
518 » delete pContext; 510 delete pContext;
519 » pPage->RemovePrivateData((void*)1); 511 pPage->RemovePrivateData((void*)1);
520 } 512 }
521 513
522 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) 514 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page)
523 { 515 {
524 » if (!page) return; 516 if (!page) return;
525 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)(((CPDF_Page*)page))->G etPrivateData((void*)page); 517 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)(((CPDF_Page*)page))->G etPrivateData((void*)page);
526 if (pPageView && pPageView->IsLocked()) { 518 if (pPageView && pPageView->IsLocked()) {
527 pPageView->TakeOverPage(); 519 pPageView->TakeOverPage();
528 return; 520 return;
529 } 521 }
530 » delete (CPDF_Page*)page; 522 delete (CPDF_Page*)page;
531 523
532 } 524 }
533 525
534 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) 526 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document)
535 { 527 {
536 » if (!document) 528 if (!document)
537 » » return; 529 return;
538 » CPDF_Document* pDoc = (CPDF_Document*)document; 530 CPDF_Document* pDoc = (CPDF_Document*)document;
539 » CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 531 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
540 » if (pParser == NULL) 532 if (pParser == NULL)
541 » { 533 {
542 » » delete pDoc; 534 delete pDoc;
543 » » return; 535 return;
544 » } 536 }
545 » delete pParser; 537 delete pParser;
546 } 538 }
547 539
548 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() 540 DLLEXPORT unsigned long STDCALL FPDF_GetLastError()
549 { 541 {
550 » return GetLastError(); 542 return GetLastError();
551 } 543 }
552 544
553 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_ y, int size_x, int size_y, 545 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_ y, int size_x, int size_y,
554 » » » » » » int rotate, int device_x, int de vice_y, double* page_x, double* page_y) 546 int rotate, int device_x, int device_y, double* page_x, double* page_y)
555 { 547 {
556 » if (page == NULL || page_x == NULL || page_y == NULL) return; 548 if (page == NULL || page_x == NULL || page_y == NULL) return;
557 » CPDF_Page* pPage = (CPDF_Page*)page; 549 CPDF_Page* pPage = (CPDF_Page*)page;
558 550
559 » CPDF_Matrix page2device; 551 CPDF_Matrix page2device;
560 » pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, r otate); 552 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotat e);
561 » CPDF_Matrix device2page; 553 CPDF_Matrix device2page;
562 » device2page.SetReverse(page2device); 554 device2page.SetReverse(page2device);
563 555
564 » FX_FLOAT page_x_f, page_y_f; 556 FX_FLOAT page_x_f, page_y_f;
565 » device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x _f, page_y_f); 557 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, page_y_f);
566 558
567 » *page_x = (page_x_f); 559 *page_x = (page_x_f);
568 » *page_y = (page_y_f); 560 *page_y = (page_y_f);
569 } 561 }
570 562
571 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_ y, int size_x, int size_y, 563 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, int start_x, int start_ y, int size_x, int size_y,
572 » » » » » » int rotate, double page_x, doubl e page_y, int* device_x, int* device_y) 564 int rotate, double page_x, double page_y, int* device_x, int* device_y)
573 { 565 {
574 » if (page == NULL || device_x == NULL || device_y == NULL) return; 566 if (page == NULL || device_x == NULL || device_y == NULL) return;
575 » CPDF_Page* pPage = (CPDF_Page*)page; 567 CPDF_Page* pPage = (CPDF_Page*)page;
576 568
577 » CPDF_Matrix page2device; 569 CPDF_Matrix page2device;
578 » pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, r otate); 570 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotat e);
579 571
580 » FX_FLOAT device_x_f, device_y_f; 572 FX_FLOAT device_x_f, device_y_f;
581 » page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f , device_y_f); 573 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, de vice_y_f);
582 574
583 » *device_x = FXSYS_round(device_x_f); 575 *device_x = FXSYS_round(device_x_f);
584 » *device_y = FXSYS_round(device_y_f); 576 *device_y = FXSYS_round(device_y_f);
585 } 577 }
586 578
587 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha ) 579 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha )
588 { 580 {
589 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); 581 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
590 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { 582 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) {
591 return NULL; 583 return NULL;
592 } 584 }
593 return pBitmap.release(); 585 return pBitmap.release();
594 } 586 }
595 587
596 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, int height, int for mat, void* first_scan, int stride) 588 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, int height, int for mat, void* first_scan, int stride)
597 { 589 {
598 » FXDIB_Format fx_format; 590 FXDIB_Format fx_format;
599 » switch (format) { 591 switch (format) {
600 » » case FPDFBitmap_Gray: 592 case FPDFBitmap_Gray:
601 » » » fx_format = FXDIB_8bppRgb; 593 fx_format = FXDIB_8bppRgb;
602 » » » break; 594 break;
603 » » case FPDFBitmap_BGR: 595 case FPDFBitmap_BGR:
604 » » » fx_format = FXDIB_Rgb; 596 fx_format = FXDIB_Rgb;
605 » » » break; 597 break;
606 » » case FPDFBitmap_BGRx: 598 case FPDFBitmap_BGRx:
607 » » » fx_format = FXDIB_Rgb32; 599 fx_format = FXDIB_Rgb32;
608 » » » break; 600 break;
609 » » case FPDFBitmap_BGRA: 601 case FPDFBitmap_BGRA:
610 » » » fx_format = FXDIB_Argb; 602 fx_format = FXDIB_Argb;
611 » » » break; 603 break;
612 » » default: 604 default:
613 » » » return NULL; 605 return NULL;
614 » } 606 }
615 » CFX_DIBitmap* pBitmap = new CFX_DIBitmap; 607 CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
616 » pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); 608 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride);
617 » return pBitmap; 609 return pBitmap;
618 } 610 }
619 611
620 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, int left, int top , int width, int height, FPDF_DWORD color) 612 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, int left, int top , int width, int height, FPDF_DWORD color)
621 { 613 {
622 » if (bitmap == NULL) return; 614 if (bitmap == NULL) return;
623 #ifdef _SKIA_SUPPORT_ 615 #ifdef _SKIA_SUPPORT_
624 » CFX_SkiaDevice device; 616 CFX_SkiaDevice device;
625 #else 617 #else
626 » CFX_FxgeDevice device; 618 CFX_FxgeDevice device;
627 #endif 619 #endif
628 » device.Attach((CFX_DIBitmap*)bitmap); 620 device.Attach((CFX_DIBitmap*)bitmap);
629 » if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) color |= 0xFF000000; 621 if (!((CFX_DIBitmap*)bitmap)->HasAlpha()) color |= 0xFF000000;
630 » FX_RECT rect(left, top, left+width, top+height); 622 FX_RECT rect(left, top, left+width, top+height);
631 » device.FillRect(&rect, color); 623 device.FillRect(&rect, color);
632 } 624 }
633 625
634 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) 626 DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap)
635 { 627 {
636 » if (bitmap == NULL) return NULL; 628 if (bitmap == NULL) return NULL;
637 » return ((CFX_DIBitmap*)bitmap)->GetBuffer(); 629 return ((CFX_DIBitmap*)bitmap)->GetBuffer();
638 } 630 }
639 631
640 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) 632 DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap)
641 { 633 {
642 » if (bitmap == NULL) return 0; 634 if (bitmap == NULL) return 0;
643 » return ((CFX_DIBitmap*)bitmap)->GetWidth(); 635 return ((CFX_DIBitmap*)bitmap)->GetWidth();
644 } 636 }
645 637
646 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) 638 DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap)
647 { 639 {
648 » if (bitmap == NULL) return 0; 640 if (bitmap == NULL) return 0;
649 » return ((CFX_DIBitmap*)bitmap)->GetHeight(); 641 return ((CFX_DIBitmap*)bitmap)->GetHeight();
650 } 642 }
651 643
652 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) 644 DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap)
653 { 645 {
654 » if (bitmap == NULL) return 0; 646 if (bitmap == NULL) return 0;
655 » return ((CFX_DIBitmap*)bitmap)->GetPitch(); 647 return ((CFX_DIBitmap*)bitmap)->GetPitch();
656 } 648 }
657 649
658 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) 650 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap)
659 { 651 {
660 delete (CFX_DIBitmap*)bitmap; 652 delete (CFX_DIBitmap*)bitmap;
661 } 653 }
662 654
663 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_ x, int start_y, int size_x, int size_y, 655 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_ x, int start_y, int size_x, int size_y,
664 int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_ PAUSE_Adapter * pause ) 656 int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_ PAUSE_Adapter * pause )
665 { 657 {
666 » CPDF_Page* pPage = (CPDF_Page*)page; 658 CPDF_Page* pPage = (CPDF_Page*)page;
667 » if (pPage == NULL) return; 659 if (pPage == NULL) return;
668 660
669 » if (!pContext->m_pOptions) 661 if (!pContext->m_pOptions)
670 » » pContext->m_pOptions = new CPDF_RenderOptions; 662 pContext->m_pOptions = new CPDF_RenderOptions;
671 663
672 » if (flags & FPDF_LCD_TEXT) 664 if (flags & FPDF_LCD_TEXT)
673 » » pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; 665 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE;
674 » else 666 else
675 » » pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; 667 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE;
676 » if (flags & FPDF_NO_NATIVETEXT) 668 if (flags & FPDF_NO_NATIVETEXT)
677 » » pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; 669 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT;
678 » if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) 670 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE)
679 » » pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; 671 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE;
680 » if (flags & FPDF_RENDER_FORCEHALFTONE) 672 if (flags & FPDF_RENDER_FORCEHALFTONE)
681 » » pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; 673 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE;
682 » if (flags & FPDF_RENDER_NO_SMOOTHTEXT) 674 if (flags & FPDF_RENDER_NO_SMOOTHTEXT)
683 » » pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; 675 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH;
684 » if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) 676 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE)
685 » » pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; 677 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH;
686 » if (flags & FPDF_RENDER_NO_SMOOTHPATH) 678 if (flags & FPDF_RENDER_NO_SMOOTHPATH)
687 » » pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; 679 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH;
688 » //Grayscale output 680 //Grayscale output
689 » if (flags & FPDF_GRAYSCALE) 681 if (flags & FPDF_GRAYSCALE)
690 » { 682 {
691 » » pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; 683 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY;
692 » » pContext->m_pOptions->m_ForeColor = 0; 684 pContext->m_pOptions->m_ForeColor = 0;
693 » » pContext->m_pOptions->m_BackColor = 0xffffff; 685 pContext->m_pOptions->m_BackColor = 0xffffff;
694 » } 686 }
695 » const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_O CContext::Print : CPDF_OCContext::View; 687 const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_OCCon text::Print : CPDF_OCContext::View;
696 » pContext->m_pOptions->m_AddFlags = flags >> 8; 688 pContext->m_pOptions->m_AddFlags = flags >> 8;
697 » pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocume nt, usage); 689 pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocument, usage);
698 690
699 » CFX_AffineMatrix matrix; 691 CFX_AffineMatrix matrix;
700 » pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate ); 692 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
701 693
702 » FX_RECT clip; 694 FX_RECT clip;
703 » clip.left = start_x; 695 clip.left = start_x;
704 » clip.right = start_x + size_x; 696 clip.right = start_x + size_x;
705 » clip.top = start_y; 697 clip.top = start_y;
706 » clip.bottom = start_y + size_y; 698 clip.bottom = start_y + size_y;
707 » pContext->m_pDevice->SaveState(); 699 pContext->m_pDevice->SaveState();
708 » pContext->m_pDevice->SetClip_Rect(&clip); 700 pContext->m_pDevice->SetClip_Rect(&clip);
709 701
710 » pContext->m_pContext = new CPDF_RenderContext; 702 pContext->m_pContext = new CPDF_RenderContext;
711 » pContext->m_pContext->Create(pPage); 703 pContext->m_pContext->Create(pPage);
712 » pContext->m_pContext->AppendObjectList(pPage, &matrix); 704 pContext->m_pContext->AppendObjectList(pPage, &matrix);
713 705
714 » if (flags & FPDF_ANNOT) { 706 if (flags & FPDF_ANNOT) {
715 » » pContext->m_pAnnots = new CPDF_AnnotList(pPage); 707 pContext->m_pAnnots = new CPDF_AnnotList(pPage);
716 » » FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXD C_DISPLAY; 708 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLA Y;
717 » » pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, &matrix, TRUE, NULL); 709 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrintin g, &matrix, TRUE, NULL);
718 » } 710 }
719 711
720 » pContext->m_pRenderer = new CPDF_ProgressiveRenderer; 712 pContext->m_pRenderer = new CPDF_ProgressiveRenderer(
721 » pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions, pause); 713 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions);
722 » if (bNeedToRestore) 714 pContext->m_pRenderer->Start(pause);
723 » { 715 if (bNeedToRestore)
724 » » pContext->m_pDevice->RestoreState(); 716 pContext->m_pDevice->RestoreState();
725 » }
726 } 717 }
727 718
728 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_i ndex, double* width, double* height) 719 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_i ndex, double* width, double* height)
729 { 720 {
730 » CPDF_Document* pDoc = (CPDF_Document*)document; 721 CPDF_Document* pDoc = (CPDF_Document*)document;
731 » if(pDoc == NULL) 722 if(pDoc == NULL)
732 » » return FALSE; 723 return FALSE;
733 724
734 » CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 725 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
735 » if (pDict == NULL) return FALSE; 726 if (pDict == NULL) return FALSE;
736 727
737 » CPDF_Page page; 728 CPDF_Page page;
738 » page.Load(pDoc, pDict); 729 page.Load(pDoc, pDict);
739 » *width = page.GetPageWidth(); 730 *width = page.GetPageWidth();
740 » *height = page.GetPageHeight(); 731 *height = page.GetPageHeight();
741 732
742 » return TRUE; 733 return TRUE;
743 } 734 }
744 735
745 DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT documen t) 736 DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT documen t)
746 { 737 {
747 » CPDF_Document* pDoc = (CPDF_Document*)document; 738 CPDF_Document* pDoc = (CPDF_Document*)document;
748 » if (!pDoc) return TRUE; 739 if (!pDoc) return TRUE;
749 » CPDF_ViewerPreferences viewRef(pDoc); 740 CPDF_ViewerPreferences viewRef(pDoc);
750 » return viewRef.PrintScaling(); 741 return viewRef.PrintScaling();
751 } 742 }
752 743
753 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) 744 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document)
754 { 745 {
755 CPDF_Document* pDoc = (CPDF_Document*)document; 746 CPDF_Document* pDoc = (CPDF_Document*)document;
756 if (!pDoc) return 1; 747 if (!pDoc) return 1;
757 CPDF_ViewerPreferences viewRef(pDoc); 748 CPDF_ViewerPreferences viewRef(pDoc);
758 return viewRef.NumCopies(); 749 return viewRef.NumCopies();
759 } 750 }
760 751
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); 783 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
793 int count = nameTree.GetCount(); 784 int count = nameTree.GetCount();
794 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); 785 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
795 if (pDest) 786 if (pDest)
796 count += pDest->GetCount(); 787 count += pDest->GetCount();
797 return count; 788 return count;
798 } 789 }
799 790
800 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_ BYTESTRING name) 791 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_ BYTESTRING name)
801 { 792 {
802 » if (!document) 793 if (!document)
803 » » return NULL; 794 return NULL;
804 » if (!name || name[0] == 0) 795 if (!name || name[0] == 0)
805 » » return NULL; 796 return NULL;
806 797
807 » CPDF_Document* pDoc = (CPDF_Document*)document; 798 CPDF_Document* pDoc = (CPDF_Document*)document;
808 » CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 799 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
809 » return name_tree.LookupNamedDest(pDoc, name); 800 return name_tree.LookupNamedDest(pDoc, name);
810 } 801 }
811 802
812 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, long* buflen) 803 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, long* buflen)
813 { 804 {
814 if (!buffer) 805 if (!buffer)
815 *buflen = 0; 806 *buflen = 0;
816 if (!document || index < 0) return NULL; 807 if (!document || index < 0) return NULL;
817 CPDF_Document* pDoc = (CPDF_Document*)document; 808 CPDF_Document* pDoc = (CPDF_Document*)document;
818 809
819 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 810 CPDF_Dictionary* pRoot = pDoc->GetRoot();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 if (!buffer) { 842 if (!buffer) {
852 *buflen = len; 843 *buflen = len;
853 } else if (*buflen >= len) { 844 } else if (*buflen >= len) {
854 memcpy(buffer, utf16Name.c_str(), len); 845 memcpy(buffer, utf16Name.c_str(), len);
855 *buflen = len; 846 *buflen = len;
856 } else { 847 } else {
857 *buflen = -1; 848 *buflen = -1;
858 } 849 }
859 return (FPDF_DEST)pDestObj; 850 return (FPDF_DEST)pDestObj;
860 } 851 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdf_progressive.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698