diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-11-25 12:15:38 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-11-25 12:15:38 -0800 |
commit | 5c4c193fd4b6dd0657abf5e74125f9887f91d720 (patch) | |
tree | 976cfb53dd2580eff58fb02556d1828fff12659d /core/src/fpdftext | |
parent | 8b90ee66872aa883fc46ac2b6e7acad35c7c96c6 (diff) | |
download | pdfium-5c4c193fd4b6dd0657abf5e74125f9887f91d720.tar.xz |
Inflict PPDF_ENABLE_XFA ifdefs on XFA core/
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1471323004 .
Diffstat (limited to 'core/src/fpdftext')
-rw-r--r-- | core/src/fpdftext/fpdf_text_int.cpp | 69 | ||||
-rw-r--r-- | core/src/fpdftext/text_int.h | 6 |
2 files changed, 75 insertions, 0 deletions
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index 3342f38da9..c69ffc8ee8 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -1525,6 +1525,10 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { int nItems = pTextObj->CountItems(); FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); +#ifndef PDF_ENABLE_XFA + const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); + const FX_BOOL bIsBidiAndMirrorInverse = +#else FX_BOOL bIsBidiAndMirrosInverse = FALSE; CFX_BidiChar* BidiChar = new CFX_BidiChar; int32_t nR2L = 0; @@ -1566,6 +1570,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { bR2L = TRUE; } bIsBidiAndMirrosInverse = +#endif bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; int32_t iBufStartAppend = m_TempTextBuf.GetLength(); int32_t iCharListStartAppend = m_TempCharList.GetSize(); @@ -1724,6 +1729,45 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { } } } +#ifndef PDF_ENABLE_XFA + if (bIsBidiAndMirrorInverse) { + SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); + } +} +void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, + int32_t iBufStartAppend) { + int32_t i, j; + i = iCharListStartAppend; + j = m_TempCharList.GetSize() - 1; + for (; i < j; i++, j--) { + std::swap(m_TempCharList[i], m_TempCharList[j]); + std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); + } + FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); + i = iBufStartAppend; + j = m_TempTextBuf.GetLength() - 1; + for (; i < j; i++, j--) { + std::swap(pTempBuffer[i], pTempBuffer[j]); + } +} +FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, + const CPDF_Font* pFont, + int nItems) const { + nonstd::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); + int32_t nR2L = 0; + int32_t nL2R = 0; + int32_t start = 0, count = 0; + CPDF_TextObjectItem item; + for (int32_t i = 0; i < nItems; i++) { + pTextObj->GetItemInfo(i, &item); + if (item.m_CharCode == (FX_DWORD)-1) { + continue; + } + CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); + FX_WCHAR wChar = wstrItem.GetAt(0); + if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { + wChar = (FX_WCHAR)item.m_CharCode; +#else if (bIsBidiAndMirrosInverse) { int32_t i, j; i = iCharListStartAppend; @@ -1731,14 +1775,39 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { for (; i < j; i++, j--) { std::swap(m_TempCharList[i], m_TempCharList[j]); std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); +#endif + } +#ifndef PDF_ENABLE_XFA + if (!wChar) { + continue; + } + if (pBidiChar->AppendChar(wChar)) { + CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); + if (ret == CFX_BidiChar::RIGHT) { + nR2L++; + } else if (ret == CFX_BidiChar::LEFT) { + nL2R++; + } } + } + if (pBidiChar->EndChar()) { + CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); + if (ret == CFX_BidiChar::RIGHT) { + nR2L++; + } else if (ret == CFX_BidiChar::LEFT) { + nL2R++; +#else FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); i = iBufStartAppend; j = m_TempTextBuf.GetLength() - 1; for (; i < j; i++, j--) { std::swap(pTempBuffer[i], pTempBuffer[j]); +#endif } } +#ifndef PDF_ENABLE_XFA + return (nR2L > 0 && nR2L >= nL2R); +#endif } int32_t CPDF_TextPage::GetTextObjectWritingMode( const CPDF_TextObject* pTextObj) { diff --git a/core/src/fpdftext/text_int.h b/core/src/fpdftext/text_int.h index da4bf70ad1..d8e79b9610 100644 --- a/core/src/fpdftext/text_int.h +++ b/core/src/fpdftext/text_int.h @@ -125,6 +125,12 @@ class CPDF_TextPage : public IPDF_TextPage { void AddCharInfoByRLDirection(CFX_WideString& str, int i); int32_t GetTextObjectWritingMode(const CPDF_TextObject* pTextObj); int32_t FindTextlineFlowDirection(); +#ifndef PDF_ENABLE_XFA + void SwapTempTextBuf(int32_t iCharListStartAppend, int32_t iBufStartAppend); + FX_BOOL IsRightToLeft(const CPDF_TextObject* pTextObj, + const CPDF_Font* pFont, + int nItems) const; +#endif CPDFText_ParseOptions m_ParseOptions; CFX_WordArray m_CharIndex; |