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

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

Issue 837723009: Add tests for GetNamedDests() API. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 80 columns 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 | « no previous file | fpdfsdk/src/fpdfview_embeddertest.cpp » ('j') | 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 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 if (!document) 810 if (!document)
811 return NULL; 811 return NULL;
812 if (!name || name[0] == 0) 812 if (!name || name[0] == 0)
813 return NULL; 813 return NULL;
814 814
815 CPDF_Document* pDoc = (CPDF_Document*)document; 815 CPDF_Document* pDoc = (CPDF_Document*)document;
816 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); 816 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
817 return name_tree.LookupNamedDest(pDoc, name); 817 return name_tree.LookupNamedDest(pDoc, name);
818 } 818 }
819 819
820 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, unsigned long& buflen) 820 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, unsigned long& buflen)
Bo Xu 2015/01/21 00:04:12 Shall we use long instead of unsigned long for buf
821 { 821 {
822 if (!buffer) 822 if (!buffer)
823 buflen = 0; 823 buflen = 0;
824 if (!document || index < 0) return NULL; 824 if (!document || index < 0) return NULL;
825 CPDF_Document* pDoc = (CPDF_Document*)document; 825 CPDF_Document* pDoc = (CPDF_Document*)document;
826 826
827 CPDF_Dictionary* pRoot = pDoc->GetRoot(); 827 CPDF_Dictionary* pRoot = pDoc->GetRoot();
828 if (!pRoot) return NULL; 828 if (!pRoot) return NULL;
829 829
830 CPDF_Object* pDestObj = NULL; 830 CPDF_Object* pDestObj = NULL;
(...skipping 10 matching lines...) Expand all
841 while (pos) { 841 while (pos) {
842 pDestObj = pDest->GetNextElement(pos, bsName); 842 pDestObj = pDest->GetNextElement(pos, bsName);
843 if (!pDestObj) continue; 843 if (!pDestObj) continue;
844 if (i == index) break; 844 if (i == index) break;
845 i++; 845 i++;
846 } 846 }
847 } else { 847 } else {
848 pDestObj = nameTree.LookupValue(index, bsName); 848 pDestObj = nameTree.LookupValue(index, bsName);
849 } 849 }
850 if (!pDestObj) return NULL; 850 if (!pDestObj) return NULL;
851 if (pDestObj->GetType() == PDFOBJ_DICTIONARY) 851 if (pDestObj->GetType() == PDFOBJ_DICTIONARY) {
852 pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D")); 852 pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D"));
853 if (!pDestObj) return NULL;
854 }
853 if (pDestObj->GetType() != PDFOBJ_ARRAY) return NULL; 855 if (pDestObj->GetType() != PDFOBJ_ARRAY) return NULL;
854 CFX_WideString wsName = PDF_DecodeText(bsName); 856 CFX_WideString wsName = PDF_DecodeText(bsName);
855 CFX_ByteString utf16Name = wsName.UTF16LE_Encode(); 857 CFX_ByteString utf16Name = wsName.UTF16LE_Encode();
856 unsigned int len = utf16Name.GetLength(); 858 unsigned int len = utf16Name.GetLength();
857 if (!buffer) { 859 if (!buffer) {
858 buflen = len + 2; 860 buflen = len + 2;
859 } else if (buflen >= len + 2) { 861 } else if (buflen >= len + 2) {
860 memcpy(buffer, utf16Name.c_str(), len); 862 memcpy(buffer, utf16Name.c_str(), len);
861 ((FX_BYTE*)buffer)[len] = 0; 863 ((FX_BYTE*)buffer)[len] = 0;
862 ((FX_BYTE*)buffer)[len + 1] = 0; 864 ((FX_BYTE*)buffer)[len + 1] = 0;
865 buflen = len + 2;
863 } else { 866 } else {
864 len = -1; 867 buflen = -1;
865 } 868 }
866 return (FPDF_DEST)pDestObj; 869 return (FPDF_DEST)pDestObj;
867 } 870 }
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/src/fpdfview_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698