pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1814606 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
Date Wed, 08 Nov 2017 17:11:37 GMT
Author: tilman
Date: Wed Nov  8 17:11:37 2017
New Revision: 1814606

URL: http://svn.apache.org/viewvc?rev=1814606&view=rev
Log:
PDFBOX-3998: inform user to use KCMS when jdk8 or higher and KCMS is available

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java?rev=1814606&r1=1814605&r2=1814606&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
Wed Nov  8 17:11:37 2017
@@ -23,6 +23,10 @@ import java.awt.image.ColorModel;
 import java.awt.image.ComponentColorModel;
 import java.awt.image.WritableRaster;
 import java.io.IOException;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSName;
 
 /**
@@ -39,7 +43,9 @@ public final class PDDeviceRGB extends P
     
     private final PDColor initialColor = new PDColor(new float[] { 0, 0, 0 }, this);
     private volatile ColorSpace awtColorSpace;
-    
+
+    private static final Log LOG = LogFactory.getLog(PDDeviceRGB.class);
+
     private PDDeviceRGB()
     {
     }
@@ -54,6 +60,9 @@ public final class PDDeviceRGB extends P
         {
             return;
         }
+
+        suggestKCMS();
+
         synchronized (this)
         {
             // we might have been waiting for another thread, so check again
@@ -134,4 +143,47 @@ public final class PDDeviceRGB extends P
         }
         return dest;
     }
+
+    private static void suggestKCMS()
+    {
+        String cmmProperty = System.getProperty("sun.java2d.cmm");
+        if (isMinJdk8() && !"sun.java2d.cmm.kcms.KcmsServiceProvider".equals(cmmProperty))
+        {
+            try
+            {
+                // Make sure that class exists
+                Class.forName("sun.java2d.cmm.kcms.KcmsServiceProvider");
+
+                LOG.info("To get more speed on JDK8 or higher, ");
+                LOG.info("  use the option -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider");
+                LOG.info("  or call System.setProperty(\"sun.java2d.cmm\", \"sun.java2d.cmm.kcms.KcmsServiceProvider\")");
+            }
+            catch (ClassNotFoundException e)
+            {
+                LOG.debug("KCMS doesn't exist anymore. SO SAD!");
+            }
+        }
+    }
+
+    private static boolean isMinJdk8()
+    {
+        // strategy from lucene-solr/lucene/core/src/java/org/apache/lucene/util/Constants.java
+        String version = System.getProperty("java.specification.version");
+        final StringTokenizer st = new StringTokenizer(version, ".");
+        try
+        {
+            int major = Integer.parseInt(st.nextToken());
+            int minor = 0;
+            if (st.hasMoreTokens())
+            {
+                minor = Integer.parseInt(st.nextToken());
+            }
+            return major > 1 || (major == 1 && minor >= 8);
+        }
+        catch (NumberFormatException nfe)
+        {
+            // maybe some new numbering scheme in the 22nd century
+            return true;
+        }
+    }
 }



Mime
View raw message