jdk/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c
changeset 36907 c3d8383e3efb
parent 27079 05150f708e53
child 41776 71e2575dd727
equal deleted inserted replaced
36906:b6c9a99a8f5d 36907:c3d8383e3efb
    56 #endif
    56 #endif
    57 
    57 
    58 #define WM_SPLASHUPDATE         WM_USER+1
    58 #define WM_SPLASHUPDATE         WM_USER+1
    59 #define WM_SPLASHRECONFIGURE    WM_USER+2
    59 #define WM_SPLASHRECONFIGURE    WM_USER+2
    60 
    60 
       
    61 #define BUFF_SIZE 1024
       
    62 
    61 /* Could use npt but decided to cut down on linked code size */
    63 /* Could use npt but decided to cut down on linked code size */
    62 char* SplashConvertStringAlloc(const char* in, int *size) {
    64 char* SplashConvertStringAlloc(const char* in, int *size) {
    63     int len, outChars, rc;
    65     int len, outChars, rc;
    64     WCHAR* buf;
    66     WCHAR* buf;
    65     if (!in) {
    67     if (!in) {
   567 SplashReconfigure(Splash * splash)
   569 SplashReconfigure(Splash * splash)
   568 {
   570 {
   569     PostMessage(splash->hWnd, WM_SPLASHRECONFIGURE, 0, 0);
   571     PostMessage(splash->hWnd, WM_SPLASHRECONFIGURE, 0, 0);
   570 }
   572 }
   571 
   573 
   572 SPLASHEXPORT char*
   574 jboolean
   573 SplashGetScaledImageName(const char* jarName, const char* fileName,
   575 SplashGetScaledImageName(const char* jarName, const char* fileName,
   574                            float *scaleFactor)
   576                            float *scaleFactor, char *scaleImageName,
   575 {
   577                            const size_t scaledImageLength)
   576     *scaleFactor = 1;
   578 {
   577     return NULL;
   579     float dpiScaleX = -1.0f;
   578 }
   580     float dpiScaleY = -1.0f;
       
   581     FILE *fp = NULL;
       
   582     *scaleFactor = 1.0;
       
   583     GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY);
       
   584     *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor;
       
   585     if (*scaleFactor > 1.0) {
       
   586         char strDpi[BUFF_SIZE];
       
   587         char *dupFileName = strdup(fileName);
       
   588         char *fileExtension = strrchr(dupFileName, '.');
       
   589         char *nameToAppend = ".scale-";
       
   590         size_t length = 0;
       
   591         int retVal = 0;
       
   592         _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX);
       
   593         /*File is missing extension */
       
   594         if (fileExtension == NULL) {
       
   595             length = strlen(dupFileName) + strlen(nameToAppend) +
       
   596                 strlen(strDpi) + 1;
       
   597             if (length > scaledImageLength) {
       
   598                 *scaleFactor = 1;
       
   599                 free(dupFileName);
       
   600                 return JNI_FALSE;
       
   601             }
       
   602             retVal = _snprintf(scaleImageName, length, "%s%s%s", dupFileName,
       
   603                 nameToAppend, strDpi);
       
   604             if (retVal < 0 || (retVal != length - 1)) {
       
   605                 *scaleFactor = 1;
       
   606                 free(dupFileName);
       
   607                 return JNI_FALSE;
       
   608             }
       
   609         }
       
   610         else {
       
   611             size_t length_Without_Ext = fileExtension - dupFileName;
       
   612             length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) +
       
   613                 strlen(fileExtension) + 1;
       
   614             if (length > scaledImageLength) {
       
   615                 *scaleFactor = 1;
       
   616                 free(dupFileName);
       
   617                 return JNI_FALSE;
       
   618             }
       
   619             retVal = _snprintf(scaleImageName, length, "%.*s%s%s%s",
       
   620                 length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension);
       
   621             if (retVal < 0 || (retVal != length - 1)) {
       
   622                 *scaleFactor = 1;
       
   623                 free(dupFileName);
       
   624                 return JNI_FALSE;
       
   625             }
       
   626         }
       
   627         free(dupFileName);
       
   628         if (!(fp = fopen(scaleImageName, "r"))) {
       
   629             *scaleFactor = 1;
       
   630             return JNI_FALSE;
       
   631         }
       
   632         fclose(fp);
       
   633         return JNI_TRUE;
       
   634     }
       
   635     return JNI_FALSE;
       
   636 }