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 de4c703a042635d2c195443ac9c1e3398e05dbb7..5b174f0187bf523fe77675d86854f0856b4e25ae 100644 |
--- a/core/src/fpdftext/fpdf_text_int.cpp |
+++ b/core/src/fpdftext/fpdf_text_int.cpp |
@@ -1682,6 +1682,53 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) |
baseSpace = 0.0; |
} |
} |
+ |
+ FX_BOOL bIsBidiAndMirrosInverse = FALSE; |
jbreiden
2014/08/18 19:10:50
What does MirrosInverse mean?
|
+ IFX_BidiChar* BidiChar = IFX_BidiChar::Create(); |
+ FX_INT32 nR2L = 0; |
+ FX_INT32 nL2R = 0; |
+ FX_INT32 start = 0, count = 0; |
+ CPDF_TextObjectItem item; |
+ for (FX_INT32 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) { |
jbreiden
2014/08/18 19:10:49
Same question. Is the character to Unicode mapping
Bo Xu
2014/08/19 03:31:49
Yes, in CFX_WideString CPDF_Font::UnicodeFromCharC
jbreiden
2014/08/22 16:58:44
Okay. If I understand correctly:
The PDF files I
|
+ wChar = (FX_WCHAR)item.m_CharCode; |
+ } |
+ if (!wChar) { |
+ continue; |
+ } |
+ if (BidiChar && BidiChar->AppendChar(wChar)) { |
+ FX_INT32 ret = BidiChar->GetBidiInfo(start, count); |
+ if (ret == 2) { |
+ nR2L++; |
+ } |
+ else if (ret == 1) { |
+ nL2R++; |
+ } |
+ } |
+ } |
+ if (BidiChar && BidiChar->EndChar()) { |
+ FX_INT32 ret = BidiChar->GetBidiInfo(start, count); |
+ if (ret == 2) { |
+ nR2L++; |
+ } |
+ else if (ret == 1) { |
+ nL2R++; |
+ } |
+ } |
+ FX_BOOL bR2L = FALSE; |
+ if (nR2L > 0 && nR2L >= nL2R) { |
+ bR2L = TRUE; |
+ } |
+ bIsBidiAndMirrosInverse = bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; |
+ FX_INT32 iBufStartAppend = m_TempTextBuf.GetLength(); |
+ FX_INT32 iCharListStartAppend = m_TempCharList.GetSize(); |
+ |
for (int i = 0; i < nItems; i++) { |
CPDF_TextObjectItem item; |
PAGECHAR_INFO charinfo; |
@@ -1828,6 +1875,30 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) |
} |
} |
} |
+ if (bIsBidiAndMirrosInverse) { |
jbreiden
2014/08/18 19:10:50
Ok, I see what is going on here. The code is rever
Bo Xu
2014/08/19 03:31:49
I wonder do you generate this particular pdf file?
jbreiden
2014/08/22 16:58:44
The PDF file is generated by Tesseract, which is a
|
+ FX_INT32 i, j; |
+ i = iCharListStartAppend; |
+ j = m_TempCharList.GetSize() - 1; |
+ PAGECHAR_INFO tempCharInfo; |
+ FX_INT32 tempIndex = 0; |
+ for (; i < j; i++, j--) { |
+ tempCharInfo = m_TempCharList[i]; |
+ m_TempCharList[i] = m_TempCharList[j]; |
+ m_TempCharList[j] = tempCharInfo; |
+ tempIndex = m_TempCharList[i].m_Index; |
+ m_TempCharList[i].m_Index = m_TempCharList[j].m_Index; |
+ m_TempCharList[j].m_Index = tempIndex; |
+ } |
+ FX_WCHAR * pTempBuffer = m_TempTextBuf.GetBuffer(); |
+ i = iBufStartAppend; |
+ j = m_TempTextBuf.GetLength() - 1; |
+ FX_WCHAR wTemp; |
+ for (; i < j; i++, j--) { |
+ wTemp = pTempBuffer[i]; |
+ pTempBuffer[i] = pTempBuffer[j]; |
+ pTempBuffer[j] = wTemp; |
+ } |
+ } |
} |
FX_INT32 CPDF_TextPage::GetTextObjectWritingMode(const CPDF_TextObject* pTextObj) |
{ |