| 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 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 pLinkList = new CPDF_LinkList; | 45 pLinkList = new CPDF_LinkList; |
| 46 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | 46 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
| 47 } | 47 } |
| 48 return pLinkList; | 48 return pLinkList; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 DLLEXPORT FPDF_BOOKMARK STDCALL | 53 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 54 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 54 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 55 if (!document) | 55 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 56 return NULL; | 56 if (!pDoc) |
| 57 CPDF_Document* pDoc = (CPDF_Document*)document; | 57 return nullptr; |
| 58 CPDF_BookmarkTree tree(pDoc); | 58 CPDF_BookmarkTree tree(pDoc); |
| 59 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 59 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 60 return tree.GetFirstChild(bookmark).GetDict(); | 60 return tree.GetFirstChild(bookmark).GetDict(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 DLLEXPORT FPDF_BOOKMARK STDCALL | 63 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 64 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 64 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 65 if (!document || !pDict) | 65 if (!pDict) |
| 66 return NULL; | 66 return nullptr; |
| 67 CPDF_Document* pDoc = (CPDF_Document*)document; | 67 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 68 if (!pDoc) |
| 69 return nullptr; |
| 68 CPDF_BookmarkTree tree(pDoc); | 70 CPDF_BookmarkTree tree(pDoc); |
| 69 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 71 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 70 return tree.GetNextSibling(bookmark).GetDict(); | 72 return tree.GetNextSibling(bookmark).GetDict(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, | 75 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, |
| 74 void* buffer, | 76 void* buffer, |
| 75 unsigned long buflen) { | 77 unsigned long buflen) { |
| 76 if (!pDict) | 78 if (!pDict) |
| 77 return 0; | 79 return 0; |
| 78 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 80 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 79 CFX_WideString title = bookmark.GetTitle(); | 81 CFX_WideString title = bookmark.GetTitle(); |
| 80 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); | 82 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
| 81 unsigned long len = encodedTitle.GetLength(); | 83 unsigned long len = encodedTitle.GetLength(); |
| 82 if (buffer && buflen >= len) { | 84 if (buffer && buflen >= len) { |
| 83 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); | 85 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
| 84 } | 86 } |
| 85 return len; | 87 return len; |
| 86 } | 88 } |
| 87 | 89 |
| 88 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, | 90 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, |
| 89 FPDF_WIDESTRING title) { | 91 FPDF_WIDESTRING title) { |
| 90 if (!document) | |
| 91 return NULL; | |
| 92 if (!title || title[0] == 0) | 92 if (!title || title[0] == 0) |
| 93 return NULL; | 93 return nullptr; |
| 94 CPDF_Document* pDoc = (CPDF_Document*)document; | 94 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 95 if (!pDoc) |
| 96 return nullptr; |
| 95 CPDF_BookmarkTree tree(pDoc); | 97 CPDF_BookmarkTree tree(pDoc); |
| 96 FX_STRSIZE len = CFX_WideString::WStringLength(title); | 98 FX_STRSIZE len = CFX_WideString::WStringLength(title); |
| 97 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); | 99 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
| 98 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); | 100 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, | 103 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, |
| 102 FPDF_BOOKMARK pDict) { | 104 FPDF_BOOKMARK pDict) { |
| 103 if (!document) | |
| 104 return NULL; | |
| 105 if (!pDict) | 105 if (!pDict) |
| 106 return NULL; | 106 return nullptr; |
| 107 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 108 if (!pDoc) |
| 109 return nullptr; |
| 107 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 110 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 108 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 109 CPDF_Dest dest = bookmark.GetDest(pDoc); | 111 CPDF_Dest dest = bookmark.GetDest(pDoc); |
| 110 if (dest) | 112 if (dest) |
| 111 return dest.GetObject(); | 113 return dest.GetObject(); |
| 112 // If this bookmark is not directly associated with a dest, we try to get | 114 // If this bookmark is not directly associated with a dest, we try to get |
| 113 // action | 115 // action |
| 114 CPDF_Action action = bookmark.GetAction(); | 116 CPDF_Action action = bookmark.GetAction(); |
| 115 if (!action) | 117 if (!action) |
| 116 return NULL; | 118 return nullptr; |
| 117 return action.GetDest(pDoc).GetObject(); | 119 return action.GetDest(pDoc).GetObject(); |
| 118 } | 120 } |
| 119 | 121 |
| 120 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { | 122 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { |
| 121 if (!pDict) | 123 if (!pDict) |
| 122 return NULL; | 124 return NULL; |
| 123 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 125 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 124 return bookmark.GetAction().GetDict(); | 126 return bookmark.GetAction().GetDict(); |
| 125 } | 127 } |
| 126 | 128 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 return PDFACTION_URI; | 141 return PDFACTION_URI; |
| 140 case CPDF_Action::Launch: | 142 case CPDF_Action::Launch: |
| 141 return PDFACTION_LAUNCH; | 143 return PDFACTION_LAUNCH; |
| 142 default: | 144 default: |
| 143 return PDFACTION_UNSUPPORTED; | 145 return PDFACTION_UNSUPPORTED; |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 | 148 |
| 147 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, | 149 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, |
| 148 FPDF_ACTION pDict) { | 150 FPDF_ACTION pDict) { |
| 149 if (!document || !pDict) | 151 if (!pDict) |
| 150 return nullptr; | 152 return nullptr; |
| 151 | 153 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 152 CPDF_Document* pDoc = (CPDF_Document*)document; | 154 if (!pDoc) |
| 155 return nullptr; |
| 153 CPDF_Action action((CPDF_Dictionary*)pDict); | 156 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 154 return action.GetDest(pDoc).GetObject(); | 157 return action.GetDest(pDoc).GetObject(); |
| 155 } | 158 } |
| 156 | 159 |
| 157 DLLEXPORT unsigned long STDCALL | 160 DLLEXPORT unsigned long STDCALL |
| 158 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { | 161 FPDFAction_GetFilePath(FPDF_ACTION pDict, void* buffer, unsigned long buflen) { |
| 159 unsigned long type = FPDFAction_GetType(pDict); | 162 unsigned long type = FPDFAction_GetType(pDict); |
| 160 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) | 163 if (type != PDFACTION_REMOTEGOTO && type != PDFACTION_LAUNCH) |
| 161 return 0; | 164 return 0; |
| 162 | 165 |
| 163 CPDF_Action action((CPDF_Dictionary*)pDict); | 166 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 164 CFX_ByteString path = action.GetFilePath().UTF8Encode(); | 167 CFX_ByteString path = action.GetFilePath().UTF8Encode(); |
| 165 unsigned long len = path.GetLength() + 1; | 168 unsigned long len = path.GetLength() + 1; |
| 166 if (buffer && buflen >= len) | 169 if (buffer && buflen >= len) |
| 167 FXSYS_memcpy(buffer, path.c_str(), len); | 170 FXSYS_memcpy(buffer, path.c_str(), len); |
| 168 return len; | 171 return len; |
| 169 } | 172 } |
| 170 | 173 |
| 171 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, | 174 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
| 172 FPDF_ACTION pDict, | 175 FPDF_ACTION pDict, |
| 173 void* buffer, | 176 void* buffer, |
| 174 unsigned long buflen) { | 177 unsigned long buflen) { |
| 175 if (!document || !pDict) | 178 if (!pDict) |
| 176 return 0; | 179 return 0; |
| 177 | 180 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 178 CPDF_Document* pDoc = (CPDF_Document*)document; | 181 if (!pDoc) |
| 182 return 0; |
| 179 CPDF_Action action((CPDF_Dictionary*)pDict); | 183 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 180 CFX_ByteString path = action.GetURI(pDoc); | 184 CFX_ByteString path = action.GetURI(pDoc); |
| 181 unsigned long len = path.GetLength() + 1; | 185 unsigned long len = path.GetLength() + 1; |
| 182 if (buffer && buflen >= len) | 186 if (buffer && buflen >= len) |
| 183 FXSYS_memcpy(buffer, path.c_str(), len); | 187 FXSYS_memcpy(buffer, path.c_str(), len); |
| 184 return len; | 188 return len; |
| 185 } | 189 } |
| 186 | 190 |
| 187 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, | 191 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
| 188 FPDF_DEST pDict) { | 192 FPDF_DEST pDict) { |
| 189 if (!document || !pDict) | 193 if (!pDict) |
| 190 return 0; | 194 return 0; |
| 191 | 195 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 192 CPDF_Document* pDoc = (CPDF_Document*)document; | 196 if (!pDoc) |
| 197 return 0; |
| 193 CPDF_Dest dest((CPDF_Array*)pDict); | 198 CPDF_Dest dest((CPDF_Array*)pDict); |
| 194 return dest.GetPageIndex(pDoc); | 199 return dest.GetPageIndex(pDoc); |
| 195 } | 200 } |
| 196 | 201 |
| 197 DLLEXPORT FPDF_LINK STDCALL | 202 DLLEXPORT FPDF_LINK STDCALL |
| 198 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { | 203 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) { |
| 199 CPDF_Page* pPage = (CPDF_Page*)page; | 204 CPDF_Page* pPage = (CPDF_Page*)page; |
| 200 CPDF_LinkList* pLinkList = GetLinkList(pPage); | 205 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 201 if (!pLinkList) | 206 if (!pLinkList) |
| 202 return nullptr; | 207 return nullptr; |
| 203 | 208 |
| 204 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr) | 209 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr) |
| 205 .GetDict(); | 210 .GetDict(); |
| 206 } | 211 } |
| 207 | 212 |
| 208 DLLEXPORT int STDCALL | 213 DLLEXPORT int STDCALL |
| 209 FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) { | 214 FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) { |
| 210 CPDF_Page* pPage = (CPDF_Page*)page; | 215 CPDF_Page* pPage = (CPDF_Page*)page; |
| 211 CPDF_LinkList* pLinkList = GetLinkList(pPage); | 216 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 212 if (!pLinkList) | 217 if (!pLinkList) |
| 213 return -1; | 218 return -1; |
| 214 | 219 |
| 215 int z_order = -1; | 220 int z_order = -1; |
| 216 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); | 221 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); |
| 217 return z_order; | 222 return z_order; |
| 218 } | 223 } |
| 219 | 224 |
| 220 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 225 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 221 FPDF_LINK pDict) { | 226 FPDF_LINK pDict) { |
| 222 if (!document || !pDict) | 227 if (!pDict) |
| 223 return nullptr; | 228 return nullptr; |
| 224 | 229 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); |
| 225 CPDF_Document* pDoc = (CPDF_Document*)document; | 230 if (!pDoc) |
| 231 return nullptr; |
| 226 CPDF_Link link((CPDF_Dictionary*)pDict); | 232 CPDF_Link link((CPDF_Dictionary*)pDict); |
| 227 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); | 233 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
| 228 if (dest) | 234 if (dest) |
| 229 return dest; | 235 return dest; |
| 230 // If this link is not directly associated with a dest, we try to get action | 236 // If this link is not directly associated with a dest, we try to get action |
| 231 CPDF_Action action = link.GetAction(); | 237 CPDF_Action action = link.GetAction(); |
| 232 if (!action) | 238 if (!action) |
| 233 return nullptr; | 239 return nullptr; |
| 234 return action.GetDest(pDoc).GetObject(); | 240 return action.GetDest(pDoc).GetObject(); |
| 235 } | 241 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 quadPoints->y4 = pArray->GetNumber(quadIndex * 8 + 7); | 316 quadPoints->y4 = pArray->GetNumber(quadIndex * 8 + 7); |
| 311 return TRUE; | 317 return TRUE; |
| 312 } | 318 } |
| 313 return FALSE; | 319 return FALSE; |
| 314 } | 320 } |
| 315 | 321 |
| 316 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, | 322 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, |
| 317 FPDF_BYTESTRING tag, | 323 FPDF_BYTESTRING tag, |
| 318 void* buffer, | 324 void* buffer, |
| 319 unsigned long buflen) { | 325 unsigned long buflen) { |
| 320 if (!doc || !tag) | 326 if (!tag) |
| 321 return 0; | 327 return 0; |
| 322 CPDF_Document* pDoc = (CPDF_Document*)doc; | 328 CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(doc); |
| 323 // Get info dictionary | 329 if (!pDoc) |
| 330 return 0; |
| 324 CPDF_Dictionary* pInfo = pDoc->GetInfo(); | 331 CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
| 325 if (!pInfo) | 332 if (!pInfo) |
| 326 return 0; | 333 return 0; |
| 327 CFX_WideString text = pInfo->GetUnicodeText(tag); | 334 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 328 // Use UTF-16LE encoding | 335 // Use UTF-16LE encoding |
| 329 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 336 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 330 unsigned long len = encodedText.GetLength(); | 337 unsigned long len = encodedText.GetLength(); |
| 331 if (buffer && buflen >= len) { | 338 if (buffer && buflen >= len) { |
| 332 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 339 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 333 } | 340 } |
| 334 return len; | 341 return len; |
| 335 } | 342 } |
| OLD | NEW |