You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2021/06/26 06:22:24 UTC

svn commit: r1891051 - in /xmlgraphics/fop/trunk/fop-core/src: main/java/org/apache/fop/render/afp/AFPFontConfig.java main/java/org/apache/fop/render/afp/AFPPainter.java test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java

Author: ssteiner
Date: Sat Jun 26 06:22:24 2021
New Revision: 1891051

URL: http://svn.apache.org/viewvc?rev=1891051&view=rev
Log:
FOP-3017: Add option to disable positioning per char

Modified:
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
    xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java?rev=1891051&r1=1891050&r2=1891051&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java Sat Jun 26 06:22:24 2021
@@ -266,8 +266,9 @@ public final class AFPFontConfig impleme
                 return null;
             }
             String subfont = cfg.getAttribute("sub-font", null);
+            boolean positionByChar = cfg.getAttributeAsBoolean("position-by-char", true);
             return new TrueTypeFontConfig(fontTriplets, type, codepage, encoding, "",
-                    name, subfont, isEmbbedable(fontTriplets), uri);
+                    name, subfont, isEmbbedable(fontTriplets), uri, positionByChar);
         }
 
         private RasterFontConfig getRasterFont(List<FontTriplet> triplets, String type,
@@ -368,14 +369,16 @@ public final class AFPFontConfig impleme
         private String characterset;
         private String subfont;
         private String fontUri;
+        private boolean positionByChar;
 
         private TrueTypeFontConfig(List<FontTriplet> triplets, String type, String codePage,
                                    String encoding, String characterset, String name, String subfont,
-                                   boolean embeddable, String uri) {
+                                   boolean embeddable, String uri, boolean positionByChar) {
             super(triplets, type, codePage, encoding, name, embeddable, null);
             this.characterset = characterset;
             this.subfont = subfont;
             this.fontUri = uri;
+            this.positionByChar = positionByChar;
         }
 
         @Override
@@ -390,7 +393,7 @@ public final class AFPFontConfig impleme
                 CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().build(characterset,
                         super.codePage, super.encoding, tf, accessor, eventProducer);
                 OutlineFont font = new AFPTrueTypeFont(super.name, super.embeddable, characterSet,
-                            eventProducer, subfont, new URI(fontUri));
+                            eventProducer, subfont, new URI(fontUri), positionByChar);
                 return getFontInfo(font, this);
             } catch (URISyntaxException e) {
                 throw new IOException(e);
@@ -401,11 +404,13 @@ public final class AFPFontConfig impleme
     public static class AFPTrueTypeFont extends OutlineFont {
         private String ttc;
         private URI uri;
+        private boolean positionByChar;
         public AFPTrueTypeFont(String name, boolean embeddable, CharacterSet charSet, AFPEventProducer eventProducer,
-                               String ttc, URI uri) {
+                               String ttc, URI uri, boolean positionByChar) {
             super(name, embeddable, charSet, eventProducer);
             this.ttc = ttc;
             this.uri = uri;
+            this.positionByChar = positionByChar;
         }
 
         public FontType getFontType() {
@@ -419,6 +424,10 @@ public final class AFPFontConfig impleme
         public URI getUri() {
             return uri;
         }
+
+        public boolean isPositionByChar() {
+            return positionByChar;
+        }
     }
 
     static final class OutlineFontConfig extends AFPFontConfigData {

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java?rev=1891051&r1=1891050&r2=1891051&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java Sat Jun 26 06:22:24 2021
@@ -70,7 +70,6 @@ import org.apache.fop.afp.ptoca.PtocaPro
 import org.apache.fop.afp.util.AFPResourceAccessor;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontTriplet;
-import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.render.ImageHandlerUtil;
 import org.apache.fop.render.RenderingContext;
@@ -1026,11 +1025,12 @@ public class AFPPainter extends Abstract
 
                 boolean fixedSpaceMode = false;
                 double ttPos = p.x;
-
+                boolean positionByChar = afpFont instanceof AFPFontConfig.AFPTrueTypeFont
+                        && ((AFPFontConfig.AFPTrueTypeFont) afpFont).isPositionByChar();
                 for (int i = 0; i < l; i++) {
                     char orgChar = text.charAt(i);
                     float glyphAdjust = 0;
-                    if (afpFont.getFontType() == FontType.TRUETYPE) {
+                    if (positionByChar) {
                         flushText(builder, sb, charSet);
                         fixedSpaceMode = true;
                         int charWidth = font.getCharWidth(orgChar);
@@ -1064,7 +1064,7 @@ public class AFPPainter extends Abstract
                         glyphAdjust += dx[i + 1];
                     }
 
-                    if (afpFont.getFontType() == FontType.TRUETYPE) {
+                    if (positionByChar) {
                         flushText(builder, sb, charSet);
                         ttPos += unitConv.mpt2units(glyphAdjust);
                         builder.absoluteMoveInline((int) Math.round(ttPos));

Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java?rev=1891051&r1=1891050&r2=1891051&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java Sat Jun 26 06:22:24 2021
@@ -224,7 +224,7 @@ public class AFPTrueTypeTestCase {
         PageObject po = new PageObject(new Factory(), "PAGE0001", 0, 0, 0, 0, 0);
         when(ds.getCurrentPage()).thenReturn(po);
 
-        AFPPainter afpPainter = new MyAFPPainter(afpDocumentHandler);
+        AFPPainter afpPainter = new MyAFPPainter(afpDocumentHandler, true);
         afpPainter.setFont("any", "normal", 400, null, null, Color.BLACK);
         afpPainter.drawText(0, 0, 0, 0, null, "test");
 
@@ -240,6 +240,19 @@ public class AFPTrueTypeTestCase {
 
     @Test
     public void testAFPPainterWidths() throws IFException, IOException {
+        String s = getAFPPainterWidths(true);
+        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"));
+    }
+
+    @Test
+    public void testAFPPainterWidthsNoPositionByChar() throws IFException, IOException {
+        String s = getAFPPainterWidths(false);
+        Assert.assertTrue(s, s.contains("DATA PRESENTATION_TEXT AMB AMI 0 SCFL SVI TRN abcdefghijklmno"));
+    }
+
+    private String getAFPPainterWidths(boolean positionByChar) throws IFException, IOException {
         AFPDocumentHandler afpDocumentHandler = mock(AFPDocumentHandler.class);
         when(afpDocumentHandler.getPaintingState()).thenReturn(new AFPPaintingState());
         when(afpDocumentHandler.getResourceManager()).thenReturn(new AFPResourceManager(null));
@@ -249,7 +262,7 @@ public class AFPTrueTypeTestCase {
         PageObject po = new PageObject(new Factory(), "PAGE0001", 0, 0, 0, 0, 0);
         when(ds.getCurrentPage()).thenReturn(po);
 
-        AFPPainter afpPainter = new MyAFPPainter(afpDocumentHandler);
+        AFPPainter afpPainter = new MyAFPPainter(afpDocumentHandler, positionByChar);
         afpPainter.setFont("any", "normal", 400, null, 12000, Color.BLACK);
         afpPainter.drawText(0, 0, 0, 0, null, "abcdefghijklmno");
 
@@ -260,14 +273,15 @@ public class AFPTrueTypeTestCase {
         AFPParser afpParser = new AFPParser(true);
         afpParser.readWidths = true;
         afpParser.read(bis, sb);
-        Assert.assertTrue(sb.toString(), sb.toString().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"));
+        return sb.toString();
     }
 
-    class MyAFPPainter extends AFPPainter {
-        MyAFPPainter(AFPDocumentHandler documentHandler) {
+    static class MyAFPPainter extends AFPPainter {
+        boolean positionByChar;
+
+        MyAFPPainter(AFPDocumentHandler documentHandler, boolean positionByChar) {
             super(documentHandler);
+            this.positionByChar = positionByChar;
         }
 
         protected FOUserAgent getUserAgent() {
@@ -292,7 +306,7 @@ public class AFPTrueTypeTestCase {
             }
             font.setWidthArray(widths);
             f.addMetrics("any", new AFPFontConfig.AFPTrueTypeFont("", true,
-                    new FopCharacterSet("", "UTF-16BE", "", font, null, null), null, null, null));
+                    new FopCharacterSet("", "UTF-16BE", "", font, null, null), null, null, null, positionByChar));
             return f;
         }
     }



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