| 1 |
|
| 2 |
package org.freehep.graphicsio.swf; |
| 3 |
|
| 4 |
import java.io.IOException; |
| 5 |
import java.util.ArrayList; |
| 6 |
import java.util.List; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class DefineFont extends DefinitionTag { |
| 16 |
|
| 17 |
private int character; |
| 18 |
|
| 19 |
private List <SWFShape>shapes; |
| 20 |
|
| 21 |
private DefineFontInfo info; |
| 22 |
|
| 23 |
public DefineFont(int id) { |
| 24 |
this(); |
| 25 |
character = id; |
| 26 |
this.shapes = new ArrayList<SWFShape>(); |
| 27 |
} |
| 28 |
|
| 29 |
public void add(SWFShape shape) { |
| 30 |
shapes.add(shape); |
| 31 |
} |
| 32 |
|
| 33 |
public DefineFont() { |
| 34 |
super(10, 1); |
| 35 |
} |
| 36 |
|
| 37 |
public SWFTag read(int tagID, SWFInputStream swf, int len) |
| 38 |
throws IOException { |
| 39 |
|
| 40 |
DefineFont tag = new DefineFont(); |
| 41 |
tag.character = swf.readUnsignedShort(); |
| 42 |
swf.getDictionary().put(tag.character, tag); |
| 43 |
|
| 44 |
int offset0 = swf.readUnsignedShort(); |
| 45 |
int glyphCount = offset0 / 2; |
| 46 |
|
| 47 |
|
| 48 |
int[] offsets = new int[glyphCount]; |
| 49 |
offsets[0] = offset0; |
| 50 |
for (int i = 1; i < glyphCount; i++) { |
| 51 |
offsets[i] = swf.readUnsignedShort(); |
| 52 |
} |
| 53 |
|
| 54 |
tag.shapes = new ArrayList<SWFShape>(); |
| 55 |
for (int i = 0; i < glyphCount; i++) { |
| 56 |
tag.shapes.add(new SWFShape(swf)); |
| 57 |
} |
| 58 |
return tag; |
| 59 |
} |
| 60 |
|
| 61 |
public void write(int tagID, SWFOutputStream swf) throws IOException { |
| 62 |
swf.writeUnsignedShort(character); |
| 63 |
swf.pushBuffer(); |
| 64 |
int[] offsets = new int[shapes.size()]; |
| 65 |
|
| 66 |
for (int i = 0; i < shapes.size(); i++) { |
| 67 |
offsets[i] = swf.getBufferLength(); |
| 68 |
shapes.get(i).write(swf); |
| 69 |
} |
| 70 |
|
| 71 |
swf.popBuffer(); |
| 72 |
for (int i = 0; i < shapes.size(); i++) { |
| 73 |
swf.writeUnsignedShort(shapes.size() * 2 + offsets[i]); |
| 74 |
} |
| 75 |
swf.append(); |
| 76 |
} |
| 77 |
|
| 78 |
public int getGlyphCount() { |
| 79 |
return shapes.size(); |
| 80 |
} |
| 81 |
|
| 82 |
public void setFontInfo(DefineFontInfo info) { |
| 83 |
this.info = info; |
| 84 |
} |
| 85 |
|
| 86 |
public String toString() { |
| 87 |
StringBuffer s = new StringBuffer(); |
| 88 |
s.append(super.toString() + "\n"); |
| 89 |
s.append(" character: " + character + "\n"); |
| 90 |
s.append(" glyphcount: " + shapes.size() + "\n"); |
| 91 |
for (int i = 0; i < shapes.size(); i++) { |
| 92 |
s.append(shapes.get(i) + "\n"); |
| 93 |
} |
| 94 |
s.append(" fontInfo: " + info + "\n"); |
| 95 |
return s.toString(); |
| 96 |
} |
| 97 |
} |