Porting update.
git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@24 820d3149-562b-4f88-9aa4-a8e61a3485cfmaster
parent
753e17ad0c
commit
02a67fe785
|
@ -4,7 +4,7 @@ using System.util;
|
|||
using iTextSharp.text.factories;
|
||||
|
||||
/*
|
||||
* $Id: Paragraph.cs,v 1.14 2008/06/01 13:10:51 psoares33 Exp $
|
||||
* $Id: Paragraph.cs,v 1.13 2008/05/13 11:25:12 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
|
@ -218,8 +218,9 @@ namespace iTextSharp.text {
|
|||
}
|
||||
else if (o is Paragraph) {
|
||||
base.Add(o);
|
||||
if (Count > 0) {
|
||||
Chunk tmp = (Chunk)Chunks[Count - 1];
|
||||
ArrayList chunks = this.Chunks;
|
||||
if (chunks.Count > 0) {
|
||||
Chunk tmp = (Chunk)chunks[chunks.Count - 1];
|
||||
base.Add(new Chunk("\n", tmp.Font));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.util;
|
||||
|
@ -560,9 +560,14 @@ namespace iTextSharp.text {
|
|||
/// </summary>
|
||||
/// <returns>a bool</returns>
|
||||
public bool HasBorders() {
|
||||
return (border > 0)
|
||||
&& ((borderWidth > 0) || (borderWidthLeft > 0)
|
||||
|| (borderWidthRight > 0) || (borderWidthTop > 0) || (borderWidthBottom > 0));
|
||||
switch (border) {
|
||||
case UNDEFINED:
|
||||
case NO_BORDER:
|
||||
return false;
|
||||
default:
|
||||
return borderWidth > 0 || borderWidthLeft > 0
|
||||
|| borderWidthRight > 0 || borderWidthTop > 0 || borderWidthBottom > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -571,7 +576,9 @@ namespace iTextSharp.text {
|
|||
/// <param name="type">the type of border</param>
|
||||
/// <returns>a bool</returns>
|
||||
public bool HasBorder(int type) {
|
||||
return border != UNDEFINED && (border & type) == type;
|
||||
if (border == UNDEFINED)
|
||||
return false;
|
||||
return (border & type) == type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -696,12 +703,9 @@ namespace iTextSharp.text {
|
|||
}
|
||||
|
||||
private float GetVariableBorderWidth(float variableWidthValue, int side) {
|
||||
if ((border & side) != 0) {
|
||||
return variableWidthValue != UNDEFINED ? variableWidthValue
|
||||
: borderWidth;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
if ((border & side) != 0)
|
||||
return variableWidthValue != UNDEFINED ? variableWidthValue : borderWidth;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,453 +1,442 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SimpleCell.
|
||||
/// </summary>
|
||||
public class SimpleCell : Rectangle, IPdfPCellEvent, ITextElementArray {
|
||||
|
||||
/** the CellAttributes object represents a row. */
|
||||
public new const bool ROW = true;
|
||||
/** the CellAttributes object represents a cell. */
|
||||
public new const bool CELL = false;
|
||||
/** the content of the Cell. */
|
||||
private ArrayList content = new ArrayList();
|
||||
/** the width of the Cell. */
|
||||
private float width = 0f;
|
||||
/** the widthpercentage of the Cell. */
|
||||
private float widthpercentage = 0f;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_left = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_right = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_top = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_bottom = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_left = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_right = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_top = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_bottom = float.NaN;
|
||||
/** the colspan of a Cell */
|
||||
private int colspan = 1;
|
||||
/** horizontal alignment inside the Cell. */
|
||||
private int horizontalAlignment = Element.ALIGN_UNDEFINED;
|
||||
/** vertical alignment inside the Cell. */
|
||||
private int verticalAlignment = Element.ALIGN_UNDEFINED;
|
||||
/** indicates if these are the attributes of a single Cell (false) or a group of Cells (true). */
|
||||
private bool cellgroup = false;
|
||||
/** Indicates that the largest ascender height should be used to determine the
|
||||
* height of the first line. Note that this only has an effect when rendered
|
||||
* to PDF. Setting this to true can help with vertical alignment problems. */
|
||||
protected bool useAscender = false;
|
||||
/** Indicates that the largest descender height should be added to the height of
|
||||
* the last line (so characters like y don't dip into the border). Note that
|
||||
* this only has an effect when rendered to PDF. */
|
||||
protected bool useDescender = false;
|
||||
/**
|
||||
* Adjusts the cell contents to compensate for border widths. Note that
|
||||
* this only has an effect when rendered to PDF.
|
||||
*/
|
||||
protected bool useBorderPadding;
|
||||
|
||||
/**
|
||||
* A CellAttributes object is always constructed without any dimensions.
|
||||
* Dimensions are defined after creation.
|
||||
* @param row only true if the CellAttributes object represents a row.
|
||||
*/
|
||||
public SimpleCell(bool row) : base (0f, 0f, 0f, 0f) {
|
||||
cellgroup = row;
|
||||
Border = BOX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to this object.
|
||||
* @param element
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public void AddElement(IElement element) {
|
||||
if (cellgroup) {
|
||||
if (element is SimpleCell) {
|
||||
if (((SimpleCell)element).Cellgroup) {
|
||||
throw new BadElementException("You can't add one row to another row.");
|
||||
}
|
||||
content.Add(element);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw new BadElementException("You can only add cells to rows, no objects of type " + element.GetType().ToString());
|
||||
}
|
||||
}
|
||||
if (element.Type == Element.PARAGRAPH
|
||||
|| element.Type == Element.PHRASE
|
||||
|| element.Type == Element.ANCHOR
|
||||
|| element.Type == Element.CHUNK
|
||||
|| element.Type == Element.LIST
|
||||
|| element.Type == Element.MARKED
|
||||
|| element.Type == Element.JPEG
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SimpleCell.
|
||||
/// </summary>
|
||||
public class SimpleCell : Rectangle, IPdfPCellEvent, ITextElementArray {
|
||||
|
||||
/** the CellAttributes object represents a row. */
|
||||
public new const bool ROW = true;
|
||||
/** the CellAttributes object represents a cell. */
|
||||
public new const bool CELL = false;
|
||||
/** the content of the Cell. */
|
||||
private ArrayList content = new ArrayList();
|
||||
/** the width of the Cell. */
|
||||
private float width = 0f;
|
||||
/** the widthpercentage of the Cell. */
|
||||
private float widthpercentage = 0f;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_left = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_right = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_top = float.NaN;
|
||||
/** an extra spacing variable */
|
||||
private float spacing_bottom = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_left = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_right = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_top = float.NaN;
|
||||
/** an extra padding variable */
|
||||
private float padding_bottom = float.NaN;
|
||||
/** the colspan of a Cell */
|
||||
private int colspan = 1;
|
||||
/** horizontal alignment inside the Cell. */
|
||||
private int horizontalAlignment = Element.ALIGN_UNDEFINED;
|
||||
/** vertical alignment inside the Cell. */
|
||||
private int verticalAlignment = Element.ALIGN_UNDEFINED;
|
||||
/** indicates if these are the attributes of a single Cell (false) or a group of Cells (true). */
|
||||
private bool cellgroup = false;
|
||||
/** Indicates that the largest ascender height should be used to determine the
|
||||
* height of the first line. Note that this only has an effect when rendered
|
||||
* to PDF. Setting this to true can help with vertical alignment problems. */
|
||||
protected bool useAscender = false;
|
||||
/** Indicates that the largest descender height should be added to the height of
|
||||
* the last line (so characters like y don't dip into the border). Note that
|
||||
* this only has an effect when rendered to PDF. */
|
||||
protected bool useDescender = false;
|
||||
/**
|
||||
* Adjusts the cell contents to compensate for border widths. Note that
|
||||
* this only has an effect when rendered to PDF.
|
||||
*/
|
||||
protected bool useBorderPadding;
|
||||
|
||||
/**
|
||||
* A CellAttributes object is always constructed without any dimensions.
|
||||
* Dimensions are defined after creation.
|
||||
* @param row only true if the CellAttributes object represents a row.
|
||||
*/
|
||||
public SimpleCell(bool row) : base (0f, 0f, 0f, 0f) {
|
||||
cellgroup = row;
|
||||
Border = BOX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to this object.
|
||||
* @param element
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public void AddElement(IElement element) {
|
||||
if (cellgroup) {
|
||||
if (element is SimpleCell) {
|
||||
if (((SimpleCell)element).Cellgroup) {
|
||||
throw new BadElementException("You can't add one row to another row.");
|
||||
}
|
||||
content.Add(element);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw new BadElementException("You can only add cells to rows, no objects of type " + element.GetType().ToString());
|
||||
}
|
||||
}
|
||||
if (element.Type == Element.PARAGRAPH
|
||||
|| element.Type == Element.PHRASE
|
||||
|| element.Type == Element.ANCHOR
|
||||
|| element.Type == Element.CHUNK
|
||||
|| element.Type == Element.LIST
|
||||
|| element.Type == Element.MARKED
|
||||
|| element.Type == Element.JPEG
|
||||
|| element.Type == Element.JPEG2000
|
||||
|| element.Type == Element.IMGRAW
|
||||
|| element.Type == Element.IMGTEMPLATE) {
|
||||
content.Add(element);
|
||||
}
|
||||
else {
|
||||
throw new BadElementException("You can't add an element of type " + element.GetType().ToString() + " to a SimpleCell.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Cell with these attributes.
|
||||
* @param rowAttributes
|
||||
* @return a cell based on these attributes.
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public Cell CreateCell(SimpleCell rowAttributes) {
|
||||
Cell cell = new Cell();
|
||||
cell.CloneNonPositionParameters(rowAttributes);
|
||||
cell.SoftCloneNonPositionParameters(this);
|
||||
cell.Colspan = colspan;
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
cell.UseAscender = useAscender;
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
cell.UseDescender = useDescender;
|
||||
foreach (IElement element in content) {
|
||||
cell.AddElement(element);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PdfPCell with these attributes.
|
||||
* @param rowAttributes
|
||||
* @return a PdfPCell based on these attributes.
|
||||
*/
|
||||
public PdfPCell CreatePdfPCell(SimpleCell rowAttributes) {
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.Border = NO_BORDER;
|
||||
SimpleCell tmp = new SimpleCell(CELL);
|
||||
tmp.Spacing_left = spacing_left;
|
||||
tmp.Spacing_right = spacing_right;
|
||||
tmp.Spacing_top = spacing_top;
|
||||
tmp.Spacing_bottom = spacing_bottom;
|
||||
tmp.CloneNonPositionParameters(rowAttributes);
|
||||
tmp.SoftCloneNonPositionParameters(this);
|
||||
cell.CellEvent = tmp;
|
||||
cell.HorizontalAlignment = rowAttributes.horizontalAlignment;
|
||||
cell.VerticalAlignment = rowAttributes.verticalAlignment;
|
||||
cell.UseAscender = rowAttributes.useAscender;
|
||||
cell.UseBorderPadding = rowAttributes.useBorderPadding;
|
||||
cell.UseDescender = rowAttributes.useDescender;
|
||||
cell.Colspan = colspan;
|
||||
if (horizontalAlignment != Element.ALIGN_UNDEFINED)
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
if (verticalAlignment != Element.ALIGN_UNDEFINED)
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
if (useAscender)
|
||||
cell.UseAscender = useAscender;
|
||||
if (useBorderPadding)
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
if (useDescender)
|
||||
cell.UseDescender = useDescender;
|
||||
float p;
|
||||
float sp_left = spacing_left;
|
||||
if (float.IsNaN(sp_left)) sp_left = 0f;
|
||||
float sp_right = spacing_right;
|
||||
if (float.IsNaN(sp_right)) sp_right = 0f;
|
||||
float sp_top = spacing_top;
|
||||
if (float.IsNaN(sp_top)) sp_top = 0f;
|
||||
float sp_bottom = spacing_bottom;
|
||||
if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
|
||||
p = padding_left;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingLeft = p + sp_left;
|
||||
p = padding_right;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingRight = p + sp_right;
|
||||
p = padding_top;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingTop = p + sp_top;
|
||||
p = padding_bottom;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingBottom = p + sp_bottom;
|
||||
foreach (IElement element in content) {
|
||||
cell.AddElement(element);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rectangle
|
||||
* @param spacing
|
||||
* @return a rectangle
|
||||
*/
|
||||
public static SimpleCell GetDimensionlessInstance(Rectangle rectangle, float spacing) {
|
||||
SimpleCell cell = new SimpleCell(CELL);
|
||||
cell.CloneNonPositionParameters(rectangle);
|
||||
cell.Spacing = spacing * 2;
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
|
||||
*/
|
||||
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
|
||||
float sp_left = spacing_left;
|
||||
if (float.IsNaN(sp_left)) sp_left = 0f;
|
||||
float sp_right = spacing_right;
|
||||
if (float.IsNaN(sp_right)) sp_right = 0f;
|
||||
float sp_top = spacing_top;
|
||||
if (float.IsNaN(sp_top)) sp_top = 0f;
|
||||
float sp_bottom = spacing_bottom;
|
||||
if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
|
||||
Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top));
|
||||
rect.CloneNonPositionParameters(this);
|
||||
canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
|
||||
rect.BackgroundColor = null;
|
||||
canvases[PdfPTable.LINECANVAS].Rectangle(rect);
|
||||
}
|
||||
|
||||
/** Sets the padding parameters if they are undefined.
|
||||
* @param padding*/
|
||||
public float Padding {
|
||||
set {
|
||||
if (float.IsNaN(padding_right)) {
|
||||
Padding_right = value;
|
||||
}
|
||||
if (float.IsNaN(padding_left)) {
|
||||
Padding_left = value;
|
||||
}
|
||||
if (float.IsNaN(padding_bottom)) {
|
||||
Padding_bottom = value;
|
||||
}
|
||||
if (float.IsNaN(padding_top)) {
|
||||
Padding_top = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the colspan.
|
||||
*/
|
||||
public int Colspan {
|
||||
get {
|
||||
return colspan;
|
||||
}
|
||||
set {
|
||||
if (value > 0) this.colspan = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param padding_bottom The padding_bottom to set.
|
||||
*/
|
||||
public float Padding_bottom {
|
||||
get {
|
||||
return padding_bottom;
|
||||
}
|
||||
set {
|
||||
padding_bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_left {
|
||||
get {
|
||||
return padding_left;
|
||||
}
|
||||
set {
|
||||
padding_left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_right {
|
||||
get {
|
||||
return padding_right;
|
||||
}
|
||||
set {
|
||||
padding_right = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_top {
|
||||
get {
|
||||
return padding_top;
|
||||
}
|
||||
set {
|
||||
padding_top = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the spacing.
|
||||
*/
|
||||
public float Spacing {
|
||||
set {
|
||||
this.spacing_left = value;
|
||||
this.spacing_right = value;
|
||||
this.spacing_top = value;
|
||||
this.spacing_bottom = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float Spacing_top {
|
||||
get {
|
||||
return spacing_top;
|
||||
}
|
||||
set {
|
||||
spacing_top = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_bottom {
|
||||
get {
|
||||
return spacing_bottom;
|
||||
}
|
||||
set {
|
||||
spacing_bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_left {
|
||||
get {
|
||||
return spacing_left;
|
||||
}
|
||||
set {
|
||||
spacing_left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_right {
|
||||
get {
|
||||
return spacing_right;
|
||||
}
|
||||
set {
|
||||
spacing_right = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellgroup.
|
||||
*/
|
||||
public bool Cellgroup {
|
||||
get {
|
||||
return cellgroup;
|
||||
}
|
||||
set {
|
||||
cellgroup = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the horizontal alignment.
|
||||
*/
|
||||
public int HorizontalAlignment {
|
||||
get {
|
||||
return horizontalAlignment;
|
||||
}
|
||||
set {
|
||||
horizontalAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int VerticalAlignment {
|
||||
get {
|
||||
return verticalAlignment;
|
||||
}
|
||||
set {
|
||||
verticalAlignment = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the width.
|
||||
*/
|
||||
public new float Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the widthpercentage.
|
||||
*/
|
||||
public float Widthpercentage {
|
||||
get {
|
||||
return widthpercentage;
|
||||
}
|
||||
set {
|
||||
widthpercentage = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the useAscender.
|
||||
*/
|
||||
public bool UseAscender {
|
||||
get {
|
||||
return useAscender;
|
||||
}
|
||||
set {
|
||||
useAscender = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseDescender {
|
||||
get {
|
||||
return useDescender;
|
||||
}
|
||||
set {
|
||||
useDescender = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the useBorderPadding.
|
||||
*/
|
||||
public bool UseBorderPadding {
|
||||
get {
|
||||
return useBorderPadding;
|
||||
}
|
||||
set {
|
||||
useBorderPadding = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the content.
|
||||
*/
|
||||
internal ArrayList Content {
|
||||
get {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.TextElementArray#add(java.lang.Object)
|
||||
*/
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
AddElement((IElement)o);
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.CELL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|| element.Type == Element.JBIG2
|
||||
|| element.Type == Element.IMGRAW
|
||||
|| element.Type == Element.IMGTEMPLATE) {
|
||||
content.Add(element);
|
||||
}
|
||||
else {
|
||||
throw new BadElementException("You can't add an element of type " + element.GetType().ToString() + " to a SimpleCell.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Cell with these attributes.
|
||||
* @param rowAttributes
|
||||
* @return a cell based on these attributes.
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public Cell CreateCell(SimpleCell rowAttributes) {
|
||||
Cell cell = new Cell();
|
||||
cell.CloneNonPositionParameters(rowAttributes);
|
||||
cell.SoftCloneNonPositionParameters(this);
|
||||
cell.Colspan = colspan;
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
cell.UseAscender = useAscender;
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
cell.UseDescender = useDescender;
|
||||
foreach (IElement element in content) {
|
||||
cell.AddElement(element);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PdfPCell with these attributes.
|
||||
* @param rowAttributes
|
||||
* @return a PdfPCell based on these attributes.
|
||||
*/
|
||||
public PdfPCell CreatePdfPCell(SimpleCell rowAttributes) {
|
||||
PdfPCell cell = new PdfPCell();
|
||||
cell.Border = NO_BORDER;
|
||||
SimpleCell tmp = new SimpleCell(CELL);
|
||||
tmp.Spacing_left = spacing_left;
|
||||
tmp.Spacing_right = spacing_right;
|
||||
tmp.Spacing_top = spacing_top;
|
||||
tmp.Spacing_bottom = spacing_bottom;
|
||||
tmp.CloneNonPositionParameters(rowAttributes);
|
||||
tmp.SoftCloneNonPositionParameters(this);
|
||||
cell.CellEvent = tmp;
|
||||
cell.HorizontalAlignment = rowAttributes.horizontalAlignment;
|
||||
cell.VerticalAlignment = rowAttributes.verticalAlignment;
|
||||
cell.UseAscender = rowAttributes.useAscender;
|
||||
cell.UseBorderPadding = rowAttributes.useBorderPadding;
|
||||
cell.UseDescender = rowAttributes.useDescender;
|
||||
cell.Colspan = colspan;
|
||||
if (horizontalAlignment != Element.ALIGN_UNDEFINED)
|
||||
cell.HorizontalAlignment = horizontalAlignment;
|
||||
if (verticalAlignment != Element.ALIGN_UNDEFINED)
|
||||
cell.VerticalAlignment = verticalAlignment;
|
||||
if (useAscender)
|
||||
cell.UseAscender = useAscender;
|
||||
if (useBorderPadding)
|
||||
cell.UseBorderPadding = useBorderPadding;
|
||||
if (useDescender)
|
||||
cell.UseDescender = useDescender;
|
||||
float p;
|
||||
float sp_left = spacing_left;
|
||||
if (float.IsNaN(sp_left)) sp_left = 0f;
|
||||
float sp_right = spacing_right;
|
||||
if (float.IsNaN(sp_right)) sp_right = 0f;
|
||||
float sp_top = spacing_top;
|
||||
if (float.IsNaN(sp_top)) sp_top = 0f;
|
||||
float sp_bottom = spacing_bottom;
|
||||
if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
|
||||
p = padding_left;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingLeft = p + sp_left;
|
||||
p = padding_right;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingRight = p + sp_right;
|
||||
p = padding_top;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingTop = p + sp_top;
|
||||
p = padding_bottom;
|
||||
if (float.IsNaN(p)) p = 0f;
|
||||
cell.PaddingBottom = p + sp_bottom;
|
||||
foreach (IElement element in content) {
|
||||
cell.AddElement(element);
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
|
||||
*/
|
||||
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
|
||||
float sp_left = spacing_left;
|
||||
if (float.IsNaN(sp_left)) sp_left = 0f;
|
||||
float sp_right = spacing_right;
|
||||
if (float.IsNaN(sp_right)) sp_right = 0f;
|
||||
float sp_top = spacing_top;
|
||||
if (float.IsNaN(sp_top)) sp_top = 0f;
|
||||
float sp_bottom = spacing_bottom;
|
||||
if (float.IsNaN(sp_bottom)) sp_bottom = 0f;
|
||||
Rectangle rect = new Rectangle(position.GetLeft(sp_left), position.GetBottom(sp_bottom), position.GetRight(sp_right), position.GetTop(sp_top));
|
||||
rect.CloneNonPositionParameters(this);
|
||||
canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
|
||||
rect.BackgroundColor = null;
|
||||
canvases[PdfPTable.LINECANVAS].Rectangle(rect);
|
||||
}
|
||||
|
||||
/** Sets the padding parameters if they are undefined.
|
||||
* @param padding*/
|
||||
public float Padding {
|
||||
set {
|
||||
if (float.IsNaN(padding_right)) {
|
||||
Padding_right = value;
|
||||
}
|
||||
if (float.IsNaN(padding_left)) {
|
||||
Padding_left = value;
|
||||
}
|
||||
if (float.IsNaN(padding_bottom)) {
|
||||
Padding_bottom = value;
|
||||
}
|
||||
if (float.IsNaN(padding_top)) {
|
||||
Padding_top = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the colspan.
|
||||
*/
|
||||
public int Colspan {
|
||||
get {
|
||||
return colspan;
|
||||
}
|
||||
set {
|
||||
if (value > 0) this.colspan = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param padding_bottom The padding_bottom to set.
|
||||
*/
|
||||
public float Padding_bottom {
|
||||
get {
|
||||
return padding_bottom;
|
||||
}
|
||||
set {
|
||||
padding_bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_left {
|
||||
get {
|
||||
return padding_left;
|
||||
}
|
||||
set {
|
||||
padding_left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_right {
|
||||
get {
|
||||
return padding_right;
|
||||
}
|
||||
set {
|
||||
padding_right = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Padding_top {
|
||||
get {
|
||||
return padding_top;
|
||||
}
|
||||
set {
|
||||
padding_top = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the spacing.
|
||||
*/
|
||||
public float Spacing {
|
||||
set {
|
||||
this.spacing_left = value;
|
||||
this.spacing_right = value;
|
||||
this.spacing_top = value;
|
||||
this.spacing_bottom = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float Spacing_top {
|
||||
get {
|
||||
return spacing_top;
|
||||
}
|
||||
set {
|
||||
spacing_top = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_bottom {
|
||||
get {
|
||||
return spacing_bottom;
|
||||
}
|
||||
set {
|
||||
spacing_bottom = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_left {
|
||||
get {
|
||||
return spacing_left;
|
||||
}
|
||||
set {
|
||||
spacing_left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Spacing_right {
|
||||
get {
|
||||
return spacing_right;
|
||||
}
|
||||
set {
|
||||
spacing_right = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellgroup.
|
||||
*/
|
||||
public bool Cellgroup {
|
||||
get {
|
||||
return cellgroup;
|
||||
}
|
||||
set {
|
||||
cellgroup = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the horizontal alignment.
|
||||
*/
|
||||
public int HorizontalAlignment {
|
||||
get {
|
||||
return horizontalAlignment;
|
||||
}
|
||||
set {
|
||||
horizontalAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int VerticalAlignment {
|
||||
get {
|
||||
return verticalAlignment;
|
||||
}
|
||||
set {
|
||||
verticalAlignment = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the width.
|
||||
*/
|
||||
public new float Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the widthpercentage.
|
||||
*/
|
||||
public float Widthpercentage {
|
||||
get {
|
||||
return widthpercentage;
|
||||
}
|
||||
set {
|
||||
widthpercentage = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the useAscender.
|
||||
*/
|
||||
public bool UseAscender {
|
||||
get {
|
||||
return useAscender;
|
||||
}
|
||||
set {
|
||||
useAscender = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseDescender {
|
||||
get {
|
||||
return useDescender;
|
||||
}
|
||||
set {
|
||||
useDescender = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the useBorderPadding.
|
||||
*/
|
||||
public bool UseBorderPadding {
|
||||
get {
|
||||
return useBorderPadding;
|
||||
}
|
||||
set {
|
||||
useBorderPadding = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the content.
|
||||
*/
|
||||
internal ArrayList Content {
|
||||
get {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.TextElementArray#add(java.lang.Object)
|
||||
*/
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
AddElement((IElement)o);
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.CELL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,283 +1,271 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SimpleTable.
|
||||
/// </summary>
|
||||
public class SimpleTable : Rectangle, IPdfPTableEvent, ITextElementArray {
|
||||
|
||||
/** the content of a Table. */
|
||||
private ArrayList content = new ArrayList();
|
||||
/** the width of the Table. */
|
||||
private float width = 0f;
|
||||
/** the widthpercentage of the Table. */
|
||||
private float widthpercentage = 0f;
|
||||
/** the spacing of the Cells. */
|
||||
private float cellspacing;
|
||||
/** the padding of the Cells. */
|
||||
private float cellpadding;
|
||||
/** the alignment of the table. */
|
||||
private int alignment;
|
||||
|
||||
/**
|
||||
* A RectangleCell is always constructed without any dimensions.
|
||||
* Dimensions are defined after creation.
|
||||
*/
|
||||
public SimpleTable() : base(0f, 0f, 0f, 0f) {
|
||||
Border = BOX;
|
||||
BorderWidth = 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to this object.
|
||||
* @param element
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public void AddElement(SimpleCell element) {
|
||||
if (!element.Cellgroup) {
|
||||
throw new BadElementException("You can't add cells to a table directly, add them to a row first.");
|
||||
}
|
||||
content.Add(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Table object based on this TableAttributes object.
|
||||
* @return a com.lowagie.text.Table object
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public Table CreateTable() {
|
||||
if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
|
||||
SimpleCell rowx = (SimpleCell)content[0];
|
||||
int columns = 0;
|
||||
foreach (SimpleCell cell in rowx.Content) {
|
||||
columns += cell.Colspan;
|
||||
}
|
||||
float[] widths = new float[columns];
|
||||
float[] widthpercentages = new float[columns];
|
||||
Table table = new Table(columns);
|
||||
table.Alignment = alignment;
|
||||
table.Spacing = cellspacing;
|
||||
table.Padding = cellpadding;
|
||||
table.CloneNonPositionParameters(this);
|
||||
int pos;
|
||||
foreach (SimpleCell row in content) {
|
||||
pos = 0;
|
||||
foreach (SimpleCell cell in row.Content) {
|
||||
table.AddCell(cell.CreateCell(row));
|
||||
if (cell.Colspan == 1) {
|
||||
if (cell.Width > 0) widths[pos] = cell.Width;
|
||||
if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
|
||||
}
|
||||
pos += cell.Colspan;
|
||||
}
|
||||
}
|
||||
float sumWidths = 0f;
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widths[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widths[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.Width = sumWidths;
|
||||
table.Locked = true;
|
||||
table.Widths = widths;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widthpercentages[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widthpercentages[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.Widths = widthpercentages;
|
||||
}
|
||||
}
|
||||
if (width > 0) {
|
||||
table.Width = width;
|
||||
table.Locked = true;
|
||||
}
|
||||
else if (widthpercentage > 0) {
|
||||
table.Width = widthpercentage;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PdfPTable object based on this TableAttributes object.
|
||||
* @return a com.lowagie.text.pdf.PdfPTable object
|
||||
* @throws DocumentException
|
||||
*/
|
||||
public PdfPTable CreatePdfPTable() {
|
||||
if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
|
||||
SimpleCell rowx = (SimpleCell)content[0];
|
||||
int columns = 0;
|
||||
foreach (SimpleCell cell in rowx.Content) {
|
||||
columns += cell.Colspan;
|
||||
}
|
||||
float[] widths = new float[columns];
|
||||
float[] widthpercentages = new float[columns];
|
||||
PdfPTable table = new PdfPTable(columns);
|
||||
table.TableEvent = this;
|
||||
table.HorizontalAlignment = alignment;
|
||||
int pos;
|
||||
foreach (SimpleCell row in content) {
|
||||
pos = 0;
|
||||
foreach (SimpleCell cell in row.Content) {
|
||||
if (float.IsNaN(cell.Spacing_left)) {
|
||||
cell.Spacing_left = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_right)) {
|
||||
cell.Spacing_right = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_top)) {
|
||||
cell.Spacing_top = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_bottom)) {
|
||||
cell.Spacing_bottom = cellspacing / 2f;
|
||||
}
|
||||
cell.Padding = cellpadding;
|
||||
table.AddCell(cell.CreatePdfPCell(row));
|
||||
if (cell.Colspan == 1) {
|
||||
if (cell.Width > 0) widths[pos] = cell.Width;
|
||||
if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
|
||||
}
|
||||
pos += cell.Colspan;
|
||||
}
|
||||
}
|
||||
float sumWidths = 0f;
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widths[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widths[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.TotalWidth = sumWidths;
|
||||
table.SetWidths(widths);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widthpercentages[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widthpercentages[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.SetWidths(widthpercentages);
|
||||
}
|
||||
}
|
||||
if (width > 0) {
|
||||
table.TotalWidth = width;
|
||||
}
|
||||
if (widthpercentage > 0) {
|
||||
table.WidthPercentage = widthpercentage;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rectangle
|
||||
* @param spacing
|
||||
* @return a rectangle
|
||||
*/
|
||||
public static SimpleTable GetDimensionlessInstance(Rectangle rectangle, float spacing) {
|
||||
SimpleTable ev = new SimpleTable();
|
||||
ev.CloneNonPositionParameters(rectangle);
|
||||
ev.Cellspacing = spacing;
|
||||
return ev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
|
||||
*/
|
||||
public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
|
||||
float[] width = widths[0];
|
||||
Rectangle rect = new Rectangle(width[0], heights[heights.Length - 1], width[width.Length - 1], heights[0]);
|
||||
rect.CloneNonPositionParameters(this);
|
||||
int bd = rect.Border;
|
||||
rect.Border = Rectangle.NO_BORDER;
|
||||
canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
|
||||
rect.Border = bd;
|
||||
rect.BackgroundColor = null;
|
||||
canvases[PdfPTable.LINECANVAS].Rectangle(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellpadding.
|
||||
*/
|
||||
public float Cellpadding {
|
||||
get {
|
||||
return cellpadding;
|
||||
}
|
||||
set {
|
||||
cellpadding = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellspacing.
|
||||
*/
|
||||
public float Cellspacing {
|
||||
get {
|
||||
return cellspacing;
|
||||
}
|
||||
set {
|
||||
cellspacing = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the alignment.
|
||||
*/
|
||||
public int Alignment {
|
||||
get {
|
||||
return alignment;
|
||||
}
|
||||
set {
|
||||
alignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the width.
|
||||
*/
|
||||
public override float Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the widthpercentage.
|
||||
*/
|
||||
public float Widthpercentage {
|
||||
get {
|
||||
return widthpercentage;
|
||||
}
|
||||
set {
|
||||
widthpercentage = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see com.lowagie.text.Element#type()
|
||||
*/
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace iTextSharp.text
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SimpleTable.
|
||||
/// </summary>
|
||||
public class SimpleTable : Rectangle, IPdfPTableEvent, ITextElementArray {
|
||||
|
||||
/** the content of a Table. */
|
||||
private ArrayList content = new ArrayList();
|
||||
/** the width of the Table. */
|
||||
private float width = 0f;
|
||||
/** the widthpercentage of the Table. */
|
||||
private float widthpercentage = 0f;
|
||||
/** the spacing of the Cells. */
|
||||
private float cellspacing;
|
||||
/** the padding of the Cells. */
|
||||
private float cellpadding;
|
||||
/** the alignment of the table. */
|
||||
private int alignment;
|
||||
|
||||
/**
|
||||
* A RectangleCell is always constructed without any dimensions.
|
||||
* Dimensions are defined after creation.
|
||||
*/
|
||||
public SimpleTable() : base(0f, 0f, 0f, 0f) {
|
||||
Border = BOX;
|
||||
BorderWidth = 2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content to this object.
|
||||
* @param element
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public void AddElement(SimpleCell element) {
|
||||
if (!element.Cellgroup) {
|
||||
throw new BadElementException("You can't add cells to a table directly, add them to a row first.");
|
||||
}
|
||||
content.Add(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Table object based on this TableAttributes object.
|
||||
* @return a com.lowagie.text.Table object
|
||||
* @throws BadElementException
|
||||
*/
|
||||
public Table CreateTable() {
|
||||
if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
|
||||
SimpleCell rowx = (SimpleCell)content[0];
|
||||
int columns = 0;
|
||||
foreach (SimpleCell cell in rowx.Content) {
|
||||
columns += cell.Colspan;
|
||||
}
|
||||
float[] widths = new float[columns];
|
||||
float[] widthpercentages = new float[columns];
|
||||
Table table = new Table(columns);
|
||||
table.Alignment = alignment;
|
||||
table.Spacing = cellspacing;
|
||||
table.Padding = cellpadding;
|
||||
table.CloneNonPositionParameters(this);
|
||||
int pos;
|
||||
foreach (SimpleCell row in content) {
|
||||
pos = 0;
|
||||
foreach (SimpleCell cell in row.Content) {
|
||||
table.AddCell(cell.CreateCell(row));
|
||||
if (cell.Colspan == 1) {
|
||||
if (cell.Width > 0) widths[pos] = cell.Width;
|
||||
if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
|
||||
}
|
||||
pos += cell.Colspan;
|
||||
}
|
||||
}
|
||||
float sumWidths = 0f;
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widths[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widths[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.Width = sumWidths;
|
||||
table.Locked = true;
|
||||
table.Widths = widths;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widthpercentages[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widthpercentages[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.Widths = widthpercentages;
|
||||
}
|
||||
}
|
||||
if (width > 0) {
|
||||
table.Width = width;
|
||||
table.Locked = true;
|
||||
}
|
||||
else if (widthpercentage > 0) {
|
||||
table.Width = widthpercentage;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PdfPTable object based on this TableAttributes object.
|
||||
* @return a com.lowagie.text.pdf.PdfPTable object
|
||||
* @throws DocumentException
|
||||
*/
|
||||
public PdfPTable CreatePdfPTable() {
|
||||
if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
|
||||
SimpleCell rowx = (SimpleCell)content[0];
|
||||
int columns = 0;
|
||||
foreach (SimpleCell cell in rowx.Content) {
|
||||
columns += cell.Colspan;
|
||||
}
|
||||
float[] widths = new float[columns];
|
||||
float[] widthpercentages = new float[columns];
|
||||
PdfPTable table = new PdfPTable(columns);
|
||||
table.TableEvent = this;
|
||||
table.HorizontalAlignment = alignment;
|
||||
int pos;
|
||||
foreach (SimpleCell row in content) {
|
||||
pos = 0;
|
||||
foreach (SimpleCell cell in row.Content) {
|
||||
if (float.IsNaN(cell.Spacing_left)) {
|
||||
cell.Spacing_left = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_right)) {
|
||||
cell.Spacing_right = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_top)) {
|
||||
cell.Spacing_top = cellspacing / 2f;
|
||||
}
|
||||
if (float.IsNaN(cell.Spacing_bottom)) {
|
||||
cell.Spacing_bottom = cellspacing / 2f;
|
||||
}
|
||||
cell.Padding = cellpadding;
|
||||
table.AddCell(cell.CreatePdfPCell(row));
|
||||
if (cell.Colspan == 1) {
|
||||
if (cell.Width > 0) widths[pos] = cell.Width;
|
||||
if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
|
||||
}
|
||||
pos += cell.Colspan;
|
||||
}
|
||||
}
|
||||
float sumWidths = 0f;
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widths[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widths[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.TotalWidth = sumWidths;
|
||||
table.SetWidths(widths);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (widthpercentages[i] == 0) {
|
||||
sumWidths = 0;
|
||||
break;
|
||||
}
|
||||
sumWidths += widthpercentages[i];
|
||||
}
|
||||
if (sumWidths > 0) {
|
||||
table.SetWidths(widthpercentages);
|
||||
}
|
||||
}
|
||||
if (width > 0) {
|
||||
table.TotalWidth = width;
|
||||
}
|
||||
if (widthpercentage > 0) {
|
||||
table.WidthPercentage = widthpercentage;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable, float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
|
||||
*/
|
||||
public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
|
||||
float[] width = widths[0];
|
||||
Rectangle rect = new Rectangle(width[0], heights[heights.Length - 1], width[width.Length - 1], heights[0]);
|
||||
rect.CloneNonPositionParameters(this);
|
||||
int bd = rect.Border;
|
||||
rect.Border = Rectangle.NO_BORDER;
|
||||
canvases[PdfPTable.BACKGROUNDCANVAS].Rectangle(rect);
|
||||
rect.Border = bd;
|
||||
rect.BackgroundColor = null;
|
||||
canvases[PdfPTable.LINECANVAS].Rectangle(rect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellpadding.
|
||||
*/
|
||||
public float Cellpadding {
|
||||
get {
|
||||
return cellpadding;
|
||||
}
|
||||
set {
|
||||
cellpadding = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the cellspacing.
|
||||
*/
|
||||
public float Cellspacing {
|
||||
get {
|
||||
return cellspacing;
|
||||
}
|
||||
set {
|
||||
cellspacing = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the alignment.
|
||||
*/
|
||||
public int Alignment {
|
||||
get {
|
||||
return alignment;
|
||||
}
|
||||
set {
|
||||
alignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the width.
|
||||
*/
|
||||
public override float Width {
|
||||
get {
|
||||
return width;
|
||||
}
|
||||
set {
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return Returns the widthpercentage.
|
||||
*/
|
||||
public float Widthpercentage {
|
||||
get {
|
||||
return widthpercentage;
|
||||
}
|
||||
set {
|
||||
widthpercentage = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see com.lowagie.text.Element#type()
|
||||
*/
|
||||
public override int Type {
|
||||
get {
|
||||
return Element.TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.Element#isNestable()
|
||||
* @since iText 2.0.8
|
||||
|
@ -286,17 +274,17 @@ namespace iTextSharp.text
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.lowagie.text.TextElementArray#add(java.lang.Object)
|
||||
*/
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
AddElement((SimpleCell)o);
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see com.lowagie.text.TextElementArray#add(java.lang.Object)
|
||||
*/
|
||||
public bool Add(Object o) {
|
||||
try {
|
||||
AddElement((SimpleCell)o);
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace iTextSharp.text
|
|||
case (char)933:
|
||||
return 'U'; // UPSILON
|
||||
case (char)934:
|
||||
return 'J'; // PHI
|
||||
return 'F'; // PHI
|
||||
case (char)935:
|
||||
return 'C'; // CHI
|
||||
case (char)936:
|
||||
|
@ -187,7 +187,7 @@ namespace iTextSharp.text
|
|||
case (char)965:
|
||||
return 'u'; // upsilon
|
||||
case (char)966:
|
||||
return 'j'; // phi
|
||||
return 'f'; // phi
|
||||
case (char)967:
|
||||
return 'c'; // chi
|
||||
case (char)968:
|
||||
|
|
|
@ -1474,7 +1474,10 @@ namespace iTextSharp.text {
|
|||
pdfptable.ElementComplete = complete;
|
||||
if (NotAddedYet)
|
||||
pdfptable.SkipFirstHeader = true;
|
||||
pdfptable.TableEvent = SimpleTable.GetDimensionlessInstance(this, cellspacing);
|
||||
SimpleTable t_evt = new SimpleTable();
|
||||
t_evt.CloneNonPositionParameters(this);
|
||||
t_evt.Cellspacing = cellspacing;
|
||||
pdfptable.TableEvent = t_evt;
|
||||
pdfptable.HeaderRows = lastHeaderRow + 1;
|
||||
pdfptable.SplitLate = cellsFitPage;
|
||||
pdfptable.KeepTogether = tableFitsPage;
|
||||
|
@ -1500,7 +1503,10 @@ namespace iTextSharp.text {
|
|||
else if (cell is Cell) {
|
||||
pcell = ((Cell)cell).CreatePdfPCell();
|
||||
pcell.Padding = cellpadding + cellspacing / 2f;
|
||||
pcell.CellEvent = SimpleCell.GetDimensionlessInstance((Cell)cell, cellspacing);
|
||||
SimpleCell c_evt = new SimpleCell(SimpleCell.CELL);
|
||||
c_evt.CloneNonPositionParameters((Cell)cell);
|
||||
c_evt.Spacing = cellspacing * 2f;
|
||||
pcell.CellEvent = c_evt;
|
||||
}
|
||||
else {
|
||||
pcell = new PdfPCell();
|
||||
|
|
Loading…
Reference in New Issue