Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: core/src/fpdftext/fpdf_text_int.cpp

Issue 1471323004: Inflict PPDF_ENABLE_XFA ifdefs on XFA core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 ProcessMarkedContent(Obj); 1518 ProcessMarkedContent(Obj);
1519 m_pPreTextObj = pTextObj; 1519 m_pPreTextObj = pTextObj;
1520 m_perMatrix.Copy(formMatrix); 1520 m_perMatrix.Copy(formMatrix);
1521 return; 1521 return;
1522 } 1522 }
1523 m_pPreTextObj = pTextObj; 1523 m_pPreTextObj = pTextObj;
1524 m_perMatrix.Copy(formMatrix); 1524 m_perMatrix.Copy(formMatrix);
1525 int nItems = pTextObj->CountItems(); 1525 int nItems = pTextObj->CountItems();
1526 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); 1526 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix);
1527 1527
1528 #ifndef PDF_ENABLE_XFA
1529 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems);
1530 const FX_BOOL bIsBidiAndMirrorInverse =
1531 #else
1528 FX_BOOL bIsBidiAndMirrosInverse = FALSE; 1532 FX_BOOL bIsBidiAndMirrosInverse = FALSE;
1529 CFX_BidiChar* BidiChar = new CFX_BidiChar; 1533 CFX_BidiChar* BidiChar = new CFX_BidiChar;
1530 int32_t nR2L = 0; 1534 int32_t nR2L = 0;
1531 int32_t nL2R = 0; 1535 int32_t nL2R = 0;
1532 int32_t start = 0, count = 0; 1536 int32_t start = 0, count = 0;
1533 CPDF_TextObjectItem item; 1537 CPDF_TextObjectItem item;
1534 for (int32_t i = 0; i < nItems; i++) { 1538 for (int32_t i = 0; i < nItems; i++) {
1535 pTextObj->GetItemInfo(i, &item); 1539 pTextObj->GetItemInfo(i, &item);
1536 if (item.m_CharCode == (FX_DWORD)-1) { 1540 if (item.m_CharCode == (FX_DWORD)-1) {
1537 continue; 1541 continue;
(...skipping 21 matching lines...) Expand all
1559 nR2L++; 1563 nR2L++;
1560 } else if (ret == CFX_BidiChar::LEFT) { 1564 } else if (ret == CFX_BidiChar::LEFT) {
1561 nL2R++; 1565 nL2R++;
1562 } 1566 }
1563 } 1567 }
1564 FX_BOOL bR2L = FALSE; 1568 FX_BOOL bR2L = FALSE;
1565 if (nR2L > 0 && nR2L >= nL2R) { 1569 if (nR2L > 0 && nR2L >= nL2R) {
1566 bR2L = TRUE; 1570 bR2L = TRUE;
1567 } 1571 }
1568 bIsBidiAndMirrosInverse = 1572 bIsBidiAndMirrosInverse =
1573 #endif
1569 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; 1574 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0;
1570 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); 1575 int32_t iBufStartAppend = m_TempTextBuf.GetLength();
1571 int32_t iCharListStartAppend = m_TempCharList.GetSize(); 1576 int32_t iCharListStartAppend = m_TempCharList.GetSize();
1572 1577
1573 FX_FLOAT spacing = 0; 1578 FX_FLOAT spacing = 0;
1574 for (int i = 0; i < nItems; i++) { 1579 for (int i = 0; i < nItems; i++) {
1575 CPDF_TextObjectItem item; 1580 CPDF_TextObjectItem item;
1576 PAGECHAR_INFO charinfo; 1581 PAGECHAR_INFO charinfo;
1577 charinfo.m_OriginX = 0; 1582 charinfo.m_OriginX = 0;
1578 charinfo.m_OriginY = 0; 1583 charinfo.m_OriginY = 0;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 } else if (i == 0) { 1722 } else if (i == 0) {
1718 CFX_WideString str = m_TempTextBuf.GetWideString(); 1723 CFX_WideString str = m_TempTextBuf.GetWideString();
1719 if (!str.IsEmpty() && 1724 if (!str.IsEmpty() &&
1720 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { 1725 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) {
1721 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1726 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1722 m_TempCharList.Delete(m_TempCharList.GetSize() - 1); 1727 m_TempCharList.Delete(m_TempCharList.GetSize() - 1);
1723 } 1728 }
1724 } 1729 }
1725 } 1730 }
1726 } 1731 }
1732 #ifndef PDF_ENABLE_XFA
1733 if (bIsBidiAndMirrorInverse) {
1734 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend);
1735 }
1736 }
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
1727 if (bIsBidiAndMirrosInverse) { 1771 if (bIsBidiAndMirrosInverse) {
1728 int32_t i, j; 1772 int32_t i, j;
1729 i = iCharListStartAppend; 1773 i = iCharListStartAppend;
1730 j = m_TempCharList.GetSize() - 1; 1774 j = m_TempCharList.GetSize() - 1;
1731 for (; i < j; i++, j--) { 1775 for (; i < j; i++, j--) {
1732 std::swap(m_TempCharList[i], m_TempCharList[j]); 1776 std::swap(m_TempCharList[i], m_TempCharList[j]);
1733 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); 1777 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index);
1778 #endif
1734 } 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
1735 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); 1800 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer();
1736 i = iBufStartAppend; 1801 i = iBufStartAppend;
1737 j = m_TempTextBuf.GetLength() - 1; 1802 j = m_TempTextBuf.GetLength() - 1;
1738 for (; i < j; i++, j--) { 1803 for (; i < j; i++, j--) {
1739 std::swap(pTempBuffer[i], pTempBuffer[j]); 1804 std::swap(pTempBuffer[i], pTempBuffer[j]);
1805 #endif
1740 } 1806 }
1741 } 1807 }
1808 #ifndef PDF_ENABLE_XFA
1809 return (nR2L > 0 && nR2L >= nL2R);
1810 #endif
1742 } 1811 }
1743 int32_t CPDF_TextPage::GetTextObjectWritingMode( 1812 int32_t CPDF_TextPage::GetTextObjectWritingMode(
1744 const CPDF_TextObject* pTextObj) { 1813 const CPDF_TextObject* pTextObj) {
1745 int32_t nChars = pTextObj->CountChars(); 1814 int32_t nChars = pTextObj->CountChars();
1746 if (nChars == 1) { 1815 if (nChars == 1) {
1747 return m_TextlineDir; 1816 return m_TextlineDir;
1748 } 1817 }
1749 CPDF_TextObjectItem first, last; 1818 CPDF_TextObjectItem first, last;
1750 pTextObj->GetCharInfo(0, &first); 1819 pTextObj->GetCharInfo(0, &first);
1751 pTextObj->GetCharInfo(nChars - 1, &last); 1820 pTextObj->GetCharInfo(nChars - 1, &last);
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2790 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2722 return; 2791 return;
2723 } 2792 }
2724 CPDF_LinkExt* link = NULL; 2793 CPDF_LinkExt* link = NULL;
2725 link = m_LinkList.GetAt(index); 2794 link = m_LinkList.GetAt(index);
2726 if (!link) { 2795 if (!link) {
2727 return; 2796 return;
2728 } 2797 }
2729 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2798 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2730 } 2799 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698