this will now do what it is supposed to(i think, haven't yet built an appropriate...
authorjohn <john>
Sat, 14 Sep 2002 16:22:14 +0000 (16:22 +0000)
committerjohn <john>
Sat, 14 Sep 2002 16:22:14 +0000 (16:22 +0000)
the basic idea is to chop up the text so images can be interspersed, with a lot of manual
typesetting and image dimension calculation going on.  hopefully a useful object is passed
to freemarker, which can then make the fo fle

source/mircoders/producer/PDFPreFormattingProducerNode.java

index cac9345..efae3c4 100755 (executable)
@@ -45,9 +45,24 @@ import freemarker.template.*;
 
 public class PDFPreFormattingProducerNode implements ProducerNode {
   private String contentKey;
+  private int numLinesBetweenImages;
+  private float contentAreaWidthCM;  
+  private float characterWidthCM;  
+  private float pixelWidthCM;
+  private float lineHeightCM;
 
-  public PDFPreFormattingProducerNode(String aContentKey) {
+  public PDFPreFormattingProducerNode(String aContentKey,String someNumLinesBetweenImages,String aContentAreaWidthCM,String aCharacterWidthCM,String aPixelWidthCM,String aLineHeightCM) {
     contentKey = aContentKey;
+    numLinesBetweenImages=(new Integer(someNumLinesBetweenImages)).intValue();
+    contentAreaWidthCM=(new Float(aContentAreaWidthCM)).floatValue();
+    characterWidthCM=(new Float(aCharacterWidthCM)).floatValue();
+    pixelWidthCM=(new Float(aPixelWidthCM)).floatValue();
+    lineHeightCM=(new Float(aLineHeightCM)).floatValue();
+    
+    //    float characterWidthCM = 0.17F;
+    //float contentAreaWidthCM = 16;
+    //float pixelWidthCM = .03F;
+    //float lineHeightCM = .5F;
   }
 
   public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
@@ -66,27 +81,64 @@ public class PDFPreFormattingProducerNode implements ProducerNode {
         throw new ProducerFailure("ContentMarkingProducerNode: value of '"+contentKey+"' is not a content EntityAdapter, but a " + entity.getClass().getName() + " adapter", null);
       }
 
-      int numLinesBetweenImages = 3;
-      float characterWidthCM = 0.17F;
-      float contentAreaWidthCM = 16;
-      float pixelWidthCM = .03F;
-      float lineHeightCM = .5F;
+      int currentPosition = 0;
+
+      //int numLinesBetweenImages=3;
       
-      int numCharsInAnImagelessRow = (new Float(numLinesBetweenImages * (contentAreaWidthCM/characterWidthCM))).intValue();
-         
 
+
+      
+      int numCharsInAnImagelessRow = (new Float(numLinesBetweenImages * (contentAreaWidthCM/characterWidthCM))).intValue();
+       
+      ArrayList brokenUpContent = new ArrayList();  
+      
       //yikes!  a templatemodel....why is freemarker in the backend?
       TemplateModel images=entity.get("to_media_images");
-      if (images != null){
+      if (images == null){
          HashMap row = new HashMap();
-         row.put("text",((EntityContent) entity).getValue("content_data").substring(0,numCharsInAnImagelessRow));
+         row.put("text",((EntityContent) entity).getValue("content_data"));
+         brokenUpContent.add(row);
+      }
+      if (images != null){
+         HashMap row0 = new HashMap();
+         row0.put("text",((EntityContent) entity).getValue("content_data").substring(0,numCharsInAnImagelessRow));
+         brokenUpContent.add(row0);
+         currentPosition=numCharsInAnImagelessRow;
+         
+         while(((SimpleList)images).hasNext()){
+             HashMap row1 = new HashMap();
+             HashMap row2 = new HashMap();
+
+             float img_width=(new Float(((EntityImages)((SimpleList)images).next()).getValue("img_width"))).floatValue();
+             float img_height=(new Float(((EntityImages)((SimpleList)images).next()).getValue("img_height"))).floatValue();
+
+             //calculate how much text goes in the column
+             float text_widthCM = contentAreaWidthCM-(img_width*pixelWidthCM)/characterWidthCM;
+             float number_of_lines = img_height*pixelWidthCM/lineHeightCM; //don't worry we will make it an int 
+             int text_amount= (new Float(text_widthCM*number_of_lines)).intValue();
+
+             row1.put("text_widthCM",Float.toString(text_widthCM));
+             row1.put("img_width",Float.toString(img_width));
+             row1.put("img_height",Float.toString(img_height));
+             
+             row1.put("img_src",((EntityImages)((SimpleList)images).next()).getValue("source"));
+
+             row1.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition,currentPosition+text_amount));
+             currentPosition=currentPosition+text_amount;
+             brokenUpContent.add(row1);
+             
+             row2.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition,currentPosition+numCharsInAnImagelessRow));
+             brokenUpContent.add(row2);
+             currentPosition=currentPosition+numCharsInAnImagelessRow;
+         }
+         HashMap row3 = new HashMap();
+         row3.put("text",((EntityContent) entity).getValue("content_data").substring(currentPosition));
+         brokenUpContent.add(row3);
       }
-
-      ArrayList brokenUpContent = new ArrayList();
       
-
-      brokenUpContent.add("hello");
-      brokenUpContent.add("goodbye");
+      
+      
+      
       
       ParameterExpander.setValueForKey(
                                       aValueMap,