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 <algorithm> | 7 #include <algorithm> |
8 #include <cctype> | 8 #include <cctype> |
9 #include <cwctype> | 9 #include <cwctype> |
10 #include <memory> | 10 #include <memory> |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return charInfo.m_Flag != FPDFTEXT_CHAR_HYPHEN; | 170 return charInfo.m_Flag != FPDFTEXT_CHAR_HYPHEN; |
171 default: | 171 default: |
172 return false; | 172 return false; |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void CPDF_TextPage::ParseTextPage() { | 176 void CPDF_TextPage::ParseTextPage() { |
177 m_bIsParsed = false; | 177 m_bIsParsed = false; |
178 m_TextBuf.Clear(); | 178 m_TextBuf.Clear(); |
179 m_CharList.clear(); | 179 m_CharList.clear(); |
180 m_pPreTextObj = NULL; | 180 m_pPreTextObj = nullptr; |
181 ProcessObject(); | 181 ProcessObject(); |
182 | 182 |
183 m_bIsParsed = true; | 183 m_bIsParsed = true; |
184 m_CharIndex.clear(); | 184 m_CharIndex.clear(); |
185 int nCount = pdfium::CollectionSize<int>(m_CharList); | 185 int nCount = pdfium::CollectionSize<int>(m_CharList); |
186 if (nCount) { | 186 if (nCount) { |
187 m_CharIndex.push_back(0); | 187 m_CharIndex.push_back(0); |
188 } | 188 } |
189 for (int i = 0; i < nCount; i++) { | 189 for (int i = 0; i < nCount; i++) { |
190 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); | 190 int indexSize = pdfium::CollectionSize<int>(m_CharIndex); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 return w; | 829 return w; |
830 | 830 |
831 return pFont->GetCharBBox(charCode).Width(); | 831 return pFont->GetCharBBox(charCode).Width(); |
832 } | 832 } |
833 | 833 |
834 void CPDF_TextPage::AddCharInfoByLRDirection(FX_WCHAR wChar, | 834 void CPDF_TextPage::AddCharInfoByLRDirection(FX_WCHAR wChar, |
835 PAGECHAR_INFO info) { | 835 PAGECHAR_INFO info) { |
836 if (!IsControlChar(info)) { | 836 if (!IsControlChar(info)) { |
837 info.m_Index = m_TextBuf.GetLength(); | 837 info.m_Index = m_TextBuf.GetLength(); |
838 if (wChar >= 0xFB00 && wChar <= 0xFB06) { | 838 if (wChar >= 0xFB00 && wChar <= 0xFB06) { |
839 FX_WCHAR* pDst = NULL; | 839 FX_WCHAR* pDst = nullptr; |
840 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); | 840 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); |
841 if (nCount >= 1) { | 841 if (nCount >= 1) { |
842 pDst = FX_Alloc(FX_WCHAR, nCount); | 842 pDst = FX_Alloc(FX_WCHAR, nCount); |
843 Unicode_GetNormalization(wChar, pDst); | 843 Unicode_GetNormalization(wChar, pDst); |
844 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 844 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
845 PAGECHAR_INFO info2 = info; | 845 PAGECHAR_INFO info2 = info; |
846 info2.m_Unicode = pDst[nIndex]; | 846 info2.m_Unicode = pDst[nIndex]; |
847 info2.m_Flag = FPDFTEXT_CHAR_PIECE; | 847 info2.m_Flag = FPDFTEXT_CHAR_PIECE; |
848 m_TextBuf.AppendChar(info2.m_Unicode); | 848 m_TextBuf.AppendChar(info2.m_Unicode); |
849 m_CharList.push_back(info2); | 849 m_CharList.push_back(info2); |
850 } | 850 } |
851 FX_Free(pDst); | 851 FX_Free(pDst); |
852 return; | 852 return; |
853 } | 853 } |
854 } | 854 } |
855 m_TextBuf.AppendChar(wChar); | 855 m_TextBuf.AppendChar(wChar); |
856 } else { | 856 } else { |
857 info.m_Index = -1; | 857 info.m_Index = -1; |
858 } | 858 } |
859 m_CharList.push_back(info); | 859 m_CharList.push_back(info); |
860 } | 860 } |
861 | 861 |
862 void CPDF_TextPage::AddCharInfoByRLDirection(FX_WCHAR wChar, | 862 void CPDF_TextPage::AddCharInfoByRLDirection(FX_WCHAR wChar, |
863 PAGECHAR_INFO info) { | 863 PAGECHAR_INFO info) { |
864 if (!IsControlChar(info)) { | 864 if (!IsControlChar(info)) { |
865 info.m_Index = m_TextBuf.GetLength(); | 865 info.m_Index = m_TextBuf.GetLength(); |
866 wChar = FX_GetMirrorChar(wChar, TRUE, FALSE); | 866 wChar = FX_GetMirrorChar(wChar, TRUE, FALSE); |
867 FX_WCHAR* pDst = NULL; | 867 FX_WCHAR* pDst = nullptr; |
868 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); | 868 FX_STRSIZE nCount = Unicode_GetNormalization(wChar, pDst); |
869 if (nCount >= 1) { | 869 if (nCount >= 1) { |
870 pDst = FX_Alloc(FX_WCHAR, nCount); | 870 pDst = FX_Alloc(FX_WCHAR, nCount); |
871 Unicode_GetNormalization(wChar, pDst); | 871 Unicode_GetNormalization(wChar, pDst); |
872 for (int nIndex = 0; nIndex < nCount; nIndex++) { | 872 for (int nIndex = 0; nIndex < nCount; nIndex++) { |
873 PAGECHAR_INFO info2 = info; | 873 PAGECHAR_INFO info2 = info; |
874 info2.m_Unicode = pDst[nIndex]; | 874 info2.m_Unicode = pDst[nIndex]; |
875 info2.m_Flag = FPDFTEXT_CHAR_PIECE; | 875 info2.m_Flag = FPDFTEXT_CHAR_PIECE; |
876 m_TextBuf.AppendChar(info2.m_Unicode); | 876 m_TextBuf.AppendChar(info2.m_Unicode); |
877 m_CharList.push_back(info2); | 877 m_CharList.push_back(info2); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 (CPDF_ContentMarkData*)pTextObj->m_ContentMark.GetObject(); | 1012 (CPDF_ContentMarkData*)pTextObj->m_ContentMark.GetObject(); |
1013 if (!pMarkData) | 1013 if (!pMarkData) |
1014 return FPDFText_MarkedContent::Pass; | 1014 return FPDFText_MarkedContent::Pass; |
1015 | 1015 |
1016 int nContentMark = pMarkData->CountItems(); | 1016 int nContentMark = pMarkData->CountItems(); |
1017 if (nContentMark < 1) | 1017 if (nContentMark < 1) |
1018 return FPDFText_MarkedContent::Pass; | 1018 return FPDFText_MarkedContent::Pass; |
1019 | 1019 |
1020 CFX_WideString actText; | 1020 CFX_WideString actText; |
1021 FX_BOOL bExist = FALSE; | 1021 FX_BOOL bExist = FALSE; |
1022 CPDF_Dictionary* pDict = NULL; | 1022 CPDF_Dictionary* pDict = nullptr; |
1023 int n = 0; | 1023 int n = 0; |
1024 for (n = 0; n < nContentMark; n++) { | 1024 for (n = 0; n < nContentMark; n++) { |
1025 CPDF_ContentMarkItem& item = pMarkData->GetItem(n); | 1025 CPDF_ContentMarkItem& item = pMarkData->GetItem(n); |
1026 if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) | 1026 if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) |
1027 continue; | 1027 continue; |
1028 pDict = item.GetParam(); | 1028 pDict = item.GetParam(); |
1029 CPDF_String* temp = | 1029 CPDF_String* temp = |
1030 ToString(pDict ? pDict->GetObjectBy("ActualText") : nullptr); | 1030 ToString(pDict ? pDict->GetObjectBy("ActualText") : nullptr); |
1031 if (temp) { | 1031 if (temp) { |
1032 bExist = TRUE; | 1032 bExist = TRUE; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 CPDF_TextObject* pTextObj = Obj.m_pTextObj; | 1078 CPDF_TextObject* pTextObj = Obj.m_pTextObj; |
1079 CPDF_ContentMarkData* pMarkData = | 1079 CPDF_ContentMarkData* pMarkData = |
1080 (CPDF_ContentMarkData*)pTextObj->m_ContentMark.GetObject(); | 1080 (CPDF_ContentMarkData*)pTextObj->m_ContentMark.GetObject(); |
1081 if (!pMarkData) | 1081 if (!pMarkData) |
1082 return; | 1082 return; |
1083 | 1083 |
1084 int nContentMark = pMarkData->CountItems(); | 1084 int nContentMark = pMarkData->CountItems(); |
1085 if (nContentMark < 1) | 1085 if (nContentMark < 1) |
1086 return; | 1086 return; |
1087 CFX_WideString actText; | 1087 CFX_WideString actText; |
1088 CPDF_Dictionary* pDict = NULL; | 1088 CPDF_Dictionary* pDict = nullptr; |
1089 for (int n = 0; n < nContentMark; n++) { | 1089 for (int n = 0; n < nContentMark; n++) { |
1090 CPDF_ContentMarkItem& item = pMarkData->GetItem(n); | 1090 CPDF_ContentMarkItem& item = pMarkData->GetItem(n); |
1091 if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) | 1091 if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) |
1092 continue; | 1092 continue; |
1093 pDict = item.GetParam(); | 1093 pDict = item.GetParam(); |
1094 if (pDict) | 1094 if (pDict) |
1095 actText = pDict->GetUnicodeTextBy("ActualText"); | 1095 actText = pDict->GetUnicodeTextBy("ActualText"); |
1096 } | 1096 } |
1097 FX_STRSIZE nItems = actText.GetLength(); | 1097 FX_STRSIZE nItems = actText.GetLength(); |
1098 if (nItems < 1) | 1098 if (nItems < 1) |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 const PAGECHAR_INFO* preChar; | 1753 const PAGECHAR_INFO* preChar; |
1754 if (!m_TempCharList.empty()) { | 1754 if (!m_TempCharList.empty()) { |
1755 preChar = &m_TempCharList.back(); | 1755 preChar = &m_TempCharList.back(); |
1756 } else if (!m_CharList.empty()) { | 1756 } else if (!m_CharList.empty()) { |
1757 preChar = &m_CharList.back(); | 1757 preChar = &m_CharList.back(); |
1758 } else { | 1758 } else { |
1759 return FALSE; | 1759 return FALSE; |
1760 } | 1760 } |
1761 info.m_Index = m_TextBuf.GetLength(); | 1761 info.m_Index = m_TextBuf.GetLength(); |
1762 info.m_Unicode = unicode; | 1762 info.m_Unicode = unicode; |
1763 info.m_pTextObj = NULL; | 1763 info.m_pTextObj = nullptr; |
1764 info.m_CharCode = CPDF_Font::kInvalidCharCode; | 1764 info.m_CharCode = CPDF_Font::kInvalidCharCode; |
1765 info.m_Flag = FPDFTEXT_CHAR_GENERATED; | 1765 info.m_Flag = FPDFTEXT_CHAR_GENERATED; |
1766 int preWidth = 0; | 1766 int preWidth = 0; |
1767 if (preChar->m_pTextObj && preChar->m_CharCode != -1) { | 1767 if (preChar->m_pTextObj && preChar->m_CharCode != -1) { |
1768 preWidth = | 1768 preWidth = |
1769 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); | 1769 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); |
1770 } | 1770 } |
1771 | 1771 |
1772 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize() | 1772 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize() |
1773 : preChar->m_CharBox.Height(); | 1773 : preChar->m_CharBox.Height(); |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; | 2338 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; |
2339 } | 2339 } |
2340 | 2340 |
2341 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { | 2341 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { |
2342 if (index >= m_LinkArray.size()) | 2342 if (index >= m_LinkArray.size()) |
2343 return std::vector<CFX_FloatRect>(); | 2343 return std::vector<CFX_FloatRect>(); |
2344 | 2344 |
2345 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, | 2345 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, |
2346 m_LinkArray[index].m_Count); | 2346 m_LinkArray[index].m_Count); |
2347 } | 2347 } |
OLD | NEW |