aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core/src
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2021-06-26 06:22:24 +0000
committerSimon Steiner <ssteiner@apache.org>2021-06-26 06:22:24 +0000
commit1b8ca39cbbd7945e505f75da595d27c411f40c9c (patch)
tree04858c06bfa3debc985cb53865501443b63cadc6 /fop-core/src
parent9a63b81a0e0da395589d1a74f3feb5e96b116e32 (diff)
downloadxmlgraphics-fop-1b8ca39cbbd7945e505f75da595d27c411f40c9c.tar.gz
xmlgraphics-fop-1b8ca39cbbd7945e505f75da595d27c411f40c9c.zip
FOP-3017: Add option to disable positioning per char
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1891051 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java17
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java8
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java30
3 files changed, 39 insertions, 16 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java
index eb6c4a77f..a9f222bf1 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java
@@ -266,8 +266,9 @@ public final class AFPFontConfig implements FontConfig {
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 implements FontConfig {
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 implements FontConfig {
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 implements FontConfig {
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 implements FontConfig {
public URI getUri() {
return uri;
}
+
+ public boolean isPositionByChar() {
+ return positionByChar;
+ }
}
static final class OutlineFontConfig extends AFPFontConfigData {
diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
index 35235668a..9a4a7b93e 100644
--- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPPainter.java
@@ -70,7 +70,6 @@ import org.apache.fop.afp.ptoca.PtocaProducer;
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 AbstractIFPainter<AFPDocumentHandler> {
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 AbstractIFPainter<AFPDocumentHandler> {
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));
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 0dfbd1a46..9c6b51873 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
@@ -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;
}
}