Initial Commit

This commit is contained in:
2023-06-21 12:46:23 -04:00
commit c70248a520
1352 changed files with 336780 additions and 0 deletions

View File

@@ -0,0 +1,384 @@
using System;
using System.IO;
using System.Net;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.document.output;
using iTextSharp.text.rtf.text;
using iTextSharp.text.rtf.style;
using iTextSharp.text.pdf.codec.wmf;
/*
* $Id: RtfImage.cs,v 1.11 2008/05/16 19:30:59 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.graphic {
/**
* The RtfImage contains one image. Supported image types are jpeg, png, wmf, bmp.
*
* @version $Version:$
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
* @author Paulo Soares
*/
public class RtfImage : RtfElement {
/**
* Constant for the shape/picture group
*/
private static byte[] PICTURE_GROUP = DocWriter.GetISOBytes("\\*\\shppict");
/**
* Constant for a picture
*/
private static byte[] PICTURE = DocWriter.GetISOBytes("\\pict");
/**
* Constant for a jpeg image
*/
private static byte[] PICTURE_JPEG = DocWriter.GetISOBytes("\\jpegblip");
/**
* Constant for a png image
*/
private static byte[] PICTURE_PNG = DocWriter.GetISOBytes("\\pngblip");
/**
* Constant for a wmf image
*/
private static byte[] PICTURE_WMF = DocWriter.GetISOBytes("\\wmetafile8");
/**
* Constant for the picture width
*/
private static byte[] PICTURE_WIDTH = DocWriter.GetISOBytes("\\picw");
/**
* Constant for the picture height
*/
private static byte[] PICTURE_HEIGHT = DocWriter.GetISOBytes("\\pich");
/**
* Constant for the picture width scale
*/
private static byte[] PICTURE_SCALED_WIDTH = DocWriter.GetISOBytes("\\picwgoal");
/**
* Constant for the picture height scale
*/
private static byte[] PICTURE_SCALED_HEIGHT = DocWriter.GetISOBytes("\\pichgoal");
/**
* Constant for horizontal picture scaling
*/
private static byte[] PICTURE_SCALE_X = DocWriter.GetISOBytes("\\picscalex");
/**
* Constant for vertical picture scaling
*/
private static byte[] PICTURE_SCALE_Y = DocWriter.GetISOBytes("\\picscaley");
/**
* "\bin" constant
*/
private static byte[] PICTURE_BINARY_DATA = DocWriter.GetISOBytes("\\bin");
/**
* Constant for converting pixels to twips
*/
private const int PIXEL_TWIPS_FACTOR = 15;
/**
* The type of image this is.
*/
private int imageType;
/**
* Binary image data.
*/
private byte[][] imageData;
/**
* The alignment of this picture
*/
private int alignment = Element.ALIGN_LEFT;
/**
* The width of this picture
*/
private float width = 0;
/**
* The height of this picutre
*/
private float height = 0;
/**
* The intended display width of this picture
*/
private float plainWidth = 0;
/**
* The intended display height of this picture
*/
private float plainHeight = 0;
/**
* Whether this RtfImage is a top level element and should
* be an extra paragraph.
*/
private bool topLevelElement = false;
/**
* Constructs a RtfImage for an Image.
*
* @param doc The RtfDocument this RtfImage belongs to
* @param image The Image that this RtfImage wraps
* @throws DocumentException If an error occured accessing the image content
*/
public RtfImage(RtfDocument doc, Image image) : base(doc) {
imageType = image.OriginalType;
if (!(imageType == Image.ORIGINAL_JPEG || imageType == Image.ORIGINAL_BMP
|| imageType == Image.ORIGINAL_PNG || imageType == Image.ORIGINAL_WMF || imageType == Image.ORIGINAL_GIF)) {
throw new DocumentException("Only BMP, PNG, WMF, GIF and JPEG images are supported by the RTF Writer");
}
alignment = image.Alignment;
width = image.Width;
height = image.Height;
plainWidth = image.PlainWidth;
plainHeight = image.PlainHeight;
this.imageData = GetImageData(image);
}
/**
* Extracts the image data from the Image.
*
* @param image The image for which to extract the content
* @return The raw image data, not formated
* @throws DocumentException If an error occurs accessing the image content
*/
private byte[][] GetImageData(Image image) {
int WMF_PLACEABLE_HEADER_SIZE = 22;
RtfByteArrayBuffer bab = new RtfByteArrayBuffer();
try {
if (imageType == Image.ORIGINAL_BMP) {
bab.Append(MetaDo.WrapBMP(image));
} else {
byte[] iod = image.OriginalData;
if (iod == null) {
Stream imageIn = WebRequest.Create(image.Url).GetResponse().GetResponseStream();
if (imageType == Image.ORIGINAL_WMF) { //remove the placeable header first
for (int k = 0; k < WMF_PLACEABLE_HEADER_SIZE; k++) {
if (imageIn.ReadByte() < 0) throw (new IOException("while removing wmf placeable header"));
}
}
bab.Write(imageIn);
imageIn.Close();
} else {
if (imageType == Image.ORIGINAL_WMF) {
//remove the placeable header
bab.Write(iod, WMF_PLACEABLE_HEADER_SIZE, iod.Length - WMF_PLACEABLE_HEADER_SIZE);
} else {
bab.Append(iod);
}
}
}
return bab.ToArrayArray();
} catch (IOException ioe) {
throw new DocumentException(ioe.Message);
}
}
/**
* lookup table used for converting bytes to hex chars.
* TODO Should probably be refactored into a helper class
*/
public static byte[] byte2charLUT = new byte[512]; //'0001020304050607 ... fafbfcfdfeff'
static RtfImage() {
char c = '0';
for (int k = 0; k < 16; k++) {
for (int x = 0; x < 16; x++) {
byte2charLUT[((k*16)+x)*2] = byte2charLUT[(((x*16)+k)*2)+1] = (byte)c;
}
if (++c == ':') c = 'a';
}
}
/**
* Writes the image data to the given buffer as hex encoded text.
*
* @param binary
* @param bab
* @
*/
private void WriteImageDataHexEncoded(Stream bab) {
int cnt = 0;
for (int k = 0; k < imageData.Length; k++) {
byte[] chunk = imageData[k];
for (int x = 0; x < chunk.Length; x++) {
bab.Write(byte2charLUT, (chunk[x]&0xff)*2, 2);
if (++cnt == 64) {
bab.WriteByte((byte)'\n');
cnt = 0;
}
}
}
if (cnt > 0) bab.WriteByte((byte)'\n');
}
/**
* Returns the image raw data size in bytes.
*
* @return
*/
private int ImageDataSize() {
int size = 0;
for (int k = 0; k < imageData.Length; k++) {
size += imageData[k].Length;
}
return size;
}
/**
* Writes the RtfImage content
*/
public override void WriteContent(Stream result)
{
byte[] t;
if (this.topLevelElement) {
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
switch (alignment) {
case Element.ALIGN_LEFT:
result.Write(RtfParagraphStyle.ALIGN_LEFT, 0, RtfParagraphStyle.ALIGN_LEFT.Length);
break;
case Element.ALIGN_RIGHT:
result.Write(RtfParagraphStyle.ALIGN_RIGHT, 0, RtfParagraphStyle.ALIGN_RIGHT.Length);
break;
case Element.ALIGN_CENTER:
result.Write(RtfParagraphStyle.ALIGN_CENTER, 0, RtfParagraphStyle.ALIGN_CENTER.Length);
break;
case Element.ALIGN_JUSTIFIED:
result.Write(RtfParagraphStyle.ALIGN_JUSTIFY, 0, RtfParagraphStyle.ALIGN_JUSTIFY.Length);
break;
}
}
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
result.Write(PICTURE_GROUP, 0, PICTURE_GROUP.Length);
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
result.Write(PICTURE, 0, PICTURE.Length);
switch (imageType) {
case Image.ORIGINAL_JPEG:
result.Write(PICTURE_JPEG, 0, PICTURE_JPEG.Length);
break;
case Image.ORIGINAL_PNG:
case Image.ORIGINAL_GIF:
result.Write(PICTURE_PNG, 0, PICTURE_PNG.Length);
break;
case Image.ORIGINAL_WMF:
case Image.ORIGINAL_BMP:
result.Write(PICTURE_WMF, 0, PICTURE_WMF.Length);
break;
}
result.Write(PICTURE_WIDTH, 0, PICTURE_WIDTH.Length);
result.Write(t = IntToByteArray((int) width), 0, t.Length);
result.Write(PICTURE_HEIGHT, 0, PICTURE_HEIGHT.Length);
result.Write(t = IntToByteArray((int) height), 0, t.Length);
if (this.document.GetDocumentSettings().IsWriteImageScalingInformation()) {
result.Write(PICTURE_SCALE_X, 0, PICTURE_SCALE_X.Length);
result.Write(t = IntToByteArray((int)(100 * plainWidth / width)), 0, t.Length);
result.Write(PICTURE_SCALE_Y, 0, PICTURE_SCALE_Y.Length);
result.Write(t = IntToByteArray((int)(100 * plainHeight / height)), 0, t.Length);
}
if (this.document.GetDocumentSettings().IsImagePDFConformance()) {
result.Write(PICTURE_SCALED_WIDTH, 0, PICTURE_SCALED_WIDTH.Length);
result.Write(t = IntToByteArray((int) (plainWidth * RtfElement.TWIPS_FACTOR)), 0, t.Length);
result.Write(PICTURE_SCALED_HEIGHT, 0, PICTURE_SCALED_HEIGHT.Length);
result.Write(t = IntToByteArray((int) (plainHeight * RtfElement.TWIPS_FACTOR)), 0, t.Length);
} else {
if (this.width != this.plainWidth || this.imageType == Image.ORIGINAL_BMP) {
result.Write(PICTURE_SCALED_WIDTH, 0, PICTURE_SCALED_WIDTH.Length);
result.Write(t = IntToByteArray((int) (plainWidth * PIXEL_TWIPS_FACTOR)), 0, t.Length);
}
if (this.height != this.plainHeight || this.imageType == Image.ORIGINAL_BMP) {
result.Write(PICTURE_SCALED_HEIGHT, 0, PICTURE_SCALED_HEIGHT.Length);
result.Write(t = IntToByteArray((int) (plainHeight * PIXEL_TWIPS_FACTOR)), 0, t.Length);
}
}
if (this.document.GetDocumentSettings().IsImageWrittenAsBinary()) {
//binary
result.WriteByte((byte)'\n');
result.Write(PICTURE_BINARY_DATA, 0, PICTURE_BINARY_DATA.Length);
result.Write(t = IntToByteArray(ImageDataSize()), 0, t.Length);
result.Write(DELIMITER, 0, DELIMITER.Length);
if (result is RtfByteArrayBuffer) {
((RtfByteArrayBuffer)result).Append(imageData);
} else {
for (int k = 0; k < imageData.Length; k++) {
result.Write(imageData[k], 0, imageData[k].Length);
}
}
} else {
//hex encoded
result.Write(DELIMITER, 0, DELIMITER.Length);
result.WriteByte((byte)'\n');
WriteImageDataHexEncoded(result);
}
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
if (this.topLevelElement) {
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
}
result.WriteByte((byte)'\n');
}
/**
* Sets the alignment of this RtfImage. Uses the alignments from com.lowagie.text.Element.
*
* @param alignment The alignment to use.
*/
public void SetAlignment(int alignment) {
this.alignment = alignment;
}
/**
* Set whether this RtfImage should behave like a top level element
* and enclose itself in a paragraph.
*
* @param topLevelElement Whether to behave like a top level element.
*/
public void SetTopLevelElement(bool topLevelElement) {
this.topLevelElement = topLevelElement;
}
}
}

