Split TextObject rect for each kPiece
When an /ActualText is used on an object, the object is represented as
text by a sequence of CharInfo marked as kPiece. Prior to this change
each CharInfo was assigned the full rectangle of the original object.
This change splits the the original object's rectangle between the
kPiece CharInfos. This allows for each CharInfo to be independently
selectable instead of all of them overlapping.
Bug: pdfium:2069
Change-Id: Iea08d4b28fa9489f159b6e0c0cc0c2d2554db19b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/111150
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 99f3365..4966a7e 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -887,7 +887,18 @@
return;
RetainPtr<CPDF_Font> pFont = pTextObj->GetFont();
+ const bool bR2L = IsRightToLeft(*pTextObj, *pFont);
CFX_Matrix matrix = pTextObj->GetTextMatrix() * obj.m_formMatrix;
+ CFX_FloatRect rect = pTextObj->GetRect();
+ float step = 0;
+
+ if (bR2L) {
+ rect.left = rect.right - (rect.Width() / actText.GetLength());
+ step = -rect.Width();
+ } else {
+ rect.right = rect.left + (rect.Width() / actText.GetLength());
+ step = rect.Width();
+ }
for (size_t k = 0; k < actText.GetLength(); ++k) {
wchar_t wChar = actText[k];
@@ -903,7 +914,8 @@
charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar);
charinfo.m_CharType = CPDF_TextPage::CharType::kPiece;
charinfo.m_pTextObj = pTextObj;
- charinfo.m_CharBox = pTextObj->GetRect();
+ charinfo.m_CharBox = CFX_FloatRect(rect);
+ charinfo.m_CharBox.Translate(k * step, 0);
charinfo.m_Matrix = matrix;
m_TempTextBuf.AppendChar(wChar);
m_TempCharList.push_back(charinfo);