CVS: jfor/src/org/jfor/jfor/converter TableBodyBuilder.java,NONE,1.1 Converter.java,1.15,1.16 TableContext.java,1.8,1.9

Phil Chu <[email protected]> Thu, 23 Oct 2003 21:42:31 -0700
Newsgroups gmane.text.xml.jfor.cvs
Message-ID <[email protected]>
Update of /cvsroot/jfor/jfor/src/org/jfor/jfor/converter
In directory sc8-pr-cvs1:/tmp/cvs-serv23738/src/org/jfor/jfor/converter

Modified Files:
	Converter.java TableContext.java 
Added Files:
	TableBodyBuilder.java 
Log Message:
Support for proportional-column-width. Requires JRE/JDK 1.4 for regex.

--- NEW FILE: TableBodyBuilder.java ---
package org.jfor.jfor.converter;



import java.io.IOException;

import org.xml.sax.Attributes;

import org.jfor.jfor.rtflib.rtfdoc.*;



/*-----------------------------------------------------------------------------

 * jfor - Open-Source XSL-FO to RTF converter - see www.jfor.org

 *

 * ====================================================================

 * jfor Apache-Style Software License.

 * Copyright (c) 2002 by the jfor project. All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 *

 * 1. Redistributions of source code must retain the above copyright

 * notice, this list of conditions and the following disclaimer.

 *

 * 2. Redistributions in binary form must reproduce the above copyright

 * notice, this list of conditions and the following disclaimer in

 * the documentation and/or other materials provided with the

 * distribution.

 *

 * 3. The end-user documentation included with the redistribution,

 * if any, must include the following acknowledgment:

 * "This product includes software developed

 * by the jfor project (http://www.jfor.org)."

 * Alternately, this acknowledgment may appear in the software itself,

 * if and wherever such third-party acknowledgments normally appear.

 *

 * 4. The name "jfor" must not be used to endorse

 * or promote products derived from this software without prior written

 * permission.  For written permission, please contact [email protected].

 *

 * 5. Products derived from this software may not be called "jfor",

 * nor may "jfor" appear in their name, without prior written

 * permission of [email protected].

 *

 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED

 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES

 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

 * DISCLAIMED.  IN NO EVENT SHALL THE JFOR PROJECT OR ITS CONTRIBUTORS BE

 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR

 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF

 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR

 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE

 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,

 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 * ====================================================================

 * Contributor(s):

-----------------------------------------------------------------------------*/



/**  An IBuilder that handles fo:table-body

 *  @author Phil Chu [email protected]

 */



//------------------------------------------------------------------------------

// $Id:

// $Log:

//

//------------------------------------------------------------------------------



class TableBodyBuilder extends AbstractBuilder

{

    private static final String TB = "fo:table-body";

    

    TableBodyBuilder(BuilderContext ctx)

    {

        super(ctx);

    }

    

    /** called by Converter at the start of an element */

    public void start(String rawName, Attributes attrs)

    throws IOException

    {

	// process proportional-column-widths

        m_context.getTableContext().processColumnWidths();

    }

    

    /** called by Converter at the end of an element */

    public void end()

    throws IOException

    {

    }

    

    /** return a TableBuilder for fo:table elements */

    public IBuilder getBuilder(BuilderContext ctx,String rawName, Attributes atts)

    {

        if(rawName.equals(TB)) return new TableBodyBuilder(ctx);

        else return null;

    }

}


Index: Converter.java
===================================================================
RCS file: /cvsroot/jfor/jfor/src/org/jfor/jfor/converter/Converter.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** Converter.java	18 Feb 2003 16:10:48 -0000	1.15
--- Converter.java	24 Oct 2003 04:42:29 -0000	1.16
***************
*** 74,77 ****
--- 74,80 ----
  // $Id$
  // $Log$
+ // Revision 1.16  2003/10/24 04:42:29  philipchu
+ // Support for proportional-column-width. Requires JRE/JDK 1.4 for regex.
+ //
  // Revision 1.15  2003/02/18 16:10:48  rmarra
  // Contributions Normand Massé

***************
*** 263,266 ****
--- 266,272 ----
          m_builders.add(new TableCellBuilder(m_context));
          m_builders.add(new TableColumnBuilder(m_context));
+ 	// Added by Phil Chu
+ 	// Postprocessing support for proportional-column-width
+ 	m_builders.add(new TableBodyBuilder(m_context));
          m_builders.add(new ListBuilder(m_context));
          m_builders.add(new ListItemBuilder(m_context));

Index: TableContext.java
===================================================================
RCS file: /cvsroot/jfor/jfor/src/org/jfor/jfor/converter/TableContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** TableContext.java	31 Aug 2003 11:43:11 -0000	1.8
--- TableContext.java	24 Oct 2003 04:42:29 -0000	1.9
***************
*** 2,5 ****
--- 2,6 ----
  
  import java.util.*;
+ import java.util.regex.*;
  import org.jfor.jfor.rtflib.rtfdoc.RtfAttributes;
  import org.xml.sax.Attributes;
***************
*** 63,66 ****
--- 64,70 ----
  // $Id$
  // $Log$
+ // Revision 1.9  2003/10/24 04:42:29  philipchu
+ // Support for proportional-column-width. Requires JRE/JDK 1.4 for regex.
+ //
  // Revision 1.8  2003/08/31 11:43:11  pherweg
  // Imporoved support for fo:table-header simplified
***************
*** 117,120 ****
--- 121,127 ----
      private final ArrayList m_colRowSpanningAttrs = new ArrayList();  //Added by Peter Herweg on 2002-06-29
     
+     // Phil Chu - check for proportional-column-width in table columns
+     private Matcher m_matcher = Pattern.compile("proportional-column-width\\(([0-9]+)\\)").matcher("");
+ 
      TableContext(BuilderContext ctx)
      {
***************
*** 125,129 ****
      throws ValueConversionException
      {
!         m_colWidths.add(new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
      }
      
--- 132,142 ----
      throws ValueConversionException
      {
! 	// Phil Chu - distinguish proportional-column-width by using Integer instead of Float
! 	m_matcher.reset(strWidth);
! 	if (m_matcher.find()) {
! 	    m_colWidths.add(new Integer(m_matcher.group(1)));
! 	} else {
! 	    m_colWidths.add(new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
! 	}
      }
      
***************
*** 229,232 ****
--- 242,269 ----
         return m_colWidths.size();
       }
+ 
+     //Added by Phil Chu on 2003-7-24
+     void processColumnWidths() {
+ 	// get total number of proportional units
+ 	// and sum up existing absolute column widths (twips)
+ 	float pwidth=0.0f; // use float because we're going to make a ratio
+ 	float twips=0.0f; // twips already calculated
+ 	for (int i=0; i<m_colWidths.size(); ++i) {
+ 	    if (Integer.class.isInstance(m_colWidths.get(i))) {
+ 		pwidth+=((Integer)m_colWidths.get(i)).intValue();
+ 	    } else {
+ 		twips+=((Float)m_colWidths.get(i)).floatValue();
+ 	    }
+ 	}
+ 	// replace each proportional-column-unit with a real width
+ 	// using a hardcoded total table width for now
+ 	float maxtwips = 7.0f*FoUnitsConverter.IN_TO_TWIPS;
+ 	for (int i=0; i<m_colWidths.size(); ++i) {
+ 	    if (Integer.class.isInstance(m_colWidths.get(i))) {
+ 		m_colWidths.set(i,new Float(((Integer)m_colWidths.get(i)).intValue()/pwidth*(maxtwips-twips)));
+ 	    }
+ 	}
+     }
+ 
       /** - end - */
  }



-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/