final Shape shClip = _g2d.getClip( ); Area ar1 = new Area( shClip ); Area ar2 = new Area( new Polygon( i2a[0], i2a[1], loa.length ) ); ar2.intersect( ar1 );
	public void fillPolygon( PolygonRenderEvent pre ) throws ChartException	{		final Fill flBackground = pre.getBackground( );		final Location[] loa = pre.getPoints( );		final int[][] i2a = getCoordinatesAsInts( loa );		if ( flBackground instanceof ColorDefinition )		{			final ColorDefinition cd = (ColorDefinition) flBackground;			_g2d.setColor( (Color) _ids.getColor( cd ) );			_g2d.fill( new Polygon( i2a[0], i2a[1], loa.length ) );		}		else if ( flBackground instanceof Gradient )		{			final Gradient g = (Gradient) flBackground;			final ColorDefinition cdStart = (ColorDefinition) g.getStartColor( );			final ColorDefinition cdEnd = (ColorDefinition) g.getEndColor( );			// final boolean bRadial = g.isCyclic();			final double dAngleInDegrees = g.getDirection( );			final double dAngleInRadians = ( ( -dAngleInDegrees * Math.PI ) / 180.0 );			// final int iAlpha = g.getTransparency();			final double dMinX = BaseRenderer.getX( loa, IConstants.MIN );			final double dMaxX = BaseRenderer.getX( loa, IConstants.MAX );			final double dMinY = BaseRenderer.getY( loa, IConstants.MIN );			final double dMaxY = BaseRenderer.getY( loa, IConstants.MAX );			/*			 * if (bRadial) { }			 */			if ( dAngleInDegrees < -90 || dAngleInDegrees > 90 )			{				throw new ChartException( ChartDeviceExtensionPlugin.ID,						ChartException.RENDERING,						"exception.gradient.angle",//$NON-NLS-1$						new Object[]{							new Double( dAngleInDegrees )						},						ResourceBundle.getBundle( Messages.DEVICE_EXTENSION,								getLocale( ) ) );			}			Point2D.Double p2dStart, p2dEnd;			if ( dAngleInDegrees == 90 )			{				p2dStart = new Point2D.Double( dMinX, dMaxY );				p2dEnd = new Point2D.Double( dMinX, dMinY );			}			else if ( dAngleInDegrees == -90 )			{				p2dStart = new Point2D.Double( dMinX, dMinY );				p2dEnd = new Point2D.Double( dMinX, dMaxY );			}			else if ( dAngleInDegrees > 0 )			{				p2dStart = new Point2D.Double( dMinX, dMaxY );				p2dEnd = new Point2D.Double( dMaxX, dMaxY						- ( dMaxX - dMinX )						* Math.abs( Math.tan( dAngleInRadians ) ) );			}			else if ( dAngleInDegrees < 0 )			{				p2dStart = new Point2D.Double( dMinX, dMinY );				p2dEnd = new Point2D.Double( dMaxX, dMinY						+ ( dMaxX - dMinX )						* Math.abs( Math.tan( dAngleInRadians ) ) );			}			else			{				p2dStart = new Point2D.Double( dMinX, dMinY );				p2dEnd = new Point2D.Double( dMaxX, dMinY );			}			_g2d.setPaint( new GradientPaint( p2dStart,					(Color) _ids.getColor( cdStart ),					p2dEnd,					(Color) _ids.getColor( cdEnd ) ) );			_g2d.fill( new Polygon( i2a[0], i2a[1], loa.length ) );		}		else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image )		{			final String sUrl = ( (org.eclipse.birt.chart.model.attribute.Image) flBackground ).getURL( );			java.awt.Image img = null;			try			{				img = (java.awt.Image) _ids.loadImage( new URL( sUrl ) );			}			catch ( ChartException ilex )			{				throw new ChartException( ChartDeviceExtensionPlugin.ID,						ChartException.RENDERING,						ilex );			}			catch ( MalformedURLException muex )			{				throw new ChartException( ChartDeviceExtensionPlugin.ID,						ChartException.RENDERING,						muex );			}			final Shape shClip = _g2d.getClip( );			Area ar1 = new Area( shClip );			Area ar2 = new Area( new Polygon( i2a[0], i2a[1], loa.length ) );			ar2.intersect( ar1 );			_g2d.setClip( ar2 );			final double dMinX = BaseRenderer.getX( loa, IConstants.MIN );			final double dMaxX = BaseRenderer.getX( loa, IConstants.MAX );			final double dMinY = BaseRenderer.getY( loa, IConstants.MIN );			final double dMaxY = BaseRenderer.getY( loa, IConstants.MAX );			final Size szImage = _ids.getSize( img );			final int iXRepeat = (int) ( Math.ceil( ( dMaxX - dMinX )					/ szImage.getWidth( ) ) );			final int iYRepeat = (int) ( Math.ceil( ( dMaxY - dMinY )					/ szImage.getHeight( ) ) );			final ImageObserver io = (ImageObserver) _ids.getObserver( );			for ( int i = 0; i < iXRepeat; i++ )			{				for ( int j = 0; j < iYRepeat; j++ )				{					_g2d.drawImage( img,							(int) ( dMinX + i * szImage.getWidth( ) ),							(int) ( dMinY + j * szImage.getHeight( ) ),							io );				}			}			// img(); // FLUSHED LATER BY CACHE; DON'T FLUSH HERE			_g2d.setClip( shClip ); // RESTORE		}		/*		 * if (pre.iObjIndex > 0) { try { Bounds bo = pre.getBounds();		 * _g2d.setColor(Color.red); _g2d.setFont(new Font("Arial", Font.BOLD,		 * 14)); _g2d.drawString("{0}" + pre.iObjIndex, (int) (bo.getLeft() +		 * bo.getWidth() / 2), (int) (bo.getTop() + bo //		 * i18n_CONCATENATIONS_REMOVED .getHeight() / 2)); } catch (Exception ex ) {		 * ex.printStackTrace(); } }		 */	}