⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tagparser.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        int advanceBits = in.readUI8();
        
        //--Read multiple text records
        int firstByte;
        
        while( ( firstByte = in.readUI8()) != 0 )
        {
            if( (firstByte & 0x80) == 0 ) //Glyph Record
            {
                //--Get number of glyph entries
                int glyphCount = firstByte & 0x7f;
        
                int[] glyphs   = new int[ glyphCount ];
                int[] advances = new int[ glyphCount ];
            
                //--Read the glyph entries
                for( int i = 0; i < glyphCount; i++ )
                {
                    glyphs[i]   = (int)in.readUBits( glyphBits );
                    advances[i] = in.readSBits( advanceBits );
                }            

                text.text( glyphs, advances );
            }
            else //Style Record
            {
                int flags = firstByte;
            
                int fontId = 0;
                
                if( ( flags & TEXT_HAS_FONT ) != 0 )
                {
                    fontId = in.readUI16();
                }
            
                if( ( flags & TEXT_HAS_COLOR ) != 0 )
                {
                    text.color( (type == TAG_DEFINETEXT2) ? 
                                    new AlphaColor( in ) : 
                                    new Color( in ));
                }

                if( ( flags & TEXT_HAS_XOFFSET ) != 0 )
                {
                    text.setX( in.readSI16() );
                }

                if( ( flags & TEXT_HAS_YOFFSET ) != 0 ) //x & y are in reverse order from flag bits
                {
                    text.setY ( in.readSI16() );
                }

                if( ( flags & TEXT_HAS_FONT ) != 0 )
                {
                    int textHeight = in.readUI16();
                    
                    text.font( fontId, textHeight );
                }
            }
        }             

        text.done();
    }
    
    protected void parseDefineTextField( InStream in ) throws IOException
    {
        int id = in.readUI16();

        Rect boundary = new Rect( in );
        
        int flags     = in.readUI16();
        int fontId    = in.readUI16();
        int fontSize  = in.readUI16();
        AlphaColor textColor = new AlphaColor( in );
        
        int charLimit = ( (flags & TEXTFIELD_LIMIT_CHARS ) != 0 ) ? in.readUI16() : 0;
        
        int alignment   = in.readUI8();
        int leftMargin  = in.readUI16();
        int rightMargin = in.readUI16();
        int indentation = in.readUI16();
        int lineSpacing = in.readUI16();
                
        String fieldName = in.readString( mStringEncoding );
        String initialText = ( (flags & TEXTFIELD_HAS_TEXT ) != 0 ) ? in.readString( mStringEncoding ) : null;
        
        mTagtypes.tagDefineTextField( id, fieldName, initialText, boundary, flags,
                                     textColor, alignment, fontId, fontSize,
                                     charLimit, leftMargin, rightMargin, 
                                     indentation, lineSpacing );
    }
    
    protected void parseDefineFont2( InStream in ) throws IOException
    {
        int id            = in.readUI16();
        int flags         = in.readUI8();
        int reservedFlags = in.readUI8();
        
        int nameLength = in.readUI8();
        String name = new String( in.read( nameLength ) );
        
        int glyphCount = in.readUI16();
        Vector glyphs = new Vector();
        
        int[] offsets = new int[ glyphCount + 1 ];
        boolean is32 = ( flags & FONT2_32OFFSETS ) != 0;
        for( int i = 0; i <= glyphCount; i++ )
        {
            offsets[i] = is32 ? (int)in.readUI32() : in.readUI16();
        }        
        
        for( int i = 1; i <= glyphCount; i++ )
        {
            int glyphSize = offsets[i] - offsets[i-1];
            byte[] glyphBytes = in.read( glyphSize );
            glyphs.addElement( glyphBytes );
        }
        
        boolean isWide = (( flags & FONT2_WIDECHARS ) != 0 ) || ( glyphCount > 256 );
        
        int[] codes = new int[ glyphCount ];
        for( int i = 0; i < glyphCount; i++ )
        {
            codes[i] = isWide ? in.readUI16() : in.readUI8();
        }        
        
        System.out.println( "glyphCount=" + glyphCount + " flags=" + Integer.toBinaryString( flags ) );
        
        int ascent = 0;
        int descent = 0;
        int leading = 0;
        int[]  advances = new int[0];
        Rect[] bounds   = new Rect[0];
        int[]  kerningCodes1      = new int[0];
        int[]  kerningCodes2      = new int[0];
        int[]  kerningAdjustments = new int[0];
        
        if( ( flags & FONT2_HAS_LAYOUT ) != 0 )
        {
            ascent  = in.readSI16();
            descent = in.readSI16();
            leading = in.readSI16();

            advances = new int[ glyphCount ];
            
            for( int i = 0; i < glyphCount; i++ )
            {
                advances[i] = in.readSI16();
            }        
            
            bounds = new Rect[ glyphCount ];
            
            for( int i = 0; i < glyphCount; i++ )
            {
                bounds[i] = new Rect( in );
            }        
         
            int kerningCount = in.readUI16();
            
            kerningCodes1      = new int[ kerningCount ];
            kerningCodes2      = new int[ kerningCount ];
            kerningAdjustments = new int[ kerningCount ];
            
            for( int i = 0; i < kerningCount; i++ )
            {
                kerningCodes1     [i] = isWide ? in.readUI16() : in.readUI8();
                kerningCodes2     [i] = isWide ? in.readUI16() : in.readUI8();
                kerningAdjustments[i] = in.readSI16();
            }        
        }    
        
        SWFVectors vectors = mTagtypes.tagDefineFont2( id, flags, name, glyphCount,
                                                      ascent, descent, leading,
                                                      codes, advances, bounds,
                                                      kerningCodes1,
                                                      kerningCodes2,
                                                      kerningAdjustments );
        
        if( vectors == null ) return;
        
        if( glyphs.isEmpty() )
        {
            vectors.done();
        }
        else
        {
            for( Enumeration enum = glyphs.elements(); enum.hasMoreElements(); )
            {
                byte[] glyphBytes = (byte[])enum.nextElement();
                
                InStream glyphIn = new InStream( glyphBytes );
                
                parseShape( glyphIn, vectors, false, false );
            }
        }
    }
    
    protected void parseFontInfo( InStream in, int length, boolean isFI2 ) throws IOException
    {
        int fontId = in.readUI16();
        
        //--Read the font name
        int nameLength = in.readUI8();
        byte[] chars = in.read( nameLength );
        String fontName = new String( chars );
        
        //--Read the font flags
        int flags = in.readUI8();
        
        //--Read language code
        int langCode = isFI2 ? in.readUI8() : 0;
        
        //--Adjust the body length
        length -= 4 + nameLength;
        
        //--Read the Glyph-to-code table
        boolean wide = (flags & FONT_WIDECHARS) != 0;
        
        int[] codes = new int[ wide ? ( length / 2 ) : length ];
        
        for( int i = 0; i < codes.length; i++ )
        {
            codes[i] = wide ? in.readUI16() : in.readUI8();
        }             
        if( isFI2 ) mTagtypes.tagDefineFontInfo2( fontId, fontName, flags, codes, langCode );
        else        mTagtypes.tagDefineFontInfo ( fontId, fontName, flags, codes );
    }
    
    protected void parseDefineFont( InStream in ) throws IOException
    {
        int id          = in.readUI16();
        int firstOffset = in.readUI16();
        int numGlyphs   = firstOffset / 2;
        
        SWFVectors vectors = mTagtypes.tagDefineFont( id, numGlyphs );
        
        if( vectors == null ) return;
        
        //--Skip the offset table
        for( int i = 1; i < numGlyphs; i++ )
        {
            in.readUI16();
        }
        
        for( int i = 0; i < numGlyphs; i++ )
        {
            parseShape( in, vectors,  false, false );
        }        
    }
    
    protected void parseDefineSprite( InStream in ) throws IOException
    {
        int id         = in.readUI16();
        int frameCount = in.readUI16();
        
        SWFTagTypes sstt = mTagtypes.tagDefineSprite( id );
        
        if( sstt == null ) return;
        
        TagParser parser = new TagParser( sstt );
        SWFReader reader = new SWFReader( parser, in );
        reader.readTags();
    }
    
    protected void parsePlaceObject2( InStream in ) throws IOException
    {
        boolean hasClipActions    = in.readUBits(1) != 0;
        boolean isClipBracket     = in.readUBits(1) != 0;
        boolean hasName           = in.readUBits(1) != 0;
        boolean hasRatio          = in.readUBits(1) != 0;
        boolean hasColorTransform = in.readUBits(1) != 0;
        boolean hasMatrix         = in.readUBits(1) != 0;
        boolean hasCharacter      = in.readUBits(1) != 0;
        boolean isMove            = in.readUBits(1) != 0;
    
        int depth = in.readUI16();
        
        int            charId    = hasCharacter      ? in.readUI16()            : 0;
        Matrix         matrix    = hasMatrix         ? new Matrix( in )         : null;
        AlphaTransform cxform    = hasColorTransform ? new AlphaTransform( in ) : null;
        int            ratio     = hasRatio          ? in.readUI16()            : -1;        
        int            clipDepth = isClipBracket     ? in.readUI16()            : 0;
        String         name      = hasName           ? in.readString( mStringEncoding )  : null;  
        
        int clipActionFlags = 0;
        
        if( hasClipActions )
        {
            in.readUI16();  //unknown
            clipActionFlags = in.readUI16();  //compound flags
        }
        
        SWFActions actions = mTagtypes.tagPlaceObject2(
                                 isMove, clipDepth, depth, charId, 
                                 matrix, cxform, ratio, name, 
                                 clipActionFlags );
        
        if( hasClipActions && actions != null )
        {
            int flags = 0;
        
            while( (flags = in.readUI16()) != 0 )
            {
                int length = (int)in.readUI32();

                actions.start( flags );
                ActionParser parser = new ActionParser( actions, mFlashVersion );
                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -