return po3;
}
protected PlaceObject mask(MaskableNode node, DefineSprite parentSprite)
{
PlaceObject po3 = null;
MaskingNode mask = node.getMask();
if (mask instanceof GroupNode)
{
// According to FXG Spec.: The masking element inherits the target
// group's coordinate space, as though it were a direct child
// element. In the case when mask is inside a shape, it doesn't
// automatically inherit the coordinates from the shape node
// but inherits from its parent node which is also parent of
// the shape node. To fix it, specifically concatenating the
// shape node matrix to the masking node matrix.
if (!(node instanceof GroupNode || node instanceof GraphicNode))
{
FXGMatrix nodeMatrix = null;
MatrixNode matrixNodeShape = ((GraphicContentNode)node).matrix;
if (matrixNodeShape == null)
// Convert shape node's discreet transform attributes to
// matrix.
nodeMatrix = FXGMatrix.convertToMatrix(((GraphicContentNode)node).scaleX, ((GraphicContentNode)node).scaleY, ((GraphicContentNode)node).rotation, ((GraphicContentNode)node).x, ((GraphicContentNode)node).y);
else
nodeMatrix = new FXGMatrix(matrixNodeShape);
// Get masking node matrix.
MatrixNode matrixNodeMasking = ((GraphicContentNode)mask).matrix;
// Create a new MatrixNode if the masking node doesn't have one.
if (matrixNodeMasking == null)
{
// Convert masking node's transform attributes to matrix
// so we can concatenate the shape node's matrix to it.
((GraphicContentNode)mask).convertTransformAttrToMatrix();
matrixNodeMasking = ((GraphicContentNode)mask).matrix;
}
FXGMatrix maskMatrix = new FXGMatrix(matrixNodeMasking);
// Concatenate the shape node's matrix to the masking node's
// matrix.
maskMatrix.concat(nodeMatrix);
// Set the masking node's matrix with the concatenated values.
maskMatrix.setMatrixNodeValue(matrixNodeMasking);
}
markLeafNodesAsMask(node, (GroupNode) mask);
po3 = group((GroupNode)mask);
}
else if (mask instanceof PlaceObjectNode)
{
po3 = placeObjectInstance((PlaceObjectNode)mask);
}
if (po3 != null)
{
int clipDepth = 1;
// If we had a graphic or group, clip the depths for all children.
if (node instanceof GroupNode)
{
GroupNode group = (GroupNode)node;
if (group.children != null)
clipDepth = parentSprite.depthCounter + group.children.size();
}
else if (node instanceof GraphicNode)
{
GraphicNode graphic = (GraphicNode)node;
if (graphic.children != null)
clipDepth = parentSprite.depthCounter + graphic.children.size();
}
// ... otherwise, just clip the shape itself.
else
{
clipDepth = po3.depth + 1;
}
po3.setClipDepth(clipDepth);
if (node.getMaskType() == MaskType.ALPHA)
{
po3.setCacheAsBitmap(true);
}
}
return po3;
}