protected void renderAppearanceStream(Graphics2D g) {
        Object AP = getObject(APPEARANCE_STREAM_KEY);
        if (AP instanceof Hashtable) {
            Object N = library.getObject(
                    (Hashtable) AP, APPEARANCE_STREAM_NORMAL_KEY.getName());
            if (N instanceof Hashtable) {
                Object AS = getObject(APPEARANCE_STATE_KEY);
                if (AS != null)
                    N = library.getObject((Hashtable) N, AS.toString());
            }

            Shapes shapes = null;
            AffineTransform matrix = null;
            Rectangle2D bbox = null;
            // n should be a Form but we have a few cases of Stream
            if (N instanceof Form) {
                Form form = (Form) N;
                form.init();
                shapes = form.getShapes();
                matrix = form.getMatrix();
                bbox = form.getBBox();
            } else if (N instanceof Stream) {

                Stream stream = (Stream) N;
                Resources res = library.getResources(stream.getEntries(), "Resources");
                bbox = library.getRectangle(stream.getEntries(), "BBox");
                matrix = new AffineTransform();
                InputStream sis = stream.getInputStreamForDecodedStreamBytes();
                try {
                    ContentParser cp = new ContentParser(library, res);
                    shapes = cp.parse(sis);
                } catch (Exception e) {
                    shapes = new Shapes();
                    logger.log(Level.FINE, "Error initializing Page.", e);
                } finally {
                    try {
                        sis.close();
                    } catch (IOException e) {
                        logger.log(Level.FINE, "Error closing page stream.", e);
                    }
                }
            }
            if (shapes != null) {
//g.setColor( Color.blue );
//Rectangle2D.Double newRect = deriveDrawingRectangle();
//g.draw( newRect );


                // step 1. appearance bounding box (BBox) is transformed, using
                // Matrix, to produce a quadrilateral with arbitrary orientation.
                Rectangle2D tBbox = matrix.createTransformedShape(bbox).getBounds2D();

                // Step 2. matrix a is computed that scales and translates the
                // transformed appearance box (tBbox) to align with the edges of
                // the annotation's rectangle (Ret).
                Rectangle2D rect = getUserSpaceRectangle();
                AffineTransform tAs = AffineTransform.getScaleInstance(
                        (rect.getWidth() / tBbox.getWidth()),
                        (rect.getHeight() / tBbox.getHeight()));
                // something not quite right here.
//                AffineTransform tAt = AffineTransform.getTranslateInstance(
//                        (tBbox.getX() - rect.getX()),
//                        (tBbox.getY() - rect.getY()));
//                tAs.concatenate(tAt);
                // Step 3. matrix is concatenated with A to form a matrix AA
                // that maps from the appearance's coordinate system to the
                // annotation's rectangle in default user space.
                tAs.concatenate(matrix);
                g.transform(tAs);

//System.out.println("Form: " + form.getEntries());
//String str = new String( form.getBytes() );
//System.out.println( str );
//System.out.println("Shapes: " + shapes + "  count: " + shapes.getShapesCount());
                // check to see if we are painting highlight annotations.
                // if so we add some transparency to the context.
                boolean isTransparency = Defs.sysPropertyBoolean("org.icepdf.core.paint.disableAlpha");
                if (subtype != null && SUBTYPE_HIGHLIGHT.equals(subtype)) {
                    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .30f));
                    // remove other alpha defs from parsing
                    Defs.setSystemProperty("org.icepdf.core.paint.disableAlpha", "true");
                }
                // regular paint
                shapes.paint(g);
                // switch transparency back to the default value
                if (subtype != null && SUBTYPE_HIGHLIGHT.equals(subtype)) {
                    // remove other alpha defs from parsing
                    Defs.setSystemProperty("org.icepdf.core.paint.disableAlpha",
                            String.valueOf(isTransparency));
                }
            }
        }
    }