fontpath.c revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <windows.h>
#include <stdio.h>
#include <jni.h>
#include <jni_util.h>
#include <sun_awt_Win32FontManager.h>
JNIEXPORT jstring JNICALL Java_sun_awt_Win32FontManager_getFontPath(JNIEnv *env, jobject thiz, jboolean noType1)
{
char *end;
/* Locate fonts directories relative to the Windows System directory.
* If Windows System location is different than the user's window
* directory location, as in a shared Windows installation,
* return both locations as potential font directories
*/
*end = 0;
}
*windir = 0;
} else {
}
}
}
/* The code below is used to obtain information from the windows font APIS
* and registry on which fonts are available and what font files hold those
* fonts. The results are used to speed font lookup.
*/
typedef struct GdiFontMapInfo {
/* IS_NT means NT or later OSes which support Unicode.
* We have to painfully deal with the ASCII and non-ASCII case we
* we really want to get the font names as unicode wherever possible.
* UNICODE_OS is 0 to mean uninitialised, 1 to mean not a unicode OS,
* 2 to mean a unicode OS.
*/
#define UC_UNKNOWN 0
#define UC_NO 1
#define UC_YES 2
static int UNICODE_OS = UC_UNKNOWN;
static int GetOSVersion () {
UNICODE_OS = UC_YES;
UNICODE_OS = UC_NO;
} else {
UNICODE_OS = UC_NO;
} else {
UNICODE_OS = UC_YES;
}
}
return UNICODE_OS;
}
/* NT is W2K & XP. WIN is Win9x */
static const char FONTKEY_NT[] =
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
static const char FONTKEY_WIN[] =
"Software\\Microsoft\\Windows\\CurrentVersion\\Fonts";
/* Callback for call to EnumFontFamiliesEx in the EnumFamilyNames function.
* Expects to be called once for each face name in the family specified
* in the call. We extract the full name for the font which is expected
* to be in the "system encoding" and create canonical and lower case
* Java strings for the name which are added to the maps. The lower case
* name is used as key to the family name value in the font to family map,
* the canonical name is one of the"list" of members of the family.
*/
static int CALLBACK EnumFontFacesInFamilyProcA(
int FontType,
{
/* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
return 1;
}
/* printf("FULL=%s\n",lpelfe->elfFullName);fflush(stdout); */
return 1;
}
typedef struct CheckFamilyInfo {
int isDifferent;
static int CALLBACK CheckFontFamilyProcW(
int FontType,
{
/* if (!info->isDifferent) { */
/* wprintf(LFor font %s expected family=%s instead got %s\n", */
/* lpelfe->elfFullName, */
/* info->family, */
/* lpelfe->elfLogFont.lfFaceName); */
/* fflush(stdout); */
/* } */
return 0;
}
/* If fullName can't be stored in the struct, assume correct family */
return 0;
}
info.isDifferent = 0;
return info.isDifferent;
}
static int CALLBACK EnumFontFacesInFamilyProcW(
int FontType,
{
/* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
return 1;
}
/* Windows has font aliases and so may enumerate fonts from
* the aliased family if any actual font of that family is installed.
* To protect against it ignore fonts which aren't enumerated under
* their true family.
*/
lpelfe->elfFullName)) {
return 1;
}
return 1;
}
/* Callback for EnumFontFamiliesEx in populateFontFileNameMap.
* Expects to be called for every charset of every font family.
* If this is the first time we have been called for this family,
* add a new mapping to the familyToFontListMap from this family to a
* list of its members. To populate that list, further enumerate all faces
* in this family for the matched charset. This assumes that all fonts
* in a family support the same charset, which is a fairly safe assumption
* and saves time as the call we make here to EnumFontFamiliesEx will
* enumerate the members of this family just once each.
* Because we set fmi->list to be the newly created list the call back
* can safely add to that list without a search.
*/
static int CALLBACK EnumFamilyNamesA(
int FontType, /* type of font */
{
/* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
return 1;
}
/* Windows lists fonts which have a vmtx (vertical metrics) table twice.
* Once using their normal name, and again preceded by '@'. These appear
* in font lists in some windows apps, such as wordpad. We don't want
* these so we skip any font where the first character is '@'
*/
return 1;
}
/* check if already seen this family with a different charset */
return 1;
}
/* printf("FAMILY=%s\n", lpelfe->elfLogFont.lfFaceName);fflush(stdout); */
lParam, 0L);
return 1;
}
static int CALLBACK EnumFamilyNamesW(
int FontType, /* type of font */
{
int slen;
/* Both Vista and XP return DEVICE_FONTTYPE for OTF fonts */
return 1;
}
/* wprintf(L"FAMILY=%s charset=%d FULL=%s\n", */
/* lpelfe->elfLogFont.lfFaceName, */
/* lpelfe->elfLogFont.lfCharSet, */
/* lpelfe->elfFullName); */
/* fflush(stdout); */
/* Windows lists fonts which have a vmtx (vertical metrics) table twice.
* Once using their normal name, and again preceded by '@'. These appear
* in font lists in some windows apps, such as wordpad. We don't want
* these so we skip any font where the first character is '@'
*/
return 1;
}
/* check if already seen this family with a different charset */
return 1;
}
lParam, 0L);
return 1;
}
/* It looks like TrueType fonts have " (TrueType)" tacked on the end of their
* name, so we can try to use that to distinguish TT from other fonts.
* However if a program "installed" a font in the registry the key may
* not include that. We could also try to "pass" fonts which have no "(..)"
* at the end. But that turns out to pass a few .FON files that MS supply.
* If there's no parenthesised type string, we could next try to infer
* the file type from the file name extension. Since the MS entries that
* have no type string are very few, and have odd names like "MS-DOS CP 437"
* and would never return a Java Font anyway its currently OK to put these
* in the font map, although clearly the returned names must never percolate
* up into a list of available fonts returned to the application.
* Additionally for TTC font files the key looks like
* Font 1 & Font 2 (TrueType)
* or sometimes even :
* Font 1 & Font 2 & Font 3 (TrueType)
* Also if a Font has a name for this locale that name also
* exists in the registry using the appropriate platform encoding.
* What do we do then?
*
* Note: OpenType fonts seems to have " (TrueType)" suffix on Vista
* but " (OpenType)" on XP.
*/
static const char TTSUFFIX[] = " (TrueType)";
static const char OTSUFFIX[] = " (OpenType)";
char *suffix;
if (len == 0) {
return FALSE;
}
return FALSE;
}
return FALSE;
}
/* suffix length is the same for truetype and opentype fonts */
return TRUE;
}
return FALSE;
}
if (len == 0) {
return FALSE;
}
return FALSE;
}
return FALSE;
}
/* suffix length is the same for truetype and opentype fonts */
return TRUE;
}
return FALSE;
}
/* TTC or ttc means it may be a collection. Need to parse out
* multiple font face names separated by " & "
* By only doing this for fonts which look like collections based on
* file name we are adhering to MS recommendations for font file names
* so it seems that we can be sure that this identifies precisely
* the MS-supplied truetype collections.
* This avoids any potential issues if a TTF file happens to have
* a & in the font name (I can't find anything which prohibits this)
* and also means we only parse the key in cases we know to be
* worthwhile.
*/
ptr1+=3;
}
break;
} else {
}
}
} else {
}
}
/* TTC or ttc means it may be a collection. Need to parse out
* multiple font face names separated by " & "
* By only doing this for fonts which look like collections based on
* file name we are adhering to MS recommendations for font file names
* so it seems that we can be sure that this identifies precisely
* the MS-supplied truetype collections.
* This avoids any potential issues if a TTF file happens to have
* a & in the font name (I can't find anything which prohibits this)
* and also means we only parse the key in cases we know to be
* worthwhile.
*/
ptr1+=3;
}
break;
} else {
}
}
} else {
}
}
/* Obtain all the fontname -> filename mappings.
* This is called once and the results returned to Java code which can
* use it for lookups to reduce or avoid the need to search font files.
*/
{
const char cname[MAX_BUFFER];
const char data[MAX_BUFFER];
/* Check we were passed all the maps we need, and do lookup of
* methods for JNI up-calls
*/
if (fontToFileMap == NULL ||
fontToFamilyMap == NULL ||
familyToFontListMap == NULL) {
return;
}
return;
}
return;
}
return;
}
return;
}
"<init>", "(I)V");
return;
}
return;
}
return;
}
return;
}
/* Enumerate fonts via GDI to build maps of fonts and families */
if (IS_NT) {
} else {
}
/* Use the windows registry to map font names to files */
if (ret != ERROR_SUCCESS) {
return;
}
if (IS_NT) {
} else {
}
if (ret != ERROR_SUCCESS ||
dwMaxValueNameLen >= MAX_BUFFER ||
dwMaxValueDataLen >= MAX_BUFFER) {
return;
}
if (IS_NT) {
} else {
}
if (ret != ERROR_SUCCESS) {
break;
}
continue;
}
if (IS_NT) {
/* If the filename ends with ".ttf" or ".otf" also accept it.
* Not expecting to need to do this for .ttc files.
* Also note this code is not mirrored in the "A" (win9x) path.
*/
continue; /* not a TT font... */
}
}
} else {
continue; /* not a TT font... */
}
}
}
}