You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by sp...@apache.org on 2011/07/22 10:36:18 UTC

svn commit: r1149498 - in /xmlgraphics/fop/branches/Temp_ComplexScripts: ./ src/documentation/ src/java/org/apache/fop/afp/ src/java/org/apache/fop/afp/apps/ src/java/org/apache/fop/afp/parser/ src/java/org/apache/fop/fonts/ src/java/org/apache/fop/fon...

Author: spepping
Date: Fri Jul 22 08:36:15 2011
New Revision: 1149498

URL: http://svn.apache.org/viewvc?rev=1149498&view=rev
Log:
Merged /xmlgraphics/fop/trunk:r1136000-1149493

Added:
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/EventProducingFilter.java
      - copied unchanged from r1149493, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/intermediate/EventProducingFilter.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/test/layoutengine/standard-testcases/inline_empty.xml
      - copied unchanged from r1149493, xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/inline_empty.xml
Modified:
    xmlgraphics/fop/branches/Temp_ComplexScripts/   (props changed)
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/documentation/skinconf.xml
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/AFPResourceManager.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/apps/   (props changed)
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/parser/   (props changed)
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SingleByteFont.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/AFMFile.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.xml
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererFactory.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java
    xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/util/ColorExt.java   (props changed)
    xmlgraphics/fop/branches/Temp_ComplexScripts/status.xml

Propchange: xmlgraphics/fop/branches/Temp_ComplexScripts/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 22 08:36:15 2011
@@ -2,4 +2,4 @@
 /xmlgraphics/fop/branches/Temp_Color:956535-1069429
 /xmlgraphics/fop/branches/fop-0_95:684572,688085,688696
 /xmlgraphics/fop/branches/fop-1_0:959975-964707
