1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 #include "fonttableatom.h"
19 #include "atomutils.h"
20
21 #define MAX_ALLOWED_FONT_RECORD_ENTRIES 255
22
23 typedef Oscl_Vector<FontRecord*, OsclMemAllocator> fontRecordVecType;
24
FontTableAtom(MP4_FF_FILE * fp)25 FontTableAtom::FontTableAtom(MP4_FF_FILE *fp)
26 : Atom(fp)
27 {
28 _pFontRecordArray = NULL;
29
30 if (_success)
31 {
32 AtomUtils::read16(fp, _entryCount);
33
34 int16 tmp = (int16)_entryCount;
35
36 if ((tmp < 0) || (tmp > MAX_ALLOWED_FONT_RECORD_ENTRIES))
37 {
38 _success = false;
39 _mp4ErrorCode = READ_FONT_TABLE_ATOM_FAILED;
40 return;
41 }
42
43 PV_MP4_FF_NEW(fp->auditCB, fontRecordVecType, (), _pFontRecordArray);
44
45 for (uint32 i = 0; i < _entryCount; i++)
46 {
47 FontRecord *rec = NULL;
48 PV_MP4_FF_NEW(fp->auditCB, FontRecord, (fp), rec);
49
50 if (!rec-> GetMP4Success())
51 {
52 PV_MP4_FF_DELETE(NULL, FontRecord, rec);
53 _success = false;
54 _mp4ErrorCode = READ_FONT_TABLE_ATOM_FAILED;
55 return;
56 }
57
58 (*_pFontRecordArray).push_back(rec);
59 }
60 }
61 else
62 {
63 _mp4ErrorCode = READ_FONT_TABLE_ATOM_FAILED;
64 }
65 }
66
67 FontRecord *
getFontRecordAt(uint16 index)68 FontTableAtom::getFontRecordAt(uint16 index)
69 {
70 if ((index) > _pFontRecordArray->size())
71 {
72 return NULL;
73 }
74
75 if (index < _entryCount)
76 {
77 return (FontRecord *)(*_pFontRecordArray)[(int32)index];
78 }
79 else
80 {
81 return NULL;
82 }
83 }
84
85
86 // Destructor
~FontTableAtom()87 FontTableAtom::~FontTableAtom()
88 {
89 if (_pFontRecordArray != NULL)
90 {
91 for (uint32 i = 0; i < _entryCount; i++)
92 {
93 PV_MP4_FF_DELETE(NULL, FontRecord, (*_pFontRecordArray)[i]);
94 }
95
96 PV_MP4_FF_TEMPLATED_DELETE(NULL, fontRecordVecType, Oscl_Vector, _pFontRecordArray);
97 }
98 }
99
100