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" |
| 11 | 11 |
| 12 static int THISMODULE = 0; | 12 namespace { |
| 13 | 13 |
| 14 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, | 14 int THISMODULE = 0; |
| 15 CPDF_Bookmark bookmark, | 15 |
| 16 const CFX_WideString& title) { | 16 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 17 CPDF_Bookmark bookmark, | |
| 18 const CFX_WideString& title) { | |
| 17 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { | 19 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
| 18 // First check this item | 20 // First check this item |
| 19 return bookmark; | 21 return bookmark; |
| 20 } | 22 } |
| 21 // go into children items | 23 // go into children items |
| 22 CPDF_Bookmark child = tree.GetFirstChild(bookmark); | 24 CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
| 23 while (child) { | 25 while (child) { |
| 24 // check if this item | 26 // check if this item |
| 25 CPDF_Bookmark found = FindBookmark(tree, child, title); | 27 CPDF_Bookmark found = FindBookmark(tree, child, title); |
| 26 if (found) | 28 if (found) |
| 27 return found; | 29 return found; |
| 28 child = tree.GetNextSibling(child); | 30 child = tree.GetNextSibling(child); |
| 29 } | 31 } |
| 30 return CPDF_Bookmark(); | 32 return CPDF_Bookmark(); |
| 31 } | 33 } |
| 32 | 34 |
| 35 void ReleaseLinkList(void* data) { | |
| 36 delete (CPDF_LinkList*)data; | |
| 37 } | |
| 38 | |
| 39 CPDF_LinkList* GetLinkList(CPDF_Page* page) { | |
| 40 if (!page) | |
| 41 return nullptr; | |
| 42 | |
| 43 // Link list is stored with the document | |
| 44 CPDF_Document* pDoc = page->m_pDocument; | |
| 45 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); | |
| 46 if (!pLinkList) { | |
| 47 pLinkList = new CPDF_LinkList; | |
| 48 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | |
| 49 } | |
| 50 return pLinkList; | |
| 51 } | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 33 DLLEXPORT FPDF_BOOKMARK STDCALL | 55 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 34 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 56 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 35 if (!document || !pDict) | 57 if (!document || !pDict) |
| 36 return NULL; | 58 return NULL; |
| 37 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 59 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 38 CPDF_BookmarkTree tree(pDoc); | 60 CPDF_BookmarkTree tree(pDoc); |
| 39 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 61 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 40 return tree.GetFirstChild(bookmark).GetDict(); | 62 return tree.GetFirstChild(bookmark).GetDict(); |
| 41 } | 63 } |
| 42 | 64 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 FPDF_DEST pDict) { | 178 FPDF_DEST pDict) { |
| 157 if (!document) | 179 if (!document) |
| 158 return 0; | 180 return 0; |
| 159 if (!pDict) | 181 if (!pDict) |
| 160 return 0; | 182 return 0; |
| 161 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 183 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 162 CPDF_Dest dest((CPDF_Array*)pDict); | 184 CPDF_Dest dest((CPDF_Array*)pDict); |
| 163 return dest.GetPageIndex(pDoc); | 185 return dest.GetPageIndex(pDoc); |
| 164 } | 186 } |
| 165 | 187 |
| 166 static void ReleaseLinkList(void* data) { | |
| 167 delete (CPDF_LinkList*)data; | |
| 168 } | |
| 169 | |
| 170 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, | 188 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, |
| 171 double x, | 189 double x, |
| 172 double y) { | 190 double y) { |
| 173 if (!page) | 191 CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page; |
|
Lei Zhang
2015/08/15 02:23:58
conflicted here.
| |
| 174 return NULL; | 192 CPDF_Page* pPage = pXFAPage->GetPDFPage(); |
| 175 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | |
| 176 if (!pPage) | 193 if (!pPage) |
| 177 return NULL; | 194 return nullptr; |
| 178 // Link list is stored with the document | 195 |
| 179 CPDF_Document* pDoc = pPage->m_pDocument; | 196 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 180 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); | 197 if (!pLinkList) |
| 181 if (!pLinkList) { | 198 return nullptr; |
| 182 pLinkList = new CPDF_LinkList(pDoc); | 199 |
| 183 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | 200 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr) |
| 184 } | 201 .GetDict(); |
| 185 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); | 202 } |
| 203 | |
| 204 DLLEXPORT int STDCALL | |
| 205 FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) { | |
| 206 CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page; | |
| 207 CPDF_Page* pPage = pXFAPage->GetPDFPage(); | |
| 208 if (!pPage) | |
| 209 return -1; | |
| 210 | |
| 211 CPDF_LinkList* pLinkList = GetLinkList(pPage); | |
| 212 if (!pLinkList) | |
| 213 return -1; | |
| 214 | |
| 215 int z_order = -1; | |
| 216 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); | |
| 217 return z_order; | |
| 186 } | 218 } |
| 187 | 219 |
| 188 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 220 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 189 FPDF_LINK pDict) { | 221 FPDF_LINK pDict) { |
| 190 if (!document) | 222 if (!document) |
| 191 return NULL; | 223 return NULL; |
| 192 if (!pDict) | 224 if (!pDict) |
| 193 return NULL; | 225 return NULL; |
| 194 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | 226 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); |
| 195 CPDF_Link link((CPDF_Dictionary*)pDict); | 227 CPDF_Link link((CPDF_Dictionary*)pDict); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 return 0; | 326 return 0; |
| 295 CFX_WideString text = pInfo->GetUnicodeText(tag); | 327 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 296 // Use UTF-16LE encoding | 328 // Use UTF-16LE encoding |
| 297 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 329 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 298 unsigned long len = encodedText.GetLength(); | 330 unsigned long len = encodedText.GetLength(); |
| 299 if (buffer && buflen >= len) { | 331 if (buffer && buflen >= len) { |
| 300 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 332 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 301 } | 333 } |
| 302 return len; | 334 return len; |
| 303 } | 335 } |
| OLD | NEW |