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