| 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 "core/fpdftext/include/cpdf_textpage.h" | 7 #include "core/fpdftext/include/cpdf_textpage.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 info->m_OriginX = charinfo.m_OriginX; | 380 info->m_OriginX = charinfo.m_OriginX; |
| 381 info->m_OriginY = charinfo.m_OriginY; | 381 info->m_OriginY = charinfo.m_OriginY; |
| 382 info->m_Unicode = charinfo.m_Unicode; | 382 info->m_Unicode = charinfo.m_Unicode; |
| 383 info->m_Flag = charinfo.m_Flag; | 383 info->m_Flag = charinfo.m_Flag; |
| 384 info->m_CharBox = charinfo.m_CharBox; | 384 info->m_CharBox = charinfo.m_CharBox; |
| 385 info->m_pTextObj = charinfo.m_pTextObj; | 385 info->m_pTextObj = charinfo.m_pTextObj; |
| 386 if (charinfo.m_pTextObj && charinfo.m_pTextObj->GetFont()) | 386 if (charinfo.m_pTextObj && charinfo.m_pTextObj->GetFont()) |
| 387 info->m_FontSize = charinfo.m_pTextObj->GetFontSize(); | 387 info->m_FontSize = charinfo.m_pTextObj->GetFontSize(); |
| 388 else | 388 else |
| 389 info->m_FontSize = kDefaultFontSize; | 389 info->m_FontSize = kDefaultFontSize; |
| 390 info->m_Matrix.Copy(charinfo.m_Matrix); | 390 info->m_Matrix = charinfo.m_Matrix; |
| 391 } | 391 } |
| 392 | 392 |
| 393 void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, | 393 void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, |
| 394 int32_t& nCount) const { | 394 int32_t& nCount) const { |
| 395 PAGECHAR_INFO charinfo = m_CharList[start]; | 395 PAGECHAR_INFO charinfo = m_CharList[start]; |
| 396 PAGECHAR_INFO charinfo2 = m_CharList[start + nCount - 1]; | 396 PAGECHAR_INFO charinfo2 = m_CharList[start + nCount - 1]; |
| 397 if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag && | 397 if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag && |
| 398 FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) { | 398 FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) { |
| 399 return; | 399 return; |
| 400 } | 400 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 558 } |
| 559 | 559 |
| 560 void CPDF_TextPage::AppendGeneratedCharacter(FX_WCHAR unicode, | 560 void CPDF_TextPage::AppendGeneratedCharacter(FX_WCHAR unicode, |
| 561 const CFX_Matrix& formMatrix) { | 561 const CFX_Matrix& formMatrix) { |
| 562 PAGECHAR_INFO generateChar; | 562 PAGECHAR_INFO generateChar; |
| 563 if (!GenerateCharInfo(unicode, generateChar)) | 563 if (!GenerateCharInfo(unicode, generateChar)) |
| 564 return; | 564 return; |
| 565 | 565 |
| 566 m_TextBuf.AppendChar(unicode); | 566 m_TextBuf.AppendChar(unicode); |
| 567 if (!formMatrix.IsIdentity()) | 567 if (!formMatrix.IsIdentity()) |
| 568 generateChar.m_Matrix.Copy(formMatrix); | 568 generateChar.m_Matrix = formMatrix; |
| 569 m_CharList.push_back(generateChar); | 569 m_CharList.push_back(generateChar); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void CPDF_TextPage::ProcessObject() { | 572 void CPDF_TextPage::ProcessObject() { |
| 573 if (m_pPage->GetPageObjectList()->empty()) | 573 if (m_pPage->GetPageObjectList()->empty()) |
| 574 return; | 574 return; |
| 575 | 575 |
| 576 m_TextlineDir = FindTextlineFlowOrientation(); | 576 m_TextlineDir = FindTextlineFlowOrientation(); |
| 577 const CPDF_PageObjectList* pObjList = m_pPage->GetPageObjectList(); | 577 const CPDF_PageObjectList* pObjList = m_pPage->GetPageObjectList(); |
| 578 for (auto it = pObjList->begin(); it != pObjList->end(); ++it) { | 578 for (auto it = pObjList->begin(); it != pObjList->end(); ++it) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 593 CloseTempLine(); | 593 CloseTempLine(); |
| 594 } | 594 } |
| 595 | 595 |
| 596 void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, | 596 void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, |
| 597 const CFX_Matrix& formMatrix) { | 597 const CFX_Matrix& formMatrix) { |
| 598 CPDF_PageObjectList* pObjectList = pFormObj->m_pForm->GetPageObjectList(); | 598 CPDF_PageObjectList* pObjectList = pFormObj->m_pForm->GetPageObjectList(); |
| 599 if (pObjectList->empty()) | 599 if (pObjectList->empty()) |
| 600 return; | 600 return; |
| 601 | 601 |
| 602 CFX_Matrix curFormMatrix; | 602 CFX_Matrix curFormMatrix; |
| 603 curFormMatrix.Copy(pFormObj->m_FormMatrix); | 603 curFormMatrix = pFormObj->m_FormMatrix; |
| 604 curFormMatrix.Concat(formMatrix); | 604 curFormMatrix.Concat(formMatrix); |
| 605 | 605 |
| 606 for (auto it = pObjectList->begin(); it != pObjectList->end(); ++it) { | 606 for (auto it = pObjectList->begin(); it != pObjectList->end(); ++it) { |
| 607 if (CPDF_PageObject* pPageObj = it->get()) { | 607 if (CPDF_PageObject* pPageObj = it->get()) { |
| 608 if (pPageObj->IsText()) | 608 if (pPageObj->IsText()) |
| 609 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it); | 609 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it); |
| 610 else if (pPageObj->IsForm()) | 610 else if (pPageObj->IsForm()) |
| 611 ProcessFormObject(pPageObj->AsForm(), curFormMatrix); | 611 ProcessFormObject(pPageObj->AsForm(), curFormMatrix); |
| 612 } | 612 } |
| 613 } | 613 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 charinfo.m_OriginY = fPosY; | 914 charinfo.m_OriginY = fPosY; |
| 915 charinfo.m_Index = nCharInfoIndex; | 915 charinfo.m_Index = nCharInfoIndex; |
| 916 charinfo.m_Unicode = wChar; | 916 charinfo.m_Unicode = wChar; |
| 917 charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar); | 917 charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar); |
| 918 charinfo.m_Flag = FPDFTEXT_CHAR_PIECE; | 918 charinfo.m_Flag = FPDFTEXT_CHAR_PIECE; |
| 919 charinfo.m_pTextObj = pTextObj; | 919 charinfo.m_pTextObj = pTextObj; |
| 920 charinfo.m_CharBox.top = charBox.top; | 920 charinfo.m_CharBox.top = charBox.top; |
| 921 charinfo.m_CharBox.left = charBox.left; | 921 charinfo.m_CharBox.left = charBox.left; |
| 922 charinfo.m_CharBox.right = charBox.right; | 922 charinfo.m_CharBox.right = charBox.right; |
| 923 charinfo.m_CharBox.bottom = charBox.bottom; | 923 charinfo.m_CharBox.bottom = charBox.bottom; |
| 924 charinfo.m_Matrix.Copy(matrix); | 924 charinfo.m_Matrix = matrix; |
| 925 m_TempTextBuf.AppendChar(wChar); | 925 m_TempTextBuf.AppendChar(wChar); |
| 926 m_TempCharList.push_back(charinfo); | 926 m_TempCharList.push_back(charinfo); |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 | 929 |
| 930 void CPDF_TextPage::FindPreviousTextObject() { | 930 void CPDF_TextPage::FindPreviousTextObject() { |
| 931 if (m_TempCharList.empty() && m_CharList.empty()) | 931 if (m_TempCharList.empty() && m_CharList.empty()) |
| 932 return; | 932 return; |
| 933 | 933 |
| 934 PAGECHAR_INFO preChar = | 934 PAGECHAR_INFO preChar = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) | 977 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) |
| 978 return; | 978 return; |
| 979 CFX_Matrix formMatrix = Obj.m_formMatrix; | 979 CFX_Matrix formMatrix = Obj.m_formMatrix; |
| 980 CPDF_Font* pFont = pTextObj->GetFont(); | 980 CPDF_Font* pFont = pTextObj->GetFont(); |
| 981 CFX_Matrix matrix; | 981 CFX_Matrix matrix; |
| 982 pTextObj->GetTextMatrix(&matrix); | 982 pTextObj->GetTextMatrix(&matrix); |
| 983 matrix.Concat(formMatrix); | 983 matrix.Concat(formMatrix); |
| 984 FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj); | 984 FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj); |
| 985 if (ePreMKC == FPDFText_MarkedContent::Done) { | 985 if (ePreMKC == FPDFText_MarkedContent::Done) { |
| 986 m_pPreTextObj = pTextObj; | 986 m_pPreTextObj = pTextObj; |
| 987 m_perMatrix.Copy(formMatrix); | 987 m_perMatrix = formMatrix; |
| 988 return; | 988 return; |
| 989 } | 989 } |
| 990 GenerateCharacter result = GenerateCharacter::None; | 990 GenerateCharacter result = GenerateCharacter::None; |
| 991 if (m_pPreTextObj) { | 991 if (m_pPreTextObj) { |
| 992 result = ProcessInsertObject(pTextObj, formMatrix); | 992 result = ProcessInsertObject(pTextObj, formMatrix); |
| 993 if (result == GenerateCharacter::LineBreak) { | 993 if (result == GenerateCharacter::LineBreak) { |
| 994 m_CurlineRect = | 994 m_CurlineRect = |
| 995 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, | 995 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, |
| 996 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); | 996 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); |
| 997 } else { | 997 } else { |
| 998 m_CurlineRect.Union( | 998 m_CurlineRect.Union( |
| 999 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, | 999 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, |
| 1000 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top)); | 1000 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top)); |
| 1001 } | 1001 } |
| 1002 switch (result) { | 1002 switch (result) { |
| 1003 case GenerateCharacter::None: | 1003 case GenerateCharacter::None: |
| 1004 break; | 1004 break; |
| 1005 case GenerateCharacter::Space: { | 1005 case GenerateCharacter::Space: { |
| 1006 PAGECHAR_INFO generateChar; | 1006 PAGECHAR_INFO generateChar; |
| 1007 if (GenerateCharInfo(TEXT_SPACE_CHAR, generateChar)) { | 1007 if (GenerateCharInfo(TEXT_SPACE_CHAR, generateChar)) { |
| 1008 if (!formMatrix.IsIdentity()) | 1008 if (!formMatrix.IsIdentity()) |
| 1009 generateChar.m_Matrix.Copy(formMatrix); | 1009 generateChar.m_Matrix = formMatrix; |
| 1010 m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR); | 1010 m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR); |
| 1011 m_TempCharList.push_back(generateChar); | 1011 m_TempCharList.push_back(generateChar); |
| 1012 } | 1012 } |
| 1013 break; | 1013 break; |
| 1014 } | 1014 } |
| 1015 case GenerateCharacter::LineBreak: | 1015 case GenerateCharacter::LineBreak: |
| 1016 CloseTempLine(); | 1016 CloseTempLine(); |
| 1017 if (m_TextBuf.GetSize()) { | 1017 if (m_TextBuf.GetSize()) { |
| 1018 AppendGeneratedCharacter(TEXT_RETURN_CHAR, formMatrix); | 1018 AppendGeneratedCharacter(TEXT_RETURN_CHAR, formMatrix); |
| 1019 AppendGeneratedCharacter(TEXT_LINEFEED_CHAR, formMatrix); | 1019 AppendGeneratedCharacter(TEXT_LINEFEED_CHAR, formMatrix); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1045 break; | 1045 break; |
| 1046 } | 1046 } |
| 1047 } else { | 1047 } else { |
| 1048 m_CurlineRect = | 1048 m_CurlineRect = |
| 1049 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, | 1049 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, |
| 1050 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); | 1050 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); |
| 1051 } | 1051 } |
| 1052 if (ePreMKC == FPDFText_MarkedContent::Delay) { | 1052 if (ePreMKC == FPDFText_MarkedContent::Delay) { |
| 1053 ProcessMarkedContent(Obj); | 1053 ProcessMarkedContent(Obj); |
| 1054 m_pPreTextObj = pTextObj; | 1054 m_pPreTextObj = pTextObj; |
| 1055 m_perMatrix.Copy(formMatrix); | 1055 m_perMatrix = formMatrix; |
| 1056 return; | 1056 return; |
| 1057 } | 1057 } |
| 1058 m_pPreTextObj = pTextObj; | 1058 m_pPreTextObj = pTextObj; |
| 1059 m_perMatrix.Copy(formMatrix); | 1059 m_perMatrix = formMatrix; |
| 1060 int nItems = pTextObj->CountItems(); | 1060 int nItems = pTextObj->CountItems(); |
| 1061 FX_FLOAT baseSpace = CalculateBaseSpace(pTextObj, matrix); | 1061 FX_FLOAT baseSpace = CalculateBaseSpace(pTextObj, matrix); |
| 1062 | 1062 |
| 1063 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); | 1063 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); |
| 1064 const FX_BOOL bIsBidiAndMirrorInverse = | 1064 const FX_BOOL bIsBidiAndMirrorInverse = |
| 1065 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; | 1065 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; |
| 1066 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); | 1066 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); |
| 1067 int32_t iCharListStartAppend = | 1067 int32_t iCharListStartAppend = |
| 1068 pdfium::CollectionSize<int32_t>(m_TempCharList); | 1068 pdfium::CollectionSize<int32_t>(m_TempCharList); |
| 1069 | 1069 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 threshold = NormalizeThreshold(threshold); | 1110 threshold = NormalizeThreshold(threshold); |
| 1111 threshold = fontsize_h * threshold / 1000; | 1111 threshold = fontsize_h * threshold / 1000; |
| 1112 } | 1112 } |
| 1113 if (threshold && (spacing && spacing >= threshold)) { | 1113 if (threshold && (spacing && spacing >= threshold)) { |
| 1114 charinfo.m_Unicode = TEXT_SPACE_CHAR; | 1114 charinfo.m_Unicode = TEXT_SPACE_CHAR; |
| 1115 charinfo.m_Flag = FPDFTEXT_CHAR_GENERATED; | 1115 charinfo.m_Flag = FPDFTEXT_CHAR_GENERATED; |
| 1116 charinfo.m_pTextObj = pTextObj; | 1116 charinfo.m_pTextObj = pTextObj; |
| 1117 charinfo.m_Index = m_TextBuf.GetLength(); | 1117 charinfo.m_Index = m_TextBuf.GetLength(); |
| 1118 m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR); | 1118 m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR); |
| 1119 charinfo.m_CharCode = CPDF_Font::kInvalidCharCode; | 1119 charinfo.m_CharCode = CPDF_Font::kInvalidCharCode; |
| 1120 charinfo.m_Matrix.Copy(formMatrix); | 1120 charinfo.m_Matrix = formMatrix; |
| 1121 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, | 1121 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, |
| 1122 charinfo.m_OriginY); | 1122 charinfo.m_OriginY); |
| 1123 charinfo.m_CharBox = | 1123 charinfo.m_CharBox = |
| 1124 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, | 1124 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, |
| 1125 charinfo.m_OriginX, charinfo.m_OriginY); | 1125 charinfo.m_OriginX, charinfo.m_OriginY); |
| 1126 m_TempCharList.push_back(charinfo); | 1126 m_TempCharList.push_back(charinfo); |
| 1127 } | 1127 } |
| 1128 if (item.m_CharCode == CPDF_Font::kInvalidCharCode) | 1128 if (item.m_CharCode == CPDF_Font::kInvalidCharCode) |
| 1129 continue; | 1129 continue; |
| 1130 } | 1130 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1161 rect.bottom * pTextObj->GetFontSize() / 1000 + item.m_OriginY; | 1161 rect.bottom * pTextObj->GetFontSize() / 1000 + item.m_OriginY; |
| 1162 if (fabsf(charinfo.m_CharBox.top - charinfo.m_CharBox.bottom) < 0.01f) { | 1162 if (fabsf(charinfo.m_CharBox.top - charinfo.m_CharBox.bottom) < 0.01f) { |
| 1163 charinfo.m_CharBox.top = | 1163 charinfo.m_CharBox.top = |
| 1164 charinfo.m_CharBox.bottom + pTextObj->GetFontSize(); | 1164 charinfo.m_CharBox.bottom + pTextObj->GetFontSize(); |
| 1165 } | 1165 } |
| 1166 if (fabsf(charinfo.m_CharBox.right - charinfo.m_CharBox.left) < 0.01f) { | 1166 if (fabsf(charinfo.m_CharBox.right - charinfo.m_CharBox.left) < 0.01f) { |
| 1167 charinfo.m_CharBox.right = | 1167 charinfo.m_CharBox.right = |
| 1168 charinfo.m_CharBox.left + pTextObj->GetCharWidth(charinfo.m_CharCode); | 1168 charinfo.m_CharBox.left + pTextObj->GetCharWidth(charinfo.m_CharCode); |
| 1169 } | 1169 } |
| 1170 matrix.TransformRect(charinfo.m_CharBox); | 1170 matrix.TransformRect(charinfo.m_CharBox); |
| 1171 charinfo.m_Matrix.Copy(matrix); | 1171 charinfo.m_Matrix = matrix; |
| 1172 if (wstrItem.IsEmpty()) { | 1172 if (wstrItem.IsEmpty()) { |
| 1173 charinfo.m_Unicode = 0; | 1173 charinfo.m_Unicode = 0; |
| 1174 m_TempCharList.push_back(charinfo); | 1174 m_TempCharList.push_back(charinfo); |
| 1175 m_TempTextBuf.AppendChar(0xfffe); | 1175 m_TempTextBuf.AppendChar(0xfffe); |
| 1176 continue; | 1176 continue; |
| 1177 } else { | 1177 } else { |
| 1178 int nTotal = wstrItem.GetLength(); | 1178 int nTotal = wstrItem.GetLength(); |
| 1179 bool bDel = false; | 1179 bool bDel = false; |
| 1180 const int count = | 1180 const int count = |
| 1181 std::min(pdfium::CollectionSize<int>(m_TempCharList), 7); | 1181 std::min(pdfium::CollectionSize<int>(m_TempCharList), 7); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 info.m_OriginY); | 1537 info.m_OriginY); |
| 1538 return TRUE; | 1538 return TRUE; |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, | 1541 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, |
| 1542 const CFX_FloatRect& rect2) { | 1542 const CFX_FloatRect& rect2) { |
| 1543 CFX_FloatRect rect = rect1; | 1543 CFX_FloatRect rect = rect1; |
| 1544 rect.Intersect(rect2); | 1544 rect.Intersect(rect2); |
| 1545 return !rect.IsEmpty(); | 1545 return !rect.IsEmpty(); |
| 1546 } | 1546 } |
| OLD | NEW |