Fixed up postscript stuff, now prints on Unix

This commit is contained in:
dcone%netscape.com 1999-03-01 16:23:36 +00:00
Родитель 4924b55d49
Коммит 8764cbc65a
8 изменённых файлов: 3058 добавлений и 2980 удалений

Просмотреть файл

@ -299,6 +299,7 @@ AFMFontInformation *fontinfo;
* @update 2/26/99 dwc
*/
void
nsAFMObject::GetKey(AFMKey *aKey)
{
PRInt32 key,len;
@ -338,7 +339,7 @@ PRBool found = PR_FALSE;
if(cmpvalue == 0){
found = PR_TRUE;
}else{
if (cmpvalue <0){
if (cmpvalue <0){
upper = midpoint-1;
}else{
lower = midpoint+1;
@ -609,10 +610,9 @@ PRUnichar *cptr;
PRInt32 i ,fwidth,index;
PRInt32 totallen=0;
//XXX This is not handle correctly yet!! DWC
//XXX This is not handle correctly yet!! DWC
aWidth = 0;
cptr = (PRUnichar*)aString;
cptr = (PRUnichar*)aString;
for(i=0;i<aLength;i++,cptr++){
asciichar = (*cptr)&0x00ff;
@ -622,5 +622,4 @@ PRInt32 totallen=0;
}
aWidth = totallen;
}

Просмотреть файл

@ -12,15 +12,15 @@
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsAFMObject_h__
#define nsAFMObject_h__
#include "nsIFontMetrics.h"
#include "nsFont.h"
#include "nsString.h"
@ -31,7 +31,6 @@
class nsDeviceContextPS;
// AFM Key Words
typedef enum
{
@ -78,6 +77,7 @@ typedef enum
kBlendDesignMap,
kBlendAxisTypes,
// Writing direction information.
kStartDirection,
kEndDirection,
@ -131,6 +131,7 @@ typedef enum
kAxisType,
kAxisLabel,
// Master Design Information
kStartMaster,
kEndMaster
@ -142,6 +143,7 @@ typedef enum
// Single character infor for AFM character.
struct AFM_Single_Char_Metrics
{
PRInt32 mCharacter_Code; // default charcode (-1 if not encoded)
double mW0x; // character width x in writing direction 0
double mW0y; // character width y in writing direction 0
@ -158,14 +160,16 @@ struct AFM_Single_Char_Metrics
double mUry;
double num_ligatures;
//AFMLigature *ligatures;
};
typedef struct AFM_Single_Char_Metrics AFMscm;
// Font information which we get from AFM files, this is needed for the PS output
struct fontInformation
{
double mFontVersion;
@ -196,46 +200,137 @@ struct fontInformation
double mUnderlineThickness;
AFMscm *AFMCharMetrics;
};
typedef struct fontInformation AFMFontInformation;
class nsAFMObject
{
public:
/** ---------------------------------------------------
* Construct and AFMObject
* @update 2/26/99 dwc
*/
nsAFMObject();
virtual ~nsAFMObject();
/** ---------------------------------------------------
* delete an AFMObject
* @update 2/26/99 dwc
*/
virtual ~nsAFMObject();
/** ---------------------------------------------------
* Initialize an AFMObject
* @update 2/26/99 dwc
* @param aFontName - A "C" string name of the font this object will get initialized to
* @param aFontHeight -- The font size for this object
*/
void Init(char *aFontName,PRInt32 aFontHeight);
/** ---------------------------------------------------
* Calculate the width of a unicharacter string
* @update 2/26/99 dwc
* @param aString - The unicharacter string to get the width for
* @param aWidth - Where the width of the string will be put.
* @param aLenth - The length of the passed in string
*/
void GetStringWidth(const PRUnichar *aString,nscoord& aWidth,nscoord aLength);
/** ---------------------------------------------------
* Calculate the width of a C style string
* @update 2/26/99 dwc
* @param aString - The C string to get the width for
* @param aWidth - Where the width of the string will be put.
* @param aLenth - The length of the passed in string
*/
void GetStringWidth(const char *aString,nscoord& aWidth,nscoord aLength);
protected:
/** ---------------------------------------------------
* Read in and parse and AFM file
* @update 2/26/99 dwc
*/
void AFM_ReadFile(void);
/** ---------------------------------------------------
* Get a Keyword in the AFM file being parsed
* @update 2/26/99 dwc
*/
void GetKey(AFMKey *aTheKey);
/** ---------------------------------------------------
* Get a token from the AFM file
* @update 2/26/99 dwc
*/
PRInt32 GetToken(void);
/** ---------------------------------------------------
* For a given token, find the keyword it represents
* @update 2/26/99 dwc
*/
PRInt32 MatchKey(char *aKey);
/** ---------------------------------------------------
* Get a line from the currently parsed file
* @update 2/26/99 dwc
*/
PRInt32 GetLine(void);
/** ---------------------------------------------------
* Get a string from the currently parsed file
* @update 2/26/99 dwc
*/
char* GetAFMString (void);
/** ---------------------------------------------------
* Get a word from the currently parsed file
* @update 2/26/99 dwc
*/
char* GetAFMName (void);
/** ---------------------------------------------------
* Get an integer from the currently parsed file
* @update 2/26/99 dwc
*/
void GetAFMInt (PRInt32 *aInt) {GetToken();*aInt = atoi (mToken);}
/** ---------------------------------------------------
* Get a floating point number from the currently parsed file
* @update 2/26/99 dwc
*/
void GetAFMNumber (double *aFloat){GetToken();*aFloat = atof (mToken);}
/** ---------------------------------------------------
* Get a boolean from the currently parsed file
* @update 2/26/99 dwc
*/
void GetAFMBool (PRBool *aBool);
/** ---------------------------------------------------
* Read in the AFMFontInformation from the currently parsed AFM file
* @update 2/26/99 dwc
*/
void ReadCharMetrics (AFMFontInformation *aFontInfo,PRInt32 aNumCharacters);
public:
AFMFontInformation *mPSFontInfo;
protected:
FILE *mAFMFile; // this is the file we are reading for the AFM files
char mToken[256]; // this is where we put the token for reading;
nscoord mFontHeight; // font height in points
FILE *mAFMFile; // this is the AFM file we are parsing.
char mToken[256]; // Temporary storage for reading and parsing the file
nscoord mFontHeight; // font height in points that we are supporting.
// XXX This should be passed into the GetStringWidth
// so we can have one font family support many sizes
};
#define NUM_KEYS (sizeof (keynames) / sizeof (struct keyname_st) - 1)
#endif

Просмотреть файл

@ -203,6 +203,7 @@ NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
}
}
// Return the color space
aColorSpace = mColorSpace;
IL_AddRefToColorSpace(aColorSpace);
@ -279,7 +280,6 @@ NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
@ -291,13 +291,13 @@ NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
{
// end the page
mPSObj->end_page();
return NS_OK;
@ -313,7 +313,10 @@ NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixe
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetMetricsFor(const nsFont& aFont, nsIFontMetrics *&aMetrics)
{
PRInt32 n,cnt;

Просмотреть файл

@ -135,13 +135,13 @@ nsFontMetricsPS :: Destroy()
void
nsFontMetricsPS::RealizeFont()
{
double fontsize;
float fontsize;
float dev2app;
mDeviceContext->GetDevUnitsToAppUnits(dev2app);
nscoord onePixel = NSToCoordRound(1 * dev2app);
fontsize = mFont->size/20.0;
fontsize = mFont->size/20.0f;
mXHeight = NSToCoordRound((float)((fontsize*mAFMInfo->mPSFontInfo->mXHeight)/1000.0)*dev2app);
mSuperscriptOffset = mXHeight;

Просмотреть файл

@ -55,74 +55,68 @@ PrintSetup* ps = new PrintSetup();
memset(ps, 0, sizeof(struct PrintSetup_));
memset(pi, 0, sizeof(struct PrintInfo_));
ps->top = 0; /* Margins (PostScript Only) */
ps->top = 0; // Margins (PostScript Only)
ps->bottom = 0;
ps->left = 0;
ps->right = 0;
ps->width = PAGE_WIDTH; /* Paper size, # of cols for text xlate */
ps->width = PAGE_WIDTH; // Paper size, # of cols for text xlate
ps->height = PAGE_HEIGHT;
ps->header = "header";
ps->footer = "footer";
ps->sizes = NULL;
ps->reverse = 0; /* Output order, 0 is acsending */
ps->color = TRUE; /* Image output */
ps->deep_color = TRUE; /* 24 bit color output */
ps->landscape = FALSE; /* Rotated output */
ps->underline = TRUE; /* underline links */
ps->scale_images = TRUE; /* Scale unsized images which are too big */
ps->scale_pre = FALSE; /* do the pre-scaling thing */
ps->dpi = 72.0f; /* dpi for externally sized items */
ps->rules = 1.0f; /* Scale factor for rulers */
ps->n_up = 0; /* cool page combining */
ps->bigger = 1; /* Used to init sizes if sizesin NULL */
ps->paper_size = NS_LEGAL_SIZE; /* Paper Size(letter,legal,exec,a4) */
ps->prefix = ""; /* For text xlate, prepended to each line */
ps->eol = ""; /* For text translation, line terminator */
ps->bullet = "+"; /* What char to use for bullets */
ps->reverse = 0; // Output order, 0 is acsending
ps->color = TRUE; // Image output
ps->deep_color = TRUE; // 24 bit color output
ps->landscape = FALSE; // Rotated output
ps->underline = TRUE; // underline links
ps->scale_images = TRUE; // Scale unsized images which are too big
ps->scale_pre = FALSE; // do the pre-scaling thing
ps->dpi = 72.0f; // dpi for externally sized items
ps->rules = 1.0f; // Scale factor for rulers
ps->n_up = 0; // cool page combining
ps->bigger = 1; // Used to init sizes if sizesin NULL
ps->paper_size = NS_LEGAL_SIZE; // Paper Size(letter,legal,exec,a4)
ps->prefix = ""; // For text xlate, prepended to each line
ps->eol = ""; // For text translation, line terminator
ps->bullet = "+"; // What char to use for bullets
URL_Struct_* url = new URL_Struct_;
memset(url, 0, sizeof(URL_Struct_));
ps->url = url; /* url of doc being translated */
ps->url = url; // url of doc being translated
char filename[30];
static char g_nsPostscriptFileCount = 0; //('a');
static char g_nsPostscriptFileCount = 0; //('a');
char ext[30];
sprintf(ext,"%d",g_nsPostscriptFileCount);
sprintf(filename,"file%s.ps", ext);
g_nsPostscriptFileCount++;
ps->out = fopen(filename , "w"); /* Where to send the output */
ps->filename = filename; /* output file name, if any */
ps->completion = NULL; /* Called when translation finished */
ps->carg = NULL; /* Data saved for completion routine */
ps->status = 0; /* Status of URL on completion */
/* "other" font is for encodings other than iso-8859-1 */
ps->out = fopen(filename , "w"); // Where to send the output
ps->filename = filename; // output file name, if any
ps->completion = NULL; // Called when translation finished
ps->carg = NULL; // Data saved for completion routine
ps->status = 0; // Status of URL on completion
// "other" font is for encodings other than iso-8859-1
ps->otherFontName[0] = NULL;
/* name of "other" PostScript font */
// name of "other" PostScript font
ps->otherFontInfo[0] = NULL;
/* font info parsed from "other" afm file */
ps->otherFontCharSetID = 0; /* charset ID of "other" font */
//ps->cx = NULL; /* original context, if available */
// font info parsed from "other" afm file
ps->otherFontCharSetID = 0; // charset ID of "other" font
//ps->cx = NULL; // original context, if available
pi->page_height = PAGE_HEIGHT * 10; /* Size of printable area on page */
pi->page_width = PAGE_WIDTH * 10; /* Size of printable area on page */
pi->page_break = 0; /* Current page bottom */
pi->page_topy = 0; /* Current page top */
pi->page_height=PAGE_HEIGHT * 10; // Size of printable area on page
pi->page_width = PAGE_WIDTH * 10; // Size of printable area on page
pi->page_break = 0; // Current page bottom
pi->page_topy = 0; // Current page top
pi->phase = 0;
/*
** CONTINUE SPECIAL
** The table print code maintains these
*/
pi->pages=NULL; /* Contains extents of each page */
pi->pt_size = 0; /* Size of above table */
pi->n_pages = 0; /* # of valid entries in above table */
/*
** END SPECIAL
*/
pi->pages=NULL; // Contains extents of each page
pi->doc_title="Test Title"; /* best guess at title */
pi->doc_width = 0; /* Total document width */
pi->doc_height = 0; /* Total document height */
pi->pt_size = 0; // Size of above table
pi->n_pages = 0; // # of valid entries in above table
pi->doc_title="Test Title"; // best guess at title
pi->doc_width = 0; // Total document width
pi->doc_height = 0; // Total document height
mPrintContext->prInfo = pi;
@ -131,11 +125,9 @@ PrintSetup* ps = new PrintSetup();
begin_document();
mPrintSetup = ps;
mPageNumber = 1; // we are on the first page
mPageNumber = 1; // we are on the first page
}
/** ---------------------------------------------------
* Destructor
* @update 2/1/99 dwc
@ -148,15 +140,16 @@ nsPostScriptObj::~nsPostScriptObj()
finalize_translation();
// Cleanup things allocated along the way
if (nsnull != mPrintContext){
if (nsnull != mPrintContext->prInfo)
delete mPrintContext->prInfo;
if (nsnull != mPrintContext->prSetup)
delete mPrintContext->prSetup;
delete mPrintContext;
if (nsnull != mPrintContext->prInfo){
delete mPrintContext->prInfo;
}
if (nsnull != mPrintContext->prSetup){
delete mPrintContext->prSetup;
}
delete mPrintContext;
}
if (nsnull != mPrintSetup)
@ -191,11 +184,10 @@ nsPostScriptObj::initialize_translation(PrintSetup* pi)
dup->left = POINT_TO_PAGE(dup->left);
dup->bottom = POINT_TO_PAGE(dup->bottom);
dup->right = POINT_TO_PAGE(dup->right);
if (pi->landscape)
{
if (pi->landscape){
dup->height = POINT_TO_PAGE(pi->width);
dup->width = POINT_TO_PAGE(pi->height);
/* XXX Should I swap the margins too ??? */
//XXX Should I swap the margins too ???
}
}
@ -206,144 +198,155 @@ nsPostScriptObj::initialize_translation(PrintSetup* pi)
void
nsPostScriptObj::begin_document()
{
int i;
XP_File f;
char* charset_name = NULL;
int i;
XP_File f;
char* charset_name = NULL;
f = mPrintContext->prSetup->out;
XP_FilePrintf(f, "%%!PS-Adobe-3.0\n");
XP_FilePrintf(f, "%%%%BoundingBox: %d %d %d %d\n",
PAGE_TO_POINT_I(mPrintContext->prSetup->left),
PAGE_TO_POINT_I(mPrintContext->prSetup->bottom),
PAGE_TO_POINT_I(mPrintContext->prSetup->width-mPrintContext->prSetup->right),
PAGE_TO_POINT_I(mPrintContext->prSetup->height-mPrintContext->prSetup->top));
XP_FilePrintf(f, "%%%%Creator: Mozilla (NetScape) HTML->PS\n");
XP_FilePrintf(f, "%%%%DocumentData: Clean8Bit\n");
XP_FilePrintf(f, "%%%%DocumentPaperSizes: %s\n",
paper_string[mPrintContext->prSetup->paper_size]);
XP_FilePrintf(f, "%%%%Orientation: %s\n",
(mPrintContext->prSetup->width < mPrintContext->prSetup->height) ? "Portrait" : "Landscape");
XP_FilePrintf(f, "%%%%Pages: %d\n", (int) mPrintContext->prInfo->n_pages);
if (mPrintContext->prSetup->reverse)
XP_FilePrintf(f, "%%%%PageOrder: Descend\n");
else
XP_FilePrintf(f, "%%%%PageOrder: Ascend\n");
XP_FilePrintf(f, "%%%%Title: %s\n", mPrintContext->prInfo->doc_title);
f = mPrintContext->prSetup->out;
XP_FilePrintf(f, "%%!PS-Adobe-3.0\n");
XP_FilePrintf(f, "%%%%BoundingBox: %d %d %d %d\n",
PAGE_TO_POINT_I(mPrintContext->prSetup->left),
PAGE_TO_POINT_I(mPrintContext->prSetup->bottom),
PAGE_TO_POINT_I(mPrintContext->prSetup->width-mPrintContext->prSetup->right),
PAGE_TO_POINT_I(mPrintContext->prSetup->height-mPrintContext->prSetup->top));
XP_FilePrintf(f, "%%%%Creator: Mozilla (NetScape) HTML->PS\n");
XP_FilePrintf(f, "%%%%DocumentData: Clean8Bit\n");
XP_FilePrintf(f, "%%%%DocumentPaperSizes: %s\n",
paper_string[mPrintContext->prSetup->paper_size]);
XP_FilePrintf(f, "%%%%Orientation: %s\n",
(mPrintContext->prSetup->width < mPrintContext->prSetup->height) ? "Portrait" : "Landscape");
XP_FilePrintf(f, "%%%%Pages: %d\n", (int) mPrintContext->prInfo->n_pages);
if (mPrintContext->prSetup->reverse)
XP_FilePrintf(f, "%%%%PageOrder: Descend\n");
else
XP_FilePrintf(f, "%%%%PageOrder: Ascend\n");
XP_FilePrintf(f, "%%%%Title: %s\n", mPrintContext->prInfo->doc_title);
#ifdef NOTYET
XP_FilePrintf(f, "%%%%For: %n", user_name_stuff);
XP_FilePrintf(f, "%%%%For: %n", user_name_stuff);
#endif
XP_FilePrintf(f, "%%%%EndComments\n");
XP_FilePrintf(f, "%%%%EndComments\n");
/* general comments: Mozilla-specific */
XP_FilePrintf(f, "\n%% MozillaURL: %s\n", mPrintContext->prSetup->url->address);
/* get charset name of non-latin1 fonts */
/* for external filters, supply information */
if (mPrintContext->prSetup->otherFontName[0] || mPrintContext->prSetup->otherFontInfo[0]){
INTL_CharSetIDToName(mPrintContext->prSetup->otherFontCharSetID, charset_name);
XP_FilePrintf(f, "%% MozillaCharsetName: %s\n\n", charset_name);
}else
/* default: iso-8859-1 */
XP_FilePrintf(f, "%% MozillaCharsetName: iso-8859-1\n\n");
// general comments: Mozilla-specific
XP_FilePrintf(f, "\n%% MozillaURL: %s\n", mPrintContext->prSetup->url->address);
// get charset name of non-latin1 fonts
// for external filters, supply information
if (mPrintContext->prSetup->otherFontName[0] || mPrintContext->prSetup->otherFontInfo[0]){
INTL_CharSetIDToName(mPrintContext->prSetup->otherFontCharSetID, charset_name);
XP_FilePrintf(f, "%% MozillaCharsetName: %s\n\n", charset_name);
}else{
// default: iso-8859-1
XP_FilePrintf(f, "%% MozillaCharsetName: iso-8859-1\n\n");
}
/* now begin prolog */
XP_FilePrintf(f, "%%%%BeginProlog\n");
XP_FilePrintf(f, "[");
for (i = 0; i < 256; i++)
{
if (*isotab[i] == '\0')
XP_FilePrintf(f, " /.notdef");
else
XP_FilePrintf(f, " /%s", isotab[i]);
if (( i % 6) == 5)
XP_FilePrintf(f, "\n");
}
XP_FilePrintf(f, "] /isolatin1encoding exch def\n");
// now begin prolog
XP_FilePrintf(f, "%%%%BeginProlog\n");
XP_FilePrintf(f, "[");
for (i = 0; i < 256; i++){
if (*isotab[i] == '\0'){
XP_FilePrintf(f, " /.notdef");
}else{
XP_FilePrintf(f, " /%s", isotab[i]);
}
for (i = 0; i < N_FONTS; i++)
XP_FilePrintf(f,
"/F%d\n"
" /%s findfont\n"
" dup length dict begin\n"
" {1 index /FID ne {def} {pop pop} ifelse} forall\n"
" /Encoding isolatin1encoding def\n"
" currentdict end\n"
"definefont pop\n"
"/f%d { /F%d findfont exch scalefont setfont } bind def\n",
i, PSFE_MaskToFI[i]->name, i, i);
for (i = 0; i < N_FONTS; i++)
if (mPrintContext->prSetup->otherFontName[i]) {
XP_FilePrintf(f,
"/of%d { /%s findfont exch scalefont setfont } bind def\n",
i, mPrintContext->prSetup->otherFontName[i]);
/* XP_FilePrintf(f, "/of /of1;\n", mPrintContext->prSetup->otherFontName); */
}
XP_FilePrintf(f, "/rhc {\n");
XP_FilePrintf(f, " {\n");
XP_FilePrintf(f, " currentfile read {\n");
XP_FilePrintf(f, " dup 97 ge\n");
XP_FilePrintf(f, " { 87 sub true exit }\n");
XP_FilePrintf(f, " { dup 48 ge { 48 sub true exit } { pop } ifelse }\n");
XP_FilePrintf(f, " ifelse\n");
XP_FilePrintf(f, " } {\n");
XP_FilePrintf(f, " false\n");
XP_FilePrintf(f, " exit\n");
XP_FilePrintf(f, " } ifelse\n");
XP_FilePrintf(f, " } loop\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "\n");
XP_FilePrintf(f, "/cvgray { %% xtra_char npix cvgray - (string npix long)\n");
XP_FilePrintf(f, " dup string\n");
XP_FilePrintf(f, " 0\n");
XP_FilePrintf(f, " {\n");
XP_FilePrintf(f, " rhc { cvr 4.784 mul } { exit } ifelse\n");
XP_FilePrintf(f, " rhc { cvr 9.392 mul } { exit } ifelse\n");
XP_FilePrintf(f, " rhc { cvr 1.824 mul } { exit } ifelse\n");
XP_FilePrintf(f, " add add cvi 3 copy put pop\n");
XP_FilePrintf(f, " 1 add\n");
XP_FilePrintf(f, " dup 3 index ge { exit } if\n");
XP_FilePrintf(f, " } loop\n");
XP_FilePrintf(f, " pop\n");
XP_FilePrintf(f, " 3 -1 roll 0 ne { rhc { pop } if } if\n");
XP_FilePrintf(f, " exch pop\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "\n");
XP_FilePrintf(f, "/smartimage12rgb { %% w h b [matrix] smartimage12rgb -\n");
XP_FilePrintf(f, " /colorimage where {\n");
XP_FilePrintf(f, " pop\n");
XP_FilePrintf(f, " { currentfile rowdata readhexstring pop }\n");
XP_FilePrintf(f, " false 3\n");
XP_FilePrintf(f, " colorimage\n");
XP_FilePrintf(f, " } {\n");
XP_FilePrintf(f, " exch pop 8 exch\n");
XP_FilePrintf(f, " 3 index 12 mul 8 mod 0 ne { 1 } { 0 } ifelse\n");
XP_FilePrintf(f, " 4 index\n");
XP_FilePrintf(f, " 6 2 roll\n");
XP_FilePrintf(f, " { 2 copy cvgray }\n");
XP_FilePrintf(f, " image\n");
XP_FilePrintf(f, " pop pop\n");
XP_FilePrintf(f, " } ifelse\n");
XP_FilePrintf(f, "} def\n");
XP_FilePrintf(f,"/cshow { dup stringwidth pop 2 div neg 0 rmoveto show } bind def\n");
XP_FilePrintf(f,"/rshow { dup stringwidth pop neg 0 rmoveto show } bind def\n");
XP_FilePrintf(f, "/BeginEPSF {\n");
XP_FilePrintf(f, " /b4_Inc_state save def\n");
XP_FilePrintf(f, " /dict_count countdictstack def\n");
XP_FilePrintf(f, " /op_count count 1 sub def\n");
XP_FilePrintf(f, " userdict begin\n");
XP_FilePrintf(f, " /showpage {} def\n");
XP_FilePrintf(f, " 0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin\n");
XP_FilePrintf(f, " 10 setmiterlimit [] 0 setdash newpath\n");
XP_FilePrintf(f, " /languagelevel where\n");
XP_FilePrintf(f, " { pop languagelevel 1 ne\n");
XP_FilePrintf(f, " { false setstrokeadjust false setoverprint } if\n");
XP_FilePrintf(f, " } if\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "/EndEPSF {\n");
XP_FilePrintf(f, " count op_count sub {pop} repeat\n");
XP_FilePrintf(f, " countdictstack dict_count sub {end} repeat\n");
XP_FilePrintf(f, " b4_Inc_state restore\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "%%%%EndProlog\n");
if (( i % 6) == 5){
XP_FilePrintf(f, "\n");
}
}
XP_FilePrintf(f, "] /isolatin1encoding exch def\n");
for (i = 0; i < N_FONTS; i++){
XP_FilePrintf(f,
"/F%d\n"
" /%s findfont\n"
" dup length dict begin\n"
" {1 index /FID ne {def} {pop pop} ifelse} forall\n"
" /Encoding isolatin1encoding def\n"
" currentdict end\n"
"definefont pop\n"
"/f%d { /F%d findfont exch scalefont setfont } bind def\n",
i, PSFE_MaskToFI[i]->name, i, i);
}
for (i = 0; i < N_FONTS; i++){
if (mPrintContext->prSetup->otherFontName[i]) {
XP_FilePrintf(f,
"/of%d { /%s findfont exch scalefont setfont } bind def\n",
i, mPrintContext->prSetup->otherFontName[i]);
//XP_FilePrintf(f, "/of /of1;\n", mPrintContext->prSetup->otherFontName);
}
}
XP_FilePrintf(f, "/rhc {\n");
XP_FilePrintf(f, " {\n");
XP_FilePrintf(f, " currentfile read {\n");
XP_FilePrintf(f, " dup 97 ge\n");
XP_FilePrintf(f, " { 87 sub true exit }\n");
XP_FilePrintf(f, " { dup 48 ge { 48 sub true exit } { pop } ifelse }\n");
XP_FilePrintf(f, " ifelse\n");
XP_FilePrintf(f, " } {\n");
XP_FilePrintf(f, " false\n");
XP_FilePrintf(f, " exit\n");
XP_FilePrintf(f, " } ifelse\n");
XP_FilePrintf(f, " } loop\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "\n");
XP_FilePrintf(f, "/cvgray { %% xtra_char npix cvgray - (string npix long)\n");
XP_FilePrintf(f, " dup string\n");
XP_FilePrintf(f, " 0\n");
XP_FilePrintf(f, " {\n");
XP_FilePrintf(f, " rhc { cvr 4.784 mul } { exit } ifelse\n");
XP_FilePrintf(f, " rhc { cvr 9.392 mul } { exit } ifelse\n");
XP_FilePrintf(f, " rhc { cvr 1.824 mul } { exit } ifelse\n");
XP_FilePrintf(f, " add add cvi 3 copy put pop\n");
XP_FilePrintf(f, " 1 add\n");
XP_FilePrintf(f, " dup 3 index ge { exit } if\n");
XP_FilePrintf(f, " } loop\n");
XP_FilePrintf(f, " pop\n");
XP_FilePrintf(f, " 3 -1 roll 0 ne { rhc { pop } if } if\n");
XP_FilePrintf(f, " exch pop\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "\n");
XP_FilePrintf(f, "/smartimage12rgb { %% w h b [matrix] smartimage12rgb -\n");
XP_FilePrintf(f, " /colorimage where {\n");
XP_FilePrintf(f, " pop\n");
XP_FilePrintf(f, " { currentfile rowdata readhexstring pop }\n");
XP_FilePrintf(f, " false 3\n");
XP_FilePrintf(f, " colorimage\n");
XP_FilePrintf(f, " } {\n");
XP_FilePrintf(f, " exch pop 8 exch\n");
XP_FilePrintf(f, " 3 index 12 mul 8 mod 0 ne { 1 } { 0 } ifelse\n");
XP_FilePrintf(f, " 4 index\n");
XP_FilePrintf(f, " 6 2 roll\n");
XP_FilePrintf(f, " { 2 copy cvgray }\n");
XP_FilePrintf(f, " image\n");
XP_FilePrintf(f, " pop pop\n");
XP_FilePrintf(f, " } ifelse\n");
XP_FilePrintf(f, "} def\n");
XP_FilePrintf(f,"/cshow { dup stringwidth pop 2 div neg 0 rmoveto show } bind def\n");
XP_FilePrintf(f,"/rshow { dup stringwidth pop neg 0 rmoveto show } bind def\n");
XP_FilePrintf(f, "/BeginEPSF {\n");
XP_FilePrintf(f, " /b4_Inc_state save def\n");
XP_FilePrintf(f, " /dict_count countdictstack def\n");
XP_FilePrintf(f, " /op_count count 1 sub def\n");
XP_FilePrintf(f, " userdict begin\n");
XP_FilePrintf(f, " /showpage {} def\n");
XP_FilePrintf(f, " 0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin\n");
XP_FilePrintf(f, " 10 setmiterlimit [] 0 setdash newpath\n");
XP_FilePrintf(f, " /languagelevel where\n");
XP_FilePrintf(f, " { pop languagelevel 1 ne\n");
XP_FilePrintf(f, " { false setstrokeadjust false setoverprint } if\n");
XP_FilePrintf(f, " } if\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "/EndEPSF {\n");
XP_FilePrintf(f, " count op_count sub {pop} repeat\n");
XP_FilePrintf(f, " countdictstack dict_count sub {end} repeat\n");
XP_FilePrintf(f, " b4_Inc_state restore\n");
XP_FilePrintf(f, "} bind def\n");
XP_FilePrintf(f, "%%%%EndProlog\n");
}
/** ---------------------------------------------------
@ -353,14 +356,14 @@ nsPostScriptObj::begin_document()
void
nsPostScriptObj::begin_page()
{
XP_File f;
XP_File f;
f = mPrintContext->prSetup->out;
XP_FilePrintf(f, "%%%%Page: %d %d\n", mPageNumber, mPageNumber);
XP_FilePrintf(f, "%%%%BeginPageSetup\n/pagelevel save def\n");
if (mPrintContext->prSetup->landscape)
XP_FilePrintf(f, "%d 0 translate 90 rotate\n",
PAGE_TO_POINT_I(mPrintContext->prSetup->height));
if (mPrintContext->prSetup->landscape){
XP_FilePrintf(f, "%d 0 translate 90 rotate\n",PAGE_TO_POINT_I(mPrintContext->prSetup->height));
}
XP_FilePrintf(f, "%d 0 translate\n", PAGE_TO_POINT_I(mPrintContext->prSetup->left));
XP_FilePrintf(f, "%%%%EndPageSetup\n");
#if 0
@ -404,7 +407,7 @@ nsPostScriptObj::end_page()
void
nsPostScriptObj::end_document()
{
XP_FilePrintf(mPrintContext->prSetup->out, "%%%%EOF\n");
XP_FilePrintf(mPrintContext->prSetup->out, "%%%%EOF\n");
}
@ -415,6 +418,7 @@ nsPostScriptObj::end_document()
void
nsPostScriptObj::annotate_page(char *aTemplate, int y, int delta_dir, int pn)
{
}
/** ---------------------------------------------------
@ -424,27 +428,29 @@ nsPostScriptObj::annotate_page(char *aTemplate, int y, int delta_dir, int pn)
void
nsPostScriptObj::show(char* txt, int len, char *align)
{
XP_File f;
XP_File f;
f = mPrintContext->prSetup->out;
XP_FilePrintf(f, "(");
while (len-- > 0) {
switch (*txt) {
f = mPrintContext->prSetup->out;
XP_FilePrintf(f, "(");
while (len-- > 0) {
switch (*txt) {
case '(':
case ')':
case '\\':
XP_FilePrintf(f, "\\%c", *txt);
break;
XP_FilePrintf(f, "\\%c", *txt);
break;
default:
if (*txt < ' ' || (*txt & 0x80))
XP_FilePrintf(f, "\\%o", *txt & 0xff);
else
XP_FilePrintf(f, "%c", *txt);
if (*txt < ' ' || (*txt & 0x80)){
XP_FilePrintf(f, "\\%o", *txt & 0xff);
}else{
XP_FilePrintf(f, "%c", *txt);
}
break;
}
txt++;
}
XP_FilePrintf(f, ") %sshow\n", align);
}
txt++;
}
XP_FilePrintf(f, ") %sshow\n", align);
}
/** ---------------------------------------------------
@ -456,9 +462,8 @@ nsPostScriptObj::moveto(int x, int y)
{
XL_SET_NUMERIC_LOCALE();
y -= mPrintContext->prInfo->page_topy;
/*
** Agh! Y inversion again !!
*/
// invert y
y = (mPrintContext->prInfo->page_height - y - 1) + mPrintContext->prSetup->bottom;
XP_FilePrintf(mPrintContext->prSetup->out, "%g %g moveto\n",
@ -477,9 +482,7 @@ nsPostScriptObj::moveto_loc(int x, int y)
XL_SET_NUMERIC_LOCALE();
/*
** Agh! Y inversion again !!
*/
// invert y
y = (mPrintContext->prSetup->height - y - 1);
XP_FilePrintf(mPrintContext->prSetup->out, "%g %g moveto\n",
@ -555,7 +558,7 @@ nsPostScriptObj::box( int aW, int aH)
{
XL_SET_NUMERIC_LOCALE();
XP_FilePrintf(mPrintContext->prSetup->out, "%g 0 rlineto 0 %g rlineto %g 0 rlineto ",
PAGE_TO_POINT_F(aW), -PAGE_TO_POINT_F(aH), -PAGE_TO_POINT_F(aW));
PAGE_TO_POINT_F(aW), -PAGE_TO_POINT_F(aH), -PAGE_TO_POINT_F(aW));
XL_RESTORE_NUMERIC_LOCALE();
}
@ -568,7 +571,7 @@ nsPostScriptObj::box_subtract( int aW, int aH)
{
XL_SET_NUMERIC_LOCALE();
XP_FilePrintf(mPrintContext->prSetup->out,"0 %g rlineto %g 0 rlineto 0 %g rlineto ",
PAGE_TO_POINT_F(-aH), PAGE_TO_POINT_F(aW), PAGE_TO_POINT_F(aH));
PAGE_TO_POINT_F(-aH), PAGE_TO_POINT_F(aW), PAGE_TO_POINT_F(aH));
XL_RESTORE_NUMERIC_LOCALE();
}
@ -649,8 +652,8 @@ nsPostScriptObj::line( int x1, int y1, int x2, int y2, int thick)
y2 = (mPrintContext->prInfo->page_height - y2 - 1) + mPrintContext->prSetup->bottom;
XP_FilePrintf(mPrintContext->prSetup->out, "%g %g moveto %g %g lineto\n",
PAGE_TO_POINT_F(x1), PAGE_TO_POINT_F(y1),
PAGE_TO_POINT_F(x2), PAGE_TO_POINT_F(y2));
PAGE_TO_POINT_F(x1), PAGE_TO_POINT_F(y1),
PAGE_TO_POINT_F(x2), PAGE_TO_POINT_F(y2));
stroke();
XP_FilePrintf(mPrintContext->prSetup->out, "grestore\n");
@ -739,7 +742,6 @@ PRUint8 *theBits,*curline;
bytewidth = 3*width;
cbits = 8;
XP_FilePrintf(mPrintContext->prSetup->out, "gsave\n");
XP_FilePrintf(mPrintContext->prSetup->out, "/rowdata %d string def\n",bytewidth);
translate(aX, aY + aHeight);
@ -801,7 +803,7 @@ int postscriptFont = 0;
case NS_FONT_STYLE_NORMAL :
if (NS_IS_BOLD(aWeight)) {
postscriptFont = 1; // NORMAL BOLD
} else {
}else{
postscriptFont = 0; // NORMAL
}
break;
@ -809,7 +811,7 @@ int postscriptFont = 0;
case NS_FONT_STYLE_ITALIC:
if (NS_IS_BOLD(aWeight)) {
postscriptFont = 3; // BOLD ITALIC
} else {
}else{
postscriptFont = 2; // ITALIC
}
break;
@ -817,7 +819,7 @@ int postscriptFont = 0;
case NS_FONT_STYLE_OBLIQUE:
if (NS_IS_BOLD(aWeight)) {
postscriptFont = 7; // COURIER-BOLD OBLIQUE
} else {
}else{
postscriptFont = 6; // COURIER OBLIQUE
}
break;

Просмотреть файл

@ -74,62 +74,42 @@ typedef struct LineRecord_struct LineRecord;
** Used to store state needed while translation is in progress
*/
struct PrintInfo_ {
/*
** BEGIN SPECIAL
** If using the table print code, the following fields must
** be properly set up.
*/
int32 page_height; /* Size of printable area on page */
int32 page_width; /* Size of printable area on page */
int32 page_break; /* Current page bottom */
int32 page_topy; /* Current page top */
// for table printing
int32 page_height; // Size of printable area on page
int32 page_width; // Size of printable area on page
int32 page_break; // Current page bottom
int32 page_topy; // Current page top
int phase;
/*
** CONTINUE SPECIAL
** The table print code maintains these
*/
PageBreaks *pages; /* Contains extents of each page */
PageBreaks *pages; // Contains extents of each page
int pt_size; /* Size of above table */
int n_pages; /* # of valid entries in above table */
/*
** END SPECIAL
*/
int pt_size; // Size of above table
int n_pages; // # of valid entries in above table
/*
** AAAOOOGAH
**
** These are used to cache values from the originating context's
** function table
*/
void (*scnatt)(MWContext*); /* SetCallNetlibAllTheTime */
void (*ccnatt)(MWContext*); /* CLearCallNetlibAllTheTime */
void (*scnatt)(MWContext*); // SetCallNetlibAllTheTime
void (*ccnatt)(MWContext*); // CLearCallNetlibAllTheTime
char* doc_title; /* best guess at title */
int32 doc_width; /* Total document width */
int32 doc_height; /* Total document height */
char* doc_title; // best guess at title
int32 doc_width; // Total document width
int32 doc_height; // Total document height
#ifdef LATER
float scale; /* for shrinking pre areas */
int32 pre_start; /* First y of current pre section */
int32 pre_end; /* Last y of current pre section */
XP_List *interesting; /* List of pre's about which I care */
XP_Bool in_pre; /* True when inside a <pre> section */
THIS IS GOING TO BE DELETED XXXXX
float scale;
int32 pre_start;
int32 pre_end;
XP_List *interesting;
XP_Bool in_pre;
#endif
/*
** These fields are used only by the text translator
*/
char *line; /* Pointer to data for the current line */
XP_Bool in_table; /* True when caching lines in a table */
XP_Bool first_line_p; /* true when the first line has not yet been
output - this is a kludge for the mail
citation code. */
int table_top, /* Size of the table being cached */
table_bottom;
LineRecord *saved_lines; /* cached lines for tables */
int last_y; /* Used to track blank lines */
// These fields are used only by the text translator
char *line; // Pointer to data for the current line
XP_Bool in_table; // True when caching lines in a table
XP_Bool first_line_p; // delete all this
int table_top,table_bottom;
LineRecord *saved_lines; // cached lines for tables
int last_y; // Used to track blank lines
};
typedef struct PrintInfo_ PrintInfo;
@ -138,61 +118,60 @@ typedef struct PrintInfo_ PrintInfo;
** Used to pass info into text and/or postscript translation
*/
struct PrintSetup_ {
int top; /* Margins (PostScript Only) */
int top; // Margins (PostScript Only)
int bottom;
int left;
int right;
int width; /* Paper size, # of cols for text xlate */
int width; // Paper size, # of cols for text xlate
int height;
char* header;
char* footer;
int *sizes;
XP_Bool reverse; /* Output order */
XP_Bool color; /* Image output */
XP_Bool deep_color; /* 24 bit color output */
XP_Bool landscape; /* Rotated output */
XP_Bool underline; /* underline links */
XP_Bool scale_images; /* Scale unsized images which are too big */
XP_Bool scale_pre; /* do the pre-scaling thing */
float dpi; /* dpi for externally sized items */
float rules; /* Scale factor for rulers */
int n_up; /* cool page combining */
int bigger; /* Used to init sizes if sizesin NULL */
int paper_size; /* Paper Size(letter,legal,exec,a4) */
XP_Bool reverse; // Output order
XP_Bool color; // Image output
XP_Bool deep_color; // 24 bit color output
XP_Bool landscape; // Rotated output
XP_Bool underline; // underline links
XP_Bool scale_images; // Scale unsized images which are too big
XP_Bool scale_pre; // do the pre-scaling thing
float dpi; // dpi for externally sized items
float rules; // Scale factor for rulers
int n_up; // cool page combining
int bigger; // Used to init sizes if sizesin NULL
int paper_size; // Paper Size(letter,legal,exec,a4)
char* prefix; /* For text xlate, prepended to each line */
char* eol; /* For text translation, line terminator */
char* bullet; /* What char to use for bullets */
char* prefix; // For text xlate, prepended to each line
char* eol; // For text translation, line terminator
char* bullet; // What char to use for bullets
struct URL_Struct_ *url; /* url of doc being translated */
XP_File out; /* Where to send the output */
char *filename; /* output file name, if any */
XL_CompletionRoutine completion; /* Called when translation finished */
void* carg; /* Data saved for completion routine */
int status; /* Status of URL on completion */
struct URL_Struct_ *url; // url of doc being translated
XP_File out; // Where to send the output
char *filename; // output file name, if any
XL_CompletionRoutine completion; // Called when translation finished
void* carg; // Data saved for completion routine
int status; // Status of URL on completion
/* "other" font is for encodings other than iso-8859-1 */
// "other" font is for encodings other than iso-8859-1
char *otherFontName[N_FONTS];
/* name of "other" PostScript font */
// name of "other" PostScript font
PS_FontInfo *otherFontInfo[N_FONTS];
/* font info parsed from "other" afm file */
int16 otherFontCharSetID; /* charset ID of "other" font */
// font info parsed from "other" afm file
int16 otherFontCharSetID; // charset ID of "other" font
//MWContext *cx; /* original context, if available */
};
typedef struct PrintSetup_ PrintSetup;
struct PSContext_{
char *url; /* URL of current document */
char * name; /* name of this context */
char * title; /* title (if supplied) of current document */
PrintSetup *prSetup; /* Info about print job */
PrintInfo *prInfo; /* State information for printing process */
char *url; // URL of current document
char * name; // name of this context
char * title; // title (if supplied) of current document
PrintSetup *prSetup; // Info about print job
PrintInfo *prInfo; // State information for printing process
};
typedef struct PSContext_ PSContext;
@ -382,7 +361,7 @@ private:
* Set up the postscript
* @update 2/1/99 dwc
*/
void initialize_translation(PrintSetup* aPi);
void initialize_translation(PrintSetup* aPi);
};