From: Simon Steiner Date: Wed, 1 Sep 2021 06:06:25 +0000 (+0000) Subject: FOP-3024: Make sure even number of bytes are output per trn for AFP TTF X-Git-Tag: fop-2_7~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b23edd0f37ef50c18f0a91d544417ef7e7b3561f;p=xmlgraphics-fop.git FOP-3024: Make sure even number of bytes are output per trn for AFP TTF git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1892774 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/afp/fonts/FopCharacterSet.java b/fop-core/src/main/java/org/apache/fop/afp/fonts/FopCharacterSet.java index 9d53cc7ea..dec45919f 100644 --- a/fop-core/src/main/java/org/apache/fop/afp/fonts/FopCharacterSet.java +++ b/fop-core/src/main/java/org/apache/fop/afp/fonts/FopCharacterSet.java @@ -51,7 +51,7 @@ public class FopCharacterSet extends CharacterSet { public FopCharacterSet(String codePage, String encoding, String name, Typeface charSet, AFPResourceAccessor accessor, AFPEventProducer eventProducer) { - super(codePage, encoding, CharacterSetType.SINGLE_BYTE, name, accessor, eventProducer); + super(codePage, encoding, CharacterSetType.DOUBLE_BYTE, name, accessor, eventProducer); this.charSet = charSet; } diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java index 9c6b51873..992436b43 100644 --- a/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java @@ -240,7 +240,7 @@ public class AFPTrueTypeTestCase { @Test public void testAFPPainterWidths() throws IFException, IOException { - String s = getAFPPainterWidths(true); + String s = getAFPPainterWidths(true, "abcdefghijklmno"); Assert.assertTrue(s, s.contains("DATA PRESENTATION_TEXT AMB AMI 0 SCFL SVI TRN a AMI" + " 9 TRN b AMI 29 TRN c AMI 59 TRN d AMI 99 TRN e AMI 149 TRN f AMI 209 TRN g AMI 24 TRN h AMI 105 TRN" + " i AMI 196 TRN j AMI 42 TRN k AMI 153 TRN l AMI 19 TRN m AMI 151 TRN n AMI 38 TRN o AMI 190")); @@ -248,11 +248,23 @@ public class AFPTrueTypeTestCase { @Test public void testAFPPainterWidthsNoPositionByChar() throws IFException, IOException { - String s = getAFPPainterWidths(false); + String s = getAFPPainterWidths(false, "abcdefghijklmno"); Assert.assertTrue(s, s.contains("DATA PRESENTATION_TEXT AMB AMI 0 SCFL SVI TRN abcdefghijklmno")); } - private String getAFPPainterWidths(boolean positionByChar) throws IFException, IOException { + @Test + public void testAFPPainterWidthsNoPositionByCharLongText() throws IFException, IOException { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 30; i++) { + sb.append("test "); + } + String s = getAFPPainterWidths(false, sb.toString()); + Assert.assertTrue(s, s.contains("DATA PRESENTATION_TEXT AMB AMI 0 SCFL SVI TRN test test test test test test " + + "test test test test test test test test test test test test test test test test test test test t " + + "TRN est test test test test")); + } + + private String getAFPPainterWidths(boolean positionByChar, String text) throws IFException, IOException { AFPDocumentHandler afpDocumentHandler = mock(AFPDocumentHandler.class); when(afpDocumentHandler.getPaintingState()).thenReturn(new AFPPaintingState()); when(afpDocumentHandler.getResourceManager()).thenReturn(new AFPResourceManager(null)); @@ -264,7 +276,7 @@ public class AFPTrueTypeTestCase { AFPPainter afpPainter = new MyAFPPainter(afpDocumentHandler, positionByChar); afpPainter.setFont("any", "normal", 400, null, 12000, Color.BLACK); - afpPainter.drawText(0, 0, 0, 0, null, "abcdefghijklmno"); + afpPainter.drawText(0, 0, 0, 0, null, text); ByteArrayOutputStream bos = new ByteArrayOutputStream(); po.writeToStream(bos);