private OfficeDrawing getOfficeDrawing()

in poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/OfficeDrawingsImpl.java [117:292]


    private OfficeDrawing getOfficeDrawing( final FSPA fspa )
    {
        return new OfficeDrawing()
        {
            @Override
            public HorizontalPositioning getHorizontalPositioning()
            {
                int value = getTertiaryPropertyValue(EscherPropertyTypes.GROUPSHAPE__POSH );

                switch ( value )
                {
                case 0:
                    return HorizontalPositioning.ABSOLUTE;
                case 1:
                    return HorizontalPositioning.LEFT;
                case 2:
                    return HorizontalPositioning.CENTER;
                case 3:
                    return HorizontalPositioning.RIGHT;
                case 4:
                    return HorizontalPositioning.INSIDE;
                case 5:
                    return HorizontalPositioning.OUTSIDE;
                }

                return HorizontalPositioning.ABSOLUTE;
            }

            @Override
            public HorizontalRelativeElement getHorizontalRelative()
            {
                int value = getTertiaryPropertyValue( EscherPropertyTypes.GROUPSHAPE__POSRELH );

                switch ( value )
                {
                case 1:
                    return HorizontalRelativeElement.MARGIN;
                case 2:
                    return HorizontalRelativeElement.PAGE;
                case 3:
                    return HorizontalRelativeElement.TEXT;
                case 4:
                    return HorizontalRelativeElement.CHAR;
                }

                return HorizontalRelativeElement.TEXT;
            }

            @Override
            public EscherContainerRecord getOfficeArtSpContainer()
            {
                return getEscherShapeRecordContainer( getShapeId() );
            }

            @Override
            public byte[] getPictureData()
            {
                EscherContainerRecord shapeDescription = getEscherShapeRecordContainer( getShapeId() );
                if ( shapeDescription == null )
                    return null;

                EscherOptRecord escherOptRecord = shapeDescription
                        .getChildById( EscherOptRecord.RECORD_ID );
                if ( escherOptRecord == null )
                    return null;

                EscherSimpleProperty escherProperty = escherOptRecord
                        .lookup( EscherPropertyTypes.BLIP__BLIPTODISPLAY );
                if ( escherProperty == null )
                    return null;

                int bitmapIndex = escherProperty.getPropertyValue();
                EscherBlipRecord escherBlipRecord = getBitmapRecord( bitmapIndex );
                if ( escherBlipRecord == null )
                    return null;

                return escherBlipRecord.getPicturedata();
            }

            @Override
            public int getRectangleBottom()
            {
                return fspa.getYaBottom();
            }

            @Override
            public int getRectangleLeft()
            {
                return fspa.getXaLeft();
            }

            @Override
            public int getRectangleRight()
            {
                return fspa.getXaRight();
            }

            @Override
            public int getRectangleTop()
            {
                return fspa.getYaTop();
            }

            @Override
            public int getShapeId()
            {
                return fspa.getSpid();
            }

            private int getTertiaryPropertyValue( EscherPropertyTypes type ) {
                EscherContainerRecord shapeDescription = getEscherShapeRecordContainer( getShapeId() );
                if ( shapeDescription == null ) {
                    return -1;
                }

                EscherTertiaryOptRecord escherTertiaryOptRecord = shapeDescription
                        .getChildById( EscherTertiaryOptRecord.RECORD_ID );
                if ( escherTertiaryOptRecord == null ) {
                    return -1;
                }

                EscherSimpleProperty escherProperty = escherTertiaryOptRecord.lookup( type );
                return ( escherProperty == null ) ? -1 : escherProperty.getPropertyValue();
            }

            @Override
            public VerticalPositioning getVerticalPositioning()
            {
                int value = getTertiaryPropertyValue( EscherPropertyTypes.GROUPSHAPE__POSV );

                switch ( value )
                {
                case 0:
                    return VerticalPositioning.ABSOLUTE;
                case 1:
                    return VerticalPositioning.TOP;
                case 2:
                    return VerticalPositioning.CENTER;
                case 3:
                    return VerticalPositioning.BOTTOM;
                case 4:
                    return VerticalPositioning.INSIDE;
                case 5:
                    return VerticalPositioning.OUTSIDE;
                }

                return VerticalPositioning.ABSOLUTE;
            }

            @Override
            public VerticalRelativeElement getVerticalRelativeElement()
            {
                int value = getTertiaryPropertyValue( EscherPropertyTypes.GROUPSHAPE__POSV );

                switch ( value )
                {
                case 1:
                    return VerticalRelativeElement.MARGIN;
                case 2:
                    return VerticalRelativeElement.PAGE;
                case 3:
                    return VerticalRelativeElement.TEXT;
                case 4:
                    return VerticalRelativeElement.LINE;
                }

                return VerticalRelativeElement.TEXT;
            }

            @Override
            public String toString()
            {
                return "OfficeDrawingImpl: " + fspa;
            }
        };
    }