diff options
-rw-r--r-- | core/fpdftext/cpdf_textpage.cpp | 92 | ||||
-rw-r--r-- | core/fpdftext/cpdf_textpage.h | 8 |
2 files changed, 45 insertions, 55 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 52b669638c..25b6759c49 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -112,6 +112,49 @@ bool IsHyphenCode(wchar_t c) { return c == 0x2D || c == 0xAD; } +bool IsRectIntersect(const CFX_FloatRect& rect1, const CFX_FloatRect& rect2) { + CFX_FloatRect rect = rect1; + rect.Intersect(rect2); + return !rect.IsEmpty(); +} + +bool IsRightToLeft(const CPDF_TextObject& text_obj, const CPDF_Font& font) { + const size_t nItems = text_obj.CountItems(); + WideString str; + str.Reserve(nItems); + for (size_t i = 0; i < nItems; ++i) { + CPDF_TextObjectItem item; + text_obj.GetItemInfo(i, &item); + if (item.m_CharCode == static_cast<uint32_t>(-1)) + continue; + WideString wstrItem = font.UnicodeFromCharCode(item.m_CharCode); + wchar_t wChar = !wstrItem.IsEmpty() ? wstrItem[0] : 0; + if (wChar == 0) + wChar = item.m_CharCode; + if (wChar) + str += wChar; + } + return CFX_BidiString(str).OverallDirection() == CFX_BidiChar::RIGHT; +} + +uint32_t GetCharWidth(uint32_t charCode, CPDF_Font* pFont) { + if (charCode == CPDF_Font::kInvalidCharCode) + return 0; + + uint32_t w = pFont->GetCharWidthF(charCode); + if (w > 0) + return w; + + ByteString str; + pFont->AppendChar(&str, charCode); + w = pFont->GetStringWidth(str.AsStringView()); + if (w > 0) + return w; + + ASSERT(pFont->GetCharBBox(charCode).Width() >= 0); + return pFont->GetCharBBox(charCode).Width(); +} + } // namespace PDFTEXT_Obj::PDFTEXT_Obj() {} @@ -588,25 +631,6 @@ void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, } } -uint32_t CPDF_TextPage::GetCharWidth(uint32_t charCode, - CPDF_Font* pFont) const { - if (charCode == CPDF_Font::kInvalidCharCode) - return 0; - - uint32_t w = pFont->GetCharWidthF(charCode); - if (w > 0) - return w; - - ByteString str; - pFont->AppendChar(&str, charCode); - w = pFont->GetStringWidth(str.AsStringView()); - if (w > 0) - return w; - - ASSERT(pFont->GetCharBBox(charCode).Width() >= 0); - return pFont->GetCharBBox(charCode).Width(); -} - void CPDF_TextPage::AddCharInfoByLRDirection(wchar_t wChar, const PAGECHAR_INFO& info) { PAGECHAR_INFO info2 = info; @@ -903,25 +927,6 @@ void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, std::swap(pTempBuffer[i], pTempBuffer[j]); } -bool CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, - const CPDF_Font* pFont, - size_t nItems) const { - WideString str; - for (size_t i = 0; i < nItems; ++i) { - CPDF_TextObjectItem item; - pTextObj->GetItemInfo(i, &item); - if (item.m_CharCode == static_cast<uint32_t>(-1)) - continue; - WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); - wchar_t wChar = !wstrItem.IsEmpty() ? wstrItem[0] : 0; - if (wChar == 0) - wChar = item.m_CharCode; - if (wChar) - str += wChar; - } - return CFX_BidiString(str).OverallDirection() == CFX_BidiChar::RIGHT; -} - void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { CPDF_TextObject* pTextObj = Obj.m_pTextObj.Get(); if (fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) @@ -1003,10 +1008,9 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { } m_pPreTextObj = pTextObj; m_perMatrix = formMatrix; - size_t nItems = pTextObj->CountItems(); float baseSpace = CalculateBaseSpace(pTextObj, matrix); - const bool bR2L = IsRightToLeft(pTextObj, pFont, nItems); + const bool bR2L = IsRightToLeft(*pTextObj, *pFont); const bool bIsBidiAndMirrorInverse = bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; int32_t iBufStartAppend = m_TempTextBuf.GetLength(); @@ -1014,6 +1018,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { pdfium::CollectionSize<int32_t>(m_TempCharList); float spacing = 0; + const size_t nItems = pTextObj->CountItems(); for (size_t i = 0; i < nItems; ++i) { CPDF_TextObjectItem item; PAGECHAR_INFO charinfo; @@ -1459,10 +1464,3 @@ Optional<PAGECHAR_INFO> CPDF_TextPage::GenerateCharInfo(wchar_t unicode) { info.m_Origin.x, info.m_Origin.y); return info; } - -bool CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, - const CFX_FloatRect& rect2) { - CFX_FloatRect rect = rect1; - rect.Intersect(rect2); - return !rect.IsEmpty(); -} diff --git a/core/fpdftext/cpdf_textpage.h b/core/fpdftext/cpdf_textpage.h index eb3950f145..43a03123ca 100644 --- a/core/fpdftext/cpdf_textpage.h +++ b/core/fpdftext/cpdf_textpage.h @@ -108,9 +108,6 @@ class CPDF_TextPage { int CountRects(int start, int nCount); bool GetRect(int rectIndex, CFX_FloatRect* pRect) const; - static bool IsRectIntersect(const CFX_FloatRect& rect1, - const CFX_FloatRect& rect2); - private: enum class TextOrientation { Unknown, @@ -143,7 +140,6 @@ class CPDF_TextPage { const CPDF_PageObjectList* pObjList, CPDF_PageObjectList::const_iterator ObjPos); bool IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject* pTextObj2); - uint32_t GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const; void CloseTempLine(); FPDFText_MarkedContent PreMarkedContent(PDFTEXT_Obj pObj); void ProcessMarkedContent(PDFTEXT_Obj pObj); @@ -155,11 +151,7 @@ class CPDF_TextPage { const CPDF_TextObject* pTextObj) const; TextOrientation FindTextlineFlowOrientation() const; void AppendGeneratedCharacter(wchar_t unicode, const CFX_Matrix& formMatrix); - void SwapTempTextBuf(int32_t iCharListStartAppend, int32_t iBufStartAppend); - bool IsRightToLeft(const CPDF_TextObject* pTextObj, - const CPDF_Font* pFont, - size_t nItems) const; UnownedPtr<const CPDF_Page> const m_pPage; std::vector<uint16_t> m_CharIndex; |