From b8d3f3b8bb105d4fae44d0c4d1e0bdf12a7f8723 Mon Sep 17 00:00:00 2001 From: "dcone%netscape.com" Date: Fri, 21 Aug 1998 17:11:15 +0000 Subject: [PATCH] Updated to the correct way the DeviceContext should work, added the twips calculation git-svn-id: svn://10.0.0.236/trunk@8329 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/mac/nsDeviceContextMac.cpp | 20 +++++++++++++++++-- mozilla/gfx/src/mac/nsDeviceContextMac.h | 16 +++------------ mozilla/widget/src/mac/nsDeviceContextMac.cpp | 20 +++++++++++++++++-- mozilla/widget/src/mac/nsDeviceContextMac.h | 16 +++------------ 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/mozilla/gfx/src/mac/nsDeviceContextMac.cpp b/mozilla/gfx/src/mac/nsDeviceContextMac.cpp index c5f371f8ffd..02f9eabf51f 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextMac.cpp +++ b/mozilla/gfx/src/mac/nsDeviceContextMac.cpp @@ -22,6 +22,7 @@ #include "math.h" #include "nspr.h" +#include static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); @@ -29,7 +30,20 @@ static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); nsDeviceContextMac :: nsDeviceContextMac() { +GDHandle thegd; +PixMapHandle thepix; +double pix_inch; + NS_INIT_REFCNT(); + + // see IM Imaging with Quickdraw, chapter 5. This is an imcomplete implementation + thegd = ::GetMainDevice(); + HLock((Handle)thegd); + thepix = (**thegd).gdPMap; + pix_inch = Fix2X((**thepix).hRes); + + mTwipsToPixels = pix_inch/(float)NSIntPointsToTwips(72); + mPixelsToTwips = 1.0f/mTwipsToPixels; } @@ -46,6 +60,9 @@ nsresult nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget) NS_ASSERTION(!(aNativeWidget == nsnull), "attempt to init devicecontext with null widget"); + // this is a windowptr, or grafptr, native to macintosh only + mSurface = aNativeWidget; + return NS_OK; } @@ -66,8 +83,7 @@ float nsDeviceContextMac :: GetScrollBarHeight() const nsDrawingSurface nsDeviceContextMac :: GetDrawingSurface(nsIRenderingContext &aContext) { - //return aContext.CreateDrawingSurface(nsnull); - return nsnull; + return aContext.CreateDrawingSurface(nsnull); } diff --git a/mozilla/gfx/src/mac/nsDeviceContextMac.h b/mozilla/gfx/src/mac/nsDeviceContextMac.h index dd610654fc8..dfadffadaff 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextMac.h +++ b/mozilla/gfx/src/mac/nsDeviceContextMac.h @@ -26,15 +26,6 @@ #include "nsIView.h" #include "nsIRenderingContext.h" -/* nsDrawingSurface is actually the following struct */ -struct nsDrawingSurfaceMac { -/* Display *display ; - Drawable drawable ; - GC gc ; - Visual * visual ; - PRUint32 depth ; */ -}; - class nsDeviceContextMac : public DeviceContextImpl { public: @@ -59,10 +50,9 @@ protected: virtual ~nsDeviceContextMac(); nsresult CreateFontCache(); - nsIFontCache *mFontCache; - nsDrawingSurfaceMac * mSurface ; - - PRUint32 mDepth; + nsIFontCache *mFontCache; + nsDrawingSurface mSurface ; + PRUint32 mDepth; }; diff --git a/mozilla/widget/src/mac/nsDeviceContextMac.cpp b/mozilla/widget/src/mac/nsDeviceContextMac.cpp index c5f371f8ffd..02f9eabf51f 100644 --- a/mozilla/widget/src/mac/nsDeviceContextMac.cpp +++ b/mozilla/widget/src/mac/nsDeviceContextMac.cpp @@ -22,6 +22,7 @@ #include "math.h" #include "nspr.h" +#include static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); @@ -29,7 +30,20 @@ static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); nsDeviceContextMac :: nsDeviceContextMac() { +GDHandle thegd; +PixMapHandle thepix; +double pix_inch; + NS_INIT_REFCNT(); + + // see IM Imaging with Quickdraw, chapter 5. This is an imcomplete implementation + thegd = ::GetMainDevice(); + HLock((Handle)thegd); + thepix = (**thegd).gdPMap; + pix_inch = Fix2X((**thepix).hRes); + + mTwipsToPixels = pix_inch/(float)NSIntPointsToTwips(72); + mPixelsToTwips = 1.0f/mTwipsToPixels; } @@ -46,6 +60,9 @@ nsresult nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget) NS_ASSERTION(!(aNativeWidget == nsnull), "attempt to init devicecontext with null widget"); + // this is a windowptr, or grafptr, native to macintosh only + mSurface = aNativeWidget; + return NS_OK; } @@ -66,8 +83,7 @@ float nsDeviceContextMac :: GetScrollBarHeight() const nsDrawingSurface nsDeviceContextMac :: GetDrawingSurface(nsIRenderingContext &aContext) { - //return aContext.CreateDrawingSurface(nsnull); - return nsnull; + return aContext.CreateDrawingSurface(nsnull); } diff --git a/mozilla/widget/src/mac/nsDeviceContextMac.h b/mozilla/widget/src/mac/nsDeviceContextMac.h index dd610654fc8..dfadffadaff 100644 --- a/mozilla/widget/src/mac/nsDeviceContextMac.h +++ b/mozilla/widget/src/mac/nsDeviceContextMac.h @@ -26,15 +26,6 @@ #include "nsIView.h" #include "nsIRenderingContext.h" -/* nsDrawingSurface is actually the following struct */ -struct nsDrawingSurfaceMac { -/* Display *display ; - Drawable drawable ; - GC gc ; - Visual * visual ; - PRUint32 depth ; */ -}; - class nsDeviceContextMac : public DeviceContextImpl { public: @@ -59,10 +50,9 @@ protected: virtual ~nsDeviceContextMac(); nsresult CreateFontCache(); - nsIFontCache *mFontCache; - nsDrawingSurfaceMac * mSurface ; - - PRUint32 mDepth; + nsIFontCache *mFontCache; + nsDrawingSurface mSurface ; + PRUint32 mDepth; };