diff --git a/gfx/src/gtk/nsDeviceContextGTK.cpp b/gfx/src/gtk/nsDeviceContextGTK.cpp index f89cfc906479..956bef2819b3 100644 --- a/gfx/src/gtk/nsDeviceContextGTK.cpp +++ b/gfx/src/gtk/nsDeviceContextGTK.cpp @@ -17,7 +17,6 @@ */ #include -#include #include "nspr.h" #include "il_util.h" @@ -25,6 +24,9 @@ #include "nsDeviceContextGTK.h" #include "../nsGfxCIID.h" +#include +#include + static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); @@ -116,7 +118,41 @@ NS_IMETHODIMP nsDeviceContextGTK::ConvertPixel(nscolor aColor, NS_IMETHODIMP nsDeviceContextGTK::CheckFontExistence(const nsString& aFontName) { - return NS_OK; + 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(GDK_DISPLAY(), wildstring, 1, &numnames, &fonts); + + if (numnames > 0) + { + ::XFreeFontInfo(fnames, fonts, numnames); + rv = NS_OK; + } + + PR_Free(wildstring); + + return rv; } diff --git a/gfx/src/gtk/nsFontMetricsGTK.cpp b/gfx/src/gtk/nsFontMetricsGTK.cpp index 2114d5f98e69..38d122120d58 100644 --- a/gfx/src/gtk/nsFontMetricsGTK.cpp +++ b/gfx/src/gtk/nsFontMetricsGTK.cpp @@ -24,6 +24,7 @@ #include +#define NOISY_FONTS 1 static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID); diff --git a/gfx/src/gtk/nsRenderingContextGTK.cpp b/gfx/src/gtk/nsRenderingContextGTK.cpp index f89b223f69d0..d19074bde1c5 100644 --- a/gfx/src/gtk/nsRenderingContextGTK.cpp +++ b/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -401,18 +401,7 @@ NS_IMETHODIMP nsRenderingContextGTK::SetFont(const nsFont& aFont) { NS_IF_RELEASE(mFontMetrics); mContext->GetMetricsFor(aFont, mFontMetrics); - if (mFontMetrics) - { - nsFontHandle fontHandle; - mFontMetrics->GetFontHandle(fontHandle); - mCurrentFont = (GdkFont *)fontHandle; - - gdk_gc_set_font(mRenderingSurface->gc, - mCurrentFont); - return NS_OK; - } - else - return NS_ERROR_FAILURE; + return SetFont(mFontMetrics); } NS_IMETHODIMP nsRenderingContextGTK::SetFont(nsIFontMetrics *aFontMetrics) @@ -444,10 +433,8 @@ NS_IMETHODIMP nsRenderingContextGTK::GetLineStyle(nsLineStyle &aLineStyle) NS_IMETHODIMP nsRenderingContextGTK::GetFontMetrics(nsIFontMetrics *&aFontMetrics) { - if (mFontMetrics) - aFontMetrics = mFontMetrics; - else - aFontMetrics = nsnull; + NS_IF_ADDREF(mFontMetrics); + aFontMetrics = mFontMetrics; return NS_OK; } @@ -820,7 +807,7 @@ nsRenderingContextGTK::DrawString(const char *aString, PRUint32 aLength, { nscoord ascent,descent; - mFontMetrics->GetMaxAscent(ascent); + mFontMetrics->GetMaxAscent(ascent); mFontMetrics->GetMaxDescent(descent); DrawLine(aX, aY + ascent + (descent >> 1),