Skip to content
Permalink
Browse files
8273808: Cleanup AddFontsToX11FontPath
Reviewed-by: pbansal, lucy
  • Loading branch information
MBaesken committed Sep 17, 2021
1 parent 1890d85 commit 35f6f1d69f4238f16595b9b8f1d11db9e49d4cc9
Showing with 1 addition and 135 deletions.
  1. +1 −135 src/java.desktop/unix/native/common/awt/fontpath.c
@@ -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;

3 comments on commit 35f6f1d

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot replied Sep 17, 2021

@MBaesken

This comment has been minimized.

Copy link
Member Author

@MBaesken MBaesken replied Oct 20, 2021

/backport jdk17u

@openjdk

This comment has been minimized.

Copy link

@openjdk openjdk bot replied Oct 20, 2021

@MBaesken @MBaesken the backport was successfully created on the branch MBaesken-backport-35f6f1d6 in my personal fork of openjdk/jdk17u. To create a pull request with this backport targeting openjdk/jdk17u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

this pull request contains a backport of commit 35f6f1d6 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 17 Sep 2021 and was reviewed by Pankaj Bansal and Lutz Schmidt.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u:

$ git fetch https://github.com/openjdk-bots/jdk17u MBaesken-backport-35f6f1d6:MBaesken-backport-35f6f1d6
$ git checkout MBaesken-backport-35f6f1d6
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u MBaesken-backport-35f6f1d6
Please sign in to comment.