Index: core/src/fpdftext/fpdf_text_int.cpp |
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp |
index 9ab09e19e44dab52fd3a2779ed6d525d95cfa4ae..84bbceef17d2f3c20eb1c89d867f57061fb0ceaf 100644 |
--- a/core/src/fpdftext/fpdf_text_int.cpp |
+++ b/core/src/fpdftext/fpdf_text_int.cpp |
@@ -81,21 +81,40 @@ CPDFText_ParseOptions::CPDFText_ParseOptions() |
: m_bGetCharCodeOnly(FALSE), |
m_bNormalizeObjs(TRUE), |
m_bOutputHyphen(FALSE) {} |
+#ifndef PDF_ENABLE_XFA |
+#else |
+IPDF_TextPage* IPDF_TextPage::CreateTextPage( |
+ const CPDF_Page* pPage, |
+ CPDFText_ParseOptions ParserOptions) { |
+ return new CPDF_TextPage(pPage, ParserOptions); |
+} |
+#endif |
IPDF_TextPage* IPDF_TextPage::CreateTextPage(const CPDF_Page* pPage, |
int flags) { |
return new CPDF_TextPage(pPage, flags); |
} |
+#ifndef PDF_ENABLE_XFA |
+#else |
+IPDF_TextPage* IPDF_TextPage::CreateTextPage(const CPDF_PageObjects* pObjs, |
+ int flags) { |
+ return new CPDF_TextPage(pObjs, flags); |
+} |
+#endif |
IPDF_TextPageFind* IPDF_TextPageFind::CreatePageFind( |
const IPDF_TextPage* pTextPage) { |
return pTextPage ? new CPDF_TextPageFind(pTextPage) : nullptr; |
} |
+#ifndef PDF_ENABLE_XFA |
+#endif |
IPDF_LinkExtract* IPDF_LinkExtract::CreateLinkExtract() { |
return new CPDF_LinkExtract(); |
} |
+#ifndef PDF_ENABLE_XFA |
+#endif |
#define TEXT_BLANK_CHAR L' ' |
#define TEXT_LINEFEED_CHAR L'\n' |
#define TEXT_RETURN_CHAR L'\r' |
@@ -119,6 +138,37 @@ CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, int flags) |
(int)pPage->GetPageHeight(), 0); |
} |
+#ifdef PDF_ENABLE_XFA |
+CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, |
+ CPDFText_ParseOptions ParserOptions) |
+ : m_ParseOptions(ParserOptions), |
+ m_pPage(pPage), |
+ m_charList(512), |
+ m_TempCharList(50), |
+ m_parserflag(0), |
+ m_pPreTextObj(nullptr), |
+ m_bIsParsed(false), |
+ m_TextlineDir(-1), |
+ m_CurlineRect(0, 0, 0, 0) { |
+ m_TextBuf.EstimateSize(0, 10240); |
+ pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int)pPage->GetPageWidth(), |
+ (int)pPage->GetPageHeight(), 0); |
+} |
+ |
+CPDF_TextPage::CPDF_TextPage(const CPDF_PageObjects* pPage, int flags) |
+ : m_pPage(pPage), |
+ m_charList(512), |
+ m_TempCharList(50), |
+ m_parserflag(flags), |
+ m_pPreTextObj(nullptr), |
+ m_bIsParsed(false), |
+ m_TextlineDir(-1), |
+ m_CurlineRect(0, 0, 0, 0) { |
+ m_TextBuf.EstimateSize(0, 10240); |
+ CFX_FloatRect pageRect = pPage->CalcBoundingBox(); |
+ m_DisplayMatrix = CFX_AffineMatrix(1, 0, 0, -1, pageRect.right, pageRect.top); |
+} |
+#endif |
void CPDF_TextPage::NormalizeObjects(FX_BOOL bNormalize) { |
m_ParseOptions.m_bNormalizeObjs = bNormalize; |
} |
@@ -1356,6 +1406,9 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { |
for (n = 0; n < nContentMark; n++) { |
CPDF_ContentMarkItem& item = pMarkData->GetItem(n); |
CFX_ByteString tagStr = (CFX_ByteString)item.GetName(); |
+#ifdef PDF_ENABLE_XFA |
+ |
+#endif |
pDict = ToDictionary(static_cast<CPDF_Object*>(item.GetParam())); |
CPDF_String* temp = |
ToString(pDict ? pDict->GetElement(FX_BSTRC("ActualText")) : nullptr); |
@@ -1524,8 +1577,52 @@ 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; |
Lei Zhang
2015/10/30 06:15:30
Weird that this file has this discrepancy.
|
+ CFX_BidiChar* BidiChar = 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; |
+ } |
+ if (!wChar) { |
+ continue; |
+ } |
+ if (BidiChar && BidiChar->AppendChar(wChar)) { |
+ CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count); |
+ if (ret == CFX_BidiChar::RIGHT) { |
+ nR2L++; |
+ } else if (ret == CFX_BidiChar::LEFT) { |
+ nL2R++; |
+ } |
+ } |
+ } |
+ if (BidiChar && BidiChar->EndChar()) { |
+ CFX_BidiChar::Direction ret = BidiChar->GetBidiInfo(&start, &count); |
+ if (ret == CFX_BidiChar::RIGHT) { |
+ nR2L++; |
+ } else if (ret == CFX_BidiChar::LEFT) { |
+ nL2R++; |
+ } |
+ } |
+ FX_BOOL bR2L = FALSE; |
+ if (nR2L > 0 && nR2L >= nL2R) { |
+ 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(); |
@@ -1684,6 +1781,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
} |
} |
} |
+#ifndef PDF_ENABLE_XFA |
if (bIsBidiAndMirrorInverse) { |
SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); |
} |
@@ -1732,7 +1830,17 @@ FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
} else if (ret == CFX_BidiChar::LEFT) { |
nL2R++; |
} |
+#else |
+ if (bIsBidiAndMirrosInverse) { |
+ 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); |
+#endif |
} |
+#ifndef PDF_ENABLE_XFA |
} |
if (pBidiChar->EndChar()) { |
CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); |
@@ -1740,9 +1848,18 @@ FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, |
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) { |