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

📄 tagwriter.java

📁 java和flash混合编程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            }
            else
            {
                out.writeUI8( 0xff );
                out.writeUI16( numStyles );
            }
            
            if( styles != null )
            {
                for( Enumeration e = styles.elements(); 
                     e.hasMoreElements(); )
                {
                    Style style = (Style)e.nextElement();
                    style.write( out, hasAlpha );
                }
                
                styles.removeAllElements();
            }
        }
    }
    
    protected static class MorphShapeImpl extends TagWriter.SWFShapeImpl
    {
        protected int edgeOffsetBase;
        protected int edgeOffsetTarget;
        protected int shapeCount;        
        protected int fillBitSize;
        protected int lineBitSize;
        protected int shapeStart;
        
        public MorphShapeImpl( TagWriter writer ) throws IOException 
        {
            super( writer, true, false );
            fill0Index = -1;
            fill1Index = -1;
            lineIndex  = -1;

            shapeCount = 2;
            
            this.out = writer.getOutStream();

            edgeOffsetBase = (int)this.out.getCount();
            
            this.out.writeUI32( 0 );  //edge offset - to be filled in later
        }      
        
        public void done() throws IOException
        {
            if( ! initialStyles )
            {
                writeInitialStyles();
                initialStyles = true;
            }
            
            this.out.writeUBits( 6, 0 );  //end record            
            this.out.flushBits();

            if( shapeCount == 2 )
            {               
                edgeOffsetTarget = (int)this.out.getCount();                
                
                fill0Index = -1;
                fill1Index = -1;
                lineIndex  = -1;
                moveXY     = null;
                outstandingChanges = true;
                initialStyles = false;
                
                shapeCount--;
                return;
            }
            
            this.out.flush();
            byte[] bytes = writer.bytes.toByteArray();
            
            int edgeOffset = edgeOffsetTarget - edgeOffsetBase - 4;
            
            byte[] offsetBytes = OutStream.uintTo4Bytes( edgeOffset );
            
            bytes[ edgeOffsetBase     ] = offsetBytes[0];
            bytes[ edgeOffsetBase + 1 ] = offsetBytes[1];
            bytes[ edgeOffsetBase + 2 ] = offsetBytes[2];
            bytes[ edgeOffsetBase + 3 ] = offsetBytes[3];
            
            writer.out = null;
            writer.bytes = null;
            
            writer.mTags.tag( writer.tagType, writer.longTag, bytes ); 
        }        
        
        protected void writeInitialStyles() throws IOException
        {   
            this.out.flushBits();       
        
            int fillCount = fillStyles.size()/2;
            int lineCount = lineStyles.size()/2;
            
            fillBitSize = OutStream.determineUnsignedBitSize( fillCount );
            lineBitSize = OutStream.determineUnsignedBitSize( lineCount );
                                        
            //--Write style definitions
            if( shapeCount == 2 )
            {                
                if( fillCount < 255 )
                {
                    this.out.writeUI8( fillCount );
                }
                else
                {
                    this.out.writeUI8( 255 );
                    this.out.writeUI16( fillCount );
                }
                
                for( Enumeration e = fillStyles.elements(); e.hasMoreElements(); )
                {
                    FillStyle startStyle = (FillStyle)e.nextElement();
                    FillStyle endStyle   = (FillStyle)e.nextElement();
                    
                    FillStyle.writeMorphFillStyle( this.out, startStyle, endStyle );
                }                
                
                if( lineCount < 255 )
                {
                    this.out.writeUI8( lineCount );
                }
                else
                {
                    this.out.writeUI8( 255 );
                    this.out.writeUI16( lineCount );
                }
                
                for( Enumeration e = lineStyles.elements(); e.hasMoreElements(); )
                {
                    LineStyle startStyle = (LineStyle)e.nextElement();
                    LineStyle endStyle   = (LineStyle)e.nextElement();
                    
                    LineStyle.writeMorphLineStyle( this.out, startStyle, endStyle );
                }                
            }
            
            if( shapeStart == 0 ) shapeStart = (int)this.out.getCount();
            
            this.out.writeUBits( 4, fillBitSize );
            this.out.writeUBits( 4, lineBitSize );        
        }        

        protected void writeChangeRecord() throws IOException
        {
            boolean hasMoveTo = ( moveXY != null );
            boolean hasFillStyle0 = fill0Index >= 0;
            boolean hasFillStyle1 = fill1Index >= 0;
            boolean hasLineStyle  = lineIndex >= 0;             
            
            if( hasFillStyle0 || hasFillStyle1 || hasLineStyle || hasMoveTo )
            {
                this.out.writeUBits( 1, 0 );  //non-edge record
                this.out.writeUBits( 1, 0 );
                this.out.writeUBits( 1, hasLineStyle  ? 1 : 0 );
                this.out.writeUBits( 1, hasFillStyle1 ? 1 : 0 );
                this.out.writeUBits( 1, hasFillStyle0 ? 1 : 0 );
                this.out.writeUBits( 1, hasMoveTo     ? 1 : 0 );

                if( hasMoveTo )
                {
                    int moveX = moveXY[0];
                    int moveY = moveXY[1];
                    int moveBits  = OutStream.determineSignedBitSize( moveX );
                    int moveYBits = OutStream.determineSignedBitSize( moveY );
                    if( moveYBits > moveBits ) moveBits = moveYBits;              
                    
                    this.out.writeUBits( 5,  moveBits );
                    this.out.writeSBits( moveBits, moveX );
                    this.out.writeSBits( moveBits, moveY );
                }
                    
                if( hasFillStyle0 )
                {
                    this.out.writeUBits( fillBitSize, fill0Index );
                }
                    
                if( hasFillStyle1 )
                {
                    this.out.writeUBits( fillBitSize, fill1Index );
                }
                    
                if( hasLineStyle )
                {
                    this.out.writeUBits( lineBitSize, lineIndex );
                }

                moveXY = null;
                fill0Index = -1;
                fill1Index = -1;
                lineIndex  = -1;            
            }
        }        
    }    
    
    protected static class Font2ShapeImpl extends TagWriter.SWFShapeImpl
    {
        protected int    flags;
        protected int    ascent;
        protected int    descent;
        protected int    leading;                 
        protected int[]  codes; 
        protected int[]  advances;
        protected Rect[] bounds;
        protected int[]  kernCodes1;
        protected int[]  kernCodes2;
        protected int[]  kernAdjustments;
                                          
        public Font2ShapeImpl( TagWriter writer, int flags, int glyphCount,
                               int ascent, int descent, int leading,
                               int[] codes, int[] advances, Rect[] bounds,
                               int[] kernCodes1, int[] kernCodes2,
                               int[] kernAdjustments ) 
        {
            super( writer, glyphCount );
     
            this.flags           = flags;
            this.ascent          = ascent;         
            this.descent         = descent;        
            this.leading         = leading;        
            this.codes           = codes;          
            this.advances        = advances;       
            this.bounds          = bounds;         
            this.kernCodes1      = kernCodes1;     
            this.kernCodes2      = kernCodes2;     
            this.kernAdjustments = kernAdjustments;            
        }
        
        protected void finishFont() throws IOException
        {
            this.out = writer.getOutStream();

            int glyphCount = glyphByteArrays.size();
            
            boolean is32 = ( flags & FONT2_32OFFSETS ) != 0;
            int offset = is32 ? (( glyphCount + 1 ) * 4) : (( glyphCount + 1 ) * 2);
            for( int i = 0; i <= glyphCount; i++ )
            {
                if( is32 )
                {
                    this.out.writeUI32( offset );
                }
                else
                {
                    this.out.writeUI16( offset );
                }
                
                if( i < glyphCount )
                {
                    offset += ((byte[])glyphByteArrays.elementAt( i )).length;
                }
            }
        
            for( int i = 0; i < glyphCount; i++ )
            {
                this.out.write( (byte[])glyphByteArrays.elementAt( i ) );            
            }
        
            boolean isWide = ( flags & FONT2_WIDECHARS ) != 0  || glyphCount > 256 ;
            for( int i = 0; i < glyphCount; i++ )
            {
                if( isWide ) this.out.writeUI16( codes[i] );
                else         this.out.writeUI8( codes[i] );
            }        
        
            if( ( flags & FONT2_HAS_LAYOUT ) != 0 )
            {
                this.out.writeSI16( (short)ascent );
                this.out.writeSI16( (short)descent );
                this.out.writeSI16( (short)leading );

                for( int i = 0; i < glyphCount; i++ )
                {
                    this.out.writeSI16( (short)advances[i] );
                }        
                
                for( int i = 0; i < glyphCount; i++ )
                {
                    bounds[i].write( this.out );
                }        
             
                int kerningCount = (kernCodes1 != null ) ? kernCodes1.length : 0;
                this.out.writeUI16( kerningCount );
                
                for( int i = 0; i < kerningCount; i++ )
                {
                    if( isWide )
                    {
                        this.out.writeUI16( kernCodes1[i] );
                        this.out.writeUI16( kernCodes2[i] );
                        this.out.writeSI16( (short)kernAdjustments[i] );                    
                    }
                    else
                    {
                        this.out.writeUI8 ( kernCodes1[i] );
                        this.out.writeUI8 ( kernCodes2[i] );
                        this.out.writeSI16( (short)kernAdjustments[i] );                    
                    }
                }        
            }                           
        }        
    }
    
    
    /**
     * @see com.anotherbigidea.flash.interfaces.SWFTagTypes#tagScriptLimits(int, int)
     */
    public void tagScriptLimits(int maxRecursionDepth, int scriptTimeoutSecs)
        throws IOException {
        startTag( TAG_SCRIPTLIMITS, false );
        out.writeUI16( maxRecursionDepth );
        out.writeUI16( scriptTimeoutSecs );
        completeTag(); 
    }

    /**
     * @see com.anotherbigidea.flash.interfaces.SWFSpriteTagTypes#tagTabOrder(int, int)
     */
    public void tagTabOrder(int depth, int tabOrder) throws IOException {
        startTag( TAG_TABORDER, false );
        out.writeUI16( depth );
        out.writeUI16( tabOrder );
        completeTag(); 
    }

    /** @see com.anotherbigidea.flash.interfaces.SWFTagTypes#tagDefineVideoStream(int, int, int, int, int, int) */
    public void tagDefineVideoStream(int id, int numFrames, int width,
            int height, int flags, int codec) throws IOException {
        
        startTag( TAG_DEFINEVIDEOSTREAM, id, false );
        
        out.writeUI16( numFrames );
        out.writeUI16( width );
        out.writeUI16( height );
        out.writeUI8 ( flags );
        out.writeUI8 ( codec );
       
        completeTag();
    }
    /** @see com.anotherbigidea.flash.interfaces.SWFTagTypes#tagVideoFrame(int, int, byte[]) */
    public void tagVideoFrame(int streamId, int seqNum, int frameType, int codec, byte[] videoPacket)
            throws IOException {

        startTag( TAG_VIDEOFRAME, streamId, false );
        
        out.writeUI16( seqNum );
        out.write    ( (frameType << 4) + codec );
        out.write    ( videoPacket );
        
        completeTag();
    }
}

⌨️ 快捷键说明

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