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

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

Issue 834703002: Add APIs for getting bookmarks and named destinations. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: check pDict and fix indent Created 5 years, 11 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/fpdfdoc.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 "../include/fsdk_define.h" 7 #include "../include/fsdk_define.h"
8 #include "../include/fsdk_mgr.h" 8 #include "../include/fsdk_mgr.h"
9 #include "../include/fpdfview.h" 9 #include "../include/fpdfview.h"
10 #include "../include/fsdk_rendercontext.h" 10 #include "../include/fsdk_rendercontext.h"
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 CFX_ByteString duplex = viewRef.Duplex(); 782 CFX_ByteString duplex = viewRef.Duplex();
783 if (FX_BSTRC("Simplex") == duplex) 783 if (FX_BSTRC("Simplex") == duplex)
784 return Simplex; 784 return Simplex;
785 if (FX_BSTRC("DuplexFlipShortEdge") == duplex) 785 if (FX_BSTRC("DuplexFlipShortEdge") == duplex)
786 return DuplexFlipShortEdge; 786 return DuplexFlipShortEdge;
787 if (FX_BSTRC("DuplexFlipLongEdge") == duplex) 787 if (FX_BSTRC("DuplexFlipLongEdge") == duplex)
788 return DuplexFlipLongEdge; 788 return DuplexFlipLongEdge;
789 return DuplexUndefined; 789 return DuplexUndefined;
790 } 790 }
791 791
792 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document)
793 {
794 if (!document) return 0;
795 CPDF_Document* pDoc = (CPDF_Document*)document;
796
797 CPDF_Dictionary* pRoot = pDoc->GetRoot();
798 if (!pRoot) return 0;
799
800 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
801 int count = nameTree.GetCount();
802 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
803 if (pDest)
804 count += pDest->GetCount();
805 return count;
806 }
807
792 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_ BYTESTRING name) 808 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_ BYTESTRING name)
793 { 809 {
794 » if (document == NULL) 810 » if (!document)
795 return NULL; 811 return NULL;
796 » if (name == NULL || name[0] == 0) 812 » if (!name || name[0] == 0)
797 return NULL; 813 return NULL;
798 814
799 CPDF_Document* pDoc = (CPDF_Document*)document; 815 CPDF_Document* pDoc = (CPDF_Document*)document;
800 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 816 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
801 return name_tree.LookupNamedDest(pDoc, name); 817 return name_tree.LookupNamedDest(pDoc, name);
802 } 818 }
819
820 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, unsigned long& buflen)
821 {
822 if (!buffer)
823 buflen = 0;
824 if (!document || index < 0) return NULL;
825 CPDF_Document* pDoc = (CPDF_Document*)document;
826
827 CPDF_Dictionary* pRoot = pDoc->GetRoot();
828 if (!pRoot) return NULL;
829
830 CPDF_Object* pDestObj = NULL;
831 CFX_ByteString bsName;
832 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
833 int count = nameTree.GetCount();
834 if (index >= count) {
835 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
836 if (!pDest) return NULL;
837 if (index >= count + pDest->GetCount()) return NULL;
838 index -= count;
839 FX_POSITION pos = pDest->GetStartPos();
840 int i = 0;
841 while (pos) {
842 pDestObj = pDest->GetNextElement(pos, bsName);
843 if (!pDestObj) continue;
844 if (i == index) break;
845 i++;
846 }
847 } else {
848 pDestObj = nameTree.LookupValue(index, bsName);
849 }
850 if (!pDestObj) return NULL;
851 if (pDestObj->GetType() == PDFOBJ_DICTIONARY)
852 pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D"));
853 if (pDestObj->GetType() != PDFOBJ_ARRAY) return NULL;
854 CFX_WideString wsName = PDF_DecodeText(bsName);
855 CFX_ByteString utf16Name = wsName.UTF16LE_Encode();
856 unsigned int len = utf16Name.GetLength();
857 if (!buffer) {
858 buflen = len + 2;
859 } else if (buflen >= len + 2) {
860 memcpy(buffer, utf16Name.c_str(), len);
861 ((FX_BYTE*)buffer)[len] = 0;
862 ((FX_BYTE*)buffer)[len + 1] = 0;
863 } else {
864 len = -1;
865 }
866 return (FPDF_DEST)pDestObj;
867 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfdoc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698