Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
nsPostScriptObj.cpp File Reference
#include "gfx-config.h"
#include "prlog.h"
#include "nscore.h"
#include "nsIAtom.h"
#include "nsPostScriptObj.h"
#include "isotab.c"
#include "nsFont.h"
#include "nsIImage.h"
#include "nsAFMObject.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include "nsReadableUtils.h"
#include "nsICharsetAlias.h"
#include "nsNetUtil.h"
#include "nsIPersistentProperties2.h"
#include "nsCRT.h"
#include "nsFontMetricsPS.h"
#include "nsPaperPS.h"
#include "nsBuildID.h"
#include "nsPrintfCString.h"
#include "prenv.h"
#include "prprf.h"
#include "prerror.h"
#include <errno.h>
#include <sys/wait.h>

Go to the source code of this file.

Classes

class  fpCString
struct  _unixPrinterFallbacks_t
struct  PrefEnumClosure

Defines

#define FORCE_PR_LOG   /* Allow logging in the release build */
#define PR_LOGGING   1
#define NS_PS_RED(x)   (((float)(NS_GET_R(x))) / 255.0)
#define NS_PS_GREEN(x)   (((float)(NS_GET_G(x))) / 255.0)
#define NS_PS_BLUE(x)   (((float)(NS_GET_B(x))) / 255.0)
#define NS_PS_GRAY(x)   (((float)(x)) / 255.0)
#define NS_RGB_TO_GRAY(r, g, b)   ((int(r) * 77 + int(g) * 150 + int(b) * 29) / 256)
#define NS_IS_BOLD(x)   (((x) >= 401) ? 1 : 0)

Typedefs

typedef struct
_unixPrinterFallbacks_t 
unixPrinterFallbacks_t

Functions

static NS_DEFINE_CID (kPrefCID, NS_PREF_CID)
static NS_DEFINE_CID (kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID)
static PRBool FreeU2Ntable (nsHashKey *aKey, void *aData, void *aClosure)
static PRBool ResetU2Ntable (nsHashKey *aKey, void *aData, void *aClosure)
static PRBool FreeLangGroups (nsHashKey *aKey, void *aData, void *aClosure)
static void PrintAsDSCTextline (FILE *f, const char *text, int maxlen)
PRBool GetUnixPrinterFallbackSetting (const nsCAutoString &aKey, char **aVal)
static void PrefEnumCallback (const char *aName, void *aClosure)

Variables

static PRLogModuleInfonsPostScriptObjLM = PR_NewLogModule("nsPostScriptObj")
static nsIUnicodeEncodergEncoder = nsnull
static nsHashtable * gU2Ntable = nsnull
static nsIPrefgPrefs = nsnull
static nsHashtable * gLangGroups = nsnull
static const unixPrinterFallbacks_t unixPrinterFallbacks []
const char * kNativeFontPrefix = "print.postscript.nativefont."
const char * kUnicodeFontPrefix = "print.postscript.unicodefont."

Class Documentation

struct _unixPrinterFallbacks_t

Definition at line 2627 of file nsPostScriptObj.cpp.

Class Members
const char * key
const char * val
struct PrefEnumClosure

Definition at line 2656 of file nsPostScriptObj.cpp.

Class Members
FILE * handle
nsPostScriptObj * psObj

Define Documentation

#define FORCE_PR_LOG   /* Allow logging in the release build */

Definition at line 52 of file nsPostScriptObj.cpp.

#define NS_IS_BOLD (   x)    (((x) >= 401) ? 1 : 0)

Definition at line 111 of file nsPostScriptObj.cpp.

#define NS_PS_BLUE (   x)    (((float)(NS_GET_B(x))) / 255.0)

Definition at line 108 of file nsPostScriptObj.cpp.

#define NS_PS_GRAY (   x)    (((float)(x)) / 255.0)

Definition at line 109 of file nsPostScriptObj.cpp.

#define NS_PS_GREEN (   x)    (((float)(NS_GET_G(x))) / 255.0)

Definition at line 107 of file nsPostScriptObj.cpp.

#define NS_PS_RED (   x)    (((float)(NS_GET_R(x))) / 255.0)

Definition at line 106 of file nsPostScriptObj.cpp.

#define NS_RGB_TO_GRAY (   r,
  g,
  b 
)    ((int(r) * 77 + int(g) * 150 + int(b) * 29) / 256)

Definition at line 110 of file nsPostScriptObj.cpp.

#define PR_LOGGING   1

Definition at line 53 of file nsPostScriptObj.cpp.


Typedef Documentation


Function Documentation

static PRBool FreeLangGroups ( nsHashKey *  aKey,
void aData,
void aClosure 
) [static]

Definition at line 142 of file nsPostScriptObj.cpp.

{
  PS_LangGroupInfo *linfo = (PS_LangGroupInfo *) aData;

  NS_IF_RELEASE(linfo->mEncoder);

  if (linfo->mU2Ntable) {
    linfo->mU2Ntable->Reset(FreeU2Ntable, nsnull);
    delete linfo->mU2Ntable;
    linfo->mU2Ntable = nsnull;
  }
  delete linfo;
  linfo = nsnull;
  return PR_TRUE;
}

