Beispiel #1
0
        /// <param name="fontID">Pass -1 if this has no font.</param>
        private void WriteEditText(EditText text, int fontID)
        {
            int cid = characterMarshal.GetIDFor(text);

            WriteBuffer textTag = this.OpenTag(Tag.DefineEditText, "; id=" + cid);

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

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

                textTag.WriteBit(text.HasText);
                textTag.WriteBit(text.WordWrapEnabled);
                textTag.WriteBit(text.IsMultiline);
                textTag.WriteBit(text.IsPassword);
                textTag.WriteBit(text.IsReadOnly);
                textTag.WriteBit(text.HasTextColor);
                textTag.WriteBit(text.HasMaxLength);
                textTag.WriteBit(text.HasFont);
                textTag.WriteBit(text.HasFontClass);
                textTag.WriteBit(text.IsAutoSized);
                textTag.WriteBit(text.HasLayout);
                textTag.WriteBit(text.IsNonSelectable);
                textTag.WriteBit(text.HasBorder);
                textTag.WriteBit(text.IsStatic);
                textTag.WriteBit(text.IsHTML);
                textTag.WriteBit(text.UseOutlines);

                if (text.HasFont)
                {
                    textTag.WriteUI16((uint)fontID);
                }

                if (text.HasFontClass)
                {
                    /* ISSUE 14 */
                    throw new SWFModellerException(SWFModellerError.UnimplementedFeature, "Font classes can't be written.");
                }

                if (text.HasFont)
                {
                    textTag.WriteUI16((uint)text.FontHeight);
                }

                if (text.HasTextColor)
                {
                    textTag.WriteRGBA(text.Color.ToArgb());
                }

                if (text.HasMaxLength)
                {
                    textTag.WriteUI16((uint)text.MaxLength.Value);
                }

                if (text.HasLayout)
                {
                    EditText.Layout layout = text.LayoutInfo;

                    textTag.WriteUI8((uint)layout.Align);
                    textTag.WriteUI16((uint)layout.LeftMargin);
                    textTag.WriteUI16((uint)layout.RightMargin);
                    textTag.WriteUI16((uint)layout.Indent);
                    textTag.WriteSI16(layout.Leading);
                }

                textTag.WriteString(text.VarName);

                if (text.HasText)
                {
                    textTag.WriteString(text.Text);
                }
            }

            CloseTag();
        }
Beispiel #2
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();
        }