diff --git a/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp b/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp index 36d3e897944..c2d11f1502c 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp +++ b/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp @@ -22,6 +22,9 @@ #include "nsIPref.h" #include "nsIServiceManager.h" #include "nsGfxCIID.h" +#include "nspr.h" +#include "xlibrgb.h" +#include "../ps/nsDeviceContextPS.h" static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID); @@ -84,7 +87,7 @@ NS_IMETHODIMP nsDeviceContextXlib::Init(nsNativeWidget aNativeWidget) mTwipsToPixels = float(dpi) / float(NSIntPointsToTwips(72)); mPixelsToTwips = 1.0f / mTwipsToPixels; - CommonInit(); + // printf("GFX: dpi=%d t2p=%g p2t=%g\n", dpi, mTwipsToPixels, mPixelsToTwips); return NS_OK; } @@ -96,16 +99,15 @@ NS_IMETHODIMP nsDeviceContextXlib::CreateRenderingContext(nsIRenderingContext *& nsIRenderingContext *context = nsnull; nsDrawingSurfaceXlib *surface = nsnull; nsresult rv; - Window win = (Window)aContext; - // XXX umm...this isn't done. + context = new nsRenderingContextXlib(); if (nsnull != context) { NS_ADDREF(context); surface = new nsDrawingSurfaceXlib(); if (nsnull != surface) { - GC gc = XCreateGC(gDisplay, win, 0, NULL); - rv = surface->Init((Drawable)win, gc); + GC gc = XCreateGC(gDisplay, (Drawable)mWidget, 0, NULL); + rv = surface->Init((Drawable)mWidget, gc); if (NS_OK == rv) { rv = context->Init(this, surface); } @@ -152,24 +154,61 @@ NS_IMETHODIMP nsDeviceContextXlib::GetSystemAttribute(nsSystemAttrID anID, Syste NS_IMETHODIMP nsDeviceContextXlib::GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface) { printf("nsDeviceContextXlib::GetDrawingSurface()\n"); - return NS_OK; + aContext.CreateDrawingSurface(nsnull, 0, aSurface); + return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK; } NS_IMETHODIMP nsDeviceContextXlib::ConvertPixel(nscolor aColor, PRUint32 & aPixel) { printf("nsDeviceContextXlib::ConvertPixel()\n"); + aPixel = xlib_rgb_xpixel_from_rgb(aPixel); return NS_OK; } NS_IMETHODIMP nsDeviceContextXlib::CheckFontExistence(const nsString& aFontName) { printf("nsDeviceContextXlib::CheckFontExistence()\n"); + char **fnames = nsnull; + PRInt32 namelen = aFontName.Length() + 1; + char *wildstring = (char *)PR_Malloc(namelen + 200); + float t2d; + GetTwipsToDevUnits(t2d); + PRInt32 dpi = NSToIntRound(t2d * 1440); + int numnames = 0; + XFontStruct *fonts; + nsresult rv = NS_ERROR_FAILURE; + + if (nsnull == wildstring) + return NS_ERROR_UNEXPECTED; + + if (abs(dpi - 75) < abs(dpi - 100)) + dpi = 75; + else + dpi = 100; + + char* fontName = aFontName.ToNewCString(); + PR_snprintf(wildstring, namelen + 200, + "*-%s-*-*-normal--*-*-%d-%d-*-*-*", + fontName, dpi, dpi); + delete [] fontName; + + fnames = ::XListFontsWithInfo(gDisplay, wildstring, 1, &numnames, &fonts); + + if (numnames > 0) + { + ::XFreeFontInfo(fnames, fonts, numnames); + rv = NS_OK; + } + + PR_Free(wildstring); return NS_OK; } NS_IMETHODIMP nsDeviceContextXlib::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) { printf("nsDeviceContextXlib::GetDeviceSurfaceDimensions()\n"); + aWidth = 1; + aHeight = 1; return NS_OK; } @@ -177,7 +216,10 @@ NS_IMETHODIMP nsDeviceContextXlib::GetDeviceContextFor(nsIDeviceContextSpec *aDe nsIDeviceContext *&aContext) { printf("nsDeviceContextXlib::GetDeviceContextFor()\n"); - return NS_OK; + aContext = new nsDeviceContextPS(); + ((nsDeviceContextPS *)aContext)->SetSpec(aDevice); + NS_ADDREF(aDevice); + return((nsDeviceContextPS *) aContext)->Init((nsIDeviceContext*)aContext, (nsIDeviceContext*)this); } NS_IMETHODIMP nsDeviceContextXlib::BeginDocument(void) diff --git a/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp b/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp index 8e2a2cb81c1..07da71c3081 100644 --- a/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp +++ b/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp @@ -502,7 +502,7 @@ nsRenderingContextXlib::GetLineStyle(nsLineStyle &aLineStyle) NS_IMETHODIMP nsRenderingContextXlib::SetColor(nscolor aColor) { - printf("nsRenderingContextXlib::SetColor()\n"); + printf("nsRenderingContextXlib::SetColor(nscolor)\n"); if (nsnull == mContext) return NS_ERROR_FAILURE; @@ -510,6 +510,7 @@ nsRenderingContextXlib::SetColor(nscolor aColor) xlib_rgb_gc_set_foreground(mRenderingSurface->GetGC(), NS_RGB(NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor))); + printf("Setting color to %d %d %d\n", NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor)); return NS_OK; } @@ -733,6 +734,8 @@ NS_IMETHODIMP nsRenderingContextXlib::FillRect(const nsRect& aRect) { printf("nsRenderingContextXlib::FillRect()\n"); + printf("About to fill rect %d %d %d %d\n", + aRect.x, aRect.y, aRect.width, aRect.height); return FillRect(aRect.x, aRect.y, aRect.width, aRect.height); }