pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1864974 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
Date Mon, 12 Aug 2019 15:52:08 GMT
Author: tilman
Date: Mon Aug 12 15:52:08 2019
New Revision: 1864974

URL: http://svn.apache.org/viewvc?rev=1864974&view=rev
Log:
PDFBOX-3353: if there is a color in /DS, then use that one for the text

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java?rev=1864974&r1=1864973&r2=1864974&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/handlers/PDFreeTextAppearanceHandler.java
Mon Aug 12 15:52:08 2019
@@ -16,6 +16,8 @@
 package org.apache.pdfbox.pdmodel.interactive.annotation.handlers;
 
 import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.util.Charsets;
@@ -49,6 +51,8 @@ public class PDFreeTextAppearanceHandler
 {
     private static final Log LOG = LogFactory.getLog(PDFreeTextAppearanceHandler.class);
 
+    final Pattern COLOR_PATTERN = Pattern.compile(".*color\\:\\#([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]).*");
+
     public PDFreeTextAppearanceHandler(PDAnnotation annotation)
     {
         super(annotation);
@@ -88,8 +92,23 @@ public class PDFreeTextAppearanceHandler
             setOpacity(cs, annotation.getConstantOpacity());
 
             // Adobe uses the last non stroking color from /DA as stroking color!
+            // But if there is a color in /DS, then that one is used for text.
             PDColor strokingColor = extractNonStrokingColor(annotation);
             boolean hasStroke = cs.setStrokingColorOnDemand(strokingColor);
+            PDColor textColor = strokingColor;
+            String defaultStyleString = annotation.getDefaultStyleString();
+            if (defaultStyleString != null)
+            {
+                Matcher m = COLOR_PATTERN.matcher(defaultStyleString);
+                if (m.find())
+                {
+                    int color = Integer.parseInt(m.group(1), 16);
+                    float r = ((color >> 16) & 0xFF) / 255f;
+                    float g = ((color >> 8) & 0xFF) / 255f;
+                    float b = (color & 0xFF) / 255f;
+                    textColor = new PDColor( new float[] { r, g, b }, PDDeviceRGB.INSTANCE);
+                }
+            }
 
             if (ab.dashArray != null)
             {
@@ -248,7 +267,7 @@ public class PDFreeTextAppearanceHandler
 
             cs.beginText();
             cs.setFont(font, fontSize);
-            cs.setNonStrokingColor(strokingColor.getComponents());
+            cs.setNonStrokingColor(textColor.getComponents());
             AppearanceStyle appearanceStyle = new AppearanceStyle();
             appearanceStyle.setFont(font);
             appearanceStyle.setFontSize(fontSize);



Mime
View raw message