transform-swf icon indicating copy to clipboard operation
transform-swf copied to clipboard

NPE on Shape.shapeFromData(ShapeData)

Open maltaisn opened this issue 5 years ago • 0 comments

DefineFont glyph shapes aren't decoded automatically. Instead, Shape.shapeFromData(ShapeData) must be used on the only ShapeData record in the glyph shape to get the glyph path. However this method throws a NullPointerException.

The NPE is caused because the method creates a new context without a registry. By setting a registry, another NPE is thrown, because context has no active tag ID being decoded. So an arbitrary tag is set, in this case I found that MovieTypes.DEFINE_SHAPE works.

public Shape shapeFromData(ShapeData shapeData) {
    Context context = new Context();
    context.setRegistry(DecoderRegistry.getDefault());
    context.put(Context.TYPE, MovieTypes.DEFINE_SHAPE);
    ByteArrayInputStream stream = new ByteArrayInputStream(shapeData.getData());
    SWFDecoder coder = new SWFDecoder(stream);
    return new Shape(coder, context);
}

This project seems pretty much dead so I won't make a pull request.

maltaisn avatar Jan 25 '20 00:01 maltaisn