View File

@@ -0,0 +1,379 @@
using System;
using System.IO;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf;
/**
* $Id: RtfShape.cs,v 1.7 2008/05/23 17:24:27 psoares33 Exp $
*
*
* Copyright 2006 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-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 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.graphic {
/**
* The RtfShape provides the interface for adding shapes to
* the RTF document. This will only work for Word 97+, older
* Word versions are not supported by this class.<br /><br />
*
* Only very simple shapes are directly supported by the RtfShape.
* For more complex shapes you will have to read the RTF
* specification (iText follows the 1.6 specification) and add
* the desired properties via the RtfShapeProperty.<br /><br />
*
* One thing to keep in mind is that distances are not expressed
* in the standard iText point, but in EMU where 1 inch = 914400 EMU
* or 1 cm = 360000 EMU.
*
* @version $Revision: 1.7 $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfShape : RtfAddableElement {
/**
* Constant for a free form shape. The shape verticies must
* be specified with an array of Point objects in a
* RtfShapeProperty with the name PROPERTY_VERTICIES.
*/
public const int SHAPE_FREEFORM = 0;
/**
* Constant for a rectangle.
*/
public const int SHAPE_RECTANGLE = 1;
/**
* Constant for a rounded rectangle. The roundness is
* set via a RtfShapeProperty with the name PROPERTY_ADJUST_VALUE.
*/
public const int SHAPE_ROUND_RECTANGLE = 2;
/**
* Constant for an ellipse. Use this to create circles.
*/
public const int SHAPE_ELLIPSE = 3;
/**
* Constant for a diamond.
*/
public const int SHAPE_DIAMOND = 4;
/**
* Constant for a isoscelle triangle.
*/
public const int SHAPE_TRIANGLE_ISOSCELES = 5;
/**
* Constant for a right triangle.
*/
public const int SHAPE_TRIANGLE_RIGHT = 6;
/**
* Constant for a parallelogram.
*/
public const int SHAPE_PARALLELOGRAM = 7;
/**
* Constant for a trapezoid.
*/
public const int SHAPE_TRAPEZOID = 8;
/**
* Constant for a hexagon.
*/
public const int SHAPE_HEXAGON = 9;
/**
* Constant for an ocatagon.
*/
public const int SHAPE_OCTAGON = 10;
/**
* Constant for a star.
*/
public const int SHAPE_STAR = 12;
/**
* Constant for an arrow.
*/
public const int SHAPE_ARROW = 13;
/**
* Constant for a thick arrow.
*/
public const int SHAPE_ARROR_THICK = 14;
/**
* Constant for a home plate style shape.
*/
public const int SHAPE_HOME_PLATE = 15;
/**
* Constant for a cube shape.
*/
public const int SHAPE_CUBE = 16;
/**
* Constant for a balloon shape.
*/
public const int SHAPE_BALLOON = 17;
/**
* Constant for a seal shape.
*/
public const int SHAPE_SEAL = 18;
/**
* Constant for an arc shape.
*/
public const int SHAPE_ARC = 19;
/**
* Constant for a line shape.
*/
public const int SHAPE_LINE = 20;
/**
* Constant for a can shape.
*/
public const int SHAPE_CAN = 22;
/**
* Constant for a donut shape.
*/
public const int SHAPE_DONUT = 23;
/**
* Constant for a Picture Frame.
*/
public const int SHAPE_PICTURE_FRAME = 75;
/**
* Text is not wrapped around the shape.
*/
public const int SHAPE_WRAP_NONE = 0;
/**
* Text is wrapped to the top and bottom.
*/
public const int SHAPE_WRAP_TOP_BOTTOM = 1;
/**
* Text is wrapped on the left and right side.
*/
public const int SHAPE_WRAP_BOTH = 2;
/**
* Text is wrapped on the left side.
*/
public const int SHAPE_WRAP_LEFT = 3;
/**
* Text is wrapped on the right side.
*/
public const int SHAPE_WRAP_RIGHT = 4;
/**
* Text is wrapped on the largest side.
*/
public const int SHAPE_WRAP_LARGEST = 5;
/**
* Text is tightly wrapped on the left and right side.
*/
public const int SHAPE_WRAP_TIGHT_BOTH = 6;
/**
* Text is tightly wrapped on the left side.
*/
public const int SHAPE_WRAP_TIGHT_LEFT = 7;
/**
* Text is tightly wrapped on the right side.
*/
public const int SHAPE_WRAP_TIGHT_RIGHT = 8;
/**
* Text is tightly wrapped on the largest side.
*/
public const int SHAPE_WRAP_TIGHT_LARGEST = 9;
/**
* Text is wrapped through the shape.
*/
public const int SHAPE_WRAP_THROUGH = 10;
/**
* The shape nr is a random unique id.
*/
private int shapeNr = 0;
/**
* The shape type.
*/
private int type = 0;
/**
* The RtfShapePosition that defines position settings for this RtfShape.
*/
private RtfShapePosition position = null;
/**
* A Hashtable with RtfShapePropertys that define further shape properties.
*/
private Hashtable properties = null;
/**
* The wrapping mode. Defaults to SHAPE_WRAP_NONE;
*/
private int wrapping = SHAPE_WRAP_NONE;
/**
* Text that is contained in the shape.
*/
private String shapeText = "";
/**
* Constructs a new RtfShape of a given shape at the given RtfShapePosition.
*
* @param type The type of shape to create.
* @param position The RtfShapePosition to create this RtfShape at.
*/
public RtfShape(int type, RtfShapePosition position) {
this.type = type;
this.position = position;
this.properties = new Hashtable();
}
/**
* Sets a property.
*
* @param property The property to set for this RtfShape.
*/
public void SetProperty(RtfShapeProperty property) {
this.properties[property.GetName()] = property;
}
/**
* Sets the text to display in this RtfShape.
*
* @param shapeText The text to display.
*/
public void SetShapeText(String shapeText) {
this.shapeText = shapeText;
}
/**
* Set the wrapping mode.
*
* @param wrapping The wrapping mode to use for this RtfShape.
*/
public void SetWrapping(int wrapping) {
this.wrapping = wrapping;
}
/**
* Writes the RtfShape. Some settings are automatically translated into
* or require other properties and these are set first.
*/
public override void WriteContent(Stream result) {
this.shapeNr = this.doc.GetRandomInt();
this.properties["ShapeType"] = new RtfShapeProperty("ShapeType", this.type);
if (this.position.IsShapeBelowText()) {
this.properties["fBehindDocument"] = new RtfShapeProperty("fBehindDocument", true);
}
if (this.inTable) {
this.properties["fLayoutInCell"] = new RtfShapeProperty("fLayoutInCell", true);
}
if (this.properties.ContainsKey("posh")) {
this.position.SetIgnoreXRelative(true);
}
if (this.properties.ContainsKey("posv")) {
this.position.SetIgnoreYRelative(true);
}
byte[] t;
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
result.Write(t = DocWriter.GetISOBytes("\\shp"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shplid"), 0, t.Length);
result.Write(t = IntToByteArray(this.shapeNr), 0, t.Length);
this.position.WriteContent(result);
switch (this.wrapping) {
case SHAPE_WRAP_NONE:
result.Write(t = DocWriter.GetISOBytes("\\shpwr3"), 0, t.Length);
break;
case SHAPE_WRAP_TOP_BOTTOM:
result.Write(t = DocWriter.GetISOBytes("\\shpwr1"), 0, t.Length);
break;
case SHAPE_WRAP_BOTH:
result.Write(t = DocWriter.GetISOBytes("\\shpwr2"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk0"), 0, t.Length);
break;
case SHAPE_WRAP_LEFT:
result.Write(t = DocWriter.GetISOBytes("\\shpwr2"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk1"), 0, t.Length);
break;
case SHAPE_WRAP_RIGHT:
result.Write(t = DocWriter.GetISOBytes("\\shpwr2"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk2"), 0, t.Length);
break;
case SHAPE_WRAP_LARGEST:
result.Write(t = DocWriter.GetISOBytes("\\shpwr2"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk3"), 0, t.Length);
break;
case SHAPE_WRAP_TIGHT_BOTH:
result.Write(t = DocWriter.GetISOBytes("\\shpwr4"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk0"), 0, t.Length);
break;
case SHAPE_WRAP_TIGHT_LEFT:
result.Write(t = DocWriter.GetISOBytes("\\shpwr4"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk1"), 0, t.Length);
break;
case SHAPE_WRAP_TIGHT_RIGHT:
result.Write(t = DocWriter.GetISOBytes("\\shpwr4"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk2"), 0, t.Length);
break;
case SHAPE_WRAP_TIGHT_LARGEST:
result.Write(t = DocWriter.GetISOBytes("\\shpwr4"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpwrk3"), 0, t.Length);
break;
case SHAPE_WRAP_THROUGH:
result.Write(t = DocWriter.GetISOBytes("\\shpwr5"), 0, t.Length);
break;
default:
result.Write(t = DocWriter.GetISOBytes("\\shpwr3"), 0, t.Length);
break;
}
if (this.inHeader) {
result.Write(t = DocWriter.GetISOBytes("\\shpfhdr1"), 0, t.Length);
}
if (this.doc.GetDocumentSettings().IsOutputDebugLineBreaks()) {
result.WriteByte((byte)'\n');
}
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
result.Write(t = DocWriter.GetISOBytes("\\*\\shpinst"), 0, t.Length);
foreach (RtfShapeProperty rsp in this.properties.Values) {
rsp.WriteContent(result);
}
if (!this.shapeText.Equals("")) {
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
result.Write(t = DocWriter.GetISOBytes("\\shptxt"), 0, t.Length);
result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
result.Write(t = DocWriter.GetISOBytes(this.shapeText), 0, t.Length);
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
}
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
if (this.doc.GetDocumentSettings().IsOutputDebugLineBreaks()) {
result.WriteByte((byte)'\n');
}
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
}
}
}

View File

@@ -0,0 +1,249 @@
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.rtf;
/**
* $Id: RtfShapePosition.cs,v 1.6 2008/05/23 17:24:27 psoares33 Exp $
*
*
* Copyright 2006 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-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 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.graphic {
/**
* The RtfShapePosition stores position and ordering
* information for one RtfShape.
*
* @version $Revision: 1.6 $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfShapePosition : RtfAddableElement {
/**
* Constant for horizontal positioning relative to the page.
*/
public const int POSITION_X_RELATIVE_PAGE = 0;
/**
* Constant for horizontal positioning relative to the margin.
*/
public const int POSITION_X_RELATIVE_MARGIN = 1;
/**
* Constant for horizontal positioning relative to the column.
*/
public const int POSITION_X_RELATIVE_COLUMN = 2;
/**
* Constant for vertical positioning relative to the page.
*/
public const int POSITION_Y_RELATIVE_PAGE = 0;
/**
* Constant for vertical positioning relative to the margin.
*/
public const int POSITION_Y_RELATIVE_MARGIN = 1;
/**
* Constant for vertical positioning relative to the paragraph.
*/
public const int POSITION_Y_RELATIVE_PARAGRAPH = 2;
/**
* The top coordinate of this RtfShapePosition.
*/
private int top = 0;
/**
* The left coordinate of this RtfShapePosition.
*/
private int left = 0;
/**
* The right coordinate of this RtfShapePosition.
*/
private int right = 0;
/**
* The bottom coordinate of this RtfShapePosition.
*/
private int bottom = 0;
/**
* The z order of this RtfShapePosition.
*/
private int zOrder = 0;
/**
* The horizontal relative position.
*/
private int xRelativePos = POSITION_X_RELATIVE_PAGE;
/**
* The vertical relative position.
*/
private int yRelativePos = POSITION_Y_RELATIVE_PAGE;
/**
* Whether to ignore the horizontal relative position.
*/
private bool ignoreXRelative = false;
/**
* Whether to ignore the vertical relative position.
*/
private bool ignoreYRelative = false;
/**
* Whether the shape is below the text.
*/
private bool shapeBelowText = false;
/**
* Constructs a new RtfShapePosition with the four bounding coordinates.
*
* @param top The top coordinate.
* @param left The left coordinate.
* @param right The right coordinate.
* @param bottom The bottom coordinate.
*/
public RtfShapePosition(int top, int left, int right, int bottom) {
this.top = top;
this.left = left;
this.right = right;
this.bottom = bottom;
}
/**
* Gets whether the shape is below the text.
*
* @return <code>True</code> if the shape is below, <code>false</code> if the text is below.
*/
public bool IsShapeBelowText() {
return shapeBelowText;
}
/**
* Sets whether the shape is below the text.
*
* @param shapeBelowText <code>True</code> if the shape is below, <code>false</code> if the text is below.
*/
public void SetShapeBelowText(bool shapeBelowText) {
this.shapeBelowText = shapeBelowText;
}
/**
* Sets the relative horizontal position. Use one of the constants
* provided in this class.
*
* @param relativePos The relative horizontal position to use.
*/
public void SetXRelativePos(int relativePos) {
xRelativePos = relativePos;
}
/**
* Sets the relative vertical position. Use one of the constants
* provides in this class.
*
* @param relativePos The relative vertical position to use.
*/
public void SetYRelativePos(int relativePos) {
yRelativePos = relativePos;
}
/**
* Sets the z order to use.
*
* @param order The z order to use.
*/
public void SetZOrder(int order) {
zOrder = order;
}
/**
* Set whether to ignore the horizontal relative position.
*
* @param ignoreXRelative <code>True</code> to ignore the horizontal relative position, <code>false</code> otherwise.
*/
protected internal void SetIgnoreXRelative(bool ignoreXRelative) {
this.ignoreXRelative = ignoreXRelative;
}
/**
* Set whether to ignore the vertical relative position.
*
* @param ignoreYRelative <code>True</code> to ignore the vertical relative position, <code>false</code> otherwise.
*/
protected internal void SetIgnoreYRelative(bool ignoreYRelative) {
this.ignoreYRelative = ignoreYRelative;
}
/**
* Write this RtfShapePosition.
*/
public override void WriteContent(Stream result) {
byte[] t;
result.Write(t = DocWriter.GetISOBytes("\\shpleft"), 0, t.Length);
result.Write(t = IntToByteArray(this.left), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shptop"), 0, t.Length);
result.Write(t = IntToByteArray(this.top), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpright"), 0, t.Length);
result.Write(t = IntToByteArray(this.right), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpbottom"), 0, t.Length);
result.Write(t = IntToByteArray(this.bottom), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\shpz"), 0, t.Length);
result.Write(t = IntToByteArray(this.zOrder), 0, t.Length);
switch(this.xRelativePos) {
case POSITION_X_RELATIVE_PAGE: result.Write(t = DocWriter.GetISOBytes("\\shpbxpage"), 0, t.Length); break;
case POSITION_X_RELATIVE_MARGIN: result.Write(t = DocWriter.GetISOBytes("\\shpbxmargin"), 0, t.Length); break;
case POSITION_X_RELATIVE_COLUMN: result.Write(t = DocWriter.GetISOBytes("\\shpbxcolumn"), 0, t.Length); break;
}
if(this.ignoreXRelative) {
result.Write(t = DocWriter.GetISOBytes("\\shpbxignore"), 0, t.Length);
}
switch(this.yRelativePos) {
case POSITION_Y_RELATIVE_PAGE: result.Write(t = DocWriter.GetISOBytes("\\shpbypage"), 0, t.Length); break;
case POSITION_Y_RELATIVE_MARGIN: result.Write(t = DocWriter.GetISOBytes("\\shpbymargin"), 0, t.Length); break;
case POSITION_Y_RELATIVE_PARAGRAPH: result.Write(t = DocWriter.GetISOBytes("\\shpbypara"), 0, t.Length); break;
}
if(this.ignoreYRelative) {
result.Write(t = DocWriter.GetISOBytes("\\shpbyignore"), 0, t.Length);
}
if(this.shapeBelowText) {
result.Write(t = DocWriter.GetISOBytes("\\shpfblwtxt1"), 0, t.Length);
} else {
result.Write(t = DocWriter.GetISOBytes("\\shpfblwtxt0"), 0, t.Length);
}
}
}
}

View File

@@ -0,0 +1,356 @@
using System;
using System.IO;
using System.Drawing;
using iTextSharp.text;
using iTextSharp.text.rtf;
/**
* $Id: RtfShapeProperty.cs,v 1.8 2008/05/23 17:24:27 psoares33 Exp $
*
*
* Copyright 2006 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-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 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.graphic {
/**
* The RtfShapeProperty stores all shape properties that are
* not handled by the RtfShape and RtfShapePosition.<br /><br />
*
* There is a huge selection of properties that can be set. For
* the most important properites there are constants for the
* property name, for all others you must find the correct
* property name in the RTF specification (version 1.6).<br /><br />
*
* The following types of property values are supported:
* <ul>
* <li>long</li>
* <li>double</li>
* <li>bool</li>
* <li>Color</li>
* <li>int[]</li>
* <li>Point[]</li>
* </ul>
*
* @version $Revision: 1.8 $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfShapeProperty : RtfAddableElement {
/**
* Property for defining an image.
*/
public const String PROPERTY_IMAGE = "pib";
/**
* Property for defining vertices in freeform shapes. Requires a
* Point array as the value.
*/
public const String PROPERTY_VERTICIES = "pVerticies";
/**
* Property for defining the minimum vertical coordinate that is
* visible. Requires a long value.
*/
public const String PROPERTY_GEO_TOP = "geoTop";
/**
* Property for defining the minimum horizontal coordinate that is
* visible. Requires a long value.
*/
public const String PROPERTY_GEO_LEFT = "geoLeft";
/**
* Property for defining the maximum horizontal coordinate that is
* visible. Requires a long value.
*/
public const String PROPERTY_GEO_RIGHT = "geoRight";
/**
* Property for defining the maximum vertical coordinate that is
* visible. Requires a long value.
*/
public const String PROPERTY_GEO_BOTTOM = "geoBottom";
/**
* Property for defining that the shape is in a table cell. Requires
* a bool value.
*/
public const String PROPERTY_LAYOUT_IN_CELL = "fLayoutInCell";
/**
* Property for signalling a vertical flip of the shape. Requires a
* bool value.
*/
public const String PROPERTY_FLIP_V = "fFlipV";
/**
* Property for signalling a horizontal flip of the shape. Requires a
* bool value.
*/
public const String PROPERTY_FLIP_H = "fFlipH";
/**
* Property for defining the fill color of the shape. Requires a
* Color value.
*/
public const String PROPERTY_FILL_COLOR = "fillColor";
/**
* Property for defining the line color of the shape. Requires a
* Color value.
*/
public const String PROPERTY_LINE_COLOR = "lineColor";
/**
* Property for defining the first adjust handle for shapes. Used
* with the rounded rectangle. Requires a long value.
*/
public const String PROPERTY_ADJUST_VALUE = "adjustValue";
/**
* The stored value is a long.
*/
private const int PROPERTY_TYPE_LONG = 1;
/**
* The stored value is bool.
*/
private const int PROPERTY_TYPE_BOOLEAN = 2;
/**
* The stored value is a double.
*/
private const int PROPERTY_TYPE_DOUBLE = 3;
/**
* The stored value is a Color.
*/
private const int PROPERTY_TYPE_COLOR = 4;
/**
* The stored value is either an int or a Point array.
*/
private const int PROPERTY_TYPE_ARRAY = 5;
/**
* The stored value is an Image.
*/
private const int PROPERTY_TYPE_IMAGE = 6;
/**
* The value type.
*/
private int type = 0;
/**
* The RtfShapeProperty name.
*/
private String name = "";
/**
* The RtfShapeProperty value.
*/
private Object value = null;
/**
* Internaly used to create the RtfShape.
*
* @param name The property name to use.
* @param value The property value to use.
*/
private RtfShapeProperty(String name, Object value) {
this.name = name;
this.value = value;
}
/**
* Constructs a RtfShapeProperty with a long value.
*
* @param name The property name to use.
* @param value The long value to use.
*/
public RtfShapeProperty(String name, long value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_LONG;
}
/**
* Constructs a RtfShapeProperty with a double value.
*
* @param name The property name to use.
* @param value The double value to use.
*/
public RtfShapeProperty(String name, double value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_DOUBLE;
}
/**
* Constructs a RtfShapeProperty with a bool value.
*
* @param name The property name to use.
* @param value The bool value to use.
*/
public RtfShapeProperty(String name, bool value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_BOOLEAN;
}
/**
* Constructs a RtfShapeProperty with a Color value.
*
* @param name The property name to use.
* @param value The Color value to use.
*/
public RtfShapeProperty(String name, Color value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_COLOR;
}
/**
* Constructs a RtfShapeProperty with an int array value.
*
* @param name The property name to use.
* @param value The int array to use.
*/
public RtfShapeProperty(String name, int[] value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_ARRAY;
}
/**
* Constructs a RtfShapeProperty with a Point array value.
*
* @param name The property name to use.
* @param value The Point array to use.
*/
public RtfShapeProperty(String name, Point[] value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_ARRAY;
}
/**
* Constructs a RtfShapeProperty with an Image value.
*
* @param name The property name to use.
* @param value The Image to use.
*/
public RtfShapeProperty(String name, Image value) {
this.name = name;
this.value = value;
this.type = PROPERTY_TYPE_IMAGE;
}
/**
* Gets the name of this RtfShapeProperty.
*
* @return The name of this RtfShapeProperty.
*/
public String GetName() {
return this.name;
}
/**
* Write this RtfShapePosition.
*/
public override void WriteContent(Stream result) {
byte[] t;
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
result.Write(t = DocWriter.GetISOBytes("\\sp"), 0, t.Length);
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
result.Write(t = DocWriter.GetISOBytes("\\sn"), 0, t.Length);
result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
result.Write(t = DocWriter.GetISOBytes(this.name), 0, t.Length);
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
result.Write(t = DocWriter.GetISOBytes("\\sv"), 0, t.Length);
result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
switch (this.type) {
case PROPERTY_TYPE_LONG:
case PROPERTY_TYPE_DOUBLE:
result.Write(t = DocWriter.GetISOBytes(this.value.ToString()), 0, t.Length);
break;
case PROPERTY_TYPE_BOOLEAN:
if ((bool)this.value) {
result.Write(t = DocWriter.GetISOBytes("1"), 0, t.Length);
} else {
result.Write(t = DocWriter.GetISOBytes("0"), 0, t.Length);
}
break;
case PROPERTY_TYPE_COLOR:
Color color = (Color) this.value;
result.Write(t = IntToByteArray(color.R | (color.G << 8) | (color.B << 16)), 0, t.Length);
break;
case PROPERTY_TYPE_ARRAY:
if (this.value is int[]) {
int[] values = (int[]) this.value;
result.Write(t = DocWriter.GetISOBytes("4;"), 0, t.Length);
result.Write(t = IntToByteArray(values.Length), 0, t.Length);
result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
for (int i = 0; i < values.Length; i++) {
result.Write(t = IntToByteArray(values[i]), 0, t.Length);
if (i < values.Length - 1) {
result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
}
}
} else if (this.value is Point[]) {
Point[] values = (Point[]) this.value;
result.Write(t = DocWriter.GetISOBytes("8;"), 0, t.Length);
result.Write(t = IntToByteArray(values.Length), 0, t.Length);
result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
for (int i = 0; i < values.Length; i++) {
result.Write(t = DocWriter.GetISOBytes("("), 0, t.Length);
result.Write(t = IntToByteArray(values[i].X), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes(","), 0, t.Length);
result.Write(t = IntToByteArray(values[i].Y), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes(")"), 0, t.Length);
if (i < values.Length - 1) {
result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
}
}
}
break;
case PROPERTY_TYPE_IMAGE:
Image image = (Image)this.value;
RtfImage img = new RtfImage(this.doc, image);
img.SetTopLevelElement(true);
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
img.WriteContent(result);
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
break;
}
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
}
}
}