*/
public static Rect getBounds(List records, List lineStyles)
{
if (records == null || records.size() == 0)
{
return new Rect();
}
else
{
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int x = 0;
int y = 0;
boolean firstMove = true;
Iterator it = records.iterator();
while (it.hasNext())
{
ShapeRecord r = (ShapeRecord)it.next();
if (r == null)
continue;
if (r instanceof StyleChangeRecord)
{
StyleChangeRecord scr = (StyleChangeRecord)r;
x = scr.moveDeltaX;
y = scr.moveDeltaY;
if (firstMove)
{
x1 = x;
y1 = y;
x2 = x;
y2 = y;
firstMove = false;
}
}
else if (r instanceof StraightEdgeRecord)
{
StraightEdgeRecord ser = (StraightEdgeRecord)r;
x = x + ser.deltaX;
y = y + ser.deltaY;
}
else if (r instanceof CurvedEdgeRecord)
{
CurvedEdgeRecord cer = (CurvedEdgeRecord)r;
x = x + cer.controlDeltaX + cer.anchorDeltaX;
y = y + cer.controlDeltaY + cer.anchorDeltaY;
}
if (x < x1) x1 = x;
if (y < y1) y1 = y;
if (x > x2) x2 = x;
if (y > y2) y2 = y;
}
if (lineStyles != null && lineStyles.size() > 0)
{
it = lineStyles.iterator();
int width = SwfConstants.TWIPS_PER_PIXEL;
while (it.hasNext())
{
LineStyle ls = (LineStyle)it.next();
if (ls == null)
continue;
else
{
if (width < ls.width)
width = ls.width;
}
}
double stroke = (int)Math.rint(width * 0.5);
x1 = (int)Math.rint(x1 - stroke);
y1 = (int)Math.rint(y1 - stroke);
x2 = (int)Math.rint(x2 + stroke);
y2 = (int)Math.rint(y2 + stroke);
}
return new Rect(x1, x2, y1, y2);
}
}