jdk/src/java.desktop/windows/native/libfontmanager/fontpath.c
author clanger
Thu, 04 Aug 2016 15:58:28 +0200
changeset 40423 6b56a2890514
parent 39874 bf85c2b8f0e0
permissions -rw-r--r--
8163177: Fix for 8152971 breaks builds with VS2010 Reviewed-by: simonis, pnarayanan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <jni_util.h>
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1716
diff changeset
    31
#include <sun_awt_Win32FontManager.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define BSIZE (max(512, MAX_PATH+1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    35
/* Typically all local references held by a JNI function are automatically
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    36
 * released by JVM when the function returns. However, there is a limit to the
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    37
 * number of local references that can remain active. If the local references
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    38
 * continue to grow, it could result in out of memory error. Henceforth, we
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    39
 * invoke DeleteLocalRef on objects that are no longer needed for execution in
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    40
 * the JNI function.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    41
 */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    42
#define DeleteLocalReference(env, jniRef) \
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    43
    do { \
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    44
        if (jniRef != NULL) { \
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    45
            (*env)->DeleteLocalRef(env, jniRef); \
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    46
            jniRef = NULL; \
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    47
        } \
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
    48
    } while (0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1716
diff changeset
    50
JNIEXPORT jstring JNICALL Java_sun_awt_Win32FontManager_getFontPath(JNIEnv *env, jobject thiz, jboolean noType1)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    char windir[BSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    char sysdir[BSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    char fontpath[BSIZE*2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    char *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* Locate fonts directories relative to the Windows System directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * If Windows System location is different than the user's window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * directory location, as in a shared Windows installation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * return both locations as potential font directories
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    GetSystemDirectory(sysdir, BSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    end = strrchr(sysdir,'\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    if (end && (stricmp(end,"\\System") || stricmp(end,"\\System32"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        *end = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         strcat(sysdir, "\\Fonts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    GetWindowsDirectory(windir, BSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    if (strlen(windir) > BSIZE-7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        *windir = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        strcat(windir, "\\Fonts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    strcpy(fontpath,sysdir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    if (stricmp(sysdir,windir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        strcat(fontpath,";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        strcat(fontpath,windir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    return JNU_NewStringPlatform(env, fontpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/* The code below is used to obtain information from the windows font APIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * and registry on which fonts are available and what font files hold those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * fonts. The results are used to speed font lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
typedef struct GdiFontMapInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    jstring family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jobject fontToFamilyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    jobject familyToFontListMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    jobject list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    jmethodID putMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    jmethodID containsKeyMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    jclass arrayListClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    jmethodID arrayListCtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    jmethodID addMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jmethodID toLowerCaseMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    jobject locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
} GdiFontMapInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   105
/* Registry entry for fonts */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
static const char FONTKEY_NT[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
typedef struct CheckFamilyInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  wchar_t *family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  wchar_t* fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  int isDifferent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
} CheckFamilyInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
static int CALLBACK CheckFontFamilyProcW(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  ENUMLOGFONTEXW *lpelfe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  NEWTEXTMETRICEX *lpntme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  int FontType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    CheckFamilyInfo *info = (CheckFamilyInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    info->isDifferent = wcscmp(lpelfe->elfLogFont.lfFaceName, info->family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
/*     if (!info->isDifferent) { */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
/*         wprintf(LFor font %s expected family=%s instead got %s\n", */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
/*                 lpelfe->elfFullName, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
/*                 info->family, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
/*                 lpelfe->elfLogFont.lfFaceName); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
/*         fflush(stdout); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
/*     } */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   134
/* This HDC is initialised and released in the populate family map
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   135
 * JNI entry point, and used within the call which would otherwise
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   136
 * create many DCs.
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   137
 */
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   138
static HDC screenDC = NULL;
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   139
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
static int DifferentFamily(wchar_t *family, wchar_t* fullName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    LOGFONTW lfw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    CheckFamilyInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /* If fullName can't be stored in the struct, assume correct family */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    if (wcslen((LPWSTR)fullName) >= LF_FACESIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    memset(&info, 0, sizeof(CheckFamilyInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    info.family = family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    info.fullName = fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    info.isDifferent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    memset(&lfw, 0, sizeof(lfw));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    wcscpy(lfw.lfFaceName, fullName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    lfw.lfCharSet = DEFAULT_CHARSET;
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   157
    EnumFontFamiliesExW(screenDC, &lfw,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        (FONTENUMPROCW)CheckFontFamilyProcW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        (LPARAM)(&info), 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return info.isDifferent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   164
/* Callback for call to EnumFontFamiliesEx in the EnumFamilyNames function.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   165
 * Expects to be called once for each face name in the family specified
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   166
 * in the call. We extract the full name for the font which is expected
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   167
 * to be in the "system encoding" and create canonical and lower case
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   168
 * Java strings for the name which are added to the maps. The lower case
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   169
 * name is used as key to the family name value in the font to family map,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   170
 * the canonical name is one of the"list" of members of the family.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   171
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
static int CALLBACK EnumFontFacesInFamilyProcW(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  ENUMLOGFONTEXW *lpelfe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  NEWTEXTMETRICEX *lpntme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  int FontType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    GdiFontMapInfo *fmi = (GdiFontMapInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    jstring fullname, fullnameLC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   182
    /* Exceptions indicate critical errors such that program cannot continue
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   183
     * with further execution. Henceforth, the function returns immediately
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   184
     * on pending exceptions. In these situations, the function also returns
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   185
     * 0 indicating windows API to stop further enumeration and callbacks.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   186
     *
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   187
     * The JNI functions do not clear the pending exceptions. This allows the
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   188
     * caller (Java code) to check and handle exceptions in the best possible
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   189
     * way.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   190
     */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   191
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   192
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   193
    }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   194
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   195
    /* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   196
    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /* Windows has font aliases and so may enumerate fonts from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * the aliased family if any actual font of that family is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * To protect against it ignore fonts which aren't enumerated under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * their true family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    if (DifferentFamily(lpelfe->elfLogFont.lfFaceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        lpelfe->elfFullName))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    fullname = (*env)->NewString(env, lpelfe->elfFullName,
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   211
                                 (jsize)wcslen((LPWSTR)lpelfe->elfFullName));
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   212
    if (fullname == NULL) {
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   213
        (*env)->ExceptionClear(env);
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   214
        return 1;
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   215
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   216
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   217
    (*env)->CallBooleanMethod(env, fmi->list, fmi->addMID, fullname);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   218
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   219
        /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   220
        DeleteLocalReference(env, fullname);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   221
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   222
    }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   223
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    fullnameLC = (*env)->CallObjectMethod(env, fullname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                          fmi->toLowerCaseMID, fmi->locale);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   226
    /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   227
    DeleteLocalReference(env, fullname);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   228
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   229
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   230
    }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   231
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    (*env)->CallObjectMethod(env, fmi->fontToFamilyMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                             fmi->putMID, fullnameLC, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   234
    /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   235
    DeleteLocalReference(env, fullnameLC);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   236
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   237
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   238
    }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   239
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
/* Callback for EnumFontFamiliesEx in populateFontFileNameMap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * Expects to be called for every charset of every font family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * If this is the first time we have been called for this family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * add a new mapping to the familyToFontListMap from this family to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * list of its members. To populate that list, further enumerate all faces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * in this family for the matched charset. This assumes that all fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * in a family support the same charset, which is a fairly safe assumption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * and saves time as the call we make here to EnumFontFamiliesEx will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * enumerate the members of this family just once each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * Because we set fmi->list to be the newly created list the call back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * can safely add to that list without a search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
static int CALLBACK EnumFamilyNamesW(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  ENUMLOGFONTEXW *lpelfe,    /* pointer to logical-font data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  NEWTEXTMETRICEX *lpntme,  /* pointer to physical-font data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  int FontType,             /* type of font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  LPARAM lParam )           /* application-defined data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    GdiFontMapInfo *fmi = (GdiFontMapInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    jstring familyLC;
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   264
    size_t slen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    LOGFONTW lfw;
40423
6b56a2890514 8163177: Fix for 8152971 breaks builds with VS2010
clanger
parents: 39874
diff changeset
   266
    jboolean mapHasKey;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   268
    /* Exceptions indicate critical errors such that program cannot continue
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   269
     * with further execution. Henceforth, the function returns immediately
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   270
     * on pending exceptions. In these situations, the function also returns
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   271
     * 0 indicating windows API to stop further enumeration and callbacks.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   272
     *
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   273
     * The JNI functions do not clear the pending exceptions. This allows the
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   274
     * caller (Java code) to check and handle exceptions in the best possible
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   275
     * way.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   276
     */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   277
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   278
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   279
    }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   280
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   281
    /* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   282
    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
/*     wprintf(L"FAMILY=%s charset=%d FULL=%s\n", */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
/*          lpelfe->elfLogFont.lfFaceName, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
/*          lpelfe->elfLogFont.lfCharSet, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
/*          lpelfe->elfFullName); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
/*     fflush(stdout); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /* Windows lists fonts which have a vmtx (vertical metrics) table twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Once using their normal name, and again preceded by '@'. These appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * in font lists in some windows apps, such as wordpad. We don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * these so we skip any font where the first character is '@'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    if (lpelfe->elfLogFont.lfFaceName[0] == L'@') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    slen = wcslen(lpelfe->elfLogFont.lfFaceName);
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   300
    fmi->family = (*env)->NewString(env,lpelfe->elfLogFont.lfFaceName, (jsize)slen);
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   301
    if (fmi->family == NULL) {
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   302
        (*env)->ExceptionClear(env);
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   303
        return 1;
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   304
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   305
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    familyLC = (*env)->CallObjectMethod(env, fmi->family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                        fmi->toLowerCaseMID, fmi->locale);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   308
    /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   309
    if ((*env)->ExceptionCheck(env)) {
39874
bf85c2b8f0e0 8162097: [PIT] A series of closed tests about SunFontManager throw NPE on Windows
prr
parents: 39864
diff changeset
   310
        DeleteLocalReference(env, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   311
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   312
    }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   313
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /* check if already seen this family with a different charset */
40423
6b56a2890514 8163177: Fix for 8152971 breaks builds with VS2010
clanger
parents: 39874
diff changeset
   315
    mapHasKey = (*env)->CallBooleanMethod(env,
6b56a2890514 8163177: Fix for 8152971 breaks builds with VS2010
clanger
parents: 39874
diff changeset
   316
                                          fmi->familyToFontListMap,
6b56a2890514 8163177: Fix for 8152971 breaks builds with VS2010
clanger
parents: 39874
diff changeset
   317
                                          fmi->containsKeyMID,
6b56a2890514 8163177: Fix for 8152971 breaks builds with VS2010
clanger
parents: 39874
diff changeset
   318
                                          familyLC);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   319
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   320
        /* Delete the created references before return */
39874
bf85c2b8f0e0 8162097: [PIT] A series of closed tests about SunFontManager throw NPE on Windows
prr
parents: 39864
diff changeset
   321
        DeleteLocalReference(env, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   322
        DeleteLocalReference(env, familyLC);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   323
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   324
    } else if (mapHasKey) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   325
        /* Delete the created references before return */
39874
bf85c2b8f0e0 8162097: [PIT] A series of closed tests about SunFontManager throw NPE on Windows
prr
parents: 39864
diff changeset
   326
        DeleteLocalReference(env, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   327
        DeleteLocalReference(env, familyLC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   330
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    fmi->list = (*env)->NewObject(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                  fmi->arrayListClass, fmi->arrayListCtr, 4);
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   333
    if (fmi->list == NULL) {
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   334
        /* Delete the created references before return */
39874
bf85c2b8f0e0 8162097: [PIT] A series of closed tests about SunFontManager throw NPE on Windows
prr
parents: 39864
diff changeset
   335
        DeleteLocalReference(env, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   336
        DeleteLocalReference(env, familyLC);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   337
        return 0;
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   338
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   339
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    (*env)->CallObjectMethod(env, fmi->familyToFontListMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                             fmi->putMID, familyLC, fmi->list);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   342
    /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   343
    DeleteLocalReference(env, familyLC);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   344
    if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   345
        /* Delete the created reference before return */
39874
bf85c2b8f0e0 8162097: [PIT] A series of closed tests about SunFontManager throw NPE on Windows
prr
parents: 39864
diff changeset
   346
        DeleteLocalReference(env, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   347
        DeleteLocalReference(env, fmi->list);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   348
        return 0;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   349
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    memset(&lfw, 0, sizeof(lfw));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    wcscpy(lfw.lfFaceName, lpelfe->elfLogFont.lfFaceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    lfw.lfCharSet = lpelfe->elfLogFont.lfCharSet;
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   354
    EnumFontFamiliesExW(screenDC, &lfw,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        (FONTENUMPROCW)EnumFontFacesInFamilyProcW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        lParam, 0L);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   357
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   358
    /* Delete the created reference after its usage in the enum function */
39874
bf85c2b8f0e0 8162097: [PIT] A series of closed tests about SunFontManager throw NPE on Windows
prr
parents: 39864
diff changeset
   359
    DeleteLocalReference(env, fmi->family);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   360
    DeleteLocalReference(env, fmi->list);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
/* It looks like TrueType fonts have " (TrueType)" tacked on the end of their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * name, so we can try to use that to distinguish TT from other fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * However if a program "installed" a font in the registry the key may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * not include that. We could also try to "pass" fonts which have no "(..)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * at the end. But that turns out to pass a few .FON files that MS supply.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 11653
diff changeset
   369
 * If there's no parenthesized type string, we could next try to infer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 * the file type from the file name extension. Since the MS entries that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 * have no type string are very few, and have odd names like "MS-DOS CP 437"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
 * and would never return a Java Font anyway its currently OK to put these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
 * in the font map, although clearly the returned names must never percolate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 * up into a list of available fonts returned to the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * Additionally for TTC font files the key looks like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * Font 1 & Font 2 (TrueType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 * or sometimes even :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
 * Font 1 & Font 2 & Font 3 (TrueType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
 * Also if a Font has a name for this locale that name also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 * exists in the registry using the appropriate platform encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 * What do we do then?
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   382
 *
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   383
 * Note: OpenType fonts seems to have " (TrueType)" suffix on Vista
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   384
 *   but " (OpenType)" on XP.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
static BOOL RegistryToBaseTTNameW(LPWSTR name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    static const wchar_t TTSUFFIX[] = L" (TrueType)";
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   388
    static const wchar_t OTSUFFIX[] = L" (OpenType)";
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   389
    size_t TTSLEN = wcslen(TTSUFFIX);
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   390
    wchar_t *suffix;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   392
    size_t len = wcslen(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if (name[len-1] != L')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    if (len <= TTSLEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   402
    /* suffix length is the same for truetype and opentype fonts */
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   403
    suffix = name + (len - TTSLEN);
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   404
    if (wcscmp(suffix, TTSUFFIX) == 0 || wcscmp(suffix, OTSUFFIX) == 0) {
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   405
        suffix[0] = L'\0'; /* truncate name */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   408
    return FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
static void registerFontW(GdiFontMapInfo *fmi, jobject fontToFileMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                          LPWSTR name, LPWSTR data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    wchar_t *ptr1, *ptr2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    jstring fontStr;
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   416
    jstring fontStrLC;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    JNIEnv *env = fmi->env;
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   418
    size_t dslen = wcslen(data);
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   419
    jstring fileStr = (*env)->NewString(env, data, (jsize)dslen);
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   420
    if (fileStr == NULL) {
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   421
        (*env)->ExceptionClear(env);
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   422
        return;
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   423
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /* TTC or ttc means it may be a collection. Need to parse out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * multiple font face names separated by " & "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * By only doing this for fonts which look like collections based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * file name we are adhering to MS recommendations for font file names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * so it seems that we can be sure that this identifies precisely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * the MS-supplied truetype collections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * This avoids any potential issues if a TTF file happens to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * a & in the font name (I can't find anything which prohibits this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * and also means we only parse the key in cases we know to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * worthwhile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    if ((data[dslen-1] == L'C' || data[dslen-1] == L'c') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        (ptr1 = wcsstr(name, L" & ")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        ptr1+=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        while (ptr1 >= name) { /* marginally safer than while (true) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            while ((ptr2 = wcsstr(ptr1, L" & ")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                ptr1 = ptr2+3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   444
            fontStr = (*env)->NewString(env, ptr1, (jsize)wcslen(ptr1));
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   445
            if (fontStr == NULL) {
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   446
                (*env)->ExceptionClear(env);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   447
                /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   448
                DeleteLocalReference(env, fileStr);
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   449
                return;
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   450
            }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   451
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   452
            fontStrLC = (*env)->CallObjectMethod(env, fontStr,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   453
                                                 fmi->toLowerCaseMID,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   454
                                                 fmi->locale);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   455
            /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   456
            DeleteLocalReference(env, fontStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   457
            if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   458
                /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   459
                DeleteLocalReference(env, fileStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   460
                return;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   461
            }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   462
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   464
                                     fontStrLC, fileStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   465
            /* Delete the reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   466
            DeleteLocalReference(env, fontStrLC);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   467
            if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   468
                /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   469
                DeleteLocalReference(env, fileStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   470
                return;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   471
            }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   472
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (ptr1 == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                *(ptr1-3) = L'\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                ptr1 = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    } else {
9460
2957bb8932db 6989724: font warnings in the build, native code
jgodinez
parents: 7668
diff changeset
   481
        fontStr = (*env)->NewString(env, name, (jsize)wcslen(name));
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   482
        if (fontStr == NULL) {
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   483
            (*env)->ExceptionClear(env);
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   484
            /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   485
            DeleteLocalReference(env, fileStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   486
            return;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   487
        }
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   488
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   489
        fontStrLC = (*env)->CallObjectMethod(env, fontStr,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   490
                                           fmi->toLowerCaseMID, fmi->locale);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   491
        /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   492
        DeleteLocalReference(env, fontStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   493
        if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   494
            /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   495
            DeleteLocalReference(env, fileStr);
23674
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   496
            return;
47a4a6183907 8035630: [parfait] JNI exception pending in jdk/src/windows/native/sun/font/fontpath.c
prr
parents: 23010
diff changeset
   497
        }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   498
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   500
                                 fontStrLC, fileStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   501
        /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   502
        DeleteLocalReference(env, fontStrLC);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   503
        if ((*env)->ExceptionCheck(env)) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   504
            /* Delete the created reference before return */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   505
            DeleteLocalReference(env, fileStr);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   506
            return;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   507
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   509
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   510
    /* Delete the created reference after its usage */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   511
    DeleteLocalReference(env, fileStr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
/* Obtain all the fontname -> filename mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
 * This is called once and the results returned to Java code which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
 * use it for lookups to reduce or avoid the need to search font files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
JNIEXPORT void JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1716
diff changeset
   519
Java_sun_awt_Win32FontManager_populateFontFileNameMap0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
(JNIEnv *env, jclass obj, jobject fontToFileMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
 jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
#define MAX_BUFFER (FILENAME_MAX+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    const wchar_t wname[MAX_BUFFER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    const char data[MAX_BUFFER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    DWORD type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    HKEY hkeyFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    DWORD dwNameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    DWORD dwDataValueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    DWORD nval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    DWORD dwNumValues, dwMaxValueNameLen, dwMaxValueDataLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    DWORD numValues = 0;
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   535
    jclass classIDHashMap;
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   536
    jclass classIDString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    jmethodID putMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    GdiFontMapInfo fmi;
40423
6b56a2890514 8163177: Fix for 8152971 breaks builds with VS2010
clanger
parents: 39874
diff changeset
   539
    LOGFONTW lfw;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /* Check we were passed all the maps we need, and do lookup of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * methods for JNI up-calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    if (fontToFileMap == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        fontToFamilyMap == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        familyToFontListMap == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   549
    classIDHashMap = (*env)->FindClass(env, "java/util/HashMap");
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   550
    if (classIDHashMap == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   553
    putMID = (*env)->GetMethodID(env, classIDHashMap, "put",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                 "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    if (putMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    fmi.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    fmi.fontToFamilyMap = fontToFamilyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    fmi.familyToFontListMap = familyToFontListMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    fmi.putMID = putMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    fmi.locale = locale;
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   564
    fmi.containsKeyMID = (*env)->GetMethodID(env, classIDHashMap,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   565
                                             "containsKey",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                             "(Ljava/lang/Object;)Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    if (fmi.containsKeyMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    fmi.arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    if (fmi.arrayListClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    fmi.arrayListCtr = (*env)->GetMethodID(env, fmi.arrayListClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                              "<init>", "(I)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    if (fmi.arrayListCtr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    fmi.addMID = (*env)->GetMethodID(env, fmi.arrayListClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                     "add", "(Ljava/lang/Object;)Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    if (fmi.addMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   585
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   586
    classIDString = (*env)->FindClass(env, "java/lang/String");
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   587
    if (classIDString == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    fmi.toLowerCaseMID =
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   591
        (*env)->GetMethodID(env, classIDString, "toLowerCase",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                            "(Ljava/util/Locale;)Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    if (fmi.toLowerCaseMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   597
    screenDC = GetDC(NULL);
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   598
    if (screenDC == NULL) {
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   599
        return;
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   600
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   601
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    /* Enumerate fonts via GDI to build maps of fonts and families */
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   603
    memset(&lfw, 0, sizeof(lfw));
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   604
    lfw.lfCharSet = DEFAULT_CHARSET;  /* all charsets */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   605
    wcscpy(lfw.lfFaceName, L"");      /* one face per family (CHECK) */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   606
    EnumFontFamiliesExW(screenDC, &lfw,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   607
                        (FONTENUMPROCW)EnumFamilyNamesW,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   608
                        (LPARAM)(&fmi), 0L);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /* Use the windows registry to map font names to files */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   612
                       FONTKEY_NT, 0L, KEY_READ, &hkeyFonts);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    if (ret != ERROR_SUCCESS) {
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   614
        ReleaseDC(NULL, screenDC);
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   615
        screenDC = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   619
    ret = RegQueryInfoKeyW(hkeyFonts, NULL, NULL, NULL, NULL, NULL, NULL,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   620
                           &dwNumValues, &dwMaxValueNameLen,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   621
                           &dwMaxValueDataLen, NULL, NULL);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   622
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    if (ret != ERROR_SUCCESS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        dwMaxValueNameLen >= MAX_BUFFER ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        dwMaxValueDataLen >= MAX_BUFFER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        RegCloseKey(hkeyFonts);
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   627
        ReleaseDC(NULL, screenDC);
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   628
        screenDC = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    for (nval = 0; nval < dwNumValues; nval++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        dwNameSize = MAX_BUFFER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        dwDataValueSize = MAX_BUFFER;
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   634
        ret = RegEnumValueW(hkeyFonts, nval, (LPWSTR)wname, &dwNameSize,
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   635
                            NULL, &type, (LPBYTE)data, &dwDataValueSize);
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   636
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (type != REG_SZ) { /* REG_SZ means a null-terminated string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   643
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   644
        if (!RegistryToBaseTTNameW((LPWSTR)wname) ) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   645
            /* If the filename ends with ".ttf" or ".otf" also accept it.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   646
             * Not expecting to need to do this for .ttc files.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   647
             * Also note this code is not mirrored in the "A" (win9x) path.
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   648
             */
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   649
            LPWSTR dot = wcsrchr((LPWSTR)data, L'.');
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   650
            if (dot == NULL || ((wcsicmp(dot, L".ttf") != 0)
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   651
                                  && (wcsicmp(dot, L".otf") != 0))) {
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   652
                continue;  /* not a TT font... */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   655
        registerFontW(&fmi, fontToFileMap, (LPWSTR)wname, (LPWSTR)data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
39864
8b3ec2abf2b1 8152971: JNI Warning with -Xcheck:jni
pnarayanan
parents: 25859
diff changeset
   657
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    RegCloseKey(hkeyFonts);
11653
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   659
    ReleaseDC(NULL, screenDC);
65d57ea9c30a 7131153: GetDC called way too many times - causes bad performance.
prr
parents: 9460
diff changeset
   660
    screenDC = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
}