src/windows/native/sun/font/fontpath.c

Print this page
rev 1297 : [mq]: fontmanager.patch


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 #include <windows.h>
  27 #include <stdio.h>
  28 
  29 #include <jni.h>
  30 #include <jni_util.h>
  31 #include <sun_font_FontManager.h>
  32 
  33 #define BSIZE (max(512, MAX_PATH+1))
  34 
  35 
  36 JNIEXPORT jstring JNICALL Java_sun_font_FontManager_getFontPath(JNIEnv *env, jclass obj, jboolean noType1)
  37 {
  38     char windir[BSIZE];
  39     char sysdir[BSIZE];
  40     char fontpath[BSIZE*2];
  41     char *end;
  42 
  43     /* Locate fonts directories relative to the Windows System directory.
  44      * If Windows System location is different than the user's window
  45      * directory location, as in a shared Windows installation,
  46      * return both locations as potential font directories
  47      */
  48     GetSystemDirectory(sysdir, BSIZE);
  49     end = strrchr(sysdir,'\\');
  50     if (end && (stricmp(end,"\\System") || stricmp(end,"\\System32"))) {
  51         *end = 0;
  52          strcat(sysdir, "\\Fonts");
  53     }
  54 
  55     GetWindowsDirectory(windir, BSIZE);
  56     if (strlen(windir) > BSIZE-7) {
  57         *windir = 0;
  58     } else {
  59         strcat(windir, "\\Fonts");
  60     }
  61 
  62     strcpy(fontpath,sysdir);
  63     if (stricmp(sysdir,windir)) {
  64         strcat(fontpath,";");
  65         strcat(fontpath,windir);
  66     }
  67 
  68     return JNU_NewStringPlatform(env, fontpath);
  69 }
  70 
  71 /* This isn't used on windows, the implementation is added in case shared
  72  * code accidentally calls this method to prevent an UnsatisfiedLinkError
  73  */
  74 JNIEXPORT void JNICALL Java_sun_font_FontManager_setNativeFontPath
  75 (JNIEnv *env, jclass obj, jstring theString)
  76 {
  77     return;
  78 }
  79 
  80 /* The code below is used to obtain information from the windows font APIS
  81  * and registry on which fonts are available and what font files hold those
  82  * fonts. The results are used to speed font lookup.
  83  */
  84 
  85 typedef struct GdiFontMapInfo {
  86     JNIEnv *env;
  87     jstring family;
  88     jobject fontToFamilyMap;
  89     jobject familyToFontListMap;
  90     jobject list;
  91     jmethodID putMID;
  92     jmethodID containsKeyMID;
  93     jclass arrayListClass;
  94     jmethodID arrayListCtr;
  95     jmethodID addMID;
  96     jmethodID toLowerCaseMID;
  97     jobject locale;
  98 } GdiFontMapInfo;
  99 


 529                 break;
 530             } else {
 531                 *(ptr1-3) = L'\0';
 532                 ptr1 = name;
 533             }
 534         }
 535     } else {
 536         fontStr = (*env)->NewString(env, name, wcslen(name));
 537         fontStr = (*env)->CallObjectMethod(env, fontStr,
 538                                            fmi->toLowerCaseMID, fmi->locale);
 539         (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
 540                                  fontStr, fileStr);
 541     }
 542 }
 543 
 544 /* Obtain all the fontname -> filename mappings.
 545  * This is called once and the results returned to Java code which can
 546  * use it for lookups to reduce or avoid the need to search font files.
 547  */
 548 JNIEXPORT void JNICALL
 549 Java_sun_font_FontManager_populateFontFileNameMap
 550 (JNIEnv *env, jclass obj, jobject fontToFileMap,
 551  jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
 552 {
 553 #define MAX_BUFFER (FILENAME_MAX+1)
 554     const wchar_t wname[MAX_BUFFER];
 555     const char cname[MAX_BUFFER];
 556     const char data[MAX_BUFFER];
 557 
 558     DWORD type;
 559     LONG ret;
 560     HKEY hkeyFonts;
 561     DWORD dwNameSize;
 562     DWORD dwDataValueSize;
 563     DWORD nval;
 564     LPCSTR fontKeyName;
 565     DWORD dwNumValues, dwMaxValueNameLen, dwMaxValueDataLen;
 566     DWORD numValues = 0;
 567     jclass classID;
 568     jmethodID putMID;
 569     GdiFontMapInfo fmi;




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any questions.
  24  */
  25 
  26 #include <windows.h>
  27 #include <stdio.h>
  28 
  29 #include <jni.h>
  30 #include <jni_util.h>
  31 #include <sun_awt_Win32FontManager.h>
  32 
  33 #define BSIZE (max(512, MAX_PATH+1))
  34 
  35 
  36 JNIEXPORT jstring JNICALL Java_sun_awt_Win32FontManager_getFontPath(JNIEnv *env, jobject thiz, jboolean noType1)
  37 {
  38     char windir[BSIZE];
  39     char sysdir[BSIZE];
  40     char fontpath[BSIZE*2];
  41     char *end;
  42 
  43     /* Locate fonts directories relative to the Windows System directory.
  44      * If Windows System location is different than the user's window
  45      * directory location, as in a shared Windows installation,
  46      * return both locations as potential font directories
  47      */
  48     GetSystemDirectory(sysdir, BSIZE);
  49     end = strrchr(sysdir,'\\');
  50     if (end && (stricmp(end,"\\System") || stricmp(end,"\\System32"))) {
  51         *end = 0;
  52          strcat(sysdir, "\\Fonts");
  53     }
  54 
  55     GetWindowsDirectory(windir, BSIZE);
  56     if (strlen(windir) > BSIZE-7) {
  57         *windir = 0;
  58     } else {
  59         strcat(windir, "\\Fonts");
  60     }
  61 
  62     strcpy(fontpath,sysdir);
  63     if (stricmp(sysdir,windir)) {
  64         strcat(fontpath,";");
  65         strcat(fontpath,windir);
  66     }
  67 
  68     return JNU_NewStringPlatform(env, fontpath);
  69 }
  70 









  71 /* The code below is used to obtain information from the windows font APIS
  72  * and registry on which fonts are available and what font files hold those
  73  * fonts. The results are used to speed font lookup.
  74  */
  75 
  76 typedef struct GdiFontMapInfo {
  77     JNIEnv *env;
  78     jstring family;
  79     jobject fontToFamilyMap;
  80     jobject familyToFontListMap;
  81     jobject list;
  82     jmethodID putMID;
  83     jmethodID containsKeyMID;
  84     jclass arrayListClass;
  85     jmethodID arrayListCtr;
  86     jmethodID addMID;
  87     jmethodID toLowerCaseMID;
  88     jobject locale;
  89 } GdiFontMapInfo;
  90 


 520                 break;
 521             } else {
 522                 *(ptr1-3) = L'\0';
 523                 ptr1 = name;
 524             }
 525         }
 526     } else {
 527         fontStr = (*env)->NewString(env, name, wcslen(name));
 528         fontStr = (*env)->CallObjectMethod(env, fontStr,
 529                                            fmi->toLowerCaseMID, fmi->locale);
 530         (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
 531                                  fontStr, fileStr);
 532     }
 533 }
 534 
 535 /* Obtain all the fontname -> filename mappings.
 536  * This is called once and the results returned to Java code which can
 537  * use it for lookups to reduce or avoid the need to search font files.
 538  */
 539 JNIEXPORT void JNICALL
 540 Java_sun_awt_Win32FontManager_populateFontFileNameMap0
 541 (JNIEnv *env, jclass obj, jobject fontToFileMap,
 542  jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
 543 {
 544 #define MAX_BUFFER (FILENAME_MAX+1)
 545     const wchar_t wname[MAX_BUFFER];
 546     const char cname[MAX_BUFFER];
 547     const char data[MAX_BUFFER];
 548 
 549     DWORD type;
 550     LONG ret;
 551     HKEY hkeyFonts;
 552     DWORD dwNameSize;
 553     DWORD dwDataValueSize;
 554     DWORD nval;
 555     LPCSTR fontKeyName;
 556     DWORD dwNumValues, dwMaxValueNameLen, dwMaxValueDataLen;
 557     DWORD numValues = 0;
 558     jclass classID;
 559     jmethodID putMID;
 560     GdiFontMapInfo fmi;