< prev index next >

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

Print this page

        

@@ -800,7 +800,59 @@
 SPLASHEXPORT char*
 SplashGetScaledImageName(const char* jarName, const char* fileName,
                            float *scaleFactor)
 {
     *scaleFactor = 1;
+#ifndef __linux__
     return NULL;
+#endif
+    *scaleFactor = getNativeScaleFactor();
+    if (*scaleFactor == 2.0) {
+        char *scaledImgName = NULL;
+        size_t length = 0;
+        char *stringToAppend = ".java-scale2x";
+        char *dupFileName = strdup(fileName);
+        char *fileExtension = strrchr(dupFileName, '.');
+        
+        if (fileExtension == NULL) {
+            length = strlen(dupFileName) + strlen(stringToAppend) + 1;
+            scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof (char));
+            snprintf(scaledImgName, length, "%s%s",
+                    dupFileName, stringToAppend);
+        } else {
+            length = fileExtension - dupFileName + 1;
+            char *fileNameWithoutExt = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof (char));
+            memcpy(fileNameWithoutExt, dupFileName, length);
+            fileNameWithoutExt[length - 1] = '\0';
+            length = strlen(fileNameWithoutExt) + 
+                    strlen(stringToAppend) + strlen(fileExtension) + 1;
+            scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof (char));
+            snprintf(scaledImgName, length, "%s%s%s", 
+                    fileNameWithoutExt, stringToAppend, fileExtension);
+            free(fileNameWithoutExt);
+        }
+        free(dupFileName);
+        FILE *fp;
+        if (!(fp = fopen(scaledImgName, "r"))) {
+            *scaleFactor = 1;
+            free(scaledImgName);
+            return NULL;
+        }
+        fclose(fp);
+        SplashSetScaleFactor(*scaleFactor);
+        return scaledImgName;
+    }
+    return NULL;
+}
+
+float getNativeScaleFactor()
+{
+    float scaleFactor = 1.0f;
+    char *scale = getenv("GDK_SCALE");
+    if (scale != NULL) {
+        scaleFactor = strtof(scale, NULL);
+        if (scaleFactor == 0 || scaleFactor < 1) {
+            scaleFactor = 1.0f;
+        }
+    }
+    return scaleFactor;
 }
< prev index next >