1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fgas/layout/cfx_breakpiece.h"
8
CFX_BreakPiece()9 CFX_BreakPiece::CFX_BreakPiece()
10 : m_dwStatus(CFX_BreakType::Piece),
11 m_iStartPos(0),
12 m_iWidth(-1),
13 m_iStartChar(0),
14 m_iChars(0),
15 m_iBidiLevel(0),
16 m_iBidiPos(0),
17 m_iFontSize(0),
18 m_iHorizontalScale(100),
19 m_iVerticalScale(100),
20 m_dwIdentity(0),
21 m_dwCharStyles(0),
22 m_pChars(nullptr) {}
23
24 CFX_BreakPiece::CFX_BreakPiece(const CFX_BreakPiece& other) = default;
25
26 CFX_BreakPiece::~CFX_BreakPiece() = default;
27
GetEndPos() const28 int32_t CFX_BreakPiece::GetEndPos() const {
29 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth;
30 }
31
GetChar(int32_t index) const32 CFX_Char* CFX_BreakPiece::GetChar(int32_t index) const {
33 ASSERT(index >= 0 && index < m_iChars && m_pChars);
34 return &(*m_pChars)[m_iStartChar + index];
35 }
36
GetString() const37 WideString CFX_BreakPiece::GetString() const {
38 WideString ret;
39 ret.Reserve(m_iChars);
40 for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++)
41 ret += static_cast<wchar_t>((*m_pChars)[i].char_code());
42 return ret;
43 }
44
GetWidths() const45 std::vector<int32_t> CFX_BreakPiece::GetWidths() const {
46 std::vector<int32_t> ret;
47 ret.reserve(m_iChars);
48 for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++)
49 ret.push_back((*m_pChars)[i].m_iCharWidth);
50 return ret;
51 }
52