diff options
author | Simon Steiner <ssteiner@apache.org> | 2022-01-21 16:07:55 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2022-01-21 16:07:55 +0000 |
commit | fa96721ca8a7a8ed0d4de31e919c28921444c9d9 (patch) | |
tree | 4f9302b5509d59b872393155f54b0110b97f5c6c | |
parent | 99601efc607d50f491d8f08c56d14f01d9a5fb82 (diff) | |
download | xmlgraphics-fop-fa96721ca8a7a8ed0d4de31e919c28921444c9d9.tar.gz xmlgraphics-fop-fa96721ca8a7a8ed0d4de31e919c28921444c9d9.zip |
FOP-3015: Set text color for simulate-style
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1897301 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java | 46 | ||||
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java | 39 |
2 files changed, 62 insertions, 23 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java index b2c7a0d17..114cb7ae7 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java @@ -469,16 +469,7 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> { 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 AbstractIFPainter<PDFDocumentHandler> { } 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 AbstractIFPainter<PDFDocumentHandler> { 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 AbstractIFPainter<PDFDocumentHandler> { xoLast = xo; yoLast = yo; } + endSimulateStyle(tf, triplet); } } diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java index f72e227db..387afef9f 100644 --- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFPainterTestCase.java @@ -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); |