зеркало из https://github.com/mozilla/pjs.git
Fixes to get viewer to render on Unix
This commit is contained in:
Родитель
0f0bbe0a61
Коммит
9635153ef3
|
@ -33,6 +33,7 @@ static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
|||
|
||||
#define NS_TO_X(a) (NS_TO_X_RED(a) | NS_TO_X_GREEN(a) | NS_TO_X_BLUE(a))
|
||||
|
||||
|
||||
nsDeviceContextUnix :: nsDeviceContextUnix()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -176,16 +177,20 @@ nsIRenderingContext * nsDeviceContextUnix :: CreateRenderingContext(nsIView *aVi
|
|||
|
||||
rv = NSRepository::CreateInstance(kRCCID, nsnull, kRCIID, (void **)&pContext);
|
||||
|
||||
if (NS_OK == rv)
|
||||
InitRenderingContext(pContext, win);
|
||||
if (NS_OK == rv) {
|
||||
rv = InitRenderingContext(pContext, win);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(pContext);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(win);
|
||||
NS_IF_RELEASE(win);
|
||||
return pContext;
|
||||
}
|
||||
|
||||
void nsDeviceContextUnix :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
nsresult nsDeviceContextUnix :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
{
|
||||
aContext->Init(this, aWin);
|
||||
return (aContext->Init(this, aWin));
|
||||
}
|
||||
|
||||
PRUint32 nsDeviceContextUnix :: ConvertPixel(nscolor aColor)
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
virtual nsresult Init(nsNativeDeviceContext aNativeDeviceContext);
|
||||
|
||||
virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView);
|
||||
virtual void InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
virtual nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
|
||||
virtual float GetTwipsToDevUnits() const;
|
||||
virtual float GetDevUnitsToTwips() const;
|
||||
|
|
|
@ -58,23 +58,25 @@ void nsFontMetricsUnix::RealizeFont()
|
|||
mFontHandle = ::XLoadFont((Display *)mContext->GetNativeDeviceContext(), "fixed");
|
||||
|
||||
XFontStruct * fs = ::XQueryFont((Display *)mContext->GetNativeDeviceContext(), mFontHandle);
|
||||
|
||||
float f = mContext->GetDevUnitsToAppUnits();
|
||||
|
||||
mAscent = fs->ascent ;
|
||||
mDescent = fs->descent ;
|
||||
mMaxAscent = fs->ascent ;
|
||||
mMaxDescent = fs->descent ;
|
||||
mAscent = nscoord(fs->ascent * f);
|
||||
mDescent = nscoord(fs->descent * f);
|
||||
mMaxAscent = nscoord(fs->ascent * f) ;
|
||||
mMaxDescent = nscoord(fs->descent * f);
|
||||
|
||||
// ::XSetFont(aRenderingSurface->display, aRenderingSurface->gc, mFontHandle);
|
||||
|
||||
// XXX Temp hardcodes
|
||||
mHeight = 15 ;
|
||||
mHeight = nscoord(15*f) ;
|
||||
|
||||
PRUint32 i;
|
||||
for (i=0;i<256;i++)
|
||||
mCharWidths[i] = 9 ;
|
||||
mCharWidths[i] = nscoord(9*f) ;
|
||||
|
||||
mMaxAdvance = 15;
|
||||
mLeading = 3;
|
||||
mMaxAdvance = nscoord(15*f);
|
||||
mLeading = nscoord(3*f);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(char ch)
|
||||
|
@ -99,16 +101,16 @@ nscoord nsFontMetricsUnix :: GetWidth(const nsString& aString)
|
|||
nscoord nsFontMetricsUnix :: GetWidth(const char *aString)
|
||||
{
|
||||
|
||||
nscoord rc = 0 ;
|
||||
PRInt32 rc = 0 ;
|
||||
|
||||
mFontHandle = ::XLoadFont((Display *)mContext->GetNativeDeviceContext(), "fixed");
|
||||
|
||||
XFontStruct * fs = ::XQueryFont((Display *)mContext->GetNativeDeviceContext(), mFontHandle);
|
||||
|
||||
rc = (nscoord) ::XTextWidth(fs, aString, nsCRT::strlen(aString));
|
||||
|
||||
return (rc);
|
||||
rc = (PRInt32) ::XTextWidth(fs, aString, nsCRT::strlen(aString));
|
||||
|
||||
return (nscoord(rc * mContext->GetDevUnitsToAppUnits()));
|
||||
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(const PRUnichar *aString, PRUint32 aLength)
|
||||
|
@ -137,7 +139,7 @@ nscoord nsFontMetricsUnix :: GetWidth(const PRUnichar *aString, PRUint32 aLength
|
|||
|
||||
PR_Free(xstring);
|
||||
|
||||
return (width);
|
||||
return (nscoord(width * mContext->GetDevUnitsToAppUnits()));
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetHeight()
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "X11/Xlib.h"
|
||||
#include "X11/Xutil.h"
|
||||
|
||||
#define CLIPPING_NOT_FUNCTIONAL 1
|
||||
|
||||
class GraphicsState
|
||||
{
|
||||
public:
|
||||
|
@ -78,8 +80,8 @@ nsRenderingContextUnix :: nsRenderingContextUnix()
|
|||
mFontCache = nsnull ;
|
||||
mFontMetrics = nsnull ;
|
||||
mContext = nsnull ;
|
||||
mFrontBuffer = nsnull ;
|
||||
mRenderingSurface = nsnull ;
|
||||
mOffscreenSurface = nsnull ;
|
||||
mCurrentColor = 0;
|
||||
mTMatrix = nsnull;
|
||||
mP2T = 1.0f;
|
||||
|
@ -119,7 +121,7 @@ nsRenderingContextUnix :: ~nsRenderingContextUnix()
|
|||
mStateCache = nsnull;
|
||||
}
|
||||
|
||||
delete mRenderingSurface;
|
||||
delete mFrontBuffer;
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsRenderingContextUnix, kRenderingContextIID)
|
||||
|
@ -129,6 +131,8 @@ NS_IMPL_RELEASE(nsRenderingContextUnix)
|
|||
nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
|
||||
nsIWidget *aWindow)
|
||||
{
|
||||
if (nsnull == aWindow->GetNativeData(NS_NATIVE_WINDOW))
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
mContext = aContext;
|
||||
NS_IF_ADDREF(mContext);
|
||||
|
@ -139,6 +143,7 @@ nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
|
|||
mRenderingSurface->drawable = (Drawable)aWindow->GetNativeData(NS_NATIVE_WINDOW);
|
||||
mRenderingSurface->gc = (GC)aWindow->GetNativeData(NS_NATIVE_GRAPHIC);
|
||||
|
||||
mFrontBuffer = mRenderingSurface;
|
||||
|
||||
((nsDeviceContextUnix *)aContext)->SetDrawingSurface(mRenderingSurface);
|
||||
((nsDeviceContextUnix *)aContext)->InstallColormap();
|
||||
|
@ -156,6 +161,7 @@ nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
|
|||
nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
|
||||
nsDrawingSurface aSurface)
|
||||
{
|
||||
|
||||
mContext = aContext;
|
||||
NS_IF_ADDREF(mContext);
|
||||
|
||||
|
@ -172,8 +178,7 @@ nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
|
|||
}
|
||||
|
||||
nsresult nsRenderingContextUnix :: SelectOffScreenDrawingSurface(nsDrawingSurface aSurface)
|
||||
{
|
||||
mOffscreenSurface = mRenderingSurface;
|
||||
{
|
||||
mRenderingSurface = (nsDrawingSurfaceUnix *) aSurface;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -197,8 +202,11 @@ void nsRenderingContextUnix :: PushState(void)
|
|||
|
||||
mStateCache->AppendElement(state);
|
||||
|
||||
mTMatrix = new nsTransform2D();
|
||||
mTMatrix->SetToIdentity();
|
||||
if (nsnull == mTMatrix)
|
||||
mTMatrix = new nsTransform2D();
|
||||
else
|
||||
mTMatrix = new nsTransform2D(mTMatrix);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -231,6 +239,9 @@ PRBool nsRenderingContextUnix :: IsVisibleRect(const nsRect& aRect)
|
|||
|
||||
PRBool nsRenderingContextUnix :: SetClipRect(const nsRect& aRect, nsClipCombine aCombine)
|
||||
{
|
||||
#ifdef CLIPPING_NOT_FUNCTIONAL
|
||||
return PR_FALSE;
|
||||
#endif
|
||||
|
||||
// Essentially, create the rect and select it into the GC. Get the current
|
||||
// ClipRegion first
|
||||
|
@ -311,6 +322,10 @@ PRBool nsRenderingContextUnix :: SetClipRect(const nsRect& aRect, nsClipCombine
|
|||
|
||||
PRBool nsRenderingContextUnix :: GetClipRect(nsRect &aRect)
|
||||
{
|
||||
#ifdef CLIPPING_NOT_FUNCTIONAL
|
||||
return PR_FALSE;
|
||||
#endif
|
||||
|
||||
if (mRegion != nsnull) {
|
||||
XRectangle xrect;
|
||||
::XClipBox(mRegion, &xrect);
|
||||
|
@ -324,6 +339,11 @@ PRBool nsRenderingContextUnix :: GetClipRect(nsRect &aRect)
|
|||
|
||||
PRBool nsRenderingContextUnix :: SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine)
|
||||
{
|
||||
|
||||
#ifdef CLIPPING_NOT_FUNCTIONAL
|
||||
return PR_FALSE;
|
||||
#endif
|
||||
|
||||
nsRect rect;
|
||||
XRectangle xrect;
|
||||
|
||||
|
@ -466,11 +486,8 @@ void nsRenderingContextUnix :: DestroyDrawingSurface(nsDrawingSurface aDS)
|
|||
// XXX - Could this be a GC? If so, store the type of surface in nsDrawingSurfaceUnix
|
||||
::XFreePixmap(surface->display, surface->drawable);
|
||||
|
||||
if (mOffscreenSurface == surface)
|
||||
mOffscreenSurface = nsnull;
|
||||
|
||||
if (mRenderingSurface == surface)
|
||||
mRenderingSurface = nsnull;
|
||||
// if (mRenderingSurface == surface)
|
||||
// mRenderingSurface = nsnull;
|
||||
|
||||
delete aDS;
|
||||
}
|
||||
|
@ -657,12 +674,13 @@ void nsRenderingContextUnix :: DrawString(const char *aString, PRUint32 aLength,
|
|||
|
||||
PRInt32 x = aX;
|
||||
PRInt32 y = aY;
|
||||
mTMatrix->TransformCoord(&x,&y);
|
||||
|
||||
// Substract xFontStruct ascent since drawing specifies baseline
|
||||
if (mFontMetrics)
|
||||
y += mFontMetrics->GetMaxAscent();
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y);
|
||||
|
||||
::XDrawString(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
|
@ -715,8 +733,8 @@ nsresult nsRenderingContextUnix :: CopyOffScreenBits(nsRect &aBounds)
|
|||
|
||||
::XCopyArea(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mOffscreenSurface->drawable,
|
||||
mOffscreenSurface->gc,
|
||||
mFrontBuffer->drawable,
|
||||
mFrontBuffer->gc,
|
||||
aBounds.x, aBounds.y, aBounds.width, aBounds.height, 0, 0);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -136,8 +136,8 @@ protected:
|
|||
nsTransform2D *mTMatrix; // transform that all the graphics drawn here will obey
|
||||
float mP2T;
|
||||
|
||||
nsDrawingSurfaceUnix *mOffscreenSurface;
|
||||
nsDrawingSurfaceUnix *mRenderingSurface;
|
||||
nsDrawingSurfaceUnix *mRenderingSurface; // Can be a BackBuffer if Selected in
|
||||
nsDrawingSurfaceUnix *mFrontBuffer;
|
||||
nsIDeviceContext *mContext;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
nsIFontCache *mFontCache;
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual nsresult Init(nsNativeDeviceContext aNativeDeviceContext) = 0;
|
||||
|
||||
virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView) = 0;
|
||||
virtual void InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWindow) = 0;
|
||||
virtual nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWindow) = 0;
|
||||
|
||||
//these are queries to figure out how large an output unit
|
||||
//(i.e. pixel) is in terms of twips (1/20 of a point)
|
||||
|
|
|
@ -127,16 +127,20 @@ nsIRenderingContext * nsDeviceContextWin :: CreateRenderingContext(nsIView *aVie
|
|||
|
||||
rv = NSRepository::CreateInstance(kRCCID, nsnull, kRCIID, (void **)&pContext);
|
||||
|
||||
if (NS_OK == rv)
|
||||
InitRenderingContext(pContext, win);
|
||||
if (NS_OK == rv) {
|
||||
rv = InitRenderingContext(pContext, win);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(pContext);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(win);
|
||||
return pContext;
|
||||
}
|
||||
|
||||
void nsDeviceContextWin :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
nsresult nsDeviceContextWin :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
{
|
||||
aContext->Init(this, aWin);
|
||||
return (aContext->Init(this, aWin));
|
||||
}
|
||||
|
||||
nsIFontCache* nsDeviceContextWin::GetFontCache()
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual nsresult Init(nsNativeDeviceContext aNativeDeviceContext);
|
||||
|
||||
virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView);
|
||||
virtual void InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
virtual nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
|
||||
virtual float GetTwipsToDevUnits() const;
|
||||
virtual float GetDevUnitsToTwips() const;
|
||||
|
|
|
@ -67,8 +67,6 @@ nsViewManager :: ~nsViewManager()
|
|||
{
|
||||
nsIRenderingContext *rc;
|
||||
|
||||
//interesting way of killing things
|
||||
|
||||
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kIRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
|
||||
|
||||
|
@ -294,11 +292,9 @@ void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsI
|
|||
{
|
||||
localcx = CreateRenderingContext(*aView);
|
||||
|
||||
//couldn't get rendering context. ack.
|
||||
|
||||
//couldn't get rendering context. this is ok at init time atleast
|
||||
if (nsnull == localcx)
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "unable to create rendering context.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -359,11 +355,9 @@ void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsR
|
|||
{
|
||||
localcx = CreateRenderingContext(*aView);
|
||||
|
||||
//couldn't get rendering context. ack.
|
||||
|
||||
//couldn't get rendering context. this is ok if at startup
|
||||
if (nsnull == localcx)
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "unable to create rendering context.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -895,7 +889,9 @@ nsIRenderingContext * nsViewManager :: CreateRenderingContext(nsIView &aView)
|
|||
{
|
||||
dx = mContext->GetDeviceContext();
|
||||
cx = dx->CreateRenderingContext(&aView);
|
||||
cx->Translate(ax, ay);
|
||||
|
||||
if (nsnull != cx)
|
||||
cx->Translate(ax, ay);
|
||||
|
||||
NS_RELEASE(dx);
|
||||
NS_RELEASE(win);
|
||||
|
|
|
@ -35,7 +35,9 @@ EX_LIBS = \
|
|||
$(DIST)/bin/libpng.so \
|
||||
$(DIST)/bin/libpref.so \
|
||||
$(DIST)/bin/libraptorbase.so \
|
||||
$(DIST)/bin/libwidgetunix.so \
|
||||
$(DIST)/bin/libraptorgfx.so \
|
||||
$(DIST)/bin/libgfxunix.so \
|
||||
$(DIST)/bin/libraptorhtml.so \
|
||||
$(DIST)/bin/libgmbaseunix.so \
|
||||
$(DIST)/bin/libraptorhtmlbase_s.so \
|
||||
|
|
Загрузка…
Ссылка в новой задаче