John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_text.h" |
| 8 | |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 9 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | 13ee55a | 2016-03-14 15:56:00 -0400 | [diff] [blame] | 10 | #include "core/fpdftext/include/ipdf_linkextract.h" |
| 11 | #include "core/fpdftext/include/ipdf_textpage.h" |
| 12 | #include "core/fpdftext/include/ipdf_textpagefind.h" |
Lei Zhang | a688a04 | 2015-11-09 13:57:49 -0800 | [diff] [blame] | 13 | #include "core/include/fpdfdoc/fpdf_doc.h" |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 14 | #include "fpdfsdk/include/fsdk_define.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 16 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 875b9c9 | 2016-01-08 13:51:10 -0800 | [diff] [blame] | 17 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
| 18 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 19 | #endif // PDF_ENABLE_XFA |
| 20 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | #ifdef _WIN32 |
| 22 | #include <tchar.h> |
| 23 | #endif |
| 24 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page) { |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 26 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
| 27 | if (!pPDFPage) |
| 28 | return nullptr; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 29 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 30 | CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | CPDFXFA_Document* pDoc = pPage->GetDocument(); |
| 32 | CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc()); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 33 | #else // PDF_ENABLE_XFA |
| 34 | CPDF_ViewerPreferences viewRef(pPDFPage->m_pDocument); |
| 35 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 36 | IPDF_TextPage* textpage = |
| 37 | IPDF_TextPage::CreateTextPage(pPDFPage, viewRef.IsDirectionR2L()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | textpage->ParseTextPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | return textpage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page) { |
| 42 | delete (IPDF_TextPage*)text_page; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page) { |
| 45 | if (!text_page) |
| 46 | return -1; |
| 47 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
| 48 | return textpage->CountChars(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | } |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, |
| 52 | int index) { |
| 53 | if (!text_page) |
Wei Li | d4e8f12 | 2016-03-21 11:20:44 -0700 | [diff] [blame] | 54 | return 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | if (index < 0 || index >= textpage->CountChars()) |
| 58 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | FPDF_CHAR_INFO charinfo; |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 61 | textpage->GetCharInfo(index, &charinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | return charinfo.m_Unicode; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | } |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, |
| 66 | int index) { |
| 67 | if (!text_page) |
| 68 | return 0; |
| 69 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | if (index < 0 || index >= textpage->CountChars()) |
| 72 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | FPDF_CHAR_INFO charinfo; |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 75 | textpage->GetCharInfo(index, &charinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | return charinfo.m_FontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, |
| 80 | int index, |
| 81 | double* left, |
| 82 | double* right, |
| 83 | double* bottom, |
| 84 | double* top) { |
| 85 | if (!text_page) |
| 86 | return; |
| 87 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | if (index < 0 || index >= textpage->CountChars()) |
| 90 | return; |
| 91 | FPDF_CHAR_INFO charinfo; |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 92 | textpage->GetCharInfo(index, &charinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | *left = charinfo.m_CharBox.left; |
| 94 | *right = charinfo.m_CharBox.right; |
| 95 | *bottom = charinfo.m_CharBox.bottom; |
| 96 | *top = charinfo.m_CharBox.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | // select |
| 100 | DLLEXPORT int STDCALL FPDFText_GetCharIndexAtPos(FPDF_TEXTPAGE text_page, |
| 101 | double x, |
| 102 | double y, |
Lei Zhang | 38a5a39 | 2015-08-13 17:52:16 -0700 | [diff] [blame] | 103 | double xTolerance, |
| 104 | double yTolerance) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | if (!text_page) |
| 106 | return -3; |
| 107 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
Lei Zhang | 38a5a39 | 2015-08-13 17:52:16 -0700 | [diff] [blame] | 108 | return textpage->GetIndexAtPos((FX_FLOAT)x, (FX_FLOAT)y, (FX_FLOAT)xTolerance, |
| 109 | (FX_FLOAT)yTolerance); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | DLLEXPORT int STDCALL FPDFText_GetText(FPDF_TEXTPAGE text_page, |
| 113 | int start, |
| 114 | int count, |
| 115 | unsigned short* result) { |
| 116 | if (!text_page) |
| 117 | return 0; |
| 118 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 119 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | if (start >= textpage->CountChars()) |
| 121 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | CFX_WideString str = textpage->GetPageText(start, count); |
| 124 | if (str.GetLength() > count) |
| 125 | str = str.Left(count); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | CFX_ByteString cbUTF16str = str.UTF16LE_Encode(); |
| 128 | FXSYS_memcpy(result, cbUTF16str.GetBuffer(cbUTF16str.GetLength()), |
| 129 | cbUTF16str.GetLength()); |
| 130 | cbUTF16str.ReleaseBuffer(cbUTF16str.GetLength()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 131 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | return cbUTF16str.GetLength() / sizeof(unsigned short); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | DLLEXPORT int STDCALL FPDFText_CountRects(FPDF_TEXTPAGE text_page, |
| 136 | int start, |
| 137 | int count) { |
| 138 | if (!text_page) |
| 139 | return 0; |
| 140 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
| 141 | return textpage->CountRects(start, count); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | DLLEXPORT void STDCALL FPDFText_GetRect(FPDF_TEXTPAGE text_page, |
| 144 | int rect_index, |
| 145 | double* left, |
| 146 | double* top, |
| 147 | double* right, |
| 148 | double* bottom) { |
| 149 | if (!text_page) |
| 150 | return; |
| 151 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
| 152 | CFX_FloatRect rect; |
| 153 | textpage->GetRect(rect_index, rect.left, rect.top, rect.right, rect.bottom); |
| 154 | *left = rect.left; |
| 155 | *top = rect.top; |
| 156 | *right = rect.right; |
| 157 | *bottom = rect.bottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page, |
| 161 | double left, |
| 162 | double top, |
| 163 | double right, |
| 164 | double bottom, |
| 165 | unsigned short* buffer, |
| 166 | int buflen) { |
| 167 | if (!text_page) |
| 168 | return 0; |
| 169 | IPDF_TextPage* textpage = (IPDF_TextPage*)text_page; |
| 170 | CFX_FloatRect rect((FX_FLOAT)left, (FX_FLOAT)bottom, (FX_FLOAT)right, |
| 171 | (FX_FLOAT)top); |
| 172 | CFX_WideString str = textpage->GetTextByRect(rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 173 | |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 174 | if (buflen <= 0 || !buffer) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | return str.GetLength(); |
| 176 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 177 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | CFX_ByteString cbUTF16Str = str.UTF16LE_Encode(); |
| 179 | int len = cbUTF16Str.GetLength() / sizeof(unsigned short); |
| 180 | int size = buflen > len ? len : buflen; |
| 181 | FXSYS_memcpy(buffer, cbUTF16Str.GetBuffer(size * sizeof(unsigned short)), |
| 182 | size * sizeof(unsigned short)); |
| 183 | cbUTF16Str.ReleaseBuffer(size * sizeof(unsigned short)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | return size; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | // Search |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 189 | // -1 for end |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 190 | DLLEXPORT FPDF_SCHHANDLE STDCALL FPDFText_FindStart(FPDF_TEXTPAGE text_page, |
| 191 | FPDF_WIDESTRING findwhat, |
| 192 | unsigned long flags, |
| 193 | int start_index) { |
| 194 | if (!text_page) |
| 195 | return NULL; |
| 196 | IPDF_TextPageFind* textpageFind = NULL; |
| 197 | textpageFind = IPDF_TextPageFind::CreatePageFind((IPDF_TextPage*)text_page); |
| 198 | FX_STRSIZE len = CFX_WideString::WStringLength(findwhat); |
| 199 | textpageFind->FindFirst(CFX_WideString::FromUTF16LE(findwhat, len), flags, |
| 200 | start_index); |
| 201 | return textpageFind; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindNext(FPDF_SCHHANDLE handle) { |
| 204 | if (!handle) |
| 205 | return FALSE; |
| 206 | IPDF_TextPageFind* textpageFind = (IPDF_TextPageFind*)handle; |
| 207 | return textpageFind->FindNext(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindPrev(FPDF_SCHHANDLE handle) { |
| 210 | if (!handle) |
| 211 | return FALSE; |
| 212 | IPDF_TextPageFind* textpageFind = (IPDF_TextPageFind*)handle; |
| 213 | return textpageFind->FindPrev(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 214 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | DLLEXPORT int STDCALL FPDFText_GetSchResultIndex(FPDF_SCHHANDLE handle) { |
| 216 | if (!handle) |
| 217 | return 0; |
| 218 | IPDF_TextPageFind* textpageFind = (IPDF_TextPageFind*)handle; |
| 219 | return textpageFind->GetCurOrder(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | DLLEXPORT int STDCALL FPDFText_GetSchCount(FPDF_SCHHANDLE handle) { |
| 222 | if (!handle) |
| 223 | return 0; |
| 224 | IPDF_TextPageFind* textpageFind = (IPDF_TextPageFind*)handle; |
| 225 | return textpageFind->GetMatchedCount(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 226 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | DLLEXPORT void STDCALL FPDFText_FindClose(FPDF_SCHHANDLE handle) { |
| 228 | if (!handle) |
| 229 | return; |
| 230 | IPDF_TextPageFind* textpageFind = (IPDF_TextPageFind*)handle; |
| 231 | delete textpageFind; |
| 232 | handle = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 235 | // web link |
| 236 | DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) { |
| 237 | if (!text_page) |
| 238 | return NULL; |
| 239 | IPDF_LinkExtract* pageLink = NULL; |
| 240 | pageLink = IPDF_LinkExtract::CreateLinkExtract(); |
| 241 | pageLink->ExtractLinks((IPDF_TextPage*)text_page); |
| 242 | return pageLink; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 243 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page) { |
| 245 | if (!link_page) |
| 246 | return 0; |
| 247 | IPDF_LinkExtract* pageLink = (IPDF_LinkExtract*)link_page; |
| 248 | return pageLink->CountLinks(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 249 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page, |
| 251 | int link_index, |
| 252 | unsigned short* buffer, |
| 253 | int buflen) { |
| 254 | if (!link_page) |
| 255 | return 0; |
| 256 | IPDF_LinkExtract* pageLink = (IPDF_LinkExtract*)link_page; |
| 257 | CFX_WideString url = pageLink->GetURL(link_index); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 258 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | CFX_ByteString cbUTF16URL = url.UTF16LE_Encode(); |
| 260 | int len = cbUTF16URL.GetLength() / sizeof(unsigned short); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 261 | if (!buffer || buflen <= 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | return len; |
| 263 | int size = len < buflen ? len : buflen; |
| 264 | if (size > 0) { |
| 265 | FXSYS_memcpy(buffer, cbUTF16URL.GetBuffer(size * sizeof(unsigned short)), |
| 266 | size * sizeof(unsigned short)); |
| 267 | cbUTF16URL.ReleaseBuffer(size * sizeof(unsigned short)); |
| 268 | } |
| 269 | return size; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 270 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, |
| 272 | int link_index) { |
| 273 | if (!link_page) |
| 274 | return 0; |
| 275 | IPDF_LinkExtract* pageLink = (IPDF_LinkExtract*)link_page; |
| 276 | CFX_RectArray rectArray; |
| 277 | pageLink->GetRects(link_index, rectArray); |
| 278 | return rectArray.GetSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, |
| 281 | int link_index, |
| 282 | int rect_index, |
| 283 | double* left, |
| 284 | double* top, |
| 285 | double* right, |
| 286 | double* bottom) { |
| 287 | if (!link_page) |
| 288 | return; |
| 289 | IPDF_LinkExtract* pageLink = (IPDF_LinkExtract*)link_page; |
| 290 | CFX_RectArray rectArray; |
| 291 | pageLink->GetRects(link_index, rectArray); |
| 292 | if (rect_index >= 0 && rect_index < rectArray.GetSize()) { |
| 293 | CFX_FloatRect rect = rectArray.GetAt(rect_index); |
| 294 | *left = rect.left; |
| 295 | *right = rect.right; |
| 296 | *top = rect.top; |
| 297 | *bottom = rect.bottom; |
| 298 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 299 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 300 | DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { |
| 301 | delete (IPDF_LinkExtract*)link_page; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 302 | } |