Example #1
0
        private void ReadDefineShapeN(Tag tagType, uint followingOffset)
        {
            int id = this.sdtr.ReadUI16();

            #if DEBUG
            this.Log("char id=" + id);
            #endif
            byte[] unparsedShape = this.sdtr.ReadByteBlock((int)(followingOffset - this.sdtr.Offset));

            IShape shape = new ShapeParser().Parse(tagType, unparsedShape, this);

            this.characterUnmarshaller.Add(id, shape);
            this.swf.AddCharacter(CID_PREFIX + id, shape);
        }
Example #2
0
        private void ReadFont(Tag fontType)
        {
            int fontID = this.sdtr.ReadUI16();

            /* Bunch of flags */
            bool hasLayout = this.sdtr.ReadBit();
            bool isShiftJIS = this.sdtr.ReadBit();
            bool isSmallText = this.sdtr.ReadBit();
            bool isANSI = this.sdtr.ReadBit();
            bool isWideOffsets = this.sdtr.ReadBit();
            bool isWideCodes = this.sdtr.ReadBit();
            bool isItalic = this.sdtr.ReadBit();
            bool isBold = this.sdtr.ReadBit();

            if (!isWideCodes)
            {
                throw new SWFModellerException(SWFModellerError.SWFParsing,
                        "Non-wide codes in font encodings are not valid.", swf.Context);
            }

            if (isShiftJIS)
            {
                /* ISSUE 50 */
                throw new SWFModellerException(SWFModellerError.UnimplementedFeature,
                        "ShiftJIS character encoding is not supported.", swf.Context);
            }

            int language = this.sdtr.ReadUI8();
            string name = this.sdtr.ReadLengthedUTF8(this.sdtr.ReadUI8());
            int numGlyphs = this.sdtr.ReadUI16();
            #if DEBUG
            this.Log("id=" + fontID + ", name=" + name);
            #endif

            SWFFont font = new SWFFont(
                    (SWFFont.Language)language,
                    name,
                    isBold,
                    isItalic,
                    isSmallText,
                    numGlyphs);

            int startOffset = (int)this.sdtr.Offset; /* The offset table measures from this point. */

            int[] shapeOffsets = new int[numGlyphs];
            for (int i = 0; i < numGlyphs; i++)
            {
                shapeOffsets[i] = isWideOffsets ? (int)this.sdtr.ReadUI32() : this.sdtr.ReadUI16();
            }

            int codeTableOffset = isWideOffsets ? (int)this.sdtr.ReadUI32() : this.sdtr.ReadUI16();

            IShape[] shapes = new IShape[numGlyphs];

            for (int i = 0; i < numGlyphs; i++)
            {
                int shapeOffset = (int)sdtr.Offset - startOffset;
                if (shapeOffsets[i] != shapeOffset)
                {
                    throw new SWFModellerException(SWFModellerError.SWFParsing, "Bad font data.", swf.Context);
                }

                int end = codeTableOffset;
                if (i < numGlyphs - 1)
                {
                    end = shapeOffsets[i + 1];
                }

                int len = end - shapeOffset;

                byte[] shapeData = this.sdtr.ReadByteBlock(len);

                shapes[i] = new ShapeParser().Parse(fontType, shapeData, this);
            }

            char[] codes = new char[numGlyphs];

            for (int i = 0; i < numGlyphs; i++)
            {
                codes[i] = (char)this.sdtr.ReadUI16();
                font.AddGlyph(codes[i], shapes[i]);
            }

            if (hasLayout)
            {
                font.Ascent = this.sdtr.ReadSI16();
                font.Descent = this.sdtr.ReadSI16();
                font.Leading = this.sdtr.ReadSI16();

                GlyphLayout[] layouts = new GlyphLayout[numGlyphs];

                for (int i = 0; i < numGlyphs; i++)
                {
                    layouts[i] = new GlyphLayout()
                    {
                        Advance = this.sdtr.ReadSI16()
                    };
                }

                for (int i = 0; i < numGlyphs; i++)
                {
                    layouts[i].Bounds = this.sdtr.ReadRect();
                    font.AddLayout(codes[i], layouts[i]);
                }

                int kerningCount = this.sdtr.ReadUI16();
                KerningPair[] kernTable = new KerningPair[kerningCount];

                for (int i = 0; i < kerningCount; i++)
                {
                    kernTable[i] = new KerningPair()
                    {
                        LeftChar = (char)(isWideCodes ? this.sdtr.ReadUI16() : this.sdtr.ReadUI8()),
                        RightChar = (char)(isWideCodes ? this.sdtr.ReadUI16() : this.sdtr.ReadUI8()),
                        Adjustment = this.sdtr.ReadSI16()
                    };
                }

                font.KerningTable = kernTable;
            }

            fontDict.Add(fontID, font);
            swf.AddFont(font);
        }
Example #3
0
        private void ReadDefineMorphShape(Tag format, uint followingOffset)
        {
            int id = this.sdtr.ReadUI16();

            byte[] unparsedShape = this.sdtr.ReadByteBlock((int)(followingOffset - this.sdtr.Offset));

            IShape shape = new ShapeParser().Parse(format, unparsedShape, this);

            this.characterUnmarshaller.Add(id, shape);
            this.swf.AddCharacter(CID_PREFIX + id, shape);
        }