Author: ssteiner
Date: Fri Jan 21 16:07:55 2022
New Revision: 1897301

URL: http://svn.apache.org/viewvc?rev=1897301&view=rev
Log:
FOP-3015: Set text color for simulate-style

Modified:
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java?rev=1897301&r1=1897300&r2=1897301&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java
 Fri Jan 21 16:07:55 2022
@@ -469,16 +469,7 @@ public class PDFPainter extends Abstract
         PDFTextUtil textutil = generator.getTextUtil();
         textutil.updateTf(fontKey, fontSize, tf.isMultiByte(), tf.isCID());
 
-        double shear = 0;
-        boolean simulateStyle = tf instanceof CustomFont && ((CustomFont) 
tf).getSimulateStyle();
-        if (simulateStyle) {
-            if (triplet.getWeight() == 700) {
-                generator.add("2 Tr 0.31543 w\n");
-            }
-            if (triplet.getStyle().equals("italic")) {
-                shear = 0.3333;
-            }
-        }
+        double shear = startSimulateStyle(tf, triplet);
 
         generator.updateCharacterSpacing(letterSpacing / 1000f);
 
@@ -531,6 +522,26 @@ public class PDFPainter extends Abstract
 
         }
         textutil.writeTJ();
+        endSimulateStyle(tf, triplet);
+    }
+
+    private double startSimulateStyle(Typeface tf, FontTriplet triplet) {
+        double shear = 0;
+        boolean simulateStyle = tf instanceof CustomFont && ((CustomFont) 
tf).getSimulateStyle();
+        if (simulateStyle) {
+            if (triplet.getWeight() == 700) {
+                generator.updateColor(state.getTextColor(), false, null);
+                generator.add("2 Tr 0.31543 w\n");
+            }
+            if (triplet.getStyle().equals("italic")) {
+                shear = 0.3333;
+            }
+        }
+        return shear;
+    }
+
+    private void endSimulateStyle(Typeface tf, FontTriplet triplet) {
+        boolean simulateStyle = tf instanceof CustomFont && ((CustomFont) 
tf).getSimulateStyle();
         if (simulateStyle && triplet.getWeight() == 700) {
             generator.add("0 Tr\n");
         }
@@ -556,19 +567,7 @@ public class PDFPainter extends Abstract
             double      yoLast          = 0f;
             double      wox             = wordSpacing;
 
-            // FOP-2810
-            boolean simulateStyle = tf instanceof CustomFont && ((CustomFont) 
tf).getSimulateStyle();
-            double shear = 0;
-
-            if (simulateStyle) {
-                if (triplet.getWeight() == 700) {
-                    generator.add("q\n");
-                    generator.add("2 Tr 0.31543 w\n");
-                }
-                if (triplet.getStyle().equals("italic")) {
-                    shear = 0.3333;
-                }
-            }
+            double shear = startSimulateStyle(tf, triplet);
 
             tu.writeTextMatrix(new AffineTransform(1, 0, shear, -1, x / 1000f, 
y / 1000f));
             tu.updateTf(fk, fsPoints, tf.isMultiByte(), true);
@@ -589,6 +588,7 @@ public class PDFPainter extends Abstract
                 xoLast = xo;
                 yoLast = yo;
             }
+            endSimulateStyle(tf, triplet);
         }
     }
 

Modified: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java?rev=1897301&r1=1897300&r2=1897301&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java
 Fri Jan 21 16:07:55 2022
@@ -172,6 +172,45 @@ public class PDFPainterTestCase {
     }
 
     @Test
+    public void testSimulateStyleColor() throws Exception {
+        FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
+        foUserAgent = fopFactory.newFOUserAgent();
+        PDFDocumentHandler pdfDocumentHandler = new PDFDocumentHandler(new 
IFContext(foUserAgent));
+
+        pdfDocumentHandler.setResult(new StreamResult(new 
ByteArrayOutputStream()));
+        pdfDocumentHandler.startDocument();
+        pdfDocumentHandler.startPage(0, "", "", new Dimension());
+
+        FontInfo fi = new FontInfo();
+        fi.addFontProperties("f1", new FontTriplet("a", "italic", 700));
+        MultiByteFont font = new MultiByteFont(null, null);
+        font.setSimulateStyle(true);
+        fi.addMetrics("f1", font);
+        pdfDocumentHandler.setFontInfo(fi);
+        PDFPainter pdfPainter = new PDFPainter(pdfDocumentHandler, null);
+        pdfPainter.setFont("a", "italic", 700, null, 12, Color.red);
+        pdfPainter.drawText(0, 0, 0, 0, null, "test");
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        PDFFilterList filters = 
pdfPainter.generator.getStream().getFilterList();
+        filters.setDisableAllFilters(true);
+        pdfPainter.generator.getStream().output(bos);
+        Assert.assertEquals(bos.toString(), "<< /Length 1 0 R >>\n"
+                + "stream\n"
+                + "q\n"
+                + "1 0 0 -1 0 0 cm\n"
+                + "1 0 0 rg\n"
+                + "BT\n"
+                + "/f1 0.012 Tf\n"
+                + "1 0 0 RG\n"
+                + "2 Tr 0.31543 w\n"
+                + "1 0 0.3333 -1 0 0 Tm [<0000000000000000>] TJ\n"
+                + "0 Tr\n"
+                + "\n"
+                + "endstream");
+    }
+
+    @Test
     public void testDrawTextWithMultiByteFont() throws IFException {
         StringBuilder output = new StringBuilder();
         PDFDocumentHandler pdfDocumentHandler = makePDFDocumentHandler(output);



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org

Reply via email to