summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp4
-rw-r--r--core/fxcrt/fx_bidi.cpp21
-rw-r--r--core/fxcrt/fx_bidi.h12
3 files changed, 18 insertions, 19 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 31ed9fc704..cc0c9db8a1 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -702,11 +702,11 @@ void CPDF_TextPage::CloseTempLine() {
eCurrentDirection == CFX_BidiChar::RIGHT)) {
eCurrentDirection = CFX_BidiChar::RIGHT;
for (int m = segment.start + segment.count; m > segment.start; --m)
- AddCharInfoByRLDirection(bidi.CharAt(m - 1), m_TempCharList[m - 1]);
+ AddCharInfoByRLDirection(str[m - 1], m_TempCharList[m - 1]);
} else {
eCurrentDirection = CFX_BidiChar::LEFT;
for (int m = segment.start; m < segment.start + segment.count; m++)
- AddCharInfoByLRDirection(bidi.CharAt(m), m_TempCharList[m]);
+ AddCharInfoByLRDirection(str[m], m_TempCharList[m]);
}
}
m_TempCharList.clear();
diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp
index db46d994c9..48504e5821 100644
--- a/core/fxcrt/fx_bidi.cpp
+++ b/core/fxcrt/fx_bidi.cpp
@@ -577,16 +577,14 @@ void CFX_BidiChar::StartNewSegment(CFX_BidiChar::Direction direction) {
m_CurrentSegment.direction = direction;
}
-CFX_BidiString::CFX_BidiString(const WideString& str)
- : m_Str(str),
- m_pBidiChar(pdfium::MakeUnique<CFX_BidiChar>()),
- m_eOverallDirection(CFX_BidiChar::LEFT) {
- for (const auto& c : m_Str) {
- if (m_pBidiChar->AppendChar(c))
- m_Order.push_back(m_pBidiChar->GetSegmentInfo());
+CFX_BidiString::CFX_BidiString(const WideString& str) : m_Str(str) {
+ CFX_BidiChar bidi;
+ for (wchar_t c : m_Str) {
+ if (bidi.AppendChar(c))
+ m_Order.push_back(bidi.GetSegmentInfo());
}
- if (m_pBidiChar->EndChar())
- m_Order.push_back(m_pBidiChar->GetSegmentInfo());
+ if (bidi.EndChar())
+ m_Order.push_back(bidi.GetSegmentInfo());
size_t nR2L = std::count_if(m_Order.begin(), m_Order.end(),
[](const CFX_BidiChar::Segment& seg) {
@@ -604,6 +602,11 @@ CFX_BidiString::CFX_BidiString(const WideString& str)
CFX_BidiString::~CFX_BidiString() {}
+CFX_BidiChar::Direction CFX_BidiString::OverallDirection() const {
+ ASSERT(m_eOverallDirection != CFX_BidiChar::NEUTRAL);
+ return m_eOverallDirection;
+}
+
void CFX_BidiString::SetOverallDirectionRight() {
if (m_eOverallDirection != CFX_BidiChar::RIGHT) {
std::reverse(m_Order.begin(), m_Order.end());
diff --git a/core/fxcrt/fx_bidi.h b/core/fxcrt/fx_bidi.h
index a9b52cf6fb..54d5255e3e 100644
--- a/core/fxcrt/fx_bidi.h
+++ b/core/fxcrt/fx_bidi.h
@@ -41,7 +41,7 @@ class CFX_BidiChar {
// Call after a change in direction is indicated by the above to get
// information about the segment to process.
- Segment GetSegmentInfo() const { return m_LastSegment; }
+ const Segment& GetSegmentInfo() const { return m_LastSegment; }
private:
void StartNewSegment(CFX_BidiChar::Direction direction);
@@ -58,22 +58,18 @@ class CFX_BidiString {
~CFX_BidiString();
// Overall direction is always LEFT or RIGHT, never NEUTRAL.
- CFX_BidiChar::Direction OverallDirection() const {
- return m_eOverallDirection;
- }
+ CFX_BidiChar::Direction OverallDirection() const;
// Force the overall direction to be R2L regardless of what was detected.
void SetOverallDirectionRight();
- wchar_t CharAt(size_t x) const { return m_Str[x]; }
const_iterator begin() const { return m_Order.begin(); }
const_iterator end() const { return m_Order.end(); }
private:
- const WideString m_Str;
- std::unique_ptr<CFX_BidiChar> m_pBidiChar;
+ const WideString& m_Str;
std::vector<CFX_BidiChar::Segment> m_Order;
- CFX_BidiChar::Direction m_eOverallDirection;
+ CFX_BidiChar::Direction m_eOverallDirection = CFX_BidiChar::LEFT;
};
#if PDF_ENABLE_XFA