1 // Copyright 2014 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 "JBig2_SymbolDict.h"
CJBig2_SymbolDict()8 CJBig2_SymbolDict::CJBig2_SymbolDict()
9 {
10     SDNUMEXSYMS = 0;
11     SDEXSYMS = NULL;
12     m_bContextRetained = FALSE;
13     m_gbContext = m_grContext = NULL;
14 }
15 
DeepCopy()16 CJBig2_SymbolDict *CJBig2_SymbolDict::DeepCopy()
17 {
18     CJBig2_SymbolDict *dst = NULL;
19     CJBig2_SymbolDict *src = this;
20     if (src->m_bContextRetained ||
21         src->m_gbContext ||
22         src->m_grContext) {
23         return NULL;
24     }
25     JBIG2_ALLOC(dst, CJBig2_SymbolDict());
26     dst->SDNUMEXSYMS = src->SDNUMEXSYMS;
27     dst->SDEXSYMS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(
28         sizeof(CJBig2_Image*), src->SDNUMEXSYMS);
29     for(FX_DWORD i = 0; i < src->SDNUMEXSYMS; i++) {
30         if (src->SDEXSYMS[i]) {
31             JBIG2_ALLOC(dst->SDEXSYMS[i],
32                         CJBig2_Image(*(src->SDEXSYMS[i])));
33         } else {
34             dst->SDEXSYMS[i] = NULL;
35         }
36     }
37     return dst;
38 }
39 
~CJBig2_SymbolDict()40 CJBig2_SymbolDict::~CJBig2_SymbolDict()
41 {
42     if(SDEXSYMS) {
43         for(FX_DWORD i = 0; i < SDNUMEXSYMS; i++) {
44             if(SDEXSYMS[i]) {
45                 delete SDEXSYMS[i];
46             }
47         }
48         m_pModule->JBig2_Free(SDEXSYMS);
49     }
50     if(m_bContextRetained) {
51         if(m_gbContext) {
52             m_pModule->JBig2_Free(m_gbContext);
53         }
54         if(m_grContext) {
55             m_pModule->JBig2_Free(m_grContext);
56         }
57     }
58 }
59