﻿<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<title>RTF Import Extension</title>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<meta name="generator" content="Adobe GoLive" />
	</head>

	<body>
		<hr />
		<p><b>ADOBE SYSTEMS INCORPORATED</b></p>
		<p>Copyright 2000-2005 Adobe Systems Incorporated<br />
			All Rights Reserved</p>
		<p>NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe.</p>
		<hr />
		<p><b>Extension Name:</b> RTFImport</p>
		<p><b>Folder name:</b> RTFImport</p>
		<hr />
		<p><b>Description:</b></p>
		<p>RTFImport</p>
		<p>The RTFImport extension is an filter for the Rich Text Format (RTF) and convert the content to simple HTML.</p>
		<p>The filter could be used by the menu File-&gt;Import-&gt;RTF... which takes the rtf source file and generates a new document or you could use the filter with a Component.<br />
			<br />
			Important: You should not to try to convert a RTF file with embedded graphics because this filter may be too slow for large image data. Use linked graphics instead.</p>
		<hr />
		<p><b>Module Definition:</b></p>
		<jsxmodule debug="false" info="$$$/extendscript/RTFImport/info=A Rich Text Format (RTF) filter." name="RTFImport" version="0.9" /> 
		<p><b>Scripts:</b></p>
		<script><!--
var scanner = null;

function startModule()
{
	var rtfSeperator = 	menus['file'].items['Impo'].addItem( '-' , '-' );
	var rtfMenu = 		menus['file'].items['Impo'].addItem( 'RTFImport', 'RTF ...' );

	rtfMenu.addEventListener( 'menuSignal', importRTF);
	app.addEventListener( 'generateMarkupForURL', generateMarkupForURL);

}


		
function importRTF( eventObj )
{
	var typestr = '';
	
	if( app.osVersion.search( 'Windows' ) != -1 )
		typestr ='rtf:*.rtf';
		
	var src = fileGetDialog( module.localize( "$$$/extendscript/RTPImport/Scanning=Scanning..." ), typestr );
	
	if( src != null && src.lastname.search( '.rtf' ) == src.lastname.length-4 )
	{
		scanner = new RTFScanner;
		scanner.source = src;
		scanner.progress = showProgress;
		
		app.startProgress( module.localize( "$$$/extendscript/RTPImport/Scanning=Scanning..." ), 
						   module.localize( "$$$/extendscript/RTPImport/ScanningRTF=Scanning RTF file" ), false, 5 );
		
		if( scanner.processSource() )
		{
			app.stopProgress();
			
			if( module.debug && confirm( module.localize( "$$$/extendscript/RTPImport/successCreateReport=Success, create report?" ) ) )
				createRTFReport( scanner );

			var doCreateDoc = ( !module.debug || ( module.debug && confirm( module.localize( "$$$/extendscript/RTPImport/createHTML=Create HTML document?" ) ) ) );
			
			if( doCreateDoc )
			{
				var parser = new RTFParser( scanner.rtf );
				
				if( parser.parse() )
				{
					var doc = app.newDocument();
					
					if( doc != null )
					{
						doc.element.getSubElement('body').setInnerHTML( parser.getSource() );
						doc.reformat();
					}
				}
			}
		}
		else
		{
			app.stopProgress();
			alert( module.localize( "$$$/extendscript/RTPImport/ImportFailed=Import Failed" ) );
		}
	}
}



function showProgress( pos, max )
{
	var cur = pos/max;

	var text = 	localize("$$$/extendscript/RTPImport/ScanningPercent=Scanning RTF file %1 %%", parseInt( (cur*100).toString() ) );
	
	if( !app.setProgress( cur, text ) )
		scanner.stop();
}

function generateMarkupForURL( eventObject )
{
	if( eventObject.generatorName == 'rtfgenerator' )
	{
		var source = new JSXFile( eventObject.url );
		
		if( source.exists )
		{
			scanner = new RTFScanner;
			scanner.source = source;
			scanner.progress = showProgress;
			
			app.startProgress( localize("$$$/extendscript/RTPImport/Scanning=Scanning..."), 'Scanning RTF file', false, 5 );
			
			if( scanner.processSource() )
			{
				app.stopProgress();
				
				var parser = new RTFParser( scanner.rtf );
					
				if( parser.parse() )
				{
					var markup = parser.getSource();
					markup = '<body>' + markup + '</body>';
					eventObject.outSource = markup;
					eventObject.outSuccess = true;
				}
			}
		}	
	}
}

