diff options
author | Chris Bowditch <cbowditch@apache.org> | 2012-12-17 16:03:24 +0000 |
---|---|---|
committer | Chris Bowditch <cbowditch@apache.org> | 2012-12-17 16:03:24 +0000 |
commit | dac3a6d0f2b80b945863daf4450c25021261d583 (patch) | |
tree | 03ae150551288ecceea00494585a621b82ce5d5e /src/java/org/apache | |
parent | 3f386d59ca9abaf9eecbee57966fd3ada3a6e8c6 (diff) | |
download | xmlgraphics-fop-dac3a6d0f2b80b945863daf4450c25021261d583.tar.gz xmlgraphics-fop-dac3a6d0f2b80b945863daf4450c25021261d583.zip |
Fix Jira FOP-2173: Invalid Postscript created with SVG and custom fonts
Patch submitted by Simon Steiner (ssteiner.at.thunderhead.com)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1422992 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSTextPainter.java | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/java/org/apache/fop/render/ps/PSTextPainter.java b/src/java/org/apache/fop/render/ps/PSTextPainter.java index 1f89dc8f0..eb2188026 100644 --- a/src/java/org/apache/fop/render/ps/PSTextPainter.java +++ b/src/java/org/apache/fop/render/ps/PSTextPainter.java @@ -269,6 +269,13 @@ public class PSTextPainter extends NativeTextPainter { this.gen = gen; } + public boolean isMultiByte(Font f) { + FontMetrics metrics = f.getFontMetrics(); + boolean multiByte = metrics instanceof MultiByteFont || metrics instanceof LazyFont + && ((LazyFont) metrics).getRealFont() instanceof MultiByteFont; + return multiByte; + } + public Font selectFontForChar(char ch) { for (int i = 0, c = fonts.length; i < c; i++) { if (fonts[i].hasChar(ch)) { @@ -290,18 +297,21 @@ public class PSTextPainter extends NativeTextPainter { } public boolean isFontChanging(Font f, char mapped) { - if (f != getCurrentFont()) { - return true; - } - if (mapped / 256 != getCurrentFontEncoding()) { - return true; + // this is only applicable for single byte fonts + if (!isMultiByte(f)) { + if (f != getCurrentFont()) { + return true; + } + if (mapped / 256 != getCurrentFontEncoding()) { + return true; + } } return false; //Font is the same } public void selectFont(Font f, char mapped) throws IOException { int encoding = mapped / 256; - String postfix = (encoding == 0 ? null : Integer.toString(encoding)); + String postfix = (!isMultiByte(f) && encoding > 0 ? Integer.toString(encoding) : null); PSFontResource res = getResourceForFont(f, postfix); gen.useFont("/" + res.getName(), f.getFontSize() / 1000f); res.notifyResourceUsageOnPage(gen.getResourceTracker()); @@ -430,10 +440,7 @@ public class PSTextPainter extends NativeTextPainter { textUtil.setCurrentFont(f, mapped); applyColor(paint, gen); - FontMetrics metrics = f.getFontMetrics(); - boolean multiByte = metrics instanceof MultiByteFont - || metrics instanceof LazyFont - && ((LazyFont) metrics).getRealFont() instanceof MultiByteFont; + boolean multiByte = textUtil.isMultiByte(f); StringBuffer sb = new StringBuffer(); sb.append(multiByte ? '<' : '('); for (int i = 0, c = this.currentChars.length(); i < c; i++) { @@ -531,9 +538,9 @@ public class PSTextPainter extends NativeTextPainter { || metrics instanceof LazyFont && ((LazyFont) metrics).getRealFont() instanceof MultiByteFont; if (multiByte) { - gen.write('<'); + gen.write("<"); gen.write(HexEncoder.encode(mapped)); - gen.write('>'); + gen.write(">"); } else { char codepoint = (char)(mapped % 256); gen.write("(" + codepoint + ")"); |