Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: core/include/fxcrt/fx_bidi.h

Issue 1682983002: Make fx_bidi sane. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Stray class decl. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/src/fpdftext/fpdf_text_int.cpp » ('j') | core/src/fpdftext/text_int.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_INCLUDE_FXCRT_FX_BIDI_H_ 7 #ifndef CORE_INCLUDE_FXCRT_FX_BIDI_H_
8 #define CORE_INCLUDE_FXCRT_FX_BIDI_H_ 8 #define CORE_INCLUDE_FXCRT_FX_BIDI_H_
9 9
10 #include <vector>
11 #include <memory>
Lei Zhang 2016/02/12 00:46:42 memory before vector.
Tom Sepez 2016/02/12 17:54:33 Done.
12
13 #include "fx_string.h"
10 #include "fx_system.h" 14 #include "fx_system.h"
11 15
12 // Processes characters and group them into segments based on text direction. 16 // Processes characters and group them into segments based on text direction.
13 class CFX_BidiChar { 17 class CFX_BidiChar {
14 public: 18 public:
15 enum Direction { NEUTRAL, LEFT, RIGHT }; 19 enum Direction { NEUTRAL, LEFT, RIGHT };
20 struct Segment {
21 int32_t start; // Start position.
22 int32_t count; // Character count.
23 Direction direction; // Segment direction.
24 };
16 25
17 CFX_BidiChar(); 26 CFX_BidiChar()
18 ~CFX_BidiChar(); 27 : m_CurrentSegment({0, 0, NEUTRAL}), m_LastSegment({0, 0, NEUTRAL}) {}
Lei Zhang 2016/02/12 00:46:42 Keep the ctor impl in the .cpp file?
Tom Sepez 2016/02/12 17:54:33 Done.
19 28
20 // Append a character and classify it as left, right, or neutral. 29 // Append a character and classify it as left, right, or neutral.
21 // Returns true if the character has a different direction than the 30 // Returns true if the character has a different direction than the
22 // existing direction to indicate there is a segment to process. 31 // existing direction to indicate there is a segment to process.
23 bool AppendChar(FX_WCHAR wch); 32 bool AppendChar(FX_WCHAR wch);
24 33
25 // Call this after the last character has been appended. AppendChar() 34 // Call this after the last character has been appended. AppendChar()
26 // must not be called after this. 35 // must not be called after this.
27 // Returns true if there is still a segment to process. 36 // Returns true if there is still a segment to process.
28 bool EndChar(); 37 bool EndChar();
29 38
30 // Get information about the segment to process. 39 // Call after a change in direction is indicated by the above to get
31 // The segment's start position and character count is returned in |iStart| 40 // information about the segment to process.
32 // and |iCount|, respectively. Pass in null pointers if the information is 41 Segment GetSegmentInfo() const { return m_LastSegment; }
33 // not needed.
34 // Returns the segment direction.
35 Direction GetBidiInfo(int32_t* iStart, int32_t* iCount) const;
36 42
37 private: 43 private:
38 void SaveCurrentStateToLastState(); 44 void StartNewSegment(CFX_BidiChar::Direction direction);
39 45
40 // Position of the current segment. 46 Segment m_CurrentSegment;
41 int32_t m_iCurStart; 47 Segment m_LastSegment;
48 };
42 49
43 // Number of characters in the current segment. 50 class CFX_BidiString {
44 int32_t m_iCurCount; 51 public:
52 using const_iterator = std::vector<CFX_BidiChar::Segment>::const_iterator;
53 CFX_BidiString(const CFX_WideString& str);
Lei Zhang 2016/02/12 00:46:42 explicit
Tom Sepez 2016/02/12 17:54:33 Done.
45 54
46 // Direction of the current segment. 55 // Overall direction is always LEFT or RIGHT, never NEUTRAL.
47 Direction m_CurBidi; 56 void SetOverallDirection(CFX_BidiChar::Direction eDirection);
Lei Zhang 2016/02/12 00:46:42 If you make this private and only expose wrappers
Tom Sepez 2016/02/12 17:54:33 Actually, we only call this with an argument of RI
57 CFX_BidiChar::Direction OverallDirection() const {
58 return m_eOverallDirection;
59 }
48 60
49 // Number of characters in the last segment. 61 FX_WCHAR CharAt(size_t x) const { return m_Str[x]; }
50 int32_t m_iLastStart; 62 const_iterator begin() const { return m_Order.begin(); }
63 const_iterator end() const { return m_Order.end(); }
51 64
52 // Number of characters in the last segment. 65 private:
53 int32_t m_iLastCount; 66 const CFX_WideString m_Str;
54 67 std::unique_ptr<CFX_BidiChar> m_pBidiChar;
55 // Direction of the last segment. 68 std::vector<CFX_BidiChar::Segment> m_Order;
56 Direction m_LastBidi; 69 CFX_BidiChar::Direction m_eOverallDirection;
57 }; 70 };
58 71
59 #endif // CORE_INCLUDE_FXCRT_FX_BIDI_H_ 72 #endif // CORE_INCLUDE_FXCRT_FX_BIDI_H_
OLDNEW
« no previous file with comments | « no previous file | core/src/fpdftext/fpdf_text_int.cpp » ('j') | core/src/fpdftext/text_int.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698