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

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

Issue 1295893005: Merge to XFA: Add new public APIs to find the z-order for links and widgets. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: self review Created 5 years, 4 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 | « core/src/fpdfdoc/doc_link.cpp ('k') | fpdfsdk/src/fpdfformfill.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 "../../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
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) { 188 DLLEXPORT FPDF_LINK STDCALL
167 delete (CPDF_LinkList*)data; 189 FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y) {
190 CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page;
191 CPDF_Page* pPage = pXFAPage->GetPDFPage();
192 if (!pPage)
193 return nullptr;
194
195 CPDF_LinkList* pLinkList = GetLinkList(pPage);
196 if (!pLinkList)
197 return nullptr;
198
199 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, nullptr)
200 .GetDict();
168 } 201 }
169 202
170 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, 203 DLLEXPORT int STDCALL
171 double x, 204 FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) {
172 double y) { 205 CPDFXFA_Page* pXFAPage = (CPDFXFA_Page*)page;
173 if (!page) 206 CPDF_Page* pPage = pXFAPage->GetPDFPage();
174 return NULL;
175 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
176 if (!pPage) 207 if (!pPage)
177 return NULL; 208 return -1;
178 // Link list is stored with the document 209
179 CPDF_Document* pDoc = pPage->m_pDocument; 210 CPDF_LinkList* pLinkList = GetLinkList(pPage);
180 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); 211 if (!pLinkList)
181 if (!pLinkList) { 212 return -1;
182 pLinkList = new CPDF_LinkList(pDoc); 213
183 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); 214 int z_order = -1;
184 } 215 pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y, &z_order);
185 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); 216 return z_order;
186 } 217 }
187 218
188 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, 219 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document,
189 FPDF_LINK pDict) { 220 FPDF_LINK pDict) {
190 if (!document) 221 if (!document)
191 return NULL; 222 return NULL;
192 if (!pDict) 223 if (!pDict)
193 return NULL; 224 return NULL;
194 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); 225 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
195 CPDF_Link link((CPDF_Dictionary*)pDict); 226 CPDF_Link link((CPDF_Dictionary*)pDict);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return 0; 325 return 0;
295 CFX_WideString text = pInfo->GetUnicodeText(tag); 326 CFX_WideString text = pInfo->GetUnicodeText(tag);
296 // Use UTF-16LE encoding 327 // Use UTF-16LE encoding
297 CFX_ByteString encodedText = text.UTF16LE_Encode(); 328 CFX_ByteString encodedText = text.UTF16LE_Encode();
298 unsigned long len = encodedText.GetLength(); 329 unsigned long len = encodedText.GetLength();
299 if (buffer && buflen >= len) { 330 if (buffer && buflen >= len) {
300 FXSYS_memcpy(buffer, encodedText.c_str(), len); 331 FXSYS_memcpy(buffer, encodedText.c_str(), len);
301 } 332 }
302 return len; 333 return len;
303 } 334 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_link.cpp ('k') | fpdfsdk/src/fpdfformfill.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698