From 8f37765b5c9b6dbe80d860207802aa4f7f8b1a94 Mon Sep 17 00:00:00 2001 From: Mehdi Houshmand Date: Wed, 4 Jul 2012 07:04:03 +0000 Subject: Bugzilla#53502: MODCA end structured field now more conformant with the spec by allowing 0xFFFF match (match any). Submitted by Robert Meyer git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1357110 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/afp/util/AFPResourceUtil.java | 97 ++++++++++++++-------- 1 file changed, 63 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/java/org/apache/fop/afp/util/AFPResourceUtil.java b/src/java/org/apache/fop/afp/util/AFPResourceUtil.java index 979376b3e..98d2a8f8a 100644 --- a/src/java/org/apache/fop/afp/util/AFPResourceUtil.java +++ b/src/java/org/apache/fop/afp/util/AFPResourceUtil.java @@ -56,8 +56,11 @@ import org.apache.fop.afp.parser.UnparsedStructuredField; */ public final class AFPResourceUtil { - private static final byte TYPE_CODE_BEGIN = (byte)(0xA8 & 0xFF); - private static final byte TYPE_CODE_END = (byte)(0xA9 & 0xFF); + private static final byte TYPE_CODE_BEGIN = (byte) (0xA8 & 0xFF); + + private static final byte TYPE_CODE_END = (byte) (0xA9 & 0xFF); + + private static final byte END_FIELD_ANY_NAME = (byte) (0xFF & 0xFF); private static final Log LOG = LogFactory.getLog(AFPResourceUtil.class); @@ -92,10 +95,13 @@ public final class AFPResourceUtil { throws UnsupportedEncodingException { //The first 8 bytes of the field data represent the resource name byte[] nameBytes = new byte[8]; - System.arraycopy(field.getData(), 0, nameBytes, 0, 8); - String asciiName; - asciiName = new String(nameBytes, AFPConstants.EBCIDIC_ENCODING); - return asciiName; + + byte[] fieldData = field.getData(); + if (fieldData.length < 8) { + throw new IllegalArgumentException("Field data does not contain a resource name"); + } + System.arraycopy(fieldData, 0, nameBytes, 0, 8); + return new String(nameBytes, AFPConstants.EBCIDIC_ENCODING); } /** @@ -128,12 +134,13 @@ public final class AFPResourceUtil { public static void copyNamedResource(String name, final InputStream in, final OutputStream out) throws IOException { final MODCAParser parser = new MODCAParser(in); - Collection resourceNames = new java.util.HashSet(); + Collection resourceNames = new java.util.HashSet(); //Find matching "Begin" field final UnparsedStructuredField fieldBegin; while (true) { - UnparsedStructuredField field = parser.readNextStructuredField(); + final UnparsedStructuredField field = parser.readNextStructuredField(); + if (field == null) { throw new IOException("Requested resource '" + name + "' not found. Encountered resource names: " + resourceNames); @@ -142,8 +149,10 @@ public final class AFPResourceUtil { if (field.getSfTypeCode() != TYPE_CODE_BEGIN) { //0xA8=Begin continue; //Not a "Begin" field } - String resourceName = getResourceName(field); + final String resourceName = getResourceName(field); + resourceNames.add(resourceName); + if (resourceName.equals(name)) { if (LOG.isDebugEnabled()) { LOG.debug("Start of requested structured field found:\n" @@ -170,45 +179,65 @@ public final class AFPResourceUtil { if (wrapInResource) { ResourceObject resourceObject = new ResourceObject(name) { protected void writeContent(OutputStream os) throws IOException { - copyStructuredFields(name, fieldBegin, parser, out); + copyNamedStructuredFields(name, fieldBegin, parser, out); } }; resourceObject.setType(ResourceObject.TYPE_PAGE_SEGMENT); resourceObject.writeToStream(out); } else { - copyStructuredFields(name, fieldBegin, parser, out); + copyNamedStructuredFields(name, fieldBegin, parser, out); } } - private static void copyStructuredFields(String name, UnparsedStructuredField fieldBegin, + private static void copyNamedStructuredFields(final String name, UnparsedStructuredField fieldBegin, MODCAParser parser, OutputStream out) throws IOException { - boolean inRequestedResource; - - //The "Begin" field first - out.write(MODCAParser.CARRIAGE_CONTROL_CHAR); - fieldBegin.writeTo(out); - UnparsedStructuredField field; - - //Then the rest of the fields until the corresponding "End" field - inRequestedResource = true; - do { - field = parser.readNextStructuredField(); + UnparsedStructuredField field = fieldBegin; + while (true) { if (field == null) { - break; //Unexpected EOF - } - - if (field.getSfTypeCode() == TYPE_CODE_END) { - String resourceName = getResourceName(field); - if (resourceName.equals(name)) { - inRequestedResource = false; //Signal end of loop - } + throw new IOException("Ending structured field not found for resource " + name); } out.write(MODCAParser.CARRIAGE_CONTROL_CHAR); field.writeTo(out); - } while (inRequestedResource); - if (inRequestedResource) { - throw new IOException("Ending structured field not found for resource " + name); + + if (isEndOfStructuredField(field, fieldBegin, name)) { + break; + } + field = parser.readNextStructuredField(); } } + private static boolean isEndOfStructuredField(UnparsedStructuredField field, + UnparsedStructuredField fieldBegin, String name) throws UnsupportedEncodingException { + return fieldMatchesEndTagType(field) + && fieldMatchesBeginCategoryCode(field, fieldBegin) + && fieldHasValidName(field, name); + } + + private static boolean fieldMatchesEndTagType(UnparsedStructuredField field) { + return field.getSfTypeCode() == TYPE_CODE_END; + } + + private static boolean fieldMatchesBeginCategoryCode(UnparsedStructuredField field, + UnparsedStructuredField fieldBegin) { + return fieldBegin.getSfCategoryCode() == field.getSfCategoryCode(); + } + + /** + * The AFP specification states that it is valid for the end structured field to have: + * - No tag name specified, which will cause it to match any existing tag type match. + * - The name has FFFF as its first two bytes + * - The given name matches the previous structured field name + */ + private static boolean fieldHasValidName(UnparsedStructuredField field, String name) + throws UnsupportedEncodingException { + if (field.getData().length > 0) { + if (field.getData()[0] == field.getData()[1] + && field.getData()[0] == END_FIELD_ANY_NAME) { + return true; + } else { + return name.equals(getResourceName(field)); + } + } + return true; + } } -- cgit v1.2.3 From b409a37cbf81a121351c96aec4610b43c23b5dd2 Mon Sep 17 00:00:00 2001 From: Mehdi Houshmand Date: Wed, 4 Jul 2012 07:54:43 +0000 Subject: Addressed some of the comments made by VH re:Temp_URI_Unification merge git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1357140 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/apps/EnvironmentProfile.java | 5 ++++- src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java | 5 ++++- src/java/org/apache/fop/apps/FOUserAgent.java | 7 ++++--- src/java/org/apache/fop/apps/FopFactory.java | 6 +++--- src/java/org/apache/fop/apps/FopFactoryBuilder.java | 2 +- src/java/org/apache/fop/apps/FopFactoryConfig.java | 3 ++- src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java | 2 +- test/java/org/apache/fop/fotreetest/FOTreeTestCase.java | 5 ++--- 8 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/java/org/apache/fop/apps/EnvironmentProfile.java b/src/java/org/apache/fop/apps/EnvironmentProfile.java index c35219353..c964120e3 100644 --- a/src/java/org/apache/fop/apps/EnvironmentProfile.java +++ b/src/java/org/apache/fop/apps/EnvironmentProfile.java @@ -25,7 +25,10 @@ import org.apache.fop.apps.io.ResourceResolver; import org.apache.fop.fonts.FontManager; /** - * The environment profile represents the restrictions and allowances that FOP is + * The environment profile represents the system in which FOP is invoked. Some of FOPs services rely + * upon features within the system, as such, the client may want to restrict access to these + * services. This object allows clients to control those restrictions by implementing the interfaces + * that the environment profile holds. */ public interface EnvironmentProfile { diff --git a/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java b/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java index 374074b8a..9ba7632d2 100644 --- a/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java +++ b/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java @@ -84,7 +84,10 @@ public final class EnvironmentalProfileFactory { throw new IllegalArgumentException("Default base URI must not be null"); } if (resourceResolver == null) { - throw new IllegalArgumentException("URI Resolver must not be null"); + throw new IllegalArgumentException("ResourceResolver must not be null"); + } + if (fontManager == null) { + throw new IllegalArgumentException("The FontManager must not be null"); } this.defaultBaseURI = defaultBaseURI; this.resourceResolver = resourceResolver; diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index 488b62474..b4c69c6e3 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -786,13 +786,14 @@ public class FOUserAgent { return factory.getImageHandlerRegistry(); } - /** TODO: javadoc*/ + /** @return the color space cache */ public ColorSpaceCache getColorSpaceCache() { return factory.getColorSpaceCache(); } - public Map getHyphPatNames() { - return factory.getHyphPatNames(); + /** @see {@link FopFactory#getHyphenationPatternNames()} */ + public Map getHyphenationPatternNames() { + return factory.getHyphenationPatternNames(); } } diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java index ec7266957..4508ea7fa 100644 --- a/src/java/org/apache/fop/apps/FopFactory.java +++ b/src/java/org/apache/fop/apps/FopFactory.java @@ -341,9 +341,9 @@ public final class FopFactory implements ImageContext { return config.getLayoutManagerMakerOverride(); } - - public Map getHyphPatNames() { - return config.getHyphPatNames(); + /** @return the hyphenation pattern names */ + public Map getHyphenationPatternNames() { + return config.getHyphenationPatternNames(); } /** diff --git a/src/java/org/apache/fop/apps/FopFactoryBuilder.java b/src/java/org/apache/fop/apps/FopFactoryBuilder.java index 44c44c119..6c3da57f3 100644 --- a/src/java/org/apache/fop/apps/FopFactoryBuilder.java +++ b/src/java/org/apache/fop/apps/FopFactoryBuilder.java @@ -452,7 +452,7 @@ public final class FopFactoryBuilder { return isComplexScript; } - public Map getHyphPatNames() { + public Map getHyphenationPatternNames() { return hyphPatNames; } } diff --git a/src/java/org/apache/fop/apps/FopFactoryConfig.java b/src/java/org/apache/fop/apps/FopFactoryConfig.java index 1ef958fae..2545eea5e 100644 --- a/src/java/org/apache/fop/apps/FopFactoryConfig.java +++ b/src/java/org/apache/fop/apps/FopFactoryConfig.java @@ -126,5 +126,6 @@ public interface FopFactoryConfig { boolean isComplexScriptFeaturesEnabled(); - Map getHyphPatNames(); + /** @see {@link FopFactory#getHyphenationPatternNames()} */ + Map getHyphenationPatternNames(); } diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java index 56c534f90..5b8145432 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java @@ -1399,7 +1399,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager Hyphenation hyph = Hyphenator.hyphenate(hyphenationProperties.language.getString(), hyphenationProperties.country.getString(), getFObj().getUserAgent().getResourceResolver(), - getFObj().getUserAgent().getHyphPatNames(), + getFObj().getUserAgent().getHyphenationPatternNames(), sbChars.toString(), hyphenationProperties.hyphenationRemainCharacterCount.getValue(), hyphenationProperties.hyphenationPushCharacterCount.getValue()); diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java b/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java index b03e35971..ab6411b3a 100644 --- a/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java +++ b/test/java/org/apache/fop/fotreetest/FOTreeTestCase.java @@ -275,9 +275,8 @@ public class FOTreeTestCase { return delegate.isComplexScriptFeaturesEnabled(); } - public Map getHyphPatNames() { - return delegate.getHyphPatNames(); + public Map getHyphenationPatternNames() { + return delegate.getHyphenationPatternNames(); } } - } -- cgit v1.2.3 From cd11fac7e67a229c85f7edff5f56ebd43f434732 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Wed, 4 Jul 2012 13:27:27 +0000 Subject: Removed limitations that were lifted after the work on the Temp_TrueTypeInPostScript branch git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1357248 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/trunk/output.xml | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index cabbbb0fa..7c4ace72e 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -331,8 +331,6 @@ out = proc.getOutputStream();]]> Limitations
  • Images and SVG may not be displayed correctly. SVG support is far from being complete. No image transparency is available.
  • -
  • Only Type 1 fonts are supported.
  • -
  • Multibyte characters are not supported.
  • PPD support is still missing.
-- cgit v1.2.3