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" |
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 FX_RECT BBox; | 1136 FX_RECT BBox; |
1137 pFont->GetCharBBox(charCode, BBox); | 1137 pFont->GetCharBBox(charCode, BBox); |
1138 w = BBox.right - BBox.left; | 1138 w = BBox.right - BBox.left; |
1139 } | 1139 } |
1140 } | 1140 } |
1141 return w; | 1141 return w; |
1142 } | 1142 } |
1143 void CPDF_TextPage::OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str) | 1143 void CPDF_TextPage::OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str) |
1144 { | 1144 { |
1145 int32_t start, count; | 1145 int32_t start, count; |
1146 int32_t ret = pBidi->GetBidiInfo(start, count); | 1146 IFX_BidiChar::Direction ret = pBidi->GetBidiInfo(&start, &count); |
1147 if(ret == 2) { | 1147 if (ret == IFX_BidiChar::RIGHT) { |
1148 for(int i = start + count - 1; i >= start; i--) { | 1148 for(int i = start + count - 1; i >= start; i--) { |
1149 m_TextBuf.AppendChar(str.GetAt(i)); | 1149 m_TextBuf.AppendChar(str.GetAt(i)); |
1150 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); | 1150 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); |
1151 } | 1151 } |
1152 } else { | 1152 } else { |
1153 int end = start + count ; | 1153 int end = start + count ; |
1154 for(int i = start; i < end; i++) { | 1154 for(int i = start; i < end; i++) { |
1155 m_TextBuf.AppendChar(str.GetAt(i)); | 1155 m_TextBuf.AppendChar(str.GetAt(i)); |
1156 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); | 1156 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); |
1157 } | 1157 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 str.Delete(i); | 1244 str.Delete(i); |
1245 count1--; | 1245 count1--; |
1246 i--; | 1246 i--; |
1247 continue; | 1247 continue; |
1248 } | 1248 } |
1249 bPrevSpace = TRUE; | 1249 bPrevSpace = TRUE; |
1250 } else { | 1250 } else { |
1251 bPrevSpace = FALSE; | 1251 bPrevSpace = FALSE; |
1252 } | 1252 } |
1253 if(pBidiChar->AppendChar(str.GetAt(i))) { | 1253 if(pBidiChar->AppendChar(str.GetAt(i))) { |
1254 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1254 IFX_BidiChar::Direction ret = |
| 1255 pBidiChar->GetBidiInfo(&start, &count); |
1255 order.Add(start); | 1256 order.Add(start); |
1256 order.Add(count); | 1257 order.Add(count); |
1257 order.Add(ret); | 1258 order.Add(ret); |
1258 if(!bR2L) { | 1259 if(!bR2L) { |
1259 if(ret == 2) { | 1260 if (ret == IFX_BidiChar::RIGHT) { |
1260 nR2L++; | 1261 nR2L++; |
1261 } else if (ret == 1) { | 1262 } else if (ret == IFX_BidiChar::LEFT) { |
1262 nL2R++; | 1263 nL2R++; |
1263 } | 1264 } |
1264 } | 1265 } |
1265 } | 1266 } |
1266 } | 1267 } |
1267 if(pBidiChar->EndChar()) { | 1268 if(pBidiChar->EndChar()) { |
1268 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1269 IFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
1269 order.Add(start); | 1270 order.Add(start); |
1270 order.Add(count); | 1271 order.Add(count); |
1271 order.Add(ret); | 1272 order.Add(ret); |
1272 if(!bR2L) { | 1273 if(!bR2L) { |
1273 if(ret == 2) { | 1274 if (ret == IFX_BidiChar::RIGHT) { |
1274 nR2L++; | 1275 nR2L++; |
1275 } else if(ret == 1) { | 1276 } else if (ret == IFX_BidiChar::LEFT) { |
1276 nL2R++; | 1277 nL2R++; |
1277 } | 1278 } |
1278 } | 1279 } |
1279 } | 1280 } |
1280 if(nR2L > 0 && nR2L >= nL2R) { | 1281 if(nR2L > 0 && nR2L >= nL2R) { |
1281 bR2L = TRUE; | 1282 bR2L = TRUE; |
1282 } | 1283 } |
1283 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { | 1284 if (m_parserflag == FPDFTEXT_RLTB || bR2L) { |
1284 int count = order.GetSize(); | 1285 int count = order.GetSize(); |
1285 for(int i = count - 1; i > 0; i -= 3) { | 1286 for(int i = count - 1; i > 0; i -= 3) { |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 std::swap(pTempBuffer[i], pTempBuffer[j]); | 1851 std::swap(pTempBuffer[i], pTempBuffer[j]); |
1851 } | 1852 } |
1852 } | 1853 } |
1853 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, | 1854 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
1854 const CPDF_Font* pFont, | 1855 const CPDF_Font* pFont, |
1855 int nItems) const | 1856 int nItems) const |
1856 { | 1857 { |
1857 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); | 1858 nonstd::unique_ptr<IFX_BidiChar> pBidiChar(IFX_BidiChar::Create()); |
1858 int32_t nR2L = 0; | 1859 int32_t nR2L = 0; |
1859 int32_t nL2R = 0; | 1860 int32_t nL2R = 0; |
1860 int32_t start = 0, count = 0; | |
1861 CPDF_TextObjectItem item; | 1861 CPDF_TextObjectItem item; |
1862 for (int32_t i = 0; i < nItems; i++) { | 1862 for (int32_t i = 0; i < nItems; i++) { |
1863 pTextObj->GetItemInfo(i, &item); | 1863 pTextObj->GetItemInfo(i, &item); |
1864 if (item.m_CharCode == (FX_DWORD)-1) { | 1864 if (item.m_CharCode == (FX_DWORD)-1) { |
1865 continue; | 1865 continue; |
1866 } | 1866 } |
1867 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | 1867 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); |
1868 FX_WCHAR wChar = wstrItem.GetAt(0); | 1868 FX_WCHAR wChar = wstrItem.GetAt(0); |
1869 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | 1869 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { |
1870 wChar = (FX_WCHAR)item.m_CharCode; | 1870 wChar = (FX_WCHAR)item.m_CharCode; |
1871 } | 1871 } |
1872 if (!wChar) { | 1872 if (!wChar) { |
1873 continue; | 1873 continue; |
1874 } | 1874 } |
1875 if (pBidiChar->AppendChar(wChar)) { | 1875 if (pBidiChar->AppendChar(wChar)) { |
1876 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1876 IFX_BidiChar::Direction ret = |
1877 if (ret == 2) { | 1877 pBidiChar->GetBidiInfo(nullptr, nullptr); |
| 1878 if (ret == IFX_BidiChar::RIGHT) { |
1878 nR2L++; | 1879 nR2L++; |
1879 } | 1880 } else if (ret == IFX_BidiChar::LEFT) { |
1880 else if (ret == 1) { | |
1881 nL2R++; | 1881 nL2R++; |
1882 } | 1882 } |
1883 } | 1883 } |
1884 } | 1884 } |
1885 if (pBidiChar->EndChar()) { | 1885 if (pBidiChar->EndChar()) { |
1886 int32_t ret = pBidiChar->GetBidiInfo(start, count); | 1886 IFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(nullptr, nullptr); |
1887 if (ret == 2) { | 1887 if (ret == IFX_BidiChar::RIGHT) { |
1888 nR2L++; | 1888 nR2L++; |
1889 } | 1889 } else if (ret == IFX_BidiChar::LEFT) { |
1890 else if (ret == 1) { | |
1891 nL2R++; | 1890 nL2R++; |
1892 } | 1891 } |
1893 } | 1892 } |
1894 return (nR2L > 0 && nR2L >= nL2R); | 1893 return (nR2L > 0 && nR2L >= nL2R); |
1895 } | 1894 } |
1896 int32_t CPDF_TextPage::GetTextObjectWritingMode(const CPDF_TextObject* pTextObj) | 1895 int32_t CPDF_TextPage::GetTextObjectWritingMode(const CPDF_TextObject* pTextObj) |
1897 { | 1896 { |
1898 int32_t nChars = pTextObj->CountChars(); | 1897 int32_t nChars = pTextObj->CountChars(); |
1899 if (nChars == 1) { | 1898 if (nChars == 1) { |
1900 return m_TextlineDir; | 1899 return m_TextlineDir; |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2832 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { | 2831 if (!m_IsParserd || index < 0 || index >= m_LinkList.GetSize()) { |
2833 return; | 2832 return; |
2834 } | 2833 } |
2835 CPDF_LinkExt* link = NULL; | 2834 CPDF_LinkExt* link = NULL; |
2836 link = m_LinkList.GetAt(index); | 2835 link = m_LinkList.GetAt(index); |
2837 if (!link) { | 2836 if (!link) { |
2838 return ; | 2837 return ; |
2839 } | 2838 } |
2840 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); | 2839 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
2841 } | 2840 } |
OLD | NEW |