| 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_text.h" | 7 #include "public/fpdf_text.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 10 #include "core/fpdfdoc/include/fpdf_doc.h" | 10 #include "core/fpdfdoc/include/fpdf_doc.h" |
| 11 #include "core/fpdftext/include/cpdf_linkextract.h" | 11 #include "core/fpdftext/include/cpdf_linkextract.h" |
| 12 #include "core/fpdftext/include/cpdf_textpage.h" | 12 #include "core/fpdftext/include/cpdf_textpage.h" |
| 13 #include "core/fpdftext/include/cpdf_textpagefind.h" | 13 #include "core/fpdftext/include/cpdf_textpagefind.h" |
| 14 #include "fpdfsdk/include/fsdk_define.h" | 14 #include "fpdfsdk/include/fsdk_define.h" |
| 15 #include "third_party/base/numerics/safe_conversions.h" |
| 15 | 16 |
| 16 #ifdef PDF_ENABLE_XFA | 17 #ifdef PDF_ENABLE_XFA |
| 17 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" | 18 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| 18 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" | 19 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_page.h" |
| 19 #endif // PDF_ENABLE_XFA | 20 #endif // PDF_ENABLE_XFA |
| 20 | 21 |
| 21 #ifdef _WIN32 | 22 #ifdef _WIN32 |
| 22 #include <tchar.h> | 23 #include <tchar.h> |
| 23 #endif | 24 #endif |
| 24 | 25 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); | 267 CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); |
| 267 delete textpageFind; | 268 delete textpageFind; |
| 268 handle = nullptr; | 269 handle = nullptr; |
| 269 } | 270 } |
| 270 | 271 |
| 271 // web link | 272 // web link |
| 272 DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) { | 273 DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) { |
| 273 if (!text_page) | 274 if (!text_page) |
| 274 return nullptr; | 275 return nullptr; |
| 275 | 276 |
| 276 CPDF_LinkExtract* pageLink = new CPDF_LinkExtract; | 277 CPDF_LinkExtract* pageLink = |
| 277 pageLink->ExtractLinks(CPDFTextPageFromFPDFTextPage(text_page)); | 278 new CPDF_LinkExtract(CPDFTextPageFromFPDFTextPage(text_page)); |
| 279 pageLink->ExtractLinks(); |
| 278 return pageLink; | 280 return pageLink; |
| 279 } | 281 } |
| 280 | 282 |
| 281 DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page) { | 283 DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page) { |
| 282 if (!link_page) | 284 if (!link_page) |
| 283 return 0; | 285 return 0; |
| 284 | 286 |
| 285 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); | 287 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
| 286 return pageLink->CountLinks(); | 288 return pdfium::base::checked_cast<int>(pageLink->CountLinks()); |
| 287 } | 289 } |
| 288 | 290 |
| 289 DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page, | 291 DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page, |
| 290 int link_index, | 292 int link_index, |
| 291 unsigned short* buffer, | 293 unsigned short* buffer, |
| 292 int buflen) { | 294 int buflen) { |
| 293 if (!link_page) | 295 if (!link_page || link_index < 0) |
| 294 return 0; | 296 return 0; |
| 295 | 297 |
| 296 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); | 298 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
| 297 CFX_WideString url = pageLink->GetURL(link_index); | 299 CFX_WideString url; |
| 300 if (!pageLink->GetURL(link_index, &url)) |
| 301 return 0; |
| 298 | 302 |
| 299 CFX_ByteString cbUTF16URL = url.UTF16LE_Encode(); | 303 CFX_ByteString cbUTF16URL = url.UTF16LE_Encode(); |
| 300 int len = cbUTF16URL.GetLength() / sizeof(unsigned short); | 304 int len = cbUTF16URL.GetLength() / sizeof(unsigned short); |
| 301 if (!buffer || buflen <= 0) | 305 if (!buffer || buflen <= 0) |
| 302 return len; | 306 return len; |
| 303 | 307 |
| 304 int size = len < buflen ? len : buflen; | 308 int size = len < buflen ? len : buflen; |
| 305 if (size > 0) { | 309 if (size > 0) { |
| 306 int buf_size = size * sizeof(unsigned short); | 310 int buf_size = size * sizeof(unsigned short); |
| 307 FXSYS_memcpy(buffer, cbUTF16URL.GetBuffer(buf_size), buf_size); | 311 FXSYS_memcpy(buffer, cbUTF16URL.GetBuffer(buf_size), buf_size); |
| 308 cbUTF16URL.ReleaseBuffer(buf_size); | 312 cbUTF16URL.ReleaseBuffer(buf_size); |
| 309 } | 313 } |
| 310 return size; | 314 return size; |
| 311 } | 315 } |
| 312 | 316 |
| 313 DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, | 317 DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, |
| 314 int link_index) { | 318 int link_index) { |
| 315 if (!link_page) | 319 if (!link_page || link_index < 0) |
| 316 return 0; | 320 return 0; |
| 317 | 321 |
| 322 CFX_RectArray rects; |
| 318 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); | 323 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
| 319 CFX_RectArray rectArray; | 324 if (!pageLink->GetRects(link_index, &rects)) |
| 320 pageLink->GetRects(link_index, rectArray); | 325 return 0; |
| 321 return rectArray.GetSize(); | 326 |
| 327 return rects.GetSize(); |
| 322 } | 328 } |
| 323 | 329 |
| 324 DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, | 330 DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, |
| 325 int link_index, | 331 int link_index, |
| 326 int rect_index, | 332 int rect_index, |
| 327 double* left, | 333 double* left, |
| 328 double* top, | 334 double* top, |
| 329 double* right, | 335 double* right, |
| 330 double* bottom) { | 336 double* bottom) { |
| 331 if (!link_page) | 337 if (!link_page || link_index < 0 || rect_index < 0) |
| 332 return; | 338 return; |
| 333 | 339 |
| 334 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); | 340 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
| 335 CFX_RectArray rectArray; | 341 CFX_RectArray rectArray; |
| 336 pageLink->GetRects(link_index, rectArray); | 342 if (!pageLink->GetRects(link_index, &rectArray)) |
| 337 if (rect_index >= 0 && rect_index < rectArray.GetSize()) { | 343 return; |
| 338 CFX_FloatRect rect = rectArray.GetAt(rect_index); | 344 |
| 339 *left = rect.left; | 345 if (rect_index >= rectArray.GetSize()) |
| 340 *right = rect.right; | 346 return; |
| 341 *top = rect.top; | 347 |
| 342 *bottom = rect.bottom; | 348 CFX_FloatRect rect = rectArray.GetAt(rect_index); |
| 343 } | 349 *left = rect.left; |
| 350 *right = rect.right; |
| 351 *top = rect.top; |
| 352 *bottom = rect.bottom; |
| 344 } | 353 } |
| 354 |
| 345 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { | 355 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { |
| 346 delete CPDFLinkExtractFromFPDFPageLink(link_page); | 356 delete CPDFLinkExtractFromFPDFPageLink(link_page); |
| 347 } | 357 } |
| OLD | NEW |