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 "atom.h" 19 #include "atomutils.h" 20 #include "oscl_file_io.h" 21 #include "fontrecord.h" 22 #include "fonttableatom.h" 23 #include"a_atomdefs.h" 24 25 #define MAX_ALLOWED_FONT_RECORD_ENTRIES 255 26 27 typedef Oscl_Vector<PVA_FF_FontRecord*, OsclMemAllocator> fontRecordVecType; 28 29 PVA_FF_FontTableAtom::PVA_FF_FontTableAtom() : PVA_FF_Atom(FourCharConstToUint32('f', 't', 'a', 'b')) 30 { 31 _fontlistsize = 0; 32 _pFontRecordArray = NULL; 33 PV_MP4_FF_NEW(fp->auditCB, fontRecordVecType, (), _pFontRecordArray); 34 recomputeSize(); 35 } 36 37 void PVA_FF_FontTableAtom::setFontListSize(uint16 FontListSize) 38 { 39 if (_fontlistsize == 0) 40 { 41 _fontlistsize = FontListSize; 42 } 43 44 } 45 46 void PVA_FF_FontTableAtom::setFontRecord(uint16 FontListID, uint16 FontId, int8 FontLength, uint8* FontName) 47 { 48 49 int16 tmp = (int16)_fontlistsize; 50 if ((tmp < 0) || (tmp > MAX_ALLOWED_FONT_RECORD_ENTRIES)) 51 { 52 return; 53 } 54 for (uint32 i = 0; i < _fontlistsize; i++) 55 { 56 PVA_FF_FontRecord *rec = NULL; 57 PV_MP4_FF_NEW(fp->auditCB, PVA_FF_FontRecord, (FontListID, FontId, FontLength, FontName), rec); 58 59 (*_pFontRecordArray).push_back(rec); 60 } 61 62 } 63 64 65 bool PVA_FF_FontTableAtom::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp) 66 { 67 int32 rendered = 0; 68 uint32 length; 69 70 if (!renderAtomBaseMembers(fp)) 71 { 72 return false; 73 } 74 rendered += getDefaultSize(); 75 76 if (!PVA_FF_AtomUtils::render16(fp, _fontlistsize)) 77 { 78 return false; 79 } 80 rendered += 2; 81 82 for (uint32 i = 0; i < _pFontRecordArray->size(); i++) 83 { 84 length = (*_pFontRecordArray)[i]->getSize(); 85 if (!((*_pFontRecordArray)[i]->renderToFileStream(fp))) 86 { 87 return false; 88 } 89 90 rendered += length; 91 } 92 93 94 return true; 95 } 96 97 void PVA_FF_FontTableAtom::recomputeSize() 98 { 99 uint32 length; 100 int32 size = getDefaultSize(); 101 102 size += 2; 103 for (uint32 i = 0; i < _pFontRecordArray->size(); i++) 104 { 105 length = (*_pFontRecordArray)[i]->getSize(); 106 size += length; 107 } 108 109 110 _size = size; 111 112 // Update size of parent 113 if (_pparent != NULL) 114 { 115 _pparent->recomputeSize(); 116 } 117 } 118 119 uint32 PVA_FF_FontTableAtom::getSize() 120 { 121 recomputeSize(); 122 return (_size); 123 } 124 125 126 // Destructor 127 PVA_FF_FontTableAtom::~PVA_FF_FontTableAtom() 128 { 129 130 if (_pFontRecordArray != NULL) 131 { 132 for (uint32 i = 0; i < _pFontRecordArray->size(); i++) 133 { 134 delete((*_pFontRecordArray)[i]); 135 } 136 PV_MP4_FF_TEMPLATED_DELETE(NULL, fontRecordVecType, Oscl_Vector, _pFontRecordArray); 137 } 138 139 } 140