jdk/src/windows/native/sun/font/fontpath.c
changeset 1716 461122becab9
parent 2 90ce3da70b43
child 3928 be186a33df9b
--- a/jdk/src/windows/native/sun/font/fontpath.c	Fri Jul 25 14:46:38 2008 +0400
+++ b/jdk/src/windows/native/sun/font/fontpath.c	Mon Aug 04 18:50:43 2008 +0400
@@ -153,7 +153,8 @@
     JNIEnv *env = fmi->env;
     jstring fullname, fullnameLC;
 
-    if (FontType != TRUETYPE_FONTTYPE) {
+    /* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
+    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
         return 1;
     }
 
@@ -227,7 +228,8 @@
     JNIEnv *env = fmi->env;
     jstring fullname, fullnameLC;
 
-    if (FontType != TRUETYPE_FONTTYPE) {
+    /* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
+    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
         return 1;
     }
 
@@ -274,7 +276,8 @@
     jstring familyLC;
     LOGFONTA lfa;
 
-    if (FontType != TRUETYPE_FONTTYPE) {
+    /* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
+    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
         return 1;
     }
 
@@ -323,7 +326,8 @@
     int slen;
     LOGFONTW lfw;
 
-    if (FontType != TRUETYPE_FONTTYPE) {
+    /* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
+    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
         return 1;
     }
 /*     wprintf(L"FAMILY=%s charset=%d FULL=%s\n", */
@@ -383,15 +387,16 @@
  * Also if a Font has a name for this locale that name also
  * exists in the registry using the appropriate platform encoding.
  * What do we do then?
+ *
+ * Note: OpenType fonts seems to have " (TrueType)" suffix on Vista
+ *   but " (OpenType)" on XP.
  */
 
-/* static const wchar_t W_TTSUFFIX[] = L" (TrueType)"; */
-/* static const char C_TTSUFFIX[] = " (TrueType)"; */
-/* static int TTSLEN = 11;  hard-coded - be careful */
-static BOOL RegistryToBaseTTNameA(LPCSTR name) {
+static BOOL RegistryToBaseTTNameA(LPSTR name) {
     static const char TTSUFFIX[] = " (TrueType)";
+    static const char OTSUFFIX[] = " (OpenType)";
     int TTSLEN = strlen(TTSUFFIX);
-    char *match;
+    char *suffix;
 
     int len = strlen(name);
     if (len == 0) {
@@ -403,19 +408,21 @@
     if (len <= TTSLEN) {
         return FALSE;
     }
-    match = strstr(name, TTSUFFIX);
-    if ((match != NULL) && (match == name+(len-TTSLEN))) {
-        match[0] = '\0'; /* truncate name */
+
+    /* suffix length is the same for truetype and opentype fonts */
+    suffix = name + len - TTSLEN;
+    if (strcmp(suffix, TTSUFFIX) == 0 || strcmp(suffix, OTSUFFIX) == 0) {
+        suffix[0] = '\0'; /* truncate name */
         return TRUE;
-    } else {
-        return FALSE;
     }
+    return FALSE;
 }
 
 static BOOL RegistryToBaseTTNameW(LPWSTR name) {
     static const wchar_t TTSUFFIX[] = L" (TrueType)";
+    static const wchar_t OTSUFFIX[] = L" (OpenType)";
     int TTSLEN = wcslen(TTSUFFIX);
-    wchar_t *match;
+    wchar_t *suffix;
 
     int len = wcslen(name);
     if (len == 0) {
@@ -427,13 +434,13 @@
     if (len <= TTSLEN) {
         return FALSE;
     }
-    match = wcsstr(name, TTSUFFIX);
-    if ((match != NULL) && (match == name+(len-TTSLEN))) {
-        match[0] = L'\0'; /* truncate name */
+    /* suffix length is the same for truetype and opentype fonts */
+    suffix = name + (len - TTSLEN);
+    if (wcscmp(suffix, TTSUFFIX) == 0 || wcscmp(suffix, OTSUFFIX) == 0) {
+        suffix[0] = L'\0'; /* truncate name */
         return TRUE;
-    } else {
-        return FALSE;
     }
+    return FALSE;
 }
 
 static void registerFontA(GdiFontMapInfo *fmi, jobject fontToFileMap,
@@ -675,18 +682,19 @@
         }
         if (IS_NT) {
             if (!RegistryToBaseTTNameW((LPWSTR)wname) ) {
-                /* If the filename ends with ".ttf" also accept it.
+                /* If the filename ends with ".ttf" or ".otf" also accept it.
                  * Not expecting to need to do this for .ttc files.
                  * Also note this code is not mirrored in the "A" (win9x) path.
                  */
                 LPWSTR dot = wcsrchr((LPWSTR)data, L'.');
-                if (dot == NULL || (wcsicmp(dot, L".ttf") != 0)) {
+                if (dot == NULL || ((wcsicmp(dot, L".ttf") != 0)
+                                      && (wcsicmp(dot, L".otf") != 0))) {
                     continue;  /* not a TT font... */
                 }
             }
             registerFontW(&fmi, fontToFileMap, (LPWSTR)wname, (LPWSTR)data);
         } else {
-            if (!RegistryToBaseTTNameA(cname) ) {
+            if (!RegistryToBaseTTNameA((LPSTR)cname)) {
                 continue; /* not a TT font... */
             }
             registerFontA(&fmi, fontToFileMap, cname, (LPCSTR)data);