< prev index next >

src/java.desktop/unix/native/common/awt/fontpath.c

Print this page




 191 static void AddFontsToX11FontPath ( fDirRecord *fDirP )
 192 {
 193     char *onePath;
 194     int index, nPaths;
 195     int origNumPaths, length;
 196     int origIndex;
 197     int totalDirCount;
 198     char  **origFontPath;
 199     char  **tempFontPath;
 200     int doNotAppend;
 201     int *appendDirList;
 202     char **newFontPath;
 203     int err, compareLength;
 204     char fontDirPath[512];
 205     int dirFile;
 206 
 207     doNotAppend = 0;
 208 
 209     if ( fDirP->num == 0 ) return;
 210 
 211     appendDirList = SAFE_SIZE_ARRAY_ALLOC(malloc, fDirP->num, sizeof ( int ));
 212     if ( appendDirList == NULL ) {
 213       return;  /* if it fails we cannot do much */
 214     }
 215 
 216     origFontPath = XGetFontPath ( awt_display, &nPaths );
 217 
 218     totalDirCount = nPaths;
 219     origNumPaths = nPaths;
 220     tempFontPath = origFontPath;
 221 
 222 
 223     for (index = 0; index < fDirP->num; index++ ) {
 224 
 225         doNotAppend = 0;
 226 
 227         tempFontPath = origFontPath;
 228         for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
 229 
 230             onePath = *tempFontPath;
 231 


 248             dirFile = open ( fontDirPath, O_RDONLY, 0 );
 249             if ( dirFile == -1 ) {
 250                 doNotAppend = 1;
 251             } else {
 252                close ( dirFile );
 253                totalDirCount++;
 254                appendDirList[index] = 1;
 255             }
 256         }
 257 
 258     }
 259 
 260     /* if no changes are required do not bother to do a setfontpath */
 261     if ( totalDirCount == nPaths ) {
 262       free ( ( void *) appendDirList );
 263       XFreeFontPath ( origFontPath );
 264       return;
 265     }
 266 
 267 
 268     newFontPath = SAFE_SIZE_ARRAY_ALLOC(malloc, totalDirCount, sizeof(char *));
 269     /* if it fails free things and get out */
 270     if ( newFontPath == NULL ) {
 271       free ( ( void *) appendDirList );
 272       XFreeFontPath ( origFontPath );
 273       return;
 274     }
 275 
 276     for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
 277       onePath = origFontPath[origIndex];
 278       newFontPath[origIndex] = onePath;
 279     }
 280 
 281     /* now add the other font paths */
 282 
 283     for (index = 0; index < fDirP->num; index++ ) {
 284 
 285       if ( appendDirList[index] == 1 ) {
 286 
 287         /* printf ( "Appending %s\n", fDirP->name[index] ); */
 288 
 289         onePath = SAFE_SIZE_ARRAY_ALLOC(malloc, strlen (fDirP->name[index]) + 2, sizeof( char ) );
 290         if (onePath == NULL) {
 291             free ( ( void *) appendDirList );
 292 
 293             for ( index = origIndex; index < nPaths; index++ ) {
 294                 free( newFontPath[index] );
 295             }
 296 
 297             free( ( void *) newFontPath);
 298             XFreeFontPath ( origFontPath );
 299             return;
 300         }
 301         strcpy ( onePath, fDirP->name[index] );
 302         strcat ( onePath, "/" );
 303         newFontPath[nPaths++] = onePath;
 304         /* printf ( "The path to be appended is %s\n", onePath ); */
 305       }
 306     }
 307 
 308     /*   printf ( "The dir count = %d\n", totalDirCount ); */
 309     free ( ( void *) appendDirList );




 191 static void AddFontsToX11FontPath ( fDirRecord *fDirP )
 192 {
 193     char *onePath;
 194     int index, nPaths;
 195     int origNumPaths, length;
 196     int origIndex;
 197     int totalDirCount;
 198     char  **origFontPath;
 199     char  **tempFontPath;
 200     int doNotAppend;
 201     int *appendDirList;
 202     char **newFontPath;
 203     int err, compareLength;
 204     char fontDirPath[512];
 205     int dirFile;
 206 
 207     doNotAppend = 0;
 208 
 209     if ( fDirP->num == 0 ) return;
 210 
 211     appendDirList = SAFE_SIZE_ARRAY_ALLOC(malloc, fDirP->num, (int)sizeof ( int ));
 212     if ( appendDirList == NULL ) {
 213       return;  /* if it fails we cannot do much */
 214     }
 215 
 216     origFontPath = XGetFontPath ( awt_display, &nPaths );
 217 
 218     totalDirCount = nPaths;
 219     origNumPaths = nPaths;
 220     tempFontPath = origFontPath;
 221 
 222 
 223     for (index = 0; index < fDirP->num; index++ ) {
 224 
 225         doNotAppend = 0;
 226 
 227         tempFontPath = origFontPath;
 228         for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
 229 
 230             onePath = *tempFontPath;
 231 


 248             dirFile = open ( fontDirPath, O_RDONLY, 0 );
 249             if ( dirFile == -1 ) {
 250                 doNotAppend = 1;
 251             } else {
 252                close ( dirFile );
 253                totalDirCount++;
 254                appendDirList[index] = 1;
 255             }
 256         }
 257 
 258     }
 259 
 260     /* if no changes are required do not bother to do a setfontpath */
 261     if ( totalDirCount == nPaths ) {
 262       free ( ( void *) appendDirList );
 263       XFreeFontPath ( origFontPath );
 264       return;
 265     }
 266 
 267 
 268     newFontPath = SAFE_SIZE_ARRAY_ALLOC(malloc, totalDirCount, (int)sizeof(char *));
 269     /* if it fails free things and get out */
 270     if ( newFontPath == NULL ) {
 271       free ( ( void *) appendDirList );
 272       XFreeFontPath ( origFontPath );
 273       return;
 274     }
 275 
 276     for ( origIndex = 0; origIndex < nPaths; origIndex++ ) {
 277       onePath = origFontPath[origIndex];
 278       newFontPath[origIndex] = onePath;
 279     }
 280 
 281     /* now add the other font paths */
 282 
 283     for (index = 0; index < fDirP->num; index++ ) {
 284 
 285       if ( appendDirList[index] == 1 ) {
 286 
 287         /* printf ( "Appending %s\n", fDirP->name[index] ); */
 288 
 289         onePath = SAFE_SIZE_ARRAY_ALLOC(malloc, (int)strlen (fDirP->name[index]) + 2, (int)sizeof( char ) );
 290         if (onePath == NULL) {
 291             free ( ( void *) appendDirList );
 292 
 293             for ( index = origIndex; index < nPaths; index++ ) {
 294                 free( newFontPath[index] );
 295             }
 296 
 297             free( ( void *) newFontPath);
 298             XFreeFontPath ( origFontPath );
 299             return;
 300         }
 301         strcpy ( onePath, fDirP->name[index] );
 302         strcat ( onePath, "/" );
 303         newFontPath[nPaths++] = onePath;
 304         /* printf ( "The path to be appended is %s\n", onePath ); */
 305       }
 306     }
 307 
 308     /*   printf ( "The dir count = %d\n", totalDirCount ); */
 309     free ( ( void *) appendDirList );


< prev index next >