зеркало из https://github.com/mozilla/pjs.git
Fixed the font information, added some postscript drawing routines.
This commit is contained in:
Родитель
6fb30ce75f
Коммит
9363ec90a2
|
@ -21,6 +21,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsFontMetricsPS.h"
|
||||
#include "prprf.h"
|
||||
#include "il_util.h"
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
|
@ -80,7 +81,7 @@ NS_IMETHODIMP nsDeviceContextPS :: Init(nsIDeviceContext *aCreatingDeviceContext
|
|||
float origscale, newscale;
|
||||
float t2d, a2d;
|
||||
|
||||
mDepth = 1;
|
||||
mDepth = 1; // just for arguments sake
|
||||
|
||||
mDC = aTheDC;
|
||||
|
||||
|
@ -169,14 +170,6 @@ NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
|
|||
return(1); // postscript is 1 bit
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
|
@ -184,11 +177,47 @@ NS_IMETHODIMP nsDeviceContextPS::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
|||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::GetILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
aColorSpace = nsnull;
|
||||
#ifdef NOTNOW
|
||||
if (nsnull == mColorSpace) {
|
||||
mColorSpace = IL_CreateGreyScaleColorSpace(1, 1);
|
||||
|
||||
if (nsnull == mColorSpace) {
|
||||
aColorSpace = nsnull;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the color space
|
||||
aColorSpace = mColorSpace;
|
||||
IL_AddRefToColorSpace(aColorSpace);
|
||||
#endif
|
||||
|
||||
if(nsnull==mColorSpace) {
|
||||
IL_RGBBits colorRGBBits;
|
||||
|
||||
// Create a 24-bit color space
|
||||
colorRGBBits.red_shift = 16;
|
||||
colorRGBBits.red_bits = 8;
|
||||
colorRGBBits.green_shift = 8;
|
||||
colorRGBBits.green_bits = 8;
|
||||
colorRGBBits.blue_shift = 0;
|
||||
colorRGBBits.blue_bits = 8;
|
||||
|
||||
mColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
|
||||
|
||||
if (nsnull == mColorSpace) {
|
||||
aColorSpace = nsnull;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the color space
|
||||
aColorSpace = mColorSpace;
|
||||
IL_AddRefToColorSpace(aColorSpace);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
|
@ -200,6 +229,20 @@ NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextPS :: GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
|
||||
switch (anID) {
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIDeviceContext.h
|
||||
* @update 12/21/98 dwc
|
||||
|
@ -245,7 +288,7 @@ PrintSetup* ps = new PrintSetup();
|
|||
ps->header = "header";
|
||||
ps->footer = "footer";
|
||||
ps->sizes = NULL;
|
||||
ps->reverse = 1; /* Output order */
|
||||
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 */
|
||||
|
@ -311,9 +354,8 @@ PrintSetup* ps = new PrintSetup();
|
|||
xl_initialize_translation(mPrintContext, ps);
|
||||
xl_begin_document(mPrintContext);
|
||||
mPrintSetup = ps;
|
||||
mPageNumber = 1; // we are on the first page
|
||||
|
||||
// begin the page
|
||||
xl_begin_page(mPrintContext, 1);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -324,8 +366,6 @@ PrintSetup* ps = new PrintSetup();
|
|||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
|
||||
{
|
||||
// end the page
|
||||
xl_end_page(mPrintContext, 1);
|
||||
|
||||
// end the document
|
||||
xl_end_document(mPrintContext);
|
||||
|
@ -355,6 +395,8 @@ NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
|
|||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
|
||||
{
|
||||
// begin the page
|
||||
xl_begin_page(mPrintContext, mPageNumber);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -365,6 +407,9 @@ NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
|
|||
*/
|
||||
NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
|
||||
{
|
||||
// end the page
|
||||
xl_end_page(mPrintContext, mPageNumber);
|
||||
mPageNumber++;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,24 @@
|
|||
#include "nsVoidArray.h"
|
||||
#include "nsPSStructs.h"
|
||||
|
||||
extern "C" void xl_begin_document(PSContext *cx);
|
||||
extern "C" void xl_initialize_translation(PSContext *cx, PrintSetup* ps);
|
||||
extern "C" void xl_end_document(PSContext *cx);
|
||||
extern "C" void xl_begin_page(PSContext *cx, int pn);
|
||||
extern "C" void xl_end_page(PSContext *cx, int pn);
|
||||
extern "C" void xl_finalize_translation(PSContext *cx);
|
||||
extern "C" void xl_show(PSContext *cx, char* txt, int len, char *align);
|
||||
extern "C" void xl_translate(PSContext* cx, int x, int y);
|
||||
extern "C" void xl_moveto(PSContext* cx, int x, int y);
|
||||
extern "C" void xl_line(PSContext* cx, int x1, int y1, int x2, int y2, int thick);
|
||||
extern "C" void xl_box(PSContext* cx, int w, int h);
|
||||
extern "C" void xl_begin_document(PSContext *aCX);
|
||||
extern "C" void xl_initialize_translation(PSContext *aCX, PrintSetup* aPS);
|
||||
extern "C" void xl_end_document(PSContext *aCX);
|
||||
extern "C" void xl_begin_page(PSContext *aCX, int aPN);
|
||||
extern "C" void xl_end_page(PSContext *aCX, int aPN);
|
||||
extern "C" void xl_finalize_translation(PSContext *aCX);
|
||||
extern "C" void xl_show(PSContext *aCX, char* aTxt, int aLen, char *aAlign);
|
||||
extern "C" void xl_translate(PSContext* aCX, int aX, int aY);
|
||||
extern "C" void xl_moveto(PSContext* aCX, int aX, int aY);
|
||||
extern "C" void xl_line(PSContext* aCX, int aX1, int aY1, int aX2, int aY2, int aThick);
|
||||
extern "C" void xl_box(PSContext* aCX, int w, int h);
|
||||
extern "C" void xl_moveto_loc(PSContext* aCX, int aX, int aY);
|
||||
extern "C" void xl_lineto(PSContext* aCX, int aX1, int aY1);
|
||||
extern "C" void xl_stroke(PSContext* aCX);
|
||||
extern "C" void xl_fill(PSContext* aCX);
|
||||
extern "C" void xl_closepath(PSContext* aCX);
|
||||
extern "C" void xl_graphics_save(PSContext *aCX);
|
||||
extern "C" void xl_graphics_restore(PSContext *aCX);
|
||||
|
||||
class nsDeviceContextWin; // need to be a friend of the class using us.
|
||||
|
||||
|
@ -66,15 +73,16 @@ public:
|
|||
|
||||
|
||||
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
|
||||
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
//NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
|
||||
|
||||
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
|
||||
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
nsIDeviceContext *&aContext);
|
||||
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext);
|
||||
NS_IMETHOD GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const;
|
||||
|
||||
|
||||
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics);
|
||||
NS_IMETHOD BeginDocument(void);
|
||||
|
@ -93,7 +101,7 @@ protected:
|
|||
PrintSetup *mPrintSetup;
|
||||
float mPixelScale;
|
||||
nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript.
|
||||
|
||||
PRUint16 mPageNumber;
|
||||
|
||||
|
||||
public:
|
||||
|
@ -101,7 +109,7 @@ public:
|
|||
PSContext* GetPrintContext() { return mPrintContext; }
|
||||
|
||||
public:
|
||||
HDC mDC;
|
||||
HDC mDC; // this is temporary!!!
|
||||
|
||||
friend nsDeviceContextWin; // need to be a friend of the class using us.
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "nsIScriptGlobalObject.h"
|
||||
#include "prprf.h"
|
||||
#include "nsPrintManager.h"
|
||||
#include "nsPSStructs.h" //XXX:PS This should be removed
|
||||
#include "nsPSStructs.h"
|
||||
|
||||
static NS_DEFINE_IID(kIRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
|
||||
|
||||
|
@ -36,6 +36,11 @@ static NS_DEFINE_IID(kIRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
|
|||
#define NS_PS_BLUE(x) (((float)(NS_GET_B(x))) / 255.0)
|
||||
#define NS_IS_BOLD(x) (((x) >= 500) ? 1 : 0)
|
||||
|
||||
#define FLAG_CLIP_VALID 0x0001
|
||||
#define FLAG_CLIP_CHANGED 0x0002
|
||||
#define FLAG_LOCAL_CLIP_VALID 0x0004
|
||||
|
||||
#define FLAGS_ALL (FLAG_CLIP_VALID | FLAG_CLIP_CHANGED | FLAG_LOCAL_CLIP_VALID)
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* Class definition of a postscript graphics state to me maintained
|
||||
|
@ -57,6 +62,7 @@ public:
|
|||
nscolor mPenColor;
|
||||
nscolor mTextColor;
|
||||
nsLineStyle mLineStyle;
|
||||
PRInt32 mFlags;
|
||||
};
|
||||
|
||||
/** ---------------------------------------------------
|
||||
|
@ -344,6 +350,50 @@ NS_IMETHODIMP nsRenderingContextPS :: IsVisibleRect(const nsRect& aRect, PRBool
|
|||
*/
|
||||
NS_IMETHODIMP nsRenderingContextPS :: SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty)
|
||||
{
|
||||
nsRect trect = aRect;
|
||||
int cliptype;
|
||||
|
||||
mStates->mLocalClip = aRect;
|
||||
|
||||
mTMatrix->TransformCoord(&trect.x, &trect.y,&trect.width, &trect.height);
|
||||
mStates->mFlags |= FLAG_LOCAL_CLIP_VALID;
|
||||
|
||||
// how we combine the new rect with the previous?
|
||||
if (aCombine == nsClipCombine_kIntersect){
|
||||
|
||||
//PushClipState();
|
||||
// push the clipstate onto the postscript stack
|
||||
xl_graphics_save(mPrintContext);
|
||||
|
||||
//cliptype = ::IntersectClipRect(mDC, trect.x,trect.y,trect.XMost(),trect.YMost());
|
||||
} else if (aCombine == nsClipCombine_kUnion){
|
||||
//PushClipState();
|
||||
xl_graphics_save(mPrintContext);
|
||||
//HRGN tregion = ::CreateRectRgn(trect.x,trect.y,trect.XMost(),trect.YMost());
|
||||
|
||||
//cliptype = ::ExtSelectClipRgn(mDC, tregion, RGN_OR);
|
||||
//::DeleteObject(tregion);
|
||||
}else if (aCombine == nsClipCombine_kSubtract){
|
||||
//PushClipState();
|
||||
xl_graphics_save(mPrintContext);
|
||||
|
||||
//cliptype = ::ExcludeClipRect(mDC, trect.x,trect.y,trect.XMost(),trect.YMost());
|
||||
}else if (aCombine == nsClipCombine_kReplace){
|
||||
//PushClipState();
|
||||
xl_graphics_save(mPrintContext);
|
||||
|
||||
//HRGN tregion = ::CreateRectRgn(trect.x,trect.y,trect.XMost(),trect.YMost());
|
||||
//cliptype = ::SelectClipRgn(mDC, tregion);
|
||||
//::DeleteObject(tregion);
|
||||
}else{
|
||||
NS_ASSERTION(FALSE, "illegal clip combination");
|
||||
}
|
||||
|
||||
if (cliptype == NULLREGION)
|
||||
aClipEmpty = PR_TRUE;
|
||||
else
|
||||
aClipEmpty = PR_FALSE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -354,8 +404,14 @@ NS_IMETHODIMP nsRenderingContextPS :: SetClipRect(const nsRect& aRect, nsClipCom
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: GetClipRect(nsRect &aRect, PRBool &aClipValid)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
if (mStates->mFlags & FLAG_LOCAL_CLIP_VALID){
|
||||
aRect = mStates->mLocalClip;
|
||||
aClipValid = PR_TRUE;
|
||||
}else{
|
||||
aClipValid = PR_FALSE;
|
||||
}
|
||||
|
||||
return NS_OK;}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
|
@ -523,14 +579,9 @@ nsRenderingContextPS :: DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord
|
|||
mTMatrix->TransformCoord(&aX0,&aY0);
|
||||
mTMatrix->TransformCoord(&aX1,&aY1);
|
||||
|
||||
// this has the moveto,lineto and the stroke
|
||||
xl_line(mPrintContext,NS_PIXELS_TO_POINTS(aX0),NS_PIXELS_TO_POINTS(aY0),
|
||||
NS_PIXELS_TO_POINTS(aX1),NS_PIXELS_TO_POINTS(aY1),1);
|
||||
|
||||
//SetupPen();
|
||||
|
||||
// support dashed lines here
|
||||
//::MoveToEx(mDC, (int)(aX0), (int)(aY0), NULL);
|
||||
//::LineTo(mDC, (int)(aX1), (int)(aY1));
|
||||
NS_PIXELS_TO_POINTS(aX1),NS_PIXELS_TO_POINTS(aY1),1);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -543,36 +594,29 @@ NS_IMETHODIMP
|
|||
nsRenderingContextPS :: DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
|
||||
if (nsLineStyle_kNone == mCurrLineStyle)
|
||||
return NS_OK;
|
||||
const nsPoint* np;
|
||||
POINT pp;
|
||||
|
||||
// First transform nsPoint's into POINT's; perform coordinate space
|
||||
// transformation at the same time
|
||||
POINT pts[20];
|
||||
POINT* pp0 = pts;
|
||||
np = &aPoints[0];
|
||||
|
||||
if (aNumPoints > 20)
|
||||
pp0 = new POINT[aNumPoints];
|
||||
pp.x = np->x;
|
||||
pp.y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp.x,(int*)&pp.y);
|
||||
xl_moveto_loc(mPrintContext,NS_PIXELS_TO_POINTS(pp.x),NS_PIXELS_TO_POINTS(pp.y));
|
||||
np++;
|
||||
|
||||
POINT* pp = pp0;
|
||||
const nsPoint* np = &aPoints[0];
|
||||
|
||||
for (PRInt32 i = 0; i < aNumPoints; i++, pp++, np++){
|
||||
pp->x = np->x;
|
||||
pp->y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
|
||||
// we are ignoring the linestyle
|
||||
for (PRInt32 i = 1; i < aNumPoints; i++, np++){
|
||||
pp.x = np->x;
|
||||
pp.y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp.x,(int*)&pp.y);
|
||||
xl_lineto(mPrintContext,NS_PIXELS_TO_POINTS(pp.x),NS_PIXELS_TO_POINTS(pp.y));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Draw the polyline
|
||||
//SetupPen();
|
||||
//::Polyline(mDC, pp0, int(aNumPoints));
|
||||
|
||||
// Release temporary storage if necessary
|
||||
if (pp0 != pts)
|
||||
delete pp0;
|
||||
// we dont close the path, this will give us a polyline
|
||||
xl_stroke(mPrintContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -584,17 +628,14 @@ nsRenderingContextPS :: DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: DrawRect(const nsRect& aRect)
|
||||
{
|
||||
RECT nr;
|
||||
nsRect tr;
|
||||
|
||||
tr = aRect;
|
||||
mTMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
|
||||
nr.left = tr.x;
|
||||
nr.top = tr.y;
|
||||
nr.right = tr.x+tr.width;
|
||||
nr.bottom = tr.y+tr.height;
|
||||
|
||||
//::FrameRect(mDC, &nr, SetupSolidBrush());
|
||||
xl_moveto(mPrintContext, NS_PIXELS_TO_POINTS(tr.x), NS_PIXELS_TO_POINTS(tr.y));
|
||||
xl_box(mPrintContext, NS_PIXELS_TO_POINTS(tr.width), NS_PIXELS_TO_POINTS(tr.height));
|
||||
xl_stroke(mPrintContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -606,15 +647,11 @@ nsRect tr;
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
RECT nr;
|
||||
|
||||
mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight);
|
||||
nr.left = aX;
|
||||
nr.top = aY;
|
||||
nr.right = aX+aWidth;
|
||||
nr.bottom = aY+aHeight;
|
||||
|
||||
//::FrameRect(mDC, &nr, SetupSolidBrush());
|
||||
xl_moveto(mPrintContext, NS_PIXELS_TO_POINTS(aX), NS_PIXELS_TO_POINTS(aY));
|
||||
xl_box(mPrintContext, NS_PIXELS_TO_POINTS(aWidth), NS_PIXELS_TO_POINTS(aHeight));
|
||||
xl_stroke(mPrintContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -626,19 +663,17 @@ RECT nr;
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: FillRect(const nsRect& aRect)
|
||||
{
|
||||
RECT nr;
|
||||
nsRect tr;
|
||||
nsRect tr;
|
||||
|
||||
tr = aRect;
|
||||
mTMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
|
||||
nr.left = tr.x;
|
||||
nr.top = tr.y;
|
||||
nr.right = tr.x+tr.width;
|
||||
nr.bottom = tr.y+tr.height;
|
||||
|
||||
PostscriptFillRect(NS_PIXELS_TO_POINTS(tr.x), NS_PIXELS_TO_POINTS(tr.y),
|
||||
NS_PIXELS_TO_POINTS(tr.width), NS_PIXELS_TO_POINTS(tr.height));
|
||||
xl_moveto(mPrintContext, NS_PIXELS_TO_POINTS(tr.x), NS_PIXELS_TO_POINTS(tr.y));
|
||||
xl_box(mPrintContext, NS_PIXELS_TO_POINTS(tr.width), NS_PIXELS_TO_POINTS(tr.height));
|
||||
xl_stroke(mPrintContext);
|
||||
|
||||
// should be fill, but layout ordering is broken, so we will settle for this now
|
||||
//xl_fill(mPrintContext);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -649,17 +684,12 @@ nsRenderingContextPS :: FillRect(const nsRect& aRect)
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
RECT nr;
|
||||
nsRect tr;
|
||||
|
||||
mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight);
|
||||
nr.left = aX;
|
||||
nr.top = aY;
|
||||
nr.right = aX+aWidth;
|
||||
nr.bottom = aY+aHeight;
|
||||
|
||||
//::FillRect(mDC, &nr, SetupSolidBrush());
|
||||
|
||||
xl_moveto(mPrintContext, NS_PIXELS_TO_POINTS(aX), NS_PIXELS_TO_POINTS(aY));
|
||||
xl_box(mPrintContext, NS_PIXELS_TO_POINTS(aWidth), NS_PIXELS_TO_POINTS(aHeight));
|
||||
xl_stroke(mPrintContext);
|
||||
// should be fill, but layout ordering is broken, so we will settle for this now
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -670,38 +700,29 @@ nsRenderingContextPS :: FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
const nsPoint* np;
|
||||
POINT pp;
|
||||
|
||||
// First transform nsPoint's into POINT's; perform coordinate space
|
||||
// transformation at the same time
|
||||
POINT pts[20];
|
||||
POINT* pp0 = pts;
|
||||
np = &aPoints[0];
|
||||
|
||||
if (aNumPoints > 20)
|
||||
pp0 = new POINT[aNumPoints];
|
||||
pp.x = np->x;
|
||||
pp.y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp.x,(int*)&pp.y);
|
||||
xl_moveto_loc(mPrintContext,NS_PIXELS_TO_POINTS(pp.x),NS_PIXELS_TO_POINTS(pp.y));
|
||||
np++;
|
||||
|
||||
POINT* pp = pp0;
|
||||
const nsPoint* np = &aPoints[0];
|
||||
|
||||
for (PRInt32 i = 0; i < aNumPoints; i++, pp++, np++){
|
||||
pp->x = np->x;
|
||||
pp->y = np->y;
|
||||
//mTMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
|
||||
// we are ignoring the linestyle
|
||||
for (PRInt32 i = 1; i < aNumPoints; i++, np++){
|
||||
pp.x = np->x;
|
||||
pp.y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp.x,(int*)&pp.y);
|
||||
xl_lineto(mPrintContext,NS_PIXELS_TO_POINTS(pp.x),NS_PIXELS_TO_POINTS(pp.y));
|
||||
}
|
||||
|
||||
// Outline the polygon - note we are implicitly ignoring the linestyle here
|
||||
LOGBRUSH lb;
|
||||
lb.lbStyle = BS_NULL;
|
||||
lb.lbColor = 0;
|
||||
lb.lbHatch = 0;
|
||||
//SetupSolidPen();
|
||||
//HBRUSH brush = ::CreateBrushIndirect(&lb);
|
||||
//HBRUSH oldBrush = (HBRUSH)::SelectObject(mDC, brush);
|
||||
//::Polygon(mDC, pp0, int(aNumPoints));
|
||||
//::SelectObject(mDC, oldBrush);
|
||||
//::DeleteObject(brush);
|
||||
|
||||
// Release temporary storage if necessary
|
||||
if (pp0 != pts)
|
||||
delete pp0;
|
||||
xl_closepath(mPrintContext);
|
||||
xl_stroke(mPrintContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -713,37 +734,29 @@ nsRenderingContextPS :: DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
const nsPoint* np;
|
||||
POINT pp;
|
||||
|
||||
// First transform nsPoint's into POINT's; perform coordinate space
|
||||
// transformation at the same time
|
||||
np = &aPoints[0];
|
||||
|
||||
POINT pts[20];
|
||||
POINT* pp0 = pts;
|
||||
pp.x = np->x;
|
||||
pp.y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp.x,(int*)&pp.y);
|
||||
xl_moveto_loc(mPrintContext,NS_PIXELS_TO_POINTS(pp.x),NS_PIXELS_TO_POINTS(pp.y));
|
||||
np++;
|
||||
|
||||
if (aNumPoints > 20)
|
||||
pp0 = new POINT[aNumPoints];
|
||||
|
||||
POINT* pp = pp0;
|
||||
const nsPoint* np = &aPoints[0];
|
||||
|
||||
for (PRInt32 i = 0; i < aNumPoints; i++, pp++, np++){
|
||||
pp->x = np->x;
|
||||
pp->y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
|
||||
// we are ignoring the linestyle
|
||||
for (PRInt32 i = 1; i < aNumPoints; i++, np++){
|
||||
pp.x = np->x;
|
||||
pp.y = np->y;
|
||||
mTMatrix->TransformCoord((int*)&pp.x,(int*)&pp.y);
|
||||
xl_lineto(mPrintContext,NS_PIXELS_TO_POINTS(pp.x),NS_PIXELS_TO_POINTS(pp.y));
|
||||
}
|
||||
|
||||
// Fill the polygon
|
||||
//SetupSolidBrush();
|
||||
|
||||
//if (NULL == mNullPen)
|
||||
//mNullPen = ::CreatePen(PS_NULL, 0, 0);
|
||||
|
||||
//HPEN oldPen = (HPEN)::SelectObject(mDC, mNullPen);
|
||||
//::Polygon(mDC, pp0, int(aNumPoints));
|
||||
//::SelectObject(mDC, oldPen);
|
||||
|
||||
// Release temporary storage if necessary
|
||||
if (pp0 != pts)
|
||||
delete pp0;
|
||||
xl_closepath(mPrintContext);
|
||||
xl_fill(mPrintContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -952,8 +965,10 @@ nsRenderingContextPS :: GetWidth(const char* aString,PRUint32 aLength,nscoord& a
|
|||
|
||||
SetupFontAndColor();
|
||||
aWidth = 12;
|
||||
//::GetTextExtentPoint32W(mDC, aString, aLength, &size);
|
||||
//aWidth = NSToCoordRound(float(size.cx) * mP2T);
|
||||
|
||||
// XXX WINDOWS ONLY
|
||||
aWidth = ::GetTextExtentPoint32(((nsDeviceContextPS*)mContext)->mDC , aString, aLength, &size);
|
||||
aWidth = NSToCoordRound(float(size.cx) * mP2T);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -983,8 +998,10 @@ nsRenderingContextPS :: GetWidth(const PRUnichar *aString,PRUint32 aLength,nscoo
|
|||
|
||||
SetupFontAndColor();
|
||||
aWidth = 12;
|
||||
//::GetTextExtentPoint32W(mDelRenderingContext->mDC, aString, aLength, &size);
|
||||
//aWidth = NSToCoordRound(float(size.cx) * mP2T);
|
||||
|
||||
// XXX WINDOWS ONLY
|
||||
aWidth = ::GetTextExtentPoint32W( ((nsDeviceContextPS*)mContext)->mDC, aString, aLength, &size);
|
||||
aWidth = NSToCoordRound(float(size.cx) * mP2T);
|
||||
|
||||
if (nsnull != aFontID)
|
||||
*aFontID = 0;
|
||||
|
@ -1020,9 +1037,7 @@ PRInt32 y = aY;
|
|||
}
|
||||
|
||||
mTMatrix->TransformCoord(&x, &y);
|
||||
//::ExtTextOut(mDC, x, y, 0, NULL, aString, aLength, aSpacing ? dx0 : NULL);
|
||||
//XXX: Remove ::ExtTextOut later
|
||||
PostscriptTextOut(aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), 0, aSpacing ? dx0 : NULL, FALSE);
|
||||
PostscriptTextOut(aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aLength, aSpacing ? dx0 : NULL, FALSE);
|
||||
|
||||
if ((nsnull != aSpacing) && (dx0 != dxMem)) {
|
||||
delete [] dx0;
|
||||
|
@ -1039,7 +1054,7 @@ PRInt32 y = aY;
|
|||
if (decorations & NS_FONT_DECORATION_OVERLINE){
|
||||
nscoord offset;
|
||||
nscoord size;
|
||||
//mFontMetrics->GetUnderline(offset, size);
|
||||
mFontMetrics->GetUnderline(offset, size);
|
||||
FillRect(aX, aY, aWidth, size);
|
||||
}
|
||||
}
|
||||
|
@ -1065,10 +1080,6 @@ nsIFontMetrics *fMetrics;
|
|||
SetupFontAndColor();
|
||||
|
||||
if (nsnull != aSpacing){
|
||||
// XXX Fix path to use a twips transform in the DC and use the
|
||||
// spacing values directly and let windows deal with the sub-pixel
|
||||
// positioning.
|
||||
|
||||
// Slow, but accurate rendering
|
||||
const PRUnichar* end = aString + aLength;
|
||||
while (aString < end){
|
||||
|
@ -1083,6 +1094,21 @@ nsIFontMetrics *fMetrics;
|
|||
mTMatrix->TransformCoord(&x, &y);
|
||||
PostscriptTextOut((const char *)aString, aLength, NS_PIXELS_TO_POINTS(x), NS_PIXELS_TO_POINTS(y), aFontID, aSpacing, PR_TRUE);
|
||||
}
|
||||
|
||||
fMetrics = mFontMetrics;
|
||||
|
||||
if (nsnull != fMetrics){
|
||||
nsFont *font;
|
||||
fMetrics->GetFont(font);
|
||||
PRUint8 decorations = font->decorations;
|
||||
|
||||
if (decorations & NS_FONT_DECORATION_OVERLINE){
|
||||
nscoord offset;
|
||||
nscoord size;
|
||||
fMetrics->GetUnderline(offset, size);
|
||||
//FillRect(aX, aY, aWidth, size);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1187,11 +1213,20 @@ nsRenderingContextPS :: SetupFontAndColor(void)
|
|||
{
|
||||
nscoord fontHeight = 0;
|
||||
nsFont *font;
|
||||
nsIFontMetrics *fMetrics;
|
||||
nsFontHandle fontHandle; // WINDOWS ONLY
|
||||
|
||||
fMetrics = mFontMetrics;
|
||||
fMetrics->GetHeight(fontHeight);
|
||||
fMetrics->GetFont(font);
|
||||
|
||||
mFontMetrics->GetHeight(fontHeight);
|
||||
mFontMetrics->GetFont(font);
|
||||
|
||||
|
||||
mFontMetrics->GetFontHandle(fontHandle);
|
||||
|
||||
HFONT tfont = (HFONT)fontHandle; // WINDOWS ONLY
|
||||
::SelectObject(((nsDeviceContextPS*)mContext)->mDC, tfont); // WINDOWS ONLY
|
||||
|
||||
//mStates->mFont = mCurrFont = tfont;
|
||||
mStates->mFontMetrics = mFontMetrics;
|
||||
|
||||
PostscriptFont(fontHeight,font->style,font->variant,font->weight,font->decorations);
|
||||
}
|
||||
|
@ -1207,17 +1242,6 @@ nsRenderingContextPS :: PostscriptColor(nscolor aColor)
|
|||
NS_PS_BLUE(aColor));
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextPS.h
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
void
|
||||
nsRenderingContextPS :: PostscriptFillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
xl_moveto(mPrintContext, aX, aY);
|
||||
xl_box(mPrintContext, aWidth, aHeight);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextPS.h
|
||||
* @update 12/21/98 dwc
|
||||
|
@ -1301,18 +1325,14 @@ nsRenderingContextPS :: PostscriptTextOut(const char *aString, PRUint32 aLength,
|
|||
int ptr = 0;
|
||||
unsigned int i;
|
||||
char *buf = 0;
|
||||
nscoord fontHeight = 0;
|
||||
nscoord fontHeight = 0,yCoord;
|
||||
nsFont *font;
|
||||
nsIFontMetrics *fMetrics;
|
||||
|
||||
fMetrics = mFontMetrics;
|
||||
fMetrics->GetHeight(fontHeight);
|
||||
fMetrics->GetFont(font);
|
||||
mFontMetrics->GetHeight(fontHeight);
|
||||
mFontMetrics->GetFont(font);
|
||||
|
||||
//XXX: NGLAYOUT expects font to be positioned based on center.
|
||||
// fontHeight / 2 is a crude approximation of this. TODO: use the correct
|
||||
// postscript command to offset from center of the text.
|
||||
xl_moveto(mPrintContext, aX, aY + (fontHeight / 2));
|
||||
yCoord = aY + (fontHeight / 2);
|
||||
xl_moveto(mPrintContext, aX, yCoord);
|
||||
if (PR_TRUE == aIsUnicode) {
|
||||
//XXX: Investigate how to really do unicode with Postscript
|
||||
// Just remove the extra byte per character and draw that instead
|
||||
|
@ -1320,7 +1340,7 @@ nsIFontMetrics *fMetrics;
|
|||
|
||||
for (i = 0; i < aLength; i++) {
|
||||
buf[i] = aString[ptr];
|
||||
ptr+=2;
|
||||
ptr+=2;
|
||||
}
|
||||
xl_show(mPrintContext, buf, aLength, "");
|
||||
delete buf;
|
||||
|
|
|
@ -160,12 +160,6 @@ public:
|
|||
*/
|
||||
void PostscriptColor(nscolor aColor);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* Fill a postscript rectangle to a file set up by the nsDeviceContextPS
|
||||
* @update 12/21/98 dwc
|
||||
*/
|
||||
void PostscriptFillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* Render a bitmap in postscript to a file set up by the nsDeviceContextPS
|
||||
* @update 12/21/98 dwc
|
||||
|
|
768
gfx/src/ps/ps.c
768
gfx/src/ps/ps.c
|
@ -1,768 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* 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
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "xlate_i.h"
|
||||
#include "isotab.c"
|
||||
#include "locale.h"
|
||||
|
||||
#include <libi18n.h>
|
||||
#include "intl_csi.h"
|
||||
|
||||
#define RED_PART 0.299 /* Constants for converting RGB to greyscale */
|
||||
#define GREEN_PART 0.587
|
||||
#define BLUE_PART 0.114
|
||||
|
||||
#define XL_SET_NUMERIC_LOCALE() char* cur_locale = setlocale(LC_NUMERIC, "C")
|
||||
#define XL_RESTORE_NUMERIC_LOCALE() setlocale(LC_NUMERIC, cur_locale)
|
||||
|
||||
/*
|
||||
* Paper Names
|
||||
*/
|
||||
char* paper_string[]={ "Letter", "Legal", "Executive", "A4" };
|
||||
|
||||
/*
|
||||
** These two functions swap values around in order to deal with page
|
||||
** rotation.
|
||||
*/
|
||||
|
||||
void xl_initialize_translation(PSContext *cx, PrintSetup* pi)
|
||||
{
|
||||
PrintSetup *dup = XP_NEW(PrintSetup);
|
||||
*dup = *pi;
|
||||
cx->prSetup = dup;
|
||||
dup->width = POINT_TO_PAGE(dup->width);
|
||||
dup->height = POINT_TO_PAGE(dup->height);
|
||||
dup->top = POINT_TO_PAGE(dup->top);
|
||||
dup->left = POINT_TO_PAGE(dup->left);
|
||||
dup->bottom = POINT_TO_PAGE(dup->bottom);
|
||||
dup->right = POINT_TO_PAGE(dup->right);
|
||||
if (pi->landscape)
|
||||
{
|
||||
dup->height = POINT_TO_PAGE(pi->width);
|
||||
dup->width = POINT_TO_PAGE(pi->height);
|
||||
/* XXX Should I swap the margins too ??? */
|
||||
}
|
||||
}
|
||||
|
||||
void xl_finalize_translation(PSContext *cx)
|
||||
{
|
||||
XP_DELETE(cx->prSetup);
|
||||
cx->prSetup = NULL;
|
||||
}
|
||||
|
||||
void xl_begin_document(PSContext *cx)
|
||||
{
|
||||
int i;
|
||||
XP_File f;
|
||||
char* charset_name = NULL;
|
||||
|
||||
f = cx->prSetup->out;
|
||||
XP_FilePrintf(f, "%%!PS-Adobe-3.0\n");
|
||||
XP_FilePrintf(f, "%%%%BoundingBox: %d %d %d %d\n",
|
||||
PAGE_TO_POINT_I(cx->prSetup->left),
|
||||
PAGE_TO_POINT_I(cx->prSetup->bottom),
|
||||
PAGE_TO_POINT_I(cx->prSetup->width-cx->prSetup->right),
|
||||
PAGE_TO_POINT_I(cx->prSetup->height-cx->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[cx->prSetup->paper_size]);
|
||||
XP_FilePrintf(f, "%%%%Orientation: %s\n",
|
||||
(cx->prSetup->width < cx->prSetup->height) ? "Portrait" : "Landscape");
|
||||
XP_FilePrintf(f, "%%%%Pages: %d\n", (int) cx->prInfo->n_pages);
|
||||
if (cx->prSetup->reverse)
|
||||
XP_FilePrintf(f, "%%%%PageOrder: Descend\n");
|
||||
else
|
||||
XP_FilePrintf(f, "%%%%PageOrder: Ascend\n");
|
||||
XP_FilePrintf(f, "%%%%Title: %s\n", cx->prInfo->doc_title);
|
||||
#ifdef NOTYET
|
||||
XP_FilePrintf(f, "%%%%For: %n", user_name_stuff);
|
||||
#endif
|
||||
XP_FilePrintf(f, "%%%%EndComments\n");
|
||||
|
||||
/* general comments: Mozilla-specific */
|
||||
XP_FilePrintf(f, "\n%% MozillaURL: %s\n", cx->prSetup->url->address);
|
||||
/* get charset name of non-latin1 fonts */
|
||||
/* for external filters, supply information */
|
||||
if (cx->prSetup->otherFontName[0] || cx->prSetup->otherFontInfo[0]){
|
||||
INTL_CharSetIDToName(cx->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");
|
||||
XP_FilePrintf(f, "/c { matrix currentmatrix currentpoint translate\n");
|
||||
XP_FilePrintf(f, " 3 1 roll scale newpath 0 0 1 0 360 arc setmatrix } bind 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 (cx->prSetup->otherFontName[i]) {
|
||||
XP_FilePrintf(f,
|
||||
"/of%d { /%s findfont exch scalefont setfont } bind def\n",
|
||||
i, cx->prSetup->otherFontName[i]);
|
||||
/* XP_FilePrintf(f, "/of /of1;\n", cx->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");
|
||||
}
|
||||
|
||||
void xl_begin_page(PSContext *cx, int pn)
|
||||
{
|
||||
XP_File f;
|
||||
|
||||
f = cx->prSetup->out;
|
||||
pn++;
|
||||
XP_FilePrintf(f, "%%%%Page: %d %d\n", pn, pn);
|
||||
XP_FilePrintf(f, "%%%%BeginPageSetup\n/pagelevel save def\n");
|
||||
if (cx->prSetup->landscape)
|
||||
XP_FilePrintf(f, "%d 0 translate 90 rotate\n",
|
||||
PAGE_TO_POINT_I(cx->prSetup->height));
|
||||
XP_FilePrintf(f, "%d 0 translate\n", PAGE_TO_POINT_I(cx->prSetup->left));
|
||||
XP_FilePrintf(f, "%%%%EndPageSetup\n");
|
||||
#if 0
|
||||
xl_annotate_page(cx, cx->prSetup->header, 0, -1, pn);
|
||||
#endif
|
||||
XP_FilePrintf(f, "newpath 0 %d moveto ", PAGE_TO_POINT_I(cx->prSetup->bottom));
|
||||
XP_FilePrintf(f, "%d 0 rlineto 0 %d rlineto -%d 0 rlineto ",
|
||||
PAGE_TO_POINT_I(cx->prInfo->page_width),
|
||||
PAGE_TO_POINT_I(cx->prInfo->page_height),
|
||||
PAGE_TO_POINT_I(cx->prInfo->page_width));
|
||||
XP_FilePrintf(f, " closepath clip newpath\n");
|
||||
}
|
||||
|
||||
void xl_end_page(PSContext *cx, int pn)
|
||||
{
|
||||
#if 0
|
||||
xl_annotate_page(cx, cx->prSetup->footer,
|
||||
cx->prSetup->height-cx->prSetup->bottom-cx->prSetup->top,
|
||||
1, pn);
|
||||
XP_FilePrintf(cx->prSetup->out, "pagelevel restore\nshowpage\n");
|
||||
#endif
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "pagelevel restore\n");
|
||||
xl_annotate_page(cx, cx->prSetup->header, cx->prSetup->top/2, -1, pn);
|
||||
xl_annotate_page(cx, cx->prSetup->footer,
|
||||
cx->prSetup->height - cx->prSetup->bottom/2,
|
||||
1, pn);
|
||||
XP_FilePrintf(cx->prSetup->out, "showpage\n");
|
||||
}
|
||||
|
||||
void xl_end_document(PSContext *cx)
|
||||
{
|
||||
XP_FilePrintf(cx->prSetup->out, "%%%%EOF\n");
|
||||
}
|
||||
|
||||
void xl_moveto(PSContext* cx, int x, int y)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
y -= cx->prInfo->page_topy;
|
||||
/*
|
||||
** Agh! Y inversion again !!
|
||||
*/
|
||||
y = (cx->prInfo->page_height - y - 1) + cx->prSetup->bottom;
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "%g %g moveto\n",
|
||||
PAGE_TO_POINT_F(x), PAGE_TO_POINT_F(y));
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_moveto_loc(PSContext* cx, int x, int y)
|
||||
{
|
||||
/* This routine doesn't care about the clip region in the page */
|
||||
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
|
||||
/*
|
||||
** Agh! Y inversion again !!
|
||||
*/
|
||||
y = (cx->prSetup->height - y - 1);
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "%g %g moveto\n",
|
||||
PAGE_TO_POINT_F(x), PAGE_TO_POINT_F(y));
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_lineto(PSContext* cx, int x1, int y1)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
|
||||
y1 -= cx->prInfo->page_topy;
|
||||
y1 = (cx->prInfo->page_height - y1 - 1) + cx->prSetup->bottom;
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "%g %g lineto\n",
|
||||
PAGE_TO_POINT_F(x1), PAGE_TO_POINT_F(y1));
|
||||
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_translate(PSContext* cx, int x, int y)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
y -= cx->prInfo->page_topy;
|
||||
/*
|
||||
** Agh! Y inversion again !!
|
||||
*/
|
||||
y = (cx->prInfo->page_height - y - 1) + cx->prSetup->bottom;
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "%g %g translate\n", PAGE_TO_POINT_F(x), PAGE_TO_POINT_F(y));
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_show(PSContext *cx, char* txt, int len, char *align)
|
||||
{
|
||||
XP_File f;
|
||||
|
||||
f = cx->prSetup->out;
|
||||
XP_FilePrintf(f, "(");
|
||||
while (len-- > 0) {
|
||||
switch (*txt) {
|
||||
case '(':
|
||||
case ')':
|
||||
case '\\':
|
||||
XP_FilePrintf(f, "\\%c", *txt);
|
||||
break;
|
||||
default:
|
||||
if (*txt < ' ' || (*txt & 0x80))
|
||||
XP_FilePrintf(f, "\\%o", *txt & 0xff);
|
||||
else
|
||||
XP_FilePrintf(f, "%c", *txt);
|
||||
break;
|
||||
}
|
||||
txt++;
|
||||
}
|
||||
XP_FilePrintf(f, ") %sshow\n", align);
|
||||
}
|
||||
|
||||
void xl_circle(PSContext* cx, int w, int h)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "%g %g c ", PAGE_TO_POINT_F(w)/2.0, PAGE_TO_POINT_F(h)/2.0);
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_box(PSContext* cx, int w, int h)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "%g 0 rlineto 0 %g rlineto %g 0 rlineto closepath ",
|
||||
PAGE_TO_POINT_F(w), -PAGE_TO_POINT_F(h), -PAGE_TO_POINT_F(w));
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
xl_draw_border(PSContext *cx, int x, int y, int w, int h, int thick)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave %g setlinewidth\n ",
|
||||
PAGE_TO_POINT_F(thick));
|
||||
xl_moveto(cx, x, y);
|
||||
xl_box(cx, w, h);
|
||||
xl_stroke(cx);
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
xl_draw_3d_border(PSContext *cx, int x, int y, int w, int h, int thick, int tl, int br)
|
||||
{
|
||||
int llx, lly;
|
||||
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave\n ");
|
||||
|
||||
/* lower left */
|
||||
llx = x;
|
||||
lly = y + h;
|
||||
|
||||
/* top left */
|
||||
xl_moveto(cx, llx, lly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto 0 %g rlineto %g 0 rlineto %g %g rlineto %g 0 rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(h-2*thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(w));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", tl);
|
||||
|
||||
/* bottom right */
|
||||
xl_moveto(cx, llx, lly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g 0 rlineto 0 %g rlineto %g %g rlineto 0 %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
PAGE_TO_POINT_F(h-2*thick),
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(h));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", br);
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
xl_draw_3d_radiobox(PSContext *cx, int x, int y, int w, int h, int thick,
|
||||
int top, int bottom, int center)
|
||||
{
|
||||
int lx, ly;
|
||||
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave\n ");
|
||||
|
||||
/* left */
|
||||
lx = x;
|
||||
ly = y + h/2;
|
||||
|
||||
/* bottom */
|
||||
xl_moveto(cx, lx, ly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g 0 rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(w/2), -PAGE_TO_POINT_F(h/2),
|
||||
PAGE_TO_POINT_F(w/2), PAGE_TO_POINT_F(h/2),
|
||||
-PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick),-PAGE_TO_POINT_F(h/2-thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick), PAGE_TO_POINT_F(h/2-thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", bottom);
|
||||
|
||||
/* top */
|
||||
xl_moveto(cx, lx, ly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g 0 rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(w/2), PAGE_TO_POINT_F(h/2),
|
||||
PAGE_TO_POINT_F(w/2), -PAGE_TO_POINT_F(h/2),
|
||||
-PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick), PAGE_TO_POINT_F(h/2-thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick), -PAGE_TO_POINT_F(h/2-thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", top);
|
||||
|
||||
/* center */
|
||||
if (center != 10) {
|
||||
xl_moveto(cx, lx+thick, ly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(w/2-thick), -PAGE_TO_POINT_F(h/2-thick),
|
||||
PAGE_TO_POINT_F(w/2-thick), PAGE_TO_POINT_F(h/2-thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick), PAGE_TO_POINT_F(h/2-thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", center);
|
||||
}
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
xl_draw_3d_checkbox(PSContext *cx, int x, int y, int w, int h, int thick,
|
||||
int tl, int br, int center)
|
||||
{
|
||||
int llx, lly;
|
||||
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave\n ");
|
||||
|
||||
/* lower left */
|
||||
llx = x;
|
||||
lly = y + h;
|
||||
|
||||
/* top left */
|
||||
xl_moveto(cx, llx, lly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto 0 %g rlineto %g 0 rlineto %g %g rlineto %g 0 rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(h-2*thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(w));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", tl);
|
||||
|
||||
/* bottom right */
|
||||
xl_moveto(cx, llx, lly);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g 0 rlineto 0 %g rlineto %g %g rlineto 0 %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
PAGE_TO_POINT_F(h-2*thick),
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(h));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", br);
|
||||
|
||||
/* center */
|
||||
if (center != 10) {
|
||||
xl_moveto(cx, llx+thick, lly-thick);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"0 %g rlineto %g 0 rlineto 0 %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(h-2*thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
-PAGE_TO_POINT_F(h-2*thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", center);
|
||||
}
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
extern void xl_draw_3d_arrow(PSContext *cx, int x , int y, int thick, int w,
|
||||
int h, XP_Bool up, int left, int right, int base)
|
||||
{
|
||||
int tx, ty;
|
||||
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave\n ");
|
||||
|
||||
if (up) {
|
||||
tx = x + w/2;
|
||||
ty = y;
|
||||
|
||||
/* left */
|
||||
|
||||
xl_moveto(cx, tx, ty);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
-PAGE_TO_POINT_F(w/2), -PAGE_TO_POINT_F(h),
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(w/2-thick), PAGE_TO_POINT_F(h-2*thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", left);
|
||||
|
||||
/* right */
|
||||
|
||||
xl_moveto(cx, tx, ty);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(w/2), -PAGE_TO_POINT_F(h),
|
||||
-PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick), PAGE_TO_POINT_F(h-2*thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", right);
|
||||
|
||||
/* base */
|
||||
|
||||
xl_moveto(cx, tx-w/2, ty+h);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g 0 rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
PAGE_TO_POINT_F(thick), -PAGE_TO_POINT_F(thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", base);
|
||||
}
|
||||
else {
|
||||
tx = x + w/2;
|
||||
ty = y + h;
|
||||
|
||||
/* left */
|
||||
|
||||
xl_moveto(cx, tx, ty);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
-PAGE_TO_POINT_F(w/2), PAGE_TO_POINT_F(h),
|
||||
PAGE_TO_POINT_F(thick), -PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(w/2-thick), -PAGE_TO_POINT_F(h-2*thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", left);
|
||||
|
||||
/* right */
|
||||
|
||||
xl_moveto(cx, tx, ty);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g %g rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(w/2), PAGE_TO_POINT_F(h),
|
||||
-PAGE_TO_POINT_F(thick), -PAGE_TO_POINT_F(thick),
|
||||
-PAGE_TO_POINT_F(w/2-thick), -PAGE_TO_POINT_F(h-2*thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", right);
|
||||
|
||||
/* base */
|
||||
|
||||
xl_moveto(cx, x, y);
|
||||
XP_FilePrintf(cx->prSetup->out,
|
||||
"%g %g rlineto %g 0 rlineto %g %g rlineto closepath\n",
|
||||
PAGE_TO_POINT_F(thick), -PAGE_TO_POINT_F(thick),
|
||||
PAGE_TO_POINT_F(w-2*thick),
|
||||
PAGE_TO_POINT_F(thick), PAGE_TO_POINT_F(thick));
|
||||
XP_FilePrintf(cx->prSetup->out, ".%d setgray fill\n", base);
|
||||
}
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_line(PSContext* cx, int x1, int y1, int x2, int y2, int thick)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave %g setlinewidth\n ",
|
||||
PAGE_TO_POINT_F(thick));
|
||||
|
||||
y1 -= cx->prInfo->page_topy;
|
||||
y1 = (cx->prInfo->page_height - y1 - 1) + cx->prSetup->bottom;
|
||||
y2 -= cx->prInfo->page_topy;
|
||||
y2 = (cx->prInfo->page_height - y2 - 1) + cx->prSetup->bottom;
|
||||
|
||||
XP_FilePrintf(cx->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));
|
||||
xl_stroke(cx);
|
||||
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
void xl_stroke(PSContext *cx)
|
||||
{
|
||||
XP_FilePrintf(cx->prSetup->out, " stroke \n");
|
||||
}
|
||||
|
||||
void xl_fill(PSContext *cx)
|
||||
{
|
||||
XP_FilePrintf(cx->prSetup->out, " fill \n");
|
||||
}
|
||||
|
||||
/*
|
||||
** This function works, but is starting to show it's age, as the list
|
||||
** of known problems grows:
|
||||
**
|
||||
** + The images are completely uncompressed, which tends to generate
|
||||
** huge output files. The university prototype browser uses RLE
|
||||
** compression on the images, which causes them to print slowly,
|
||||
** but is a huge win on some class of images.
|
||||
** + 12 bit files can be constructed which print on any printer, but
|
||||
** not 24 bit files.
|
||||
** + The 12 bit code is careful not to create a string-per-row, unless
|
||||
** it is going through the compatibility conversion routine.
|
||||
** + The 1-bit code is completely unused and untested.
|
||||
** + It should squish the image if squishing is currently in effect.
|
||||
*/
|
||||
|
||||
void xl_colorimage(PSContext *cx, int x, int y, int w, int h, IL_Pixmap *image,
|
||||
IL_Pixmap *mask)
|
||||
{
|
||||
uint8 pixmap_depth;
|
||||
int row, col, pps;
|
||||
int n;
|
||||
int16 *p12;
|
||||
int32 *p24;
|
||||
unsigned char *p8;
|
||||
int cbits;
|
||||
int rowdata, rowextra, row_ends_within_byte;
|
||||
XP_File f;
|
||||
NI_PixmapHeader *img_header = &image->header;
|
||||
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
f = cx->prSetup->out;
|
||||
pps = 1;
|
||||
row_ends_within_byte = 0;
|
||||
pixmap_depth = img_header->color_space->pixmap_depth;
|
||||
|
||||
/* Imagelib row data is aligned to 32-bit boundaries */
|
||||
if (pixmap_depth == 1) {
|
||||
rowdata = (img_header->width + 7)/8;
|
||||
rowextra = img_header->widthBytes - rowdata;
|
||||
cbits = 1;
|
||||
pps = 8;
|
||||
}
|
||||
else if (pixmap_depth == 16) {
|
||||
if (cx->prSetup->color) {
|
||||
rowdata = (img_header->width*12)/8;
|
||||
row_ends_within_byte = (img_header->width*12)%8 ? 1 : 0;
|
||||
cbits = 4;
|
||||
} else {
|
||||
cbits = 8;
|
||||
rowdata = img_header->width;
|
||||
}
|
||||
rowextra = img_header->widthBytes - img_header->width * 2;
|
||||
}
|
||||
else { /* depth assumed to be 32 */
|
||||
rowdata = 3 * img_header->width;
|
||||
rowextra = 0;
|
||||
cbits = 8;
|
||||
}
|
||||
|
||||
assert(pixmap_depth == 16 || pixmap_depth == 32 || pixmap_depth == 1);
|
||||
XP_FilePrintf(f, "gsave\n");
|
||||
XP_FilePrintf(f, "/rowdata %d string def\n",
|
||||
rowdata + row_ends_within_byte);
|
||||
xl_translate(cx, x, y + h);
|
||||
XP_FilePrintf(f, "%g %g scale\n", PAGE_TO_POINT_F(w), PAGE_TO_POINT_F(h));
|
||||
XP_FilePrintf(f, "%d %d ", img_header->width, img_header->height);
|
||||
XP_FilePrintf(f, "%d ", cbits);
|
||||
XP_FilePrintf(f, "[%d 0 0 %d 0 %d]\n", img_header->width,
|
||||
-img_header->height, img_header->height);
|
||||
if (cx->prSetup->color && pixmap_depth == 16)
|
||||
XP_FilePrintf(f, " smartimage12rgb\n");
|
||||
else if (pixmap_depth == 32) {
|
||||
XP_FilePrintf(f, " { currentfile rowdata readhexstring pop }\n");
|
||||
XP_FilePrintf(f, " false 3 colorimage\n");
|
||||
} else {
|
||||
XP_FilePrintf(f, " { currentfile rowdata readhexstring pop }\n");
|
||||
XP_FilePrintf(f, " image\n");
|
||||
}
|
||||
|
||||
n = 0;
|
||||
p8 = (unsigned char*) image->bits;
|
||||
p12 = (int16*) image->bits;
|
||||
p24 = (int32*) image->bits;
|
||||
for (row = 0; row < img_header->height; row++) {
|
||||
for (col = 0; col < img_header->width; col += pps) {
|
||||
switch ( pixmap_depth ) {
|
||||
case 16:
|
||||
if (cx->prSetup->color) {
|
||||
if (n > 76) {
|
||||
XP_FilePrintf(f, "\n");
|
||||
n = 0;
|
||||
}
|
||||
XP_FilePrintf(f, "%03x", 0xfff & *p12++);
|
||||
n += 3;
|
||||
} else {
|
||||
unsigned char value;
|
||||
value = (*p12 & 0x00f)/15.0 * GREEN_PART * 255.0
|
||||
+ ((((*p12 & 0x0f0)>>4)/15.0) * BLUE_PART * 255.0)
|
||||
+ ((((*p12 & 0xf00)>>8)/15.0) * RED_PART * 255.0);
|
||||
p12++;
|
||||
if (n > 76) {
|
||||
XP_FilePrintf(f, "\n");
|
||||
n = 0;
|
||||
}
|
||||
XP_FilePrintf(f, "%02X", value);
|
||||
n += 2;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
if (n > 71) {
|
||||
XP_FilePrintf(f, "\n");
|
||||
n = 0;
|
||||
}
|
||||
XP_FilePrintf(f, "%06x", (int) (0xffffff & *p24++));
|
||||
n += 6;
|
||||
break;
|
||||
case 1:
|
||||
if (n > 78) {
|
||||
XP_FilePrintf(f, "\n");
|
||||
n = 0;
|
||||
}
|
||||
XP_FilePrintf(f, "%02x", 0xff ^ *p8++);
|
||||
n += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (row_ends_within_byte) {
|
||||
XP_FilePrintf(f, "0");
|
||||
n += 1;
|
||||
}
|
||||
p8 += rowextra;
|
||||
p12 = (int16*)((char*)p12 + rowextra);
|
||||
}
|
||||
XP_FilePrintf(f, "\ngrestore\n");
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
xl_begin_squished_text(PSContext *cx, float scale)
|
||||
{
|
||||
XL_SET_NUMERIC_LOCALE();
|
||||
XP_FilePrintf(cx->prSetup->out, "gsave %g 1 scale\n", scale);
|
||||
XL_RESTORE_NUMERIC_LOCALE();
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
xl_end_squished_text(PSContext *cx)
|
||||
{
|
||||
XP_FilePrintf(cx->prSetup->out, "grestore\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,200 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* 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
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** External points of interest for the translation library
|
||||
*/
|
||||
|
||||
#ifndef XLATE_H
|
||||
#define XLATE_H
|
||||
|
||||
#define N_FONTS 8
|
||||
|
||||
typedef void (*XL_CompletionRoutine)(PrintSetup*);
|
||||
typedef void* XL_TextTranslation;
|
||||
typedef void* XL_PostscriptTranslation;
|
||||
|
||||
typedef struct {
|
||||
short llx, lly, urx, ury;
|
||||
} PS_BBox;
|
||||
|
||||
typedef struct {
|
||||
short wx, wy;
|
||||
PS_BBox charBBox;
|
||||
} PS_CharInfo;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
PS_BBox fontBBox;
|
||||
short upos, uthick;
|
||||
PS_CharInfo chars[256];
|
||||
} PS_FontInfo;
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
extern void XL_InitializePrintSetup(PrintSetup *p);
|
||||
extern void XL_InitializeTextSetup(PrintSetup *p);
|
||||
extern void XL_TranslatePostscript(MWContext*, URL_Struct *u,
|
||||
SHIST_SavedData *sd, PrintSetup*p);
|
||||
extern XL_TextTranslation
|
||||
XL_TranslateText(MWContext *, URL_Struct *u, PrintSetup*p);
|
||||
extern void XL_GetTextImage(LO_ImageStruct *image);
|
||||
extern void
|
||||
XL_DisplayTextImage(MWContext *cx, int iLocation, LO_ImageStruct *img);
|
||||
extern XP_Bool XP_CheckElementSpan(MWContext*, int top, int height);
|
||||
extern void XP_InitializePrintInfo(MWContext *);
|
||||
extern void XP_CleanupPrintInfo(MWContext *);
|
||||
extern void XP_DrawForPrint(MWContext *, int );
|
||||
extern void XP_LayoutForPrint(MWContext *cx, int32 doc_height);
|
||||
extern void XP_ParseAFMFile(FILE *fp, PS_FontInfo** fi);
|
||||
XP_END_PROTOS
|
||||
|
||||
typedef struct LineRecord_struct LineRecord;
|
||||
|
||||
/*
|
||||
** PAGE coordinates are 720/inch, layout happens in this space
|
||||
** POINT coordinates are 72/inch, the printer wants these
|
||||
*/
|
||||
#define INCH_TO_PAGE(f) ((int) (.5 + (f)*720))
|
||||
#define PAGE_TO_POINT_I(f) ((int) ((f) / 10.0))
|
||||
#define PAGE_TO_POINT_F(f) ((f) / 10.0)
|
||||
#define POINT_TO_PAGE(p) ((p)*10)
|
||||
|
||||
/*
|
||||
** Used to pass info into text and/or postscript translation
|
||||
*/
|
||||
struct PrintSetup_ {
|
||||
int top; /* Margins (PostScript Only) */
|
||||
int bottom;
|
||||
int left;
|
||||
int right;
|
||||
|
||||
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) */
|
||||
|
||||
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 */
|
||||
|
||||
/* "other" font is for encodings other than iso-8859-1 */
|
||||
char *otherFontName[N_FONTS];
|
||||
/* name of "other" PostScript font */
|
||||
PS_FontInfo *otherFontInfo[N_FONTS];
|
||||
/* font info parsed from "other" afm file */
|
||||
int16 otherFontCharSetID; /* charset ID of "other" font */
|
||||
|
||||
MWContext *cx; /* original context, if available */
|
||||
};
|
||||
|
||||
#define XL_LOADING_PHASE 1
|
||||
#define XL_LAYOUT_PHASE 2
|
||||
#define XL_DRAW_PHASE 3
|
||||
|
||||
typedef struct page_breaks {
|
||||
int32 y_top;
|
||||
int32 y_break;
|
||||
} PageBreaks;
|
||||
|
||||
/*
|
||||
** 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 */
|
||||
int phase;
|
||||
/*
|
||||
** CONTINUE SPECIAL
|
||||
** The table print code maintains these
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
/*
|
||||
** AAAOOOGAH
|
||||
**
|
||||
** These are used to cache values from the originating context's
|
||||
** function table
|
||||
*/
|
||||
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 */
|
||||
|
||||
#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 */
|
||||
#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 */
|
||||
};
|
||||
|
||||
#endif /* XLATE_H */
|
||||
|
|
@ -33,27 +33,30 @@ extern void xl_begin_document(PSContext*);
|
|||
extern void xl_begin_page(PSContext*,int);
|
||||
extern void xl_end_page(PSContext*,int);
|
||||
extern void xl_end_document(PSContext*);
|
||||
extern void xl_show(PSContext *cx, char* txt, int len, char*);
|
||||
extern void xl_moveto(PSContext* cx, int x, int y);
|
||||
extern void xl_moveto_loc(PSContext* cx, int x, int y);
|
||||
extern void xl_lineto(PSContext* cx, int x1, int y1);
|
||||
extern void xl_circle(PSContext* cx, int w, int h);
|
||||
extern void xl_box(PSContext* cx, int w, int h);
|
||||
extern void xl_line(PSContext* cx, int x1, int y1, int x2, int y2, int thick);
|
||||
extern void xl_stroke(PSContext*);
|
||||
extern void xl_fill(PSContext*);
|
||||
extern void xl_colorimage(PSContext *cx, int x, int y, int w, int h,IL_Pixmap *image, IL_Pixmap *mask);
|
||||
extern void xl_show(PSContext *aCX, char* txt, int len, char*);
|
||||
extern void xl_moveto(PSContext* aCX, int x, int y);
|
||||
extern void xl_moveto_loc(PSContext* aCX, int x, int y);
|
||||
extern void xl_lineto(PSContext* aCX, int x1, int y1);
|
||||
extern void xl_closepath(PSContext* aCX);
|
||||
extern void xl_circle(PSContext* aCX, int w, int h);
|
||||
extern void xl_box(PSContext* aCX, int w, int h);
|
||||
extern void xl_line(PSContext* aCX, int x1, int y1, int x2, int y2, int thick);
|
||||
extern void xl_stroke(PSContext* aCX);
|
||||
extern void xl_fill(PSContext* aCX);
|
||||
extern void xl_graphics_save(PSContext *aCX);
|
||||
extern void xl_graphics_restore(PSContext *aCX);
|
||||
extern void xl_colorimage(PSContext *aCX, int x, int y, int w, int h,IL_Pixmap *image, IL_Pixmap *mask);
|
||||
extern void xl_begin_squished_text(PSContext*, float);
|
||||
extern void xl_end_squished_text(PSContext*);
|
||||
extern void xl_initialize_translation(PSContext*, PrintSetup*);
|
||||
extern void xl_finalize_translation(PSContext*);
|
||||
extern void xl_annotate_page(PSContext*, char*, int, int, int);
|
||||
extern void xl_draw_border(PSContext *, int , int , int , int , int );
|
||||
extern void xl_draw_3d_border(PSContext *, int , int , int , int , int, int tl, int br );
|
||||
extern void xl_draw_3d_radiobox(PSContext *, int , int , int , int , int, int t, int b, int c);
|
||||
extern void xl_draw_3d_checkbox(PSContext *, int , int , int , int , int, int tl, int br, int c);
|
||||
extern void xl_draw_3d_arrow(PSContext *, int, int, int, int, int, XP_Bool, int, int, int);
|
||||
extern XP_Bool xl_item_span(PSContext* cx, int top, int bottom);
|
||||
extern void xl_annotate_page(PSContext* aCX, char*, int, int, int);
|
||||
extern void xl_draw_border(PSContext* aCX, int , int , int , int , int );
|
||||
extern void xl_draw_3d_border(PSContext* aCX, int , int , int , int , int, int tl, int br );
|
||||
extern void xl_draw_3d_radiobox(PSContext* aCX, int , int , int , int , int, int t, int b, int c);
|
||||
extern void xl_draw_3d_checkbox(PSContext* aCX, int , int , int , int , int, int tl, int br, int c);
|
||||
extern void xl_draw_3d_arrow(PSContext* aCX, int, int, int, int, int, XP_Bool, int, int, int);
|
||||
extern XP_Bool xl_item_span(PSContext* aCX, int top, int bottom);
|
||||
|
||||
extern XP_Bool psfe_init_image_callbacks(PSContext *cx);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче