proportional-column-width using Float
Sébastien Chauvin <[email protected]> Fri, 25 Feb 2005 18:34:19 +0100
| Newsgroups | gmane.text.xml.jfor.devel |
|---|---|
| Organization | Jouve Rennes |
| Message-ID | <02c901c51b60$3cf50c70$6633a8c0@schauvin> |
This is a multi-part message in MIME format.
------=_NextPart_000_02C5_01C51B68.9E65FD40
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_02C6_01C51B68.9E686E40"
------=_NextPart_001_02C6_01C51B68.9E686E40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
For personnal needs i extended the TableContext class to accept Float =
numbers in the proportional-column-width attribute.
I used an internal class (ProportionalColumnWidth) to store the value as =
a Float instead of storing it as an Integer so i can still distinguish =
normal width from proportional ones.
Thanks to Phil Chu for adding the support for proportional-column-width.
You'll find attached the java file and the diff with CVS version.
S=E9bastien.
------=_NextPart_001_02C6_01C51B68.9E686E40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2604" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>For personnal needs i extended the =
TableContext=20
class to accept Float numbers in the proportional-column-width=20
attribute.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I used an internal class =
(ProportionalColumnWidth)=20
to store the value as a Float instead of storing it as an Integer so i =
can still=20
distinguish normal width from proportional ones.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks to Phil Chu for adding the =
support for=20
proportional-column-width.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>You'll find attached the java file and =
the diff=20
with CVS version.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =
S=E9bastien.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_001_02C6_01C51B68.9E686E40--
------=_NextPart_000_02C5_01C51B68.9E65FD40
Content-Type: application/octet-stream;
name="TableContext.java.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="TableContext.java.diff"
Index: TableContext.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: =
/cvsroot/jfor/jfor/src/org/jfor/jfor/converter/TableContext.java,v
retrieving revision 1.10
diff -u -r1.10 TableContext.java
--- TableContext.java 25 Oct 2003 23:23:06 -0000 1.10
+++ TableContext.java 25 Feb 2005 17:22:07 -0000
@@ -2,7 +2,6 @@
=20
import java.util.*;
import org.jfor.jfor.rtflib.rtfdoc.RtfAttributes;
-import org.xml.sax.Attributes;
import org.jfor.jfor.interfaces.ITableColumnsInfo;
=20
=
/*-----------------------------------------------------------------------=
------
@@ -122,6 +121,25 @@
*/
private final ArrayList m_colRowSpanningAttrs =3D new ArrayList(); =
//Added by Peter Herweg on 2002-06-29
=20
+ /**
+ * Added by SC on 2004-02-25
+ * Class to distinguish proportional-column-width from other width
+ */
+ class ProportionalColumnWidth
+ {
+ Float width;
+ =09
+ private ProportionalColumnWidth(Float aWidth)
+ {
+ this.width =3D aWidth;
+ }
+ =09
+ private Float getWidth()
+ {
+ return this.width;
+ }
+ }
+ =20
TableContext(BuilderContext ctx)
{
m_context =3D ctx;
@@ -131,11 +149,12 @@
throws ValueConversionException
{
// if column-width is a proportional-column-width,
- // distinguish using an Integer instead of a Float
+ // distinguish using a ProportionalColumnWidth instead of a Float
if (strWidth.startsWith("proportional-column-width")) {
int begin =3D strWidth.indexOf("(")+1;
int end =3D strWidth.indexOf(")",begin);
- m_colWidths.add(new Integer(strWidth.substring(begin,end)));
+ // Added by SC on 2004-02-25
+ m_colWidths.add(new ProportionalColumnWidth(new =
Float(strWidth.substring(begin,end))));
} else {
m_colWidths.add(new =
Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
}
@@ -250,18 +269,20 @@
float pwidth=3D0.0f; // use float because we're going to make a ratio
float twips=3D0.0f; // twips already calculated
for (int i=3D0; i<m_colWidths.size(); ++i) {
- if (Integer.class.isInstance(m_colWidths.get(i))) {
- pwidth+=3D((Integer)m_colWidths.get(i)).intValue();
+ // Added by SC on 2004-02-25
+ if (ProportionalColumnWidth.class.isInstance(m_colWidths.get(i))) =
{
+ =
pwidth+=3D((ProportionalColumnWidth)m_colWidths.get(i)).getWidth().floatV=
alue();
} else {
- twips+=3D((Float)m_colWidths.get(i)).floatValue();
+ twips+=3D((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 =3D 7.0f*FoUnitsConverter.IN_TO_TWIPS;
for (int i=3D0; 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)));=
+ // Added by SC on 2004-02-25
+ if (ProportionalColumnWidth.class.isInstance(m_colWidths.get(i))) =
{
+ m_colWidths.set(i,new =
Float(((ProportionalColumnWidth)m_colWidths.get(i)).getWidth().floatValue=
()/pwidth*(maxtwips-twips)));
}
}
}
------=_NextPart_000_02C5_01C51B68.9E65FD40
Content-Type: application/octet-stream;
name="TableContext.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="TableContext.java"
package org.jfor.jfor.converter;
import java.util.*;
import org.jfor.jfor.rtflib.rtfdoc.RtfAttributes;
import org.jfor.jfor.interfaces.ITableColumnsInfo;
/*-----------------------------------------------------------------------=
------
* jfor - Open-Source XSL-FO to RTF converter - see www.jfor.org
*
* =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
* 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.
* =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
* Contributor(s):
-------------------------------------------------------------------------=
----*/
/** Used when handling fo:table to hold information common to several =
builders
* that collaborate to build the table.
* @author Bertrand Delacretaz [email protected]
*/
//-----------------------------------------------------------------------=
-------
// $Id: TableContext.java,v 1.10 2003/10/25 23:23:06 philipchu Exp $
// $Log: TableContext.java,v $
// Revision 1.10 2003/10/25 23:23:06 philipchu
// replace regex usage with exact string match - removes requirement of =
jdk/jre 1.4
//
// 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
//
// Revision 1.7 2003/08/30 16:06:18 pherweg
// fo:rows inside fo:table-header are to be repeated on every page
//
// Revision 1.6 2003/06/29 22:31:02 pherweg
// support for number-rows-spanned added
//
// Revision 1.5 2002/08/12 09:40:02 bdelacretaz
// V0.7.1dev-e, contributions from Boris Poud=E9rous for =
number-columns-spanned
// and vertical merging of tables cells.
//
// Revision 1.4 2002/07/12 08:08:31 bdelacretaz
// License changed to jfor Apache-style license
//
// Revision 1.3 2002/07/02 16:03:19 bdelacretaz
// patch from Trembicki-Guy, Ed <[email protected]> to handle undefined table =
column widths
//
// Revision 1.2 2001/08/31 07:51:01 bdelacretaz
// MPL license text added + javadoc class comments corrected
//
// Revision 1.1 2001/08/29 13:27:51 bdelacretaz
// V0.4.1 - base package name changed to org.jfor.jfor
//
// Revision 1.1.1.1 2001/08/02 12:53:45 bdelacretaz
// initial SourceForge checkin of V0.1 code
//
//-----------------------------------------------------------------------=
-------
class TableContext implements ITableColumnsInfo
{
private final BuilderContext m_context;
private final ArrayList m_colWidths =3D new ArrayList();
private int m_colIndex;
=20
/**
* Added by Peter Herweg on 2002-06-29
* This ArrayList contains one element for each column in the table.
* value =3D=3D 0 means there is no row-spanning
* value > 0 means there is row-spanning
* Each value in the list is decreased by 1 after each finished =
table-row
*/
private final ArrayList m_colRowSpanningNumber =3D new ArrayList();=20
=20
/**
* Added by Peter Herweg on 2002-06-29
* If there has a vertical merged cell to be created, its attributes =
are=20
* inherited from the corresponding MERGE_START-cell.
* For this purpose the attributes of a cell are stored in this =
array, as soon
* as a number-rows-spanned attribute has been found.
*/
private final ArrayList m_colRowSpanningAttrs =3D new ArrayList(); =
//Added by Peter Herweg on 2002-06-29
=20
/**
* Added by SC on 2004-02-25
* Class to distinguish proportional-column-width from other width
*/
class ProportionalColumnWidth
{
Float width;
=09
private ProportionalColumnWidth(Float aWidth)
{
this.width =3D aWidth;
}
=09
private Float getWidth()
{
return this.width;
}
}
=20
TableContext(BuilderContext ctx)
{
m_context =3D ctx;
}
void setNextColumnWidth(String strWidth)
throws ValueConversionException
{
// if column-width is a proportional-column-width,
// distinguish using a ProportionalColumnWidth instead of a Float
if (strWidth.startsWith("proportional-column-width")) {
int begin =3D strWidth.indexOf("(")+1;
int end =3D strWidth.indexOf(")",begin);
// Added by SC on 2004-02-25
m_colWidths.add(new ProportionalColumnWidth(new =
Float(strWidth.substring(begin,end))));
} else {
m_colWidths.add(new =
Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
}
}
=20
//Added by Peter Herweg on 2002-06-29
RtfAttributes getColumnRowSpanningAttrs()
{
return (RtfAttributes)m_colRowSpanningAttrs.get(m_colIndex);
}
=20
//Added by Peter Herweg on 2002-06-29
Integer getColumnRowSpanningNumber()
{
return (Integer)m_colRowSpanningNumber.get(m_colIndex);
}
//Added by Peter Herweg on 2002-06-29
void setCurrentColumnRowSpanning(Integer iRowSpanning, =
RtfAttributes attrs)
throws ValueConversionException
{
=20
if(m_colIndex<m_colRowSpanningNumber.size())
{
m_colRowSpanningNumber.set(m_colIndex, iRowSpanning);
m_colRowSpanningAttrs.set(m_colIndex, attrs);
}
else
{
m_colRowSpanningNumber.add(iRowSpanning);
m_colRowSpanningAttrs.add(m_colIndex, attrs);
}
}
=20
//Added by Peter Herweg on 2002-06-29
public void setNextColumnRowSpanning(Integer iRowSpanning, =
RtfAttributes attrs)
{
m_colRowSpanningNumber.add(iRowSpanning);
m_colRowSpanningAttrs.add(m_colIndex, attrs);
}
=20
/**
* Added by Peter Herweg on 2002-06-29
* This function is called after each finished table-row.
* It decreases all values in m_colRowSpanningNumber by 1. If a =
value
* reaches 0 row-spanning is finished, and the value won't be =
decreased anymore.
*/
public void decreaseRowSpannings()
{
for(int z=3D0;z<m_colRowSpanningNumber.size();++z)
{
Integer i=3D(Integer)m_colRowSpanningNumber.get(z);
=20
if(i.intValue()>0)
i=3Dnew Integer(i.intValue()-1);
=20
m_colRowSpanningNumber.set(z,i);
=20
if(i.intValue()=3D=3D0)
m_colRowSpanningAttrs.set(z,null);
}
}
/** reset the column iteration index, meant to be called when =
creating a new row
* The 'public' modifier has been added by Boris Poud=E9rous for =
'number-columns-spanned' processing
*/
public void selectFirstColumn()
{
m_colIndex =3D 0;
}
/** increment the column iteration index
* The 'public' modifier has been added by Boris Poud=E9rous for =
'number-columns-spanned' processing
*/
public void selectNextColumn()
{
m_colIndex++;
}
/** get current column width according to column iteration index
* @return INVALID_COLUMN_WIDTH if we cannot find the value
* The 'public' modifier has been added by Boris Poud=E9rous for =
'number-columns-spanned' processing
*/
public float getColumnWidth()
{
try {
return ((Float)m_colWidths.get(m_colIndex)).floatValue();
} catch (IndexOutOfBoundsException ex) {
// this code contributed by Trembicki-Guy, Ed <[email protected]>
m_context.log.logWarning("fo:table-column width not =
defined,using " + INVALID_COLUM_WIDTH);
return INVALID_COLUM_WIDTH;
}
}
/** Added by Boris Poud=E9rous on 07/22/2002 */
public int getColumnIndex()
{
return m_colIndex;
}
/** - end - */
/** Added by Boris Poud=E9rous on 07/22/2002 */
public int getNumberOfColumns()
{
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=3D0.0f; // use float because we're going to make a ratio
float twips=3D0.0f; // twips already calculated
for (int i=3D0; i<m_colWidths.size(); ++i) {
// Added by SC on 2004-02-25
if (ProportionalColumnWidth.class.isInstance(m_colWidths.get(i))) {
=
pwidth+=3D((ProportionalColumnWidth)m_colWidths.get(i)).getWidth().floatV=
alue();
} else {
twips+=3D((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 =3D 7.0f*FoUnitsConverter.IN_TO_TWIPS;
for (int i=3D0; i<m_colWidths.size(); ++i) {
// Added by SC on 2004-02-25
if (ProportionalColumnWidth.class.isInstance(m_colWidths.get(i))) {
m_colWidths.set(i,new =
Float(((ProportionalColumnWidth)m_colWidths.get(i)).getWidth().floatValue=
()/pwidth*(maxtwips-twips)));
}
}
}
/** - end - */
}
------=_NextPart_000_02C5_01C51B68.9E65FD40--
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click