Esempio n. 1
0
static void
writeSWFTextToMethod(SWFBlock block, SWFByteOutputMethod method, void *data)
{
	SWFText text = (SWFText)block;
	int length = 0;
	SWFOutput out;

	if ( text->matrix == NULL )
		text->matrix = newSWFMatrix(1.0, 0, 0, 1.0, 0, 0);

	length += (SWFMatrix_numBits(text->matrix)+7)/8;
	length += (SWFRect_numBits(CHARACTER(text)->bounds)+7)/8;
	length += 4;

	out = newSizedSWFOutput(length);

	SWFOutput_writeUInt16(out, CHARACTERID(text));
	SWFOutput_writeRect(out, CHARACTER(text)->bounds);
	SWFOutput_writeMatrix(out, text->matrix);
	SWFOutput_writeUInt8(out, text->nGlyphBits);
	SWFOutput_writeUInt8(out, text->nAdvanceBits);

	SWFOutput_writeToMethod(out, method, data);
	SWFOutput_writeToMethod(text->out, method, data);

	destroySWFOutput(out);
}
Esempio n. 2
0
int
completeSWFTextField(SWFBlock block)
{
	SWFTextField field = (SWFTextField)block;

	/* we're guessing how big the block's going to be.. */
	SWFOutput out =
		newSizedSWFOutput(42 
			+ ((field->varName)?strlen(field->varName):0) 
			+ ((field->string)?strlen(field->string):0));

	field->out = out;

	resetBounds(field);

	SWFOutput_writeUInt16(out, CHARACTERID(field));
	SWFOutput_writeRect(out, CHARACTER(field)->bounds);
	SWFOutput_writeUInt16(out, field->flags);

	if(field->flags & SWFTEXTFIELD_HASFONT)
	{
		SWFOutput_writeUInt16(out, CHARACTERID(field->font.fontchar));
		SWFOutput_writeUInt16(out, field->fontHeight);
	}

	if(field->flags & SWFTEXTFIELD_HASCOLOR)
	{
		SWFOutput_writeUInt8(out, field->r);
		SWFOutput_writeUInt8(out, field->g);
		SWFOutput_writeUInt8(out, field->b);
		SWFOutput_writeUInt8(out, field->a);
	}

	if ( field->flags & SWFTEXTFIELD_HASLENGTH )
		SWFOutput_writeUInt16(out, field->length);

	if(field->flags & SWFTEXTFIELD_HASLAYOUT)
	{
		SWFOutput_writeUInt8(out, field->alignment);
		SWFOutput_writeUInt16(out, field->leftMargin);
		SWFOutput_writeUInt16(out, field->rightMargin);
		SWFOutput_writeUInt16(out, field->indentation);
		SWFOutput_writeUInt16(out, field->lineSpacing);
	}

	SWFOutput_writeString(out, (byte*) field->varName);
	if ( field->flags & SWFTEXTFIELD_HASTEXT )
		SWFOutput_writeString(out, (byte*)field->string);

	/*
		XXX - if font is a real font, do we need to talk to it?
		flash 4 just makes a browser font for (editable) textfields for all fonts
	*/

	SWFOutput_byteAlign(out);
	return SWFOutput_getLength(out);
}
Esempio n. 3
0
void
SWFShape_addStyleHeader(SWFShape shape)
{
    SWFOutput out = newSWFOutput();
    SWFOutput_writeUInt16(out, CHARACTERID(shape));
    SWFOutput_writeRect(out, SWFCharacter_getBounds(CHARACTER(shape)));
    if(shape->useVersion == SWF_SHAPE4)
    {
        SWFOutput_writeRect(out, shape->edgeBounds);
        SWFOutput_writeUInt8(out, shape->flags);
    }

    SWFOutput_writeFillStyles(out, shape->fills, shape->nFills,
                              BLOCK(shape)->type, shape->edgeBounds);
    SWFOutput_writeLineStyles(out, shape->lines, shape->nLines, BLOCK(shape)->type);

    /* prepend shape->out w/ shape header */
    SWFOutput_setNext(out, shape->out);
    shape->out = out;
}
Esempio n. 4
0
void
SWFShape_addStyleHeader(SWFShape shape)
{
	SWFOutput out = newSWFOutput();

	SWFOutput_writeUInt16(out, CHARACTERID(shape));
	SWFOutput_writeRect(out, SWFCharacter_getBounds(CHARACTER(shape)));

	if (shape->isUsingNewStyles) {
		shape->nFills2 = 0;
		shape->nLines2 = 0;
	}

	SWFOutput_writeFillStyles(out, shape->fills2, shape->nFills2, BLOCK(shape)->type);
	SWFOutput_writeLineStyles(out, shape->lines2, shape->nLines2, BLOCK(shape)->type);

	/* prepend shape->out w/ shape header */
	SWFOutput_setNext(out, shape->out);
	shape->out = out;
}
Esempio n. 5
0
SWFOutput
SWFMovie_toOutput(SWFMovie movie, int level)
{
	int swflength;
#if USE_ZLIB
	int status;
#endif
	SWFOutput header, tempbuffer=0, buffer, swfbuffer;
	SWFBlock lastBlock;
	unsigned long compresslength;

	if ( movie->nExports > 0 )
		SWFMovie_writeExports(movie);

	if ( movie->metadata != NULL)
	{
		SWFMovie_addBlock(movie, (SWFBlock)movie->metadata);
		movie->metadata = NULL; // do not destroy with movie if added as block
	}

	/* Add a terminating SHOWFRAME tag if not already there */
	lastBlock = SWFBlockList_getLastBlock(movie->blockList);
	if ( ! lastBlock || SWFBlock_getType(lastBlock) != SWF_SHOWFRAME )
	{
		SWFMovie_nextFrame(movie);
	}

	while ( movie->nFrames < movie->totalFrames )
		SWFMovie_nextFrame(movie);

	if(movie->symbolClass)
		SWFMovie_addBlock(movie, (SWFBlock)movie->symbolClass);

	if(movie->sceneData)
		SWFMovie_addBlock(movie, (SWFBlock)movie->sceneData);

	SWFMovie_addBlock(movie, newSWFEndBlock());

	// add five for the setbackground block..
	swflength = SWFBlockList_completeBlocks(movie->blockList, movie->version);

	/* XXX - hack */
	SWFDisplayList_rewindSoundStream(movie->displayList);

	header = newSizedSWFOutput(23);

	SWFOutput_writeRect(header, movie->bounds);
	SWFOutput_writeUInt16(header, (int)floor(movie->rate*256));
	SWFOutput_writeUInt16(header, movie->nFrames);

	/* SWF >= 8: first block _must_ be SWF_FILEATTRIBUTES */ 
	if(movie->fattrs)
		writeSWFBlockToMethod((SWFBlock)movie->fattrs, SWFOutputMethod, header);

	if(movie->backgroundBlock)
		writeSWFBlockToMethod(movie->backgroundBlock, SWFOutputMethod, header);
	
	if(movie->limits)
		writeSWFBlockToMethod((SWFBlock)movie->limits, SWFOutputMethod, header);	
	SWFOutput_byteAlign(header);
	swflength += 8 + SWFOutput_getLength(header);

	// compression level check
#if USE_ZLIB
	if (level < -1) level = -1;
	if (level >  9) level = 9;
#else
	if ( level != -1 )
	{
		SWF_warn("No zlib support compiled in, "
			"cannot generate compressed output");
		level = -1; 
	}
#endif

	// reserve output buffer
	if(level >= 0)
	{	// a little bit more than the uncompressed data
		compresslength = swflength + (swflength/1000) + 15 + 1;
		swfbuffer    = newSizedSWFOutput( compresslength + 8 );
	}
	else
		swfbuffer    = newSizedSWFOutput( swflength );

	if (level >= 0) SWFOutput_writeUInt8 (swfbuffer, 'C');
	else SWFOutput_writeUInt8 (swfbuffer, 'F');
	SWFOutput_writeUInt8 (swfbuffer, 'W');
	SWFOutput_writeUInt8 (swfbuffer, 'S');

	SWFOutput_writeUInt8 (swfbuffer, movie->version);

	// Movie length
	SWFOutput_writeUInt32(swfbuffer, swflength);

	if(level >= 0)
		buffer = tempbuffer = newSizedSWFOutput( swflength - 8);
	else
		buffer = swfbuffer;

	SWFOutput_writeToMethod(header, SWFOutputMethod, buffer);

	destroySWFOutput(header);

	// fill swfbuffer with blocklist
	SWFBlockList_writeBlocksToMethod(movie->blockList, SWFOutputMethod, buffer);

#if USE_ZLIB
	if (level >= 0)
	{
		status = compress2 ( (Bytef*) SWFOutput_getBuffer(swfbuffer)+8, &compresslength, SWFOutput_getBuffer(tempbuffer), SWFOutput_getLength(tempbuffer), level);
		if (status == Z_OK) {
			SWFOutput_truncate(swfbuffer, compresslength+8);
			destroySWFOutput(tempbuffer);
		} else SWF_error("compression failed");
	}
#endif // ndef USE_ZLIB
	return swfbuffer;
}