1 // Copyright 2017 The PDFium Authors 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/cfgas_breakpiece.h" 8 9 #include "third_party/base/check_op.h" 10 #include "third_party/base/numerics/safe_conversions.h" 11 #include "xfa/fgas/layout/cfgas_textuserdata.h" 12 13 CFGAS_BreakPiece::CFGAS_BreakPiece() = default; 14 15 CFGAS_BreakPiece::CFGAS_BreakPiece(const CFGAS_BreakPiece& other) = default; 16 17 CFGAS_BreakPiece::~CFGAS_BreakPiece() = default; 18 GetEndPos() const19int32_t CFGAS_BreakPiece::GetEndPos() const { 20 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; 21 } 22 GetLength() const23size_t CFGAS_BreakPiece::GetLength() const { 24 return pdfium::base::checked_cast<size_t>(m_iCharCount); 25 } 26 GetChar(int32_t index) const27CFGAS_Char* CFGAS_BreakPiece::GetChar(int32_t index) const { 28 return GetChar(pdfium::base::checked_cast<size_t>(index)); 29 } 30 GetChar(size_t index) const31CFGAS_Char* CFGAS_BreakPiece::GetChar(size_t index) const { 32 DCHECK_LT(index, GetLength()); 33 DCHECK(m_pChars); 34 return &(*m_pChars)[m_iStartChar + index]; 35 } 36 GetString() const37WideString CFGAS_BreakPiece::GetString() const { 38 WideString ret; 39 ret.Reserve(m_iCharCount); 40 for (int32_t i = m_iStartChar; i < m_iStartChar + m_iCharCount; i++) 41 ret += static_cast<wchar_t>((*m_pChars)[i].char_code()); 42 return ret; 43 } 44 GetWidths() const45std::vector<int32_t> CFGAS_BreakPiece::GetWidths() const { 46 std::vector<int32_t> ret; 47 ret.reserve(m_iCharCount); 48 for (int32_t i = m_iStartChar; i < m_iStartChar + m_iCharCount; i++) 49 ret.push_back((*m_pChars)[i].m_iCharWidth); 50 return ret; 51 } 52