1 // Copyright 2016 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 "core/fpdfdoc/clines.h" 8 9 #include "core/fpdfdoc/cline.h" 10 11 CLines::CLines() : m_nTotal(0) {} 12 13 CLines::~CLines() { 14 RemoveAll(); 15 } 16 17 int32_t CLines::GetSize() const { 18 return m_Lines.GetSize(); 19 } 20 21 CLine* CLines::GetAt(int32_t nIndex) const { 22 return m_Lines.GetAt(nIndex); 23 } 24 25 void CLines::Empty() { 26 m_nTotal = 0; 27 } 28 29 void CLines::RemoveAll() { 30 for (int32_t i = 0, sz = GetSize(); i < sz; i++) 31 delete GetAt(i); 32 m_Lines.RemoveAll(); 33 m_nTotal = 0; 34 } 35 36 int32_t CLines::Add(const CPVT_LineInfo& lineinfo) { 37 if (m_nTotal >= GetSize()) { 38 CLine* pLine = new CLine; 39 pLine->m_LineInfo = lineinfo; 40 m_Lines.Add(pLine); 41 } else if (CLine* pLine = GetAt(m_nTotal)) { 42 pLine->m_LineInfo = lineinfo; 43 } 44 return m_nTotal++; 45 } 46 47 void CLines::Clear() { 48 for (int32_t i = GetSize() - 1; i >= m_nTotal; i--) { 49 delete GetAt(i); 50 m_Lines.RemoveAt(i); 51 } 52 } 53