
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2008 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
* $DateTime: 2008/04/10 13:35:00 $
*
* Adobe Output Module 2.0
*
* MediaGallery Originally Written by Quality Process Incorporated, Enhanced by
* Adobe System China. Contact Sheet written by Adobe System China.
* 
*
**************************************************************************/

/*
	
	Class AOM.PDFGeneratorExternal:
	
	Public Methods:
	
		setPageLayout(dimension, arrange, margins, spacings)
			dimension: Page size in the form of [width, height].
			arrange:   Define how many images placed in each row and column, in
			           the form of [imagePerRow, imagePerColumn].
			margins:   Page margine in horizontal and vertical, in the form of
			           [vertical, horizontal].
			spacings:  Space interval between adjecent images, in the form of
			           [vertical, horizontal].
					   
		addImage(filename, dimension, bits, annotation, colorMode)
			Add an image to the contact sheet document.
			filename:   Filename.
			dimension:  Size of image in pixel, in the form of [width, height].
			bits:       Bits per color component per pixel.
			annotation: Description appearing beneath the image.
			colorMode:	The color mode of the image to be used.
			
		exportPDF(filename)
			Generate PDF disk file.
	
 */


AOM.PDFGeneratorExternal = function(location)
{
	this.images = new Array();
	this.externalFilename = "PDFGenerator";
	this.externalLocation = location;
	this.highQuality = true;
}



AOM.PDFGeneratorExternal.prototype.getFontInformation = function()
{
	var pdfGenerator = new ExternalObject("lib:" + this.externalLocation
	                                             + this.externalFilename);
	var fontCount;
	var i;
	var result = new Array();

	pdfGenerator.buildFontInformationList();
	fontCount = pdfGenerator.getFontInformationCount();
	
	for(i = 0; i < fontCount; ++i) {
		result.push(pdfGenerator.getFontName(i));
	}

	pdfGenerator.unload();
	return result;
}



AOM.PDFGeneratorExternal.prototype.addImage = function(filename, dimension, bits, annotation, colorMode)
{
	this.images.push([filename, dimension, bits, annotation, colorMode]);
}


AOM.PDFGeneratorExternal.prototype.setQuality = function(high)
{
	this.highQuality = true;
}


AOM.PDFGeneratorExternal.prototype.setPageLayout = function(dimension, arrange, margins, spacings)
{
	this.pageLayout = new Object();
	this.pageLayout.dimension = dimension;
	this.pageLayout.margins = margins;
	this.pageLayout.spacings = spacings;
	this.pageLayout.arrange = arrange;	
}



AOM.PDFGeneratorExternal.prototype.setAnnotationRatio = function(ratio)
{
	this.annotationRatio = ratio;
}



AOM.PDFGeneratorExternal.prototype.setFullScreenMode = function(b)
{
	this.fullScreenMode = b;
}



AOM.PDFGeneratorExternal.prototype.setLoop = function(b)
{
    this.loop = b;
}



AOM.PDFGeneratorExternal.prototype.setTransitionMode = function(mode, duration)
{
	this.transitionMode = mode;
	this.transitionDuration = duration;
}



AOM.PDFGeneratorExternal.prototype.setUserPassword = function(userPw)
{
	this.userPw = userPw;
}




AOM.PDFGeneratorExternal.prototype.setOwnerPassword = function(ownerPw)
{
	this.ownerPw = ownerPw;
}




AOM.PDFGeneratorExternal.prototype.setPrintPermission = function(b)
{
	this.printable = b;
}




