Exemple #1
0
void
SWFShape_drawScaledLine(SWFShape shape, int dx, int dy)
{
    ShapeRecord record;

    if ( shape->isEnded )
        return;

    if ( dx == 0 && dy == 0 )
        return;

    record = newShapeRecord(shape, SHAPERECORD_LINETO);

    SWF_assert(SWFOutput_numSBits(dx) < 18);
    SWF_assert(SWFOutput_numSBits(dy) < 18);

    record.record.lineTo->dx = dx;
    record.record.lineTo->dy = dy;

    shape->xpos += dx;
    shape->ypos += dy;

    SWFRect_includePoint(SWFCharacter_getBounds(CHARACTER(shape)),
                         shape->xpos, shape->ypos, shape->lineWidth);
    SWFRect_includePoint(shape->edgeBounds, shape->xpos, shape->ypos, 0);
}
Exemple #2
0
void writeSWFFontToMethod(SWFBlock block,
			  SWFByteOutputMethod method, void *data)
{
  SWFFont font = (SWFFont)block;
  int offset, i;
  byte *p, *s;

  methodWriteUInt16(CHARACTERID(font), method, data);

  offset = font->nGlyphs*2;

  /* write offset table for glyphs */
  for(i=0; i<font->nGlyphs; ++i)
  {
    methodWriteUInt16(offset, method, data);
    offset += glyphLength(font, font->codeToGlyph[i]);
  }

  /* write shape records for glyphs */
  for(i=0; i<font->nGlyphs; ++i)
  {
    p = font->glyphOffset[font->codeToGlyph[i]];
    s = font->glyphOffset[font->codeToGlyph[i]+1];

    SWF_assert(p < s);

    while(p < s)
      method(*(p++), data);
  }
}
Exemple #3
0
static void
finishBrowserFont(SWFBrowserFont font)
{
	unsigned int i;
	SWFOutput out;
	SWF_assert(BLOCK(font)->swfVersion);

	out = newSWFOutput();
	font->out = out;

	SWFOutput_writeUInt16(out, CHARACTERID(font));
	if(BLOCK(font)->swfVersion > 5)	/* maybe italic or bold flag? */
		SWFOutput_writeUInt8(out, SWF_FONT_WIDECODES);
	else
	 	SWFOutput_writeUInt8(out, 0);

	SWFOutput_writeUInt8(out, 0); /* reserved flags */
	SWFOutput_writeUInt8(out, strlen(font->name));

	for ( i=0; i<strlen(font->name); ++i )
		SWFOutput_writeUInt8(out, font->name[i]);

	SWFOutput_writeUInt16(out, 0); /* number of glyphs */
	SWFOutput_writeSInt16(out, 2); /* offset */

	SWFOutput_byteAlign(out);
}
static void subdivideCubicRight(cubic *New, cubic *old, float t)
{
	SWF_assert(t>0.0 && t<1.0);

	if(New != old)
		memcpy(New, old, sizeof(cubic));

	New->a.x = t*New->a.x + (1-t)*New->b.x;
	New->a.y = t*New->a.y + (1-t)*New->b.y;
	New->b.x = t*New->b.x + (1-t)*New->c.x;
	New->b.y = t*New->b.y + (1-t)*New->c.y;
	New->c.x = t*New->c.x + (1-t)*New->d.x;
	New->c.y = t*New->c.y + (1-t)*New->d.y;

	New->a.x = t*New->a.x + (1-t)*New->b.x;
	New->a.y = t*New->a.y + (1-t)*New->b.y;
	New->b.x = t*New->b.x + (1-t)*New->c.x;
	New->b.y = t*New->b.y + (1-t)*New->c.y;

	New->a.x = t*New->a.x + (1-t)*New->b.x;
	New->a.y = t*New->a.y + (1-t)*New->b.y;
}
void SWFOutput_writeMorphLineStyles(SWFOutput out,
						SWFLineStyle *lines1, int nLines1,
						SWFLineStyle *lines2, int nLines2)
{
	SWFLineStyle line1, line2;
	int i;

	SWF_assert(nLines1 == nLines2);

	if(nLines1<255)
		SWFOutput_writeUInt8(out, nLines1);
	else
	{
		SWFOutput_writeUInt8(out, 255);
		SWFOutput_writeUInt16(out, nLines1);
	}

	for(i=0; i<nLines1; ++i)
	{
		line1 = lines1[i];
		line2 = lines2[i];

		SWFOutput_writeUInt16(out, line1->width);
		SWFOutput_writeUInt16(out, line2->width);
		SWFOutput_writeUInt8(out, line1->r);
		SWFOutput_writeUInt8(out, line1->g);
		SWFOutput_writeUInt8(out, line1->b);
		SWFOutput_writeUInt8(out, line1->a);
		SWFOutput_writeUInt8(out, line2->r);
		SWFOutput_writeUInt8(out, line2->g);
		SWFOutput_writeUInt8(out, line2->b);
		SWFOutput_writeUInt8(out, line2->a);

		++line1;
		++line2;
	}
}
Exemple #6
0
void
SWFShape_writeShapeRecord(SWFShape shape, ShapeRecord record, SWFOutput out)
{
    switch(record.type)
    {
    case SHAPERECORD_STATECHANGE:
    {
        int flags = record.record.stateChange->flags;

        if(flags == 0)
            return;

        SWFOutput_writeBits(out, flags, 6);

        if(flags & SWF_SHAPE_MOVETOFLAG)
        {
            int x = record.record.stateChange->moveToX;
            int y = record.record.stateChange->moveToY;
            int nBits = max(SWFOutput_numSBits(x), SWFOutput_numSBits(y));

            SWF_assert(nBits<32);
            SWFOutput_writeBits(out, nBits, 5);
            SWFOutput_writeSBits(out, x, nBits);
            SWFOutput_writeSBits(out, y, nBits);
        }

        if(flags & SWF_SHAPE_FILLSTYLE0FLAG)
        {
            SWFOutput_writeBits(out, record.record.stateChange->leftFill,
                                SWFOutput_numBits(shape->nFills));
        }

        if(flags & SWF_SHAPE_FILLSTYLE1FLAG)
        {
            SWFOutput_writeBits(out, record.record.stateChange->rightFill,
                                SWFOutput_numBits(shape->nFills));
        }

        if(flags & SWF_SHAPE_LINESTYLEFLAG)
        {
            SWFOutput_writeBits(out, record.record.stateChange->line,
                                SWFOutput_numBits(shape->nLines));
        }

        /* newstyle's never used.	 But this is what it looks like:

        if ( flags & SWF_SHAPE_NEWSTYLEFLAG )
        {
        	SWFOutput_writeFillStyles(shape->out, shape->fills, shape->nFills,
        	BLOCK(shape)->type);

        	SWFOutput_writeLineStyles(shape->out, shape->lines, shape->nLines,
        		BLOCK(shape)->type);

        	SWFOutput_writeBits(shape->out, SWFOutput_numBits(shape->nFills), 4);
        	SWFOutput_writeBits(shape->out, SWFOutput_numBits(shape->nLines), 4);
        }

        */

        break;
    }

    case SHAPERECORD_LINETO:
    {
        int nBits;
        int dx = record.record.lineTo->dx;
        int dy = record.record.lineTo->dy;

        SWFOutput_writeBits(out, 3, 2); /* straight edge */

        if(dx==0)
        {
            nBits = SWFOutput_numSBits(dy);
            SWF_assert(nBits<18);
            SWFOutput_writeBits(out, nBits-2, 4);
            SWFOutput_writeBits(out, 1, 2); /* vertical line */
            SWFOutput_writeSBits(out, dy, nBits);
        }
        else if(dy==0)
        {
            nBits = SWFOutput_numSBits(dx);
            SWF_assert(nBits<18);
            SWFOutput_writeBits(out, nBits-2, 4);
            SWFOutput_writeBits(out, 0, 2); /* horizontal line */
            SWFOutput_writeSBits(out, dx, nBits);
        }
        else
        {
            nBits = max(SWFOutput_numSBits(dx), SWFOutput_numSBits(dy));
            SWF_assert(nBits<18);
            SWFOutput_writeBits(out, nBits-2, 4);
            SWFOutput_writeBits(out, 1, 1); /* general line */
            SWFOutput_writeSBits(out, dx, nBits);
            SWFOutput_writeSBits(out, dy, nBits);
        }

        break;
    }

    case SHAPERECORD_CURVETO:
    {
        int controlx = record.record.curveTo->controlx;
        int controly = record.record.curveTo->controly;
        int anchorx = record.record.curveTo->anchorx;
        int anchory = record.record.curveTo->anchory;

        int nBits = max(max(SWFOutput_numSBits(controlx),
                            SWFOutput_numSBits(controly)),
                        max(SWFOutput_numSBits(anchorx),
                            SWFOutput_numSBits(anchory)));

        if ( nBits < 2 )
            nBits = 2;

        SWF_assert(nBits < 18);

        SWFOutput_writeBits(out, 2, 2); /* curved edge */
        SWFOutput_writeBits(out, nBits-2, 4);
        SWFOutput_writeSBits(out, controlx, nBits);
        SWFOutput_writeSBits(out, controly, nBits);
        SWFOutput_writeSBits(out, anchorx, nBits);
        SWFOutput_writeSBits(out, anchory, nBits);

        break;
    }

    default:
        SWF_error("Unknown shapeRecordType");
    }
}
Exemple #7
0
void
SWFShape_writeShapeRecord(SWFShape shape, ShapeRecord record)
{
	SWFOutput out = shape->out;

	switch(record.type)
	{
		case SHAPERECORD_STATECHANGE:
		{
			int flags = record.record.stateChange->flags;

			if(flags == 0)
				return;

			SWFOutput_writeBits(out, flags, 6);

			if(flags & SWF_SHAPE_MOVETOFLAG)
			{
				int x = record.record.stateChange->moveToX;
				int y = record.record.stateChange->moveToY;
				int nBits = max(SWFOutput_numSBits(x), SWFOutput_numSBits(y));

				SWF_assert(nBits<32);
				SWFOutput_writeBits(out, nBits, 5);
				SWFOutput_writeSBits(out, x, nBits);
				SWFOutput_writeSBits(out, y, nBits);
			}

			if(flags & SWF_SHAPE_FILLSTYLE0FLAG)
			{
				SWFOutput_writeBits(out, record.record.stateChange->leftFill,
														SWFOutput_numBits(shape->nFills2));
			}

			if(flags & SWF_SHAPE_FILLSTYLE1FLAG)
			{
				SWFOutput_writeBits(out, record.record.stateChange->rightFill,
														SWFOutput_numBits(shape->nFills2));
			}

			if(flags & SWF_SHAPE_LINESTYLEFLAG)
			{
				SWFOutput_writeBits(out, record.record.stateChange->line,
														SWFOutput_numBits(shape->nLines2));
			}

			/* newstyle's never used.	 But this is what it looks like: */

			if ( flags & SWF_SHAPE_NEWSTYLEFLAG )
			{
				int i;

				shape->lines = &record.record.stateChange->lines;
				shape->fills = &record.record.stateChange->fills;
				shape->nLines = &record.record.stateChange->nLines;
				shape->nFills = &record.record.stateChange->nFills;
				shape->nFills2 = *shape->nFills;
				shape->nLines2 = *shape->nLines;

				SWFOutput_writeFillStyles(shape->out, *shape->fills, *shape->nFills,
				BLOCK(shape)->type);

				SWFOutput_writeLineStyles(shape->out, *shape->lines, *shape->nLines,
					BLOCK(shape)->type);

				SWFOutput_writeBits(shape->out, SWFOutput_numBits(*shape->nFills), 4);
				SWFOutput_writeBits(shape->out, SWFOutput_numBits(*shape->nLines), 4);

				for ( i=0; i<*shape->nFills; ++i )
				{
					SWFMatrix matrix = SWFFillStyle_getMatrix((*shape->fills)[i]);

					if ( matrix != NULL )
						destroySWFMatrix(matrix);

					/* gradients and bitmaps are destroyed separately */

					free((*shape->fills)[i]);
				}

				if ( *shape->fills != NULL )
					free(*shape->fills);

				for ( i=0; i<*shape->nLines; ++i )
					free((*shape->lines)[i]);

				if ( *shape->lines != NULL )
					free(*shape->lines);
			}

			break;
		}

		case SHAPERECORD_LINETO:
		{
			int nBits;
			int dx = record.record.lineTo->dx;
			int dy = record.record.lineTo->dy;

			SWFOutput_writeBits(out, 3, 2); /* straight edge */

			if(dx==0 && dy!=0)
			{
				nBits = SWFOutput_numSBits(dy);
				SWF_assert(nBits<18);
				SWFOutput_writeBits(out, nBits-2, 4);
				SWFOutput_writeBits(out, 1, 2); /* vertical line */
				SWFOutput_writeSBits(out, dy, nBits);
			}
			else if(dy==0 && dx!=0)
			{
				nBits = SWFOutput_numSBits(dx);
				SWF_assert(nBits<18);
				SWFOutput_writeBits(out, nBits-2, 4);
				SWFOutput_writeBits(out, 0, 2); /* horizontal line */
				SWFOutput_writeSBits(out, dx, nBits);
			}
			else
			{
				nBits = max(SWFOutput_numSBits(dx), SWFOutput_numSBits(dy));
				nBits = max(nBits, 2);
				SWF_assert(nBits<18);
				SWFOutput_writeBits(out, nBits-2, 4);
				SWFOutput_writeBits(out, 1, 1); /* general line */
				SWFOutput_writeSBits(out, dx, nBits);
				SWFOutput_writeSBits(out, dy, nBits);
			}

			break;
		}

		case SHAPERECORD_CURVETO:
		{
			int controlx = record.record.curveTo->controlx;
			int controly = record.record.curveTo->controly;
			int anchorx = record.record.curveTo->anchorx;
			int anchory = record.record.curveTo->anchory;

			int nBits = max(max(SWFOutput_numSBits(controlx),
													SWFOutput_numSBits(controly)),
											max(SWFOutput_numSBits(anchorx),
													SWFOutput_numSBits(anchory)));

			if ( nBits < 2 )
				nBits = 2;

			SWF_assert(nBits < 18);

			SWFOutput_writeBits(out, 2, 2); /* curved edge */
			SWFOutput_writeBits(out, nBits-2, 4);
			SWFOutput_writeSBits(out, controlx, nBits);
			SWFOutput_writeSBits(out, controly, nBits);
			SWFOutput_writeSBits(out, anchorx, nBits);
			SWFOutput_writeSBits(out, anchory, nBits);

			break;
		}

		default:
			SWF_error("Unknown shapeRecordType");
	}
}