nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ) { PRBool      isGray, isAPrinter, isFirstPageFirst; int         landscape; float       fwidth, fheight; const char *printername;  PrintInfo* pi = new PrintInfo(); mPrintSetup = new PrintSetup();  if( (nsnull!=pi) && (nsnull!=mPrintSetup) ){ memset(mPrintSetup, 0, sizeof(struct PrintSetup_));  mPrintSetup->color = PR_TRUE; mPrintSetup->deep_color = PR_TRUE; mPrintSetup->reverse = 0; if ( aSpec != nsnull ) { aSpec->GetCopies(mPrintSetup->num_copies); aSpec->GetGrayscale( isGray ); if ( isGray == PR_TRUE ) { mPrintSetup->color = PR_FALSE; mPrintSetup->deep_color = PR_FALSE; }  aSpec->GetFirstPageFirst( isFirstPageFirst ); if ( isFirstPageFirst == PR_FALSE ) mPrintSetup->reverse = 1;   const char *paper_name = nsnull; aSpec->GetPaperName(&paper_name); mPrintSetup->paper_size = paper_name_to_PSPaperSizeRec(paper_name);  if (!mPrintSetup->paper_size) return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED;  aSpec->GetToPrinter( isAPrinter ); if (isAPrinter) {    aSpec->GetPrinterName(&printername);   if (printername) {  printername = printername + NS_POSTSCRIPT_DRIVER_NAME_LEN;  if (!strcmp(printername, "default")) printername = ""; } else printername = "";   static char *moz_printer_string; char *old_printer_string = moz_printer_string; moz_printer_string = PR_smprintf("MOZ_PRINTER_NAME=%s", printername); #ifdef DEBUG printf("setting '%s'\n", moz_printer_string); #endif  if (!moz_printer_string) {  moz_printer_string = old_printer_string; return (PR_OUT_OF_MEMORY_ERROR == PR_GetError()) ? NS_ERROR_OUT_OF_MEMORY : NS_ERROR_UNEXPECTED; } else { PR_SetEnv(moz_printer_string); if (old_printer_string) PR_smprintf_free(old_printer_string); }   aSpec->GetCommand(&mPrintSetup->print_cmd); mPrintSetup->out = tmpfile(); mPrintSetup->filename = nsnull; } else { const char *path; aSpec->GetPath(&path); mPrintSetup->filename = path; mPrintSetup->out = fopen(mPrintSetup->filename, "w"); if (!mPrintSetup->out) return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE; } mPrintSetup->tmpBody = tmpfile(); NS_ENSURE_TRUE(mPrintSetup->tmpBody, NS_ERROR_FAILURE); mPrintSetup->tmpBody_filename = nsnull; } else return NS_ERROR_FAILURE;    if (!mPrintSetup->out) return NS_ERROR_GFX_PRINTER_CMD_FAILURE;  mPrintContext = new PSContext(); memset(mPrintContext, 0, sizeof(struct PSContext_)); memset(pi, 0, sizeof(struct PrintInfo_));  mPrintSetup->dpi = 72.0f; aSpec->GetLandscape( landscape ); fwidth  = mPrintSetup->paper_size->width; fheight = mPrintSetup->paper_size->height;  if (landscape) { float temp; temp   = fwidth; fwidth = fheight; fheight = temp; }  mPrintSetup->left   = NSToCoordRound(mPrintSetup->paper_size->left * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); mPrintSetup->top    = NSToCoordRound(mPrintSetup->paper_size->top * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); mPrintSetup->bottom = NSToCoordRound(mPrintSetup->paper_size->bottom * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); mPrintSetup->right  = NSToCoordRound(mPrintSetup->paper_size->right * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);  mPrintSetup->width  = NSToCoordRound(fwidth * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); mPrintSetup->height = NSToCoordRound(fheight * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT); #ifdef DEBUG printf("\nPreWidth = %f PreHeight = %f\n",fwidth,fheight); printf("\nWidth = %d Height = %d\n",mPrintSetup->width,mPrintSetup->height); #endif mPrintSetup->header = "header"; mPrintSetup->footer = "footer"; mPrintSetup->sizes = nsnull;  mPrintSetup->landscape = (landscape) ? PR_TRUE : PR_FALSE;   mPrintSetup->underline = PR_TRUE; mPrintSetup->scale_images = PR_TRUE; mPrintSetup->scale_pre = PR_FALSE;   PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("dpi %g top %d bottom %d left %d right %d\n", mPrintSetup->dpi, mPrintSetup->top, mPrintSetup->bottom, mPrintSetup->left, mPrintSetup->right));  mPrintSetup->rules = 1.0f; mPrintSetup->n_up = 0; mPrintSetup->bigger = 1; mPrintSetup->prefix = ""; mPrintSetup->eol = ""; mPrintSetup->bullet = "+";  #ifdef NOTYET URL_Struct_* url = new URL_Struct_; memset(url, 0, sizeof(URL_Struct_)); mPrintSetup->url = url; #else mPrintSetup->url = nsnull; #endif mPrintSetup->completion = nsnull; mPrintSetup->carg = nsnull; mPrintSetup->status = 0;  pi->page_height = mPrintSetup->height; pi->page_width = mPrintSetup->width; pi->page_break = 0; pi->page_topy = 0; pi->phase = 0;   pi->pages = nsnull;  pi->pt_size = 0; pi->n_pages = 0;  mTitle = nsnull;  pi->doc_title = mTitle; pi->doc_width = 0; pi->doc_height = 0;  mPrintContext->prInfo = pi;   initialize_translation(mPrintSetup);  begin_document(); mPageNumber = 1; return NS_OK; } else { return NS_ERROR_FAILURE; } }
NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWidget) {return NS_ERROR_NOT_IMPLEMENTED;}
nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec ){  PRBool      isGray,              isAPrinter,              isFirstPageFirst;  int         landscape;  float       fwidth, fheight;  const char *printername;  PrintInfo* pi = new PrintInfo();   mPrintSetup = new PrintSetup();  if( (nsnull!=pi) && (nsnull!=mPrintSetup) ){    memset(mPrintSetup, 0, sizeof(struct PrintSetup_));        mPrintSetup->color = PR_TRUE;              // Image output     mPrintSetup->deep_color = PR_TRUE;         // 24 bit color output     mPrintSetup->reverse = 0;                  // Output order, 0 is acsending     if ( aSpec != nsnull ) {      aSpec->GetCopies(mPrintSetup->num_copies);      aSpec->GetGrayscale( isGray );      if ( isGray == PR_TRUE ) {        mPrintSetup->color = PR_FALSE;         mPrintSetup->deep_color = PR_FALSE;       }      aSpec->GetFirstPageFirst( isFirstPageFirst );      if ( isFirstPageFirst == PR_FALSE )        mPrintSetup->reverse = 1;      /* Find PS paper size record by name */      const char *paper_name = nsnull;      aSpec->GetPaperName(&paper_name);          mPrintSetup->paper_size = paper_name_to_PSPaperSizeRec(paper_name);      if (!mPrintSetup->paper_size)        return NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED;                     aSpec->GetToPrinter( isAPrinter );      if (isAPrinter) {        /* Define the destination printer (queue).          * We assume that the print command is set to          * "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}"          * - which means that if the ${MOZ_PRINTER_NAME} env var is not empty         * the "-P" option of lpr will be set to the printer name.         */        /* get printer name */        aSpec->GetPrinterName(&printername);                /* do not set the ${MOZ_PRINTER_NAME} env var if we want the default          * printer */        if (printername)        {          /* strip the leading NS_POSTSCRIPT_DRIVER_NAME string */          printername = printername + NS_POSTSCRIPT_DRIVER_NAME_LEN;                    if (!strcmp(printername, "default"))            printername = "";        }        else           printername = "";        /* Construct an environment string MOZ_PRINTER_NAME=<printername>         * and add it to the environment.         * On a POSIX system the original buffer becomes part of the         * environment, so it must remain valid until replaced. To preserve         * the ability to unload shared libraries, we have to either remove         * the string from the environment at unload time or else store the         * string in the heap, where it'll be left behind after unloading         * the library.         */        static char *moz_printer_string;        char *old_printer_string = moz_printer_string;        moz_printer_string = PR_smprintf("MOZ_PRINTER_NAME=%s", printername);#ifdef DEBUG        printf("setting '%s'\n", moz_printer_string);#endif        if (!moz_printer_string) {          /* We're probably out of memory */          moz_printer_string = old_printer_string;          return (PR_OUT_OF_MEMORY_ERROR == PR_GetError()) ?             NS_ERROR_OUT_OF_MEMORY : NS_ERROR_UNEXPECTED;        }        else {          PR_SetEnv(moz_printer_string);          if (old_printer_string)            PR_smprintf_free(old_printer_string);        }                aSpec->GetCommand(&mPrintSetup->print_cmd);        mPrintSetup->out = tmpfile();        mPrintSetup->filename = nsnull;        } else {        const char *path;        aSpec->GetPath(&path);        mPrintSetup->filename = path;                  mPrintSetup->out = fopen(mPrintSetup->filename, "w");         if (!mPrintSetup->out)          return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE;      }      mPrintSetup->tmpBody = tmpfile();      NS_ENSURE_TRUE(mPrintSetup->tmpBody, NS_ERROR_FAILURE);      mPrintSetup->tmpBody_filename = nsnull;    } else         return NS_ERROR_FAILURE;    /* make sure the open worked */    if (!mPrintSetup->out)      return NS_ERROR_GFX_PRINTER_CMD_FAILURE;          mPrintContext = new PSContext();    memset(mPrintContext, 0, sizeof(struct PSContext_));    memset(pi, 0, sizeof(struct PrintInfo_));    mPrintSetup->dpi = 72.0f;   // dpi for externally sized items     aSpec->GetLandscape( landscape );    fwidth  = mPrintSetup->paper_size->width;    fheight = mPrintSetup->paper_size->height;    if (landscape) {      float temp;      temp   = fwidth;      fwidth = fheight;      fheight = temp;    }    mPrintSetup->left   = NSToCoordRound(mPrintSetup->paper_size->left                            * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);    mPrintSetup->top    = NSToCoordRound(mPrintSetup->paper_size->top                            * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);    mPrintSetup->bottom = NSToCoordRound(mPrintSetup->paper_size->bottom                            * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);    mPrintSetup->right  = NSToCoordRound(mPrintSetup->paper_size->right                            * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);        mPrintSetup->width  = NSToCoordRound(fwidth                            * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);    mPrintSetup->height = NSToCoordRound(fheight                            * mPrintSetup->dpi * TWIPS_PER_POINT_FLOAT);#ifdef DEBUG    printf("\nPreWidth = %f PreHeight = %f\n",fwidth,fheight);    printf("\nWidth = %d Height = %d\n",mPrintSetup->width,mPrintSetup->height);#endif    mPrintSetup->header = "header";    mPrintSetup->footer = "footer";    mPrintSetup->sizes = nsnull;    mPrintSetup->landscape = (landscape) ? PR_TRUE : PR_FALSE; // Rotated output     //mPrintSetup->landscape = PR_FALSE;    mPrintSetup->underline = PR_TRUE;             // underline links     mPrintSetup->scale_images = PR_TRUE;          // Scale unsized images which are too big     mPrintSetup->scale_pre = PR_FALSE;		        // do the pre-scaling thing     // scale margins (specified in inches) to dots.    PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("dpi %g top %d bottom %d left %d right %d\n",            mPrintSetup->dpi, mPrintSetup->top, mPrintSetup->bottom, mPrintSetup->left, mPrintSetup->right));    mPrintSetup->rules = 1.0f;			            // Scale factor for rulers     mPrintSetup->n_up = 0;                     // cool page combining     mPrintSetup->bigger = 1;                   // Used to init sizes if sizesin NULL     mPrintSetup->prefix = "";                  // For text xlate, prepended to each line     mPrintSetup->eol = "";			    // For text translation, line terminator     mPrintSetup->bullet = "+";                 // What char to use for bullets #ifdef NOTYET    URL_Struct_* url = new URL_Struct_;    memset(url, 0, sizeof(URL_Struct_));    mPrintSetup->url = url;                    // url of doc being translated #else    mPrintSetup->url = nsnull;#endif    mPrintSetup->completion = nsnull;          // Called when translation finished     mPrintSetup->carg = nsnull;                // Data saved for completion routine     mPrintSetup->status = 0;                   // Status of URL on completion     pi->page_height = mPrintSetup->height;	// Size of printable area on page     pi->page_width = mPrintSetup->width;	// Size of printable area on page     pi->page_break = 0;	              // Current page bottom     pi->page_topy = 0;	              // Current page top     pi->phase = 0;     pi->pages = nsnull;		                // Contains extents of each page     pi->pt_size = 0;		              // Size of above table     pi->n_pages = 0;	        	      // # of valid entries in above table     mTitle = nsnull;    pi->doc_title = mTitle;    pi->doc_width = 0;	              // Total document width     pi->doc_height = 0;	              // Total document height     mPrintContext->prInfo = pi;    // begin the document    initialize_translation(mPrintSetup);    begin_document();	    mPageNumber = 1;                  // we are on the first page    return NS_OK;    } else {    return NS_ERROR_FAILURE;    }}