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 "core/fpdfapi/font/cfx_stockfontarray.h" 8 9 #include <iterator> 10 #include <utility> 11 12 #include "core/fpdfapi/font/cpdf_font.h" 13 #include "core/fpdfapi/parser/cpdf_dictionary.h" 14 #include "third_party/base/check_op.h" 15 16 CFX_StockFontArray::CFX_StockFontArray() = default; 17 ~CFX_StockFontArray()18CFX_StockFontArray::~CFX_StockFontArray() { 19 for (size_t i = 0; i < std::size(m_StockFonts); ++i) { 20 if (m_StockFonts[i]) { 21 // Ensure m_StockFonts[i]'s dict is cleared before releasing what 22 // may be the last reference to it. 23 RetainPtr<CPDF_Dictionary> destroy = 24 m_StockFonts[i]->GetMutableFontDict(); 25 m_StockFonts[i]->ClearFontDict(); 26 } 27 } 28 } 29 GetFont(CFX_FontMapper::StandardFont index) const30RetainPtr<CPDF_Font> CFX_StockFontArray::GetFont( 31 CFX_FontMapper::StandardFont index) const { 32 CHECK_LT(index, std::size(m_StockFonts)); 33 return m_StockFonts[index]; 34 } 35 SetFont(CFX_FontMapper::StandardFont index,RetainPtr<CPDF_Font> pFont)36void CFX_StockFontArray::SetFont(CFX_FontMapper::StandardFont index, 37 RetainPtr<CPDF_Font> pFont) { 38 if (index < std::size(m_StockFonts)) 39 m_StockFonts[index] = std::move(pFont); 40 } 41