*/
BitmapFillNode fillNode = (BitmapFillNode) fill;
// Calculate the bounds of the shape outline (without strokes)
Rect edgeBounds = node.getBounds(shapeRecords, null);
String source = parseSource(fillNode.source);
if (source == null)
{
// Missing source attribute in <BitmapGraphic> or <BitmapFill>.
problems.add(new FXGMissingAttributeProblem(node.getDocumentPath(), node.getStartLine(),
node.getStartColumn(), FXGConstants.FXG_SOURCE_ATTRIBUTE, node.getNodeName()));
return null;
}
DefineImage defImage = createDefineBitsTag(fill, source);
if(defImage == null)
return null;
//process the filters later to avoid masking
List<IFilterNode> filters = null;
if (context.filters != null)
{
filters = context.filters;
context.filters = null;
DefineSpriteTag filterSprite = createDefineSpriteTag("MaskFilter");
spriteStack.push(filterSprite);
}
DefineSpriteTag imageSprite = createDefineSpriteTag("BitmapFill");
spriteStack.push(imageSprite);
// First, generate the clipping mask
DefineSpriteTag clipSprite = createDefineSpriteTag("BitmapFill_Clip");
spriteStack.push(clipSprite);
List<ShapeRecord> clipRectRecords = ShapeHelper.rectangle(0.0, 0.0, defImage.getWidth(), defImage.getHeight());
DefineShapeTag clipShape = createDefineShapeTag(null, clipRectRecords, new SolidColorFillNode(), null, context.getTransform());
FXGMatrix bitmapMatrix = TypeHelper.bitmapFillMatrix(fillNode, defImage, edgeBounds);
FXGMatrix clipMatrix = new FXGMatrix(bitmapMatrix.a, bitmapMatrix.b, bitmapMatrix.c, bitmapMatrix.d, 0, 0);
clipMatrix.scale(1.0/ISWFConstants.TWIPS_PER_PIXEL, 1.0/ISWFConstants.TWIPS_PER_PIXEL);
clipMatrix.translate(bitmapMatrix.tx, bitmapMatrix.ty);
GraphicContext clipContext = new GraphicContext();
clipContext.setTransform(clipMatrix);
PlaceObject3Tag(clipShape, clipContext);
spriteStack.pop();
// Set the depth of the mask to that of the bitmap image fill
clipContext.setTransform(context.getTransform());
PlaceObject3Tag po3clip = PlaceObject3Tag(clipSprite, clipContext);
po3clip.setClipDepth(po3clip.getDepth() + 1);
po3clip.setHasClipDepth(true);
Styles styles = new Styles(new FillStyleArray(), new LineStyleArray());
// Then, process the bitmap image fill
ShapeWithStyle sws = new ShapeWithStyle(styles);
int lineStyleIndex = 0;
int fillStyle0Index = 1;
int fillStyle1Index = 0;
FillStyle fillStyle = createFillStyle(fill, edgeBounds);
if(fillStyle != null)
sws.getFillStyles().add(fillStyle);
if (windings.length > 0)
ShapeHelper.setPathStyles(shapeRecords, lineStyleIndex, fillStyle0Index, fillStyle1Index, styles);
else
ShapeHelper.setStyles(shapeRecords, lineStyleIndex, fillStyle0Index, fillStyle1Index, styles);
sws.addShapeRecords(shapeRecords);
DefineShape4Tag imageShape = new DefineShape4Tag();
imageShape.setShapes(sws);
imageShape.setShapeBounds(edgeBounds);
imageShape.setEdgeBounds(edgeBounds);
if ((fill != null) &&( windings.length > 0))
{
Winding windingValue = windings[0];
imageShape.setUsesFillWindingRule(windingValue == Winding.NON_ZERO);
}
PlaceObject3Tag po3 = PlaceObject3Tag(imageShape, context);
if (stroke != null)
{
//make a copy of ShapeRecord for strokes
ArrayList<ShapeRecord> shapeRecords2 = new ArrayList<ShapeRecord>(shapeRecords);
Collections.copy(shapeRecords2, shapeRecords);
Styles strokeStyles = new Styles(new FillStyleArray(), new LineStyleArray());
//generate the define sprite for the stroke object with no clipping
ShapeWithStyle swsStroke = new ShapeWithStyle(strokeStyles);
// Consider linestyle stroke widths with bounds calculation
AbstractStrokeNode strokeNode = (AbstractStrokeNode) stroke;
LineStyle ls = createGenericLineStyle(strokeNode);
Rect shapeBounds = node.getBounds(shapeRecords2, ls);
LineStyle lineStyle = createLineStyle(stroke, shapeBounds);
swsStroke.getLineStyles().add(lineStyle);
lineStyleIndex = 1;