OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "JBig2_SymbolDict.h" | 7 #include "JBig2_SymbolDict.h" |
8 | 8 |
9 #include "../../../include/fxcrt/fx_memory.h" | 9 #include "../../../include/fxcrt/fx_memory.h" |
10 #include "JBig2_Image.h" | 10 #include "JBig2_Image.h" |
11 | 11 |
12 CJBig2_SymbolDict::CJBig2_SymbolDict() { | 12 CJBig2_SymbolDict::CJBig2_SymbolDict() { |
13 SDNUMEXSYMS = 0; | |
14 SDEXSYMS = NULL; | |
15 m_bContextRetained = FALSE; | 13 m_bContextRetained = FALSE; |
16 m_gbContext = m_grContext = NULL; | 14 m_gbContext = m_grContext = NULL; |
17 } | 15 } |
18 | 16 |
| 17 CJBig2_SymbolDict::~CJBig2_SymbolDict() { |
| 18 if (m_bContextRetained) { |
| 19 FX_Free(m_gbContext); |
| 20 FX_Free(m_grContext); |
| 21 } |
| 22 } |
| 23 |
19 nonstd::unique_ptr<CJBig2_SymbolDict> CJBig2_SymbolDict::DeepCopy() const { | 24 nonstd::unique_ptr<CJBig2_SymbolDict> CJBig2_SymbolDict::DeepCopy() const { |
20 nonstd::unique_ptr<CJBig2_SymbolDict> dst; | 25 nonstd::unique_ptr<CJBig2_SymbolDict> dst; |
21 const CJBig2_SymbolDict* src = this; | 26 const CJBig2_SymbolDict* src = this; |
22 if (src->m_bContextRetained || src->m_gbContext || src->m_grContext) | 27 if (src->m_bContextRetained || src->m_gbContext || src->m_grContext) |
23 return dst; | 28 return dst; |
24 | 29 |
25 dst.reset(new CJBig2_SymbolDict); | 30 dst.reset(new CJBig2_SymbolDict); |
26 dst->SDNUMEXSYMS = src->SDNUMEXSYMS; | 31 for (size_t i = 0; i < src->m_SDEXSYMS.size(); ++i) { |
27 dst->SDEXSYMS = FX_Alloc(CJBig2_Image*, src->SDNUMEXSYMS); | 32 CJBig2_Image* image = src->m_SDEXSYMS.get(i); |
28 for (FX_DWORD i = 0; i < src->SDNUMEXSYMS; ++i) { | 33 dst->m_SDEXSYMS.push_back(image ? new CJBig2_Image(*image) : nullptr); |
29 if (src->SDEXSYMS[i]) { | |
30 dst->SDEXSYMS[i] = new CJBig2_Image(*(src->SDEXSYMS[i])); | |
31 } else { | |
32 dst->SDEXSYMS[i] = NULL; | |
33 } | |
34 } | 34 } |
35 return dst; | 35 return dst; |
36 } | 36 } |
37 | |
38 CJBig2_SymbolDict::~CJBig2_SymbolDict() { | |
39 if (SDEXSYMS) { | |
40 for (FX_DWORD i = 0; i < SDNUMEXSYMS; i++) { | |
41 delete SDEXSYMS[i]; | |
42 } | |
43 FX_Free(SDEXSYMS); | |
44 } | |
45 if (m_bContextRetained) { | |
46 FX_Free(m_gbContext); | |
47 FX_Free(m_grContext); | |
48 } | |
49 } | |
OLD | NEW |