Author: vsiveton
Date: Mon Jun  8 13:00:45 2009
New Revision: 782611

URL: http://svn.apache.org/viewvc?rev=782611&view=rev
Log:
o try to fix the cover logo to be sure that the width are not overload

Modified:
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java?rev=782611&r1=782610&r2=782611&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
 Mon Jun  8 13:00:45 2009
@@ -19,7 +19,10 @@
  * under the License.
  */
 
+import java.awt.image.BufferedImage;
+import java.io.File;
 import java.io.Writer;
+import java.net.URL;
 
 import java.util.Calendar;
 import java.util.Date;
@@ -29,6 +32,7 @@
 import java.util.ResourceBundle;
 import java.util.Stack;
 
+import javax.imageio.ImageIO;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.html.HTML.Tag;
 
@@ -963,9 +967,7 @@
             atts.addAttribute( "text-align", "left" );
             atts.addAttribute( "vertical-align", "top" );
             writeStartTag( BLOCK_TAG, atts );
-            atts = new SinkEventAttributeSet();
-            atts.addAttribute( SinkEventAttributes.HEIGHT, "1.5in" );
-            figureGraphics( compLogo, atts );
+            figureGraphics( compLogo, getGraphicsAttributes( compLogo ) );
             writeEndTag( BLOCK_TAG );
         }
 
@@ -979,9 +981,7 @@
             atts.addAttribute( "text-align", "right" );
             atts.addAttribute( "vertical-align", "top" );
             writeStartTag( BLOCK_TAG, atts );
-            atts = new SinkEventAttributeSet();
-            atts.addAttribute( SinkEventAttributes.HEIGHT, "1.5in" );
-            figureGraphics( projLogo, atts );
+            figureGraphics( projLogo, getGraphicsAttributes( projLogo ) );
             writeEndTag( BLOCK_TAG );
         }
 
@@ -1148,4 +1148,50 @@
     {
         return ResourceBundle.getBundle( "doxia-fo", locale, 
this.getClass().getClassLoader() );
     }
+
+    private SinkEventAttributeSet getGraphicsAttributes( String logo )
+    {
+        SinkEventAttributeSet atts = new SinkEventAttributeSet();
+
+        BufferedImage img = null;
+        if ( ( logo.toLowerCase( Locale.ENGLISH ).startsWith( "http://"; ) )
+            || ( logo.toLowerCase( Locale.ENGLISH ).startsWith( "https://"; ) ) 
)
+        {
+            try
+            {
+                img = ImageIO.read( new URL( logo ) );
+            }
+            catch ( Exception e )
+            {
+                getLog().debug( e );
+            }
+        }
+        else
+        {
+            try
+            {
+                img = ImageIO.read( new File( logo ) );
+            }
+            catch ( Exception e )
+            {
+                getLog().debug( e );
+            }
+        }
+
+        if ( img == null )
+        {
+            atts.addAttribute( SinkEventAttributes.HEIGHT, "1.5in" );
+            return atts;
+        }
+
+        // FOP dpi: 72
+        // Max width : 3.125 inch, table cell size, see #coverPage()
+        double maxWidth = 3.125 * 72;
+        if ( img.getWidth() > maxWidth )
+        {
+            atts.addAttribute( "content-width", "3.125in" );
+        }
+
+        return atts;
+    }
 }

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java?rev=782611&r1=782610&r2=782611&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
 Mon Jun  8 13:00:45 2009
@@ -770,18 +770,28 @@
         MutableAttributeSet atts = config.getAttributeSet( "figure.graphics" );
         atts.addAttribute( Attribute.SRC.toString(), src );
 
+        // http://xmlgraphics.apache.org/fop/graphics.html#resolution
         if ( attributes != null && attributes.isDefined( 
SinkEventAttributes.WIDTH ) )
         {
             atts.addAttribute( "width", attributes.getAttribute( 
SinkEventAttributes.WIDTH ) );
         }
+        if ( attributes != null && attributes.isDefined( "content-width" ) )
+        {
+            atts.removeAttribute( "content-width" );
+            atts.addAttribute( "content-width", attributes.getAttribute( 
"content-width" ) );
+        }
 
         if ( attributes != null && attributes.isDefined( 
SinkEventAttributes.HEIGHT ) )
         {
             atts.addAttribute( "height", attributes.getAttribute( 
SinkEventAttributes.HEIGHT ) );
         }
+        if ( attributes != null && attributes.isDefined( "content-height" ) )
+        {
+            atts.removeAttribute( "content-height" );
+            atts.addAttribute( "content-height", attributes.getAttribute( 
"content-height" ) );
+        }
 
         writeln( "<fo:external-graphic" + SinkUtils.getAttributeString( atts ) 
+ "/>" );
-
     }
 
     /**


Reply via email to