function inspectMarkupForURL( eventObject )
{
	//
	// setup dialog
	//
	dialogs['RTFSettings'].children['bold'].value		= rtf2html[2][6];
	dialogs['RTFSettings'].children['italic'].value		= rtf2html[3][6];
	dialogs['RTFSettings'].children['underline'].value	= rtf2html[4][6];
	dialogs['RTFSettings'].children['alignment'].value	= rtf2html[22][6];
	dialogs['RTFSettings'].children['fontname'].value	= rtf2html[28][6];
	dialogs['RTFSettings'].children['fontsize'].value	= rtf2html[29][6];
	dialogs['RTFSettings'].children['fontcolor'].value	= rtf2html[30][6];
	dialogs['RTFSettings'].children['limage'].value		= rtf2html[32][6];

	dialogs['RTFSettings'].center();
	
	if( dialogs['RTFSettings'].runModal() )
	{
		//
		// set rtf settings from dialog
		//
		rtf2html[2][6]	= dialogs['RTFSettings'].children['bold'].value;
		rtf2html[3][6]	= dialogs['RTFSettings'].children['italic'].value;

		rtf2html[4][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[5][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[6][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[7][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[8][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[9][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[10][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[11][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[12][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[13][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[14][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[15][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[16][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[17][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[18][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[19][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[20][6]	= dialogs['RTFSettings'].children['underline'].value;
		rtf2html[21][6]	= dialogs['RTFSettings'].children['underline'].value;

		rtf2html[22][6]	= dialogs['RTFSettings'].children['alignment'].value;
		rtf2html[23][6]	= dialogs['RTFSettings'].children['alignment'].value;
		rtf2html[24][6]	= dialogs['RTFSettings'].children['alignment'].value;
		rtf2html[25][6]	= dialogs['RTFSettings'].children['alignment'].value;

		rtf2html[28][6]	= dialogs['RTFSettings'].children['fontname'].value;
		rtf2html[29][6]	= dialogs['RTFSettings'].children['fontsize'].value;
		rtf2html[30][6]	= dialogs['RTFSettings'].children['fontcolor'].value;
		rtf2html[32][6]	= dialogs['RTFSettings'].children['limage'].value;
	}
}
//-->
</script>
		<script type="text/javascript" src="rtfScanner.js"></script>
		<script type="text/javascript" src="rtfGroup.js"></script>
		<script type="text/javascript" src="rtfEntry.js"></script>
		<script type="text/javascript" src="rtfMapping.js"></script>
		<script type="text/javascript" src="rtfParser.js"></script>
		<script type="text/javascript" src="htmlItem.js"></script>
		<script type="text/javascript" src="rtfReport.js"></script>
		<hr />
		<p><b>Markup Generator</b></p>
		<jsxmlgenerator mimetype="application/rtf" internalname="rtfgenerator" uiname="RTF" settings="yes"></jsxmlgenerator>
		<p><b>UI</b></p>
		<jsxdialog height="205" name="RTFSettings" title="RTF Filter Settings" width="250">
			<jsxcontrol height="20" name="bold" posx="15" posy="5" type="checkbox" value="bold" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="italic" posx="15" posy="25" type="checkbox" value="italic" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="underline" posx="15" posy="45" type="checkbox" value="underline" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="alignment" posx="15" posy="65" type="checkbox" value="paragraph alignment" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="fontname" posx="15" posy="85" type="checkbox" value="font name" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="fontsize" posx="15" posy="105" type="checkbox" value="font size" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="fontcolor" posx="15" posy="125" type="checkbox" value="font color" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="limage" posx="15" posy="145" type="checkbox" value="linked image" width="220"></jsxcontrol>
			<jsxcontrol height="20" name="dialogok" posx="170" posy="180" type="button" value="OK" width="60"></jsxcontrol>
			<jsxcontrol height="20" name="dialogcancel" posx="20" posy="180" type="button" value="Cancel" width="60"></jsxcontrol>
		</jsxdialog>
	</body>

</html>