| 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 static int THISMODULE = 0; |
| 11 | 11 |
| 12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark b
ookmark, const CFX_WideString& title) | 12 static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, |
| 13 { | 13 CPDF_Bookmark bookmark, |
| 14 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { | 14 const CFX_WideString& title) { |
| 15 // First check this item | 15 if (bookmark && bookmark.GetTitle().CompareNoCase(title.c_str()) == 0) { |
| 16 return bookmark; | 16 // First check this item |
| 17 return bookmark; |
| 18 } |
| 19 // go into children items |
| 20 CPDF_Bookmark child = tree.GetFirstChild(bookmark); |
| 21 while (child) { |
| 22 // check if this item |
| 23 CPDF_Bookmark found = FindBookmark(tree, child, title); |
| 24 if (found) |
| 25 return found; |
| 26 child = tree.GetNextSibling(child); |
| 27 } |
| 28 return CPDF_Bookmark(); |
| 29 } |
| 30 |
| 31 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 32 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 33 if (!document) |
| 34 return NULL; |
| 35 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 36 CPDF_BookmarkTree tree(pDoc); |
| 37 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 38 return tree.GetFirstChild(bookmark).GetDict(); |
| 39 } |
| 40 |
| 41 DLLEXPORT FPDF_BOOKMARK STDCALL |
| 42 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) { |
| 43 if (!document || !pDict) |
| 44 return NULL; |
| 45 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 46 CPDF_BookmarkTree tree(pDoc); |
| 47 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); |
| 48 return tree.GetNextSibling(bookmark).GetDict(); |
| 49 } |
| 50 |
| 51 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, |
| 52 void* buffer, |
| 53 unsigned long buflen) { |
| 54 if (!pDict) |
| 55 return 0; |
| 56 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 57 CFX_WideString title = bookmark.GetTitle(); |
| 58 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); |
| 59 unsigned long len = encodedTitle.GetLength(); |
| 60 if (buffer && buflen >= len) { |
| 61 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); |
| 62 } |
| 63 return len; |
| 64 } |
| 65 |
| 66 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, |
| 67 FPDF_WIDESTRING title) { |
| 68 if (!document) |
| 69 return NULL; |
| 70 if (!title || title[0] == 0) |
| 71 return NULL; |
| 72 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 73 CPDF_BookmarkTree tree(pDoc); |
| 74 FX_STRSIZE len = CFX_WideString::WStringLength(title); |
| 75 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); |
| 76 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); |
| 77 } |
| 78 |
| 79 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, |
| 80 FPDF_BOOKMARK pDict) { |
| 81 if (!document) |
| 82 return NULL; |
| 83 if (!pDict) |
| 84 return NULL; |
| 85 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 86 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 87 CPDF_Dest dest = bookmark.GetDest(pDoc); |
| 88 if (dest) |
| 89 return dest.GetObject(); |
| 90 // If this bookmark is not directly associated with a dest, we try to get |
| 91 // action |
| 92 CPDF_Action action = bookmark.GetAction(); |
| 93 if (!action) |
| 94 return NULL; |
| 95 return action.GetDest(pDoc).GetObject(); |
| 96 } |
| 97 |
| 98 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) { |
| 99 if (!pDict) |
| 100 return NULL; |
| 101 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); |
| 102 return bookmark.GetAction().GetDict(); |
| 103 } |
| 104 |
| 105 DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) { |
| 106 if (!pDict) |
| 107 return 0; |
| 108 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 109 CPDF_Action::ActionType type = action.GetType(); |
| 110 switch (type) { |
| 111 case CPDF_Action::GoTo: |
| 112 return PDFACTION_GOTO; |
| 113 case CPDF_Action::GoToR: |
| 114 return PDFACTION_REMOTEGOTO; |
| 115 case CPDF_Action::URI: |
| 116 return PDFACTION_URI; |
| 117 case CPDF_Action::Launch: |
| 118 return PDFACTION_LAUNCH; |
| 119 default: |
| 120 return PDFACTION_UNSUPPORTED; |
| 121 } |
| 122 return PDFACTION_UNSUPPORTED; |
| 123 } |
| 124 |
| 125 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, |
| 126 FPDF_ACTION pDict) { |
| 127 if (!document) |
| 128 return NULL; |
| 129 if (!pDict) |
| 130 return NULL; |
| 131 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 132 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 133 return action.GetDest(pDoc).GetObject(); |
| 134 } |
| 135 |
| 136 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, |
| 137 FPDF_ACTION pDict, |
| 138 void* buffer, |
| 139 unsigned long buflen) { |
| 140 if (!document) |
| 141 return 0; |
| 142 if (!pDict) |
| 143 return 0; |
| 144 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 145 CPDF_Action action((CPDF_Dictionary*)pDict); |
| 146 CFX_ByteString path = action.GetURI(pDoc); |
| 147 unsigned long len = path.GetLength() + 1; |
| 148 if (buffer != NULL && buflen >= len) |
| 149 FXSYS_memcpy(buffer, path.c_str(), len); |
| 150 return len; |
| 151 } |
| 152 |
| 153 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, |
| 154 FPDF_DEST pDict) { |
| 155 if (!document) |
| 156 return 0; |
| 157 if (!pDict) |
| 158 return 0; |
| 159 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 160 CPDF_Dest dest((CPDF_Array*)pDict); |
| 161 return dest.GetPageIndex(pDoc); |
| 162 } |
| 163 |
| 164 static void ReleaseLinkList(void* data) { |
| 165 delete (CPDF_LinkList*)data; |
| 166 } |
| 167 |
| 168 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, |
| 169 double x, |
| 170 double y) { |
| 171 if (!page) |
| 172 return NULL; |
| 173 CPDF_Page* pPage = (CPDF_Page*)page; |
| 174 // Link list is stored with the document |
| 175 CPDF_Document* pDoc = pPage->m_pDocument; |
| 176 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE); |
| 177 if (!pLinkList) { |
| 178 pLinkList = new CPDF_LinkList(pDoc); |
| 179 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); |
| 180 } |
| 181 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); |
| 182 } |
| 183 |
| 184 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, |
| 185 FPDF_LINK pDict) { |
| 186 if (!document) |
| 187 return NULL; |
| 188 if (!pDict) |
| 189 return NULL; |
| 190 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 191 CPDF_Link link((CPDF_Dictionary*)pDict); |
| 192 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); |
| 193 if (dest) |
| 194 return dest; |
| 195 // If this link is not directly associated with a dest, we try to get action |
| 196 CPDF_Action action = link.GetAction(); |
| 197 if (!action) |
| 198 return NULL; |
| 199 return action.GetDest(pDoc).GetObject(); |
| 200 } |
| 201 |
| 202 DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) { |
| 203 if (!pDict) |
| 204 return NULL; |
| 205 CPDF_Link link((CPDF_Dictionary*)pDict); |
| 206 return link.GetAction().GetDict(); |
| 207 } |
| 208 |
| 209 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, |
| 210 int* startPos, |
| 211 FPDF_LINK* linkAnnot) { |
| 212 if (!page || !startPos || !linkAnnot) |
| 213 return FALSE; |
| 214 CPDF_Page* pPage = (CPDF_Page*)page; |
| 215 if (!pPage->m_pFormDict) |
| 216 return FALSE; |
| 217 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); |
| 218 if (!pAnnots) |
| 219 return FALSE; |
| 220 for (int i = *startPos; i < (int)pAnnots->GetCount(); i++) { |
| 221 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i); |
| 222 if (!pDict || pDict->GetType() != PDFOBJ_DICTIONARY) |
| 223 continue; |
| 224 if (pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))) { |
| 225 *startPos = i + 1; |
| 226 *linkAnnot = (FPDF_LINK)pDict; |
| 227 return TRUE; |
| 17 } | 228 } |
| 18 // go into children items | 229 } |
| 19 CPDF_Bookmark child = tree.GetFirstChild(bookmark); | 230 return FALSE; |
| 20 while (child) { | 231 } |
| 21 // check if this item | 232 |
| 22 CPDF_Bookmark found = FindBookmark(tree, child, title); | 233 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, |
| 23 if (found) | 234 FS_RECTF* rect) { |
| 24 return found; | 235 if (!linkAnnot || !rect) |
| 25 child = tree.GetNextSibling(child); | 236 return FALSE; |
| 26 } | 237 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 27 return CPDF_Bookmark(); | 238 CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect")); |
| 28 } | 239 rect->left = rt.left; |
| 29 | 240 rect->bottom = rt.bottom; |
| 30 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetFirstChild(FPDF_DOCUMENT documen
t, FPDF_BOOKMARK pDict) | 241 rect->right = rt.right; |
| 31 { | 242 rect->top = rt.top; |
| 32 if (!document) | 243 return TRUE; |
| 33 return NULL; | 244 } |
| 34 CPDF_Document* pDoc = (CPDF_Document*)document; | 245 |
| 35 CPDF_BookmarkTree tree(pDoc); | 246 DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) { |
| 36 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 247 if (!linkAnnot) |
| 37 return tree.GetFirstChild(bookmark).GetDict(); | 248 return 0; |
| 38 } | 249 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 39 | 250 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); |
| 40 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetNextSibling(FPDF_DOCUMENT docume
nt, FPDF_BOOKMARK pDict) | 251 if (!pArray) |
| 41 { | 252 return 0; |
| 42 if (!document || !pDict) | 253 return pArray->GetCount() / 8; |
| 43 return NULL; | 254 } |
| 44 CPDF_Document* pDoc = (CPDF_Document*)document; | 255 |
| 45 CPDF_BookmarkTree tree(pDoc); | 256 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, |
| 46 CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); | 257 int quadIndex, |
| 47 return tree.GetNextSibling(bookmark).GetDict(); | 258 FS_QUADPOINTSF* quadPoints) { |
| 48 } | 259 if (!linkAnnot || !quadPoints) |
| 49 | 260 return FALSE; |
| 50 DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void*
buffer, unsigned long buflen) | 261 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; |
| 51 { | 262 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); |
| 52 if (!pDict) | 263 if (pArray) { |
| 53 return 0; | 264 if (quadIndex < 0 || quadIndex >= (int)pArray->GetCount() / 8 || |
| 54 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | 265 ((quadIndex * 8 + 7) >= (int)pArray->GetCount())) |
| 55 CFX_WideString title = bookmark.GetTitle(); | 266 return FALSE; |
| 56 CFX_ByteString encodedTitle = title.UTF16LE_Encode(); | 267 quadPoints->x1 = pArray->GetNumber(quadIndex * 8); |
| 57 unsigned long len = encodedTitle.GetLength(); | 268 quadPoints->y1 = pArray->GetNumber(quadIndex * 8 + 1); |
| 58 if (buffer && buflen >= len) { | 269 quadPoints->x2 = pArray->GetNumber(quadIndex * 8 + 2); |
| 59 FXSYS_memcpy(buffer, encodedTitle.c_str(), len); | 270 quadPoints->y2 = pArray->GetNumber(quadIndex * 8 + 3); |
| 60 } | 271 quadPoints->x3 = pArray->GetNumber(quadIndex * 8 + 4); |
| 61 return len; | 272 quadPoints->y3 = pArray->GetNumber(quadIndex * 8 + 5); |
| 62 } | 273 quadPoints->x4 = pArray->GetNumber(quadIndex * 8 + 6); |
| 63 | 274 quadPoints->y4 = pArray->GetNumber(quadIndex * 8 + 7); |
| 64 DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W
IDESTRING title) | |
| 65 { | |
| 66 if (!document) | |
| 67 return NULL; | |
| 68 if (!title || title[0] == 0) | |
| 69 return NULL; | |
| 70 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 71 CPDF_BookmarkTree tree(pDoc); | |
| 72 FX_STRSIZE len = CFX_WideString::WStringLength(title); | |
| 73 CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); | |
| 74 return FindBookmark(tree, CPDF_Bookmark(), encodedTitle).GetDict(); | |
| 75 } | |
| 76 | |
| 77 DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BO
OKMARK pDict) | |
| 78 { | |
| 79 if (!document) | |
| 80 return NULL; | |
| 81 if (!pDict) | |
| 82 return NULL; | |
| 83 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | |
| 84 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 85 CPDF_Dest dest = bookmark.GetDest(pDoc); | |
| 86 if (dest) | |
| 87 return dest.GetObject(); | |
| 88 // If this bookmark is not directly associated with a dest, we try to get ac
tion | |
| 89 CPDF_Action action = bookmark.GetAction(); | |
| 90 if (!action) | |
| 91 return NULL; | |
| 92 return action.GetDest(pDoc).GetObject(); | |
| 93 } | |
| 94 | |
| 95 DLLEXPORT FPDF_ACTION STDCALL FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) | |
| 96 { | |
| 97 if (!pDict) | |
| 98 return NULL; | |
| 99 CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); | |
| 100 return bookmark.GetAction().GetDict(); | |
| 101 } | |
| 102 | |
| 103 DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) | |
| 104 { | |
| 105 if (!pDict) | |
| 106 return 0; | |
| 107 CPDF_Action action((CPDF_Dictionary*)pDict); | |
| 108 CPDF_Action::ActionType type = action.GetType(); | |
| 109 switch (type) { | |
| 110 case CPDF_Action::GoTo: | |
| 111 return PDFACTION_GOTO; | |
| 112 case CPDF_Action::GoToR: | |
| 113 return PDFACTION_REMOTEGOTO; | |
| 114 case CPDF_Action::URI: | |
| 115 return PDFACTION_URI; | |
| 116 case CPDF_Action::Launch: | |
| 117 return PDFACTION_LAUNCH; | |
| 118 default: | |
| 119 return PDFACTION_UNSUPPORTED; | |
| 120 } | |
| 121 return PDFACTION_UNSUPPORTED; | |
| 122 } | |
| 123 | |
| 124 DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTI
ON pDict) | |
| 125 { | |
| 126 if (!document) | |
| 127 return NULL; | |
| 128 if (!pDict) | |
| 129 return NULL; | |
| 130 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 131 CPDF_Action action((CPDF_Dictionary*)pDict); | |
| 132 return action.GetDest(pDoc).GetObject(); | |
| 133 } | |
| 134 | |
| 135 DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FP
DF_ACTION pDict, | |
| 136 void* buffer, unsigned long buflen
) | |
| 137 { | |
| 138 if (!document) | |
| 139 return 0; | |
| 140 if (!pDict) | |
| 141 return 0; | |
| 142 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 143 CPDF_Action action((CPDF_Dictionary*)pDict); | |
| 144 CFX_ByteString path = action.GetURI(pDoc); | |
| 145 unsigned long len = path.GetLength() + 1; | |
| 146 if (buffer != NULL && buflen >= len) | |
| 147 FXSYS_memcpy(buffer, path.c_str(), len); | |
| 148 return len; | |
| 149 } | |
| 150 | |
| 151 DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FP
DF_DEST pDict) | |
| 152 { | |
| 153 if (!document) | |
| 154 return 0; | |
| 155 if (!pDict) | |
| 156 return 0; | |
| 157 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 158 CPDF_Dest dest((CPDF_Array*)pDict); | |
| 159 return dest.GetPageIndex(pDoc); | |
| 160 } | |
| 161 | |
| 162 static void ReleaseLinkList(void* data) | |
| 163 { | |
| 164 delete (CPDF_LinkList*)data; | |
| 165 } | |
| 166 | |
| 167 DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, do
uble y) | |
| 168 { | |
| 169 if (!page) | |
| 170 return NULL; | |
| 171 CPDF_Page* pPage = (CPDF_Page*)page; | |
| 172 // Link list is stored with the document | |
| 173 CPDF_Document* pDoc = pPage->m_pDocument; | |
| 174 CPDF_LinkList* pLinkList = (CPDF_LinkList*)pDoc->GetPrivateData(&THISMODULE)
; | |
| 175 if (!pLinkList) { | |
| 176 pLinkList = new CPDF_LinkList(pDoc); | |
| 177 pDoc->SetPrivateData(&THISMODULE, pLinkList, ReleaseLinkList); | |
| 178 } | |
| 179 return pLinkList->GetLinkAtPoint(pPage, (FX_FLOAT)x, (FX_FLOAT)y).GetDict(); | |
| 180 } | |
| 181 | |
| 182 DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK p
Dict) | |
| 183 { | |
| 184 if (!document) | |
| 185 return NULL; | |
| 186 if (!pDict) | |
| 187 return NULL; | |
| 188 CPDF_Document* pDoc = (CPDF_Document*)document; | |
| 189 CPDF_Link link((CPDF_Dictionary*)pDict); | |
| 190 FPDF_DEST dest = link.GetDest(pDoc).GetObject(); | |
| 191 if (dest) | |
| 192 return dest; | |
| 193 // If this link is not directly associated with a dest, we try to get action | |
| 194 CPDF_Action action = link.GetAction(); | |
| 195 if (!action) | |
| 196 return NULL; | |
| 197 return action.GetDest(pDoc).GetObject(); | |
| 198 } | |
| 199 | |
| 200 DLLEXPORT FPDF_ACTION STDCALL FPDFLink_GetAction(FPDF_LINK pDict) | |
| 201 { | |
| 202 if (!pDict) | |
| 203 return NULL; | |
| 204 CPDF_Link link((CPDF_Dictionary*)pDict); | |
| 205 return link.GetAction().GetDict(); | |
| 206 } | |
| 207 | |
| 208 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FP
DF_LINK* linkAnnot) | |
| 209 { | |
| 210 if(!page || !startPos || !linkAnnot) | |
| 211 return FALSE; | |
| 212 CPDF_Page* pPage = (CPDF_Page*)page; | |
| 213 if(!pPage->m_pFormDict) | |
| 214 return FALSE; | |
| 215 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots"); | |
| 216 if(!pAnnots) | |
| 217 return FALSE; | |
| 218 for (int i = *startPos; i < (int)pAnnots->GetCount(); i++) { | |
| 219 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pAnnots->GetElementValue(i); | |
| 220 if (!pDict || pDict->GetType() != PDFOBJ_DICTIONARY) | |
| 221 continue; | |
| 222 if(pDict->GetString(FX_BSTRC("Subtype")).Equal(FX_BSTRC("Link"))) { | |
| 223 *startPos = i + 1; | |
| 224 *linkAnnot = (FPDF_LINK)pDict; | |
| 225 return TRUE; | |
| 226 } | |
| 227 } | |
| 228 return FALSE; | |
| 229 } | |
| 230 | |
| 231 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot, FS_RECTF*
rect) | |
| 232 { | |
| 233 if(!linkAnnot || !rect) | |
| 234 return FALSE; | |
| 235 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; | |
| 236 CPDF_Rect rt = pAnnotDict->GetRect(FX_BSTRC("Rect")); | |
| 237 rect->left = rt.left; | |
| 238 rect->bottom = rt.bottom; | |
| 239 rect->right = rt.right; | |
| 240 rect->top = rt.top; | |
| 241 return TRUE; | 275 return TRUE; |
| 242 } | 276 } |
| 243 | 277 return FALSE; |
| 244 DLLEXPORT int STDCALL FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot) | 278 } |
| 245 { | 279 |
| 246 if(!linkAnnot) | 280 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, |
| 247 return 0; | 281 FPDF_BYTESTRING tag, |
| 248 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; | 282 void* buffer, |
| 249 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); | 283 unsigned long buflen) { |
| 250 if (!pArray) | 284 if (!doc || !tag) |
| 251 return 0; | 285 return 0; |
| 252 return pArray->GetCount() / 8; | 286 CPDF_Document* pDoc = (CPDF_Document*)doc; |
| 253 } | 287 // Get info dictionary |
| 254 | 288 CPDF_Dictionary* pInfo = pDoc->GetInfo(); |
| 255 DLLEXPORT FPDF_BOOL STDCALL FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot, int quad
Index, FS_QUADPOINTSF* quadPoints) | 289 if (!pInfo) |
| 256 { | 290 return 0; |
| 257 if(!linkAnnot || !quadPoints) | 291 CFX_WideString text = pInfo->GetUnicodeText(tag); |
| 258 return FALSE; | 292 // Use UTF-16LE encoding |
| 259 CPDF_Dictionary* pAnnotDict = (CPDF_Dictionary*)linkAnnot; | 293 CFX_ByteString encodedText = text.UTF16LE_Encode(); |
| 260 CPDF_Array* pArray = pAnnotDict->GetArray(FX_BSTRC("QuadPoints")); | 294 unsigned long len = encodedText.GetLength(); |
| 261 if (pArray) { | 295 if (buffer && buflen >= len) { |
| 262 if (quadIndex < 0 || quadIndex >= (int)pArray->GetCount()/8 || ((quadInd
ex*8+7) >= (int)pArray->GetCount())) | 296 FXSYS_memcpy(buffer, encodedText.c_str(), len); |
| 263 return FALSE; | 297 } |
| 264 quadPoints->x1 = pArray->GetNumber(quadIndex*8); | 298 return len; |
| 265 quadPoints->y1 = pArray->GetNumber(quadIndex*8+1); | 299 } |
| 266 quadPoints->x2 = pArray->GetNumber(quadIndex*8+2); | |
| 267 quadPoints->y2 = pArray->GetNumber(quadIndex*8+3); | |
| 268 quadPoints->x3 = pArray->GetNumber(quadIndex*8+4); | |
| 269 quadPoints->y3 = pArray->GetNumber(quadIndex*8+5); | |
| 270 quadPoints->x4 = pArray->GetNumber(quadIndex*8+6); | |
| 271 quadPoints->y4 = pArray->GetNumber(quadIndex*8+7); | |
| 272 return TRUE; | |
| 273 } | |
| 274 return FALSE; | |
| 275 } | |
| 276 | |
| 277 DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTR
ING tag, | |
| 278 void* buffer, unsigned long buf
len) | |
| 279 { | |
| 280 if (!doc || !tag) | |
| 281 return 0; | |
| 282 CPDF_Document* pDoc = (CPDF_Document*)doc; | |
| 283 // Get info dictionary | |
| 284 CPDF_Dictionary* pInfo = pDoc->GetInfo(); | |
| 285 if (!pInfo) | |
| 286 return 0; | |
| 287 CFX_WideString text = pInfo->GetUnicodeText(tag); | |
| 288 // Use UTF-16LE encoding | |
| 289 CFX_ByteString encodedText = text.UTF16LE_Encode(); | |
| 290 unsigned long len = encodedText.GetLength(); | |
| 291 if (buffer && buflen >= len) { | |
| 292 FXSYS_memcpy(buffer, encodedText.c_str(), len); | |
| 293 } | |
| 294 return len; | |
| 295 } | |
| OLD | NEW |