<commit_before>/*******************************************************************************
 * Copyright (c) 2007 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.emitter.ppt;

import java.awt.Color;
import java.awt.Image;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import org.apache.commons.codec.binary.Base64;
import org.eclipse.birt.report.engine.layout.emitter.util.BackgroundImageLayout;
import org.eclipse.birt.report.engine.layout.emitter.util.Position;
import org.eclipse.birt.report.engine.layout.pdf.font.FontInfo;

import com.lowagie.text.Font;
import com.lowagie.text.pdf.BaseFont;

public class PPTWriter
{

	protected static Logger logger = Logger.getLogger( PPTRender.class
			.getName( ) );

	/**
	 * Output stream where postscript to be output.
	 */
	private PrintWriter writer = null;

	protected int currentPageNum = 0;
	private int shapeCount = 0;

	protected float pageWidth, pageHeight;

	// Holds all the images' name appears in report design
	private Map imageNames = new HashMap( );

	private List imageTitles = new ArrayList( );

	// Holds the extension types of all images
	private Map imageExtensions = new HashMap( );

	// Holds the files' name for each page
	private Map fileNamesLists = new TreeMap( );

	private Map currentImageData = new HashMap( );;

	public PPTWriter( OutputStream output )
	{
		try
		{
			writer = new PrintWriter(
					new OutputStreamWriter( output, "UTF-8" ), false );
		}
		catch ( UnsupportedEncodingException e )
		{
			assert ( false );
		}
	}

	/**
	 * Creates a PPT Document.
	 * 
	 */
	public void start( )
	{
		if ( !imageNames.isEmpty( ) )
		{
			imageNames.clear( );
		}
		if ( !fileNamesLists.isEmpty( ) )
		{
			fileNamesLists.clear( );
		}

		println( "MIME-Version: 1.0" ); //$NON-NLS-1$
		println( "Content-Type: multipart/related; boundary=\"___Actuate_Content_Boundary___\"" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "--___Actuate_Content_Boundary___" ); //$NON-NLS-1$
		println( "Content-Location: slide-show" ); //$NON-NLS-1$
		println( "Content-Transfer-Encoding: quoted-printable" ); //$NON-NLS-1$
		println( "Content-Type: text/html; charset=\"utf-8\"" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "<html" ); //$NON-NLS-1$
		println( "xmlns=3D'http://www.w3.org/TR/REC-html40'" ); //$NON-NLS-1$
		println( "xmlns:o=3D'urn:schemas-microsoft-com:office:office'" ); //$NON-NLS-1$
		println( "xmlns:p=3D'urn:schemas-microsoft-com:office:powerpoint'" ); //$NON-NLS-1$
		println( "xmlns:v=3D'urn:schemas-microsoft-com:vml'" ); //$NON-NLS-1$
		println( ">" ); //$NON-NLS-1$
		println( "<head>" ); //$NON-NLS-1$
		println( "<meta http-equiv=3D'Content-Type' content=3D'text/html; charset=3Dutf-8'>" ); //$NON-NLS-1$
		println( "<meta name=3D'ProgId' content=3D'PowerPoint.Slide'>" ); //$NON-NLS-1$
		println( "<meta name=3D'Generator' content=3D'Actuate View Server'>" ); //$NON-NLS-1$
		println( "<title>Actuate Report</title>" ); //$NON-NLS-1$
		println( "<xml><o:DocumentProperties>" ); //$NON-NLS-1$
		println( "<o:Author>Actuate View Server</o:Author>" ); //$NON-NLS-1$
		println( "</o:DocumentProperties></xml><link rel=3DFile-List href=3D'file-list'>" ); //$NON-NLS-1$
		println( "<link rel=3DPresentation-XML href=3D'presentation'>" ); //$NON-NLS-1$
		println( "</head><body/></html>" ); //$NON-NLS-1$
	}

	private void print( String text )
	{
		writer.print( text );
	}

	private void println( String text )
	{
		writer.println( text );
	}

	private void print( byte[] data )
	{
		print( new String( data ) );
	}

	/**
	 * Closes the document.
	 * 
	 */
	public void end( )
	{
		println( "--___Actuate_Content_Boundary___" ); //$NON-NLS-1$
		println( "Content-Location: presentation" ); //$NON-NLS-1$
		println( "Content-Transfer-Encoding: quoted-printable" ); //$NON-NLS-1$
		println( "Content-Type: text/xml; charset=\"utf-8\"" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "<xml" ); //$NON-NLS-1$
		println( " xmlns:o=3D'urn:schemas-microsoft-com:office:office'" ); //$NON-NLS-1$
		println( " xmlns:p=3D'urn:schemas-microsoft-com:office:powerpoint'" ); //$NON-NLS-1$
		println( ">" ); //$NON-NLS-1$
		println( ( "<p:presentation sizeof=3D'custom' slidesizex=3D'" + ( pageWidth * 8 ) + "' slidesizey=3D'" + ( pageHeight * 8 ) + "'>" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

		for ( int i = 0; i < currentPageNum; i++ )
		{
			println( ( "<p:slide id=3D'" + ( i + 1 ) + "' href=3D's" + ( i + 1 ) + "'/>" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		}

		println( "</p:presentation></xml>" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "--___Actuate_Content_Boundary___" ); //$NON-NLS-1$
		println( "Content-Location: file-list" ); //$NON-NLS-1$
		println( "Content-Transfer-Encoding: quoted-printable" ); //$NON-NLS-1$
		println( "Content-Type: text/xml; charset=\"utf-8\"" ); //$NON-NLS-1$
		println( "<xml" ); //$NON-NLS-1$
		println( " xmlns:o=3D'urn:schemas-microsoft-com:office:office'" ); //$NON-NLS-1$
		println( " xmlns:p=3D'urn:schemas-microsoft-com:office:powerpoint'" ); //$NON-NLS-1$
		println( ">" ); //$NON-NLS-1$
		println( "<o:MainFile href=3D'slide-show'/>" ); //$NON-NLS-1$
		println( "<o:File href=3D'presentation'/>" ); //$NON-NLS-1$
		println( "<o:File href=3D'file-list'/>" ); //$NON-NLS-1$

		for ( int i = 0; i < currentPageNum; i++ )
		{
			println( ( "<o:File href=3D's" + ( i + 1 ) + "'/>" ) ); //$NON-NLS-1$ //$NON-NLS-2$
			if ( fileNamesLists.containsKey( new Integer( i + 1 ) ) )
			{
				List filenames = (List) fileNamesLists<commit_msg>fix bug 220610: Report as PPT sends "data corrupt" with Windows XP<commit_after>/*******************************************************************************
 * Copyright (c) 2007 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.engine.emitter.ppt;

import java.awt.Color;
import java.awt.Image;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import org.apache.commons.codec.binary.Base64;
import org.eclipse.birt.report.engine.layout.emitter.util.BackgroundImageLayout;
import org.eclipse.birt.report.engine.layout.emitter.util.Position;
import org.eclipse.birt.report.engine.layout.pdf.font.FontInfo;

import com.lowagie.text.Font;
import com.lowagie.text.pdf.BaseFont;

public class PPTWriter
{

	protected static Logger logger = Logger.getLogger( PPTRender.class
			.getName( ) );

	/**
	 * Output stream where postscript to be output.
	 */
	private PrintWriter writer = null;

	protected int currentPageNum = 0;
	private int shapeCount = 0;

	protected float pageWidth, pageHeight;

	// Holds all the images' name appears in report design
	private Map imageNames = new HashMap( );

	private List imageTitles = new ArrayList( );

	// Holds the extension types of all images
	private Map imageExtensions = new HashMap( );

	// Holds the files' name for each page
	private Map fileNamesLists = new TreeMap( );

	private Map currentImageData = new HashMap( );;

	public PPTWriter( OutputStream output )
	{
		try
		{
			writer = new PrintWriter(
					new OutputStreamWriter( output, "UTF-8" ), false );
		}
		catch ( UnsupportedEncodingException e )
		{
			assert ( false );
		}
	}

	/**
	 * Creates a PPT Document.
	 * 
	 */
	public void start( )
	{
		if ( !imageNames.isEmpty( ) )
		{
			imageNames.clear( );
		}
		if ( !fileNamesLists.isEmpty( ) )
		{
			fileNamesLists.clear( );
		}

		println( "MIME-Version: 1.0" ); //$NON-NLS-1$
		println( "Content-Type: multipart/related; boundary=\"___Actuate_Content_Boundary___\"" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "--___Actuate_Content_Boundary___" ); //$NON-NLS-1$
		println( "Content-Location: slide-show" ); //$NON-NLS-1$
		println( "Content-Transfer-Encoding: quoted-printable" ); //$NON-NLS-1$
		println( "Content-Type: text/html; charset=\"utf-8\"" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "<html" ); //$NON-NLS-1$
		println( "xmlns=3D'http://www.w3.org/TR/REC-html40'" ); //$NON-NLS-1$
		println( "xmlns:o=3D'urn:schemas-microsoft-com:office:office'" ); //$NON-NLS-1$
		println( "xmlns:p=3D'urn:schemas-microsoft-com:office:powerpoint'" ); //$NON-NLS-1$
		println( "xmlns:v=3D'urn:schemas-microsoft-com:vml'" ); //$NON-NLS-1$
		println( ">" ); //$NON-NLS-1$
		println( "<head>" ); //$NON-NLS-1$
		println( "<meta http-equiv=3D'Content-Type' content=3D'text/html; charset=3Dutf-8'>" ); //$NON-NLS-1$
		println( "<meta name=3D'ProgId' content=3D'PowerPoint.Slide'>" ); //$NON-NLS-1$
		println( "<meta name=3D'Generator' content=3D'Actuate View Server'>" ); //$NON-NLS-1$
		println( "<title>Actuate Report</title>" ); //$NON-NLS-1$
		println( "<xml><o:DocumentProperties>" ); //$NON-NLS-1$
		println( "<o:Author>Actuate View Server</o:Author>" ); //$NON-NLS-1$
		println( "</o:DocumentProperties></xml><link rel=3DFile-List href=3D'file-list'>" ); //$NON-NLS-1$
		println( "<link rel=3DPresentation-XML href=3D'presentation'>" ); //$NON-NLS-1$
		println( "</head><body/></html>" ); //$NON-NLS-1$
	}

	private void print( String text )
	{
		writer.print( text );
	}

	private void println( String text )
	{
		writer.println( text );
	}

	private void print( byte[] data )
	{
		print( new String( data ) );
	}

	/**
	 * Closes the document.
	 * 
	 */
	public void end( )
	{
		int slidesizex = (int) ( Math.ceil( pageWidth * 8 ) );
		int slidesizey = (int) ( Math.ceil( pageHeight * 8 ) );
		println( "--___Actuate_Content_Boundary___" ); //$NON-NLS-1$
		println( "Content-Location: presentation" ); //$NON-NLS-1$
		println( "Content-Transfer-Encoding: quoted-printable" ); //$NON-NLS-1$
		println( "Content-Type: text/xml; charset=\"utf-8\"" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "<xml" ); //$NON-NLS-1$
		println( " xmlns:o=3D'urn:schemas-microsoft-com:office:office'" ); //$NON-NLS-1$
		println( " xmlns:p=3D'urn:schemas-microsoft-com:office:powerpoint'" ); //$NON-NLS-1$
		println( ">" ); //$NON-NLS-1$
		println( ( "<p:presentation sizeof=3D'custom' slidesizex=3D'" + slidesizex + "' slidesizey=3D'" + slidesizey + "'>" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

		for ( int i = 0; i < currentPageNum; i++ )
		{
			println( ( "<p:slide id=3D'" + ( i + 1 ) + "' href=3D's" + ( i + 1 ) + "'/>" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		}

		println( "</p:presentation></xml>" ); //$NON-NLS-1$
		println( "" ); //$NON-NLS-1$
		println( "--___Actuate_Content_Boundary___" ); //$NON-NLS-1$
		println( "Content-Location: file-list" ); //$NON-NLS-1$
		println( "Content-Transfer-Encoding: quoted-printable" ); //$NON-NLS-1$
		println( "Content-Type: text/xml; charset=\"utf-8\"" ); //$NON-NLS-1$
		println( "<xml" ); //$NON-NLS-1$
		println( " xmlns:o=3D'urn:schemas-microsoft-com:office:office'" ); //$NON-NLS-1$
		println( " xmlns:p=3D'urn:schemas-microsoft-com:office:powerpoint'" ); //$NON-NLS-1$
		println( ">" ); //$NON-NLS-1$
		println( "<o:MainFile href=3D'slide-show'/>" ); //$NON-NLS-1$
		println( "<o:File href=3D'presentation'/>" ); //$NON-NLS-1$
		println( "<o:File href=3D'file-list'/>" ); //$NON-NLS-1$

		for ( int i = 0; i < currentPageNum; i++ )
		{
			println( ( "<o:File href=3D's" + ( i + 1 ) + "'/>" ) ); //$NON-NLS-1$ //$NON-NLS-2$
			if ( fileNamesLists.containsKey( new Integer( i + 1 ) ) )
			{
				List filenames = (List) fileNamesLists
{'fraction_non_alphanumeric': 0.2127382683916405, 'fraction_numerical': 0.01760698155094542, 'mean_word_length': 3.8171091445427727, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 30}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5569138', 'n_tokens_mistral': 5127, 'n_tokens_neox': 4743, 'n_words': 938}