Beispiel #1
0
void printMorphShape(FILE *f, int length)
{
  int offset, start = fileOffset, here;
  struct Rect r;
  struct Shape shape1, shape2;
  int id = readUInt16(f);

  printf("\n\t### Morph %i ###\n", id);
  printf("\t$s%i = new SWF::Morph();\n", id);

  readRect(f, &r); /* bounds 1 */
  readRect(f, &r); /* bounds 2 */

  offset = readUInt32(f);

  here = fileOffset+1;

  memset(&shape1, 0, sizeof(struct Shape));
  memset(&shape2, 0, sizeof(struct Shape));

  shape1.shapeType = shape2.shapeType = DEFINESHAPE3;

  readFillStyleArray(f, &shape1, 1);
  readLineStyleArray(f, &shape1, 1);

  byteAlign();

  shape1.fillBits = shape2.fillBits = readBits(f,4);
  shape1.lineBits = shape2.lineBits = readBits(f,4);

  while(fileOffset < here+offset &&
	readShapeRec(f, &shape1)) ;

  printf("\n\t$s%i_1 = $s%i->getShape1();\n", id, id);

  printDefineShape(&shape1, id, 0);

  byteAlign();

  readUInt8(f); /* redundant fill/line bits */

  while(fileOffset < start+length &&
	readShapeRec(f, &shape2)) ;

  printf("\n\t$s%i_2 = $s%i->getShape2();\n", id, id);

  printDefineShape(&shape1, id, 1);
}
Beispiel #2
0
void printCXForm(FILE *f, boolean hasAlpha)
{
  int hasAdd, hasMult, nBits;

  byteAlign();

  hasAdd = readBits(f, 1);
  hasMult = readBits(f, 1);
  nBits = readBits(f, 4);

  if(hasMult)
  {
    puts("x(");
    printf("%i,", readSBits(f, nBits));
    printf("%i,", readSBits(f, nBits));
    printf("%i)", readSBits(f, nBits));
    if(hasAlpha)
      printf("%i,", readSBits(f, nBits));
  }
  else puts("x()");

  if(hasAdd)
  {
    puts("+(");
    printf("%i,", readSBits(f, nBits));
    printf("%i,", readSBits(f, nBits));
    printf("%i)", readSBits(f, nBits));
    if(hasAlpha)
      printf("%i,", readSBits(f, nBits));
  }
  else puts("+()");

  putchar('\n');
}
Beispiel #3
0
void printMatrix(FILE *f)
{
  int nBits;
  float num;

  byteAlign();

  if(readBits(f, 1)) /* has scale */
  {
    nBits = readBits(f, 5);
    num = (float)readSBits(f, nBits)/0x10000;
    println("xScale: %f", num);
    num = (float)readSBits(f, nBits)/0x10000;
    println("yScale: %f", num);
  }
  if(readBits(f, 1)) /* has rotate */
  {
    nBits = readBits(f, 5);
    num = (float)readSBits(f, nBits)/0x10000;
    println("rotate0: %f", num);
    num = (float)readSBits(f, nBits)/0x10000;
    println("rotate1: %f", num);
  }

  nBits = readBits(f, 5);
  println("x: %i", readSBits(f, nBits));
  println("y: %i", readSBits(f, nBits));
}
Beispiel #4
0
void printShape(FILE *f, int length, SWFBlocktype type)
{
  int start = fileOffset;
  int fillBits, lineBits;

  println("ShapeID: %i", readUInt16(f));

  print("Bounds: ");
  printRect(f);

  putchar('\n');
  putchar('\n');

  printFillStyleArray(f, type);
  printLineStyleArray(f, type);

  putchar('\n');

  byteAlign();

  fillBits = readBits(f,4);
  lineBits = readBits(f,4);

  while(fileOffset < length+start &&
	printShapeRec(f, &lineBits, &fillBits, type)) ;

  /* go for end tag..
  if(fileOffset == length+start && bufbits > 5)
    printShapeRec(f, &lineBits, &fillBits, type);
  */

  putchar('\n');
}
Beispiel #5
0
void printShape(FILE *f, int length, int shapeType)
{
  struct Shape shape;
  int id, start = fileOffset;

  memset(&shape, 0, sizeof(struct Shape));

  id = readUInt16(f);

  shape.shapeType = shapeType;

  readRect(f, &(shape.bounds)); /* bounds */

  readFillStyleArray(f, &shape, 0);
  readLineStyleArray(f, &shape, 0);

  byteAlign();

  shape.fillBits = readBits(f,4);
  shape.lineBits = readBits(f,4);

  while(fileOffset < length+start &&
	readShapeRec(f, &shape)) ;

  /* go for end tag..
  if(fileOffset == length+start && bufbits > 5)
    printShapeRec(f, &lineBits, &fillBits, 2);
  */

  printf("\n\t### Shape %i ###\n", id);
  printf("\t$s%i = new SWF::Shape();\n", id);

  printDefineShape(&shape, id, 0);
}
Beispiel #6
0
void readMatrix(FILE *f, struct Matrix *s)
{
  int nBits;

  byteAlign();

  if(readBits(f, 1)) /* has scale */
  {
    nBits = readBits(f, 5);
    s->xScale = (float)readSBits(f, nBits)/0x10000;
    s->yScale = (float)readSBits(f, nBits)/0x10000;
  }
  else
    s->xScale = s->yScale = 1.0;

  if(readBits(f, 1)) /* has rotate */
  {
    nBits = readBits(f, 5);
    s->rot0 = (float)readSBits(f, nBits)/0x10000;
    s->rot1 = (float)readSBits(f, nBits)/0x10000;
  }
  else
    s->rot0 = s->rot1 = 0;

  nBits = readBits(f, 5);
  s->x = readSBits(f, nBits);
  s->y = readSBits(f, nBits);
}
Beispiel #7
0
void readRect(FILE *f, struct Rect *s)
{
  int nBits;

  byteAlign();

  nBits = readBits(f, 5);
  s->xMin = readSBits(f, nBits);
  s->xMax = readSBits(f, nBits);
  s->yMin = readSBits(f, nBits);
  s->yMax = readSBits(f, nBits);
}
Beispiel #8
0
void printRect(FILE *f)
{
  int nBits, xMin, xMax, yMin, yMax;

  byteAlign();

  nBits = readBits(f, 5);
  xMin = readSBits(f, nBits);
  xMax = readSBits(f, nBits);
  yMin = readSBits(f, nBits);
  yMax = readSBits(f, nBits);

  printf("(%i,%i)x(%i,%i)", xMin, xMax, yMin, yMax);
}
Beispiel #9
0
void readCXForm(FILE *f, struct CXForm *s, boolean hasAlpha)
{
  int hasAdd, hasMult, nBits;

  byteAlign();

  hasAdd = readBits(f, 1);
  hasMult = readBits(f, 1);
  nBits = readBits(f, 4);

  if(hasMult)
  {
    s->rMult = readSBits(f, nBits);
    s->gMult = readSBits(f, nBits);
    s->bMult = readSBits(f, nBits);

    if(hasAlpha)
      s->aMult = readSBits(f, nBits);
    else
      s->aMult = 0x100;
  }
  else
  {
    s->aMult = 0x100;
    s->rMult = 0x100;
    s->gMult = 0x100;
    s->bMult = 0x100;
  }

  if(hasAdd)
  {
    s->rAdd = readSBits(f, nBits);
    s->gAdd = readSBits(f, nBits);
    s->bAdd = readSBits(f, nBits);

    if(hasAlpha)
      s->aAdd = readSBits(f, nBits);
    else
      s->aAdd = 0;
  }
  else
  {
    s->aAdd = 0;
    s->rAdd = 0;
    s->gAdd = 0;
    s->bAdd = 0;
  }
}
Beispiel #10
0
void printDefineText(FILE *f, int length, int type) /* type 2 allows transparency */
{
  int glyphBits, advanceBits, end = fileOffset+length;

  println("character id: %i", readUInt16(f));
  print("bounds: ");
  printRect(f);
  putchar('\n');
  byteAlign();
  println("matrix:");
  printMatrix(f);
  glyphBits = readUInt8(f);
  advanceBits = readUInt8(f);

  while(fileOffset < end &&
	printTextRecord(f, glyphBits, advanceBits, type)) ;
}
Beispiel #11
0
void printDefineFont(FILE *f, int length)
{
  int here, off0, off, i, nShapes, fillBits=1, lineBits=1;
  int *offset;

  println("FontID: %i", readUInt16(f));

  off0 = readUInt16(f);

  nShapes = off0/2;
  println("Number of shapes: %i", nShapes);

  offset = (int *)malloc(nShapes*sizeof(int));

  ++gIndent;
  println("Offset0: 0");

  for(i=1; i<nShapes; ++i)
  {
    off = readUInt16(f);
    offset[i-1] = off-off0;
    println("Offset%i: %i", i, offset[i-1]);
  }
  offset[nShapes-1] = length-2-(nShapes*2);

  here = fileOffset;

  for(i=0; i<nShapes; ++i)
  {
    putchar('\n');

    byteAlign();
    println("Shape %i:", i);

    fillBits = readBits(f, 4);
    lineBits = readBits(f, 4);

    ++gIndent;
    while(fileOffset < here+offset[i])
      printShapeRec(f, &fillBits, &lineBits, 2);
    --gIndent;
  }

  --gIndent;
}
Beispiel #12
0
void printMorphShape(FILE *f, int length)
{
  int offset, start = fileOffset;
  int fillBits, lineBits, here;

  println("ShapeID: %i", readUInt16(f));

  print("Bounds1: ");
  printRect(f);
  putchar('\n');
  print("Bounds2: ");
  printRect(f);
  putchar('\n');

  offset = readUInt32(f);
  println("(%i)\toffset = %i", fileOffset, offset);

  here = fileOffset;

  printFillStyleArray(f, SWF_DEFINEMORPHSHAPE);
  printLineStyleArray(f, SWF_DEFINEMORPHSHAPE);

  fillBits = readBits(f, 4);
  lineBits = readBits(f, 4);

  putchar('\n');
  println("Shape1:");
  while(fileOffset < here+offset)
    printShapeRec(f, &lineBits, &fillBits, SWF_DEFINESHAPE3);

  byteAlign();

  /* ??? */
  fillBits = readBits(f, 4);
  lineBits = readBits(f, 4);

  putchar('\n');
  println("Shape2:");
  while(fileOffset < start+length)
    printShapeRec(f, &lineBits, &fillBits, SWF_DEFINESHAPE3);
}
Beispiel #13
0
void
SWFShape_drawScaledGlyph(SWFShape shape,
												 SWFFont font, unsigned short c, int size)
{
	byte *p = SWFFont_findGlyph(font, c);
	byte **f = &p;

	int moveBits, x=0, y=0;
	int straight, numBits;
	int numFillBits, numLineBits;

	/* moveTos in the record are absolute, but we want to draw from the current
		 location. grr. */

	int startX = shape->xpos;
	int startY = shape->ypos;
	int style;

	byteAlign();

	if ( (numFillBits = readBitsP(f, 4)) != 1 ) /* fill bits */
		SWF_error("SWFShape_drawGlyph: bad file format (was expecting fill bits = 1)");

	if ( (numLineBits = readBitsP(f, 4)) > 1 ) /* line bits */
		SWF_error("SWFShape_drawGlyph: bad file format (was expecting line bits = 0)");

	/* now we get to parse the shape commands.	Oh boy.
		 the first one will be a non-edge block- grab the moveto loc */

	readBitsP(f, 2); /* type 0, newstyles */
	style = readBitsP(f, 3);

	if(readBitsP(f, 1))
	{	moveBits = readBitsP(f, 5);
		x = startX + readSBitsP(f, moveBits);
		y = startY + readSBitsP(f, moveBits);
	}
	else if(style == 0)	/* no style, no move => space character */
		return;

	SWFShape_moveScaledPenTo(shape, x*size/1024, y*size/1024);

	if ( style & 1 )
		if ( readBitsP(f, numFillBits) != 0 ) /* fill0 = 0 */
			SWF_error("SWFFont_getShape: bad file format (was expecting fill0 = 0)");
	if ( style & 2 )
		if ( readBitsP(f, numFillBits) != 1 ) /* fill1 = 1 */
			SWF_error("SWFFont_getShape: bad file format (was expecting fill1 = 1)");
	if ( style & 4 )
		if ( readBitsP(f, numLineBits) != 0 ) /* line = 1 */
			SWF_error("SWFFont_getShape: bad file format (was expecting line = 0)");

	/* translate the glyph's shape records into drawing commands */

	for ( ;; )
	{
		if ( readBitsP(f, 1) == 0 )
		{
			/* it's a moveTo or a shape end */

			if ( readBitsP(f, 5) == 0 )
				break;

			moveBits = readBitsP(f, 5);
			x = startX + readSBitsP(f, moveBits);
			y = startY + readSBitsP(f, moveBits);

			SWFShape_moveScaledPenTo(shape, x*size/1024, y*size/1024);

			continue;
		}

		straight = readBitsP(f, 1);
		numBits = readBitsP(f, 4)+2;

		if ( straight==1 )
		{
			if ( readBitsP(f, 1) ) /* general line */
			{
				x += readSBitsP(f, numBits);
				y += readSBitsP(f, numBits);
			}
			else
			{
				if ( readBitsP(f, 1) ) /* vert = 1 */
					y += readSBitsP(f, numBits);
				else
					x += readSBitsP(f, numBits);
			}

			SWFShape_drawScaledLineTo(shape, x*size/1024, y*size/1024);
		}
		else
		{
			int controlX = readSBitsP(f, numBits);
			int controlY = readSBitsP(f, numBits);
			int anchorX = readSBitsP(f, numBits);
			int anchorY = readSBitsP(f, numBits);

			SWFShape_drawScaledCurveTo(shape,
				 (x+controlX)*size/1024,
				 (y+controlY)*size/1024,
				 (x+controlX+anchorX)*size/1024,
				 (y+controlY+anchorY)*size/1024);

			x += controlX + anchorX;
			y += controlY + anchorY;
		}
	}

	/* no idea where the pen was left */
	SWFShape_moveScaledPenTo(shape, startX, startY);
}
Beispiel #14
0
void printDefineFont2(FILE *f, int length)
{
  int flags, nGlyphs, namelen, i, fillBits, lineBits;
  int here = fileOffset;
  int *offset;

  println("fontID: %i", readUInt16(f));

  flags = readUInt8(f);

  readUInt8(f); /* "reserved" */

  namelen = readUInt8(f);

  print("Font Name: ");

  for(; namelen>0; --namelen)
    putchar((unsigned char)readUInt8(f));

  putchar('\n');

  nGlyphs = readUInt16(f);
  println("number of glyphs: %i\n", nGlyphs);

  offset = (unsigned int *)malloc(nGlyphs*sizeof(int));

  /* offset table */

  here = fileOffset;

  for(i=0; i<=nGlyphs; ++i)
  {
    if(flags & FONTINFO2_WIDEOFFSETS)
      offset[i] = readUInt32(f)-4*nGlyphs-2;
    else
      offset[i] = readUInt16(f)-2*nGlyphs-2;

    println("Offset%i: %i", i, offset[i]);
  }

  here = fileOffset;

  /* shape table */
  for(i=0; i<nGlyphs; ++i)
  {
    byteAlign();
    println("Glyph %i:", i);

    fillBits = readBits(f, 4);
    lineBits = readBits(f, 4);

    byteAlign();
    while(printShapeRec(f, &fillBits, &lineBits, 2)) ;

    putchar('\n');
  }

  /* code table */
  for(i=0; i<nGlyphs; ++i)
  {
    if(flags & FONTINFO2_WIDECODES)
      println("glyph code %i: %i", i, readUInt16(f));
    else
      println("glyph code %i: %i", i, readUInt8(f));
  }

  if(flags & FONTINFO2_HASLAYOUT)
  {
    int kernCount, code1, code2;

    println("ascender height: %i", readSInt16(f));
    println("descender height: %i", readSInt16(f));
    println("leading height: %i", readSInt16(f));

    for(i=0; i<nGlyphs; ++i)
      printf("\tadvance %i: %i\n", i, readSInt16(f));

    for(i=0; i<nGlyphs; ++i)
    {
      print("bounds %i: ", i);
      printRect(f);
      putchar('\n');
    }

    kernCount = readUInt16(f);

    for(i=0; i<kernCount; ++i)
    {
      code1 = (flags & FONTINFO2_WIDECODES) ? readUInt16(f) : readUInt8(f);
      code2 = (flags & FONTINFO2_WIDECODES) ? readUInt16(f) : readUInt8(f);
      println("(%i,%i): adjustment = %i", code1, code2, readSInt16(f));
    }
  }
}