?? tagwriter.java
字號:
public void header( int version, long length,
int twipsWidth, int twipsHeight,
int frameRate, int frameCount ) throws IOException
{
}
}
protected void startShape( int tagType, int id, Rect outline ) throws IOException
{
startTag( tagType, id, true );
outline.write( out );
}
/**
* Implementation of the SWFShape interface
*/
protected static class SWFShapeImpl implements SWFShape
{
protected boolean hasAlpha;
protected boolean hasStyle;
protected boolean outstandingChanges = true;
protected boolean initialStyles = false;
protected int fill0Index = -1;
protected int fill1Index = -1;
protected int lineIndex = -1;
protected int[] moveXY;
protected Vector lineStyles = new Vector();
protected Vector fillStyles = new Vector();
protected int fillBits;
protected int lineBits;
protected int glyphCount = 0;
protected Vector glyphByteArrays;
protected OutStream out;
protected TagWriter writer;
protected ByteArrayOutputStream bout;
/**
* For shapes (other than glyphs)
*/
public SWFShapeImpl( TagWriter writer, boolean hasAlpha, boolean hasStyle )
{
this.hasAlpha = hasAlpha;
this.hasStyle = hasStyle;
this.writer = writer;
out = writer.getOutStream();
}
/**
* For glyphs
*/
public SWFShapeImpl( TagWriter writer, int glyphCount )
{
this( writer, false, false );
this.glyphCount = glyphCount;
bout = new ByteArrayOutputStream();
out = new OutStream( bout );
glyphByteArrays = new Vector();
fill1Index = 1;
lineIndex = 0;
}
public void done() throws IOException
{
if( ! initialStyles )
{
writeInitialStyles();
initialStyles = true;
}
out.writeUBits( 6, 0 ); //end record
out.flushBits();
if( bout != null && glyphCount > 0 ) //capturing bytes internally
{
byte[] glyphBytes = bout.toByteArray();
glyphByteArrays.addElement( glyphBytes );
}
if( glyphCount > 1 )
{
bout = new ByteArrayOutputStream();
out = new OutStream( bout );
glyphCount--;
fill1Index = 1;
lineIndex = 0;
outstandingChanges = true;
initialStyles = false;
}
else
{
if( bout != null ) finishFont();
writer.completeTag();
}
}
protected void finishFont() throws IOException
{
out = writer.getOutStream();
int glyphCount = glyphByteArrays.size();
//--Write first shape offset
int offset = glyphCount * 2;
out.writeUI16( offset );
//--Write subsequent shape offsets
for( int i = 0; i < glyphCount - 1; i++ )
{
offset += ((byte[])glyphByteArrays.elementAt(i)).length;
out.writeUI16( offset );
}
//--Write shapes
for( int i = 0; i < glyphCount; i++ )
{
out.write( (byte[])glyphByteArrays.elementAt(i) );
}
}
public void setFillStyle0( int styleIndex ) throws IOException
{
fill0Index = styleIndex;
outstandingChanges = true;
}
public void setFillStyle1( int styleIndex ) throws IOException
{
fill1Index = styleIndex;
outstandingChanges = true;
}
public void setLineStyle( int styleIndex ) throws IOException
{
lineIndex = styleIndex;
outstandingChanges = true;
}
public void defineFillStyle( Color color ) throws IOException
{
fillStyles.addElement( new FillStyle( color ) );
outstandingChanges = true;
}
public void defineFillStyle( Matrix matrix, int[] ratios,
Color[] colors, boolean radial )
throws IOException
{
fillStyles.addElement( new FillStyle( matrix, ratios, colors, radial ) );
outstandingChanges = true;
}
public void defineFillStyle( int bitmapId, Matrix matrix, boolean clipped )
throws IOException
{
fillStyles.addElement( new FillStyle( bitmapId, matrix, clipped ) );
outstandingChanges = true;
}
public void defineLineStyle( int width, Color color ) throws IOException
{
lineStyles.addElement( new LineStyle( width, color ) );
outstandingChanges = true;
}
public void line( int deltaX, int deltaY ) throws IOException
{
if( outstandingChanges ) flushChangeRecords();
int numBits = OutStream.determineSignedBitSize( deltaX );
int dyBits = OutStream.determineSignedBitSize( deltaY );
if( dyBits > numBits ) numBits = dyBits;
if( numBits < 2 ) numBits = 2;
out.writeUBits( 2, 3 ); //11b = line record
out.writeUBits( 4, numBits - 2 );
if( deltaX != 0 && deltaY != 0 ) //general line
{
out.writeUBits( 1, 1 );
out.writeSBits( numBits, deltaX );
out.writeSBits( numBits, deltaY );
}
else //horz or vert line
{
out.writeUBits( 1, 0 );
if( deltaY != 0 ) //vert line
{
out.writeUBits( 1, 1 );
out.writeSBits( numBits, deltaY );
}
else ///horz line
{
out.writeUBits( 1, 0 );
out.writeSBits( numBits, deltaX );
}
}
}
public void curve( int cx, int cy, int dx, int dy ) throws IOException
{
if( outstandingChanges ) flushChangeRecords();
int numBits = OutStream.determineSignedBitSize( cx );
int dyBits = OutStream.determineSignedBitSize( cy );
int adxBits = OutStream.determineSignedBitSize( dx );
int adyBits = OutStream.determineSignedBitSize( dy );
if( dyBits > numBits ) numBits = dyBits;
if( adxBits > numBits ) numBits = adxBits;
if( adyBits > numBits ) numBits = adyBits;
if( numBits < 2 ) numBits = 2;
out.writeUBits( 2, 2 ); //10b = curve record
out.writeUBits( 4, numBits - 2 );
out.writeSBits( numBits, cx );
out.writeSBits( numBits, cy );
out.writeSBits( numBits, dx );
out.writeSBits( numBits, dy );
}
public void move( int x, int y ) throws IOException
{
moveXY = new int[] { x, y };
outstandingChanges = true;
}
protected void flushChangeRecords() throws IOException
{
if( ! initialStyles )
{
writeInitialStyles();
initialStyles = true;
}
writeChangeRecord();
outstandingChanges = false;
}
protected void writeInitialStyles() throws IOException
{
out.flushBits();
fillBits = OutStream.determineUnsignedBitSize( fillStyles.size() );
lineBits = OutStream.determineUnsignedBitSize( lineStyles.size() );
//--For fonts - the fillstyle bits must be one
if( ! hasStyle )
{
fillBits = 1;
}
else
{
writeStyles( fillStyles );
writeStyles( lineStyles );
out.flushBits();
}
out.writeUBits( 4, fillBits );
out.writeUBits( 4, lineBits );
}
protected void writeChangeRecord() throws IOException
{
boolean hasNewStyles = hasStyle &&
( fillStyles.size() > 0 || lineStyles.size() > 0 );
boolean hasMoveTo = ( moveXY != null );
boolean hasFillStyle0 = fill0Index >= 0;
boolean hasFillStyle1 = fill1Index >= 0;
boolean hasLineStyle = lineIndex >= 0;
if( (! hasStyle) && hasFillStyle0 ) hasFillStyle1 = false;
if( hasNewStyles )
{
out.writeUBits( 1, 0 ); //non-edge record
out.writeUBits( 1, 1 ); //defines new styles
out.writeUBits( 1, 1 );
out.writeUBits( 1, 1 );
out.writeUBits( 1, 1 );
out.writeUBits( 1, 1 );
//--Clear existing styles
writeMoveXY( 0, 0 );
out.writeUBits( fillBits, 0 );
out.writeUBits( fillBits, 0 );
out.writeUBits( lineBits, 0 );
if( fill0Index == 0 ) fill0Index = -1;
if( fill1Index == 0 ) fill1Index = -1;
if( lineIndex == 0 ) lineIndex = -1;
fillBits = OutStream.determineUnsignedBitSize( fillStyles.size() );
lineBits = OutStream.determineUnsignedBitSize( lineStyles.size() );
writeStyles( fillStyles );
writeStyles( lineStyles );
out.writeUBits( 4, fillBits );
out.writeUBits( 4, lineBits );
writeChangeRecord();
return;
}
if( hasFillStyle0 || hasFillStyle1 || hasLineStyle || hasMoveTo )
{
out.writeUBits( 1, 0 ); //non-edge record
out.writeUBits( 1, 0 );
out.writeUBits( 1, hasLineStyle ? 1 : 0 );
out.writeUBits( 1, hasFillStyle1 ? 1 : 0 );
out.writeUBits( 1, hasFillStyle0 ? 1 : 0 );
out.writeUBits( 1, hasMoveTo ? 1 : 0 );
if( hasMoveTo )
{
int moveX = moveXY[0];
int moveY = moveXY[1];
writeMoveXY( moveX, moveY );
}
if( hasFillStyle0 )
{
out.writeUBits( fillBits, fill0Index );
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -