fixed some scaling issues for the mac, more to come

This commit is contained in:
dcone%netscape.com 1998-12-15 16:56:53 +00:00
parent 89910f892e
commit b8ac234783
4 changed files with 106 additions and 54 deletions

View File

@ -57,6 +57,8 @@ double pix_inch;
mDepth = (**thepix).pixelSize;
mPageRect = (**thepix).bounds;
::HSetState ((Handle)thepix,PixMapHState);
// cps - Unlocking GDeviceHandles is a no - no. See above.
//::HUnlock((Handle)thegd);
@ -79,11 +81,17 @@ NS_IMPL_RELEASE(nsDeviceContextMac)
NS_IMETHODIMP nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget)
{
//float t2d, a2d;
NS_ASSERTION(!(aNativeWidget == nsnull), "attempt to init devicecontext with null widget");
// this is a windowptr, or grafptr, native to macintosh only
mSurface = aNativeWidget;
//mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
mAppUnitsToDevUnits = mTwipsToPixels;
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
return NS_OK;
}
@ -230,30 +238,48 @@ NS_IMETHODIMP nsDeviceContextMac :: CheckFontExistence(const nsString& aFontName
return NS_ERROR_FAILURE;
}
//------------------------------------------------------------------------
/**------------------------------------------------------------------------
* See the documentation in nsDeviceContext.h
* @update 12/11/98 dwc
*/
NS_IMETHODIMP nsDeviceContextMac::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
aWidth = 1;
aHeight = 1;
aWidth = mPageRect.right-mPageRect.left;
aHeight = mPageRect.bottom-mPageRect.top;
return NS_ERROR_FAILURE;
}
//------------------------------------------------------------------------
/**------------------------------------------------------------------------
* See the documentation in nsDeviceContext.h
* @update 12/11/98 dwc
*/
NS_IMETHODIMP nsDeviceContextMac::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext)
{
GrafPtr curPort;
double pix_Inch;
THPrint thePrintRecord; // handle to print record
aContext = new nsDeviceContextMac();
((nsDeviceContextMac*)aContext)->mSpec = aDevice;
NS_ADDREF(aDevice);
::GetPort(&curPort);
return ((nsDeviceContextMac*)aContext)->Init(curPort);
thePrintRecord = ((nsDeviceContextSpecMac*)aDevice)->mPrtRec;
pix_Inch = (**thePrintRecord).prInfo.iHRes;
((nsDeviceContextMac*)aContext)->Init(curPort);
((nsDeviceContextMac*)aContext)->mPageRect = (**thePrintRecord).prInfo.rPage;
((nsDeviceContextMac*)aContext)->mTwipsToPixels = pix_Inch/(float)NSIntPointsToTwips(72);
((nsDeviceContextMac*)aContext)->mPixelsToTwips = 1.0f/mTwipsToPixels;
((nsDeviceContextMac*)aContext)->mAppUnitsToDevUnits = mTwipsToPixels;
((nsDeviceContextMac*)aContext)->mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
return NS_OK;
}
@ -301,13 +327,7 @@ NS_IMETHODIMP nsDeviceContextMac::BeginPage(void)
NS_IMETHODIMP nsDeviceContextMac::EndPage(void)
{
if(((nsDeviceContextSpecMac*)(this->mSpec))->mPrintManagerOpen) {
Rect theRect;
::SetPort((GrafPtr)(((nsDeviceContextSpecMac*)(this->mSpec))->mPrinterPort));
::SetRect(&theRect,0,0,100,100);
::PenNormal();
::PaintRect(&theRect);
::PrClosePage(((nsDeviceContextSpecMac*)(this->mSpec))->mPrinterPort);
}
return NS_OK;

View File

@ -33,39 +33,45 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsNativeWidget aNativeWidget);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
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 GetDepth(PRUint32& aDepth);
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext);
NS_IMETHOD BeginDocument(void);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginDocument(void);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
protected:
virtual ~nsDeviceContextMac();
nsDrawingSurface mSurface ;
virtual ~nsDeviceContextMac();
/** ---------------------------------------------------
* Common initialization actions for the nsDeviceContextMac
* @update 12/9/98 dwc
*/
nsDrawingSurface mSurface;
PRUint32 mDepth;
Rect mPageRect;
nsIDeviceContextSpec *mSpec;
GrafPtr mOldPort;

