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 | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <vector> |
| 11 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 13 | #include "core/fpdfdoc/cpdf_viewerpreferences.h" |
dsinclair | e030786 | 2016-09-29 13:25:38 -0700 | [diff] [blame] | 14 | #include "core/fpdftext/cpdf_linkextract.h" |
| 15 | #include "core/fpdftext/cpdf_textpage.h" |
| 16 | #include "core/fpdftext/cpdf_textpagefind.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/fsdk_define.h" |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 18 | #include "third_party/base/numerics/safe_conversions.h" |
tsepez | df964df | 2016-04-21 12:09:41 -0700 | [diff] [blame] | 19 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 21 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 22 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 23 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 24 | #endif // PDF_ENABLE_XFA |
| 25 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | #ifdef _WIN32 |
| 27 | #include <tchar.h> |
| 28 | #endif |
| 29 | |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 30 | namespace { |
| 31 | |
| 32 | CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE text_page) { |
| 33 | return static_cast<CPDF_TextPage*>(text_page); |
| 34 | } |
| 35 | |
| 36 | CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(FPDF_SCHHANDLE handle) { |
| 37 | return static_cast<CPDF_TextPageFind*>(handle); |
| 38 | } |
| 39 | |
| 40 | CPDF_LinkExtract* CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link) { |
| 41 | return static_cast<CPDF_LinkExtract*>(link); |
| 42 | } |
| 43 | |
| 44 | } // namespace |
| 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page) { |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 47 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
| 48 | if (!pPDFPage) |
| 49 | return nullptr; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 50 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 51 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 53 | CPDFXFA_Context* pContext = pPage->GetContext(); |
| 54 | CPDF_ViewerPreferences viewRef(pContext->GetPDFDoc()); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 55 | #else // PDF_ENABLE_XFA |
| 56 | CPDF_ViewerPreferences viewRef(pPDFPage->m_pDocument); |
| 57 | #endif // PDF_ENABLE_XFA |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 58 | |
dsinclair | 8f4bf9a | 2016-05-04 13:51:51 -0700 | [diff] [blame] | 59 | CPDF_TextPage* textpage = new CPDF_TextPage( |
| 60 | pPDFPage, viewRef.IsDirectionR2L() ? FPDFText_Direction::Right |
| 61 | : FPDFText_Direction::Left); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | textpage->ParseTextPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | return textpage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 65 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page) { |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 67 | delete CPDFTextPageFromFPDFTextPage(text_page); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page) { |
| 71 | if (!text_page) |
| 72 | return -1; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 73 | |
| 74 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | return textpage->CountChars(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 76 | } |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 77 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | DLLEXPORT unsigned int STDCALL FPDFText_GetUnicode(FPDF_TEXTPAGE text_page, |
| 79 | int index) { |
| 80 | if (!text_page) |
Wei Li | d4e8f12 | 2016-03-21 11:20:44 -0700 | [diff] [blame] | 81 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 83 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | if (index < 0 || index >= textpage->CountChars()) |
| 85 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | FPDF_CHAR_INFO charinfo; |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 88 | textpage->GetCharInfo(index, &charinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | return charinfo.m_Unicode; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | } |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | DLLEXPORT double STDCALL FPDFText_GetFontSize(FPDF_TEXTPAGE text_page, |
| 93 | int index) { |
| 94 | if (!text_page) |
| 95 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 96 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | if (index < 0 || index >= textpage->CountChars()) |
| 99 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | FPDF_CHAR_INFO charinfo; |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 102 | textpage->GetCharInfo(index, &charinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | return charinfo.m_FontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | DLLEXPORT void STDCALL FPDFText_GetCharBox(FPDF_TEXTPAGE text_page, |
| 107 | int index, |
| 108 | double* left, |
| 109 | double* right, |
| 110 | double* bottom, |
| 111 | double* top) { |
| 112 | if (!text_page) |
| 113 | return; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 114 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | if (index < 0 || index >= textpage->CountChars()) |
| 117 | return; |
| 118 | FPDF_CHAR_INFO charinfo; |
Lei Zhang | 0f2ea02 | 2016-01-11 12:01:23 -0800 | [diff] [blame] | 119 | textpage->GetCharInfo(index, &charinfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | *left = charinfo.m_CharBox.left; |
| 121 | *right = charinfo.m_CharBox.right; |
| 122 | *bottom = charinfo.m_CharBox.bottom; |
| 123 | *top = charinfo.m_CharBox.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 126 | // select |
| 127 | DLLEXPORT int STDCALL FPDFText_GetCharIndexAtPos(FPDF_TEXTPAGE text_page, |
| 128 | double x, |
| 129 | double y, |
Lei Zhang | 38a5a39 | 2015-08-13 17:52:16 -0700 | [diff] [blame] | 130 | double xTolerance, |
| 131 | double yTolerance) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | if (!text_page) |
| 133 | return -3; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 134 | |
| 135 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Dan Sinclair | d476adc | 2017-02-21 14:31:41 -0500 | [diff] [blame^] | 136 | return textpage->GetIndexAtPos( |
| 137 | CFX_PointF(static_cast<FX_FLOAT>(x), static_cast<FX_FLOAT>(y)), |
| 138 | CFX_SizeF(static_cast<FX_FLOAT>(xTolerance), |
| 139 | static_cast<FX_FLOAT>(yTolerance))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | DLLEXPORT int STDCALL FPDFText_GetText(FPDF_TEXTPAGE text_page, |
| 143 | int start, |
| 144 | int count, |
| 145 | unsigned short* result) { |
| 146 | if (!text_page) |
| 147 | return 0; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 148 | |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 149 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | if (start >= textpage->CountChars()) |
| 151 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 152 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | CFX_WideString str = textpage->GetPageText(start, count); |
| 154 | if (str.GetLength() > count) |
| 155 | str = str.Left(count); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | CFX_ByteString cbUTF16str = str.UTF16LE_Encode(); |
| 158 | FXSYS_memcpy(result, cbUTF16str.GetBuffer(cbUTF16str.GetLength()), |
| 159 | cbUTF16str.GetLength()); |
| 160 | cbUTF16str.ReleaseBuffer(cbUTF16str.GetLength()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | return cbUTF16str.GetLength() / sizeof(unsigned short); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | DLLEXPORT int STDCALL FPDFText_CountRects(FPDF_TEXTPAGE text_page, |
| 166 | int start, |
| 167 | int count) { |
| 168 | if (!text_page) |
| 169 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 170 | |
| 171 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | return textpage->CountRects(start, count); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 173 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 174 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | DLLEXPORT void STDCALL FPDFText_GetRect(FPDF_TEXTPAGE text_page, |
| 176 | int rect_index, |
| 177 | double* left, |
| 178 | double* top, |
| 179 | double* right, |
| 180 | double* bottom) { |
| 181 | if (!text_page) |
| 182 | return; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 183 | |
| 184 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | CFX_FloatRect rect; |
| 186 | textpage->GetRect(rect_index, rect.left, rect.top, rect.right, rect.bottom); |
| 187 | *left = rect.left; |
| 188 | *top = rect.top; |
| 189 | *right = rect.right; |
| 190 | *bottom = rect.bottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | DLLEXPORT int STDCALL FPDFText_GetBoundedText(FPDF_TEXTPAGE text_page, |
| 194 | double left, |
| 195 | double top, |
| 196 | double right, |
| 197 | double bottom, |
| 198 | unsigned short* buffer, |
| 199 | int buflen) { |
| 200 | if (!text_page) |
| 201 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 202 | |
| 203 | CPDF_TextPage* textpage = CPDFTextPageFromFPDFTextPage(text_page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | CFX_FloatRect rect((FX_FLOAT)left, (FX_FLOAT)bottom, (FX_FLOAT)right, |
| 205 | (FX_FLOAT)top); |
| 206 | CFX_WideString str = textpage->GetTextByRect(rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 207 | |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 208 | if (buflen <= 0 || !buffer) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | return str.GetLength(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | CFX_ByteString cbUTF16Str = str.UTF16LE_Encode(); |
| 212 | int len = cbUTF16Str.GetLength() / sizeof(unsigned short); |
| 213 | int size = buflen > len ? len : buflen; |
| 214 | FXSYS_memcpy(buffer, cbUTF16Str.GetBuffer(size * sizeof(unsigned short)), |
| 215 | size * sizeof(unsigned short)); |
| 216 | cbUTF16Str.ReleaseBuffer(size * sizeof(unsigned short)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 217 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | return size; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | // Search |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 222 | // -1 for end |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | DLLEXPORT FPDF_SCHHANDLE STDCALL FPDFText_FindStart(FPDF_TEXTPAGE text_page, |
| 224 | FPDF_WIDESTRING findwhat, |
| 225 | unsigned long flags, |
| 226 | int start_index) { |
| 227 | if (!text_page) |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 228 | return nullptr; |
| 229 | |
| 230 | CPDF_TextPageFind* textpageFind = |
| 231 | new CPDF_TextPageFind(CPDFTextPageFromFPDFTextPage(text_page)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | FX_STRSIZE len = CFX_WideString::WStringLength(findwhat); |
| 233 | textpageFind->FindFirst(CFX_WideString::FromUTF16LE(findwhat, len), flags, |
| 234 | start_index); |
| 235 | return textpageFind; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 237 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindNext(FPDF_SCHHANDLE handle) { |
| 239 | if (!handle) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 240 | return false; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 241 | |
| 242 | CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | return textpageFind->FindNext(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 244 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 245 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | DLLEXPORT FPDF_BOOL STDCALL FPDFText_FindPrev(FPDF_SCHHANDLE handle) { |
| 247 | if (!handle) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 248 | return false; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 249 | |
| 250 | CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | return textpageFind->FindPrev(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | DLLEXPORT int STDCALL FPDFText_GetSchResultIndex(FPDF_SCHHANDLE handle) { |
| 255 | if (!handle) |
| 256 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 257 | |
| 258 | CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | return textpageFind->GetCurOrder(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | DLLEXPORT int STDCALL FPDFText_GetSchCount(FPDF_SCHHANDLE handle) { |
| 263 | if (!handle) |
| 264 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 265 | |
| 266 | CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | return textpageFind->GetMatchedCount(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 268 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 269 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | DLLEXPORT void STDCALL FPDFText_FindClose(FPDF_SCHHANDLE handle) { |
| 271 | if (!handle) |
| 272 | return; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 273 | |
| 274 | CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | delete textpageFind; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 276 | handle = nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | // web link |
| 280 | DLLEXPORT FPDF_PAGELINK STDCALL FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) { |
| 281 | if (!text_page) |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 282 | return nullptr; |
| 283 | |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 284 | CPDF_LinkExtract* pageLink = |
| 285 | new CPDF_LinkExtract(CPDFTextPageFromFPDFTextPage(text_page)); |
| 286 | pageLink->ExtractLinks(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | return pageLink; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 289 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | DLLEXPORT int STDCALL FPDFLink_CountWebLinks(FPDF_PAGELINK link_page) { |
| 291 | if (!link_page) |
| 292 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 293 | |
| 294 | CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 295 | return pdfium::base::checked_cast<int>(pageLink->CountLinks()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 296 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 297 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | DLLEXPORT int STDCALL FPDFLink_GetURL(FPDF_PAGELINK link_page, |
| 299 | int link_index, |
| 300 | unsigned short* buffer, |
| 301 | int buflen) { |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 302 | CFX_WideString wsUrl(L""); |
| 303 | if (link_page && link_index >= 0) { |
| 304 | CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
| 305 | wsUrl = pageLink->GetURL(link_index); |
| 306 | } |
| 307 | CFX_ByteString cbUTF16URL = wsUrl.UTF16LE_Encode(); |
| 308 | int required = cbUTF16URL.GetLength() / sizeof(unsigned short); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 309 | if (!buffer || buflen <= 0) |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 310 | return required; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 311 | |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 312 | int size = std::min(required, buflen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | if (size > 0) { |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 314 | int buf_size = size * sizeof(unsigned short); |
| 315 | FXSYS_memcpy(buffer, cbUTF16URL.GetBuffer(buf_size), buf_size); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | } |
| 317 | return size; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 318 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 319 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | DLLEXPORT int STDCALL FPDFLink_CountRects(FPDF_PAGELINK link_page, |
| 321 | int link_index) { |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 322 | if (!link_page || link_index < 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | return 0; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 324 | |
| 325 | CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
tsepez | df964df | 2016-04-21 12:09:41 -0700 | [diff] [blame] | 326 | return pdfium::CollectionSize<int>(pageLink->GetRects(link_index)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 327 | } |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 328 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 329 | DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page, |
| 330 | int link_index, |
| 331 | int rect_index, |
| 332 | double* left, |
| 333 | double* top, |
| 334 | double* right, |
| 335 | double* bottom) { |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 336 | if (!link_page || link_index < 0 || rect_index < 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | return; |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 338 | |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 339 | CPDF_LinkExtract* pageLink = CPDFLinkExtractFromFPDFPageLink(link_page); |
tsepez | df964df | 2016-04-21 12:09:41 -0700 | [diff] [blame] | 340 | std::vector<CFX_FloatRect> rectArray = pageLink->GetRects(link_index); |
| 341 | if (rect_index >= pdfium::CollectionSize<int>(rectArray)) |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 342 | return; |
| 343 | |
tsepez | df964df | 2016-04-21 12:09:41 -0700 | [diff] [blame] | 344 | *left = rectArray[rect_index].left; |
| 345 | *right = rectArray[rect_index].right; |
| 346 | *top = rectArray[rect_index].top; |
| 347 | *bottom = rectArray[rect_index].bottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 348 | } |
tsepez | 6914118 | 2016-04-21 10:43:39 -0700 | [diff] [blame] | 349 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page) { |
dsinclair | a28ae38 | 2016-04-19 10:39:24 -0700 | [diff] [blame] | 351 | delete CPDFLinkExtractFromFPDFPageLink(link_page); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 352 | } |