From dac3a6d0f2b80b945863daf4450c25021261d583 Mon Sep 17 00:00:00 2001 From: Chris Bowditch Date: Mon, 17 Dec 2012 16:03:24 +0000 Subject: [PATCH] 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 --- .../apache/fop/render/ps/PSTextPainter.java | 31 ++++++++++++------- status.xml | 4 +++ 2 files changed, 23 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 + ")"); diff --git a/status.xml b/status.xml index 1cae0afb1..e6a532ede 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Invalid Postscript created if more than 255 characters in a custom font are used within + SVG when generating Postscript + Implementation of changes necessary to warn of invalid property values. -- 2.39.5