예제 #1
0
        private void WriteStaticText(StaticText text)
        {
            int cid = characterMarshal.GetIDFor(text);

            bool hasAlpha = text.HasAlpha;

            WriteBuffer textTag = this.OpenTag(hasAlpha ? Tag.DefineText2 : Tag.DefineText, "; id=" + cid);

            /* Tag.DefineText(2) */
            {
                textTag.WriteUI16((uint)cid);

                textTag.WriteRect(text.Bounds);
                textTag.Align8();

                textTag.WriteMatrix(text.Position);
                textTag.Align8();

                /* ISSUE 49: We're lazy here. We max out the bits for text and advances coz we can't
                 * yet calculate them. Fix this attrocity. */

                int glyphBits   = 16;
                int advanceBits = 16;

                textTag.WriteUI8((uint)glyphBits);
                textTag.WriteUI8((uint)advanceBits);

                foreach (TextRecord tr in text.Records)
                {
                    Dictionary <char, int> glyphIDX = null;

                    uint flags = 0x80;

                    if (tr.HasFont)
                    {
                        flags |= 0x08;
                    }

                    if (tr.HasColour)
                    {
                        flags |= 0x04;
                    }

                    if (tr.HasYOffset)
                    {
                        flags |= 0x02;
                    }

                    if (tr.HasXOffset)
                    {
                        flags |= 0x01;
                    }

                    textTag.WriteUI8(flags);

                    if (tr.HasFont)
                    {
                        textTag.WriteUI16((uint)this.characterMarshal.GetExistingIDFor(tr.Font));
                    }

                    if (tr.HasColour)
                    {
                        if (hasAlpha)
                        {
                            textTag.WriteRGBA(tr.Colour.ToArgb());
                        }
                        else
                        {
                            textTag.WriteRGB(tr.Colour.ToArgb());
                        }
                    }

                    if (tr.HasXOffset)
                    {
                        textTag.WriteSI16(tr.XOffset);
                    }

                    if (tr.HasYOffset)
                    {
                        textTag.WriteSI16(tr.YOffset);
                    }

                    if (tr.HasFont)
                    {
                        textTag.WriteUI16((uint)tr.FontHeight);

                        glyphIDX = tr.Font.IndexMap;
                    }

                    char[] chars = tr.Text.ToCharArray();
                    if (chars.Length > 255)
                    {
                        throw new SWFModellerException(SWFModellerError.Internal, "String too long. This should be split across text records.");
                    }

                    textTag.WriteUI8((uint)chars.Length);
                    for (int i = 0; i < tr.Advances.Length; i++)
                    {
                        textTag.WriteUBits((uint)glyphIDX[chars[i]], glyphBits);
                        textTag.WriteSBits(tr.Advances[i], advanceBits);
                    }

                    textTag.Align8();
                }

                textTag.WriteUI8(0); /* End record */
            } /* End of tag code. */

            this.CloseTag();
        }