[Gdiplus] Try harder to get a monospace font

Adam Petaccia adam at tpetaccia.com
Thu Jul 31 19:35:20 CDT 2008


This series of patches allows the GdipGetGeneric* font functions to use the liberation 
fonts in addition to Microsoft's True Type fonts.

---
 dlls/gdiplus/font.c       |   16 +++++++++++++++-
 dlls/gdiplus/tests/font.c |    8 ++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c
index 70f7bb0..f0dc7dc 100644
--- a/dlls/gdiplus/font.c
+++ b/dlls/gdiplus/font.c
@@ -609,14 +609,28 @@ GpStatus WINGDIPAPI GdipIsStyleAvailable(GDIPCONST GpFontFamily* family,
  * RETURNS
  *  InvalidParameter if nativeFamily is NULL.
  *  Ok otherwise.
+ *
+ * NOTES
+ *  If Courier New is not found, the replacement font Liberation Mono is used.
  */
 GpStatus WINGDIPAPI GdipGetGenericFontFamilyMonospace(GpFontFamily **nativeFamily)
 {
     static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
+    static const WCHAR LibMono[] = {'L','i','b','e','r','a','t','i','o','n',' ','M','o','n','o','\0'};
+    GpStatus stat;
 
     if (nativeFamily == NULL) return InvalidParameter;
 
-    return GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily);
+    stat = GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily);
+    if (stat != Ok)
+    {
+        stat = GdipCreateFontFamilyFromName(LibMono, NULL, nativeFamily);
+        if (stat != Ok)
+             ERR("Could not find a Monospace font. Install liberation fonts or "
+                     "Microsoft Core fonts.\n");
+    }
+
+    return stat;
 }
 
 /*****************************************************************************
diff --git a/dlls/gdiplus/tests/font.c b/dlls/gdiplus/tests/font.c
index 8ce0ec6..8dde2f9 100644
--- a/dlls/gdiplus/tests/font.c
+++ b/dlls/gdiplus/tests/font.c
@@ -31,6 +31,8 @@ static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t','
 static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
 static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
 
+static const WCHAR LibMono[] ={'L','i','b','e','r','a','t','i','o','n',' ','M','o','n','o','\0'};
+
 static const char *debugstr_w(LPCWSTR str)
 {
    static char buf[1024];
@@ -305,8 +307,10 @@ static void test_getgenerics (void)
     expect (Ok, stat);
     stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
     expect (Ok, stat);
-    ok (lstrcmpiW(familyName, CourierNew) == 0,
-        "Expected Courier New, got %s\n", debugstr_w(familyName));
+    ok (lstrcmpiW(familyName, CourierNew) == 0 ||
+            lstrcmpiW(familyName, LibMono) == 0,
+        "Expected Courier New, or Liberation Mono, got %s\n",
+        debugstr_w(familyName));
     stat = GdipDeleteFontFamily (family);
     expect (Ok, stat);
 }
-- 
1.5.4.3




More information about the wine-patches mailing list