[Gdiplus] Try harder to get a Sans Serif font. Skip the tests if they don't exist.

Adam Petaccia adam at tpetaccia.com
Thu Jul 31 19:37:05 CDT 2008


Also remove a comment that was completely wrong.

The skip also removes some valgrind warnings that would occur if the user didn't have the needed fonts installed.

---
 dlls/gdiplus/font.c       |   21 +++++++++++++++++----
 dlls/gdiplus/tests/font.c |   10 ++++++++--
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c
index 149c586..a60c8d2 100644
--- a/dlls/gdiplus/font.c
+++ b/dlls/gdiplus/font.c
@@ -680,16 +680,29 @@ GpStatus WINGDIPAPI GdipGetGenericFontFamilySerif(GpFontFamily **nativeFamily)
  * RETURNS
  *  InvalidParameter if nativeFamily is NULL.
  *  Ok otherwise.
+ *
+ * NOTES
+ *  If Microsoft Sans Serif is not found, the replacement font Liberation Sans
+ *  is used.
  */
 GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily **nativeFamily)
 {
-    /* FIXME: On Windows this is called Microsoft Sans Serif, this shouldn't
-     * affect anything */
-    static const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
+    static const WCHAR MSSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
+    static const WCHAR LibSans[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','a','n','s','\0'};
+    GpStatus stat;
 
     if (nativeFamily == NULL) return InvalidParameter;
 
-    return GdipCreateFontFamilyFromName(MSSansSerif, NULL, nativeFamily);
+    stat = GdipCreateFontFamilyFromName(MSSansSerif, NULL, nativeFamily);
+    if (stat != Ok)
+    {
+        stat = GdipCreateFontFamilyFromName(LibSans, NULL, nativeFamily);
+        if (stat != Ok)
+            ERR("Could not find a Sans Serif 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 6383f9f..b2f1c80 100644
--- a/dlls/gdiplus/tests/font.c
+++ b/dlls/gdiplus/tests/font.c
@@ -32,6 +32,7 @@ static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R
 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 WCHAR LibSans[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','a','n','s','\0'};
 static const WCHAR LibSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f','\0'};
 
 static const char *debugstr_w(LPCWSTR str)
@@ -285,12 +286,17 @@ static void test_getgenerics (void)
     ZeroMemory(familyName, sizeof(familyName)/sizeof(WCHAR));
 
     stat = GdipGetGenericFontFamilySansSerif (&family);
+    if (stat == FontFamilyNotFound)
+    {
+        skip("Neither Microsoft Core Fonts nor Liberation Fonts are installed\n");
+        return;
+    }
     expect (Ok, stat);
     stat = GdipGetFamilyName (family, familyName, LANG_NEUTRAL);
     expect (Ok, stat);
     ok ((lstrcmpiW(familyName, MicrosoftSansSerif) == 0) ||
-        (lstrcmpiW(familyName,MSSansSerif) == 0),
-        "Expected Microsoft Sans Serif or MS Sans Serif, got %s\n",
+            lstrcmpiW(familyName, LibSans) == 0,
+        "Expected Microsoft Sans Serif or Liberation Sans, got %s\n",
         debugstr_w(familyName));
     stat = GdipDeleteFontFamily (family);
     expect (Ok, stat);
-- 
1.5.4.3




More information about the wine-patches mailing list