/*
//
//   ADOBE SYSTEMS INCORPORATED
//   Copyright (C) 2000-2003 Adobe Systems Incorporated
//   All rights reserved.
//
//   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.
//
*/
/*
 * MyPDFLibUtils.h
 *
 */

#ifndef _MyPDFLibUtils_H_
#define _MyPDFLibUtils_H_

#include "PDFInit.h"
#include "PDFLCalls.h"
#include "PDExpT.h"

#ifdef __cplusplus
extern   "C"  {
#endif

#if MAC_PLATFORM
#include <Foundation/Foundation.h>
#ifndef __LP64__
OSErr PDFLAppInit_Mac( const  CFragInitBlock* initBlock);
#endif
void  PDFLAppTerm_Mac();
int  GetOneSampleFile_Mac( char  *fileName, FSSpec *fsSpec);

/* It handles initialization and release of NSAutoreleasePool such that
 * no memory leak takes place when COCOA objects are created. It is required
 * only on MAC platform.
 */
#define INIT_AUTO_POOL(varName) NSAutoreleasePool *varName = [[NSAutoreleasePool alloc] init]
#define RELEASE_AUTO_POOL(varName) [varName release]
#else
#define INIT_AUTO_POOL(varName)
#define RELEASE_AUTO_POOL(varName)
#endif

int     MyPDFLInit();
void   MyPDFLTerm();

PDDoc   MyPDDocOpen( const   char  *fileName);

/* Scale used for conversion between ASFixed and ASDouble value; */
#define FIXED_SCALE 65536.0

/* To convert ASFixed to ASDouble */
ASDouble   FixedToDouble(ASFixed  x);

/* To convert ASDouble to ASFixed */
ASFixed   DoubleToFixed(ASDouble  d);

/* To convert ASFixedMatrix to ASDoubleMatrix */
void   FixedToDoubleMatrix(ASDoubleMatrix  *out,  ASFixedMatrix  *in);

/* To convert ASDoubleMatrix to ASFixedMatrix */
void   DoubleToFixedMatrix(ASFixedMatrix  *out,  ASDoubleMatrix  *in);

/* To convert ASFixedRect to ASDoubleRect */
void   FixedToDoubleRect(ASDoubleRect  *out,  ASFixedRect  *in);

/* To convert ASDoubleRect to ASFixedRect */
void   DoubleToFixedRect(ASFixedRect  *out,  ASDoubleRect  *in);

void   DisplayError(ASErrorCode  errCode);

void   DisplayErrorAndWarnings(PDDoc  pdDoc,  ASErrorCode  errCode,  ASBool  printWarnings =  true );

/* Safer vesions of string functions */
#ifdef WIN_PLATFORM

#define strcpy_safe strcpy_s
#define strncpy_safe strncpy_s
#define strcat_safe strcat_s
#define strncat_safe strncat_s
#define sprintf_safe sprintf_s

#else

/* Possible errors during string operations */
#define ERROR_SAFE_INVALID_PARAM -1
#define ERROR_SAFE_BUFFER_OVERFLOW -2

size_t  strlen_safe ( const   char  *str);

size_t  strnlen_safe ( const   char  *str,  size_t  maxSize);

static   void  copyChars ( char  *dest,  const   char  *src,  size_t  numChars);

int   strcpy_safe  ( char  *dest,  size_t  dest_size,  const   char  *src);

int   strncpy_safe  ( char  *dest,  size_t  dest_size,  const   char  *src,  size_t  n);

int   strcat_safe  ( char  *dest,  size_t  dest_size,  const   char  *src);

int   strncat_safe  ( char  *dest,  size_t  dest_size,  const   char  *src,  size_t  n);

#define sprintf_safe snprintf

#endif

#ifdef __cplusplus
}
#endif

#endif  /* _MyPDFLibUtils_H_ */