jdk/src/windows/native/sun/font/fontpath.c
author rkennke
Fri, 07 Aug 2009 18:31:11 +0200
changeset 3928 be186a33df9b
parent 1716 461122becab9
child 5506 202f599c92aa
permissions -rw-r--r--
6795908: Refactor FontManager Reviewed-by: prr, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1716
diff changeset
    36
JNIEXPORT jstring JNICALL Java_sun_awt_Win32FontManager_getFontPath(JNIEnv *env, jobject thiz, jboolean noType1)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    char windir[BSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    char sysdir[BSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    char fontpath[BSIZE*2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    char *end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /* Locate fonts directories relative to the Windows System directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * If Windows System location is different than the user's window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * directory location, as in a shared Windows installation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * return both locations as potential font directories
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    GetSystemDirectory(sysdir, BSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    end = strrchr(sysdir,'\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    if (end && (stricmp(end,"\\System") || stricmp(end,"\\System32"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        *end = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         strcat(sysdir, "\\Fonts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    GetWindowsDirectory(windir, BSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    if (strlen(windir) > BSIZE-7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        *windir = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        strcat(windir, "\\Fonts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    strcpy(fontpath,sysdir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if (stricmp(sysdir,windir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        strcat(fontpath,";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        strcat(fontpath,windir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    return JNU_NewStringPlatform(env, fontpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/* The code below is used to obtain information from the windows font APIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * and registry on which fonts are available and what font files hold those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * fonts. The results are used to speed font lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
typedef struct GdiFontMapInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    jstring family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    jobject fontToFamilyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    jobject familyToFontListMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    jobject list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    jmethodID putMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    jmethodID containsKeyMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    jclass arrayListClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    jmethodID arrayListCtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    jmethodID addMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    jmethodID toLowerCaseMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    jobject locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
} GdiFontMapInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/* IS_NT means NT or later OSes which support Unicode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * We have to painfully deal with the ASCII and non-ASCII case we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * we really want to get the font names as unicode wherever possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * UNICODE_OS is 0 to mean uninitialised, 1 to mean not a unicode OS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * 2 to mean a unicode OS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#define UC_UNKNOWN 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#define UC_NO     1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#define UC_YES    2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
static int UNICODE_OS = UC_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
static int GetOSVersion () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    OSVERSIONINFO vinfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    vinfo.dwOSVersionInfoSize = sizeof(vinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    GetVersionEx(&vinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    if ((int)vinfo.dwMajorVersion > 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        UNICODE_OS = UC_YES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    } else if ((int)vinfo.dwMajorVersion < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        UNICODE_OS = UC_NO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if ((int)vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            UNICODE_OS = UC_NO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            UNICODE_OS = UC_YES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return UNICODE_OS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#define IS_NT ((UNICODE_OS == UC_UNKNOWN) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   ? (GetOSVersion() == UC_YES) : (UNICODE_OS == UC_YES))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
/* NT is W2K & XP. WIN is Win9x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
static const char FONTKEY_NT[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
static const char FONTKEY_WIN[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    "Software\\Microsoft\\Windows\\CurrentVersion\\Fonts";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
/* Callback for call to EnumFontFamiliesEx in the EnumFamilyNames function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * Expects to be called once for each face name in the family specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * in the call. We extract the full name for the font which is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * to be in the "system encoding" and create canonical and lower case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * Java strings for the name which are added to the maps. The lower case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * name is used as key to the family name value in the font to family map,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * the canonical name is one of the"list" of members of the family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
static int CALLBACK EnumFontFacesInFamilyProcA(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  ENUMLOGFONTEXA *lpelfe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  NEWTEXTMETRICEX *lpntme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  int FontType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  LPARAM lParam )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    GdiFontMapInfo *fmi = (GdiFontMapInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    jstring fullname, fullnameLC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   147
    /* 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
   148
    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /* printf("FULL=%s\n",lpelfe->elfFullName);fflush(stdout);  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    fullname = JNU_NewStringPlatform(env, lpelfe->elfFullName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    fullnameLC = (*env)->CallObjectMethod(env, fullname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                          fmi->toLowerCaseMID, fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    (*env)->CallObjectMethod(env, fmi->list, fmi->addMID, fullname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    (*env)->CallObjectMethod(env, fmi->fontToFamilyMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                             fmi->putMID, fullnameLC, fmi->family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
typedef struct CheckFamilyInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  wchar_t *family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  wchar_t* fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  int isDifferent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
} CheckFamilyInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
static int CALLBACK CheckFontFamilyProcW(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  ENUMLOGFONTEXW *lpelfe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  NEWTEXTMETRICEX *lpntme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
  int FontType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    CheckFamilyInfo *info = (CheckFamilyInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    info->isDifferent = wcscmp(lpelfe->elfLogFont.lfFaceName, info->family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
/*     if (!info->isDifferent) { */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
/*         wprintf(LFor font %s expected family=%s instead got %s\n", */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
/*                 lpelfe->elfFullName, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
/*                 info->family, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
/*                 lpelfe->elfLogFont.lfFaceName); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
/*         fflush(stdout); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
/*     } */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
static int DifferentFamily(wchar_t *family, wchar_t* fullName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    LOGFONTW lfw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    CheckFamilyInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /* If fullName can't be stored in the struct, assume correct family */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    if (wcslen((LPWSTR)fullName) >= LF_FACESIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    memset(&info, 0, sizeof(CheckFamilyInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    info.family = family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    info.fullName = fullName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    info.isDifferent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    memset(&lfw, 0, sizeof(lfw));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    wcscpy(lfw.lfFaceName, fullName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    lfw.lfCharSet = DEFAULT_CHARSET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    EnumFontFamiliesExW(GetDC(NULL), &lfw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        (FONTENUMPROCW)CheckFontFamilyProcW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        (LPARAM)(&info), 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    return info.isDifferent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
static int CALLBACK EnumFontFacesInFamilyProcW(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  ENUMLOGFONTEXW *lpelfe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  NEWTEXTMETRICEX *lpntme,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  int FontType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    GdiFontMapInfo *fmi = (GdiFontMapInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    jstring fullname, fullnameLC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   222
    /* 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
   223
    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /* Windows has font aliases and so may enumerate fonts from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * the aliased family if any actual font of that family is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * To protect against it ignore fonts which aren't enumerated under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * their true family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (DifferentFamily(lpelfe->elfLogFont.lfFaceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        lpelfe->elfFullName))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    fullname = (*env)->NewString(env, lpelfe->elfFullName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                 wcslen((LPWSTR)lpelfe->elfFullName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    fullnameLC = (*env)->CallObjectMethod(env, fullname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                          fmi->toLowerCaseMID, fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    (*env)->CallObjectMethod(env, fmi->list, fmi->addMID, fullname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    (*env)->CallObjectMethod(env, fmi->fontToFamilyMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                             fmi->putMID, fullnameLC, fmi->family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
/* Callback for EnumFontFamiliesEx in populateFontFileNameMap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * Expects to be called for every charset of every font family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * If this is the first time we have been called for this family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * add a new mapping to the familyToFontListMap from this family to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * list of its members. To populate that list, further enumerate all faces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * in this family for the matched charset. This assumes that all fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * in a family support the same charset, which is a fairly safe assumption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * and saves time as the call we make here to EnumFontFamiliesEx will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * enumerate the members of this family just once each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * Because we set fmi->list to be the newly created list the call back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * can safely add to that list without a search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
static int CALLBACK EnumFamilyNamesA(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  ENUMLOGFONTEXA *lpelfe,    /* pointer to logical-font data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  NEWTEXTMETRICEX *lpntme,   /* pointer to physical-font data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  int FontType,              /* type of font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
  LPARAM lParam)             /* application-defined data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    GdiFontMapInfo *fmi = (GdiFontMapInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    jstring familyLC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    LOGFONTA lfa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   270
    /* 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
   271
    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /* Windows lists fonts which have a vmtx (vertical metrics) table twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Once using their normal name, and again preceded by '@'. These appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * in font lists in some windows apps, such as wordpad. We don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * these so we skip any font where the first character is '@'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    if (lpelfe->elfLogFont.lfFaceName[0] == '@') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    fmi->family = JNU_NewStringPlatform(env,lpelfe->elfLogFont.lfFaceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    familyLC = (*env)->CallObjectMethod(env, fmi->family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                        fmi->toLowerCaseMID, fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /* check if already seen this family with a different charset */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    if ((*env)->CallBooleanMethod(env,fmi->familyToFontListMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                  fmi->containsKeyMID, familyLC)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    fmi->list = (*env)->NewObject(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                  fmi->arrayListClass, fmi->arrayListCtr, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    (*env)->CallObjectMethod(env, fmi->familyToFontListMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                             fmi->putMID, familyLC, fmi->list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
/*  printf("FAMILY=%s\n", lpelfe->elfLogFont.lfFaceName);fflush(stdout); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    memset(&lfa, 0, sizeof(lfa));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    strcpy(lfa.lfFaceName, lpelfe->elfLogFont.lfFaceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    lfa.lfCharSet = lpelfe->elfLogFont.lfCharSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    EnumFontFamiliesExA(GetDC(NULL), &lfa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        (FONTENUMPROCA)EnumFontFacesInFamilyProcA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                        lParam, 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
static int CALLBACK EnumFamilyNamesW(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  ENUMLOGFONTEXW *lpelfe,    /* pointer to logical-font data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
  NEWTEXTMETRICEX *lpntme,  /* pointer to physical-font data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
  int FontType,             /* type of font */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  LPARAM lParam )           /* application-defined data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    GdiFontMapInfo *fmi = (GdiFontMapInfo*)lParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    jstring familyLC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    int slen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    LOGFONTW lfw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   320
    /* 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
   321
    if (FontType != TRUETYPE_FONTTYPE && FontType != DEVICE_FONTTYPE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
/*     wprintf(L"FAMILY=%s charset=%d FULL=%s\n", */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
/*          lpelfe->elfLogFont.lfFaceName, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
/*          lpelfe->elfLogFont.lfCharSet, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
/*          lpelfe->elfFullName); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
/*     fflush(stdout); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /* Windows lists fonts which have a vmtx (vertical metrics) table twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Once using their normal name, and again preceded by '@'. These appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * in font lists in some windows apps, such as wordpad. We don't want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * these so we skip any font where the first character is '@'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    if (lpelfe->elfLogFont.lfFaceName[0] == L'@') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    slen = wcslen(lpelfe->elfLogFont.lfFaceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    fmi->family = (*env)->NewString(env,lpelfe->elfLogFont.lfFaceName, slen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    familyLC = (*env)->CallObjectMethod(env, fmi->family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                        fmi->toLowerCaseMID, fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /* check if already seen this family with a different charset */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    if ((*env)->CallBooleanMethod(env,fmi->familyToFontListMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                  fmi->containsKeyMID, familyLC)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    fmi->list = (*env)->NewObject(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                  fmi->arrayListClass, fmi->arrayListCtr, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    (*env)->CallObjectMethod(env, fmi->familyToFontListMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                             fmi->putMID, familyLC, fmi->list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    memset(&lfw, 0, sizeof(lfw));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    wcscpy(lfw.lfFaceName, lpelfe->elfLogFont.lfFaceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    lfw.lfCharSet = lpelfe->elfLogFont.lfCharSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    EnumFontFamiliesExW(GetDC(NULL), &lfw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        (FONTENUMPROCW)EnumFontFacesInFamilyProcW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        lParam, 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
/* It looks like TrueType fonts have " (TrueType)" tacked on the end of their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 * name, so we can try to use that to distinguish TT from other fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * However if a program "installed" a font in the registry the key may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * not include that. We could also try to "pass" fonts which have no "(..)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * at the end. But that turns out to pass a few .FON files that MS supply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * If there's no parenthesised type string, we could next try to infer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * the file type from the file name extension. Since the MS entries that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 * have no type string are very few, and have odd names like "MS-DOS CP 437"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 * and would never return a Java Font anyway its currently OK to put these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
 * in the font map, although clearly the returned names must never percolate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
 * up into a list of available fonts returned to the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 * Additionally for TTC font files the key looks like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * Font 1 & Font 2 (TrueType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * or sometimes even :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 * Font 1 & Font 2 & Font 3 (TrueType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
 * Also if a Font has a name for this locale that name also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
 * exists in the registry using the appropriate platform encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 * What do we do then?
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   381
 *
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   382
 * 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
   383
 *   but " (OpenType)" on XP.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   386
static BOOL RegistryToBaseTTNameA(LPSTR name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    static const char TTSUFFIX[] = " (TrueType)";
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   388
    static const char OTSUFFIX[] = " (OpenType)";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    int TTSLEN = strlen(TTSUFFIX);
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   390
    char *suffix;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    int len = strlen(name);
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] != ')') {
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
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   403
    /* 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
   404
    suffix = name + len - TTSLEN;
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   405
    if (strcmp(suffix, TTSUFFIX) == 0 || strcmp(suffix, OTSUFFIX) == 0) {
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   406
        suffix[0] = '\0'; /* truncate name */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   409
    return FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
static BOOL RegistryToBaseTTNameW(LPWSTR name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    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
   414
    static const wchar_t OTSUFFIX[] = L" (OpenType)";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    int TTSLEN = wcslen(TTSUFFIX);
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   416
    wchar_t *suffix;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    int len = wcslen(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    if (name[len-1] != L')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    if (len <= TTSLEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   428
    /* 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
   429
    suffix = name + (len - TTSLEN);
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   430
    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
   431
        suffix[0] = L'\0'; /* truncate name */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   434
    return FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
static void registerFontA(GdiFontMapInfo *fmi, jobject fontToFileMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                          LPCSTR name, LPCSTR data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    LPSTR ptr1, ptr2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    jstring fontStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    int dslen = strlen(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    jstring fileStr = JNU_NewStringPlatform(env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /* TTC or ttc means it may be a collection. Need to parse out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * multiple font face names separated by " & "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * By only doing this for fonts which look like collections based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * file name we are adhering to MS recommendations for font file names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * so it seems that we can be sure that this identifies precisely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * the MS-supplied truetype collections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * This avoids any potential issues if a TTF file happens to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * a & in the font name (I can't find anything which prohibits this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * and also means we only parse the key in cases we know to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * worthwhile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    if ((data[dslen-1] == 'C' || data[dslen-1] == 'c') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        (ptr1 = strstr(name, " & ")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        ptr1+=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        while (ptr1 >= name) { /* marginally safer than while (true) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            while ((ptr2 = strstr(ptr1, " & ")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    ptr1 = ptr2+3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            fontStr = JNU_NewStringPlatform(env, ptr1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            fontStr = (*env)->CallObjectMethod(env, fontStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                               fmi->toLowerCaseMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                               fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                     fontStr, fileStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            if (ptr1 == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                *(ptr1-3) ='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                ptr1 = (LPSTR)name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        fontStr = JNU_NewStringPlatform(env, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        fontStr = (*env)->CallObjectMethod(env, fontStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                                           fmi->toLowerCaseMID, fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                 fontStr, fileStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
static void registerFontW(GdiFontMapInfo *fmi, jobject fontToFileMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                          LPWSTR name, LPWSTR data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    wchar_t *ptr1, *ptr2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    jstring fontStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    JNIEnv *env = fmi->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    int dslen = wcslen(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    jstring fileStr = (*env)->NewString(env, data, dslen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /* TTC or ttc means it may be a collection. Need to parse out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * multiple font face names separated by " & "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * By only doing this for fonts which look like collections based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * file name we are adhering to MS recommendations for font file names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * so it seems that we can be sure that this identifies precisely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * the MS-supplied truetype collections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * This avoids any potential issues if a TTF file happens to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * a & in the font name (I can't find anything which prohibits this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * and also means we only parse the key in cases we know to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * worthwhile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    if ((data[dslen-1] == L'C' || data[dslen-1] == L'c') &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        (ptr1 = wcsstr(name, L" & ")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        ptr1+=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        while (ptr1 >= name) { /* marginally safer than while (true) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            while ((ptr2 = wcsstr(ptr1, L" & ")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                ptr1 = ptr2+3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            fontStr = (*env)->NewString(env, ptr1, wcslen(ptr1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            fontStr = (*env)->CallObjectMethod(env, fontStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                               fmi->toLowerCaseMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                               fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                     fontStr, fileStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if (ptr1 == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                *(ptr1-3) = L'\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                ptr1 = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        fontStr = (*env)->NewString(env, name, wcslen(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        fontStr = (*env)->CallObjectMethod(env, fontStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                           fmi->toLowerCaseMID, fmi->locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        (*env)->CallObjectMethod(env, fontToFileMap, fmi->putMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                 fontStr, fileStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
/* Obtain all the fontname -> filename mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
 * This is called once and the results returned to Java code which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
 * use it for lookups to reduce or avoid the need to search font files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
JNIEXPORT void JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 1716
diff changeset
   540
Java_sun_awt_Win32FontManager_populateFontFileNameMap0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
(JNIEnv *env, jclass obj, jobject fontToFileMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
 jobject fontToFamilyMap, jobject familyToFontListMap, jobject locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
#define MAX_BUFFER (FILENAME_MAX+1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    const wchar_t wname[MAX_BUFFER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    const char cname[MAX_BUFFER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    const char data[MAX_BUFFER];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    DWORD type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    LONG ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    HKEY hkeyFonts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    DWORD dwNameSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    DWORD dwDataValueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    DWORD nval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    LPCSTR fontKeyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    DWORD dwNumValues, dwMaxValueNameLen, dwMaxValueDataLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    DWORD numValues = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    jclass classID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    jmethodID putMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    GdiFontMapInfo fmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /* Check we were passed all the maps we need, and do lookup of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * methods for JNI up-calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    if (fontToFileMap == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        fontToFamilyMap == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        familyToFontListMap == 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
    classID = (*env)->FindClass(env, "java/util/HashMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    if (classID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    putMID = (*env)->GetMethodID(env, classID, "put",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                 "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    if (putMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    fmi.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    fmi.fontToFamilyMap = fontToFamilyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    fmi.familyToFontListMap = familyToFontListMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    fmi.putMID = putMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    fmi.locale = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    fmi.containsKeyMID = (*env)->GetMethodID(env, classID, "containsKey",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                             "(Ljava/lang/Object;)Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    if (fmi.containsKeyMID == NULL) {
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    fmi.arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    if (fmi.arrayListClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    fmi.arrayListCtr = (*env)->GetMethodID(env, fmi.arrayListClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                              "<init>", "(I)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    if (fmi.arrayListCtr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    fmi.addMID = (*env)->GetMethodID(env, fmi.arrayListClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                                     "add", "(Ljava/lang/Object;)Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    if (fmi.addMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    classID = (*env)->FindClass(env, "java/lang/String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    if (classID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    fmi.toLowerCaseMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        (*env)->GetMethodID(env, classID, "toLowerCase",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                            "(Ljava/util/Locale;)Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    if (fmi.toLowerCaseMID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /* Enumerate fonts via GDI to build maps of fonts and families */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    if (IS_NT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        LOGFONTW lfw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        memset(&lfw, 0, sizeof(lfw));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        lfw.lfCharSet = DEFAULT_CHARSET;  /* all charsets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        wcscpy(lfw.lfFaceName, L"");      /* one face per family (CHECK) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        EnumFontFamiliesExW(GetDC(NULL), &lfw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                            (FONTENUMPROCW)EnumFamilyNamesW,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                            (LPARAM)(&fmi), 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        LOGFONT lfa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        memset(&lfa, 0, sizeof(lfa));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        lfa.lfCharSet = DEFAULT_CHARSET; /* all charsets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        strcpy(lfa.lfFaceName, "");      /* one face per family */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        ret = EnumFontFamiliesExA(GetDC(NULL), &lfa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                            (FONTENUMPROCA)EnumFamilyNamesA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                            (LPARAM)(&fmi), 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /* Use the windows registry to map font names to files */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    fontKeyName = (IS_NT) ? FONTKEY_NT : FONTKEY_WIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                       fontKeyName, 0L, KEY_READ, &hkeyFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    if (IS_NT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        ret = RegQueryInfoKeyW(hkeyFonts, NULL, NULL, NULL, NULL, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                               &dwNumValues, &dwMaxValueNameLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                               &dwMaxValueDataLen, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        ret = RegQueryInfoKeyA(hkeyFonts, NULL, NULL, NULL, NULL, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                               &dwNumValues, &dwMaxValueNameLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                               &dwMaxValueDataLen, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    if (ret != ERROR_SUCCESS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        dwMaxValueNameLen >= MAX_BUFFER ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        dwMaxValueDataLen >= MAX_BUFFER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        RegCloseKey(hkeyFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    for (nval = 0; nval < dwNumValues; nval++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        dwNameSize = MAX_BUFFER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        dwDataValueSize = MAX_BUFFER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (IS_NT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            ret = RegEnumValueW(hkeyFonts, nval, (LPWSTR)wname, &dwNameSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                                NULL, &type, (LPBYTE)data, &dwDataValueSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            ret = RegEnumValueA(hkeyFonts, nval, (LPSTR)cname, &dwNameSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                                NULL, &type, (LPBYTE)data, &dwDataValueSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        if (ret != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (type != REG_SZ) { /* REG_SZ means a null-terminated string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (IS_NT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            if (!RegistryToBaseTTNameW((LPWSTR)wname) ) {
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   676
                /* If the filename ends with ".ttf" or ".otf" also accept it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                 * Not expecting to need to do this for .ttc files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                 * Also note this code is not mirrored in the "A" (win9x) path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                LPWSTR dot = wcsrchr((LPWSTR)data, L'.');
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   681
                if (dot == NULL || ((wcsicmp(dot, L".ttf") != 0)
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   682
                                      && (wcsicmp(dot, L".otf") != 0))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    continue;  /* not a TT font... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            registerFontW(&fmi, fontToFileMap, (LPWSTR)wname, (LPWSTR)data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        } else {
1716
461122becab9 4356282: RFE: T2K should be used to rasterize CID/CFF fonts
igor
parents: 2
diff changeset
   688
            if (!RegistryToBaseTTNameA((LPSTR)cname)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                continue; /* not a TT font... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            registerFontA(&fmi, fontToFileMap, cname, (LPCSTR)data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    RegCloseKey(hkeyFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
}