From 484c5fdefb02cd6ac4d36429343888d46ca04772 Mon Sep 17 00:00:00 2001 From: Glenn Adams Date: Mon, 18 Aug 2014 18:43:50 +0000 Subject: [PATCH] FOP-2391: ensure mapping is non-null in CS SVG text git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1618701 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fonts/GlyphMapping.java | 16 ++++++++++------ .../fop/layoutmgr/inline/TextLayoutManager.java | 2 +- .../apache/fop/svg/font/FOPGVTGlyphVector.java | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/fop/fonts/GlyphMapping.java b/src/java/org/apache/fop/fonts/GlyphMapping.java index 69943242d..f0fadaad4 100644 --- a/src/java/org/apache/fop/fonts/GlyphMapping.java +++ b/src/java/org/apache/fop/fonts/GlyphMapping.java @@ -83,22 +83,22 @@ public class GlyphMapping { public static GlyphMapping doGlyphMapping(TextFragment text, int startIndex, int endIndex, Font font, MinOptMax letterSpaceIPD, MinOptMax[] letterSpaceAdjustArray, char precedingChar, char breakOpportunityChar, final boolean endsWithHyphen, int level, - boolean retainAssociations) { + boolean dontOptimizeForIdentityMapping, boolean retainAssociations) { GlyphMapping mapping; if (font.performsSubstitution() || font.performsPositioning()) { mapping = processWordMapping(text, startIndex, endIndex, font, - breakOpportunityChar, endsWithHyphen, level, retainAssociations); + breakOpportunityChar, endsWithHyphen, level, dontOptimizeForIdentityMapping, retainAssociations); } else { mapping = processWordNoMapping(text, startIndex, endIndex, font, - letterSpaceIPD, letterSpaceAdjustArray, precedingChar, breakOpportunityChar, endsWithHyphen, - level); + letterSpaceIPD, letterSpaceAdjustArray, precedingChar, breakOpportunityChar, endsWithHyphen, level); } return mapping; } private static GlyphMapping processWordMapping(TextFragment text, int startIndex, int endIndex, final Font font, final char breakOpportunityChar, - final boolean endsWithHyphen, int level, boolean retainAssociations) { + final boolean endsWithHyphen, int level, + boolean dontOptimizeForIdentityMapping, boolean retainAssociations) { int e = endIndex; // end index of word in FOText character buffer int nLS = 0; // # of letter spaces String script = text.getScript(); @@ -163,7 +163,8 @@ public class GlyphMapping { return new GlyphMapping(startIndex, e, 0, nLS, ipd, endsWithHyphen, false, breakOpportunityChar != 0, font, level, gpa, - CharUtilities.isSameSequence(mcs, ics) ? null : mcs.toString(), associations); + !dontOptimizeForIdentityMapping && CharUtilities.isSameSequence(mcs, ics) ? null : mcs.toString(), + associations); } /** @@ -320,6 +321,9 @@ public class GlyphMapping { } public void reverse() { + if (mapping == null) { + return; + } if (mapping.length() > 0) { mapping = new StringBuffer(mapping).reverse().toString(); } diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index 24c1fcbbb..c7258ee6b 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -934,7 +934,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { && prevMapping.endIndex > 0 ? foText.charAt(prevMapping.endIndex - 1) : 0; GlyphMapping mapping = GlyphMapping.doGlyphMapping(foText, thisStart, lastIndex, font, letterSpaceIPD, letterSpaceAdjustArray, precedingChar, breakOpportunityChar, - endsWithHyphen, level, false); + endsWithHyphen, level, false, false); prevMapping = mapping; addGlyphMapping(mapping); tempStart = nextStart; diff --git a/src/java/org/apache/fop/svg/font/FOPGVTGlyphVector.java b/src/java/org/apache/fop/svg/font/FOPGVTGlyphVector.java index 0abffc52c..40a1e8ad3 100644 --- a/src/java/org/apache/fop/svg/font/FOPGVTGlyphVector.java +++ b/src/java/org/apache/fop/svg/font/FOPGVTGlyphVector.java @@ -90,7 +90,7 @@ class FOPGVTGlyphVector implements GVTGlyphVector { MinOptMax letterSpaceIPD = MinOptMax.ZERO; MinOptMax[] letterSpaceAdjustments = new MinOptMax[charIter.getEndIndex() - charIter.getBeginIndex()]; GlyphMapping mapping = GlyphMapping.doGlyphMapping(text, charIter.getBeginIndex(), charIter.getEndIndex(), - f, letterSpaceIPD, letterSpaceAdjustments, '\0', '\0', false, 0, true); + f, letterSpaceIPD, letterSpaceAdjustments, '\0', '\0', false, 0, true, true); maybeReverse(mapping); CharacterIterator glyphAsCharIter = mapping.mapping != null ? new StringCharacterIterator(mapping.mapping) : charIter; -- 2.39.5