Here is the call graph for this function:

static PRBool FreeU2Ntable ( nsHashKey *  aKey,
void aData,
void aClosure 
) [static]

Definition at line 125 of file nsPostScriptObj.cpp.

{
  delete(int *) aData;
  return PR_TRUE;
}

Here is the caller graph for this function:

PRBool GetUnixPrinterFallbackSetting ( const nsCAutoString aKey,
char **  aVal 
)

Definition at line 2639 of file nsPostScriptObj.cpp.

{
  const unixPrinterFallbacks_t *p;
  const char* key = aKey.get();
  for (p=unixPrinterFallbacks; p->key; p++) {
    if (strcmp(key, p->key) == 0) {
      *aVal = nsCRT::strdup(p->val);
      return PR_TRUE;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kPrefCID  ,
NS_PREF_CID   
) [static]
static NS_DEFINE_CID ( kCharsetConverterManagerCID  ,
NS_ICHARSETCONVERTERMANAGER_CID   
) [static]
static void PrefEnumCallback ( const char *  aName,
void aClosure 
) [static]

Definition at line 2662 of file nsPostScriptObj.cpp.

{
  nsPostScriptObj *psObj = ((PrefEnumClosure *)aClosure)->psObj;
  FILE *f = ((PrefEnumClosure *)aClosure)->handle;
  nsAutoString lang; lang.AssignWithConversion(aName);


  if (strstr(aName, kNativeFontPrefix)) {
    NS_ASSERTION(strlen(kNativeFontPrefix) == 28, "Wrong hard-coded size.");
    lang.Cut(0, 28);
  } else if (strstr(aName, kUnicodeFontPrefix)) {
    NS_ASSERTION(strlen(kNativeFontPrefix) == 29, "Wrong hard-coded size.");
    lang.Cut(0, 29);
  }
  nsStringKey key(lang);

  PS_LangGroupInfo *linfo = (PS_LangGroupInfo *) gLangGroups->Get(&key);

  if (linfo) {
    /* already exist */
    return;
  }

  /* define new language group */
  nsXPIDLCString psnativefont;
  nsXPIDLCString psnativecode;
  nsXPIDLCString psunicodefont;
  int psfontorder = 0;
  PRBool use_prefsfile = PR_FALSE;
  PRBool use_vendorfile = PR_FALSE;

  //
  // Try to get the info from the user's prefs file
  //
  nsCAutoString namepsnativefont(kNativeFontPrefix);
  namepsnativefont.AppendWithConversion(lang);
  gPrefs->CopyCharPref(namepsnativefont.get(), getter_Copies(psnativefont));

  nsCAutoString namepsnativecode("print.postscript.nativecode.");
  namepsnativecode.AppendWithConversion(lang);
  gPrefs->CopyCharPref(namepsnativecode.get(), getter_Copies(psnativecode));
  if (((psnativefont)&&(*psnativefont)) && ((psnativecode)&&(*psnativecode))) {
    use_prefsfile = PR_TRUE;
  } else {
    psnativefont.Adopt(0);
    psnativecode.Adopt(0);
  }

  //
  // if not found look for info from the printer vendor
  //
  if (use_prefsfile != PR_TRUE) {
    psObj->GetUnixPrinterSetting(namepsnativefont, getter_Copies(psnativefont));
    psObj->GetUnixPrinterSetting(namepsnativecode, getter_Copies(psnativecode));
    if ((psnativefont) && (psnativecode)) {
      use_vendorfile = PR_TRUE;
    } else {
      psnativefont.Adopt(0);
      psnativecode.Adopt(0);
    }
  }
  if (!use_prefsfile && !use_vendorfile) {
    GetUnixPrinterFallbackSetting(namepsnativefont, getter_Copies(psnativefont));
    GetUnixPrinterFallbackSetting(namepsnativecode, getter_Copies(psnativecode));
  }

  /* psnativefont and psnativecode both should be set */
  if (!psnativefont || !psnativecode) {
    psnativefont.Adopt(0);
    psnativecode.Adopt(0);
  } else {
    nsCAutoString namepsfontorder("print.postscript.fontorder.");
    namepsfontorder.AppendWithConversion(lang);
    if (use_prefsfile) {
      gPrefs->GetIntPref(namepsfontorder.get(), &psfontorder);
    }
    else if (use_vendorfile) {
      nsXPIDLCString psfontorder_str;
      psObj->GetUnixPrinterSetting(namepsfontorder, getter_Copies(psfontorder_str));
      if (psfontorder_str) {
        psfontorder = atoi(psfontorder_str);
      }
    }
  }

  /* check UCS fonts */
  nsCAutoString namepsunicodefont(kUnicodeFontPrefix);
  namepsunicodefont.AppendWithConversion(lang);
  if (use_prefsfile) {
    gPrefs->CopyCharPref(namepsunicodefont.get(), getter_Copies(psunicodefont));
  } else if (use_vendorfile) {
    psObj->GetUnixPrinterSetting(namepsunicodefont, getter_Copies(psunicodefont));
  }

  nsresult res = NS_OK;

  if (psnativefont || psunicodefont) {
    linfo = new PS_LangGroupInfo;
    linfo->mEncoder = nsnull;
    linfo->mU2Ntable = nsnull;

    if (psnativecode) {
      nsAutoString str;
      nsCOMPtr<nsICharsetConverterManager> ccMain =
        do_GetService(kCharsetConverterManagerCID, &res);
      
      if (NS_SUCCEEDED(res)) {
        res = ccMain->GetUnicodeEncoder(psnativecode.get(), &linfo->mEncoder);
      }
    }

    gLangGroups->Put(&key, (void *) linfo);

    nsCAutoString langstrC; langstrC.AssignWithConversion(lang);
    if (psnativefont && linfo->mEncoder) {
      fprintf(f, "/Unicode2NativeDict%s 0 dict def\n", langstrC.get());
    }

    fprintf(f, "/%s_ls {\n", langstrC.get());
    fprintf(f, "  /NativeFont /%s def\n",
      (psnativefont && linfo->mEncoder) ? psnativefont.get() : "Courier");
    fprintf(f, "  /UCS2Font /%s def\n",
                psunicodefont ? psunicodefont.get() : "Courier");
    if (psnativefont && linfo->mEncoder) {
      fprintf(f, "  /Unicode2NativeDict Unicode2NativeDict%s def\n",
                  langstrC.get());
    }

    if (psfontorder) {
      fprintf(f, "  /unicodeshow1 { real_unicodeshow_native } bind def\n");
      fprintf(f, "  /unicodeshow2 { real_unicodeshow } bind def\n");
    } else {
      fprintf(f, "  /unicodeshow1 { real_unicodeshow } bind def\n");
      fprintf(f, "  /unicodeshow2 { real_unicodeshow_native } bind def\n");
    }

    fprintf(f, "} bind def\n");

    if (linfo->mEncoder) {
      linfo->mEncoder->SetOutputErrorBehavior(
                  linfo->mEncoder->kOnError_Replace, nsnull, '?');
      linfo->mU2Ntable = new nsHashtable();
    }
  }
}

Here is the call graph for this function:

static void PrintAsDSCTextline ( FILE f,
const char *  text,
int  maxlen 
) [static]

Definition at line 159 of file nsPostScriptObj.cpp.

{
  NS_ASSERTION(maxlen > 1, "bad max length");

  if (*text != '(') {
    // Format as DSC textline type
    fprintf(f, "%.*s", maxlen, text);
    return;
  }

  // Fallback: Format as DSC text type
  fprintf(f, "(");

  int len = maxlen - 2;
  while (*text && len > 0) {
    if (!isprint(*text)) {
      if (len < 4) break;
      fprintf(f, "\\%03o", *text);
      len -= 4;
    }
    else if (*text == '(' || *text == ')' || *text == '\\') {
      if (len < 2) break;
      fprintf(f, "\\%c", *text);
      len -= 2;
    }
    else {
      fprintf(f, "%c", *text);
      len--;
    }
    text++;
  }
  fprintf(f, ")");
}

Here is the call graph for this function:

static PRBool ResetU2Ntable ( nsHashKey *  aKey,
void aData,
void aClosure 
) [static]

Definition at line 132 of file nsPostScriptObj.cpp.

{
  PS_LangGroupInfo *linfo = (PS_LangGroupInfo *)aData;
  if (linfo && linfo->mU2Ntable) {
    linfo->mU2Ntable->Reset(FreeU2Ntable, nsnull);
  }
  return PR_TRUE;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 119 of file nsPostScriptObj.cpp.

nsHashtable* gLangGroups = nsnull [static]

Definition at line 122 of file nsPostScriptObj.cpp.

nsIPref* gPrefs = nsnull [static]

Definition at line 121 of file nsPostScriptObj.cpp.

nsHashtable* gU2Ntable = nsnull [static]

Definition at line 120 of file nsPostScriptObj.cpp.

const char* kNativeFontPrefix = "print.postscript.nativefont."

Definition at line 2653 of file nsPostScriptObj.cpp.

const char* kUnicodeFontPrefix = "print.postscript.unicodefont."

Definition at line 2654 of file nsPostScriptObj.cpp.

PRLogModuleInfo* nsPostScriptObjLM = PR_NewLogModule("nsPostScriptObj") [static]

Definition at line 91 of file nsPostScriptObj.cpp.

Initial value:
 {
  {"print.postscript.nativefont.ja", "Ryumin-Light-EUC-H"},
  {"print.postscript.nativecode.ja", "euc-jp"},
  {nsnull, nsnull}
}

Definition at line 2632 of file nsPostScriptObj.cpp.