From da83d3a5cc09c4056310b3cf299dbbccd5c70d11 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 13 Feb 2017 15:30:30 -0500 Subject: Convert Origins to points MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL converts various OriginX, OriginY pairs into CFX_PointF objects. Change-Id: I9141f7fc713c710b2014d4fdcdec7dc93501f844 Reviewed-on: https://pdfium-review.googlesource.com/2575 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- core/fpdftext/cpdf_textpage.cpp | 242 +++++++++++++++++++--------------------- core/fpdftext/cpdf_textpage.h | 19 +++- 2 files changed, 128 insertions(+), 133 deletions(-) (limited to 'core/fpdftext') diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 55551dcfa0..bd068a596b 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -55,7 +55,7 @@ FX_FLOAT CalculateBaseSpace(const CPDF_TextObject* pTextObj, pTextObj->GetItemInfo(i, &item); if (item.m_CharCode == static_cast(-1)) { FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); - FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; + FX_FLOAT kerning = -fontsize_h * item.m_Origin.x / 1000; baseSpace = std::min(baseSpace, kerning + spacing); bAllChar = false; } @@ -108,6 +108,22 @@ float MaskPercentFilled(const std::vector& mask, } // namespace +FPDF_CHAR_INFO::FPDF_CHAR_INFO() + : m_Unicode(0), + m_Charcode(0), + m_Flag(0), + m_FontSize(0), + m_pTextObj(nullptr) {} + +FPDF_CHAR_INFO::~FPDF_CHAR_INFO() {} + +PAGECHAR_INFO::PAGECHAR_INFO() + : m_CharCode(0), m_Unicode(0), m_Flag(0), m_pTextObj(nullptr), m_Index(0) {} + +PAGECHAR_INFO::PAGECHAR_INFO(const PAGECHAR_INFO&) = default; + +PAGECHAR_INFO::~PAGECHAR_INFO() {} + CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, FPDFText_Direction flags) : m_pPage(pPage), m_parserflag(flags), @@ -239,30 +255,30 @@ std::vector CPDF_TextPage::GetRectArray(int start, bFlagNewRect = true; } if (bFlagNewRect) { - FX_FLOAT orgX = info_curchar.m_OriginX, orgY = info_curchar.m_OriginY; CFX_Matrix matrix = info_curchar.m_pTextObj->GetTextMatrix(); matrix.Concat(info_curchar.m_Matrix); CFX_Matrix matrix_reverse; matrix_reverse.SetReverse(matrix); - matrix_reverse.TransformPoint(orgX, orgY); + CFX_PointF origin = matrix_reverse.Transform(info_curchar.m_Origin); + rect.left = info_curchar.m_CharBox.left; rect.right = info_curchar.m_CharBox.right; if (pCurObj->GetFont()->GetTypeDescent()) { - rect.bottom = orgY + + rect.bottom = origin.y + pCurObj->GetFont()->GetTypeDescent() * pCurObj->GetFontSize() / 1000; - FX_FLOAT xPosTemp = orgX; + FX_FLOAT xPosTemp = origin.x; matrix.TransformPoint(xPosTemp, rect.bottom); } else { rect.bottom = info_curchar.m_CharBox.bottom; } if (pCurObj->GetFont()->GetTypeAscent()) { rect.top = - orgY + + origin.y + pCurObj->GetFont()->GetTypeAscent() * pCurObj->GetFontSize() / 1000; FX_FLOAT xPosTemp = - orgX + + origin.x + GetCharWidth(info_curchar.m_CharCode, pCurObj->GetFont()) * pCurObj->GetFontSize() / 1000; matrix.TransformPoint(xPosTemp, rect.top); @@ -297,7 +313,7 @@ int CPDF_TextPage::GetIndexAtPos(CFX_FloatPoint point, while (pos < pdfium::CollectionSize(m_CharList)) { PAGECHAR_INFO charinfo = m_CharList[pos]; CFX_FloatRect charrect = charinfo.m_CharBox; - if (charrect.Contains(point.x, point.y)) + if (charrect.Contains(point)) break; if (xTolerance > 0 || yTolerance > 0) { CFX_FloatRect charRectExt; @@ -306,7 +322,7 @@ int CPDF_TextPage::GetIndexAtPos(CFX_FloatPoint point, charRectExt.right = charrect.right + xTolerance / 2; charRectExt.top = charrect.top + yTolerance / 2; charRectExt.bottom = charrect.bottom - yTolerance / 2; - if (charRectExt.Contains(point.x, point.y)) { + if (charRectExt.Contains(point)) { double curXdif, curYdif; curXdif = FXSYS_fabs(point.x - charrect.left) < FXSYS_fabs(point.x - charrect.right) @@ -338,9 +354,9 @@ CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const { CFX_WideString strText; for (const auto& charinfo : m_CharList) { if (IsRectIntersect(rect, charinfo.m_CharBox)) { - if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar && + if (FXSYS_fabs(posy - charinfo.m_Origin.y) > 0 && !IsContainPreChar && IsAddLineFeed) { - posy = charinfo.m_OriginY; + posy = charinfo.m_Origin.y; if (!strText.IsEmpty()) strText += L"\r\n"; } @@ -379,8 +395,7 @@ void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const { const PAGECHAR_INFO& charinfo = m_CharList[index]; info->m_Charcode = charinfo.m_CharCode; - info->m_OriginX = charinfo.m_OriginX; - info->m_OriginY = charinfo.m_OriginY; + info->m_Origin = charinfo.m_Origin; info->m_Unicode = charinfo.m_Unicode; info->m_Flag = charinfo.m_Flag; info->m_CharBox = charinfo.m_CharBox; @@ -738,10 +753,9 @@ void CPDF_TextPage::ProcessTextObject( const CFX_Matrix& formMatrix, const CPDF_PageObjectList* pObjList, CPDF_PageObjectList::const_iterator ObjPos) { - CFX_FloatRect re(pTextObj->m_Left, pTextObj->m_Bottom, pTextObj->m_Right, - pTextObj->m_Top); if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) return; + size_t count = m_LineObj.size(); PDFTEXT_Obj Obj; Obj.m_pTextObj = pTextObj; @@ -752,6 +766,7 @@ void CPDF_TextPage::ProcessTextObject( } if (IsSameAsPreTextObject(pTextObj, pObjList, ObjPos)) return; + PDFTEXT_Obj prev_Obj = m_LineObj[count - 1]; CPDF_TextObjectItem item; int nItem = prev_Obj.m_pTextObj->CountItems(); @@ -776,28 +791,28 @@ void CPDF_TextPage::ProcessTextObject( FX_FLOAT threshold = prev_width > this_width ? prev_width / 4 : this_width / 4; - FX_FLOAT prev_x = prev_Obj.m_pTextObj->GetPosX(), - prev_y = prev_Obj.m_pTextObj->GetPosY(); - prev_Obj.m_formMatrix.TransformPoint(prev_x, prev_y); - m_DisplayMatrix.TransformPoint(prev_x, prev_y); - FX_FLOAT this_x = pTextObj->GetPosX(), this_y = pTextObj->GetPosY(); - formMatrix.TransformPoint(this_x, this_y); - m_DisplayMatrix.TransformPoint(this_x, this_y); - if (FXSYS_fabs(this_y - prev_y) > threshold * 2) { + CFX_PointF prev = prev_Obj.m_pTextObj->GetPos(); + prev_Obj.m_formMatrix.Transform(prev); + m_DisplayMatrix.Transform(prev); + + CFX_PointF this_pos = pTextObj->GetPos(); + formMatrix.Transform(this_pos); + m_DisplayMatrix.Transform(this_pos); + if (FXSYS_fabs(this_pos.y - prev.y) > threshold * 2) { for (size_t i = 0; i < count; i++) ProcessTextObject(m_LineObj[i]); m_LineObj.clear(); m_LineObj.push_back(Obj); return; } + size_t i; for (i = count; i > 0; --i) { PDFTEXT_Obj prev_text_obj = m_LineObj[i - 1]; - FX_FLOAT Prev_x = prev_text_obj.m_pTextObj->GetPosX(), - Prev_y = prev_text_obj.m_pTextObj->GetPosY(); - prev_text_obj.m_formMatrix.TransformPoint(Prev_x, Prev_y); - m_DisplayMatrix.TransformPoint(Prev_x, Prev_y); - if (this_x >= Prev_x) { + CFX_PointF new_prev = prev_text_obj.m_pTextObj->GetPos(); + prev_text_obj.m_formMatrix.Transform(new_prev); + m_DisplayMatrix.Transform(new_prev); + if (this_pos.x >= new_prev.x) { m_LineObj.insert(m_LineObj.begin() + i, Obj); break; } @@ -893,14 +908,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { CFX_Matrix matrix = pTextObj->GetTextMatrix(); matrix.Concat(Obj.m_formMatrix); - FX_FLOAT fPosX = pTextObj->GetPosX(); - FX_FLOAT fPosY = pTextObj->GetPosY(); int nCharInfoIndex = m_TextBuf.GetLength(); - CFX_FloatRect charBox; - charBox.top = pTextObj->m_Top; - charBox.left = pTextObj->m_Left; - charBox.right = pTextObj->m_Right; - charBox.bottom = pTextObj->m_Bottom; for (FX_STRSIZE k = 0; k < nItems; k++) { FX_WCHAR wChar = actText.GetAt(k); if (wChar <= 0x80 && !isprint(wChar)) @@ -909,17 +917,13 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { continue; PAGECHAR_INFO charinfo; - charinfo.m_OriginX = fPosX; - charinfo.m_OriginY = fPosY; + charinfo.m_Origin = pTextObj->GetPos(); charinfo.m_Index = nCharInfoIndex; charinfo.m_Unicode = wChar; charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar); charinfo.m_Flag = FPDFTEXT_CHAR_PIECE; charinfo.m_pTextObj = pTextObj; - charinfo.m_CharBox.top = charBox.top; - charinfo.m_CharBox.left = charBox.left; - charinfo.m_CharBox.right = charBox.right; - charinfo.m_CharBox.bottom = charBox.bottom; + charinfo.m_CharBox = pTextObj->GetRect(); charinfo.m_Matrix = matrix; m_TempTextBuf.AppendChar(wChar); m_TempCharList.push_back(charinfo); @@ -989,15 +993,11 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { GenerateCharacter result = GenerateCharacter::None; if (m_pPreTextObj) { result = ProcessInsertObject(pTextObj, formMatrix); - if (result == GenerateCharacter::LineBreak) { - m_CurlineRect = - CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, - Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); - } else { - m_CurlineRect.Union( - CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, - Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top)); - } + if (result == GenerateCharacter::LineBreak) + m_CurlineRect = Obj.m_pTextObj->GetRect(); + else + m_CurlineRect.Union(Obj.m_pTextObj->GetRect()); + switch (result) { case GenerateCharacter::None: break; @@ -1044,10 +1044,9 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { break; } } else { - m_CurlineRect = - CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, - Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); + m_CurlineRect = Obj.m_pTextObj->GetRect(); } + if (ePreMKC == FPDFText_MarkedContent::Delay) { ProcessMarkedContent(Obj); m_pPreTextObj = pTextObj; @@ -1070,8 +1069,6 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { for (int i = 0; i < nItems; i++) { CPDF_TextObjectItem item; PAGECHAR_INFO charinfo; - charinfo.m_OriginX = 0; - charinfo.m_OriginY = 0; pTextObj->GetItemInfo(i, &item); if (item.m_CharCode == static_cast(-1)) { CFX_WideString str = m_TempTextBuf.MakeString(); @@ -1081,7 +1078,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { continue; FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); - spacing = -fontsize_h * item.m_OriginX / 1000; + spacing = -fontsize_h * item.m_Origin.x / 1000; continue; } FX_FLOAT charSpace = pTextObj->m_TextState.GetCharSpace(); @@ -1118,12 +1115,10 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { charinfo.m_CharCode = CPDF_Font::kInvalidCharCode; charinfo.m_Matrix = formMatrix; - charinfo.m_OriginX = item.m_OriginX; - charinfo.m_OriginY = item.m_OriginY; - matrix.TransformPoint(charinfo.m_OriginX, charinfo.m_OriginY); + charinfo.m_Origin = matrix.Transform(item.m_Origin); charinfo.m_CharBox = - CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, - charinfo.m_OriginX, charinfo.m_OriginY); + CFX_FloatRect(charinfo.m_Origin.x, charinfo.m_Origin.y, + charinfo.m_Origin.x, charinfo.m_Origin.y); m_TempCharList.push_back(charinfo); } if (item.m_CharCode == CPDF_Font::kInvalidCharCode) @@ -1144,20 +1139,18 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { charinfo.m_Flag = FPDFTEXT_CHAR_NORMAL; charinfo.m_pTextObj = pTextObj; - charinfo.m_OriginX = item.m_OriginX; - charinfo.m_OriginY = item.m_OriginY; - matrix.TransformPoint(charinfo.m_OriginX, charinfo.m_OriginY); + charinfo.m_Origin = matrix.Transform(item.m_Origin); FX_RECT rect = charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode); charinfo.m_CharBox.top = - rect.top * pTextObj->GetFontSize() / 1000 + item.m_OriginY; + rect.top * pTextObj->GetFontSize() / 1000 + item.m_Origin.y; charinfo.m_CharBox.left = - rect.left * pTextObj->GetFontSize() / 1000 + item.m_OriginX; + rect.left * pTextObj->GetFontSize() / 1000 + item.m_Origin.x; charinfo.m_CharBox.right = - rect.right * pTextObj->GetFontSize() / 1000 + item.m_OriginX; + rect.right * pTextObj->GetFontSize() / 1000 + item.m_Origin.x; charinfo.m_CharBox.bottom = - rect.bottom * pTextObj->GetFontSize() / 1000 + item.m_OriginY; + rect.bottom * pTextObj->GetFontSize() / 1000 + item.m_Origin.y; if (fabsf(charinfo.m_CharBox.top - charinfo.m_CharBox.bottom) < 0.01f) { charinfo.m_CharBox.top = charinfo.m_CharBox.bottom + pTextObj->GetFontSize(); @@ -1185,8 +1178,10 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { const PAGECHAR_INFO& charinfo1 = m_TempCharList[n - 1]; if (charinfo1.m_CharCode == charinfo.m_CharCode && charinfo1.m_pTextObj->GetFont() == charinfo.m_pTextObj->GetFont() && - FXSYS_fabs(charinfo1.m_OriginX - charinfo.m_OriginX) < threshold && - FXSYS_fabs(charinfo1.m_OriginY - charinfo.m_OriginY) < threshold) { + FXSYS_fabs(charinfo1.m_Origin.x - charinfo.m_Origin.x) < + threshold && + FXSYS_fabs(charinfo1.m_Origin.y - charinfo.m_Origin.y) < + threshold) { bDel = true; break; } @@ -1227,10 +1222,11 @@ CPDF_TextPage::TextOrientation CPDF_TextPage::GetTextObjectWritingMode( pTextObj->GetCharInfo(nChars - 1, &last); CFX_Matrix textMatrix = pTextObj->GetTextMatrix(); - textMatrix.TransformPoint(first.m_OriginX, first.m_OriginY); - textMatrix.TransformPoint(last.m_OriginX, last.m_OriginY); - FX_FLOAT dX = FXSYS_fabs(last.m_OriginX - first.m_OriginX); - FX_FLOAT dY = FXSYS_fabs(last.m_OriginY - first.m_OriginY); + first.m_Origin = textMatrix.Transform(first.m_Origin); + last.m_Origin = textMatrix.Transform(last.m_Origin); + + FX_FLOAT dX = FXSYS_fabs(last.m_Origin.x - first.m_Origin.x); + FX_FLOAT dY = FXSYS_fabs(last.m_Origin.y - first.m_Origin.y); if (dX <= 0.0001f && dY <= 0.0001f) return TextOrientation::Unknown; @@ -1287,10 +1283,8 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( if (WritingMode == TextOrientation::Unknown) WritingMode = GetTextObjectWritingMode(m_pPreTextObj); - CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, - pObj->m_Top); - CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, - m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); + CFX_FloatRect this_rect = pObj->GetRect(); + CFX_FloatRect prev_rect = m_pPreTextObj->GetRect(); CPDF_TextObjectItem PrevItem, item; int nItem = m_pPreTextObj->CountItems(); m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); @@ -1325,7 +1319,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( } } } - FX_FLOAT last_pos = PrevItem.m_OriginX; + FX_FLOAT last_pos = PrevItem.m_Origin.x; int nLastWidth = GetCharWidth(PrevItem.m_CharCode, m_pPreTextObj->GetFont()); FX_FLOAT last_width = nLastWidth * m_pPreTextObj->GetFontSize() / 1000; last_width = FXSYS_fabs(last_width); @@ -1340,42 +1334,39 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( CFX_Matrix prev_reverse; prev_reverse.SetReverse(prev_matrix); - FX_FLOAT x = pObj->GetPosX(); - FX_FLOAT y = pObj->GetPosY(); - formMatrix.TransformPoint(x, y); - prev_reverse.TransformPoint(x, y); + + CFX_PointF pos = pObj->GetPos(); + formMatrix.Transform(pos); + prev_reverse.Transform(pos); if (last_width < this_width) threshold = prev_reverse.TransformDistance(threshold); bool bNewline = false; if (WritingMode == TextOrientation::Horizontal) { - CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom, - m_pPreTextObj->m_Right, pObj->m_Top); - CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, - m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); + CFX_FloatRect rect1 = m_pPreTextObj->GetRect(); + CFX_FloatRect rect2 = m_pPreTextObj->GetRect(); CFX_FloatRect rect3 = rect1; rect1.Intersect(rect2); if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) || - ((y > threshold * 2 || y < threshold * -3) && - (FXSYS_fabs(y) < 1 ? FXSYS_fabs(x) < FXSYS_fabs(y) : true))) { + ((pos.y > threshold * 2 || pos.y < threshold * -3) && + (FXSYS_fabs(pos.y) < 1 ? FXSYS_fabs(pos.x) < FXSYS_fabs(pos.y) + : true))) { bNewline = true; if (nItem > 1) { CPDF_TextObjectItem tempItem; m_pPreTextObj->GetItemInfo(0, &tempItem); CFX_Matrix m = m_pPreTextObj->GetTextMatrix(); - if (PrevItem.m_OriginX > tempItem.m_OriginX && + if (PrevItem.m_Origin.x > tempItem.m_Origin.x && m_DisplayMatrix.a > 0.9 && m_DisplayMatrix.b < 0.1 && m_DisplayMatrix.c < 0.1 && m_DisplayMatrix.d < -0.9 && m.b < 0.1 && m.c < 0.1) { CFX_FloatRect re(0, m_pPreTextObj->m_Bottom, 1000, m_pPreTextObj->m_Top); - if (re.Contains(pObj->GetPosX(), pObj->GetPosY())) { + if (re.Contains(pObj->GetPos())) { bNewline = false; } else { CFX_FloatRect rect(0, pObj->m_Bottom, 1000, pObj->m_Top); - if (rect.Contains(m_pPreTextObj->GetPosX(), - m_pPreTextObj->GetPosY())) { + if (rect.Contains(m_pPreTextObj->GetPos())) bNewline = false; - } } } } @@ -1415,19 +1406,17 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( (threshold < 1.39001 && threshold > 1.38999)) { threshold *= 1.5; } - if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && - preChar != L' ') { - if (curChar != L' ' && preChar != L' ') { - if ((x - last_pos - last_width) > threshold || - (last_pos - x - last_width) > threshold) { - return GenerateCharacter::Space; - } - if (x < 0 && (last_pos - x - last_width) > threshold) - return GenerateCharacter::Space; - if ((x - last_pos - last_width) > this_width || - (x - last_pos - this_width) > last_width) { - return GenerateCharacter::Space; - } + if (FXSYS_fabs(last_pos + last_width - pos.x) > threshold && + curChar != L' ' && preChar != L' ') { + if ((pos.x - last_pos - last_width) > threshold || + (last_pos - pos.x - last_width) > threshold) { + return GenerateCharacter::Space; + } + if (pos.x < 0 && (last_pos - pos.x - last_width) > threshold) + return GenerateCharacter::Space; + if ((pos.x - last_pos - last_width) > this_width || + (pos.x - last_pos - this_width) > last_width) { + return GenerateCharacter::Space; } } return GenerateCharacter::None; @@ -1437,10 +1426,8 @@ bool CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject* pTextObj2) { if (!pTextObj1 || !pTextObj2) return false; - CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, - pTextObj2->m_Right, pTextObj2->m_Top); - CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, - pTextObj1->m_Right, pTextObj1->m_Top); + CFX_FloatRect rcPreObj = pTextObj2->GetRect(); + CFX_FloatRect rcCurObj = pTextObj1->GetRect(); if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) { FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left); size_t nCount = m_CharList.size(); @@ -1470,24 +1457,25 @@ bool CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, if (!nPreCount) return true; - CPDF_TextObjectItem itemPer = {0, 0.0f, 0.0f}; - CPDF_TextObjectItem itemCur = {0, 0.0f, 0.0f}; + CPDF_TextObjectItem itemPer; + CPDF_TextObjectItem itemCur; for (int i = 0; i < nPreCount; i++) { pTextObj2->GetItemInfo(i, &itemPer); pTextObj1->GetItemInfo(i, &itemCur); if (itemCur.m_CharCode != itemPer.m_CharCode) return false; } - if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) > - GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) * - pTextObj2->GetFontSize() / 1000 * 0.9 || - FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > - std::max(std::max(rcPreObj.Height(), rcPreObj.Width()), - pTextObj2->GetFontSize()) / - 8) { - return false; - } - return true; + + CFX_PointF pos1 = pTextObj1->GetPos(); + CFX_PointF pos2 = pTextObj2->GetPos(); + + return FXSYS_fabs(pos1.x - pos2.x) <= + GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) * + pTextObj2->GetFontSize() / 1000 * 0.9 && + FXSYS_fabs(pos1.y - pos2.y) <= + std::max(std::max(rcPreObj.Height(), rcPreObj.Width()), + pTextObj2->GetFontSize()) / + 8.0; } bool CPDF_TextPage::IsSameAsPreTextObject( @@ -1531,10 +1519,10 @@ bool CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) { if (!fFontSize) fFontSize = kDefaultFontSize; - info.m_OriginX = preChar->m_OriginX + preWidth * (fFontSize) / 1000; - info.m_OriginY = preChar->m_OriginY; - info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_OriginX, - info.m_OriginY); + info.m_Origin = CFX_PointF(preChar->m_Origin.x + preWidth * fFontSize / 1000, + preChar->m_Origin.y); + info.m_CharBox = CFX_FloatRect(info.m_Origin.x, info.m_Origin.y, + info.m_Origin.x, info.m_Origin.y); return true; } diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h index 85ee7058b6..d22cba3e40 100644 --- a/core/fpdftext/cpdf_textpage.h +++ b/core/fpdftext/cpdf_textpage.h @@ -44,13 +44,16 @@ enum class FPDFText_MarkedContent { Pass = 0, Done, Delay }; enum class FPDFText_Direction { Left = -1, Right = 1 }; -struct FPDF_CHAR_INFO { +class FPDF_CHAR_INFO { + public: + FPDF_CHAR_INFO(); + ~FPDF_CHAR_INFO(); + FX_WCHAR m_Unicode; FX_WCHAR m_Charcode; int32_t m_Flag; FX_FLOAT m_FontSize; - FX_FLOAT m_OriginX; - FX_FLOAT m_OriginY; + CFX_PointF m_Origin; CFX_FloatRect m_CharBox; CPDF_TextObject* m_pTextObj; CFX_Matrix m_Matrix; @@ -61,11 +64,15 @@ struct FPDF_SEGMENT { int m_nCount; }; -struct PAGECHAR_INFO { +class PAGECHAR_INFO { + public: + PAGECHAR_INFO(); + PAGECHAR_INFO(const PAGECHAR_INFO&); + ~PAGECHAR_INFO(); + int m_CharCode; FX_WCHAR m_Unicode; - FX_FLOAT m_OriginX; - FX_FLOAT m_OriginY; + CFX_PointF m_Origin; int32_t m_Flag; CFX_FloatRect m_CharBox; CPDF_TextObject* m_pTextObj; -- cgit v1.2.3