From bdfd1791d80445379bde6549076d0a1dc5387331 Mon Sep 17 00:00:00 2001 From: "michaelp%netscape.com" Date: Sat, 1 Aug 1998 21:36:05 +0000 Subject: [PATCH] added font existence API. --- gfx/src/motif/nsDeviceContextUnix.h | 2 ++ gfx/src/nsIDeviceContext.h | 1 + gfx/src/windows/nsDeviceContextWin.cpp | 24 ++++++++++++++++++++++++ gfx/src/windows/nsDeviceContextWin.h | 2 ++ 4 files changed, 29 insertions(+) diff --git a/gfx/src/motif/nsDeviceContextUnix.h b/gfx/src/motif/nsDeviceContextUnix.h index 28fcf31041c6..487187bfb635 100644 --- a/gfx/src/motif/nsDeviceContextUnix.h +++ b/gfx/src/motif/nsDeviceContextUnix.h @@ -97,6 +97,8 @@ public: PRInt32 aId, nsIImage*& aImage); + NS_IMETHOD CheckFontExistence(const char * aFontName); + protected: ~nsDeviceContextUnix(); nsresult CreateFontCache(); diff --git a/gfx/src/nsIDeviceContext.h b/gfx/src/nsIDeviceContext.h index 59def53e7bfa..4085341fd78a 100644 --- a/gfx/src/nsIDeviceContext.h +++ b/gfx/src/nsIDeviceContext.h @@ -108,6 +108,7 @@ public: PRInt32 aId, nsIImage*& aImage) = 0; + NS_IMETHOD CheckFontExistence(const char * aFontName) = 0; }; #endif /* nsIDeviceContext_h___ */ diff --git a/gfx/src/windows/nsDeviceContextWin.cpp b/gfx/src/windows/nsDeviceContextWin.cpp index 9e1f0b71cd26..a33155e72d83 100644 --- a/gfx/src/windows/nsDeviceContextWin.cpp +++ b/gfx/src/windows/nsDeviceContextWin.cpp @@ -59,4 +59,28 @@ nsDrawingSurface nsDeviceContextWin :: GetDrawingSurface(nsIRenderingContext &aC return mSurface; } +int CALLBACK fontcallback(ENUMLOGFONT FAR *lpelf, NEWTEXTMETRIC FAR *lpntm, + int FontType, LPARAM lParam) +{ + if (NULL != lpelf) + *((PRBool *)lParam) = PR_TRUE; + + return 0; +} + +NS_IMETHODIMP nsDeviceContextWin :: CheckFontExistence(const char * aFontName) +{ + HWND hwnd = (HWND)GetNativeWidget(); + HDC hdc = ::GetDC(hwnd); + PRBool isthere = PR_FALSE; + + ::EnumFontFamilies(hdc, aFontName, (FONTENUMPROC)fontcallback, (LPARAM)&isthere); + + ::ReleaseDC(hwnd, hdc); + + if (PR_TRUE == isthere) + return NS_OK; + else + return NS_ERROR_FAILURE; +} diff --git a/gfx/src/windows/nsDeviceContextWin.h b/gfx/src/windows/nsDeviceContextWin.h index e90c4e5f0062..042450bbc523 100644 --- a/gfx/src/windows/nsDeviceContextWin.h +++ b/gfx/src/windows/nsDeviceContextWin.h @@ -36,6 +36,8 @@ public: //in the device context for re-use. virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext); + NS_IMETHOD CheckFontExistence(const char * aFontName); + protected: virtual ~nsDeviceContextWin();