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 <ctype.h> | 7 #include <ctype.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "../../../third_party/base/nonstd_unique_ptr.h" | 10 #include "../../../third_party/base/nonstd_unique_ptr.h" |
11 #include "../../include/fpdfapi/fpdf_module.h" | 11 #include "../../include/fpdfapi/fpdf_module.h" |
12 #include "../../include/fpdfapi/fpdf_page.h" | 12 #include "../../include/fpdfapi/fpdf_page.h" |
13 #include "../../include/fpdfapi/fpdf_pageobj.h" | 13 #include "../../include/fpdfapi/fpdf_pageobj.h" |
14 #include "../../include/fpdfapi/fpdf_resource.h" | 14 #include "../../include/fpdfapi/fpdf_resource.h" |
15 #include "../../include/fpdftext/fpdf_text.h" | 15 #include "../../include/fpdftext/fpdf_text.h" |
16 #include "../../include/fxcrt/fx_arb.h" | 16 #include "../../include/fxcrt/fx_bidi.h" |
17 #include "../../include/fxcrt/fx_ucd.h" | 17 #include "../../include/fxcrt/fx_ucd.h" |
18 #include "text_int.h" | 18 #include "text_int.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) { | 22 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) { |
23 if (curChar < 255) { | 23 if (curChar < 255) { |
24 return FALSE; | 24 return FALSE; |
25 } | 25 } |
26 if ((curChar >= 0x0600 && curChar <= 0x06FF) || | 26 if ((curChar >= 0x0600 && curChar <= 0x06FF) || |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 pFont->AppendChar(str, charCode); | 1013 pFont->AppendChar(str, charCode); |
1014 w = pFont->GetStringWidth(str, 1); | 1014 w = pFont->GetStringWidth(str, 1); |
1015 if (w == 0) { | 1015 if (w == 0) { |
1016 FX_RECT BBox; | 1016 FX_RECT BBox; |
1017 pFont->GetCharBBox(charCode, BBox); | 1017 pFont->GetCharBBox(charCode, BBox); |
1018 w = BBox.right - BBox.left; | 1018 w = BBox.right - BBox.left; |
1019 } | 1019 } |
1020 } | 1020 } |
1021 return w; | 1021 return w; |
1022 } | 1022 } |
1023 void CPDF_TextPage::OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str) { | 1023 void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) { |
1024 int32_t start, count; | 1024 int32_t start, count; |
1025 int32_t ret = pBidi->GetBidiInfo(start, count); | 1025 CFX_BidiChar::Direction ret = pBidi->GetBidiInfo(&start, &count); |
1026 if (ret == 2) { | 1026 if (ret == CFX_BidiChar::RIGHT) { |
1027 for (int i = start + count - 1; i >= start; i--) { | 1027 for (int i = start + count - 1; i >= start; i--) { |
1028 m_TextBuf.AppendChar(str.GetAt(i)); | 1028 m_TextBuf.AppendChar(str.GetAt(i)); |
1029 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); | 1029 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); |
1030 } | 1030 } |
1031 } else { | 1031 } else { |
1032 int end = start + count; | 1032 int end = start + count; |
1033 for (int i = start; i < end; i++) { | 1033 for (int i = start; i < end; i++) { |
1034 m_TextBuf.AppendChar(str.GetAt(i)); | 1034 m_TextBuf.AppendChar(str.GetAt(i)); |
1035 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); | 1035 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); |
1036 } | 1036 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 } | 1097 } |
1098 if (!m_ParseOptions.m_bGetCharCodeOnly) { | 1098 if (!m_ParseOptions.m_bGetCharCodeOnly) { |
1099 m_charList.Add(Info); | 1099 m_charList.Add(Info); |
1100 } | 1100 } |
1101 } | 1101 } |
1102 void CPDF_TextPage::CloseTempLine() { | 1102 void CPDF_TextPage::CloseTempLine() { |
1103 int count1 = m_TempCharList.GetSize(); | 1103 int count1 = m_TempCharList.GetSize(); |
1104 if (count1 <= 0) { | 1104 if (count1 <= 0) { |
1105 return; | 1105 return; |
1106 } | 1106 } |
1107 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 1107 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
1108 CFX_WideString str = m_TempTextBuf.GetWideString(); | 1108 CFX_WideString str = m_TempTextBuf.GetWideString(); |
1109 CFX_WordArray order; | 1109 CFX_WordArray order; |
1110 FX_BOOL bR2L = FALSE; | 1110 FX_BOOL bR2L = FALSE; |
1111 int32_t start = 0, count = 0; | 1111 int32_t start = 0, count = 0; |
1112 int nR2L = 0, nL2R = 0; | 1112 int nR2L = 0, nL2R = 0; |
1113 FX_BOOL bPrevSpace = FALSE; | 1113 FX_BOOL bPrevSpace = FALSE; |
1114 for (int i = 0; i < str.GetLength(); i++) { | 1114 for (int i = 0; i < str.GetLength(); i++) { |
1115 if (str.GetAt(i) == 32) { | 1115 if (str.GetAt(i) == 32) { |
1116 if (bPrevSpace) { | 1116 if (bPrevSpace) { |
1117 m_TempTextBuf.Delete(i, 1); | 1117 m_TempTextBuf.Delete(i, 1); |
1118 m_TempCharList.Delete(i); | 1118 m_TempCharList.Delete(i); |
1119 str.Delete(i); | 1119 str.Delete(i); |
1120 count1--; | 1120 count1--; |
1121 i--; | 1121 i--; |
1122 continue; | 1122 continue; |
1123 } | 1123 } |
1124 bPrevSpace = TRUE; | 1124 bPrevSpace = TRUE; |
1125 } else { | 1125 } else { |
1126 bPrevSpace = FALSE; | 1126 bPrevSpace = FALSE; |
1127 } | 1127 } |
1128 if (pBidiChar->AppendChar(str.GetAt(i))) { | 1128 if (pBidiChar->AppendChar(str.GetAt(i))) { |
1129 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1129 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
1130 order.Add(start); | 1130 order.Add(start); |
1131 order.Add(count); | 1131 order.Add(count); |
1132 order.Add(ret); | 1132 order.Add(ret); |
1133 if (!bR2L) { | 1133 if (!bR2L) { |
1134 if (ret == 2) { | 1134 if (ret == CFX_BidiChar::RIGHT) { |
1135 nR2L++; | 1135 nR2L++; |
1136 } else if (ret == 1) { | 1136 } else if (ret == CFX_BidiChar::LEFT) { |
1137 nL2R++; | 1137 nL2R++; |
1138 } | 1138 } |
1139 } | 1139 } |
1140 } | 1140 } |
1141 } | 1141 } |
1142 if (pBidiChar->EndChar()) { | 1142 if (pBidiChar->EndChar()) { |
1143 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1143 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
1144 order.Add(start); | 1144 order.Add(start); |
1145 order.Add(count); | 1145 order.Add(count); |
1146 order.Add(ret); | 1146 order.Add(ret); |
1147 if (!bR2L) { | 1147 if (!bR2L) { |
1148 if (ret == 2) { | 1148 if (ret == CFX_BidiChar::RIGHT) { |
1149 nR2L++; | 1149 nR2L++; |
1150 } else if (ret == 1) { | 1150 } else if (ret == CFX_BidiChar::LEFT) { |
1151 nL2R++; | 1151 nL2R++; |
1152 } | 1152 } |
1153 } | 1153 } |
1154 } | 1154 } |
1155 if (nR2L > 0 && nR2L >= nL2R) { | 1155 if (nR2L > 0 && nR2L >= nL2R) { |
1156 bR2L = TRUE; | 1156 bR2L = TRUE; |
1157 } | 1157 } |
1158 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { | 1158 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { |
1159 int count = order.GetSize(); | 1159 int count = order.GetSize(); |
1160 for (int i = count - 1; i > 0; i -= 3) { | 1160 for (int i = count - 1; i > 0; i -= 3) { |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); | 1755 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); |
1756 i = iBufStartAppend; | 1756 i = iBufStartAppend; |
1757 j = m_TempTextBuf.GetLength() - 1; | 1757 j = m_TempTextBuf.GetLength() - 1; |
1758 for (; i < j; i++, j--) { | 1758 for (; i < j; i++, j--) { |
1759 std::swap(pTempBuffer[i], pTempBuffer[j]); | 1759 std::swap(pTempBuffer[i], pTempBuffer[j]); |
1760 } | 1760 } |
1761 } | 1761 } |
1762 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, | 1762 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
1763 const CPDF_Font* pFont, | 1763 const CPDF_Font* pFont, |
1764 int nItems) const { | 1764 int nItems) const { |
1765 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 1765 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
1766 int32_t nR2L = 0; | 1766 int32_t nR2L = 0; |
1767 int32_t nL2R = 0; | 1767 int32_t nL2R = 0; |
1768 int32_t start = 0, count = 0; | 1768 int32_t start = 0, count = 0; |
1769 CPDF_TextObjectItem item; | 1769 CPDF_TextObjectItem item; |
1770 for (int32_t i = 0; i < nItems; i++) { | 1770 for (int32_t i = 0; i < nItems; i++) { |
1771 pTextObj->GetItemInfo(i, &item); | 1771 pTextObj->GetItemInfo(i, &item); |
1772 if (item.m_CharCode == (FX_DWORD)-1) { | 1772 if (item.m_CharCode == (FX_DWORD)-1) { |
1773 continue; | 1773 continue; |
1774 } | 1774 } |
1775 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | 1775 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); |
1776 FX_WCHAR wChar = wstrItem.GetAt(0); | 1776 FX_WCHAR wChar = wstrItem.GetAt(0); |
1777 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | 1777 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { |
1778 wChar = (FX_WCHAR)item.m_CharCode; | 1778 wChar = (FX_WCHAR)item.m_CharCode; |
1779 } | 1779 } |
1780 if (!wChar) { | 1780 if (!wChar) { |
1781 continue; | 1781 continue; |
1782 } | 1782 } |
1783 if (pBidiChar->AppendChar(wChar)) { | 1783 if (pBidiChar->AppendChar(wChar)) { |
1784 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1784 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
1785 if (ret == 2) { | 1785 if (ret == CFX_BidiChar::RIGHT) { |
1786 nR2L++; | 1786 nR2L++; |
1787 } else if (ret == 1) { | 1787 } else if (ret == CFX_BidiChar::LEFT) { |
1788 nL2R++; | 1788 nL2R++; |
1789 } | 1789 } |
1790 } | 1790 } |
1791 } | 1791 } |
1792 if (pBidiChar->EndChar()) { | 1792 if (pBidiChar->EndChar()) { |
1793 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1793 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
1794 if (ret == 2) { | 1794 if (ret == CFX_BidiChar::RIGHT) { |
1795 nR2L++; | 1795 nR2L++; |
1796 } else if (ret == 1) { | 1796 } else if (ret == CFX_BidiChar::LEFT) { |
1797 nL2R++; | 1797 nL2R++; |
1798 } | 1798 } |
1799 } | 1799 } |
1800 return (nR2L > 0 && nR2L >= nL2R); | 1800 return (nR2L > 0 && nR2L >= nL2R); |
1801 } | 1801 } |
1802 int32_t CPDF_TextPage::GetTextObjectWritingMode( | 1802 int32_t CPDF_TextPage::GetTextObjectWritingMode( |
1803 const CPDF_TextObject* pTextObj) { | 1803 const CPDF_TextObject* pTextObj) { |
1804 int32_t nChars = pTextObj->CountChars(); | 1804 int32_t nChars = pTextObj->CountChars(); |
1805 if (nChars == 1) { | 1805 if (nChars == 1) { |
1806 return m_TextlineDir; | 1806 return m_TextlineDir; |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2776 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { | 2776 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { |
2777 return; | 2777 return; |
2778 } | 2778 } |
2779 CPDF_LinkExt* link = NULL; | 2779 CPDF_LinkExt* link = NULL; |
2780 link = m_LinkList.GetAt(index); | 2780 link = m_LinkList.GetAt(index); |
2781 if (!link) { | 2781 if (!link) { |
2782 return; | 2782 return; |
2783 } | 2783 } |
2784 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); | 2784 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
2785 } | 2785 } |
OLD | NEW |