AOM.PDFGeneratorExternal.prototype.exportPDF = function(filename, majorVer, minorVer)
{
	var i;
	var pdfGenerator;
	
	pdfGenerator = new ExternalObject("lib:" + this.externalLocation
	                                         + this.externalFilename);
	
	for(i = 0; i < this.images.length; ++i) {
		var annotation = this.images[i][3];
		
		if(this.displayFileExtension != undefined &&
		   this.displayFileExtension == false) {
			annotation = this.stripExtension(annotation);
		}
	
		if(this.displayFilename != undefined &&
		   this.displayFilename == false) {
			annotation = "";
		}
		
		pdfGenerator.addImage(
			this.images[i][0],     // Filename
			this.images[i][1][0],  // Image Width
			this.images[i][1][1],  // Image Height
			this.images[i][2],
			annotation,
			this.images[i][4]);
	}

	pdfGenerator.setPageLayout(
		this.pageLayout.dimension[0],
		this.pageLayout.dimension[1],
		this.pageLayout.arrange[0],
		this.pageLayout.arrange[1],
		this.pageLayout.margins[0],
		this.pageLayout.margins[1],
		this.pageLayout.margins[2],
		this.pageLayout.margins[3],
		this.pageLayout.spacings[0],
		this.pageLayout.spacings[1]);
	if(this.annotationRatio != undefined)
		pdfGenerator.setAnnotationRatio(this.annotationRatio * 100);
	if(this.fullScreenMode != undefined)
		pdfGenerator.setFullScreen(this.fullScreenMode);
	if(this.loop != undefined)
	    pdfGenerator.setLoop(this.loop);
	if(this.transitionMode != undefined)
		pdfGenerator.setTransMode(this.transitionMode, this.transitionDuration);
	if(this.pageDuration != undefined)
		pdfGenerator.setPageDuration(this.pageDuration);
	if(this.background != undefined)
		pdfGenerator.setBackground(this.background[0], this.background[1], this.background[2]);
	if(this.fontColor != undefined)
		pdfGenerator.setFontColor(this.fontColor[0], this.fontColor[1], this.fontColor[2]);
	if(this.userPw != undefined)
		pdfGenerator.setUserPassword(this.userPw);
	if(this.ownerPw != undefined)
		pdfGenerator.setOwnerPassword(this.ownerPw);
	if(this.printable != undefined)
		pdfGenerator.setPrintPermission(this.printable);
		

    if(this.fontFamily != undefined && this.fontFace != undefined)
		pdfGenerator.setFontStyle(this.fontFamily, this.fontFace);

	if(this.placeByColumn != undefined)
		pdfGenerator.setPlaceByColumn(this.placeByColumn);
	
	if(this.watermark != undefined)
		pdfGenerator.setWatermark(this.watermark.text,
								  this.watermark.fontFamily,
								  this.watermark.fontFace,
								  this.watermark.fontSize,
								  this.watermark.fontColor,
								  this.watermark.opacity,
								  this.watermark.isBackground);
	
	var result = pdfGenerator.exportPDF(filename, majorVer, minorVer);
	
	pdfGenerator.reset();
	pdfGenerator.unload();
	
	return result;
}





AOM.PDFGeneratorExternal.prototype.stripExtension = function(filename)
{
	var index;
	index = filename.indexOf(".", 0);
	
	if(index < 0)
		return filename;
	
	return filename.substring(0, index);
}



AOM.PDFGeneratorExternal.prototype.getSystemFontFamilies = function()

{
	var pdfGenerator = new ExternalObject("lib:" + this.externalLocation
											     + this.externalFilename);
	var result = new Array();
	var fontFamilyCount = pdfGenerator.getSystemFontFamilyCount();
	for(var i = 0; i < fontFamilyCount; ++i) {
		result.push(pdfGenerator.getSystemFontFamily(i));
	}
	
	var failingFontCount = pdfGenerator.getFailingSystemFontFamilyCount();
	result.errors = new Array();
	for(i = 0; i < failingFontCount; ++i) {
		result.errors.push(pdfGenerator.getFailingSystemFontFamily(i));
	}
		
	pdfGenerator.unload();
	return result;
}

AOM.PDFGeneratorExternal.prototype.getSystemFontFaces = function(fontFamilyName)

{
	var pdfGenerator = new ExternalObject("lib:" + this.externalLocation
												 + this.externalFilename);
	var result = new Array();
	var fontFamilyCount = pdfGenerator.getSystemFontFaceCount(fontFamilyName);
	
	for(var i = 0; i < fontFamilyCount; ++i) {
		result.push(pdfGenerator.getSystemFontFace(fontFamilyName, i));
	}
	
	pdfGenerator.unload();
	return result;
}

AOM.PDFGeneratorExternal.prototype.combineDiacriticMarks = function(text)

{
	var pdfGenerator = new ExternalObject("lib:" + this.externalLocation
												 + this.externalFilename);
	var result = pdfGenerator.combineDiacriticMarks(text);
	
	pdfGenerator.unload();
	return result;
}
