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

Side by Side Diff: fpdfsdk/fpdftext.cpp

Issue 1896303002: Remove CFX_ArrayTemplate from CPDF_LinkExtract (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Old API behaviour; funnel empty sring processing. Created 4 years, 8 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
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_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
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 CFX_WideString wsUrl(L"");
294 return 0; 296 if (link_page && link_index >= 0) {
297 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page);
298 wsUrl = pageLink->GetURL(link_index);
299 }
300 CFX_ByteString cbUTF16URL = wsUrl.UTF16LE_Encode();
301 int required = cbUTF16URL.GetLength() / sizeof(unsigned short);
302 if (!buffer || buflen <= 0)
303 return required;
295 304
296 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); 305 int size = std::min(required, buflen);
297 CFX_WideString url = pageLink->GetURL(link_index);
298
299 CFX_ByteString cbUTF16URL = url.UTF16LE_Encode();
300 int len = cbUTF16URL.GetLength() / sizeof(unsigned short);
301 if (!buffer || buflen <= 0)
302 return len;
303
304 int size = len < buflen ? len : buflen;
305 if (size > 0) { 306 if (size > 0) {
306 int buf_size = size * sizeof(unsigned short); 307 int buf_size = size * sizeof(unsigned short);
307 FXSYS_memcpy(buffer, cbUTF16URL.GetBuffer(buf_size), buf_size); 308 FXSYS_memcpy(buffer, cbUTF16URL.GetBuffer(buf_size), buf_size);
308 cbUTF16URL.ReleaseBuffer(buf_size);
309 } 309 }
310 return size; 310 return size;
311 } 311 }
312 312
313 DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, 313 DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page,
314 int link_index) { 314 int link_index) {
315 if (!link_page) 315 if (!link_page || link_index < 0)
316 return 0; 316 return 0;
317 317
318 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); 318 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page);
319 CFX_RectArray rectArray; 319 return pageLink->GetRects(link_index).GetSize();
320 pageLink->GetRects(link_index, rectArray);
321 return rectArray.GetSize();
322 } 320 }
323 321
324 DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, 322 DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page,
325 int link_index, 323 int link_index,
326 int rect_index, 324 int rect_index,
327 double* left, 325 double* left,
328 double* top, 326 double* top,
329 double* right, 327 double* right,
330 double* bottom) { 328 double* bottom) {
331 if (!link_page) 329 if (!link_page || link_index < 0 || rect_index < 0)
332 return; 330 return;
333 331
334 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); 332 CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page);
335 CFX_RectArray rectArray; 333 CFX_RectArray rectArray = pageLink->GetRects(link_index);
336 pageLink->GetRects(link_index, rectArray); 334 if (rect_index >= rectArray.GetSize())
337 if (rect_index >= 0 && rect_index < rectArray.GetSize()) { 335 return;
338 CFX_FloatRect rect = rectArray.GetAt(rect_index); 336
339 *left = rect.left; 337 CFX_FloatRect rect = rectArray.GetAt(rect_index);
340 *right = rect.right; 338 *left = rect.left;
341 *top = rect.top; 339 *right = rect.right;
342 *bottom = rect.bottom; 340 *top = rect.top;
343 } 341 *bottom = rect.bottom;
344 } 342 }
343
345 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { 344 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) {
346 delete CPDFLinkExtractFromFPDFPageLink(link_page); 345 delete CPDFLinkExtractFromFPDFPageLink(link_page);
347 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698