1 package com.googlecode.mp4parser.boxes.threegpp26245; 2 3 import com.coremedia.iso.IsoTypeReader; 4 import com.coremedia.iso.IsoTypeWriter; 5 import com.coremedia.iso.Utf8; 6 import com.googlecode.mp4parser.AbstractBox; 7 8 import java.io.IOException; 9 import java.nio.ByteBuffer; 10 import java.util.LinkedList; 11 import java.util.List; 12 13 /** 14 * 15 */ 16 public class FontTableBox extends AbstractBox { 17 List<FontRecord> entries = new LinkedList<FontRecord>(); 18 FontTableBox()19 public FontTableBox() { 20 super("ftab"); 21 } 22 23 @Override getContentSize()24 protected long getContentSize() { 25 int size = 2; 26 for (FontRecord fontRecord : entries) { 27 size += fontRecord.getSize(); 28 } 29 return size; 30 } 31 32 33 @Override _parseDetails(ByteBuffer content)34 public void _parseDetails(ByteBuffer content) { 35 int numberOfRecords = IsoTypeReader.readUInt16(content); 36 for (int i = 0; i < numberOfRecords; i++) { 37 FontRecord fr = new FontRecord(); 38 fr.parse(content); 39 entries.add(fr); 40 } 41 } 42 43 @Override getContent(ByteBuffer byteBuffer)44 protected void getContent(ByteBuffer byteBuffer) { 45 IsoTypeWriter.writeUInt16(byteBuffer, entries.size()); 46 for (FontRecord record : entries) { 47 record.getContent(byteBuffer); 48 } 49 } 50 getEntries()51 public List<FontRecord> getEntries() { 52 return entries; 53 } 54 setEntries(List<FontRecord> entries)55 public void setEntries(List<FontRecord> entries) { 56 this.entries = entries; 57 } 58 59 public static class FontRecord { 60 int fontId; 61 String fontname; 62 FontRecord()63 public FontRecord() { 64 } 65 FontRecord(int fontId, String fontname)66 public FontRecord(int fontId, String fontname) { 67 this.fontId = fontId; 68 this.fontname = fontname; 69 } 70 parse(ByteBuffer bb)71 public void parse(ByteBuffer bb) { 72 fontId = IsoTypeReader.readUInt16(bb); 73 int length = IsoTypeReader.readUInt8(bb); 74 fontname = IsoTypeReader.readString(bb, length); 75 } 76 getContent(ByteBuffer bb)77 public void getContent(ByteBuffer bb) { 78 IsoTypeWriter.writeUInt16(bb, fontId); 79 IsoTypeWriter.writeUInt8(bb, fontname.length()); 80 bb.put(Utf8.convert(fontname)); 81 } 82 getSize()83 public int getSize() { 84 return Utf8.utf8StringLengthInBytes(fontname) + 3; 85 } 86 87 @Override toString()88 public String toString() { 89 return "FontRecord{" + 90 "fontId=" + fontId + 91 ", fontname='" + fontname + '\'' + 92 '}'; 93 } 94 } 95 } 96