Bug 413489 - Directly generate vector image from JFreeChart to iText
Summary: Directly generate vector image from JFreeChart to iText
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 4.3.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Birt-ReportEngine-inbox@eclipse.org CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-23 02:05 EDT by janine chang CLA
Modified: 2013-07-23 02:24 EDT (History)
0 users

See Also:


Attachments
JFreeChart to PNG to Birt (15.79 KB, image/png)
2013-07-23 02:05 EDT, janine chang CLA
no flags Details
JFreeChart to SVG to Birt (26.15 KB, image/png)
2013-07-23 02:05 EDT, janine chang CLA
no flags Details
JFreeChart directly to Birt (19.39 KB, image/png)
2013-07-23 02:06 EDT, janine chang CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description janine chang CLA 2013-07-23 02:05:20 EDT
Created attachment 233686 [details]
JFreeChart to PNG to Birt

Data Source: JFreeChart
Output Format: PDF
Issue: convert JFreeChart to PNG byte array makes the image blurred, convert JFreeChart to SVG byte array also makes the die data point blurred even if the text is clear after zoom in, and the output file size is big in this two ways
Purpose: clear vetor image and small file size
Comment 1 janine chang CLA 2013-07-23 02:05:43 EDT
Created attachment 233687 [details]
JFreeChart to SVG to Birt
Comment 2 janine chang CLA 2013-07-23 02:06:09 EDT
Created attachment 233688 [details]
JFreeChart directly to Birt
Comment 3 janine chang CLA 2013-07-23 02:15:40 EDT
I did my own "patch" to org.eclipse.birt.report.engine.emitter.pdf.PDFPage

I modify the following method:

protected void drawImage( String imageId, byte[] imageData,
			String extension, float imageX, float imageY, float height,float width, String helpText, Map params ) throws Exception



		if ( SvgFile.isSvg( null, null, extension ) )
		{
//start add JFreeChart
			if(null == imageData)
				return;
			JFreeChart[] charts = null;
			try {
				ObjectInputStream obj =new ObjectInputStream(new ByteArrayInputStream(imageData));
				charts = (JFreeChart[])obj.readObject();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				System.out.println("not jfreechart");
			}
			
			if(charts!=null){
				template = contentByte.createTemplate(width*2, height*2);
	    		Image img = genJfreechartImage(template, charts, width, height);
	    		if(img!=null)
	    			drawImage( img, imageX, imageY, height, width, helpText );
				return;
//end add JFreeChart
			}else{
				template = generateTemplateFromSVG( null, imageData, imageX,
					imageY, height, width, helpText );
			}
		}
Comment 4 janine chang CLA 2013-07-23 02:17:35 EDT
and add my genJfreechartImage:

	//add genJfreechartImage
		private Image genJfreechartImage(PdfTemplate tp, JFreeChart[] charts, float width, float height)throws BadElementException, DocumentException{
	        Graphics2D g2d = tp.createGraphics(width*2, height*2, true, 0);
	        for(int i=0;i<charts.length;i++){
	        	Rectangle2D r2d = new Rectangle2D.Double(i*width*2/charts.length, 0, width*2/charts.length, height*2);
	        	charts[i].draw(g2d, r2d, null);
	        }
	        Image img = Image.getInstance(tp);
	        g2d.dispose();
	        g2d = null;
	        return img;
	    }
Comment 5 janine chang CLA 2013-07-23 02:22:50 EDT
To use the "patch", need to do:
1: serialize the JFreeChart[] to byte[]
2: setMimeType("image/svg+xml") to the image in report design
In this way, the vector image is always clear after zoom in and the file size will be much smaller than convert to PNG/SVG
Comment 6 janine chang CLA 2013-07-23 02:24:13 EDT
If this patch is acceptable, could you add it to the future birt updates?