private void ReadText(Tag format)
{
int cid = this.sdtr.ReadUI16();
StaticText text = this.swf.NewStaticText(CID_PREFIX + cid); /* ISSUE 38: Should this silly name thing be wrapped into SWF? */
this.characterUnmarshaller.Add(cid, text);
text.Bounds = this.sdtr.ReadRect();
this.sdtr.Align8();
text.Position = this.sdtr.ReadMatrix();
this.sdtr.Align8();
int glyphBits = this.sdtr.ReadUI8();
int advanceBits = this.sdtr.ReadUI8();
int flags = 0;
while((flags = this.sdtr.ReadUI8()) != 0)
{
TextRecord tr = new TextRecord();
if ((flags & 0xF0) != 0x80)
{
/* Top 4 bits must match 1000xxxx */
throw new SWFModellerException(SWFModellerError.SWFParsing, "Bad flags in DefineText", swf.Context);
}
bool hasFont = ((flags & 0x08) != 0);
bool hasColour = ((flags & 0x04) != 0);
bool hasYOffset = ((flags & 0x02) != 0);
bool hasXOffset = ((flags & 0x01) != 0);
if (hasFont)
{
tr.Font = fontDict[this.sdtr.ReadUI16()];
}
if (hasColour)
{
if (format == Tag.DefineText2)
{
tr.Colour = this.sdtr.ReadRGBA();
}
else /* assume DefineText */
{
tr.Colour = this.sdtr.ReadRGB();
}
}
if (hasXOffset)
{
tr.XOffset = this.sdtr.ReadSI16();
}
if (hasYOffset)
{
tr.YOffset = this.sdtr.ReadSI16();
}
if (hasFont)
{
tr.FontHeight = this.sdtr.ReadUI16();
}
int glyphCount = this.sdtr.ReadUI8();
char[] glyphIndex = tr.Font.CodePoints;
int[] advances = new int[glyphCount];
StringBuilder sb = new StringBuilder(glyphCount);
for (int i = 0; i < glyphCount; i++)
{
sb.Append(glyphIndex[(int)this.sdtr.ReadUBits(glyphBits)]);
advances[i] = this.sdtr.ReadSBits(advanceBits);
}
tr.Text = sb.ToString();
tr.Advances = advances;
text.Records.Add(tr);
this.sdtr.Align8();
}
}