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"stylerecord.h" 22 #include"a_atomdefs.h" 23 24 PVA_FF_StyleRecord::PVA_FF_StyleRecord() : PVA_FF_Atom(FourCharConstToUint32('t', 't', 's', 's')) 25 { 26 _startChar = 0; 27 _endChar = 0; 28 _fontID = 0; 29 _fontStyleFlags = 0; 30 _fontSize = 0; 31 _pRGBA = NULL; 32 recomputeSize(); 33 } 34 35 PVA_FF_StyleRecord::PVA_FF_StyleRecord(uint16 StartChar, uint16 EndChar, uint16 FontID, uint8 FontSizeFlag, uint8 FontSize, uint8* Trgba) 36 : PVA_FF_Atom(FourCharConstToUint32('t', 't', 's', 's')) 37 { 38 _endChar = 0; 39 _fontID = 0; 40 _fontStyleFlags = 0; 41 _fontSize = 0; 42 _pRGBA = NULL; 43 setStartChar(StartChar); 44 setEndChar(EndChar); 45 setFontID(FontID); 46 setFontStyleFlags(FontSizeFlag); 47 setFontSize(FontSize); 48 setTextColourRGBA(Trgba); 49 50 recomputeSize(); 51 } 52 void PVA_FF_StyleRecord::setStartChar(uint16 startchar) 53 { 54 if (_startChar == 0) 55 { 56 _startChar = startchar; 57 } 58 } 59 60 void PVA_FF_StyleRecord::setEndChar(uint16 endchar) 61 { 62 if (_endChar == 0) 63 { 64 _endChar = endchar; 65 } 66 } 67 68 void PVA_FF_StyleRecord::setFontID(uint16 FontID) 69 { 70 if (_fontID == 0) 71 { 72 _fontID = FontID; 73 } 74 } 75 76 void PVA_FF_StyleRecord::setFontStyleFlags(uint8 flag) 77 { 78 if (_fontStyleFlags == 0) 79 { 80 _fontStyleFlags = flag; 81 } 82 } 83 84 void PVA_FF_StyleRecord::setFontSize(uint8 FontSize) 85 { 86 if (_fontSize == 0) 87 { 88 _fontSize = FontSize; 89 } 90 } 91 92 void PVA_FF_StyleRecord::setTextColourRGBA(uint8* RGBA) 93 { 94 if (_pRGBA == NULL) 95 { 96 _pRGBA = (uint8 *)(OSCL_MALLOC(4 * sizeof(uint8))); 97 _pRGBA[0] = RGBA[0]; 98 _pRGBA[1] = RGBA[1]; 99 _pRGBA[2] = RGBA[2]; 100 _pRGBA[3] = RGBA[3]; 101 } 102 103 } 104 105 106 bool PVA_FF_StyleRecord::renderToFileStream(MP4_AUTHOR_FF_FILE_IO_WRAP *fp) 107 { 108 int32 rendered = 0; 109 110 if (!PVA_FF_AtomUtils::render16(fp, _startChar)) 111 { 112 return false; 113 } 114 rendered += 2; 115 if (!PVA_FF_AtomUtils::render16(fp, _endChar)) 116 { 117 return false; 118 } 119 rendered += 2; 120 if (!PVA_FF_AtomUtils::render16(fp, _fontID)) 121 { 122 return false; 123 } 124 rendered += 2; 125 if (!PVA_FF_AtomUtils::render8(fp, _fontStyleFlags)) 126 { 127 return false; 128 } 129 rendered += 1; 130 if (!PVA_FF_AtomUtils::render8(fp, _fontSize)) 131 { 132 return false; 133 } 134 rendered += 1; 135 if (!PVA_FF_AtomUtils::renderByteData(fp, 4, (uint8 *)_pRGBA)) 136 { 137 return false; 138 } 139 rendered += 4; 140 141 142 return true; 143 } 144 145 void PVA_FF_StyleRecord::recomputeSize() 146 { 147 int32 size = 0; 148 149 size += 2; 150 size += 2; 151 size += 2; 152 size += 1; 153 size += 1; 154 size += 4; 155 156 _size = size; 157 158 // Update size of parent 159 if (_pparent != NULL) 160 { 161 _pparent->recomputeSize(); 162 } 163 } 164 165 uint32 PVA_FF_StyleRecord::getSize() 166 { 167 recomputeSize(); 168 return (_size); 169 } 170 171 // Destructor 172 PVA_FF_StyleRecord::~PVA_FF_StyleRecord() 173 { 174 if (_pRGBA) 175 { 176 OSCL_FREE(_pRGBA); 177 _pRGBA = NULL; 178 } 179 } 180