Initial Commit
This commit is contained in:
561
iTechSharp/iTextSharp/text/rtf/table/RtfBorder.cs
Normal file
561
iTechSharp/iTextSharp/text/rtf/table/RtfBorder.cs
Normal file
@@ -0,0 +1,561 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfBorder.cs,v 1.6 2008/05/16 19:31:18 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfBorder handle one row or cell border.
|
||||
* INTERNAL USE ONLY
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Unknown
|
||||
*/
|
||||
public class RtfBorder : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the left row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_LEFT = DocWriter.GetISOBytes("\\trbrdrl");
|
||||
/**
|
||||
* Constant for the top row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_TOP = DocWriter.GetISOBytes("\\trbrdrt");
|
||||
/**
|
||||
* Constant for the right row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_RIGHT = DocWriter.GetISOBytes("\\trbrdrr");
|
||||
/**
|
||||
* Constant for the bottom row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_BOTTOM = DocWriter.GetISOBytes("\\trbrdrb");
|
||||
/**
|
||||
* Constant for the horizontal line
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_HORIZONTAL = DocWriter.GetISOBytes("\\trbrdrh");
|
||||
/**
|
||||
* Constant for the vertical line
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_VERTICAL = DocWriter.GetISOBytes("\\trbrdrv");
|
||||
/**
|
||||
* Constant for the left cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_LEFT = DocWriter.GetISOBytes("\\clbrdrl");
|
||||
/**
|
||||
* Constant for the top cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_TOP = DocWriter.GetISOBytes("\\clbrdrt");
|
||||
/**
|
||||
* Constant for the right cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_RIGHT = DocWriter.GetISOBytes("\\clbrdrr");
|
||||
/**
|
||||
* Constant for the bottom cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_BOTTOM = DocWriter.GetISOBytes("\\clbrdrb");
|
||||
/**
|
||||
* Constant for the border width
|
||||
*/
|
||||
protected internal static byte[] BORDER_WIDTH = DocWriter.GetISOBytes("\\brdrw");
|
||||
/**
|
||||
* Constant for the border colour number
|
||||
*/
|
||||
protected internal static byte[] BORDER_COLOR_NUMBER = DocWriter.GetISOBytes("\\brdrcf");
|
||||
/**
|
||||
* Constant for the single border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_SINGLE = DocWriter.GetISOBytes("\\brdrs");
|
||||
/**
|
||||
* Constant for the double thick border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOUBLE_THICK = DocWriter.GetISOBytes("\\brdrth");
|
||||
/**
|
||||
* Constant for the shadowed border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_SHADOWED = DocWriter.GetISOBytes("\\brdrsh");
|
||||
/**
|
||||
* Constant for the dotted border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOTTED = DocWriter.GetISOBytes("\\brdrdot");
|
||||
/**
|
||||
* Constant for the dashed border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DASHED = DocWriter.GetISOBytes("\\brdrdash");
|
||||
/**
|
||||
* Constant for the hairline border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_HAIRLINE = DocWriter.GetISOBytes("\\brdrhair");
|
||||
/**
|
||||
* Constant for the double border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOUBLE = DocWriter.GetISOBytes("\\brdrdb");
|
||||
/**
|
||||
* Constant for the dot dash border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOT_DASH = DocWriter.GetISOBytes("\\brdrdashd");
|
||||
/**
|
||||
* Constant for the dot dot dash border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOT_DOT_DASH = DocWriter.GetISOBytes("\\brdrdashdd");
|
||||
/**
|
||||
* Constant for the triple border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_TRIPLE = DocWriter.GetISOBytes("\\brdrtriple");
|
||||
/**
|
||||
* Constant for the thick thin border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THICK_THIN = DocWriter.GetISOBytes("\\brdrtnthsg");
|
||||
/**
|
||||
* Constant for the thin thick border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK = DocWriter.GetISOBytes("\\brdrthtnsg");
|
||||
/**
|
||||
* Constant for the thin thick thin border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_THIN = DocWriter.GetISOBytes("\\brdrtnthtnsg");
|
||||
/**
|
||||
* Constant for the thick thin medium border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THICK_THIN_MED = DocWriter.GetISOBytes("\\brdrtnthmg");
|
||||
/**
|
||||
* Constant for the thin thick medium border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_MED = DocWriter.GetISOBytes("\\brdrthtnmg");
|
||||
/**
|
||||
* Constant for the thin thick thin medium border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_THIN_MED = DocWriter.GetISOBytes("\\brdrtnthtnmg");
|
||||
/**
|
||||
* Constant for the thick thin large border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THICK_THIN_LARGE = DocWriter.GetISOBytes("\\brdrtnthlg");
|
||||
/**
|
||||
* Constant for the thin thick large border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_LARGE = DocWriter.GetISOBytes("\\brdrthtnlg");
|
||||
/**
|
||||
* Constant for the thin thick thin large border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_THIN_LARGE = DocWriter.GetISOBytes("\\brdrtnthtnlg");
|
||||
/**
|
||||
* Constant for the wavy border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_WAVY = DocWriter.GetISOBytes("\\brdrwavy");
|
||||
/**
|
||||
* Constant for the double wavy border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOUBLE_WAVY = DocWriter.GetISOBytes("\\brdrwavydb");
|
||||
/**
|
||||
* Constant for the striped border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_STRIPED = DocWriter.GetISOBytes("\\brdrdashdotstr");
|
||||
/**
|
||||
* Constant for the embossed border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_EMBOSS = DocWriter.GetISOBytes("\\brdremboss");
|
||||
/**
|
||||
* Constant for the engraved border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_ENGRAVE = DocWriter.GetISOBytes("\\brdrengrave");
|
||||
|
||||
/**
|
||||
* Constant for a row border
|
||||
*/
|
||||
protected internal const int ROW_BORDER = 1;
|
||||
/**
|
||||
* Constant for a cell border
|
||||
*/
|
||||
protected internal const int CELL_BORDER = 2;
|
||||
|
||||
/**
|
||||
* This border is no border :-)
|
||||
*/
|
||||
protected internal const int NO_BORDER = 0;
|
||||
/**
|
||||
* Constant for a left border
|
||||
*/
|
||||
protected internal const int LEFT_BORDER = 1;
|
||||
/**
|
||||
* Constant for a top border
|
||||
*/
|
||||
protected internal const int TOP_BORDER = 2;
|
||||
/**
|
||||
* Constant for a right border
|
||||
*/
|
||||
protected internal const int RIGHT_BORDER = 4;
|
||||
/**
|
||||
* Constant for a bottom border
|
||||
*/
|
||||
protected internal const int BOTTOM_BORDER = 8;
|
||||
/**
|
||||
* Constant for a box (left, top, right, bottom) border
|
||||
*/
|
||||
protected internal const int BOX_BORDER = 15;
|
||||
/**
|
||||
* Constant for a vertical line
|
||||
*/
|
||||
protected internal const int VERTICAL_BORDER = 16;
|
||||
/**
|
||||
* Constant for a horizontal line
|
||||
*/
|
||||
protected internal const int HORIZONTAL_BORDER = 32;
|
||||
|
||||
/**
|
||||
* Constant for a border with no border
|
||||
*/
|
||||
public const int BORDER_NONE = 0;
|
||||
/**
|
||||
* Constant for a single border
|
||||
*/
|
||||
public const int BORDER_SINGLE = 1;
|
||||
/**
|
||||
* Constant for a double thick border
|
||||
*/
|
||||
public const int BORDER_DOUBLE_THICK = 2;
|
||||
/**
|
||||
* Constant for a shadowed border
|
||||
*/
|
||||
public const int BORDER_SHADOWED = 3;
|
||||
/**
|
||||
* Constant for a dotted border
|
||||
*/
|
||||
public const int BORDER_DOTTED = 4;
|
||||
/**
|
||||
* Constant for a dashed border
|
||||
*/
|
||||
public const int BORDER_DASHED = 5;
|
||||
/**
|
||||
* Constant for a hairline border
|
||||
*/
|
||||
public const int BORDER_HAIRLINE = 6;
|
||||
/**
|
||||
* Constant for a double border
|
||||
*/
|
||||
public const int BORDER_DOUBLE = 7;
|
||||
/**
|
||||
* Constant for a dot dash border
|
||||
*/
|
||||
public const int BORDER_DOT_DASH = 8;
|
||||
/**
|
||||
* Constant for a dot dot dash border
|
||||
*/
|
||||
public const int BORDER_DOT_DOT_DASH = 9;
|
||||
/**
|
||||
* Constant for a triple border
|
||||
*/
|
||||
public const int BORDER_TRIPLE = 10;
|
||||
/**
|
||||
* Constant for a thick thin border
|
||||
*/
|
||||
public const int BORDER_THICK_THIN = 11;
|
||||
/**
|
||||
* Constant for a thin thick border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK = 12;
|
||||
/**
|
||||
* Constant for a thin thick thin border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_THIN = 13;
|
||||
/**
|
||||
* Constant for a thick thin medium border
|
||||
*/
|
||||
public const int BORDER_THICK_THIN_MED = 14;
|
||||
/**
|
||||
* Constant for a thin thick medium border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_MED = 15;
|
||||
/**
|
||||
* Constant for a thin thick thin medium border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_THIN_MED = 16;
|
||||
/**
|
||||
* Constant for a thick thin large border
|
||||
*/
|
||||
public const int BORDER_THICK_THIN_LARGE = 17;
|
||||
/**
|
||||
* Constant for a thin thick large border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_LARGE = 18;
|
||||
/**
|
||||
* Constant for a thin thick thin large border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_THIN_LARGE = 19;
|
||||
/**
|
||||
* Constant for a wavy border
|
||||
*/
|
||||
public const int BORDER_WAVY = 20;
|
||||
/**
|
||||
* Constant for a double wavy border
|
||||
*/
|
||||
public const int BORDER_DOUBLE_WAVY = 21;
|
||||
/**
|
||||
* Constant for a striped border
|
||||
*/
|
||||
public const int BORDER_STRIPED = 22;
|
||||
/**
|
||||
* Constant for an embossed border
|
||||
*/
|
||||
public const int BORDER_EMBOSS = 23;
|
||||
/**
|
||||
* Constant for an engraved border
|
||||
*/
|
||||
public const int BORDER_ENGRAVE = 24;
|
||||
|
||||
/**
|
||||
* The type of this RtfBorder
|
||||
*/
|
||||
private int borderType = ROW_BORDER;
|
||||
/**
|
||||
* The position of this RtfBorder
|
||||
*/
|
||||
private int borderPosition = NO_BORDER;
|
||||
/**
|
||||
* The style of this RtfBorder
|
||||
*/
|
||||
private int borderStyle = BORDER_NONE;
|
||||
/**
|
||||
* The width of this RtfBorder
|
||||
*/
|
||||
private int borderWidth = 20;
|
||||
/**
|
||||
* The colour of this RtfBorder
|
||||
*/
|
||||
private RtfColor borderColor = null;
|
||||
|
||||
/**
|
||||
* Makes a copy of the given RtfBorder
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorder belongs to
|
||||
* @param borderType The border type of this RtfBorder
|
||||
* @param border The RtfBorder to copy
|
||||
*/
|
||||
protected internal RtfBorder(RtfDocument doc, int borderType, RtfBorder border) : base(doc) {
|
||||
this.borderType = borderType;
|
||||
this.borderPosition = border.GetBorderPosition();
|
||||
this.borderStyle = border.GetBorderStyle();
|
||||
this.borderWidth = border.GetBorderWidth();
|
||||
this.borderColor = new RtfColor(this.document, border.GetBorderColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorder
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorder belongs to
|
||||
* @param borderType The type of border this RtfBorder is
|
||||
* @param borderPosition The position of this RtfBorder
|
||||
* @param borderStyle The style of this RtfBorder
|
||||
* @param borderWidth The width of this RtfBorder
|
||||
* @param borderColor The colour of this RtfBorder
|
||||
*/
|
||||
protected internal RtfBorder(RtfDocument doc, int borderType, int borderPosition, int borderStyle, float borderWidth, Color borderColor) : base(doc) {
|
||||
this.borderType = borderType;
|
||||
this.borderPosition = borderPosition;
|
||||
this.borderStyle = borderStyle;
|
||||
this.borderWidth = (int) Math.Min((borderWidth * TWIPS_FACTOR), 75);
|
||||
if (this.borderWidth == 0) {
|
||||
this.borderStyle = BORDER_NONE;
|
||||
}
|
||||
if (borderColor == null) {
|
||||
this.borderColor = new RtfColor(this.document, new Color(0, 0, 0));
|
||||
} else {
|
||||
this.borderColor = new RtfColor(this.document, borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the RtfBorder settings
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
if (this.borderStyle == BORDER_NONE || this.borderPosition == NO_BORDER || this.borderWidth == 0) {
|
||||
return;
|
||||
}
|
||||
byte[] t;
|
||||
if (this.borderType == ROW_BORDER) {
|
||||
switch (this.borderPosition) {
|
||||
case LEFT_BORDER:
|
||||
result.Write(ROW_BORDER_LEFT, 0, ROW_BORDER_LEFT.Length);
|
||||
break;
|
||||
case TOP_BORDER:
|
||||
result.Write(ROW_BORDER_TOP, 0, ROW_BORDER_TOP.Length);
|
||||
break;
|
||||
case RIGHT_BORDER:
|
||||
result.Write(ROW_BORDER_RIGHT, 0, ROW_BORDER_RIGHT.Length);
|
||||
break;
|
||||
case BOTTOM_BORDER:
|
||||
result.Write(ROW_BORDER_BOTTOM, 0, ROW_BORDER_BOTTOM.Length);
|
||||
break;
|
||||
case HORIZONTAL_BORDER:
|
||||
result.Write(ROW_BORDER_HORIZONTAL, 0, ROW_BORDER_HORIZONTAL.Length);
|
||||
break;
|
||||
case VERTICAL_BORDER:
|
||||
result.Write(ROW_BORDER_VERTICAL, 0, ROW_BORDER_VERTICAL.Length);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
result.Write(t = WriteBorderStyle(), 0, t.Length);
|
||||
result.Write(BORDER_WIDTH, 0, BORDER_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(this.borderWidth), 0, t.Length);
|
||||
result.Write(BORDER_COLOR_NUMBER, 0, BORDER_COLOR_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(this.borderColor.GetColorNumber()), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
} else if (this.borderType == CELL_BORDER) {
|
||||
switch (this.borderPosition) {
|
||||
case LEFT_BORDER:
|
||||
result.Write(CELL_BORDER_LEFT, 0, CELL_BORDER_LEFT.Length);
|
||||
break;
|
||||
case TOP_BORDER:
|
||||
result.Write(CELL_BORDER_TOP, 0, CELL_BORDER_TOP.Length);
|
||||
break;
|
||||
case RIGHT_BORDER:
|
||||
result.Write(CELL_BORDER_RIGHT, 0, CELL_BORDER_RIGHT.Length);
|
||||
break;
|
||||
case BOTTOM_BORDER:
|
||||
result.Write(CELL_BORDER_BOTTOM, 0, CELL_BORDER_BOTTOM.Length);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
result.Write(t = WriteBorderStyle(), 0, t.Length);
|
||||
result.Write(BORDER_WIDTH, 0, BORDER_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(this.borderWidth), 0, t.Length);
|
||||
result.Write(BORDER_COLOR_NUMBER, 0, BORDER_COLOR_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(this.borderColor.GetColorNumber()), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the style of this RtfBorder
|
||||
*
|
||||
* @return A byte array containing the style of this RtfBorder
|
||||
*/
|
||||
private byte[] WriteBorderStyle() {
|
||||
switch (this.borderStyle) {
|
||||
case BORDER_NONE : return new byte[0];
|
||||
case BORDER_SINGLE : return BORDER_STYLE_SINGLE;
|
||||
case BORDER_DOUBLE_THICK : return BORDER_STYLE_DOUBLE_THICK;
|
||||
case BORDER_SHADOWED : return BORDER_STYLE_SHADOWED;
|
||||
case BORDER_DOTTED : return BORDER_STYLE_DOTTED;
|
||||
case BORDER_DASHED : return BORDER_STYLE_DASHED;
|
||||
case BORDER_HAIRLINE : return BORDER_STYLE_HAIRLINE;
|
||||
case BORDER_DOUBLE : return BORDER_STYLE_DOUBLE;
|
||||
case BORDER_DOT_DASH : return BORDER_STYLE_DOT_DASH;
|
||||
case BORDER_DOT_DOT_DASH : return BORDER_STYLE_DOT_DOT_DASH;
|
||||
case BORDER_TRIPLE : return BORDER_STYLE_TRIPLE;
|
||||
case BORDER_THICK_THIN : return BORDER_STYLE_THICK_THIN;
|
||||
case BORDER_THIN_THICK : return BORDER_STYLE_THIN_THICK;
|
||||
case BORDER_THIN_THICK_THIN : return BORDER_STYLE_THIN_THICK_THIN;
|
||||
case BORDER_THICK_THIN_MED : return BORDER_STYLE_THICK_THIN_MED;
|
||||
case BORDER_THIN_THICK_MED : return BORDER_STYLE_THIN_THICK_MED;
|
||||
case BORDER_THIN_THICK_THIN_MED : return BORDER_STYLE_THIN_THICK_THIN_MED;
|
||||
case BORDER_THICK_THIN_LARGE : return BORDER_STYLE_THICK_THIN_LARGE;
|
||||
case BORDER_THIN_THICK_LARGE : return BORDER_STYLE_THIN_THICK_LARGE;
|
||||
case BORDER_THIN_THICK_THIN_LARGE : return BORDER_STYLE_THIN_THICK_THIN_LARGE;
|
||||
case BORDER_WAVY : return BORDER_STYLE_WAVY;
|
||||
case BORDER_DOUBLE_WAVY : return BORDER_STYLE_DOUBLE_WAVY;
|
||||
case BORDER_STRIPED : return BORDER_STYLE_STRIPED;
|
||||
case BORDER_EMBOSS : return BORDER_STYLE_EMBOSS;
|
||||
case BORDER_ENGRAVE : return BORDER_STYLE_ENGRAVE;
|
||||
default : return BORDER_STYLE_SINGLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the colour of this RtfBorder
|
||||
*
|
||||
* @return Returns RtfColor of this RtfBorder
|
||||
*/
|
||||
protected RtfColor GetBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of this RtfBorder
|
||||
* @return Returns the position of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderPosition() {
|
||||
return borderPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the style of this RtfBorder
|
||||
*
|
||||
* @return Returns the style of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderStyle() {
|
||||
return borderStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of this RtfBorder
|
||||
*
|
||||
* @return Returns the type of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderType() {
|
||||
return borderType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of this RtfBorder
|
||||
*
|
||||
* @return Returns the width of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderWidth() {
|
||||
return borderWidth;
|
||||
}
|
||||
}
|
||||
}
|
213
iTechSharp/iTextSharp/text/rtf/table/RtfBorderGroup.cs
Normal file
213
iTechSharp/iTextSharp/text/rtf/table/RtfBorderGroup.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfBorderGroup.cs,v 1.5 2008/05/16 19:31:18 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfBorderGroup represents a collection of RtfBorders to use in a RtfCell
|
||||
* or RtfTable.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfBorderGroup : RtfElement {
|
||||
/**
|
||||
* The type of borders this RtfBorderGroup contains.
|
||||
* RtfBorder.ROW_BORDER or RtfBorder.CELL_BORDER
|
||||
*/
|
||||
private int borderType = RtfBorder.ROW_BORDER;
|
||||
/**
|
||||
* The borders in this RtfBorderGroup
|
||||
*/
|
||||
private Hashtable borders = null;
|
||||
|
||||
/**
|
||||
* Constructs an empty RtfBorderGroup.
|
||||
*/
|
||||
public RtfBorderGroup() : base(null) {
|
||||
this.borders = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorderGroup with on border style for multiple borders.
|
||||
*
|
||||
* @param bordersToAdd The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX)
|
||||
* @param borderStyle The style of border to add (from RtfBorder)
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
public RtfBorderGroup(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) : base(null) {
|
||||
this.borders = new Hashtable();
|
||||
AddBorder(bordersToAdd, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorderGroup based on another RtfBorderGroup.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorderGroup belongs to
|
||||
* @param borderType The type of borders this RtfBorderGroup contains
|
||||
* @param borderGroup The RtfBorderGroup to use as a base
|
||||
*/
|
||||
protected internal RtfBorderGroup(RtfDocument doc, int borderType, RtfBorderGroup borderGroup) : base(doc) {
|
||||
this.borders = new Hashtable();
|
||||
this.borderType = borderType;
|
||||
if (borderGroup != null) {
|
||||
foreach (DictionaryEntry entry in borderGroup.GetBorders()) {
|
||||
int borderPos = (int)entry.Key;
|
||||
RtfBorder border = (RtfBorder)entry.Value;
|
||||
this.borders[borderPos] = new RtfBorder(this.document, this.borderType, border);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorderGroup with certain borders
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorderGroup belongs to
|
||||
* @param borderType The type of borders this RtfBorderGroup contains
|
||||
* @param bordersToUse The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX)
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
protected internal RtfBorderGroup(RtfDocument doc, int borderType, int bordersToUse, float borderWidth, Color borderColor) : base(doc) {
|
||||
this.borderType = borderType;
|
||||
this.borders = new Hashtable();
|
||||
AddBorder(bordersToUse, RtfBorder.BORDER_SINGLE, borderWidth, borderColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a border in the Hashtable of borders
|
||||
*
|
||||
* @param borderPosition The position of this RtfBorder
|
||||
* @param borderStyle The type of borders this RtfBorderGroup contains
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
private void SetBorder(int borderPosition, int borderStyle, float borderWidth, Color borderColor) {
|
||||
RtfBorder border = new RtfBorder(this.document, this.borderType, borderPosition, borderStyle, borderWidth, borderColor);
|
||||
this.borders[borderPosition] = border;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds borders to the RtfBorderGroup
|
||||
*
|
||||
* @param bordersToAdd The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX)
|
||||
* @param borderStyle The style of border to add (from RtfBorder)
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
public void AddBorder(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) {
|
||||
if ((bordersToAdd & Rectangle.LEFT_BORDER) == Rectangle.LEFT_BORDER) {
|
||||
SetBorder(RtfBorder.LEFT_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.TOP_BORDER) == Rectangle.TOP_BORDER) {
|
||||
SetBorder(RtfBorder.TOP_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.RIGHT_BORDER) == Rectangle.RIGHT_BORDER) {
|
||||
SetBorder(RtfBorder.RIGHT_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.BOTTOM_BORDER) == Rectangle.BOTTOM_BORDER) {
|
||||
SetBorder(RtfBorder.BOTTOM_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.BOX) == Rectangle.BOX && this.borderType == RtfBorder.ROW_BORDER) {
|
||||
SetBorder(RtfBorder.VERTICAL_BORDER, borderStyle, borderWidth, borderColor);
|
||||
SetBorder(RtfBorder.HORIZONTAL_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes borders from the list of borders
|
||||
*
|
||||
* @param bordersToRemove The borders to remove (from Rectangle)
|
||||
*/
|
||||
public void RemoveBorder(int bordersToRemove) {
|
||||
if ((bordersToRemove & Rectangle.LEFT_BORDER) == Rectangle.LEFT_BORDER) {
|
||||
this.borders.Remove(RtfBorder.LEFT_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.TOP_BORDER) == Rectangle.TOP_BORDER) {
|
||||
this.borders.Remove(RtfBorder.TOP_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.RIGHT_BORDER) == Rectangle.RIGHT_BORDER) {
|
||||
this.borders.Remove(RtfBorder.RIGHT_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.BOTTOM_BORDER) == Rectangle.BOTTOM_BORDER) {
|
||||
this.borders.Remove(RtfBorder.BOTTOM_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.BOX) == Rectangle.BOX && this.borderType == RtfBorder.ROW_BORDER) {
|
||||
this.borders.Remove(RtfBorder.VERTICAL_BORDER);
|
||||
this.borders.Remove(RtfBorder.HORIZONTAL_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the borders of this RtfBorderGroup
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
foreach (RtfBorder rb in this.borders.Values) {
|
||||
rb.WriteContent(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfBorders of this RtfBorderGroup
|
||||
*
|
||||
* @return The RtfBorders of this RtfBorderGroup
|
||||
*/
|
||||
protected internal Hashtable GetBorders() {
|
||||
return this.borders;
|
||||
}
|
||||
}
|
||||
}
|
493
iTechSharp/iTextSharp/text/rtf/table/RtfCell.cs
Normal file
493
iTechSharp/iTextSharp/text/rtf/table/RtfCell.cs
Normal file
@@ -0,0 +1,493 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.text;
|
||||
/*
|
||||
* $Id: RtfCell.cs,v 1.14 2008/05/16 19:31:18 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfCell wraps a Cell, but can also be added directly to a Table.
|
||||
* The RtfCell is an extension of Cell, that supports a multitude of different
|
||||
* borderstyles.
|
||||
*
|
||||
* @version $Id: RtfCell.cs,v 1.14 2008/05/16 19:31:18 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Steffen Stundzig
|
||||
* @author Benoit WIART <b.wiart@proxiad.com>
|
||||
* @see com.lowagie.text.rtf.table.RtfBorder
|
||||
*/
|
||||
public class RtfCell : Cell, IRtfExtendedElement {
|
||||
|
||||
/**
|
||||
* This cell is not merged
|
||||
*/
|
||||
private const int MERGE_NONE = 0;
|
||||
/**
|
||||
* This cell is the parent cell of a vertical merge operation
|
||||
*/
|
||||
private const int MERGE_VERT_PARENT = 1;
|
||||
/**
|
||||
* This cell is a child cell of a vertical merge operation
|
||||
*/
|
||||
private const int MERGE_VERT_CHILD = 2;
|
||||
|
||||
/**
|
||||
* The parent RtfRow of this RtfCell
|
||||
*/
|
||||
private RtfRow parentRow = null;
|
||||
/**
|
||||
* The content of this RtfCell
|
||||
*/
|
||||
private ArrayList content = null;
|
||||
/**
|
||||
* The right margin of this RtfCell
|
||||
*/
|
||||
private int cellRight = 0;
|
||||
/**
|
||||
* The width of this RtfCell
|
||||
*/
|
||||
private int cellWidth = 0;
|
||||
/**
|
||||
* The borders of this RtfCell
|
||||
*/
|
||||
private RtfBorderGroup borders = null;
|
||||
/**
|
||||
* The background color of this RtfCell
|
||||
*/
|
||||
private new RtfColor backgroundColor = null;
|
||||
/**
|
||||
* The padding of this RtfCell
|
||||
*/
|
||||
private int cellPadding = 0;
|
||||
/**
|
||||
* The merge type of this RtfCell
|
||||
*/
|
||||
private int mergeType = MERGE_NONE;
|
||||
/**
|
||||
* The RtfDocument this RtfCell belongs to
|
||||
*/
|
||||
private RtfDocument document = null;
|
||||
/**
|
||||
* Whether this RtfCell is in a header
|
||||
*/
|
||||
private bool inHeader = false;
|
||||
/**
|
||||
* Whether this RtfCell is a placeholder for a removed table cell.
|
||||
*/
|
||||
private bool deleted = false;
|
||||
|
||||
/**
|
||||
* Constructs an empty RtfCell
|
||||
*/
|
||||
public RtfCell() : base() {
|
||||
this.borders = new RtfBorderGroup();
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfCell based upon a String
|
||||
*
|
||||
* @param content The String to base the RtfCell on
|
||||
*/
|
||||
public RtfCell(String content) : base(content) {
|
||||
this.borders = new RtfBorderGroup();
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfCell based upon an Element
|
||||
*
|
||||
* @param element The Element to base the RtfCell on
|
||||
* @throws BadElementException If the Element is not valid
|
||||
*/
|
||||
public RtfCell(IElement element) : base(element) {
|
||||
this.borders = new RtfBorderGroup();
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a deleted RtfCell.
|
||||
*
|
||||
* @param deleted Whether this RtfCell is actually deleted.
|
||||
*/
|
||||
protected internal RtfCell(bool deleted) : base() {
|
||||
this.deleted = deleted;
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfCell based on a Cell.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfCell belongs to
|
||||
* @param row The RtfRow this RtfCell lies in
|
||||
* @param cell The Cell to base this RtfCell on
|
||||
*/
|
||||
protected internal RtfCell(RtfDocument doc, RtfRow row, Cell cell) {
|
||||
this.document = doc;
|
||||
this.parentRow = row;
|
||||
ImportCell(cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports the Cell properties into the RtfCell
|
||||
*
|
||||
* @param cell The Cell to import
|
||||
*/
|
||||
private void ImportCell(Cell cell) {
|
||||
this.content = new ArrayList();
|
||||
|
||||
if (cell == null) {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders());
|
||||
return;
|
||||
}
|
||||
|
||||
this.colspan = cell.Colspan;
|
||||
this.rowspan = cell.Rowspan;
|
||||
if (cell.Rowspan > 1) {
|
||||
this.mergeType = MERGE_VERT_PARENT;
|
||||
}
|
||||
if (cell is RtfCell) {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, ((RtfCell) cell).GetBorders());
|
||||
} else {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor);
|
||||
}
|
||||
this.verticalAlignment = cell.VerticalAlignment;
|
||||
if (cell.BackgroundColor == null) {
|
||||
this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
|
||||
} else {
|
||||
this.backgroundColor = new RtfColor(this.document, cell.BackgroundColor);
|
||||
}
|
||||
|
||||
this.cellPadding = (int) this.parentRow.GetParentTable().GetCellPadding();
|
||||
|
||||
Paragraph container = null;
|
||||
foreach (IElement element in cell.Elements) {
|
||||
try {
|
||||
// should we wrap it in a paragraph
|
||||
if (!(element is Paragraph) && !(element is List)) {
|
||||
if (container != null) {
|
||||
container.Add(element);
|
||||
} else {
|
||||
container = new Paragraph();
|
||||
container.Alignment = cell.HorizontalAlignment;
|
||||
container.Add(element);
|
||||
}
|
||||
} else {
|
||||
if (container != null) {
|
||||
IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container);
|
||||
for(int i = 0; i < rtfElements.Length; i++) {
|
||||
rtfElements[i].SetInTable(true);
|
||||
this.content.Add(rtfElements[i]);
|
||||
}
|
||||
container = null;
|
||||
}
|
||||
// if horizontal alignment is undefined overwrite
|
||||
// with that of enclosing cell
|
||||
if (element is Paragraph && ((Paragraph) element).Alignment == Element.ALIGN_UNDEFINED) {
|
||||
((Paragraph) element).Alignment = cell.HorizontalAlignment;
|
||||
}
|
||||
|
||||
IRtfBasicElement[] rtfElements2 = this.document.GetMapper().MapElement(element);
|
||||
for(int i = 0; i < rtfElements2.Length; i++) {
|
||||
rtfElements2[i].SetInTable(true);
|
||||
this.content.Add(rtfElements2[i]);
|
||||
}
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
if (container != null) {
|
||||
try {
|
||||
IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container);
|
||||
for(int i = 0; i < rtfElements.Length; i++) {
|
||||
rtfElements[i].SetInTable(true);
|
||||
this.content.Add(rtfElements[i]);
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the cell definition part of this RtfCell
|
||||
*
|
||||
* @return A byte array with the cell definition
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
byte[] t;
|
||||
if (this.mergeType == MERGE_VERT_PARENT) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvmgf"), 0, t.Length);
|
||||
} else if (this.mergeType == MERGE_VERT_CHILD) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvmrg"), 0, t.Length);
|
||||
}
|
||||
switch (verticalAlignment) {
|
||||
case Element.ALIGN_BOTTOM:
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvertalb"), 0, t.Length);
|
||||
break;
|
||||
case Element.ALIGN_CENTER:
|
||||
case Element.ALIGN_MIDDLE:
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvertalc"), 0, t.Length);
|
||||
break;
|
||||
case Element.ALIGN_TOP:
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvertalt"), 0, t.Length);
|
||||
break;
|
||||
}
|
||||
this.borders.WriteContent(result);
|
||||
|
||||
if (this.backgroundColor != null) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clcbpat"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.backgroundColor.GetColorNumber()), 0, t.Length);
|
||||
}
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clftsWidth3"), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clwWidth"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellWidth), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
if (this.cellPadding > 0) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadl"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadt"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadr"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadb"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadfl3"), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadft3"), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadfr3"), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadfb3"), 0, t.Length);
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\cellx"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellRight), 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of this RtfCell
|
||||
*/
|
||||
public virtual void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
if (this.content.Count == 0) {
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
if (this.parentRow.GetParentTable().GetTableFitToPage()) {
|
||||
result.Write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT, 0, RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT.Length);
|
||||
}
|
||||
result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
|
||||
} else {
|
||||
for (int i = 0; i < this.content.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) this.content[i];
|
||||
if (rtfElement is RtfParagraph) {
|
||||
((RtfParagraph) rtfElement).SetKeepTogetherWithNext(this.parentRow.GetParentTable().GetTableFitToPage());
|
||||
}
|
||||
rtfElement.WriteContent(result);
|
||||
if (rtfElement is RtfParagraph && i < (this.content.Count - 1)) {
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\cell"), 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right margin of this cell. Used in merge operations
|
||||
*
|
||||
* @param cellRight The right margin to use
|
||||
*/
|
||||
protected internal void SetCellRight(int cellRight) {
|
||||
this.cellRight = cellRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the right margin of this RtfCell
|
||||
*
|
||||
* @return The right margin of this RtfCell.
|
||||
*/
|
||||
protected internal int GetCellRight() {
|
||||
return this.cellRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cell width of this RtfCell. Used in merge operations.
|
||||
*
|
||||
* @param cellWidth The cell width to use
|
||||
*/
|
||||
protected internal void SetCellWidth(int cellWidth) {
|
||||
this.cellWidth = cellWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell width of this RtfCell
|
||||
*
|
||||
* @return The cell width of this RtfCell
|
||||
*/
|
||||
protected internal int GetCellWidth() {
|
||||
return this.cellWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell padding of this RtfCell
|
||||
*
|
||||
* @return The cell padding of this RtfCell
|
||||
*/
|
||||
protected internal int GetCellpadding() {
|
||||
return this.cellPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the borders of this RtfCell
|
||||
*
|
||||
* @return The borders of this RtfCell
|
||||
*/
|
||||
protected internal RtfBorderGroup GetBorders() {
|
||||
return this.borders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the borders of this RtfCell
|
||||
*
|
||||
* @param borderGroup The RtfBorderGroup to use as borders
|
||||
*/
|
||||
public void SetBorders(RtfBorderGroup borderGroup) {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, borderGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color of this RtfCell
|
||||
*
|
||||
* @return The background color of this RtfCell
|
||||
*/
|
||||
protected internal RtfColor GetRtfBackgroundColor() {
|
||||
return this.backgroundColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge this cell into the parent cell.
|
||||
*
|
||||
* @param mergeParent The RtfCell to merge with
|
||||
*/
|
||||
protected internal void SetCellMergeChild(RtfCell mergeParent) {
|
||||
this.mergeType = MERGE_VERT_CHILD;
|
||||
this.cellWidth = mergeParent.GetCellWidth();
|
||||
this.cellRight = mergeParent.GetCellRight();
|
||||
this.cellPadding = mergeParent.GetCellpadding();
|
||||
this.borders = mergeParent.GetBorders();
|
||||
this.verticalAlignment = mergeParent.VerticalAlignment;
|
||||
this.backgroundColor = mergeParent.GetRtfBackgroundColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfCell belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param inTable
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfCell is in a header
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfCell is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
this.inHeader = inHeader;
|
||||
for (int i = 0; i < this.content.Count; i++) {
|
||||
((IRtfBasicElement) this.content[i]).SetInHeader(inHeader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this <code>RtfCell</code> is in a header
|
||||
*
|
||||
* @return <code>True</code> if this <code>RtfCell</code> is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public bool IsInHeader() {
|
||||
return this.inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an integer into its String representation and then returns the bytes
|
||||
* of that string.
|
||||
*
|
||||
* @param i The integer to convert
|
||||
* @return A byte array representing the integer
|
||||
*/
|
||||
private byte[] IntToByteArray(int i) {
|
||||
return DocWriter.GetISOBytes(i.ToString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this RtfCell is a placeholder for
|
||||
* a table cell that has been removed due to col/row spanning.
|
||||
*
|
||||
* @return <code>True</code> if this RtfCell is deleted, <code>false</code> otherwise.
|
||||
*/
|
||||
public bool IsDeleted() {
|
||||
return this.deleted;
|
||||
}
|
||||
}
|
||||
}
|
377
iTechSharp/iTextSharp/text/rtf/table/RtfRow.cs
Normal file
377
iTechSharp/iTextSharp/text/rtf/table/RtfRow.cs
Normal file
@@ -0,0 +1,377 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfRow.cs,v 1.10 2008/05/16 19:31:19 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004, 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfRow wraps one Row for a RtfTable.
|
||||
* INTERNAL USE ONLY
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Steffen Stundzig
|
||||
* @author Lorenz Maierhofer <larry@sbox.tugraz.at>
|
||||
*/
|
||||
public class RtfRow : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the RtfRow beginning
|
||||
*/
|
||||
private static byte[] ROW_BEGIN = DocWriter.GetISOBytes("\\trowd");
|
||||
/**
|
||||
* Constant for the RtfRow width style
|
||||
*/
|
||||
private static byte[] ROW_WIDTH_STYLE = DocWriter.GetISOBytes("\\trftsWidth3");
|
||||
/**
|
||||
* Constant for the RtfRow width
|
||||
*/
|
||||
private static byte[] ROW_WIDTH = DocWriter.GetISOBytes("\\trwWidth");
|
||||
/**
|
||||
* Constant to specify that this RtfRow are not to be broken across pages
|
||||
*/
|
||||
private static byte[] ROW_KEEP_TOGETHER = DocWriter.GetISOBytes("\\trkeep");
|
||||
/**
|
||||
* Constant to specify that this is a header RtfRow
|
||||
*/
|
||||
private static byte[] ROW_HEADER_ROW = DocWriter.GetISOBytes("\\trhdr");
|
||||
/**
|
||||
* Constant for left alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_LEFT = DocWriter.GetISOBytes("\\trql");
|
||||
/**
|
||||
* Constant for right alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_RIGHT = DocWriter.GetISOBytes("\\trqr");
|
||||
/**
|
||||
* Constant for center alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_CENTER = DocWriter.GetISOBytes("\\trqc");
|
||||
/**
|
||||
* Constant for justified alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_JUSTIFIED = DocWriter.GetISOBytes("\\trqj");
|
||||
/**
|
||||
* Constant for the graph style of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_GRAPH = DocWriter.GetISOBytes("\\trgaph10");
|
||||
/**
|
||||
* Constant for the cell left spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_LEFT = DocWriter.GetISOBytes("\\trspdl");
|
||||
/**
|
||||
* Constant for the cell top spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_TOP = DocWriter.GetISOBytes("\\trspdt");
|
||||
/**
|
||||
* Constant for the cell right spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_RIGHT = DocWriter.GetISOBytes("\\trspdr");
|
||||
/**
|
||||
* Constant for the cell bottom spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_BOTTOM = DocWriter.GetISOBytes("\\trspdb");
|
||||
/**
|
||||
* Constant for the cell left spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_LEFT_STYLE = DocWriter.GetISOBytes("\\trspdfl3");
|
||||
/**
|
||||
* Constant for the cell top spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_TOP_STYLE = DocWriter.GetISOBytes("\\trspdft3");
|
||||
/**
|
||||
* Constant for the cell right spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_RIGHT_STYLE = DocWriter.GetISOBytes("\\trspdfr3");
|
||||
/**
|
||||
* Constant for the cell bottom spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_BOTTOM_STYLE = DocWriter.GetISOBytes("\\trspdfb3");
|
||||
/**
|
||||
* Constant for the cell left padding
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_LEFT = DocWriter.GetISOBytes("\\trpaddl");
|
||||
/**
|
||||
* Constant for the cell right padding
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_RIGHT = DocWriter.GetISOBytes("\\trpaddr");
|
||||
/**
|
||||
* Constant for the cell left padding style
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_LEFT_STYLE = DocWriter.GetISOBytes("\\trpaddfl3");
|
||||
/**
|
||||
* Constant for the cell right padding style
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_RIGHT_STYLE = DocWriter.GetISOBytes("\\trpaddfr3");
|
||||
/**
|
||||
* Constant for the end of a row
|
||||
*/
|
||||
private static byte[] ROW_END = DocWriter.GetISOBytes("\\row");
|
||||
|
||||
/**
|
||||
* The RtfTable this RtfRow belongs to
|
||||
*/
|
||||
private RtfTable parentTable = null;
|
||||
/**
|
||||
* The cells of this RtfRow
|
||||
*/
|
||||
private ArrayList cells = null;
|
||||
/**
|
||||
* The width of this row
|
||||
*/
|
||||
private int width = 0;
|
||||
/**
|
||||
* The row number
|
||||
*/
|
||||
private int rowNumber = 0;
|
||||
|
||||
/**
|
||||
* Constructs a RtfRow for a Row.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfRow belongs to
|
||||
* @param rtfTable The RtfTable this RtfRow belongs to
|
||||
* @param row The Row this RtfRow is based on
|
||||
* @param rowNumber The number of this row
|
||||
*/
|
||||
protected internal RtfRow(RtfDocument doc, RtfTable rtfTable, Row row, int rowNumber) : base(doc) {
|
||||
this.parentTable = rtfTable;
|
||||
this.rowNumber = rowNumber;
|
||||
ImportRow(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a Row and copies all settings
|
||||
*
|
||||
* @param row The Row to import
|
||||
*/
|
||||
private void ImportRow(Row row) {
|
||||
this.cells = new ArrayList();
|
||||
this.width = this.document.GetDocumentHeader().GetPageSetting().GetPageWidth() - this.document.GetDocumentHeader().GetPageSetting().GetMarginLeft() - this.document.GetDocumentHeader().GetPageSetting().GetMarginRight();
|
||||
this.width = (int) (this.width * this.parentTable.GetTableWidthPercent() / 100);
|
||||
|
||||
int cellRight = 0;
|
||||
int cellWidth = 0;
|
||||
for (int i = 0; i < row.Columns; i++) {
|
||||
cellWidth = (int) (this.width * this.parentTable.GetProportionalWidths()[i] / 100);
|
||||
cellRight = cellRight + cellWidth;
|
||||
|
||||
Cell cell = (Cell) row.GetCell(i);
|
||||
RtfCell rtfCell = new RtfCell(this.document, this, cell);
|
||||
rtfCell.SetCellRight(cellRight);
|
||||
rtfCell.SetCellWidth(cellWidth);
|
||||
this.cells.Add(rtfCell);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a second pass over all cells to handle cell row/column spanning.
|
||||
*/
|
||||
protected internal void HandleCellSpanning() {
|
||||
RtfCell deletedCell = new RtfCell(true);
|
||||
for (int i = 0; i < this.cells.Count; i++) {
|
||||
RtfCell rtfCell = (RtfCell) this.cells[i];
|
||||
if (rtfCell.Colspan > 1) {
|
||||
int cSpan = rtfCell.Colspan;
|
||||
for (int j = i + 1; j < i + cSpan; j++) {
|
||||
if (j < this.cells.Count) {
|
||||
RtfCell rtfCellMerge = (RtfCell) this.cells[j];
|
||||
rtfCell.SetCellRight(rtfCell.GetCellRight() + rtfCellMerge.GetCellWidth());
|
||||
rtfCell.SetCellWidth(rtfCell.GetCellWidth() + rtfCellMerge.GetCellWidth());
|
||||
this.cells[j] = deletedCell;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rtfCell.Rowspan > 1) {
|
||||
ArrayList rows = this.parentTable.GetRows();
|
||||
for (int j = 1; j < rtfCell.Rowspan; j++) {
|
||||
RtfRow mergeRow = (RtfRow) rows[this.rowNumber + j];
|
||||
if (this.rowNumber + j < rows.Count) {
|
||||
RtfCell rtfCellMerge = (RtfCell) mergeRow.GetCells()[i];
|
||||
rtfCellMerge.SetCellMergeChild(rtfCell);
|
||||
}
|
||||
if (rtfCell.Colspan > 1) {
|
||||
int cSpan = rtfCell.Colspan;
|
||||
for (int k = i + 1; k < i + cSpan; k++) {
|
||||
if (k < mergeRow.GetCells().Count) {
|
||||
mergeRow.GetCells()[k] = deletedCell;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the deleted RtfCells from the total RtfCells.
|
||||
*/
|
||||
protected internal void CleanRow() {
|
||||
int i = 0;
|
||||
while (i < this.cells.Count) {
|
||||
if (((RtfCell) this.cells[i]).IsDeleted()) {
|
||||
this.cells.RemoveAt(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the row definition/settings.
|
||||
*
|
||||
* @param result The <code>OutputStream</code> to write the definitions to.
|
||||
*/
|
||||
private void WriteRowDefinition(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(ROW_BEGIN, 0, ROW_BEGIN.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
result.Write(ROW_WIDTH_STYLE, 0, ROW_WIDTH_STYLE.Length);
|
||||
result.Write(ROW_WIDTH, 0, ROW_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(this.width), 0, t.Length);
|
||||
if (this.parentTable.GetCellsFitToPage()) {
|
||||
result.Write(ROW_KEEP_TOGETHER, 0, ROW_KEEP_TOGETHER.Length);
|
||||
}
|
||||
if (this.rowNumber <= this.parentTable.GetHeaderRows()) {
|
||||
result.Write(ROW_HEADER_ROW, 0, ROW_HEADER_ROW.Length);
|
||||
}
|
||||
switch (this.parentTable.GetAlignment()) {
|
||||
case Element.ALIGN_LEFT:
|
||||
result.Write(ROW_ALIGN_LEFT, 0, ROW_ALIGN_LEFT.Length);
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
result.Write(ROW_ALIGN_RIGHT, 0, ROW_ALIGN_RIGHT.Length);
|
||||
break;
|
||||
case Element.ALIGN_CENTER:
|
||||
result.Write(ROW_ALIGN_CENTER, 0, ROW_ALIGN_CENTER.Length);
|
||||
break;
|
||||
case Element.ALIGN_JUSTIFIED:
|
||||
case Element.ALIGN_JUSTIFIED_ALL:
|
||||
result.Write(ROW_ALIGN_JUSTIFIED, 0, ROW_ALIGN_JUSTIFIED.Length);
|
||||
break;
|
||||
}
|
||||
result.Write(ROW_GRAPH, 0, ROW_GRAPH.Length);
|
||||
|
||||
this.parentTable.GetBorders().WriteContent(result);
|
||||
|
||||
if (this.parentTable.GetCellSpacing() > 0) {
|
||||
result.Write(ROW_CELL_SPACING_LEFT, 0, ROW_CELL_SPACING_LEFT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_LEFT_STYLE, 0, ROW_CELL_SPACING_LEFT_STYLE.Length);
|
||||
result.Write(ROW_CELL_SPACING_TOP, 0, ROW_CELL_SPACING_TOP.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_TOP_STYLE, 0, ROW_CELL_SPACING_TOP_STYLE.Length);
|
||||
result.Write(ROW_CELL_SPACING_RIGHT, 0, ROW_CELL_SPACING_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_RIGHT_STYLE, 0, ROW_CELL_SPACING_RIGHT_STYLE.Length);
|
||||
result.Write(ROW_CELL_SPACING_BOTTOM, 0, ROW_CELL_SPACING_BOTTOM.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_BOTTOM_STYLE, 0, ROW_CELL_SPACING_BOTTOM_STYLE.Length);
|
||||
}
|
||||
|
||||
result.Write(ROW_CELL_PADDING_LEFT, 0, ROW_CELL_PADDING_LEFT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellPadding() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_PADDING_RIGHT, 0, ROW_CELL_PADDING_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellPadding() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_PADDING_LEFT_STYLE, 0, ROW_CELL_PADDING_LEFT_STYLE.Length);
|
||||
result.Write(ROW_CELL_PADDING_RIGHT_STYLE, 0, ROW_CELL_PADDING_RIGHT_STYLE.Length);
|
||||
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
for (int i = 0; i < this.cells.Count; i++) {
|
||||
RtfCell rtfCell = (RtfCell) this.cells[i];
|
||||
rtfCell.WriteDefinition(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfRow
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
WriteRowDefinition(result);
|
||||
|
||||
for (int i = 0; i < this.cells.Count; i++) {
|
||||
RtfCell rtfCell = (RtfCell) this.cells[i];
|
||||
rtfCell.WriteContent(result);
|
||||
}
|
||||
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
|
||||
if (this.document.GetDocumentSettings().IsOutputTableRowDefinitionAfter()) {
|
||||
WriteRowDefinition(result);
|
||||
}
|
||||
|
||||
result.Write(ROW_END, 0, ROW_END.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent RtfTable of this RtfRow
|
||||
*
|
||||
* @return The parent RtfTable of this RtfRow
|
||||
*/
|
||||
protected internal RtfTable GetParentTable() {
|
||||
return this.parentTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cells of this RtfRow
|
||||
*
|
||||
* @return The cells of this RtfRow
|
||||
*/
|
||||
protected internal ArrayList GetCells() {
|
||||
return this.cells;
|
||||
}
|
||||
}
|
||||
}
|
271
iTechSharp/iTextSharp/text/rtf/table/RtfTable.cs
Normal file
271
iTechSharp/iTextSharp/text/rtf/table/RtfTable.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfTable.cs,v 1.9 2008/05/23 17:24:29 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfTable wraps a Table.
|
||||
* INTERNAL USE ONLY
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Steffen Stundzig
|
||||
* @author Benoit WIART <b.wiart@proxiad.com>
|
||||
*/
|
||||
public class RtfTable : RtfElement {
|
||||
|
||||
/**
|
||||
* The rows of this RtfTable
|
||||
*/
|
||||
private ArrayList rows = null;
|
||||
/**
|
||||
* The percentage of the page width that this RtfTable covers
|
||||
*/
|
||||
private float tableWidthPercent = 80;
|
||||
/**
|
||||
* An array with the proportional widths of the cells in each row
|
||||
*/
|
||||
private float[] proportionalWidths = null;
|
||||
/**
|
||||
* The cell padding
|
||||
*/
|
||||
private float cellPadding = 0;
|
||||
/**
|
||||
* The cell spacing
|
||||
*/
|
||||
private float cellSpacing = 0;
|
||||
/**
|
||||
* The border style of this RtfTable
|
||||
*/
|
||||
private RtfBorderGroup borders = null;
|
||||
/**
|
||||
* The alignment of this RtfTable
|
||||
*/
|
||||
private int alignment = Element.ALIGN_CENTER;
|
||||
/**
|
||||
* Whether the cells in this RtfTable must fit in a page
|
||||
*/
|
||||
private bool cellsFitToPage = false;
|
||||
/**
|
||||
* Whether the whole RtfTable must fit in a page
|
||||
*/
|
||||
private bool tableFitToPage = false;
|
||||
/**
|
||||
* The number of header rows in this RtfTable
|
||||
*/
|
||||
private int headerRows = 0;
|
||||
/**
|
||||
* The offset from the previous text
|
||||
*/
|
||||
private int offset = -1;
|
||||
|
||||
/**
|
||||
* Constructs a RtfTable based on a Table for a RtfDocument.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfTable belongs to
|
||||
* @param table The Table that this RtfTable wraps
|
||||
*/
|
||||
public RtfTable(RtfDocument doc, Table table) : base(doc) {
|
||||
table.Complete();
|
||||
ImportTable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports the rows and settings from the Table into this
|
||||
* RtfTable.
|
||||
*
|
||||
* @param table The source Table
|
||||
*/
|
||||
private void ImportTable(Table table) {
|
||||
this.rows = new ArrayList();
|
||||
this.tableWidthPercent = table.Width;
|
||||
this.proportionalWidths = table.ProportionalWidths;
|
||||
this.cellPadding = (float) (table.Cellpadding * TWIPS_FACTOR);
|
||||
this.cellSpacing = (float) (table.Cellspacing * TWIPS_FACTOR);
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.Border, table.BorderWidth, table.BorderColor);
|
||||
this.alignment = table.Alignment;
|
||||
|
||||
int i = 0;
|
||||
foreach (Row row in table) {
|
||||
this.rows.Add(new RtfRow(this.document, this, row, i));
|
||||
i++;
|
||||
}
|
||||
for (i = 0; i < this.rows.Count; i++) {
|
||||
((RtfRow) this.rows[i]).HandleCellSpanning();
|
||||
((RtfRow) this.rows[i]).CleanRow();
|
||||
}
|
||||
this.headerRows = table.LastHeaderRow;
|
||||
this.cellsFitToPage = table.CellsFitPage;
|
||||
this.tableFitToPage = table.TableFitsPage;
|
||||
if (!float.IsNaN(table.Offset)) {
|
||||
this.offset = (int) (table.Offset * 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfTable
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
if (!inHeader) {
|
||||
if(this.offset != -1) {
|
||||
result.Write(RtfFont.FONT_SIZE, 0, RtfFont.FONT_SIZE.Length);
|
||||
byte[] t;
|
||||
result.Write(t = IntToByteArray(this.offset), 0, t.Length);
|
||||
}
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.rows.Count; i++) {
|
||||
RtfElement re = (RtfElement)this.rows[i];
|
||||
re.WriteContent(result);
|
||||
}
|
||||
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alignment of this RtfTable
|
||||
*
|
||||
* @return The alignment of this RtfTable.
|
||||
*/
|
||||
protected internal int GetAlignment() {
|
||||
return alignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the borders of this RtfTable
|
||||
*
|
||||
* @return The borders of this RtfTable.
|
||||
*/
|
||||
protected internal RtfBorderGroup GetBorders() {
|
||||
return this.borders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell padding of this RtfTable
|
||||
*
|
||||
* @return The cell padding of this RtfTable.
|
||||
*/
|
||||
protected internal float GetCellPadding() {
|
||||
return cellPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell spacing of this RtfTable
|
||||
*
|
||||
* @return The cell spacing of this RtfTable.
|
||||
*/
|
||||
protected internal float GetCellSpacing() {
|
||||
return cellSpacing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the proportional cell widths of this RtfTable
|
||||
*
|
||||
* @return The proportional widths of this RtfTable.
|
||||
*/
|
||||
protected internal float[] GetProportionalWidths() {
|
||||
return (float[]) proportionalWidths.Clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the percentage of the page width this RtfTable covers
|
||||
*
|
||||
* @return The percentage of the page width.
|
||||
*/
|
||||
protected internal float GetTableWidthPercent() {
|
||||
return tableWidthPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rows of this RtfTable
|
||||
*
|
||||
* @return The rows of this RtfTable
|
||||
*/
|
||||
protected internal ArrayList GetRows() {
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cellsFitToPage setting of this RtfTable.
|
||||
*
|
||||
* @return The cellsFitToPage setting of this RtfTable.
|
||||
*/
|
||||
protected internal bool GetCellsFitToPage() {
|
||||
return this.cellsFitToPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tableFitToPage setting of this RtfTable.
|
||||
*
|
||||
* @return The tableFitToPage setting of this RtfTable.
|
||||
*/
|
||||
protected internal bool GetTableFitToPage() {
|
||||
return this.tableFitToPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of header rows of this RtfTable
|
||||
*
|
||||
* @return The number of header rows
|
||||
*/
|
||||
protected internal int GetHeaderRows() {
|
||||
return this.headerRows;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user