Chromium Code Reviews| 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 "../../public/fpdf_doc.h" | 7 #include "../../public/fpdf_doc.h" |
| 8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
| 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 10 #include "../include/fpdfxfa/fpdfxfa_page.h" | 10 #include "../include/fpdfxfa/fpdfxfa_page.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 pLinkList = new CPDF_LinkList; | 47 pLinkList = new CPDF_LinkList; |
| 48 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | 48 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
| 49 } | 49 } |
| 50 return pLinkList; | 50 return pLinkList; |
| 51 } | 51 } |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 DLLEXPORT FPDF_BOOKMARK STDCALL | 55 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 56 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 56 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 57 if (!document) | 57 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 58 return NULL; | 58 if (!pDoc) |
| 59 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 59 return nullptr; |
| 60 CPDF_BookmarkTree tree(pDoc); | 60 CPDF_BookmarkTree tree(pDoc); |
| 61 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 61 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 62 return tree.GetFirstChild(bookmark).GetDict(); | 62 return tree.GetFirstChild(bookmark).GetDict(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 DLLEXPORT FPDF_BOOKMARK STDCALL | 65 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 66 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 66 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 67 if (!document || !pDict) | 67 if (!pDict) |
| 68 return NULL; | 68 return nullptr; |
| 69 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 69 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 70 if (!pDoc) | |
| 71 return nullptr; | |
| 70 CPDF_BookmarkTree tree(pDoc); | 72 CPDF_BookmarkTree tree(pDoc); |
| 71 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 73 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 72 return tree.GetNextSibling(bookmark).GetDict(); | 74 return tree.GetNextSibling(bookmark).GetDict(); |
| 73 } | 75 } |
| 74 | 76 |
| 75 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, | 77 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, |
| 76 void* buffer, | 78 void* buffer, |
| 77 unsigned long buflen) { | 79 unsigned long buflen) { |
| 78 if (!pDict) | 80 if (!pDict) |
| 79 return 0; | 81 return 0; |
| 80 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 82 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 81 CFX_WideString title = bookmark.GetTitle(); | 83 CFX_WideString title = bookmark.GetTitle(); |
| 82 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); | 84 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
| 83 unsigned long len = encodedTitle.GetLength(); | 85 unsigned long len = encodedTitle.GetLength(); |
| 84 if (buffer && buflen >= len) { | 86 if (buffer && buflen >= len) { |
| 85 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); | 87 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
| 86 } | 88 } |
| 87 return len; | 89 return len; |
| 88 } | 90 } |
| 89 | 91 |
| 90 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, | 92 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, |
| 91 FPDF_WIDESTRING title) { | 93 FPDF_WIDESTRING title) { |
| 92 if (!document) | |
| 93 return NULL; | |
| 94 if (!title || title[0] == 0) | 94 if (!title || title[0] == 0) |
| 95 return NULL; | 95 return nullptr; |
| 96 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 96 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 97 if (!pDoc) | |
| 98 return nullptr; | |
| 97 CPDF_BookmarkTree tree(pDoc); | 99 CPDF_BookmarkTree tree(pDoc); |
| 98 FX_STRSIZE len = CFX_WideString::WStringLength(title); | 100 FX_STRSIZE len = CFX_WideString::WStringLength(title); |
| 99 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); | 101 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
| 100 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); | 102 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, | 105 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, |
| 104 FPDF_BOOKMARK pDict) { | 106 FPDF_BOOKMARK pDict) { |
| 105 if (!document) | |
| 106 return NULL; | |
| 107 if (!pDict) | 107 if (!pDict) |
| 108 return NULL; | 108 return nullptr; |
| 109 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | |
| 110 if (!pDoc) | |
| 111 return nullptr; | |
| 109 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 112 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 110 CPDF_Document* pDoc = (CPDF_Document*)document; | |
|
Tom Sepez
2015/10/15 22:08:23
note: this looks like it was a casting bug.
Lei Zhang
2015/10/15 22:44:27
I hope that wasn't me...
| |
| 111 CPDF_Dest dest = bookmark.GetDest(pDoc); | 113 CPDF_Dest dest = bookmark.GetDest(pDoc); |
| 112 if (dest) | 114 if (dest) |
| 113 return dest.GetObject(); | 115 return dest.GetObject(); |
| 114 // If this bookmark is not directly associated with a dest, we try to get | 116 // If this bookmark is not directly associated with a dest, we try to get |
| 115 // action | 117 // action |
| 116 CPDF_Action action = bookmark.GetAction(); | 118 CPDF_Action action = bookmark.GetAction(); |
| 117 if (!action) | 119 if (!action) |
| 118 return NULL; | 120 return nullptr; |
| 119 return action.GetDest(pDoc).GetObject(); | 121 return action.GetDest(pDoc).GetObject(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { | 124 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { |
| 123 if (!pDict) | 125 if (!pDict) |
| 124 return NULL; | 126 return NULL; |
| 125 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 127 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 126 return bookmark.GetAction().GetDict(); | 128 return bookmark.GetAction().GetDict(); |
| 127 } | 129 } |
| 128 | 130 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 141 return PDFACTION_URI; | 143 return PDFACTION_URI; |
| 142 case CPDF_Action::Launch: | 144 case CPDF_Action::Launch: |
| 143 return PDFACTION_LAUNCH; | 145 return PDFACTION_LAUNCH; |
| 144 default: | 146 default: |
| 145 return PDFACTION_UNSUPPORTED; | 147 return PDFACTION_UNSUPPORTED; |
| 146 } | 148 } |
| 147 } | 149 } |
| 148 | 150 |
| 149 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, | 151 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, |
| 150 FPDF_ACTION pDict) { | 152 FPDF_ACTION pDict) { |
| 151 if (!document || !pDict) | 153 if (!pDict) |
| 152 return nullptr; | 154 return nullptr; |
| 153 | 155 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 154 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 156 if (!pDoc) |
| 157 return nullptr; | |
| 155 CPDF_Action action((CPDF_Dictionary*)pDict); | 158 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 156 return action.GetDest(pDoc).GetObject(); | 159 return action.GetDest(pDoc).GetObject(); |
| 157 } | 160 } |
| 158 | 161 |
| 159 DLLEXPORT unsigned long STDCALL | 162 DLLEXPORT unsigned long STDCALL |
| 160 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { | 163 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { |
| 161 unsigned long type = FPDFAction_GetType(pDict); | 164 unsigned long type = FPDFAction_GetType(pDict); |
| 162 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) | 165 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) |
| 163 return 0; | 166 return 0; |
| 164 | 167 |
| 165 CPDF_Action action((CPDF_Dictionary*)pDict); | 168 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 166 CFX_ByteString path = action.GetFilePath().UTF8Encode(); | 169 CFX_ByteString path = action.GetFilePath().UTF8Encode(); |
| 167 unsigned long len = path.GetLength() + 1; | 170 unsigned long len = path.GetLength() + 1; |
| 168 if (buffer && buflen >= len) | 171 if (buffer && buflen >= len) |
| 169 FXSYS_memcpy(buffer, path.c_str(), len); | 172 FXSYS_memcpy(buffer, path.c_str(), len); |
| 170 return len; | 173 return len; |
| 171 } | 174 } |
| 172 | 175 |
| 173 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, | 176 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
| 174 FPDF_ACTION pDict, | 177 FPDF_ACTION pDict, |
| 175 void* buffer, | 178 void* buffer, |
| 176 unsigned long buflen) { | 179 unsigned long buflen) { |
| 177 if (!document || !pDict) | 180 if (!pDict) |
| 178 return 0; | 181 return 0; |
| 179 | 182 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 180 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 183 if (!pDoc) |
| 184 return 0; | |
| 181 CPDF_Action action((CPDF_Dictionary*)pDict); | 185 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 182 CFX_ByteString path = action.GetURI(pDoc); | 186 CFX_ByteString path = action.GetURI(pDoc); |
| 183 unsigned long len = path.GetLength() + 1; | 187 unsigned long len = path.GetLength() + 1; |
| 184 if (buffer && buflen >= len) | 188 if (buffer && buflen >= len) |
| 185 FXSYS_memcpy(buffer, path.c_str(), len); | 189 FXSYS_memcpy(buffer, path.c_str(), len); |
| 186 return len; | 190 return len; |
| 187 } | 191 } |
| 188 | 192 |
| 189 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, | 193 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
| 190 FPDF_DEST pDict) { | 194 FPDF_DEST pDict) { |
| 191 if (!document || !pDict) | 195 if (!pDict) |
| 192 return 0; | 196 return 0; |
| 193 | 197 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 194 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 198 if (!pDoc) |
| 199 return 0; | |
| 195 CPDF_Dest dest((CPDF_Array*)pDict); | 200 CPDF_Dest dest((CPDF_Array*)pDict); |
| 196 return dest.GetPageIndex(pDoc); | 201 return dest.GetPageIndex(pDoc); |
| 197 } | 202 } |
| 198 | 203 |
| 199 DLLEXPORT FPDF_LINK STDCALL | 204 DLLEXPORT FPDF_LINK STDCALL |
| 200 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { | 205 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { |
| 201 CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page; | 206 CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page; |
| 202 CPDF_Page* pPage = pXFAPage->GetPDFPage(); | 207 CPDF_Page* pPage = pXFAPage->GetPDFPage(); |
| 203 if (!pPage) | 208 if (!pPage) |
| 204 return nullptr; | 209 return nullptr; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 222 if (!pLinkList) | 227 if (!pLinkList) |
| 223 return -1; | 228 return -1; |
| 224 | 229 |
| 225 int z_order = -1; | 230 int z_order = -1; |
| 226 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); | 231 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); |
| 227 return z_order; | 232 return z_order; |
| 228 } | 233 } |
| 229 | 234 |
| 230 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 235 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 231 FPDF_LINK pDict) { | 236 FPDF_LINK pDict) { |
| 232 if (!document || !pDict) | 237 if (!pDict) |
| 233 return nullptr; | 238 return nullptr; |
| 234 | 239 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 235 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 240 if (!pDoc) |
| 241 return nullptr; | |
| 236 CPDF_Link link((CPDF_Dictionary*)pDict); | 242 CPDF_Link link((CPDF_Dictionary*)pDict); |
| 237 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); | 243 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
| 238 if (dest) | 244 if (dest) |
| 239 return dest; | 245 return dest; |
| 240 // If this link is not directly associated with a dest, we try to get action | 246 // If this link is not directly associated with a dest, we try to get action |
| 241 CPDF_Action action = link.GetAction(); | 247 CPDF_Action action = link.GetAction(); |
| 242 if (!action) | 248 if (!action) |
| 243 return nullptr; | 249 return nullptr; |
| 244 return action.GetDest(pDoc).GetObject(); | 250 return action.GetDest(pDoc).GetObject(); |
| 245 } | 251 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 quadPoints->y4 = pArray->GetNumber(quadIndex * 8 + 7); | 326 quadPoints->y4 = pArray->GetNumber(quadIndex * 8 + 7); |
| 321 return TRUE; | 327 return TRUE; |
| 322 } | 328 } |
| 323 return FALSE; | 329 return FALSE; |
| 324 } | 330 } |
| 325 | 331 |
| 326 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, | 332 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, |
| 327 FPDF_BYTESTRING tag, | 333 FPDF_BYTESTRING tag, |
| 328 void* buffer, | 334 void* buffer, |
| 329 unsigned long buflen) { | 335 unsigned long buflen) { |
| 330 if (!doc || !tag) | 336 if (!tag) |
| 331 return 0; | 337 return 0; |
| 332 CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc(); | 338 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
| 333 // Get info dictionary | 339 if (!pDoc) |
| 340 return 0; | |
| 334 CPDF_Dictionary* pInfo = pDoc->GetInfo(); | 341 CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
| 335 if (!pInfo) | 342 if (!pInfo) |
| 336 return 0; | 343 return 0; |
| 337 CFX_WideString text = pInfo->GetUnicodeText(tag); | 344 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 338 // Use UTF-16LE encoding | 345 // Use UTF-16LE encoding |
| 339 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 346 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 340 unsigned long len = encodedText.GetLength(); | 347 unsigned long len = encodedText.GetLength(); |
| 341 if (buffer && buflen >= len) { | 348 if (buffer && buflen >= len) { |
| 342 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 349 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 343 } | 350 } |
| 344 return len; | 351 return len; |
| 345 } | 352 } |
| OLD | NEW |