8273808: Cleanup AddFontsToX11FontPath
Reviewed-by: pbansal, lucy
This commit is contained in:
parent
1890d85c0e
commit
35f6f1d69f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -135,140 +135,6 @@ jboolean isDisplayLocal(JNIEnv *env) {
|
||||
return isLocal;
|
||||
}
|
||||
|
||||
static void AddFontsToX11FontPath ( fDirRecord *fDirP )
|
||||
{
|
||||
char *onePath;
|
||||
int index, nPaths;
|
||||
int origNumPaths, length;
|
||||
int origIndex;
|
||||
int totalDirCount;
|
||||
char **origFontPath;
|
||||
char **tempFontPath;
|
||||
int doNotAppend;
|
||||
int *appendDirList;
|
||||
char **newFontPath;
|
||||
int err, compareLength;
|
||||
char fontDirPath[512];
|
||||
int dirFile;
|
||||
|
||||
doNotAppend = 0;
|
||||
|
||||
if ( fDirP->num == 0 ) return;
|
||||
|
||||
appendDirList = SAFE_SIZE_ARRAY_ALLOC(malloc, fDirP->num, sizeof ( int ));
|
||||
if ( appendDirList == NULL ) {
|
||||
return; /* if it fails we cannot do much */
|
||||
}
|
||||
|
||||
origFontPath = XGetFontPath ( awt_display, &nPaths );
|
||||
|
||||
totalDirCount = nPaths;
|
||||
origNumPaths = nPaths;
|
||||
tempFontPath = origFontPath;
|
||||
|
||||
|
||||
for (index = 0; index < fDirP->num; index++ ) {
|
||||
|
||||
doNotAppend = 0;
|
||||
|
||||
tempFontPath = origFontPath;
|
||||
for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
|
||||
|
||||
onePath = *tempFontPath;
|
||||
|
||||
compareLength = strlen ( onePath );
|
||||
if ( onePath[compareLength -1] == '/' )
|
||||
compareLength--;
|
||||
|
||||
/* there is a slash at the end of every solaris X11 font path name */
|
||||
if ( strncmp ( onePath, fDirP->name[index], compareLength ) == 0 ) {
|
||||
doNotAppend = 1;
|
||||
break;
|
||||
}
|
||||
tempFontPath++;
|
||||
}
|
||||
|
||||
appendDirList[index] = 0;
|
||||
if ( doNotAppend == 0 ) {
|
||||
snprintf(fontDirPath, sizeof(fontDirPath), "%s/fonts.dir", fDirP->name[index]);
|
||||
fontDirPath[sizeof(fontDirPath) - 1] = '\0';
|
||||
dirFile = open ( fontDirPath, O_RDONLY, 0 );
|
||||
if ( dirFile == -1 ) {
|
||||
doNotAppend = 1;
|
||||
} else {
|
||||
close ( dirFile );
|
||||
totalDirCount++;
|
||||
appendDirList[index] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* if no changes are required do not bother to do a setfontpath */
|
||||
if ( totalDirCount == nPaths ) {
|
||||
free ( ( void *) appendDirList );
|
||||
XFreeFontPath ( origFontPath );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
newFontPath = SAFE_SIZE_ARRAY_ALLOC(malloc, totalDirCount, sizeof(char *));
|
||||
/* if it fails free things and get out */
|
||||
if ( newFontPath == NULL ) {
|
||||
free ( ( void *) appendDirList );
|
||||
XFreeFontPath ( origFontPath );
|
||||
return;
|
||||
}
|
||||
|
||||
for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
|
||||
onePath = origFontPath[origIndex];
|
||||
newFontPath[origIndex] = onePath;
|
||||
}
|
||||
|
||||
/* now add the other font paths */
|
||||
|
||||
for (index = 0; index < fDirP->num; index++ ) {
|
||||
|
||||
if ( appendDirList[index] == 1 ) {
|
||||
|
||||
/* printf ( "Appending %s\n", fDirP->name[index] ); */
|
||||
|
||||
onePath = SAFE_SIZE_ARRAY_ALLOC(malloc, strlen (fDirP->name[index]) + 2, sizeof( char ) );
|
||||
if (onePath == NULL) {
|
||||
free ( ( void *) appendDirList );
|
||||
|
||||
for ( index = origIndex; index < nPaths; index++ ) {
|
||||
free( newFontPath[index] );
|
||||
}
|
||||
|
||||
free( ( void *) newFontPath);
|
||||
XFreeFontPath ( origFontPath );
|
||||
return;
|
||||
}
|
||||
strcpy ( onePath, fDirP->name[index] );
|
||||
strcat ( onePath, "/" );
|
||||
newFontPath[nPaths++] = onePath;
|
||||
/* printf ( "The path to be appended is %s\n", onePath ); */
|
||||
}
|
||||
}
|
||||
|
||||
/* printf ( "The dir count = %d\n", totalDirCount ); */
|
||||
free ( ( void *) appendDirList );
|
||||
|
||||
XSetFontPath ( awt_display, newFontPath, totalDirCount );
|
||||
|
||||
for ( index = origNumPaths; index < totalDirCount; index++ ) {
|
||||
free( newFontPath[index] );
|
||||
}
|
||||
|
||||
free ( (void *) newFontPath );
|
||||
XFreeFontPath ( origFontPath );
|
||||
return;
|
||||
}
|
||||
#endif /* !HEADLESS */
|
||||
|
||||
|
||||
#ifndef HEADLESS
|
||||
static char **getX11FontPath ()
|
||||
{
|
||||
char **x11Path, **fontdirs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user