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 <cctype> | 7 #include <cctype> |
8 #include <cwctype> | 8 #include <cwctype> |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 if (m_TempCharList.GetSize() >= 1) { | 1414 if (m_TempCharList.GetSize() >= 1) { |
1415 preChar = | 1415 preChar = |
1416 *(PAGECHAR_INFO*)m_TempCharList.GetAt(m_TempCharList.GetSize() - 1); | 1416 *(PAGECHAR_INFO*)m_TempCharList.GetAt(m_TempCharList.GetSize() - 1); |
1417 } else { | 1417 } else { |
1418 preChar = *(PAGECHAR_INFO*)m_charList.GetAt(m_charList.GetSize() - 1); | 1418 preChar = *(PAGECHAR_INFO*)m_charList.GetAt(m_charList.GetSize() - 1); |
1419 } | 1419 } |
1420 if (preChar.m_pTextObj) { | 1420 if (preChar.m_pTextObj) { |
1421 m_pPreTextObj = preChar.m_pTextObj; | 1421 m_pPreTextObj = preChar.m_pTextObj; |
1422 } | 1422 } |
1423 } | 1423 } |
| 1424 void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, |
| 1425 int32_t iBufStartAppend) { |
| 1426 int32_t i, j; |
| 1427 i = iCharListStartAppend; |
| 1428 j = m_TempCharList.GetSize() - 1; |
| 1429 for (; i < j; i++, j--) { |
| 1430 std::swap(m_TempCharList[i], m_TempCharList[j]); |
| 1431 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); |
| 1432 } |
| 1433 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); |
| 1434 i = iBufStartAppend; |
| 1435 j = m_TempTextBuf.GetLength() - 1; |
| 1436 for (; i < j; i++, j--) { |
| 1437 std::swap(pTempBuffer[i], pTempBuffer[j]); |
| 1438 } |
| 1439 } |
| 1440 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
| 1441 const CPDF_Font* pFont, |
| 1442 int nItems) const { |
| 1443 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
| 1444 int32_t nR2L = 0; |
| 1445 int32_t nL2R = 0; |
| 1446 int32_t start = 0, count = 0; |
| 1447 CPDF_TextObjectItem item; |
| 1448 for (int32_t i = 0; i < nItems; i++) { |
| 1449 pTextObj->GetItemInfo(i, &item); |
| 1450 if (item.m_CharCode == (FX_DWORD)-1) { |
| 1451 continue; |
| 1452 } |
| 1453 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); |
| 1454 FX_WCHAR wChar = wstrItem.GetAt(0); |
| 1455 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { |
| 1456 wChar = (FX_WCHAR)item.m_CharCode; |
| 1457 } |
| 1458 if (!wChar) { |
| 1459 continue; |
| 1460 } |
| 1461 if (pBidiChar->AppendChar(wChar)) { |
| 1462 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
| 1463 if (ret == CFX_BidiChar::RIGHT) { |
| 1464 nR2L++; |
| 1465 } else if (ret == CFX_BidiChar::LEFT) { |
| 1466 nL2R++; |
| 1467 } |
| 1468 } |
| 1469 } |
| 1470 if (pBidiChar->EndChar()) { |
| 1471 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
| 1472 if (ret == CFX_BidiChar::RIGHT) { |
| 1473 nR2L++; |
| 1474 } else if (ret == CFX_BidiChar::LEFT) { |
| 1475 nL2R++; |
| 1476 } |
| 1477 } |
| 1478 return (nR2L > 0 && nR2L >= nL2R); |
| 1479 } |
1424 void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { | 1480 void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
1425 CPDF_TextObject* pTextObj = Obj.m_pTextObj; | 1481 CPDF_TextObject* pTextObj = Obj.m_pTextObj; |
1426 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) { | 1482 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) { |
1427 return; | 1483 return; |
1428 } | 1484 } |
1429 CFX_AffineMatrix formMatrix = Obj.m_formMatrix; | 1485 CFX_AffineMatrix formMatrix = Obj.m_formMatrix; |
1430 CPDF_Font* pFont = pTextObj->GetFont(); | 1486 CPDF_Font* pFont = pTextObj->GetFont(); |
1431 CFX_AffineMatrix matrix; | 1487 CFX_AffineMatrix matrix; |
1432 pTextObj->GetTextMatrix(&matrix); | 1488 pTextObj->GetTextMatrix(&matrix); |
1433 matrix.Concat(formMatrix); | 1489 matrix.Concat(formMatrix); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 ProcessMarkedContent(Obj); | 1574 ProcessMarkedContent(Obj); |
1519 m_pPreTextObj = pTextObj; | 1575 m_pPreTextObj = pTextObj; |
1520 m_perMatrix.Copy(formMatrix); | 1576 m_perMatrix.Copy(formMatrix); |
1521 return; | 1577 return; |
1522 } | 1578 } |
1523 m_pPreTextObj = pTextObj; | 1579 m_pPreTextObj = pTextObj; |
1524 m_perMatrix.Copy(formMatrix); | 1580 m_perMatrix.Copy(formMatrix); |
1525 int nItems = pTextObj->CountItems(); | 1581 int nItems = pTextObj->CountItems(); |
1526 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); | 1582 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); |
1527 | 1583 |
1528 #ifndef PDF_ENABLE_XFA | |
1529 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); | 1584 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); |
1530 const FX_BOOL bIsBidiAndMirrorInverse = | 1585 const FX_BOOL bIsBidiAndMirrorInverse = |
1531 #else | |
1532 FX_BOOL bIsBidiAndMirrosInverse = FALSE; | |
1533 CFX_BidiChar* BidiChar = new CFX_BidiChar; | |
1534 int32_t nR2L = 0; | |
1535 int32_t nL2R = 0; | |
1536 int32_t start = 0, count = 0; | |
1537 CPDF_TextObjectItem item; | |
1538 for (int32_t i = 0; i < nItems; i++) { | |
1539 pTextObj->GetItemInfo(i, &item); | |
1540 if (item.m_CharCode == (FX_DWORD)-1) { | |
1541 continue; | |
1542 } | |
1543 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | |
1544 FX_WCHAR wChar = wstrItem.GetAt(0); | |
1545 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | |
1546 wChar = (FX_WCHAR)item.m_CharCode; | |
1547 } | |
1548 if (!wChar) { | |
1549 continue; | |
1550 } | |
1551 if (BidiChar && BidiChar->AppendChar(wChar)) { | |
1552 CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count); | |
1553 if (ret == CFX_BidiChar::RIGHT) { | |
1554 nR2L++; | |
1555 } else if (ret == CFX_BidiChar::LEFT) { | |
1556 nL2R++; | |
1557 } | |
1558 } | |
1559 } | |
1560 if (BidiChar && BidiChar->EndChar()) { | |
1561 CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count); | |
1562 if (ret == CFX_BidiChar::RIGHT) { | |
1563 nR2L++; | |
1564 } else if (ret == CFX_BidiChar::LEFT) { | |
1565 nL2R++; | |
1566 } | |
1567 } | |
1568 FX_BOOL bR2L = FALSE; | |
1569 if (nR2L > 0 && nR2L >= nL2R) { | |
1570 bR2L = TRUE; | |
1571 } | |
1572 bIsBidiAndMirrosInverse = | |
1573 #endif | |
1574 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; | 1586 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; |
1575 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); | 1587 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); |
1576 int32_t iCharListStartAppend = m_TempCharList.GetSize(); | 1588 int32_t iCharListStartAppend = m_TempCharList.GetSize(); |
1577 | 1589 |
1578 FX_FLOAT spacing = 0; | 1590 FX_FLOAT spacing = 0; |
1579 for (int i = 0; i < nItems; i++) { | 1591 for (int i = 0; i < nItems; i++) { |
1580 CPDF_TextObjectItem item; | 1592 CPDF_TextObjectItem item; |
1581 PAGECHAR_INFO charinfo; | 1593 PAGECHAR_INFO charinfo; |
1582 charinfo.m_OriginX = 0; | 1594 charinfo.m_OriginX = 0; |
1583 charinfo.m_OriginY = 0; | 1595 charinfo.m_OriginY = 0; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 } else if (i == 0) { | 1734 } else if (i == 0) { |
1723 CFX_WideString str = m_TempTextBuf.GetWideString(); | 1735 CFX_WideString str = m_TempTextBuf.GetWideString(); |
1724 if (!str.IsEmpty() && | 1736 if (!str.IsEmpty() && |
1725 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { | 1737 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { |
1726 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); | 1738 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
1727 m_TempCharList.Delete(m_TempCharList.GetSize() - 1); | 1739 m_TempCharList.Delete(m_TempCharList.GetSize() - 1); |
1728 } | 1740 } |
1729 } | 1741 } |
1730 } | 1742 } |
1731 } | 1743 } |
1732 #ifndef PDF_ENABLE_XFA | |
1733 if (bIsBidiAndMirrorInverse) { | 1744 if (bIsBidiAndMirrorInverse) { |
1734 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); | 1745 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); |
1735 } | 1746 } |
1736 } | 1747 } |
1737 void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, | |
1738 int32_t iBufStartAppend) { | |
1739 int32_t i, j; | |
1740 i = iCharListStartAppend; | |
1741 j = m_TempCharList.GetSize() - 1; | |
1742 for (; i < j; i++, j--) { | |
1743 std::swap(m_TempCharList[i], m_TempCharList[j]); | |
1744 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); | |
1745 } | |
1746 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); | |
1747 i = iBufStartAppend; | |
1748 j = m_TempTextBuf.GetLength() - 1; | |
1749 for (; i < j; i++, j--) { | |
1750 std::swap(pTempBuffer[i], pTempBuffer[j]); | |
1751 } | |
1752 } | |
1753 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, | |
1754 const CPDF_Font* pFont, | |
1755 int nItems) const { | |
1756 nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); | |
1757 int32_t nR2L = 0; | |
1758 int32_t nL2R = 0; | |
1759 int32_t start = 0, count = 0; | |
1760 CPDF_TextObjectItem item; | |
1761 for (int32_t i = 0; i < nItems; i++) { | |
1762 pTextObj->GetItemInfo(i, &item); | |
1763 if (item.m_CharCode == (FX_DWORD)-1) { | |
1764 continue; | |
1765 } | |
1766 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); | |
1767 FX_WCHAR wChar = wstrItem.GetAt(0); | |
1768 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { | |
1769 wChar = (FX_WCHAR)item.m_CharCode; | |
1770 #else | |
1771 if (bIsBidiAndMirrosInverse) { | |
1772 int32_t i, j; | |
1773 i = iCharListStartAppend; | |
1774 j = m_TempCharList.GetSize() - 1; | |
1775 for (; i < j; i++, j--) { | |
1776 std::swap(m_TempCharList[i], m_TempCharList[j]); | |
1777 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); | |
1778 #endif | |
1779 } | |
1780 #ifndef PDF_ENABLE_XFA | |
1781 if (!wChar) { | |
1782 continue; | |
1783 } | |
1784 if (pBidiChar->AppendChar(wChar)) { | |
1785 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); | |
1786 if (ret == CFX_BidiChar::RIGHT) { | |
1787 nR2L++; | |
1788 } else if (ret == CFX_BidiChar::LEFT) { | |
1789 nL2R++; | |
1790 } | |
1791 } | |
1792 } | |
1793 if (pBidiChar->EndChar()) { | |
1794 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); | |
1795 if (ret == CFX_BidiChar::RIGHT) { | |
1796 nR2L++; | |
1797 } else if (ret == CFX_BidiChar::LEFT) { | |
1798 nL2R++; | |
1799 #else | |
1800 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); | |
1801 i = iBufStartAppend; | |
1802 j = m_TempTextBuf.GetLength() - 1; | |
1803 for (; i < j; i++, j--) { | |
1804 std::swap(pTempBuffer[i], pTempBuffer[j]); | |
1805 #endif | |
1806 } | |
1807 } | |
1808 #ifndef PDF_ENABLE_XFA | |
1809 return (nR2L > 0 && nR2L >= nL2R); | |
1810 #endif | |
1811 } | |
1812 int32_t CPDF_TextPage::GetTextObjectWritingMode( | 1748 int32_t CPDF_TextPage::GetTextObjectWritingMode( |
1813 const CPDF_TextObject* pTextObj) { | 1749 const CPDF_TextObject* pTextObj) { |
1814 int32_t nChars = pTextObj->CountChars(); | 1750 int32_t nChars = pTextObj->CountChars(); |
1815 if (nChars == 1) { | 1751 if (nChars == 1) { |
1816 return m_TextlineDir; | 1752 return m_TextlineDir; |
1817 } | 1753 } |
1818 CPDF_TextObjectItem first, last; | 1754 CPDF_TextObjectItem first, last; |
1819 pTextObj->GetCharInfo(0, &first); | 1755 pTextObj->GetCharInfo(0, &first); |
1820 pTextObj->GetCharInfo(nChars - 1, &last); | 1756 pTextObj->GetCharInfo(nChars - 1, &last); |
1821 CFX_Matrix textMatrix; | 1757 CFX_Matrix textMatrix; |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2790 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { | 2726 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { |
2791 return; | 2727 return; |
2792 } | 2728 } |
2793 CPDF_LinkExt* link = NULL; | 2729 CPDF_LinkExt* link = NULL; |
2794 link = m_LinkList.GetAt(index); | 2730 link = m_LinkList.GetAt(index); |
2795 if (!link) { | 2731 if (!link) { |
2796 return; | 2732 return; |
2797 } | 2733 } |
2798 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); | 2734 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
2799 } | 2735 } |
OLD | NEW |