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/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 Loading... | |
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, char* name, unsigned int& len) | |
821 { | |
822 if (!name) | |
823 len = 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 if (!name) { | |
855 len = bsName.GetLength() + 1; | |
856 } else { | |
857 CFX_WideString wsName = PDF_DecodeText(bsName); | |
Tom Sepez
2015/01/07 16:56:24
need to check that len was sufficient here to get
Bo Xu
2015/01/09 19:35:21
Return -1 if length not sufficient.
| |
858 CFX_ByteString utf16Name = wsName.UTF16LE_Encode(); | |
859 memcpy(name, utf16Name.c_str(), len-1); | |
860 name[len-1] = '\0'; | |
861 } | |
862 return (FPDF_DEST)pDestObj; | |
863 } | |
OLD | NEW |