View File

@ -57,6 +57,8 @@ double pix_inch;
mDepth = (**thepix).pixelSize;
mPageRect = (**thepix).bounds;
::HSetState ((Handle)thepix,PixMapHState);
// cps - Unlocking GDeviceHandles is a no - no. See above.
//::HUnlock((Handle)thegd);
@ -79,11 +81,17 @@ NS_IMPL_RELEASE(nsDeviceContextMac)
NS_IMETHODIMP nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget)
{
//float t2d, a2d;
NS_ASSERTION(!(aNativeWidget == nsnull), "attempt to init devicecontext with null widget");
// this is a windowptr, or grafptr, native to macintosh only
mSurface = aNativeWidget;
//mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
mAppUnitsToDevUnits = mTwipsToPixels;
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
return NS_OK;
}
@ -230,30 +238,48 @@ NS_IMETHODIMP nsDeviceContextMac :: CheckFontExistence(const nsString& aFontName
return NS_ERROR_FAILURE;
}
//------------------------------------------------------------------------
/**------------------------------------------------------------------------
* See the documentation in nsDeviceContext.h
* @update 12/11/98 dwc
*/
NS_IMETHODIMP nsDeviceContextMac::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
aWidth = 1;
aHeight = 1;
aWidth = mPageRect.right-mPageRect.left;
aHeight = mPageRect.bottom-mPageRect.top;
return NS_ERROR_FAILURE;
}
//------------------------------------------------------------------------
/**------------------------------------------------------------------------
* See the documentation in nsDeviceContext.h
* @update 12/11/98 dwc
*/
NS_IMETHODIMP nsDeviceContextMac::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext)
{
GrafPtr curPort;
double pix_Inch;
THPrint thePrintRecord; // handle to print record
aContext = new nsDeviceContextMac();
((nsDeviceContextMac*)aContext)->mSpec = aDevice;
NS_ADDREF(aDevice);
::GetPort(&curPort);
return ((nsDeviceContextMac*)aContext)->Init(curPort);
thePrintRecord = ((nsDeviceContextSpecMac*)aDevice)->mPrtRec;
pix_Inch = (**thePrintRecord).prInfo.iHRes;
((nsDeviceContextMac*)aContext)->Init(curPort);
((nsDeviceContextMac*)aContext)->mPageRect = (**thePrintRecord).prInfo.rPage;
((nsDeviceContextMac*)aContext)->mTwipsToPixels = pix_Inch/(float)NSIntPointsToTwips(72);
((nsDeviceContextMac*)aContext)->mPixelsToTwips = 1.0f/mTwipsToPixels;
((nsDeviceContextMac*)aContext)->mAppUnitsToDevUnits = mTwipsToPixels;
((nsDeviceContextMac*)aContext)->mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
return NS_OK;
}
@ -301,13 +327,7 @@ NS_IMETHODIMP nsDeviceContextMac::BeginPage(void)
NS_IMETHODIMP nsDeviceContextMac::EndPage(void)
{
if(((nsDeviceContextSpecMac*)(this->mSpec))->mPrintManagerOpen) {
Rect theRect;
::SetPort((GrafPtr)(((nsDeviceContextSpecMac*)(this->mSpec))->mPrinterPort));
::SetRect(&theRect,0,0,100,100);
::PenNormal();
::PaintRect(&theRect);
::PrClosePage(((nsDeviceContextSpecMac*)(this->mSpec))->mPrinterPort);
}
return NS_OK;

View File

@ -33,39 +33,45 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsNativeWidget aNativeWidget);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; }
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
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 GetDepth(PRUint32& aDepth);
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext);
NS_IMETHOD BeginDocument(void);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginDocument(void);
NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
protected:
virtual ~nsDeviceContextMac();
nsDrawingSurface mSurface ;
virtual ~nsDeviceContextMac();
/** ---------------------------------------------------
* Common initialization actions for the nsDeviceContextMac
* @update 12/9/98 dwc
*/
nsDrawingSurface mSurface;
PRUint32 mDepth;
Rect mPageRect;
nsIDeviceContextSpec *mSpec;
GrafPtr mOldPort;