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

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

Issue 1395493007: Introduce CPDF_Document::FromFPDFDocument(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 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
« no previous file with comments | « fpdfsdk/src/fpdfsave.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"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return NULL; 211 return NULL;
212 } 212 }
213 CPDF_Document* pDoc = NULL; 213 CPDF_Document* pDoc = NULL;
214 pDoc = pParser ? pParser->GetDocument() : NULL; 214 pDoc = pParser ? pParser->GetDocument() : NULL;
215 CheckUnSupportError(pDoc, err_code); 215 CheckUnSupportError(pDoc, err_code);
216 return pParser->GetDocument(); 216 return pParser->GetDocument();
217 } 217 }
218 218
219 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, 219 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
220 int* fileVersion) { 220 int* fileVersion) {
221 if (!doc || !fileVersion) 221 if (!fileVersion)
222 return FALSE; 222 return FALSE;
223
223 *fileVersion = 0; 224 *fileVersion = 0;
224 CPDF_Document* pDoc = (CPDF_Document*)doc; 225 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(doc);
226 if (!pDoc)
227 return FALSE;
228
225 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 229 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
226 if (!pParser) 230 if (!pParser)
227 return FALSE; 231 return FALSE;
232
228 *fileVersion = pParser->GetFileVersion(); 233 *fileVersion = pParser->GetFileVersion();
229 return TRUE; 234 return TRUE;
230 } 235 }
231 236
232 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match 237 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match
233 // header). 238 // header).
234 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { 239 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
235 if (document == NULL) 240 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
241 if (!pDoc)
236 return 0; 242 return 0;
237 CPDF_Document* pDoc = (CPDF_Document*)document; 243
238 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 244 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
239 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 245 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
240 if (pDict == NULL) 246 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
241 return (FX_DWORD)-1;
242
243 return pDict->GetInteger("P");
244 } 247 }
245 248
246 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { 249 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
247 if (document == NULL) 250 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
251 if (!pDoc)
248 return -1; 252 return -1;
249 CPDF_Document* pDoc = (CPDF_Document*)document; 253
250 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 254 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
251 CPDF_Dictionary* pDict = pParser->GetEncryptDict(); 255 CPDF_Dictionary* pDict = pParser->GetEncryptDict();
252 if (pDict == NULL) 256 return pDict ? pDict->GetInteger("R") : -1;
253 return -1;
254
255 return pDict->GetInteger("R");
256 } 257 }
257 258
258 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { 259 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
259 if (document == NULL) 260 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
260 return 0; 261 return pDoc ? pDoc->GetPageCount() : 0;
261 return ((CPDF_Document*)document)->GetPageCount();
262 } 262 }
263 263
264 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, 264 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
265 int page_index) { 265 int page_index) {
266 if (document == NULL) 266 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
267 return NULL; 267 if (!pDoc)
268 return nullptr;
269
268 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) 270 if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
269 return NULL; 271 return nullptr;
270 272
271 CPDF_Document* pDoc = (CPDF_Document*)document;
272 if (pDoc == NULL)
273 return NULL;
274 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 273 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
275 if (pDict == NULL) 274 if (pDict == NULL)
276 return NULL; 275 return NULL;
277 CPDF_Page* pPage = new CPDF_Page; 276 CPDF_Page* pPage = new CPDF_Page;
278 pPage->Load(pDoc, pDict); 277 pPage->Load(pDoc, pDict);
279 pPage->ParseContent(); 278 pPage->ParseContent();
280 return pPage; 279 return pPage;
281 } 280 }
282 281
283 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { 282 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 CPDFSDK_PageView* pPageView = 505 CPDFSDK_PageView* pPageView =
507 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); 506 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page);
508 if (pPageView && pPageView->IsLocked()) { 507 if (pPageView && pPageView->IsLocked()) {
509 pPageView->TakeOverPage(); 508 pPageView->TakeOverPage();
510 return; 509 return;
511 } 510 }
512 delete (CPDF_Page*)page; 511 delete (CPDF_Page*)page;
513 } 512 }
514 513
515 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { 514 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
516 if (!document) 515 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
516 if (!pDoc)
517 return; 517 return;
518 CPDF_Document* pDoc = (CPDF_Document*)document; 518
519 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); 519 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
520 if (pParser == NULL) { 520 if (!pParser) {
521 delete pDoc; 521 delete pDoc;
522 return; 522 return;
523 } 523 }
524 delete pParser; 524 delete pParser;
525 } 525 }
526 526
527 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { 527 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
528 return GetLastError(); 528 return GetLastError();
529 } 529 }
530 530
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions); 738 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions);
739 pContext->m_pRenderer->Start(pause); 739 pContext->m_pRenderer->Start(pause);
740 if (bNeedToRestore) 740 if (bNeedToRestore)
741 pContext->m_pDevice->RestoreState(); 741 pContext->m_pDevice->RestoreState();
742 } 742 }
743 743
744 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, 744 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
745 int page_index, 745 int page_index,
746 double* width, 746 double* width,
747 double* height) { 747 double* height) {
748 CPDF_Document* pDoc = (CPDF_Document*)document; 748 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
749 if (pDoc == NULL) 749 if (!pDoc)
750 return FALSE; 750 return FALSE;
751 751
752 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); 752 CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
753 if (pDict == NULL) 753 if (!pDict)
754 return FALSE; 754 return FALSE;
755 755
756 CPDF_Page page; 756 CPDF_Page page;
757 page.Load(pDoc, pDict); 757 page.Load(pDoc, pDict);
758 *width = page.GetPageWidth(); 758 *width = page.GetPageWidth();
759 *height = page.GetPageHeight(); 759 *height = page.GetPageHeight();
760 760
761 return TRUE; 761 return TRUE;
762 } 762 }
763 763
764 DLLEXPORT FPDF_BOOL STDCALL 764 DLLEXPORT FPDF_BOOL STDCALL
765 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { 765 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
766 CPDF_Document* pDoc = (CPDF_Document*)document; 766 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
767 if (!pDoc) 767 if (!pDoc)
768 return TRUE; 768 return TRUE;
769 CPDF_ViewerPreferences viewRef(pDoc); 769 CPDF_ViewerPreferences viewRef(pDoc);
770 return viewRef.PrintScaling(); 770 return viewRef.PrintScaling();
771 } 771 }
772 772
773 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { 773 DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
774 CPDF_Document* pDoc = (CPDF_Document*)document; 774 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
775 if (!pDoc) 775 if (!pDoc)
776 return 1; 776 return 1;
777 CPDF_ViewerPreferences viewRef(pDoc); 777 CPDF_ViewerPreferences viewRef(pDoc);
778 return viewRef.NumCopies(); 778 return viewRef.NumCopies();
779 } 779 }
780 780
781 DLLEXPORT FPDF_PAGERANGE STDCALL 781 DLLEXPORT FPDF_PAGERANGE STDCALL
782 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { 782 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
783 CPDF_Document* pDoc = (CPDF_Document*)document; 783 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
784 if (!pDoc) 784 if (!pDoc)
785 return NULL; 785 return NULL;
786 CPDF_ViewerPreferences viewRef(pDoc); 786 CPDF_ViewerPreferences viewRef(pDoc);
787 return viewRef.PrintPageRange(); 787 return viewRef.PrintPageRange();
788 } 788 }
789 789
790 DLLEXPORT FPDF_DUPLEXTYPE STDCALL 790 DLLEXPORT FPDF_DUPLEXTYPE STDCALL
791 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { 791 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
792 CPDF_Document* pDoc = (CPDF_Document*)document; 792 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
793 if (!pDoc) 793 if (!pDoc)
794 return DuplexUndefined; 794 return DuplexUndefined;
795 CPDF_ViewerPreferences viewRef(pDoc); 795 CPDF_ViewerPreferences viewRef(pDoc);
796 CFX_ByteString duplex = viewRef.Duplex(); 796 CFX_ByteString duplex = viewRef.Duplex();
797 if (FX_BSTRC("Simplex") == duplex) 797 if (FX_BSTRC("Simplex") == duplex)
798 return Simplex; 798 return Simplex;
799 if (FX_BSTRC("DuplexFlipShortEdge") == duplex) 799 if (FX_BSTRC("DuplexFlipShortEdge") == duplex)
800 return DuplexFlipShortEdge; 800 return DuplexFlipShortEdge;
801 if (FX_BSTRC("DuplexFlipLongEdge") == duplex) 801 if (FX_BSTRC("DuplexFlipLongEdge") == duplex)
802 return DuplexFlipLongEdge; 802 return DuplexFlipLongEdge;
803 return DuplexUndefined; 803 return DuplexUndefined;
804 } 804 }
805 805
806 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { 806 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
807 if (!document) 807 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
808 if (!pDoc)
808 return 0; 809 return 0;
809 CPDF_Document* pDoc = (CPDF_Document*)document;
810 810
811 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 811 CPDF_Dictionary* pRoot = pDoc->GetRoot();
812 if (!pRoot) 812 if (!pRoot)
813 return 0; 813 return 0;
814 814
815 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); 815 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
816 int count = nameTree.GetCount(); 816 int count = nameTree.GetCount();
817 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); 817 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
818 if (pDest) 818 if (pDest)
819 count += pDest->GetCount(); 819 count += pDest->GetCount();
820 return count; 820 return count;
821 } 821 }
822 822
823 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, 823 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
824 FPDF_BYTESTRING name) { 824 FPDF_BYTESTRING name) {
825 if (!document)
826 return NULL;
827 if (!name || name[0] == 0) 825 if (!name || name[0] == 0)
828 return NULL; 826 return nullptr;
829 827
830 CPDF_Document* pDoc = (CPDF_Document*)document; 828 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
829 if (!pDoc)
830 return nullptr;
831
831 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 832 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
832 return name_tree.LookupNamedDest(pDoc, name); 833 return name_tree.LookupNamedDest(pDoc, name);
833 } 834 }
834 835
835 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, 836 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
836 int index, 837 int index,
837 void* buffer, 838 void* buffer,
838 long* buflen) { 839 long* buflen) {
839 if (!buffer) 840 if (!buffer)
840 *buflen = 0; 841 *buflen = 0;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 if (!buffer) { 886 if (!buffer) {
886 *buflen = len; 887 *buflen = len;
887 } else if (*buflen >= len) { 888 } else if (*buflen >= len) {
888 memcpy(buffer, utf16Name.c_str(), len); 889 memcpy(buffer, utf16Name.c_str(), len);
889 *buflen = len; 890 *buflen = len;
890 } else { 891 } else {
891 *buflen = -1; 892 *buflen = -1;
892 } 893 }
893 return (FPDF_DEST)pDestObj; 894 return (FPDF_DEST)pDestObj;
894 } 895 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfsave.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698