summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdftext.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-11-30 21:02:41 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-30 21:02:41 +0000
commit8b357e7504ea804293983453540ae91c9fc57922 (patch)
tree7b8f611eac73034f9149b014fb547d6886e0d5b7 /fpdfsdk/fpdftext.cpp
parent0ae8e03cc2d310ba0ba19b878ea448f17a577cdb (diff)
downloadpdfium-8b357e7504ea804293983453540ae91c9fc57922.tar.xz
Rewrite lower level details of extracting text from page
The current implementation of text extraction was difficult to understand, duplicated logic that existed in other methods, and wasn't clear about the units the inputs were in. It also didn't handle control characters correctly. The new implementation leans on the methods for converting indices between the text buffer index and character list index spaces to avoid duplication of code. It also makes it clear to the reader that inputs are in the character list index space. Finally, it fixes issues being seen in Chrome with respect of ranges being slightly off. This CL also adds a test for extracting text that has control characters. BUG=pdfium:942,chromium:654578 Change-Id: Id9d1f360c2d7492c7b5a48d6c9ae29f530892742 Reviewed-on: https://pdfium-review.googlesource.com/20014 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdftext.cpp')
-rw-r--r--fpdfsdk/fpdftext.cpp21
1 files changed, 3 insertions, 18 deletions
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 5a2deb9a81..d9f7d572e9 100644
--- a/fpdfsdk/fpdftext.cpp
+++ b/fpdfsdk/fpdftext.cpp
@@ -179,25 +179,10 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetText(FPDF_TEXTPAGE page,
return 1;
}
- // char_* values are for a data structure that includes non-printing unicode
- // characters, where the text_* values are from a data structure that doesn't
- // include these characters, so translation is needed.
- int text_start = textpage->TextIndexFromCharIndex(char_start);
- if (text_start == -1)
- return 0;
-
- int char_last = char_start + char_count - 1;
- int text_last = textpage->TextIndexFromCharIndex(char_last);
- if (text_last == -1)
- return 0;
-
- int text_count = text_last - text_start + 1;
- if (text_count < 1)
- return 0;
+ WideString str = textpage->GetPageText(char_start, char_count);
- WideString str = textpage->GetPageText(text_start, text_count);
- if (str.GetLength() > static_cast<size_t>(text_count))
- str = str.Left(static_cast<size_t>(text_count));
+ if (str.GetLength() > static_cast<size_t>(char_count))
+ str = str.Left(static_cast<size_t>(char_count));
// UFT16LE_Encode doesn't handle surrogate pairs properly, so it is expected
// the number of items to stay the same.