pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1840313 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdmodel/graphics/color/PDDeviceRGB.java rendering/PDFRenderer.java
Date Fri, 07 Sep 2018 17:02:48 GMT
Author: tilman
Date: Fri Sep  7 17:02:47 2018
New Revision: 1840313

URL: http://svn.apache.org/viewvc?rev=1840313&view=rev
Log:
PDFBOX-4315: move KCMS info msg so that it comes up only when rendering is called

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java?rev=1840313&r1=1840312&r2=1840313&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceRGB.java
Fri Sep  7 17:02:47 2018
@@ -20,10 +20,7 @@ import java.awt.color.ColorSpace;
 import java.awt.image.BufferedImage;
 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;
 
 /**
@@ -41,8 +38,6 @@ 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()
     {
     }
@@ -58,8 +53,6 @@ public final class PDDeviceRGB extends P
             return;
         }
 
-        suggestKCMS();
-
         synchronized (this)
         {
             // we might have been waiting for another thread, so check again
@@ -124,47 +117,4 @@ public final class PDDeviceRGB extends P
         image.setData(raster);
         return image;
     }
-
-    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 higher rendering speed on java 8 or 9,");
-                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!", e);
-            }
-        }
-    }
-
-    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;
-        }
-    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java?rev=1840313&r1=1840312&r2=1840313&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java Fri Sep
 7 17:02:47 2018
@@ -20,6 +20,9 @@ import java.awt.Color;
 import java.awt.Graphics2D;
 import java.awt.image.BufferedImage;
 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;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
@@ -38,6 +41,8 @@ import org.apache.pdfbox.pdmodel.interac
  */
 public class PDFRenderer
 {
+    private static final Log LOG = LogFactory.getLog(PDFRenderer.class);
+
     protected final PDDocument document;
     // TODO keep rendering state such as caches here
     
@@ -57,6 +62,8 @@ public class PDFRenderer
 
     private BufferedImage pageImage;
 
+    private static boolean kcmsLogged = false;
+
     /**
      * Creates a new PDFRenderer.
      * @param document the document to render
@@ -64,6 +71,12 @@ public class PDFRenderer
     public PDFRenderer(PDDocument document)
     {
         this.document = document;
+
+        if (!kcmsLogged)
+        {
+            suggestKCMS();
+            kcmsLogged = true;
+        }
     }
     
     /**
@@ -374,4 +387,48 @@ public class PDFRenderer
     {
         return pageImage;
     }
+
+    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 higher rendering speed on java 8 or 9,");
+                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)
+            {
+                // jdk 10 and higher
+                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