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 "core/fpdfapi/font/cfx_stockfontarray.h"
8 
9 #include <memory>
10 #include <utility>
11 
12 #include "core/fpdfapi/font/cpdf_font.h"
13 #include "core/fpdfapi/parser/cpdf_dictionary.h"
14 #include "core/fxcrt/fx_memory.h"
15 
16 CFX_StockFontArray::CFX_StockFontArray() = default;
17 
~CFX_StockFontArray()18 CFX_StockFontArray::~CFX_StockFontArray() {
19   for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) {
20     if (m_StockFonts[i]) {
21       RetainPtr<CPDF_Dictionary> destroy(m_StockFonts[i]->GetFontDict());
22       m_StockFonts[i]->ClearFontDict();
23     }
24   }
25 }
26 
GetFont(CFX_FontMapper::StandardFont index) const27 RetainPtr<CPDF_Font> CFX_StockFontArray::GetFont(
28     CFX_FontMapper::StandardFont index) const {
29   if (index < FX_ArraySize(m_StockFonts))
30     return m_StockFonts[index];
31   NOTREACHED();
32   return nullptr;
33 }
34 
SetFont(CFX_FontMapper::StandardFont index,const RetainPtr<CPDF_Font> & pFont)35 void CFX_StockFontArray::SetFont(CFX_FontMapper::StandardFont index,
36                                  const RetainPtr<CPDF_Font>& pFont) {
37   if (index < FX_ArraySize(m_StockFonts))
38     m_StockFonts[index] = pFont;
39 }
40