Fixed the font information, added some postscript drawing routines.

This commit is contained in:
dcone%netscape.com 1999-01-29 17:00:46 +00:00
Родитель dec7693094
Коммит 3f77479aa3
7 изменённых файлов: 445 добавлений и 354 удалений

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

@ -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

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

@ -40,11 +40,11 @@ char* paper_string[]={ "Letter", "Legal", "Executive", "A4" };
** rotation.
*/
void xl_initialize_translation(PSContext *cx, PrintSetup* pi)
void xl_initialize_translation(PSContext *aCX, PrintSetup* pi)
{
PrintSetup *dup = XP_NEW(PrintSetup);
*dup = *pi;
cx->prSetup = dup;
aCX->prSetup = dup;
dup->width = POINT_TO_PAGE(dup->width);
dup->height = POINT_TO_PAGE(dup->height);
dup->top = POINT_TO_PAGE(dup->top);
@ -59,48 +59,48 @@ void xl_initialize_translation(PSContext *cx, PrintSetup* pi)
}
}
void xl_finalize_translation(PSContext *cx)
void xl_finalize_translation(PSContext *aCX)
{
XP_DELETE(cx->prSetup);
cx->prSetup = NULL;
XP_DELETE(aCX->prSetup);
aCX->prSetup = NULL;
}
void xl_begin_document(PSContext *cx)
void xl_begin_document(PSContext *aCX)
{
int i;
XP_File f;
char* charset_name = NULL;
f = cx->prSetup->out;
f = aCX->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));
PAGE_TO_POINT_I(aCX->prSetup->left),
PAGE_TO_POINT_I(aCX->prSetup->bottom),
PAGE_TO_POINT_I(aCX->prSetup->width-aCX->prSetup->right),
PAGE_TO_POINT_I(aCX->prSetup->height-aCX->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]);
paper_string[aCX->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)
(aCX->prSetup->width < aCX->prSetup->height) ? "Portrait" : "Landscape");
XP_FilePrintf(f, "%%%%Pages: %d\n", (int) aCX->prInfo->n_pages);
if (aCX->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);
XP_FilePrintf(f, "%%%%Title: %s\n", aCX->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);
XP_FilePrintf(f, "\n%% MozillaURL: %s\n", aCX->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);
if (aCX->prSetup->otherFontName[0] || aCX->prSetup->otherFontInfo[0]){
INTL_CharSetIDToName(aCX->prSetup->otherFontCharSetID, charset_name);
XP_FilePrintf(f, "%% MozillaCharsetName: %s\n\n", charset_name);
}else
/* default: iso-8859-1 */
@ -133,11 +133,11 @@ void xl_begin_document(PSContext *cx)
"/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]) {
if (aCX->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); */
i, aCX->prSetup->otherFontName[i]);
/* XP_FilePrintf(f, "/of /of1;\n", aCX->prSetup->otherFontName); */
}
XP_FilePrintf(f, "/rhc {\n");
XP_FilePrintf(f, " {\n");
@ -208,67 +208,67 @@ void xl_begin_document(PSContext *cx)
XP_FilePrintf(f, "%%%%EndProlog\n");
}
void xl_begin_page(PSContext *cx, int pn)
void xl_begin_page(PSContext *aCX, int pn)
{
XP_File f;
f = cx->prSetup->out;
pn++;
f = aCX->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)
if (aCX->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));
PAGE_TO_POINT_I(aCX->prSetup->height));
XP_FilePrintf(f, "%d 0 translate\n", PAGE_TO_POINT_I(aCX->prSetup->left));
XP_FilePrintf(f, "%%%%EndPageSetup\n");
#if 0
xl_annotate_page(cx, cx->prSetup->header, 0, -1, pn);
xl_annotate_page(aCX, aCX->prSetup->header, 0, -1, pn);
#endif
XP_FilePrintf(f, "newpath 0 %d moveto ", PAGE_TO_POINT_I(cx->prSetup->bottom));
XP_FilePrintf(f, "newpath 0 %d moveto ", PAGE_TO_POINT_I(aCX->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));
PAGE_TO_POINT_I(aCX->prInfo->page_width),
PAGE_TO_POINT_I(aCX->prInfo->page_height),
PAGE_TO_POINT_I(aCX->prInfo->page_width));
XP_FilePrintf(f, " closepath clip newpath\n");
}
void xl_end_page(PSContext *cx, int pn)
void xl_end_page(PSContext *aCX, int pn)
{
#if 0
xl_annotate_page(cx, cx->prSetup->footer,
cx->prSetup->height-cx->prSetup->bottom-cx->prSetup->top,
xl_annotate_page(aCX, aCX->prSetup->footer,
aCX->prSetup->height-aCX->prSetup->bottom-aCX->prSetup->top,
1, pn);
XP_FilePrintf(cx->prSetup->out, "pagelevel restore\nshowpage\n");
XP_FilePrintf(aCX->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,
XP_FilePrintf(aCX->prSetup->out, "pagelevel restore\n");
xl_annotate_page(aCX, aCX->prSetup->header, aCX->prSetup->top/2, -1, pn);
xl_annotate_page(aCX, aCX->prSetup->footer,
aCX->prSetup->height - aCX->prSetup->bottom/2,
1, pn);
XP_FilePrintf(cx->prSetup->out, "showpage\n");
XP_FilePrintf(aCX->prSetup->out, "showpage\n");
}
void xl_end_document(PSContext *cx)
void xl_end_document(PSContext *aCX)
{
XP_FilePrintf(cx->prSetup->out, "%%%%EOF\n");
XP_FilePrintf(aCX->prSetup->out, "%%%%EOF\n");
}
void xl_moveto(PSContext* cx, int x, int y)
void xl_moveto(PSContext* aCX, int x, int y)
{
XL_SET_NUMERIC_LOCALE();
y -= cx->prInfo->page_topy;
y -= aCX->prInfo->page_topy;
/*
** Agh! Y inversion again !!
*/
y = (cx->prInfo->page_height - y - 1) + cx->prSetup->bottom;
y = (aCX->prInfo->page_height - y - 1) + aCX->prSetup->bottom;
XP_FilePrintf(cx->prSetup->out, "%g %g moveto\n",
XP_FilePrintf(aCX->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)
void xl_moveto_loc(PSContext* aCX, int x, int y)
{
/* This routine doesn't care about the clip region in the page */
@ -277,44 +277,50 @@ void xl_moveto_loc(PSContext* cx, int x, int y)
/*
** Agh! Y inversion again !!
*/
y = (cx->prSetup->height - y - 1);
y = (aCX->prSetup->height - y - 1);
XP_FilePrintf(cx->prSetup->out, "%g %g moveto\n",
XP_FilePrintf(aCX->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)
void xl_lineto(PSContext* aCX, int x1, int y1)
{
XL_SET_NUMERIC_LOCALE();
y1 -= cx->prInfo->page_topy;
y1 = (cx->prInfo->page_height - y1 - 1) + cx->prSetup->bottom;
y1 -= aCX->prInfo->page_topy;
y1 = (aCX->prInfo->page_height - y1 - 1) + aCX->prSetup->bottom;
XP_FilePrintf(cx->prSetup->out, "%g %g lineto\n",
XP_FilePrintf(aCX->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)
void xl_closepath(PSContext* aCX)
{
XP_FilePrintf(aCX->prSetup->out, "closepath ");
}
void xl_translate(PSContext* aCX, int x, int y)
{
XL_SET_NUMERIC_LOCALE();
y -= cx->prInfo->page_topy;
y -= aCX->prInfo->page_topy;
/*
** Agh! Y inversion again !!
*/
y = (cx->prInfo->page_height - y - 1) + cx->prSetup->bottom;
y = (aCX->prInfo->page_height - y - 1) + aCX->prSetup->bottom;
XP_FilePrintf(cx->prSetup->out, "%g %g translate\n", PAGE_TO_POINT_F(x), PAGE_TO_POINT_F(y));
XP_FilePrintf(aCX->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)
void xl_show(PSContext *aCX, char* txt, int len, char *align)
{
XP_File f;
f = cx->prSetup->out;
f = aCX->prSetup->out;
XP_FilePrintf(f, "(");
while (len-- > 0) {
switch (*txt) {
@ -335,179 +341,179 @@ void xl_show(PSContext *cx, char* txt, int len, char *align)
XP_FilePrintf(f, ") %sshow\n", align);
}
void xl_circle(PSContext* cx, int w, int h)
void xl_circle(PSContext* aCX, 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);
XP_FilePrintf(aCX->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)
void xl_box(PSContext* aCX, int w, int h)
{
XL_SET_NUMERIC_LOCALE();
XP_FilePrintf(cx->prSetup->out, "%g 0 rlineto 0 %g rlineto %g 0 rlineto closepath ",
XP_FilePrintf(aCX->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_draw_border(PSContext *aCX, int x, int y, int w, int h, int thick)
{
XL_SET_NUMERIC_LOCALE();
XP_FilePrintf(cx->prSetup->out, "gsave %g setlinewidth\n ",
XP_FilePrintf(aCX->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_moveto(aCX, x, y);
xl_box(aCX, w, h);
xl_stroke(aCX);
XP_FilePrintf(aCX->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)
xl_draw_3d_border(PSContext *aCX, 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 ");
XP_FilePrintf(aCX->prSetup->out, "gsave\n ");
/* lower left */
llx = x;
lly = y + h;
/* top left */
xl_moveto(cx, llx, lly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, llx, lly);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", tl);
/* bottom right */
xl_moveto(cx, llx, lly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, llx, lly);
XP_FilePrintf(aCX->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(aCX->prSetup->out, ".%d setgray fill\n", br);
XP_FilePrintf(cx->prSetup->out, "grestore\n");
XP_FilePrintf(aCX->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,
xl_draw_3d_radiobox(PSContext *aCX, 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 ");
XP_FilePrintf(aCX->prSetup->out, "gsave\n ");
/* left */
lx = x;
ly = y + h/2;
/* bottom */
xl_moveto(cx, lx, ly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, lx, ly);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", bottom);
/* top */
xl_moveto(cx, lx, ly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, lx, ly);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", top);
/* center */
if (center != 10) {
xl_moveto(cx, lx+thick, ly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, lx+thick, ly);
XP_FilePrintf(aCX->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(aCX->prSetup->out, ".%d setgray fill\n", center);
}
XP_FilePrintf(cx->prSetup->out, "grestore\n");
XP_FilePrintf(aCX->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,
xl_draw_3d_checkbox(PSContext *aCX, 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 ");
XP_FilePrintf(aCX->prSetup->out, "gsave\n ");
/* lower left */
llx = x;
lly = y + h;
/* top left */
xl_moveto(cx, llx, lly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, llx, lly);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", tl);
/* bottom right */
xl_moveto(cx, llx, lly);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, llx, lly);
XP_FilePrintf(aCX->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(aCX->prSetup->out, ".%d setgray fill\n", br);
/* center */
if (center != 10) {
xl_moveto(cx, llx+thick, lly-thick);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, llx+thick, lly-thick);
XP_FilePrintf(aCX->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(aCX->prSetup->out, ".%d setgray fill\n", center);
}
XP_FilePrintf(cx->prSetup->out, "grestore\n");
XP_FilePrintf(aCX->prSetup->out, "grestore\n");
XL_RESTORE_NUMERIC_LOCALE();
}
extern void xl_draw_3d_arrow(PSContext *cx, int x , int y, int thick, int w,
extern void xl_draw_3d_arrow(PSContext *aCX, 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 ");
XP_FilePrintf(aCX->prSetup->out, "gsave\n ");
if (up) {
tx = x + w/2;
@ -515,33 +521,33 @@ extern void xl_draw_3d_arrow(PSContext *cx, int x , int y, int thick, int w,
/* left */
xl_moveto(cx, tx, ty);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, tx, ty);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", left);
/* right */
xl_moveto(cx, tx, ty);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, tx, ty);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", right);
/* base */
xl_moveto(cx, tx-w/2, ty+h);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, tx-w/2, ty+h);
XP_FilePrintf(aCX->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(aCX->prSetup->out, ".%d setgray fill\n", base);
}
else {
tx = x + w/2;
@ -549,69 +555,82 @@ extern void xl_draw_3d_arrow(PSContext *cx, int x , int y, int thick, int w,
/* left */
xl_moveto(cx, tx, ty);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, tx, ty);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", left);
/* right */
xl_moveto(cx, tx, ty);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, tx, ty);
XP_FilePrintf(aCX->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);
XP_FilePrintf(aCX->prSetup->out, ".%d setgray fill\n", right);
/* base */
xl_moveto(cx, x, y);
XP_FilePrintf(cx->prSetup->out,
xl_moveto(aCX, x, y);
XP_FilePrintf(aCX->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(aCX->prSetup->out, ".%d setgray fill\n", base);
}
XP_FilePrintf(cx->prSetup->out, "grestore\n");
XP_FilePrintf(aCX->prSetup->out, "grestore\n");
XL_RESTORE_NUMERIC_LOCALE();
}
void xl_line(PSContext* cx, int x1, int y1, int x2, int y2, int thick)
void xl_line(PSContext* aCX, int x1, int y1, int x2, int y2, int thick)
{
XL_SET_NUMERIC_LOCALE();
XP_FilePrintf(cx->prSetup->out, "gsave %g setlinewidth\n ",
XP_FilePrintf(aCX->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;
y1 -= aCX->prInfo->page_topy;
y1 = (aCX->prInfo->page_height - y1 - 1) + aCX->prSetup->bottom;
y2 -= aCX->prInfo->page_topy;
y2 = (aCX->prInfo->page_height - y2 - 1) + aCX->prSetup->bottom;
XP_FilePrintf(cx->prSetup->out, "%g %g moveto %g %g lineto\n",
XP_FilePrintf(aCX->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);
xl_stroke(aCX);
XP_FilePrintf(cx->prSetup->out, "grestore\n");
XP_FilePrintf(aCX->prSetup->out, "grestore\n");
XL_RESTORE_NUMERIC_LOCALE();
}
void xl_stroke(PSContext *cx)
void xl_stroke(PSContext *aCX)
{
XP_FilePrintf(cx->prSetup->out, " stroke \n");
XP_FilePrintf(aCX->prSetup->out, " stroke \n");
}
void xl_fill(PSContext *cx)
void xl_fill(PSContext *aCX)
{
XP_FilePrintf(cx->prSetup->out, " fill \n");
XP_FilePrintf(aCX->prSetup->out, " fill \n");
}
void xl_graphics_save(PSContext *aCX)
{
XP_FilePrintf(aCX->prSetup->out, " gsave \n");
}
void xl_graphics_restore(PSContext *aCX)
{
XP_FilePrintf(aCX->prSetup->out, " grestore \n");
}
/*
** This function works, but is starting to show it's age, as the list
** of known problems grows:
@ -628,7 +647,7 @@ void xl_fill(PSContext *cx)
** + 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,
void xl_colorimage(PSContext *aCX, int x, int y, int w, int h, IL_Pixmap *image,
IL_Pixmap *mask)
{
uint8 pixmap_depth;
@ -643,7 +662,7 @@ void xl_colorimage(PSContext *cx, int x, int y, int w, int h, IL_Pixmap *image,
NI_PixmapHeader *img_header = &image->header;
XL_SET_NUMERIC_LOCALE();
f = cx->prSetup->out;
f = aCX->prSetup->out;
pps = 1;
row_ends_within_byte = 0;
pixmap_depth = img_header->color_space->pixmap_depth;
@ -656,7 +675,7 @@ void xl_colorimage(PSContext *cx, int x, int y, int w, int h, IL_Pixmap *image,
pps = 8;
}
else if (pixmap_depth == 16) {
if (cx->prSetup->color) {
if (aCX->prSetup->color) {
rowdata = (img_header->width*12)/8;
row_ends_within_byte = (img_header->width*12)%8 ? 1 : 0;
cbits = 4;
@ -676,13 +695,13 @@ void xl_colorimage(PSContext *cx, int x, int y, int w, int h, IL_Pixmap *image,
XP_FilePrintf(f, "gsave\n");
XP_FilePrintf(f, "/rowdata %d string def\n",
rowdata + row_ends_within_byte);
xl_translate(cx, x, y + h);
xl_translate(aCX, 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)
if (aCX->prSetup->color && pixmap_depth == 16)
XP_FilePrintf(f, " smartimage12rgb\n");
else if (pixmap_depth == 32) {
XP_FilePrintf(f, " { currentfile rowdata readhexstring pop }\n");
@ -700,7 +719,7 @@ void xl_colorimage(PSContext *cx, int x, int y, int w, int h, IL_Pixmap *image,
for (col = 0; col < img_header->width; col += pps) {
switch ( pixmap_depth ) {
case 16:
if (cx->prSetup->color) {
if (aCX->prSetup->color) {
if (n > 76) {
XP_FilePrintf(f, "\n");
n = 0;
@ -751,17 +770,17 @@ void xl_colorimage(PSContext *cx, int x, int y, int w, int h, IL_Pixmap *image,
}
MODULE_PRIVATE void
xl_begin_squished_text(PSContext *cx, float scale)
xl_begin_squished_text(PSContext *aCX, float scale)
{
XL_SET_NUMERIC_LOCALE();
XP_FilePrintf(cx->prSetup->out, "gsave %g 1 scale\n", scale);
XP_FilePrintf(aCX->prSetup->out, "gsave %g 1 scale\n", scale);
XL_RESTORE_NUMERIC_LOCALE();
}
MODULE_PRIVATE void
xl_end_squished_text(PSContext *cx)
xl_end_squished_text(PSContext *aCX)
{
XP_FilePrintf(cx->prSetup->out, "grestore\n");
XP_FilePrintf(aCX->prSetup->out, "grestore\n");
}

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

@ -70,11 +70,13 @@ 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
*/

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

@ -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);