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 "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../../public/fpdf_doc.h" | 8 #include "../../public/fpdf_doc.h" |
| 9 | 9 |
| 10 static int THISMODULE = 0; | 10 namespace { |
| 11 | 11 |
| 12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, | 12 int THISMODULE = 0; |
|
Tom Sepez
2015/08/11 17:25:01
nit: g_ThisModule so long as you're mucking with i
| |
| 13 CPDF_Bookmark bookmark, | 13 |
| 14 const CFX_WideString& title) { | 14 CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 15 CPDF_Bookmark bookmark, | |
| 16 const CFX_WideString& title) { | |
| 15 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { | 17 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
| 16 // First check this item | 18 // First check this item |
| 17 return bookmark; | 19 return bookmark; |
| 18 } | 20 } |
| 19 // go into children items | 21 // go into children items |
| 20 CPDF_Bookmark child = tree.GetFirstChild(bookmark); | 22 CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
| 21 while (child) { | 23 while (child) { |
| 22 // check if this item | 24 // check if this item |
| 23 CPDF_Bookmark found = FindBookmark(tree, child, title); | 25 CPDF_Bookmark found = FindBookmark(tree, child, title); |
| 24 if (found) | 26 if (found) |
| 25 return found; | 27 return found; |
| 26 child = tree.GetNextSibling(child); | 28 child = tree.GetNextSibling(child); |
| 27 } | 29 } |
| 28 return CPDF_Bookmark(); | 30 return CPDF_Bookmark(); |
| 29 } | 31 } |
| 30 | 32 |
| 33 void ReleaseLinkList(void* data) { | |
| 34 delete (CPDF_LinkList*)data; | |
| 35 } | |
| 36 | |
| 37 CPDF_LinkList* GetLinkList(CPDF_Page* page) { | |
| 38 if (!page) | |
| 39 return nullptr; | |
| 40 | |
| 41 // Link list is stored with the document | |
| 42 CPDF_Document* pDoc = page->m_pDocument; | |
| 43 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); | |
| 44 if (!pLinkList) { | |
| 45 pLinkList = new CPDF_LinkList; | |
| 46 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | |
| 47 } | |
| 48 return pLinkList; | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 31 DLLEXPORT FPDF_BOOKMARK STDCALL | 53 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 32 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { | 54 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 33 if (!document) | 55 if (!document) |
| 34 return NULL; | 56 return NULL; |
| 35 CPDF_Document* pDoc = (CPDF_Document*)document; | 57 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 36 CPDF_BookmarkTree tree(pDoc); | 58 CPDF_BookmarkTree tree(pDoc); |
| 37 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 59 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 38 return tree.GetFirstChild(bookmark).GetDict(); | 60 return tree.GetFirstChild(bookmark).GetDict(); |
| 39 } | 61 } |
| 40 | 62 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 FPDF_DEST pDict) { | 176 FPDF_DEST pDict) { |
| 155 if (!document) | 177 if (!document) |
| 156 return 0; | 178 return 0; |
| 157 if (!pDict) | 179 if (!pDict) |
| 158 return 0; | 180 return 0; |
| 159 CPDF_Document* pDoc = (CPDF_Document*)document; | 181 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 160 CPDF_Dest dest((CPDF_Array*)pDict); | 182 CPDF_Dest dest((CPDF_Array*)pDict); |
| 161 return dest.GetPageIndex(pDoc); | 183 return dest.GetPageIndex(pDoc); |
| 162 } | 184 } |
| 163 | 185 |
| 164 static void ReleaseLinkList(void* data) { | |
| 165 delete (CPDF_LinkList*)data; | |
| 166 } | |
| 167 | |
| 168 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, | 186 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, |
| 169 double x, | 187 double x, |
| 170 double y) { | 188 double y) { |
| 171 if (!page) | |
| 172 return NULL; | |
| 173 CPDF_Page* pPage = (CPDF_Page*)page; | 189 CPDF_Page* pPage = (CPDF_Page*)page; |
| 174 // Link list is stored with the document | 190 CPDF_LinkList* pLinkList = GetLinkList(pPage); |
| 175 CPDF_Document* pDoc = pPage->m_pDocument; | 191 if (!pLinkList) |
| 176 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); | 192 return nullptr; |
| 177 if (!pLinkList) { | 193 |
| 178 pLinkList = new CPDF_LinkList(pDoc); | 194 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr) |
| 179 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | 195 .GetDict(); |
| 180 } | 196 } |
| 181 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); | 197 |
| 198 DLLEXPORT int STDCALL FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, | |
| 199 double x, | |
| 200 double y) { | |
| 201 CPDF_Page* pPage = (CPDF_Page*)page; | |
| 202 CPDF_LinkList* pLinkList = GetLinkList(pPage); | |
| 203 if (!pLinkList) | |
| 204 return -1; | |
| 205 | |
| 206 int z_order = -1; | |
| 207 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order); | |
| 208 return z_order; | |
| 182 } | 209 } |
| 183 | 210 |
| 184 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, | 211 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 185 FPDF_LINK pDict) { | 212 FPDF_LINK pDict) { |
| 186 if (!document) | 213 if (!document) |
| 187 return NULL; | 214 return NULL; |
| 188 if (!pDict) | 215 if (!pDict) |
| 189 return NULL; | 216 return NULL; |
| 190 CPDF_Document* pDoc = (CPDF_Document*)document; | 217 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 191 CPDF_Link link((CPDF_Dictionary*)pDict); | 218 CPDF_Link link((CPDF_Dictionary*)pDict); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 return 0; | 317 return 0; |
| 291 CFX_WideString text = pInfo->GetUnicodeText(tag); | 318 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 292 // Use UTF-16LE encoding | 319 // Use UTF-16LE encoding |
| 293 CFX_ByteString encodedText = text.UTF16LE_Encode(); | 320 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 294 unsigned long len = encodedText.GetLength(); | 321 unsigned long len = encodedText.GetLength(); |
| 295 if (buffer && buflen >= len) { | 322 if (buffer && buflen >= len) { |
| 296 FXSYS_memcpy(buffer, encodedText.c_str(), len); | 323 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 297 } | 324 } |
| 298 return len; | 325 return len; |
| 299 } | 326 } |
| OLD | NEW |