-/xmlgraphics/fop/trunk:981451-1135999
+/xmlgraphics/fop/trunk:981451-1149493

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/documentation/skinconf.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/documentation/skinconf.xml?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/documentation/skinconf.xml (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/documentation/skinconf.xml Fri Jul 22 08:36:15 2011
@@ -15,20 +15,20 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-
 <!--
 Skin configuration file. This file contains details of your project,
 which will be used to configure the chosen Forrest skin.
--->
 
-<!DOCTYPE skinconfig PUBLIC "-//APACHE//DTD Skin Configuration V0.6-3//EN" "http://forrest.apache.org/dtd/skinconfig-v06-3.dtd">
+Explanation of some elements has been removed from this file.
+See main/fresh-site/src/documentation/skinconf.xml for details.
+-->
+<!DOCTYPE skinconfig PUBLIC "-//APACHE//DTD Skin Configuration V0.8-2//EN" "http://forrest.apache.org/dtd/skinconfig-v08-2.dtd">
 <skinconfig>
-  <!-- To enable lucene search add provider="lucene" (default is google).
+<!-- To enable lucene search add provider="lucene"
     Add box-location="alt" to move the search box to an alternate location
     (if the skin supports it) and box-location="all" to show it in all
     available locations on the page.  Remove the <search> element to show
-    no search box. @domain will enable sitesearch for the specific domain with google.
-    In other words google will search the @domain for the query string.
+    no search box.
   -->
   <search name="Apache FOP" domain="xmlgraphics.apache.org" provider="google"/>
 
@@ -60,8 +60,7 @@ which will be used to configure the chos
   <!-- Render mailto: links unrecognisable by spam harvesters? -->
   <obfuscate-mail-links>true</obfuscate-mail-links>
   <obfuscate-mail-value>.at.</obfuscate-mail-value>
-
-  <!-- Disable the javascript facility to change the font size -->
+<!-- Disable the javascript facility to change the font size -->
   <disable-font-script>false</disable-font-script>
 
   <!-- mandatory project logo
@@ -86,16 +85,21 @@ which will be used to configure the chos
        default skin: renders it at the bottom-left corner -->
   <host-url></host-url>
   <host-logo></host-logo>
-
-  <!-- relative url of a favicon file, normally favicon.ico -->
-  <favicon-url></favicon-url>
-
-  <!-- The following used to construct a copyright statement -->
-  <year>1999-2009</year>
-  <vendor>The Apache Software Foundation.</vendor>
+<!-- relative url of a favicon file, normally favicon.ico -->
+  <favicon-url>favicon.ico</favicon-url>
+<!-- The following used to construct a copyright statement -->
+  <!-- <year>1999-2011</year> -->
+  <year inception="true">1999</year>
+  <vendor>The Apache Software Foundation. Licensed under Apache License 2.0</vendor>
   <copyright-link>http://www.apache.org/licenses/</copyright-link>
-  
-  <!-- Some skins use this to form a 'breadcrumb trail' of links.
+<!-- Optional text trademark statement below the copyright statement -->
+  <trademark-statement>
+    Apache, Apache Forrest, the Apache feather logo, and the Apache Forrest
+    logos are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
+  </trademark-statement>
+<!-- Some skins use this to form a 'breadcrumb trail' of links.
+    If you don't want these, then set the attributes to blank.
+    The DTD purposefully requires them.
     Use location="alt" to move the trail to an alternate location
     (if the skin supports it).
           Omit the location attribute to display the trail in the default location.
@@ -106,8 +110,7 @@ which will be used to configure the chos
     <link1 name="The Apache Software Foundation" href="http://www.apache.org/"/>
     <link2 name="Apache XML Graphics Project" href="http://xmlgraphics.apache.org/"/>
   </trail>
-
-  <!-- Configure the TOC, i.e. the Table of Contents.
+<!-- Configure the TOC, i.e. the Table of Contents.
   @max-depth
    how many "section" levels need to be included in the
    generated Table of Contents (TOC). 
@@ -117,8 +120,7 @@ which will be used to configure the chos
    Where to show the TOC.
   -->
   <toc max-depth="2" min-sections="1" location="page"/>
-
-  <!-- Heading types can be clean|underlined|boxed  -->
+<!-- Heading types can be clean|underlined|boxed  -->
   <headings type="underlined"/>
   
   <!-- The optional feedback element will be used to construct a
@@ -166,7 +168,6 @@ which will be used to configure the chos
     .menuitemgroup{ display: block;}
 
   </extra-css>
-
   <colors>
   <!-- These values are used for the generated CSS files. -->
 
@@ -301,10 +302,9 @@ which will be used to configure the chos
     <color name="footer" value="#E5E4D9"/>
 -->
   </colors>
- 
-  <!-- Settings specific to PDF output. -->
+<!-- Settings specific to PDF output.  -->
   <pdf>
-    <!-- 
+<!-- 
        Supported page sizes are a0, a1, a2, a3, a4, a5, executive,
        folio, legal, ledger, letter, quarto, tabloid (default letter).
        Supported page orientations are portrait, landscape (default
@@ -312,7 +312,7 @@ which will be used to configure the chos
        Supported text alignments are left, right, justify (default left).
     -->
     <page size="letter" orientation="portrait" text-align="justify"/>
-    <page-numbering-format>1</page-numbering-format>
+    <page-numbering-format>Page 1/1</page-numbering-format>
     <!--
        Margins can be specified for top, bottom, inner, and outer
        edges. If double-sided="false", the inner edge is always left
@@ -327,8 +327,7 @@ which will be used to configure the chos
       <inner>1in</inner>
       <outer>0.5in</outer>
     </margins>
-
-    <!--
+<!--
       Print the URL text next to all links going outside the file
     -->
     <show-external-urls>false</show-external-urls>
@@ -341,8 +340,7 @@ which will be used to configure the chos
     -->
     <disable-copyright-footer>false</disable-copyright-footer>
   </pdf>
-
-  <!-- 
+<!-- 
     Credits are typically rendered as a set of small clickable
     images in the page footer.
     
@@ -377,15 +375,13 @@ which will be used to configure the chos
       <height>125</height>
     </credit>
     -->
-    <!--
     <credit box-location="alt2">
-      <name>ApacheCon US 2009</name>
-      <url>http://us.apachecon.com/</url>
-      <image>http://apache.org/ads/ApacheCon/2009-usa-125x125.png</image>
+      <name>ApacheCon NA 2011</name>
+      <url>http://www.apachecon.com/</url>
+      <image>http://apache.org/ads/ApacheCon/2011-na-125x125.png</image>
       <width>125</width>
       <height>125</height>
     </credit>
-    -->
     
     <credit role="pdf">
       <name>PDF created by Apache FOP</name>

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/AFPResourceManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/AFPResourceManager.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/AFPResourceManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/AFPResourceManager.java Fri Jul 22 08:36:15 2011
@@ -66,10 +66,12 @@ public class AFPResourceManager {
     private int instreamObjectCount = 0;
 
     /** a mapping of resourceInfo --> include name */
-    private final Map/*<AFPResourceInfo,String>*/ includeNameMap
-        = new java.util.HashMap()/*<AFPResourceInfo,String>*/;
+    private final Map<AFPResourceInfo, String> includeNameMap
+        = new java.util.HashMap<AFPResourceInfo, String>();
 
-    private Map pageSegmentMap = new java.util.HashMap();
+    /** a mapping of resourceInfo --> page segment name */
+    private Map<AFPResourceInfo, String> pageSegmentMap
+        = new java.util.HashMap<AFPResourceInfo, String>();
 
     private AFPResourceLevelDefaults resourceLevelDefaults = new AFPResourceLevelDefaults();
 
@@ -126,32 +128,49 @@ public class AFPResourceManager {
     }
 
     /**
-     * Creates a new data object in the AFP datastream
-     *
+     * Tries to create an include of a data object that has been previously added to the
+     * AFP data stream. If no such object was available, the method returns false which serves
+     * as a signal that the object has to be created.
      * @param dataObjectInfo the data object info
-     *
+     * @return true if the inclusion succeeded, false if the object was not available
      * @throws IOException thrown if an I/O exception of some sort has occurred.
      */
-    public void createObject(AFPDataObjectInfo dataObjectInfo) throws IOException {
-        AbstractNamedAFPObject namedObj = null;
-
+    public boolean tryIncludeObject(AFPDataObjectInfo dataObjectInfo) throws IOException {
         AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
         updateResourceInfoUri(resourceInfo);
 
-        String objectName = (String)includeNameMap.get(resourceInfo);
+        String objectName = includeNameMap.get(resourceInfo);
         if (objectName != null) {
             // an existing data resource so reference it by adding an include to the current page
             includeObject(dataObjectInfo, objectName);
-            return;
+            return true;
         }
 
-        objectName = (String)pageSegmentMap.get(resourceInfo);
+        objectName = pageSegmentMap.get(resourceInfo);
         if (objectName != null) {
             // an existing data resource so reference it by adding an include to the current page
             includePageSegment(dataObjectInfo, objectName);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Creates a new data object in the AFP datastream
+     *
+     * @param dataObjectInfo the data object info
+     *
+     * @throws IOException thrown if an I/O exception of some sort has occurred.
+     */
+    public void createObject(AFPDataObjectInfo dataObjectInfo) throws IOException {
+        if (tryIncludeObject(dataObjectInfo)) {
+            //Object has already been produced and is available by inclusion, so return early.
             return;
         }
 
+        AbstractNamedAFPObject namedObj = null;
+        AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
+
         boolean useInclude = true;
         Registry.ObjectType objectType = null;
 
@@ -194,7 +213,7 @@ public class AFPResourceManager {
             resourceGroup.addObject(namedObj);
 
             // create the include object
-            objectName = namedObj.getName();
+            String objectName = namedObj.getName();
             if (usePageSegment) {
                 includePageSegment(dataObjectInfo, objectName);
                 pageSegmentMap.put(resourceInfo, objectName);
@@ -296,7 +315,7 @@ public class AFPResourceManager {
         resourceInfo.setName(resourceName);
         resourceInfo.setUri(uri.toASCIIString());
 
-        String objectName = (String)includeNameMap.get(resourceInfo);
+        String objectName = includeNameMap.get(resourceInfo);
         if (objectName == null) {
             if (log.isDebugEnabled()) {
                 log.debug("Adding included resource: " + resourceName);
@@ -334,7 +353,7 @@ public class AFPResourceManager {
         resourceInfo.setName(resourceName);
         resourceInfo.setUri(uri.toASCIIString());
 
-        String resource = (String)includeNameMap.get(resourceInfo);
+        String resource = includeNameMap.get(resourceInfo);
         if (resource == null) {
 
             ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel);
@@ -343,6 +362,7 @@ public class AFPResourceManager {
             //The included resource may already be wrapped in a resource object
             AbstractNamedAFPObject resourceObject = new AbstractNamedAFPObject(null) {
 
+                @Override
                 protected void writeContent(OutputStream os) throws IOException {
                     InputStream inputStream = null;
                     try {
@@ -355,8 +375,10 @@ public class AFPResourceManager {
                 }
 
                 //bypass super.writeStart
+                @Override
                 protected void writeStart(OutputStream os) throws IOException { }
                 //bypass super.writeEnd
+                @Override
                 protected void writeEnd(OutputStream os) throws IOException { }
             };
 

Propchange: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/apps/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 22 08:36:15 2011
@@ -3,4 +3,4 @@
 /xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/afp/apps:956535-1069429
 /xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/afp/apps:684572,688085,688696
 /xmlgraphics/fop/branches/fop-1_0/src/java/org/apache/fop/afp/apps:959975-964707
-/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/apps:959946-1135999
+/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/apps:959946-1149493

Propchange: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/afp/parser/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 22 08:36:15 2011
@@ -3,4 +3,4 @@
 /xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/afp/parser:956535-1069429
 /xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/afp/parser:684572,688085,688696
 /xmlgraphics/fop/branches/fop-1_0/src/java/org/apache/fop/afp/parser:959975-964707
-/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/parser:959946-1135999
+/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/parser:959946-1149493

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java Fri Jul 22 08:36:15 2011
@@ -20,12 +20,11 @@
 package org.apache.fop.fonts;
 
 import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
 
-import org.apache.fop.util.CharUtilities;
 import org.apache.xmlgraphics.fonts.Glyphs;
 
+import org.apache.fop.util.CharUtilities;
+
 /**
  * Abstract base class for code point mapping classes (1-byte character encodings).
  */
@@ -37,8 +36,6 @@ public class AbstractCodePointMapping im
     private char[] codepoints;
     private char[] unicodeMap; //code point to Unicode char
     private String[] charNameMap; //all character names in the encoding
-    //Here we accumulate all mappings we have found through substitution
-    private Map<Character, Character> fallbackMap;
 
     /**
      * Main constructor.
@@ -141,44 +138,9 @@ public class AbstractCodePointMapping im
                 bot = mid + 1;
             }
         }
-
-        //Fallback: using cache
-        synchronized (this) {
-            if (fallbackMap != null) {
-                Character fallback = fallbackMap.get(new Character(c));
-                if (fallback != null) {
-                    return fallback.charValue();
-                }
-            }
-        }
-        //Fallback: find alternatives (slow!)
-        String glyphName = Glyphs.charToGlyphName(c);
-        if (glyphName.length() > 0) {
-            String[] alternatives = Glyphs.getCharNameAlternativesFor(glyphName);
-            if (alternatives != null) {
-                for (int i = 0, ic = alternatives.length; i < ic; i++) {
-                    int idx = getCodePointForGlyph(alternatives[i]);
-                    if (idx >= 0) {
-                        putFallbackCharacter(c, (char)idx);
-                        return (char)idx;
-                    }
-                }
-            }
-        }
-
-        putFallbackCharacter(c, NOT_FOUND_CODE_POINT);
         return NOT_FOUND_CODE_POINT;
     }
 
-    private void putFallbackCharacter(char c, char mapTo) {
-        synchronized (this) {
-            if (this.fallbackMap == null) {
-                this.fallbackMap = new HashMap<Character, Character>();
-            }
-            this.fallbackMap.put(new Character(c), new Character(mapTo));
-        }
-    }
-
     /**
      * Returns the main Unicode value that is associated with the given code point in the encoding.
      * Note that multiple Unicode values can theoretically be mapped to one code point in the

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java Fri Jul 22 08:36:15 2011
@@ -25,9 +25,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.fop.util.CharUtilities;
 import org.apache.xmlgraphics.fonts.Glyphs;
 
+import org.apache.fop.util.CharUtilities;
+
 /**
  * A simple implementation of the OneByteEncoding mostly used for encodings that are constructed
  * on-the-fly.
@@ -53,7 +54,7 @@ public class SimpleSingleByteEncoding im
 
     /** {@inheritDoc} */
     public char mapChar(char c) {
-        Character nc = charMap.get(new Character(c));
+        Character nc = charMap.get(Character.valueOf(c));
         if (nc != null) {
             return nc.charValue();
         }
@@ -118,7 +119,7 @@ public class SimpleSingleByteEncoding im
         }
         char newSlot = (char)(getLastChar() + 1);
         this.mapping.add(ch);
-        this.charMap.put(new Character(ch.getSingleUnicodeValue()), new Character(newSlot));
+        this.charMap.put(Character.valueOf(ch.getSingleUnicodeValue()), Character.valueOf(newSlot));
         return newSlot;
     }
 

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/SingleByteFont.java Fri Jul 22 08:36:15 2011
@@ -81,7 +81,7 @@ public class SingleByteFont extends Cust
         if (i < 256) {
             int idx = i - getFirstChar();
             if (idx >= 0 && idx < width.length) {
-                return size * width[i - getFirstChar()];
+                return size * width[idx];
             }
         } else if (this.additionalEncodings != null) {
             int encodingIndex = (i / 256) - 1;
@@ -89,7 +89,7 @@ public class SingleByteFont extends Cust
             int codePoint = i % 256;
             NamedCharacter nc = encoding.getCharacterForIndex(codePoint);
             UnencodedCharacter uc
-                = this.unencodedCharacters.get(new Character(nc.getSingleUnicodeValue()));
+                = this.unencodedCharacters.get(Character.valueOf(nc.getSingleUnicodeValue()));
             return size * uc.getWidth();
         }
         return 0;
@@ -172,7 +172,7 @@ public class SingleByteFont extends Cust
 
     private char mapUnencodedChar(char ch) {
         if (this.unencodedCharacters != null) {
-            UnencodedCharacter unencoded = this.unencodedCharacters.get(new Character(ch));
+            UnencodedCharacter unencoded = this.unencodedCharacters.get(Character.valueOf(ch));
             if (unencoded != null) {
                 if (this.additionalEncodings == null) {
                     this.additionalEncodings = new ArrayList<SimpleSingleByteEncoding>();
@@ -294,7 +294,7 @@ public class SingleByteFont extends Cust
         }
         if (ch.hasSingleUnicodeValue()) {
             UnencodedCharacter uc = new UnencodedCharacter(ch, width);
-            this.unencodedCharacters.put(new Character(ch.getSingleUnicodeValue()), uc);
+            this.unencodedCharacters.put(Character.valueOf(ch.getSingleUnicodeValue()), uc);
         } else {
             //Cannot deal with unicode sequences, so ignore this character
         }
@@ -362,7 +362,7 @@ public class SingleByteFont extends Cust
         for (int i = 0, c = arr.length; i < c; i++) {
             NamedCharacter nc = enc.getCharacterForIndex(enc.getFirstChar() + i);
             UnencodedCharacter uc = this.unencodedCharacters.get(
-                    new Character(nc.getSingleUnicodeValue()));
+                    Character.valueOf(nc.getSingleUnicodeValue()));
             arr[i] = uc.getWidth();
         }
         return arr;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/AFMFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/AFMFile.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/AFMFile.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/AFMFile.java Fri Jul 22 08:36:15 2011
@@ -22,10 +22,12 @@ package org.apache.fop.fonts.type1;
 import java.awt.geom.Dimension2D;
 import java.awt.geom.RectangularShape;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.apache.xmlgraphics.java2d.Dimension2DDouble;
 
 import org.apache.fop.fonts.NamedCharacter;
@@ -36,6 +38,9 @@ import org.apache.fop.fonts.SingleByteEn
  */
 public class AFMFile {
 
+    /** logging instance */
+    private static final Log LOG = LogFactory.getLog(AFMFile.class);
+
     private String fontName;
     private String fullName;
     private String familyName;
@@ -56,15 +61,13 @@ public class AFMFile {
     private AFMWritingDirectionMetrics[] writingDirectionMetrics
         = new AFMWritingDirectionMetrics[3];
 
-    private List charMetrics = new java.util.ArrayList();
-    //List<AFMCharMetrics>
-    private Map charNameToMetrics = new java.util.HashMap();
-    //Map<String, AFMCharMetrics>
+    private List<AFMCharMetrics> charMetrics = new java.util.ArrayList<AFMCharMetrics>();
+    private Map<String, AFMCharMetrics> charNameToMetrics
+                = new java.util.HashMap<String, AFMCharMetrics>();
     private int firstChar = -1;
     private int lastChar = -1;
 
-    private Map kerningMap;
-    //Map<String, Map<String, Dimension2D>>
+    private Map<String, Map<String, Dimension2D>> kerningMap;
 
     /**
      * Default constructor.
@@ -365,14 +368,14 @@ public class AFMFile {
      * @return the character metrics or null if there's no such character
      */
     public AFMCharMetrics getChar(String name) {
-        return (AFMCharMetrics)this.charNameToMetrics.get(name);
+        return this.charNameToMetrics.get(name);
     }
 
     /**
      * Returns the list of AFMCharMetrics instances representing all the available characters.
      * @return a List of AFMCharMetrics instances
      */
-    public List getCharMetrics() {
+    public List<AFMCharMetrics> getCharMetrics() {
         return Collections.unmodifiableList(this.charMetrics);
     }
 
@@ -384,11 +387,11 @@ public class AFMFile {
      */
     public void addXKerning(String name1, String name2, double kx) {
         if (this.kerningMap == null) {
-            this.kerningMap = new java.util.HashMap();
+            this.kerningMap = new java.util.HashMap<String, Map<String, Dimension2D>>();
         }
-        Map entries = (Map)this.kerningMap.get(name1);
+        Map<String, Dimension2D> entries = this.kerningMap.get(name1);
         if (entries == null) {
-            entries = new java.util.HashMap();
+            entries = new java.util.HashMap<String, Dimension2D>();
             this.kerningMap.put(name1, entries);
         }
         entries.put(name2, new Dimension2DDouble(kx, 0));
@@ -406,40 +409,37 @@ public class AFMFile {
      * Creates and returns a kerning map for writing mode 0 (ltr) with character codes.
      * @return the kerning map or null if there is no kerning information.
      */
-    public Map createXKerningMapEncoded() {
+    public Map<Integer, Map<Integer, Integer>> createXKerningMapEncoded() {
         if (!hasKerning()) {
             return null;
         }
-        Map m = new java.util.HashMap();
-        Iterator iterFrom = this.kerningMap.entrySet().iterator();
-        while (iterFrom.hasNext()) {
-            Map.Entry entryFrom = (Map.Entry)iterFrom.next();
-            String name1 = (String)entryFrom.getKey();
+        Map<Integer, Map<Integer, Integer>> m
+                    = new java.util.HashMap<Integer, Map<Integer, Integer>>();
+        for (Map.Entry<String, Map<String, Dimension2D>> entryFrom : this.kerningMap.entrySet()) {
+            String name1 = entryFrom.getKey();
             AFMCharMetrics chm1 = getChar(name1);
             if (chm1 == null || !chm1.hasCharCode()) {
                 continue;
             }
-            Map container = null;
-            Map entriesTo = (Map)entryFrom.getValue();
-            Iterator iterTo = entriesTo.entrySet().iterator();
-            while (iterTo.hasNext()) {
-                Map.Entry entryTo = (Map.Entry)iterTo.next();
-                String name2 = (String)entryTo.getKey();
+            Map<Integer, Integer> container = null;
+            Map<String, Dimension2D> entriesTo = entryFrom.getValue();
+            for (Map.Entry<String, Dimension2D> entryTo : entriesTo.entrySet()) {
+                String name2 = entryTo.getKey();
                 AFMCharMetrics chm2 = getChar(name2);
                 if (chm2 == null || !chm2.hasCharCode()) {
                     continue;
                 }
                 if (container == null) {
-                    Integer k1 = new Integer(chm1.getCharCode());
-                    container = (Map)m.get(k1);
+                    Integer k1 = Integer.valueOf(chm1.getCharCode());
+                    container = m.get(k1);
                     if (container == null) {
-                        container = new java.util.HashMap();
+                        container = new java.util.HashMap<Integer, Integer>();
                         m.put(k1, container);
                     }
                 }
-                Dimension2D dim = (Dimension2D)entryTo.getValue();
-                container.put(new Integer(chm2.getCharCode()),
-                        new Integer((int)Math.round(dim.getWidth())));
+                Dimension2D dim = entryTo.getValue();
+                container.put(Integer.valueOf(chm2.getCharCode()),
+                        Integer.valueOf((int)Math.round(dim.getWidth())));
             }
         }
         return m;
@@ -451,14 +451,41 @@ public class AFMFile {
      * @param encoding the encoding to replace the one given in the AFM
      */
     public void overridePrimaryEncoding(SingleByteEncoding encoding) {
-        Iterator iter = this.charMetrics.iterator();
-        while (iter.hasNext()) {
-            AFMCharMetrics cm = (AFMCharMetrics)iter.next();
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Overriding primary encoding of " + getFontName() + " with: " + encoding);
+        }
+        AFMCharMetrics[] mapped = new AFMCharMetrics[256];
+        for (AFMCharMetrics cm : this.charMetrics) {
             NamedCharacter nc = cm.getCharacter();
             if (nc.hasSingleUnicodeValue()) {
-                int mapped = encoding.mapChar(nc.getSingleUnicodeValue());
-                if (mapped > 0) {
-                    cm.setCharCode(mapped);
+                int codePoint = encoding.mapChar(nc.getSingleUnicodeValue());
+                if (codePoint > 0) {
+                    if (mapped[codePoint] != null) {
+                        if (LOG.isDebugEnabled()) {
+                            AFMCharMetrics other = mapped[codePoint];
+                            String msg = "Not mapping character " + nc + " to code point "
+                                + codePoint + " (" + Integer.toHexString(codePoint) + ") in "
+                                + encoding + ". "
+                                + other + " has already been assigned that code point.";
+                            if (other.getUnicodeSequence()
+                                    .equals(nc.getUnicodeSequence())) {
+                                msg += " This is a specialized glyph for the"
+                                    + " same Unicode character.";
+                                //TODO should these be mapped to a private Unicode area to make
+                                //them accessible?
+                            } else {
+                                msg += " This is a similar character.";
+                            }
+                            if (cm.getWidthX() != other.getWidthX()) {
+                                msg += " They have differing widths: "
+                                    + cm.getWidthX() + " vs. " + other.getWidthX();
+                            }
+                            LOG.debug(msg);
+                        }
+                    } else {
+                        cm.setCharCode(codePoint);
+                        mapped[codePoint] = cm;
+                    }
                 } else {
                     cm.setCharCode(-1);
                 }
@@ -470,6 +497,7 @@ public class AFMFile {
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         return "AFM: " + getFullName();
     }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java Fri Jul 22 08:36:15 2011
@@ -65,6 +65,7 @@ public class Type1FontLoader extends Fon
     private static final String[] AFM_EXTENSIONS = new String[] {".AFM", ".afm", ".Afm"};
 
     /** {@inheritDoc} */
+    @Override
     protected void read() throws IOException {
         AFMFile afm = null;
         PFMFile pfm = null;
@@ -173,10 +174,10 @@ public class Type1FontLoader extends Fon
         }
     }
 
-    private Set toGlyphSet(String[] glyphNames) {
-        Set glyphSet = new java.util.HashSet();
-        for (int i = 0, c = glyphNames.length; i < c; i++) {
-            glyphSet.add(glyphNames[i]);
+    private Set<String> toGlyphSet(String[] glyphNames) {
+        Set<String> glyphSet = new java.util.HashSet<String>();
+        for (String name : glyphNames) {
+            glyphSet.add(name);
         }
         return glyphSet;
     }
@@ -188,10 +189,9 @@ public class Type1FontLoader extends Fon
      */
     private void addUnencodedBasedOnEncoding(AFMFile afm) {
         SingleByteEncoding encoding = singleFont.getEncoding();
-        Set glyphNames = toGlyphSet(encoding.getCharNameMap());
-        List charMetrics = afm.getCharMetrics();
-        for (int i = 0, c = afm.getCharCount(); i < c; i++) {
-            AFMCharMetrics metrics = (AFMCharMetrics)charMetrics.get(i);
+        Set<String> glyphNames = toGlyphSet(encoding.getCharNameMap());
+        List<AFMCharMetrics> charMetrics = afm.getCharMetrics();
+        for (AFMCharMetrics metrics : charMetrics) {
             String charName = metrics.getCharName();
             if (charName != null && !glyphNames.contains(charName)) {
                 singleFont.addUnencodedCharacter(metrics.getCharacter(),
@@ -357,9 +357,7 @@ public class Type1FontLoader extends Fon
 
             returnFont.setFirstChar(afm.getFirstChar());
             returnFont.setLastChar(afm.getLastChar());
-            Iterator iter = afm.getCharMetrics().iterator();
-            while (iter.hasNext()) {
-                AFMCharMetrics chm = (AFMCharMetrics)iter.next();
+            for (AFMCharMetrics chm : afm.getCharMetrics()) {
                 if (chm.hasCharCode()) {
                     singleFont.setWidth(chm.getCharCode(), (int)Math.round(chm.getWidthX()));
                 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Fri Jul 22 08:36:15 2011
@@ -680,8 +680,8 @@ public class LineLayoutManager extends I
 
         Paragraph lastPar = null;
 
-        InlineLevelLayoutManager curLM = (InlineLevelLayoutManager) getChildLM();
-        while (curLM != null) {
+        InlineLevelLayoutManager curLM;
+        while ((curLM = (InlineLevelLayoutManager) getChildLM()) != null) {
             List inlineElements = curLM.getNextKnuthElements(inlineLC, effectiveAlignment);
             if (inlineElements == null || inlineElements.size() == 0) {
                 /* curLM.getNextKnuthElements() returned null or an empty list;
@@ -778,7 +778,6 @@ public class LineLayoutManager extends I
                     }
                 }
             } // end of loop over returnedList
-            curLM = (InlineLevelLayoutManager) getChildLM();
         }
 
         if (lastPar != null) {
@@ -1180,6 +1179,7 @@ public class LineLayoutManager extends I
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getChangedKnuthElements(List oldList, int alignment) {
         List<KnuthElement> returnList = new LinkedList<KnuthElement>();
         for (int p = 0; p < knuthParagraphs.size(); p++) {
@@ -1450,7 +1450,7 @@ public class LineLayoutManager extends I
     private void addInlineArea(LayoutContext context, LineBreakPosition lbp,
             boolean isLastPosition) {
 
-        KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(lbp.parIndex);
+        KnuthSequence seq = knuthParagraphs.get(lbp.parIndex);
         int startElementIndex = lbp.startIndex;
         int endElementIndex = lbp.getLeafPos();
 

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.java Fri Jul 22 08:36:15 2011
@@ -53,4 +53,11 @@ public interface RendererEventProducer e
      * @event.severity ERROR
      */
     void ioError(Object source, IOException ioe);
+
+    /**
+     * Triggered at the end of page rendering.
+     * @param source the event source
+     * @param number the page number
+     */
+    void endPage(Object source, int number);
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.xml?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.xml (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererEventProducer.xml Fri Jul 22 08:36:15 2011
@@ -18,4 +18,5 @@
 <!-- $Id$ -->
 <catalogue xml:lang="en">
   <message key="ioError">I/O error while writing to target file.[ Reason: {ioe}]</message>
+  <message key="endPage">Rendered page #{number}.</message>
 </catalogue>

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererFactory.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/RendererFactory.java Fri Jul 22 08:36:15 2011
@@ -35,6 +35,7 @@ import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.area.AreaTreeHandler;
 import org.apache.fop.fo.FOEventHandler;
 import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
+import org.apache.fop.render.intermediate.EventProducingFilter;
 import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
 import org.apache.fop.render.intermediate.IFRenderer;
@@ -389,7 +390,7 @@ public class RendererFactory {
         if (configurator != null) {
             configurator.configure(documentHandler);
         }
-        return documentHandler;
+        return new EventProducingFilter(documentHandler, userAgent);
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java Fri Jul 22 08:36:15 2011
@@ -83,9 +83,6 @@ public class AFPDocumentHandler extends 
     private Map<String, PageSegmentDescriptor> pageSegmentMap
         = new java.util.HashMap<String, PageSegmentDescriptor>();
 
-    /** Medium Map referenced on previous page **/
-    private String lastMediumMap;
-
     private static enum Location {
         ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER
     }
@@ -379,9 +376,8 @@ public class AFPDocumentHandler extends 
             }
             AFPInvokeMediumMap imm = (AFPInvokeMediumMap)extension;
             String mediumMap = imm.getName();
-            if (mediumMap != null && !mediumMap.equals(lastMediumMap)) {
+            if (mediumMap != null) {
                 dataStream.createInvokeMediumMap(mediumMap);
-                lastMediumMap = mediumMap;
             }
         } else if (extension instanceof AFPIncludeFormMap) {
             AFPIncludeFormMap formMap = (AFPIncludeFormMap)extension;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java Fri Jul 22 08:36:15 2011
@@ -68,226 +68,6 @@ public class AFPImageHandlerRenderedImag
         ImageFlavor.RENDERED_IMAGE
     };
 
-    private AFPDataObjectInfo updateDataObjectInfo              // CSOK: MethodLength
-        (AFPImageObjectInfo imageObjectInfo,
-         AFPPaintingState paintingState, ImageRendered imageRendered, Dimension targetSize)
-        throws IOException {
-
-        long start = System.currentTimeMillis();
-
-        int resolution = paintingState.getResolution();
-        int maxPixelSize = paintingState.getBitsPerPixel();
-        if (paintingState.isColorImages()) {
-            if (paintingState.isCMYKImagesSupported()) {
-                maxPixelSize *= 4; //CMYK is maximum
-            } else {
-                maxPixelSize *= 3; //RGB is maximum
-            }
-        }
-        float ditheringQuality = paintingState.getDitheringQuality();
-        RenderedImage renderedImage = imageRendered.getRenderedImage();
-
-        ImageInfo imageInfo = imageRendered.getInfo();
-        ImageSize intrinsicSize = imageInfo.getSize();
-
-        boolean useFS10 = (maxPixelSize == 1) || BitmapImageUtil.isMonochromeImage(renderedImage);
-        int functionSet = useFS10 ? 10 : 11;
-        boolean usePageSegments = useFS10
-                    && !imageObjectInfo.getResourceInfo().getLevel().isInline();
-
-        ImageSize effIntrinsicSize = intrinsicSize;
-        if (usePageSegments) {
-            //Resize, optionally resample and convert image
-            Dimension resampledDim = new Dimension(
-                    (int)Math.ceil(UnitConv.mpt2px(targetSize.getWidth(), resolution)),
-                    (int)Math.ceil(UnitConv.mpt2px(targetSize.getHeight(), resolution)));
-
-            imageObjectInfo.setCreatePageSegment(true);
-            imageObjectInfo.getResourceInfo().setImageDimension(resampledDim);
-
-            //Only resample/downsample if image is smaller than its intrinsic size
-            //to make print file smaller
-            boolean resample = resampledDim.width < renderedImage.getWidth()
-                && resampledDim.height < renderedImage.getHeight();
-            if (resample) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Resample from " + intrinsicSize.getDimensionPx()
-                            + " to " + resampledDim);
-                }
-                renderedImage = BitmapImageUtil.convertToMonochrome(renderedImage,
-                        resampledDim, ditheringQuality);
-                effIntrinsicSize = new ImageSize(
-                        resampledDim.width, resampledDim.height, resolution);
-            } else if (ditheringQuality >= 0.5f) {
-                renderedImage = BitmapImageUtil.convertToMonochrome(renderedImage,
-                        intrinsicSize.getDimensionPx(), ditheringQuality);
-            }
-        }
-
-        imageObjectInfo.setDataHeightRes((int)Math.round(
-                effIntrinsicSize.getDpiHorizontal() * 10));
-        imageObjectInfo.setDataWidthRes((int)Math.round(
-                effIntrinsicSize.getDpiVertical() * 10));
-
-        int dataHeight = renderedImage.getHeight();
-        imageObjectInfo.setDataHeight(dataHeight);
-
-        int dataWidth = renderedImage.getWidth();
-        imageObjectInfo.setDataWidth(dataWidth);
-
-        //TODO To reduce AFP file size, investigate using a compression scheme.
-        //Currently, all image data is uncompressed.
-        ColorModel cm = renderedImage.getColorModel();
-        if (log.isTraceEnabled()) {
-            log.trace("ColorModel: " + cm);
-        }
-        int pixelSize = cm.getPixelSize();
-        if (cm.hasAlpha()) {
-            pixelSize -= 8;
-        }
-
-        byte[] imageData = null;
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        boolean allowDirectEncoding = true;
-        if (allowDirectEncoding && (pixelSize <= maxPixelSize)) {
-            //Attempt to encode without resampling the image
-            ImageEncodingHelper helper = new ImageEncodingHelper(renderedImage, pixelSize == 32);
-            ColorModel encodedColorModel = helper.getEncodedColorModel();
-            boolean directEncode = true;
-            if (helper.getEncodedColorModel().getPixelSize() > maxPixelSize) {
-                directEncode = false; //pixel size needs to be reduced
-            }
-            if (BitmapImageUtil.getColorIndexSize(renderedImage) > 2) {
-                directEncode = false; //Lookup tables are not implemented, yet
-            }
-            if (useFS10
-                    && BitmapImageUtil.isMonochromeImage(renderedImage)
-                    && BitmapImageUtil.isZeroBlack(renderedImage)) {
-                directEncode = false;
-                //need a special method to invert the bit-stream since setting the subtractive mode
-                //in AFP alone doesn't seem to do the trick.
-                if (encodeInvertedBilevel(helper, imageObjectInfo, baos)) {
-                    imageData = baos.toByteArray();
-                }
-            }
-            if (directEncode) {
-                log.debug("Encoding image directly...");
-                imageObjectInfo.setBitsPerPixel(encodedColorModel.getPixelSize());
-                if (pixelSize == 32) {
-                    functionSet = 45; //IOCA FS45 required for CMYK
-                }
-
-                helper.encode(baos);
-                imageData = baos.toByteArray();
-            }
-        }
-        if (imageData == null) {
-            log.debug("Encoding image via RGB...");
-
-            //Convert image to 24bit RGB
-            ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baos);
-            imageData = baos.toByteArray();
-            imageObjectInfo.setBitsPerPixel(24);
-
-            boolean colorImages = paintingState.isColorImages();
-            imageObjectInfo.setColor(colorImages);
-
-            // convert to grayscale
-            if (!colorImages) {
-                log.debug("Converting RGB image to grayscale...");
-                baos.reset();
-                int bitsPerPixel = paintingState.getBitsPerPixel();
-                imageObjectInfo.setBitsPerPixel(bitsPerPixel);
-                //TODO this should be done off the RenderedImage to avoid buffering the
-                //intermediate 24bit image
-                ImageEncodingHelper.encodeRGBAsGrayScale(
-                      imageData, dataWidth, dataHeight, bitsPerPixel, baos);
-                imageData = baos.toByteArray();
-                if (bitsPerPixel == 1) {
-                    imageObjectInfo.setSubtractive(true);
-                }
-            }
-        }
-
-        switch (functionSet) {
-        case 10:
-            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS10);
-            break;
-        case 11:
-            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11);
-            break;
-        case 45:
-            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
-            break;
-        default:
-            throw new IllegalStateException("Invalid IOCA function set: " + functionSet);
-        }
-
-        imageObjectInfo.setData(imageData);
-
-        // set object area info
-        AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
-        objectAreaInfo.setWidthRes(resolution);
-        objectAreaInfo.setHeightRes(resolution);
-
-        if (log.isDebugEnabled()) {
-            long duration = System.currentTimeMillis() - start;
-            log.debug("Image encoding took " + duration + "ms.");
-        }
-
-        return imageObjectInfo;
-    }
-
-    /**
-     * Efficiently encodes a bi-level image in inverted form as a plain bit-stream.
-     * @param helper the image encoding helper used to analyze the image
-     * @param imageObjectInfo the AFP image object
-     * @param out the output stream
-     * @return true if the image was encoded, false if there was something prohibiting that
-     * @throws IOException if an I/O error occurs
-     */
-    private boolean encodeInvertedBilevel(ImageEncodingHelper helper,
-            AFPImageObjectInfo imageObjectInfo, OutputStream out) throws IOException {
-        RenderedImage renderedImage = helper.getImage();
-        if (!BitmapImageUtil.isMonochromeImage(renderedImage)) {
-            throw new IllegalStateException("This method only supports binary images!");
-        }
-        int tiles = renderedImage.getNumXTiles() * renderedImage.getNumYTiles();
-        if (tiles > 1) {
-            return false;
-        }
-        SampleModel sampleModel = renderedImage.getSampleModel();
-        SampleModel expectedSampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
-                renderedImage.getWidth(), renderedImage.getHeight(), 1);
-        if (!expectedSampleModel.equals(sampleModel)) {
-            return false; //Pixels are not packed
-        }
-
-        imageObjectInfo.setBitsPerPixel(1);
-
-        Raster raster = renderedImage.getTile(0, 0);
-        DataBuffer buffer = raster.getDataBuffer();
-        if (buffer instanceof DataBufferByte) {
-            DataBufferByte byteBuffer = (DataBufferByte)buffer;
-            log.debug("Encoding image as inverted bi-level...");
-            byte[] rawData = byteBuffer.getData();
-            int remaining = rawData.length;
-            int pos = 0;
-            byte[] data = new byte[4096];
-            while (remaining > 0) {
-                int size = Math.min(remaining, data.length);
-                for (int i = 0; i < size; i++) {
-                    data[i] = (byte)~rawData[pos]; //invert bits
-                    pos++;
-                }
-                out.write(data, 0, size);
-                remaining -= size;
-            }
-            return true;
-        }
-        return false;
-    }
-
     private void setDefaultResourceLevel(AFPImageObjectInfo imageObjectInfo,
             AFPResourceManager resourceManager) {
         AFPResourceInfo resourceInfo = imageObjectInfo.getResourceInfo();
@@ -324,6 +104,7 @@ public class AFPImageHandlerRenderedImag
         AFPRenderingContext afpContext = (AFPRenderingContext)context;
 
         AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)createDataObjectInfo();
+        AFPPaintingState paintingState = afpContext.getPaintingState();
 
         // set resource information
         setResourceInformation(imageObjectInfo,
@@ -332,15 +113,28 @@ public class AFPImageHandlerRenderedImag
         setDefaultResourceLevel(imageObjectInfo, afpContext.getResourceManager());
 
         // Positioning
-        imageObjectInfo.setObjectAreaInfo(createObjectAreaInfo(afpContext.getPaintingState(), pos));
+        imageObjectInfo.setObjectAreaInfo(createObjectAreaInfo(paintingState, pos));
         Dimension targetSize = pos.getSize();
 
+
         // Image content
         ImageRendered imageRend = (ImageRendered)image;
-        updateDataObjectInfo(imageObjectInfo, afpContext.getPaintingState(), imageRend, targetSize);
+        RenderedImageEncoder encoder = new RenderedImageEncoder(imageRend, targetSize);
+        encoder.prepareEncoding(imageObjectInfo, paintingState);
 
-        // Create image
-        afpContext.getResourceManager().createObject(imageObjectInfo);
+        boolean included = afpContext.getResourceManager().tryIncludeObject(imageObjectInfo);
+        if (!included) {
+            long start = System.currentTimeMillis();
+            //encode only if the same image has not been encoded, yet
+            encoder.encodeImage(imageObjectInfo, paintingState);
+            if (log.isDebugEnabled()) {
+                long duration = System.currentTimeMillis() - start;
+                log.debug("Image encoding took " + duration + "ms.");
+            }
+
+            // Create image
+            afpContext.getResourceManager().createObject(imageObjectInfo);
+        }
     }
 
     /** {@inheritDoc} */
@@ -349,4 +143,256 @@ public class AFPImageHandlerRenderedImag
             && targetContext instanceof AFPRenderingContext;
     }
 
+    private static final class RenderedImageEncoder {
+
+        private ImageRendered imageRendered;
+        private Dimension targetSize;
+
+        private boolean useFS10;
+        private int maxPixelSize;
+        private boolean usePageSegments;
+        private boolean resample;
+        private Dimension resampledDim;
+        private ImageSize intrinsicSize;
+        private ImageSize effIntrinsicSize;
+
+        private RenderedImageEncoder(ImageRendered imageRendered, Dimension targetSize) {
+            this.imageRendered = imageRendered;
+            this.targetSize = targetSize;
+
+        }
+
+        private void prepareEncoding(AFPImageObjectInfo imageObjectInfo,
+                AFPPaintingState paintingState) {
+            maxPixelSize = paintingState.getBitsPerPixel();
+            if (paintingState.isColorImages()) {
+                if (paintingState.isCMYKImagesSupported()) {
+                    maxPixelSize *= 4; //CMYK is maximum
+                } else {
+                    maxPixelSize *= 3; //RGB is maximum
+                }
+            }
+            RenderedImage renderedImage = imageRendered.getRenderedImage();
+            useFS10 = (maxPixelSize == 1) || BitmapImageUtil.isMonochromeImage(renderedImage);
+
+            ImageInfo imageInfo = imageRendered.getInfo();
+            this.intrinsicSize = imageInfo.getSize();
+            this.effIntrinsicSize = intrinsicSize;
+
+            AFPResourceInfo resourceInfo = imageObjectInfo.getResourceInfo();
+            this.usePageSegments = useFS10 && !resourceInfo.getLevel().isInline();
+            if (usePageSegments) {
+                //The image may need to be resized/resampled for use as a page segment
+                int resolution = paintingState.getResolution();
+                this.resampledDim = new Dimension(
+                        (int)Math.ceil(UnitConv.mpt2px(targetSize.getWidth(), resolution)),
+                        (int)Math.ceil(UnitConv.mpt2px(targetSize.getHeight(), resolution)));
+                resourceInfo.setImageDimension(resampledDim);
+                //Only resample/downsample if image is smaller than its intrinsic size
+                //to make print file smaller
+                this.resample = resampledDim.width < renderedImage.getWidth()
+                        && resampledDim.height < renderedImage.getHeight();
+                if (resample) {
+                    effIntrinsicSize = new ImageSize(
+                            resampledDim.width, resampledDim.height, resolution);
+                }
+            }
+
+            //Update image object info
+            imageObjectInfo.setDataHeightRes((int)Math.round(
+                    effIntrinsicSize.getDpiHorizontal() * 10));
+            imageObjectInfo.setDataWidthRes((int)Math.round(
+                    effIntrinsicSize.getDpiVertical() * 10));
+            imageObjectInfo.setDataHeight(effIntrinsicSize.getHeightPx());
+            imageObjectInfo.setDataWidth(effIntrinsicSize.getWidthPx());
+
+            // set object area info
+            int resolution = paintingState.getResolution();
+            AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
+            objectAreaInfo.setWidthRes(resolution);
+            objectAreaInfo.setHeightRes(resolution);
+        }
+
+        private AFPDataObjectInfo encodeImage
+            (AFPImageObjectInfo imageObjectInfo,
+             AFPPaintingState paintingState)
+                throws IOException {
+
+            RenderedImage renderedImage = imageRendered.getRenderedImage();
+            int functionSet = useFS10 ? 10 : 11;
+
+            if (usePageSegments) {
+                assert resampledDim != null;
+                //Resize, optionally resample and convert image
+
+                imageObjectInfo.setCreatePageSegment(true);
+
+                float ditheringQuality = paintingState.getDitheringQuality();
+                if (this.resample) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Resample from " + intrinsicSize.getDimensionPx()
+                                + " to " + resampledDim);
+                    }
+                    renderedImage = BitmapImageUtil.convertToMonochrome(renderedImage,
+                            resampledDim, ditheringQuality);
+                } else if (ditheringQuality >= 0.5f) {
+                    renderedImage = BitmapImageUtil.convertToMonochrome(renderedImage,
+                            intrinsicSize.getDimensionPx(), ditheringQuality);
+                }
+            }
+
+            //TODO To reduce AFP file size, investigate using a compression scheme.
+            //Currently, all image data is uncompressed.
+            ColorModel cm = renderedImage.getColorModel();
+            if (log.isTraceEnabled()) {
+                log.trace("ColorModel: " + cm);
+            }
+            int pixelSize = cm.getPixelSize();
+            if (cm.hasAlpha()) {
+                pixelSize -= 8;
+            }
+
+            byte[] imageData = null;
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            boolean allowDirectEncoding = true;
+            if (allowDirectEncoding && (pixelSize <= maxPixelSize)) {
+                //Attempt to encode without resampling the image
+                ImageEncodingHelper helper = new ImageEncodingHelper(renderedImage,
+                        pixelSize == 32);
+                ColorModel encodedColorModel = helper.getEncodedColorModel();
+                boolean directEncode = true;
+                if (helper.getEncodedColorModel().getPixelSize() > maxPixelSize) {
+                    directEncode = false; //pixel size needs to be reduced
+                }
+                if (BitmapImageUtil.getColorIndexSize(renderedImage) > 2) {
+                    directEncode = false; //Lookup tables are not implemented, yet
+                }
+                if (useFS10
+                        && BitmapImageUtil.isMonochromeImage(renderedImage)
+                        && BitmapImageUtil.isZeroBlack(renderedImage)) {
+                    directEncode = false;
+                    //need a special method to invert the bit-stream since setting the
+                    //subtractive mode in AFP alone doesn't seem to do the trick.
+                    if (encodeInvertedBilevel(helper, imageObjectInfo, baos)) {
+                        imageData = baos.toByteArray();
+                    }
+                }
+                if (directEncode) {
+                    log.debug("Encoding image directly...");
+                    imageObjectInfo.setBitsPerPixel(encodedColorModel.getPixelSize());
+                    if (pixelSize == 32) {
+                        functionSet = 45; //IOCA FS45 required for CMYK
+                    }
+
+                    helper.encode(baos);
+                    imageData = baos.toByteArray();
+                }
+            }
+            if (imageData == null) {
+                log.debug("Encoding image via RGB...");
+                imageData = encodeViaRGB(renderedImage, imageObjectInfo, paintingState, baos);
+            }
+
+            switch (functionSet) {
+            case 10:
+                imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS10);
+                break;
+            case 11:
+                imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11);
+                break;
+            case 45:
+                imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
+                break;
+            default:
+                throw new IllegalStateException("Invalid IOCA function set: " + functionSet);
+            }
+
+            imageObjectInfo.setData(imageData);
+
+            return imageObjectInfo;
+        }
+
+        private byte[] encodeViaRGB(RenderedImage renderedImage,
+                AFPImageObjectInfo imageObjectInfo, AFPPaintingState paintingState,
+                ByteArrayOutputStream baos) throws IOException {
+            byte[] imageData;
+            //Convert image to 24bit RGB
+            ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baos);
+            imageData = baos.toByteArray();
+            imageObjectInfo.setBitsPerPixel(24);
+
+            boolean colorImages = paintingState.isColorImages();
+            imageObjectInfo.setColor(colorImages);
+
+            // convert to grayscale
+            if (!colorImages) {
+                log.debug("Converting RGB image to grayscale...");
+                baos.reset();
+                int bitsPerPixel = paintingState.getBitsPerPixel();
+                imageObjectInfo.setBitsPerPixel(bitsPerPixel);
+                //TODO this should be done off the RenderedImage to avoid buffering the
+                //intermediate 24bit image
+                ImageEncodingHelper.encodeRGBAsGrayScale(
+                      imageData, renderedImage.getWidth(), renderedImage.getHeight(),
+                      bitsPerPixel, baos);
+                imageData = baos.toByteArray();
+                if (bitsPerPixel == 1) {
+                    imageObjectInfo.setSubtractive(true);
+                }
+            }
+            return imageData;
+        }
+
+        /**
+         * Efficiently encodes a bi-level image in inverted form as a plain bit-stream.
+         * @param helper the image encoding helper used to analyze the image
+         * @param imageObjectInfo the AFP image object
+         * @param out the output stream
+         * @return true if the image was encoded, false if there was something prohibiting that
+         * @throws IOException if an I/O error occurs
+         */
+        private boolean encodeInvertedBilevel(ImageEncodingHelper helper,
+                AFPImageObjectInfo imageObjectInfo, OutputStream out) throws IOException {
+            RenderedImage renderedImage = helper.getImage();
+            if (!BitmapImageUtil.isMonochromeImage(renderedImage)) {
+                throw new IllegalStateException("This method only supports binary images!");
+            }
+            int tiles = renderedImage.getNumXTiles() * renderedImage.getNumYTiles();
+            if (tiles > 1) {
+                return false;
+            }
+            SampleModel sampleModel = renderedImage.getSampleModel();
+            SampleModel expectedSampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+                    renderedImage.getWidth(), renderedImage.getHeight(), 1);
+            if (!expectedSampleModel.equals(sampleModel)) {
+                return false; //Pixels are not packed
+            }
+
+            imageObjectInfo.setBitsPerPixel(1);
+
+            Raster raster = renderedImage.getTile(0, 0);
+            DataBuffer buffer = raster.getDataBuffer();
+            if (buffer instanceof DataBufferByte) {
+                DataBufferByte byteBuffer = (DataBufferByte)buffer;
+                log.debug("Encoding image as inverted bi-level...");
+                byte[] rawData = byteBuffer.getData();
+                int remaining = rawData.length;
+                int pos = 0;
+                byte[] data = new byte[4096];
+                while (remaining > 0) {
+                    int size = Math.min(remaining, data.length);
+                    for (int i = 0; i < size; i++) {
+                        data[i] = (byte)~rawData[pos]; //invert bits
+                        pos++;
+                    }
+                    out.write(data, 0, size);
+                    remaining -= size;
+                }
+                return true;
+            }
+            return false;
+        }
+
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java Fri Jul 22 08:36:15 2011
@@ -86,6 +86,7 @@ public class PDFPainter extends Abstract
     }
 
     /** {@inheritDoc} */
+    @Override
     protected IFContext getContext() {
         return this.documentHandler.getContext();
     }
@@ -155,6 +156,7 @@ public class PDFPainter extends Abstract
     }
 
     /** {@inheritDoc} */
+    @Override
     protected RenderingContext createRenderingContext() {
         PDFRenderingContext pdfContext = new PDFRenderingContext(
                 getUserAgent(), generator, this.documentHandler.currentPage, getFontInfo());
@@ -257,6 +259,7 @@ public class PDFPainter extends Abstract
     }
 
     /** {@inheritDoc} */
+    @Override
     public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
             BorderProps left, BorderProps right) throws IFException {
         if (top != null || bottom != null || left != null || right != null) {
@@ -270,6 +273,7 @@ public class PDFPainter extends Abstract
     }
 
     /** {@inheritDoc} */
+    @Override
     public void drawLine(Point start, Point end, int width, Color color, RuleStyle style)
         throws IFException {
         generator.endTextObject();
@@ -280,7 +284,7 @@ public class PDFPainter extends Abstract
         if (fontName == null) {
             throw new NullPointerException("fontName must not be null");
         }
-        Typeface tf = (Typeface)getFontInfo().getFonts().get(fontName);
+        Typeface tf = getFontInfo().getFonts().get(fontName);
         if (tf instanceof LazyFont) {
             tf = ((LazyFont)tf).getRealFont();
         }
@@ -352,16 +356,7 @@ public class PDFPainter extends Abstract
             float glyphAdjust = 0;
             if (font.hasChar(orgChar)) {
                 ch = font.mapChar(orgChar);
-                if (singleByteFont != null && singleByteFont.hasAdditionalEncodings()) {
-                    int encoding = ch / 256;
-                    if (encoding == 0) {
-                        textutil.updateTf(fontName, fontSize, tf.isMultiByte());
-                    } else {
-                        textutil.updateTf(fontName + "_" + Integer.toString(encoding),
-                                fontSize, tf.isMultiByte());
-                        ch = (char)(ch % 256);
-                    }
-                }
+                ch = selectAndMapSingleByteFont(singleByteFont, fontName, fontSize, textutil, ch);
                 if ((wordSpacing != 0) && CharUtilities.isAdjustableSpace(orgChar)) {
                     glyphAdjust += wordSpacing;
                 }
@@ -377,6 +372,8 @@ public class PDFPainter extends Abstract
                         glyphAdjust += wordSpacing;
                     }
                 }
+                ch = selectAndMapSingleByteFont(singleByteFont, fontName, fontSize,
+                        textutil, ch);
             }
             textutil.writeTJMappedChar(ch);
 
@@ -456,4 +453,19 @@ public class PDFPainter extends Abstract
     }
     */
 
+    private char selectAndMapSingleByteFont(SingleByteFont singleByteFont, String fontName,
+            float fontSize, PDFTextUtil textutil, char ch) {
+        if (singleByteFont != null && singleByteFont.hasAdditionalEncodings()) {
+            int encoding = ch / 256;
+            if (encoding == 0) {
+                textutil.updateTf(fontName, fontSize, singleByteFont.isMultiByte());
+            } else {
+                textutil.updateTf(fontName + "_" + Integer.toString(encoding),
+                        fontSize, singleByteFont.isMultiByte());
+                ch = (char)(ch % 256);
+            }
+        }
+        return ch;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/svg/AbstractFOPImageElementBridge.java Fri Jul 22 08:36:15 2011
@@ -23,11 +23,15 @@ import java.awt.Graphics2D;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
+import org.w3c.dom.Element;
+import org.w3c.dom.svg.SVGDocument;
+
 import org.apache.batik.bridge.BridgeContext;
 import org.apache.batik.bridge.SVGImageElementBridge;
 import org.apache.batik.gvt.AbstractGraphicsNode;
 import org.apache.batik.gvt.GraphicsNode;
 import org.apache.batik.util.ParsedURL;
+
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageException;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
@@ -39,8 +43,8 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
 import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
-import org.w3c.dom.Element;
-import org.w3c.dom.svg.SVGDocument;
+
+import org.apache.fop.image.loader.batik.BatikUtil;
 
 /**
  * Bridge class for the &lt;image> element when jpeg images.
@@ -63,6 +67,7 @@ public abstract class AbstractFOPImageEl
      * @param purl the parsed url for the image resource
      * @return a new graphics node
      */
+    @Override
     protected GraphicsNode createImageGraphicsNode
                 (BridgeContext ctx, Element imageElement, ParsedURL purl) {
         AbstractFOPBridgeContext bridgeCtx = (AbstractFOPBridgeContext)ctx;
@@ -80,8 +85,11 @@ public abstract class AbstractFOPImageEl
             if (image instanceof ImageXMLDOM) {
                 ImageXMLDOM xmlImage = (ImageXMLDOM)image;
                 if (xmlImage.getDocument() instanceof SVGDocument) {
-                    return createSVGImageNode(ctx, imageElement,
-                            (SVGDocument)xmlImage.getDocument());
+                    //Clone DOM because the Batik's CSS Parser attaches to the DOM and is therefore
+                    //not thread-safe.
+                    SVGDocument clonedDoc = (SVGDocument)BatikUtil.cloneSVGDocument(
+                            xmlImage.getDocument());
+                    return createSVGImageNode(ctx, imageElement, clonedDoc);
                 } else {
                     //Convert image to Graphics2D
                     image = manager.convertImage(xmlImage,
@@ -100,22 +108,25 @@ public abstract class AbstractFOPImageEl
                         new ImageException("Cannot convert an image to a usable format: " + purl));
             }
 
-            Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
-            Rectangle2D bounds = specializedNode.getPrimitiveBounds();
-            float [] vb = new float[4];
-            vb[0] = 0; // x
-            vb[1] = 0; // y
-            vb[2] = (float) bounds.getWidth(); // width
-            vb[3] = (float) bounds.getHeight(); // height
-
-            // handles the 'preserveAspectRatio', 'overflow' and 'clip'
-            // and sets the appropriate AffineTransform to the image node
-            initializeViewport(ctx, imageElement, specializedNode, vb, imgBounds);
-            return specializedNode;
+            if (specializedNode != null) {
+                Rectangle2D imgBounds = getImageBounds(ctx, imageElement);
+                Rectangle2D bounds = specializedNode.getPrimitiveBounds();
+                float [] vb = new float[4];
+                vb[0] = 0; // x
+                vb[1] = 0; // y
+                vb[2] = (float) bounds.getWidth(); // width
+                vb[3] = (float) bounds.getHeight(); // height
+
+                // handles the 'preserveAspectRatio', 'overflow' and 'clip'
+                // and sets the appropriate AffineTransform to the image node
+                initializeViewport(ctx, imageElement, specializedNode, vb, imgBounds);
+                return specializedNode;
+            }
         } catch (Exception e) {
             ctx.getUserAgent().displayError(e);
         }
 
+        //Fallback
         return superCreateGraphicsNode(ctx, imageElement, purl);
     }
 
@@ -241,7 +252,7 @@ public abstract class AbstractFOPImageEl
     /**
      * A node that holds a Graphics2D image.
      */
-    public class Graphics2DNode extends AbstractGraphicsNode {
+    public static class Graphics2DNode extends AbstractGraphicsNode {
 
         private final ImageGraphics2D image;
 

Propchange: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/util/ColorExt.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 22 08:36:15 2011
@@ -3,4 +3,4 @@
 /xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/util/ColorExt.java:603620-746655
 /xmlgraphics/fop/branches/Temp_Color/src/java/org/apache/fop/util/ColorExt.java:956535-1069429
 /xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/util/ColorExt.java:684572,688085,688696
-/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorExt.java:981451-1135999
+/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ColorExt.java:981451-1149493

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/status.xml?rev=1149498&r1=1149497&r2=1149498&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/status.xml (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/status.xml Fri Jul 22 08:36:15 2011
@@ -30,6 +30,7 @@
     <person name="Andreas Delmelle"  email="adelmelle@apache.org"     id="AD"/>
     <person name="Luca Furini"       email="lfurini@apache.org"       id="LF"/>
     <person name="Christian Geisert" email="chrisg@apache.org"        id="CG"/>
+    <person name="Peter Hancock"     email="phancock@apache.org"      id="PH"/>
     <person name="Vincent Hennebert" email="vhennebert@apache.org"    id="VH"/>
     <person name="Clay Leeds"        email="clay@apache.org"          id="CL"/>
     <person name="Manuel Mall"       email="manuel@apache.org"        id="MM"/>
@@ -59,6 +60,17 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Fonts" dev="JM" type="fix" fixes-bug="50605">
+        Fixed a number of bugs concerning Type 1 and other single-byte fonts
+        (glyph width mismatches and overlapping characters).
+      </action>
+      <action context="Renderers" dev="JM" type="fix">
+        Fixed a multi-threading bug for SVG images included through svg:image inside SVG documents.
+      </action>
+      <action context="Renderers" dev="PH" type="add">
+        Added an IFDocumentHandler filter for triggering rendering events.  Created an Event that
+        captures an end page event with the page number.
+      </action>
       <action context="Renderers" dev="VH" type="fix">
         Bugfix: alternative text not working in tagged PDF for TIFF images.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org