< prev index next >

src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c

Print this page

        

*** 36,46 **** #include "splashscreen_impl.h" #include <windowsx.h> #include <windows.h> #include <winuser.h> #include "sizecalc.h" - #ifndef WS_EX_LAYERED #define WS_EX_LAYERED 0x80000 #endif #ifndef ULW_ALPHA --- 36,45 ----
*** 56,65 **** --- 55,66 ---- #endif #define WM_SPLASHUPDATE WM_USER+1 #define WM_SPLASHRECONFIGURE WM_USER+2 + #define BUFF_SIZE 1024 + /* Could use npt but decided to cut down on linked code size */ char* SplashConvertStringAlloc(const char* in, int *size) { int len, outChars, rc; WCHAR* buf; if (!in) {
*** 571,578 **** --- 572,630 ---- SPLASHEXPORT char* SplashGetScaledImageName(const char* jarName, const char* fileName, float *scaleFactor) { + float dpiScaleX = -1.0f; + float dpiScaleY = -1.0f; + *scaleFactor = 1.0; + GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY); + *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor; + + if (*scaleFactor > 1.0) { + char strDpi[BUFF_SIZE]; + _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX); + char *dupFileName = strdup(fileName); + char *fileExtension = strrchr(dupFileName, '.'); + char *scaledImgName = NULL; + char *nameToAppend = ".scale-"; + size_t length = 0; + /*File is missing extension */ + if (fileExtension == NULL) { + length = strlen(dupFileName) + strlen(nameToAppend) + + strlen(strDpi) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + int retVal = _snprintf(scaledImgName, length, "%s%s%s", dupFileName, + nameToAppend, strDpi); + if (retVal < 0 || (retVal != length - 1)) { + *scaleFactor = 1; + free(dupFileName); + free(scaledImgName); + return NULL; + } + } + else { + size_t length_Without_Ext = fileExtension - dupFileName; + length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) + + strlen(fileExtension) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + int retVal = _snprintf(scaledImgName, length, "%.*s%s%s%s", + length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension); + if (retVal < 0 || (retVal != length - 1)) { *scaleFactor = 1; + free(dupFileName); + free(scaledImgName); + return NULL; + } + } + free(dupFileName); + FILE *fp = NULL; + if (!(fp = fopen(scaledImgName, "r"))) { + *scaleFactor = 1; + free(scaledImgName); + return NULL; + } + fclose(fp); + return scaledImgName; + } return NULL; }
< prev index next >