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,285 @@
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
/*
* $Id: RtfColor.cs,v 1.6 2008/05/16 19:31:10 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.style {
/**
* The RtfColor stores one rtf color value for a rtf document
*
* @version $Version:$
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfColor : RtfElement, IRtfExtendedElement {
/**
* Constant for RED value
*/
private static byte[] COLOR_RED = DocWriter.GetISOBytes("\\red");
/**
* Constant for GREEN value
*/
private static byte[] COLOR_GREEN = DocWriter.GetISOBytes("\\green");
/**
* Constant for BLUE value
*/
private static byte[] COLOR_BLUE = DocWriter.GetISOBytes("\\blue");
/**
* Constant for the end of one color entry
*/
private const byte COLON = (byte) ';';
/**
* Constant for the number of the colour in the list of colours
*/
private static byte[] COLOR_NUMBER = DocWriter.GetISOBytes("\\cf");
/**
* The number of the colour in the list of colours
*/
private int colorNumber = 0;
/**
* The red value
*/
private int red = 0;
/**
* The green value
*/
private int green = 0;
/**
* The blue value
*/
private int blue = 0;
/**
* Constructor only for use when initializing the RtfColorList
*
* @param doc The RtfDocument this RtfColor belongs to
* @param red The red value to use
* @param green The green value to use
* @param blue The blue value to use
* @param colorNumber The number of the colour in the colour list
*/
protected internal RtfColor(RtfDocument doc, int red, int green, int blue, int colorNumber) : base(doc) {
this.red = red;
this.blue = blue;
this.green = green;
this.colorNumber = colorNumber;
}
/**
* Constructs a RtfColor as a clone of an existing RtfColor
*
* @param doc The RtfDocument this RtfColor belongs to
* @param col The RtfColor to use as a base
*/
public RtfColor(RtfDocument doc, RtfColor col) : base(doc) {
if (col != null) {
this.red = col.GetRed();
this.green = col.GetGreen();
this.blue = col.GetBlue();
}
if (this.document != null) {
this.colorNumber = this.document.GetDocumentHeader().GetColorNumber(this);
}
}
/**
* Constructs a RtfColor based on the Color
*
* @param doc The RtfDocument this RtfColor belongs to
* @param col The Color to base this RtfColor on
*/
public RtfColor(RtfDocument doc, Color col) : base(doc) {
if (col != null) {
this.red = col.R;
this.blue = col.B;
this.green = col.G;
}
if (this.document != null) {
this.colorNumber = this.document.GetDocumentHeader().GetColorNumber(this);
}
}
/**
* Constructs a RtfColor based on the red/green/blue values
*
* @param doc The RtfDocument this RtfColor belongs to
* @param red The red value to use
* @param green The green value to use
* @param blue The blue value to use
*/
public RtfColor(RtfDocument doc, int red, int green, int blue) : base(doc) {
this.red = red;
this.blue = blue;
this.green = green;
if (this.document != null) {
this.colorNumber = this.document.GetDocumentHeader().GetColorNumber(this);
}
}
/**
* unused
*/
public override void WriteContent(Stream outp) {
}
/**
* Write the definition part of this RtfColor.
*/
public virtual void WriteDefinition(Stream result) {
byte[] t;
result.Write(COLOR_RED, 0, COLOR_RED.Length);
result.Write(t = IntToByteArray(red), 0, t.Length);
result.Write(COLOR_GREEN, 0, COLOR_GREEN.Length);
result.Write(t = IntToByteArray(green), 0, t.Length);
result.Write(COLOR_BLUE, 0, COLOR_BLUE.Length);
result.Write(t = IntToByteArray(blue), 0, t.Length);
result.WriteByte(COLON);
}
/**
* Writes the beginning of this RtfColor
*
*/
public void WriteBegin(Stream result) {
byte[] t;
try {
result.Write(COLOR_NUMBER, 0, COLOR_NUMBER.Length);
result.Write(t = IntToByteArray(colorNumber), 0, t.Length);
} catch (IOException) {
}
}
/**
* Unused
*
*/
public void WriteEnd(Stream result) {
}
/**
* Tests if this RtfColor is equal to another RtfColor.
*
* @param obj another RtfColor
* @return <code>True</code> if red, green and blue values of the two colours match,
* <code>false</code> otherwise.
*/
public override bool Equals(Object obj) {
if (!(obj is RtfColor)) {
return false;
}
RtfColor color = (RtfColor) obj;
return (this.red == color.GetRed() && this.green == color.GetGreen() && this.blue == color.GetBlue());
}
/**
* Returns the hash code of this RtfColor. The hash code is
* an integer with the lowest three bytes containing the values
* of red, green and blue.
*
* @return The hash code of this RtfColor
*/
public override int GetHashCode() {
return (this.red << 16) | (this.green << 8) | this.blue;
}
/**
* Get the blue value of this RtfColor
*
* @return The blue value
*/
public int GetBlue() {
return blue;
}
/**
* Get the green value of this RtfColor
*
* @return The green value
*/
public int GetGreen() {
return green;
}
/**
* Get the red value of this RtfColor
*
* @return The red value
*/
public int GetRed() {
return red;
}
/**
* Gets the number of this RtfColor in the list of colours
*
* @return Returns the colorNumber.
*/
public int GetColorNumber() {
return colorNumber;
}
/**
* Sets the RtfDocument this RtfColor belongs to
*
* @param doc The RtfDocument to use
*/
public override void SetRtfDocument(RtfDocument doc) {
base.SetRtfDocument(doc);
if (document != null) {
this.colorNumber = document.GetDocumentHeader().GetColorNumber(this);
}
}
}
}

View File

@@ -0,0 +1,131 @@
using System;
using System.IO;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
/*
* $Id: RtfColorList.cs,v 1.5 2008/05/16 19:31:11 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.style {
/**
* The RtfColorList stores all colours that appear in the document. Black
* and White are always added
*
* @version $Version:$
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfColorList : RtfElement, IRtfExtendedElement {
/**
* Constant for the beginning of the colour table
*/
private static byte[] COLOR_TABLE = DocWriter.GetISOBytes("\\colortbl");
/**
* ArrayList containing all colours of this RtfColorList
*/
ArrayList colorList = new ArrayList();
/**
* Constructs a new RtfColorList for the RtfDocument. Will add the default
* black and white colours.
*
* @param doc The RtfDocument this RtfColorList belongs to
*/
public RtfColorList(RtfDocument doc) : base(doc) {
colorList.Add(new RtfColor(doc, 0, 0, 0, 0));
colorList.Add(new RtfColor(doc, 255, 255, 255, 1));
}
/**
* Returns the index of the given RtfColor in the colour list. If the RtfColor
* is not in the list of colours, then it is added.
*
* @param color The RtfColor for which to get the index
* @return The index of the RtfColor
*/
public int GetColorNumber(RtfColor color) {
int colorIndex = -1;
for (int i = 0; i < colorList.Count; i++) {
if (colorList[i].Equals(color)) {
colorIndex = i;
}
}
if (colorIndex == -1) {
colorIndex = colorList.Count;
colorList.Add(color);
}
return colorIndex;
}
/**
* unused
*/
public override void WriteContent(Stream outp) {
}
/**
* Write the definition part of the colour list. Calls the writeDefinition
* methods of the RtfColors in the colour list.
*/
public virtual void WriteDefinition(Stream result) {
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
result.Write(COLOR_TABLE, 0, COLOR_TABLE.Length);
for (int i = 0; i < colorList.Count; i++) {
RtfColor color = (RtfColor) colorList[i];
color.WriteDefinition(result);
}
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
result.WriteByte((byte)'\n');
}
}
}

View File

@@ -0,0 +1,730 @@
using System;
using System.IO;
using System.util;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
/*
* $Id: RtfFont.cs,v 1.13 2008/05/16 19:31:11 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.style {
/**
* The RtfFont class stores one font for an rtf document. It extends Font,
* so can be set as a font, to allow adding of fonts with arbitrary names.
* BaseFont fontname handling contributed by Craig Fleming. Various fixes
* Renaud Michel, Werner Daehn.
*
* Version: $Id: RtfFont.cs,v 1.13 2008/05/16 19:31:11 psoares33 Exp $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
* @author Craig Fleming (rythos@rhana.dhs.org)
* @author Renaud Michel (r.michel@immedia.be)
* @author Werner Daehn (Werner.Daehn@BusinessObjects.com)
* @author Lidong Liu (tmslld@gmail.com)
*/
public class RtfFont : Font, IRtfExtendedElement {
/**
* Constant for the font family to use ("froman")
*/
private static byte[] FONT_FAMILY = DocWriter.GetISOBytes("\\froman");
/**
* Constant for the charset
*/
private static byte[] FONT_CHARSET = DocWriter.GetISOBytes("\\fcharset");
/**
* Constant for the font size
*/
public static byte[] FONT_SIZE = DocWriter.GetISOBytes("\\fs");
/**
* Constant for the bold flag
*/
private static byte[] FONT_BOLD = DocWriter.GetISOBytes("\\b");
/**
* Constant for the italic flag
*/
private static byte[] FONT_ITALIC = DocWriter.GetISOBytes("\\i");
/**
* Constant for the underline flag
*/
private static byte[] FONT_UNDERLINE = DocWriter.GetISOBytes("\\ul");
/**
* Constant for the strikethrough flag
*/
private static byte[] FONT_STRIKETHROUGH = DocWriter.GetISOBytes("\\strike");
/**
* Constant for the double strikethrough flag
*/
private static byte[] FONT_DOUBLE_STRIKETHROUGH = DocWriter.GetISOBytes("\\striked");
/**
* Constant for the shadow flag
*/
private static byte[] FONT_SHADOW = DocWriter.GetISOBytes("\\shad");
/**
* Constant for the outline flag
*/
private static byte[] FONT_OUTLINE = DocWriter.GetISOBytes("\\outl");
/**
* Constant for the embossed flag
*/
private static byte[] FONT_EMBOSSED = DocWriter.GetISOBytes("\\embo");
/**
* Constant for the engraved flag
*/
private static byte[] FONT_ENGRAVED = DocWriter.GetISOBytes("\\impr");
/**
* Constant for hidden text flag
*/
private static byte[] FONT_HIDDEN = DocWriter.GetISOBytes("\\v");
/**
* Constant for a plain font
*/
public const int STYLE_NONE = 0;
/**
* Constant for a bold font
*/
public const int STYLE_BOLD = 1;
/**
* Constant for an italic font
*/
public const int STYLE_ITALIC = 2;
/**
* Constant for an underlined font
*/
public const int STYLE_UNDERLINE = 4;
/**
* Constant for a strikethrough font
*/
public const int STYLE_STRIKETHROUGH = 8;
/**
* Constant for a double strikethrough font
*/
public const int STYLE_DOUBLE_STRIKETHROUGH = 16;
/**
* Constant for a shadowed font
*/
public const int STYLE_SHADOW = 32;
/**
* Constant for an outlined font
*/
public const int STYLE_OUTLINE = 64;
/**
* Constant for an embossed font
*/
public const int STYLE_EMBOSSED = 128;
/**
* Constant for an engraved font
*/
public const int STYLE_ENGRAVED = 256;
/**
* Constant for a font that hides the actual text.
*/
public const int STYLE_HIDDEN = 512;
/**
* The font name. Defaults to "Times New Roman"
*/
private String fontName = "Times New Roman";
/**
* The font size. Defaults to 10
*/
private int fontSize = 10;
/**
* The font style. Defaults to STYLE_NONE
*/
private int fontStyle = STYLE_NONE;
/**
* The number of this font
*/
private int fontNumber = 0;
/**
* The colour of this font
*/
private RtfColor color = null;
/**
* The character set to use for this font
*/
private int charset = 0;
/**
* The RtfDocument this RtfFont belongs to.
*/
protected RtfDocument document = null;
/**
* Constructs a RtfFont with the given font name and all other properties
* at their default values.
*
* @param fontName The font name to use
*/
public RtfFont(String fontName) : base(Font.UNDEFINED, Font.UNDEFINED, Font.UNDEFINED, null) {
this.fontName = fontName;
}
/**
* Constructs a RtfFont with the given font name and font size and all other
* properties at their default values.
*
* @param fontName The font name to use
* @param size The font size to use
*/
public RtfFont(String fontName, float size) : base(Font.UNDEFINED, size, Font.UNDEFINED, null) {
this.fontName = fontName;
}
/**
* Constructs a RtfFont with the given font name, font size and font style and the
* default color.
*
* @param fontName The font name to use
* @param size The font size to use
* @param style The font style to use
*/
public RtfFont(String fontName, float size, int style) : base(Font.UNDEFINED, size, style, null) {
this.fontName = fontName;
}
/**
* Constructs a RtfFont with the given font name, font size, font style and
* color.
*
* @param fontName The font name to use
* @param size the font size to use
* @param style The font style to use
* @param color The font color to use
*/
public RtfFont(String fontName, float size, int style, Color color) : base(Font.UNDEFINED, size, style, color) {
this.fontName = fontName;
}
/**
* Constructs a RtfFont with the given font name, font size, font style, colour
* and charset. This can be used when generating non latin-1 text.
*
* @param fontName The font name to use
* @param size the font size to use
* @param style The font style to use
* @param color The font color to use
* @param charset The charset of the font content
*/
public RtfFont(String fontName, float size, int style, Color color, int charset) : this(fontName, size, style, color){
this.charset = charset;
}
/**
* Special constructor for the default font
*
* @param doc The RtfDocument this font appears in
* @param fontNumber The id of this font
*/
protected internal RtfFont(RtfDocument doc, int fontNumber) {
this.document = doc;
this.fontNumber = fontNumber;
color = new RtfColor(doc, 0, 0, 0);
}
/**
* Constructs a RtfFont from a com.lowagie.text.Font
* @param doc The RtfDocument this font appears in
* @param font The Font to use as a base
*/
public RtfFont(RtfDocument doc, Font font) {
this.document = doc;
if (font != null) {
if (font is RtfFont) {
this.fontName = ((RtfFont) font).GetFontName();
this.charset = ((RtfFont) font).GetCharset();
} else {
SetToDefaultFamily(font.Familyname);
}
if (font.BaseFont != null) {
String[][] fontNames = font.BaseFont.FullFontName;
for (int i = 0; i < fontNames.Length; i++) {
if (fontNames[i][2].Equals("0")) {
this.fontName = fontNames[i][3];
break;
} else if (fontNames[i][2].Equals("1033") || fontNames[i][2].Equals("")) {
this.fontName = fontNames[i][3];
}
}
}
Size = font.Size;
SetStyle(font.Style);
Color = font.Color;
}
if (Util.EqualsIgnoreCase(this.fontName, "unknown")) {
return;
}
if (document != null) {
SetRtfDocument(document);
}
}
/**
* Writes the font definition
*/
public virtual void WriteDefinition(Stream result) {
byte[] t;
result.Write(FONT_FAMILY, 0, FONT_FAMILY.Length);
result.Write(FONT_CHARSET, 0, FONT_CHARSET.Length);
result.Write(t = IntToByteArray(charset), 0, t.Length);
result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
document.FilterSpecialChar(result, fontName, true, false);
}
/**
* Writes the font beginning
*
* @return A byte array with the font start data
*/
public virtual void WriteBegin(Stream result) {
byte[] t;
if(this.fontNumber != Font.UNDEFINED) {
result.Write(RtfFontList.FONT_NUMBER, 0, RtfFontList.FONT_NUMBER.Length);
result.Write(t = IntToByteArray(fontNumber), 0, t.Length);
}
if(this.fontSize != Font.UNDEFINED) {
result.Write(FONT_SIZE, 0, FONT_SIZE.Length);
result.Write(t = IntToByteArray(fontSize * 2), 0, t.Length);
}
if (this.fontStyle != UNDEFINED) {
if ((fontStyle & STYLE_BOLD) == STYLE_BOLD) {
result.Write(FONT_BOLD, 0, FONT_BOLD.Length);
}
if ((fontStyle & STYLE_ITALIC) == STYLE_ITALIC) {
result.Write(FONT_ITALIC, 0, FONT_ITALIC.Length);
}
if ((fontStyle & STYLE_UNDERLINE) == STYLE_UNDERLINE) {
result.Write(FONT_UNDERLINE, 0, FONT_UNDERLINE.Length);
}
if ((fontStyle & STYLE_STRIKETHROUGH) == STYLE_STRIKETHROUGH) {
result.Write(FONT_STRIKETHROUGH, 0, FONT_STRIKETHROUGH.Length);
}
if ((fontStyle & STYLE_HIDDEN) == STYLE_HIDDEN) {
result.Write(FONT_HIDDEN, 0, FONT_HIDDEN.Length);
}
if ((fontStyle & STYLE_DOUBLE_STRIKETHROUGH) == STYLE_DOUBLE_STRIKETHROUGH) {
result.Write(FONT_DOUBLE_STRIKETHROUGH, 0, FONT_DOUBLE_STRIKETHROUGH.Length);
result.Write(t = IntToByteArray(1), 0, t.Length);
}
if ((fontStyle & STYLE_SHADOW) == STYLE_SHADOW) {
result.Write(FONT_SHADOW, 0, FONT_SHADOW.Length);
}
if ((fontStyle & STYLE_OUTLINE) == STYLE_OUTLINE) {
result.Write(FONT_OUTLINE, 0, FONT_OUTLINE.Length);
}
if ((fontStyle & STYLE_EMBOSSED) == STYLE_EMBOSSED) {
result.Write(FONT_EMBOSSED, 0, FONT_EMBOSSED.Length);
}
if ((fontStyle & STYLE_ENGRAVED) == STYLE_ENGRAVED) {
result.Write(FONT_ENGRAVED, 0, FONT_ENGRAVED.Length);
}
}
if(color != null) {
color.WriteBegin(result);
}
}
/**
* Write the font end
*
*/
public virtual void WriteEnd(Stream result) {
byte[] t;
if (this.fontStyle != UNDEFINED) {
if ((fontStyle & STYLE_BOLD) == STYLE_BOLD) {
result.Write(FONT_BOLD, 0, FONT_BOLD.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_ITALIC) == STYLE_ITALIC) {
result.Write(FONT_ITALIC, 0, FONT_ITALIC.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_UNDERLINE) == STYLE_UNDERLINE) {
result.Write(FONT_UNDERLINE, 0, FONT_UNDERLINE.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_STRIKETHROUGH) == STYLE_STRIKETHROUGH) {
result.Write(FONT_STRIKETHROUGH, 0, FONT_STRIKETHROUGH.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_HIDDEN) == STYLE_HIDDEN) {
result.Write(FONT_HIDDEN, 0, FONT_HIDDEN.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_DOUBLE_STRIKETHROUGH) == STYLE_DOUBLE_STRIKETHROUGH) {
result.Write(FONT_DOUBLE_STRIKETHROUGH, 0, FONT_DOUBLE_STRIKETHROUGH.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_SHADOW) == STYLE_SHADOW) {
result.Write(FONT_SHADOW, 0, FONT_SHADOW.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_OUTLINE) == STYLE_OUTLINE) {
result.Write(FONT_OUTLINE, 0, FONT_OUTLINE.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_EMBOSSED) == STYLE_EMBOSSED) {
result.Write(FONT_EMBOSSED, 0, FONT_EMBOSSED.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
if ((fontStyle & STYLE_ENGRAVED) == STYLE_ENGRAVED) {
result.Write(FONT_ENGRAVED, 0, FONT_ENGRAVED.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
}
}
}
/**
* unused
*/
public virtual void WriteContent(Stream outp) {
}
/**
* Tests for equality of RtfFonts. RtfFonts are equal if their fontName,
* fontSize, fontStyle and fontSuperSubscript are equal
*
* @param obj The RtfFont to compare with this RtfFont
* @return <code>True</code> if the RtfFonts are equal, <code>false</code> otherwise
*/
public override bool Equals(Object obj) {
if (!(obj is RtfFont)) {
return false;
}
RtfFont font = (RtfFont) obj;
bool result = true;
result = result & this.fontName.Equals(font.GetFontName());
return result;
}
/**
* Returns the hash code of this RtfFont. The hash code is the hash code of the
* string containing the font name + font size + "-" + the font style + "-" + the
* font super/supscript value.
*
* @return The hash code of this RtfFont
*/
public override int GetHashCode() {
return (this.fontName + this.fontSize + "-" + this.fontStyle).GetHashCode();
}
/**
* Gets the font name of this RtfFont
*
* @return The font name
*/
public String GetFontName() {
return this.fontName;
}
/**
* Sets the font name of this RtfFont.
*
* @param fontName The font name to use
*/
public virtual void SetFontName(String fontName) {
this.fontName = fontName;
if(document != null) {
this.fontNumber = document.GetDocumentHeader().GetFontNumber(this);
}
}
/**
* @see com.lowagie.text.Font#getFamilyname()
*/
public override String Familyname {
get {
return this.fontName;
}
}
/**
* @see com.lowagie.text.Font#setFamily(String)
*/
public override void SetFamily(String family){
base.SetFamily(family);
SetToDefaultFamily(family);
}
/**
* Sets the correct font name from the family name.
*
* @param familyname The family name to set the name to.
*/
private void SetToDefaultFamily(String familyname){
switch (Font.GetFamilyIndex(familyname)) {
case Font.COURIER:
this.fontName = "Courier";
break;
case Font.HELVETICA:
this.fontName = "Arial";
break;
case Font.SYMBOL:
this.fontName = "Symbol";
this.charset = 2;
break;
case Font.TIMES_ROMAN:
this.fontName = "Times New Roman";
break;
case Font.ZAPFDINGBATS:
this.fontName = "Windings";
break;
default:
this.fontName = familyname;
break;
}
}
/**
* Gets the font size of this RtfFont
*
* @return The font size
*/
public int GetFontSize() {
return this.fontSize;
}
/**
* @see com.lowagie.text.Font#setSize(float)
*/
public override float Size {
set {
base.Size = value;
this.fontSize = (int)Size;
}
}
/**
* Gets the font style of this RtfFont
*
* @return The font style
*/
public int GetFontStyle() {
return this.fontStyle;
}
/**
* @see com.lowagie.text.Font#setStyle(int)
*/
public override void SetStyle(int style){
base.SetStyle(style);
this.fontStyle = Style;
}
/**
* @see com.lowagie.text.Font#setStyle(String)
*/
public override void SetStyle(String style) {
base.SetStyle(style);
fontStyle = Style;
}
/**
* Gets the charset used for constructing this RtfFont.
*
* @return The charset of this RtfFont.
*/
public int GetCharset() {
return charset;
}
/**
* Sets the charset used for constructing this RtfFont.
*
* @param charset The charset to use.
*/
public void SetCharset(int charset) {
this.charset = charset;
}
/**
* Gets the font number of this RtfFont
*
* @return The font number
*/
public int GetFontNumber() {
return fontNumber;
}
/**
* Sets the RtfDocument this RtfFont belongs to
*
* @param doc The RtfDocument to use
*/
public void SetRtfDocument(RtfDocument doc) {
this.document = doc;
if (document != null) {
this.fontNumber = document.GetDocumentHeader().GetFontNumber(this);
}
if (this.color != null) {
this.color.SetRtfDocument(this.document);
}
}
/**
* Unused
* @param inTable
*/
public void SetInTable(bool inTable) {
}
/**
* Unused
* @param inHeader
*/
public void SetInHeader(bool inHeader) {
}
/**
* @see com.lowagie.text.Font#setColor(Color)
*/
public override Color Color {
set {
base.Color = value;
if(value != null) {
this.color = new RtfColor(document, value);
} else {
this.color = null;
}
}
}
/**
* @see com.lowagie.text.Font#setColor(int, int, int)
*/
public override void SetColor(int red, int green, int blue) {
base.SetColor(red,green,blue);
this.color = new RtfColor(document, red, green, blue);
}
/**
* 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
*/
protected byte[] IntToByteArray(int i) {
return DocWriter.GetISOBytes(i.ToString());
}
/**
* Replaces the attributes that are equal to <VAR>null</VAR> with
* the attributes of a given font.
*
* @param font The surrounding font
* @return A RtfFont
*/
public override Font Difference(Font font) {
String dFamilyname = font.Familyname;
if (dFamilyname == null || dFamilyname.Trim().Equals("") || Util.EqualsIgnoreCase(dFamilyname.Trim(), "unknown")) {
dFamilyname = this.fontName;
}
float dSize = font.Size;
if (dSize == Font.UNDEFINED) {
dSize = this.Size;
}
int dStyle = Font.UNDEFINED;
if (this.Style != Font.UNDEFINED && font.Style != Font.UNDEFINED) {
dStyle = this.Style | font.Style;
} else if (this.Style != Font.UNDEFINED) {
dStyle = this.Style;
} else if (font.Style != Font.UNDEFINED) {
dStyle = font.Style;
}
Color dColor = font.Color;
if (dColor == null) {
dColor = this.Color;
}
int dCharset = this.charset;
if(font is RtfFont) {
dCharset = ((RtfFont)font).GetCharset();
}
return new RtfFont(dFamilyname, dSize, dStyle, dColor, dCharset);
}
/**
* The <code>RtfFont</code> is never a standard font.
*
* @since 2.1.0
*/
public override bool IsStandardFont() {
return false;
}
/**
* Compares this <code>RtfFont</code> to either a {@link com.lowagie.text.Font} or
* an <code>RtfFont</code>.
*
* @since 2.1.0
*/
public override int CompareTo(Object obj) {
if (obj == null) {
return -1;
}
if(obj is RtfFont) {
if(this.GetFontName().CompareTo(((RtfFont) obj).GetFontName()) != 0) {
return 1;
} else {
return base.CompareTo(obj);
}
} else if (obj is Font) {
return base.CompareTo(obj);
} else {
return -3;
}
}
}
}

View File

@@ -0,0 +1,147 @@
using System;
using System.IO;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
/*
* $Id: RtfFontList.cs,v 1.6 2008/05/16 19:31:12 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.style {
/**
* The RtfFontList stores the list of fonts used in the rtf document. It also
* has methods for writing this list to the document
*
* Version: $Id: RtfFontList.cs,v 1.6 2008/05/16 19:31:12 psoares33 Exp $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfFontList : RtfElement, IRtfExtendedElement {
/**
* Constant for the default font
*/
private static byte[] DEFAULT_FONT = DocWriter.GetISOBytes("\\deff");
/**
* Constant for the font table
*/
private static byte[] FONT_TABLE = DocWriter.GetISOBytes("\\fonttbl");
/**
* Constant for the font number
*/
public static byte[] FONT_NUMBER = DocWriter.GetISOBytes("\\f");
/**
* The list of fonts
*/
private ArrayList fontList = new ArrayList();
/**
* Creates a RtfFontList
*
* @param doc The RtfDocument this RtfFontList belongs to
*/
public RtfFontList(RtfDocument doc) : base(doc) {
fontList.Add(new RtfFont(document, 0));
}
/**
* unused
*/
public override void WriteContent(Stream outp) {
}
/**
* Gets the index of the font in the list of fonts. If the font does not
* exist in the list, it is added.
*
* @param font The font to get the id for
* @return The index of the font
*/
public int GetFontNumber(RtfFont font) {
if(font is RtfParagraphStyle) {
font = new RtfFont(this.document, (RtfParagraphStyle) font);
}
int fontIndex = -1;
for (int i = 0; i < fontList.Count; i++) {
if (fontList[i].Equals(font)) {
fontIndex = i;
}
}
if (fontIndex == -1) {
fontIndex = fontList.Count;
fontList.Add(font);
}
return fontIndex;
}
/**
* Writes the definition of the font list
*/
public virtual void WriteDefinition(Stream result) {
byte[] t;
result.Write(DEFAULT_FONT, 0, DEFAULT_FONT.Length);
result.Write(t = IntToByteArray(0), 0, t.Length);
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
result.Write(FONT_TABLE, 0, FONT_TABLE.Length);
for (int i = 0; i < fontList.Count; i++) {
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
result.Write(FONT_NUMBER, 0, FONT_NUMBER.Length);
result.Write(t = IntToByteArray(i), 0, t.Length);
RtfFont rf = (RtfFont) fontList[i];
rf.WriteDefinition(result);
result.Write(COMMA_DELIMITER, 0, COMMA_DELIMITER.Length);
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
}
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
result.WriteByte((byte)'\n');
}
}
}

View File

@@ -0,0 +1,675 @@
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.text;
namespace iTextSharp.text.rtf.style {
/**
* The RtfParagraphStyle stores all style/formatting attributes of a RtfParagraph.
* Additionally it also supports the style name system available in RTF. The RtfParagraphStyle
* is a Font and can thus be used as such. To use the stylesheet functionality
* it needs to be set as the font of a Paragraph. Otherwise it will work like a
* RtfFont. It also supports inheritance of styles.
*
* @version $Revision: 1.8 $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfParagraphStyle : RtfFont {
/**
* Constant for left alignment
*/
public static byte[] ALIGN_LEFT = DocWriter.GetISOBytes("\\ql");
/**
* Constant for right alignment
*/
public static byte[] ALIGN_RIGHT = DocWriter.GetISOBytes("\\qr");
/**
* Constant for center alignment
*/
public static byte[] ALIGN_CENTER = DocWriter.GetISOBytes("\\qc");
/**
* Constant for justified alignment
*/
public static byte[] ALIGN_JUSTIFY = DocWriter.GetISOBytes("\\qj");
/**
* Constant for the first line indentation
*/
public static byte[] FIRST_LINE_INDENT = DocWriter.GetISOBytes("\\fi");
/**
* Constant for left indentation
*/
public static byte[] INDENT_LEFT = DocWriter.GetISOBytes("\\li");
/**
* Constant for right indentation
*/
public static byte[] INDENT_RIGHT = DocWriter.GetISOBytes("\\ri");
/**
* Constant for keeping the paragraph together on one page
*/
public static byte[] KEEP_TOGETHER = DocWriter.GetISOBytes("\\keep");
/**
* Constant for keeping the paragraph toghether with the next one on one page
*/
public static byte[] KEEP_TOGETHER_WITH_NEXT = DocWriter.GetISOBytes("\\keepn");
/**
* Constant for the space after the paragraph.
*/
public static byte[] SPACING_AFTER = DocWriter.GetISOBytes("\\sa");
/**
* Constant for the space before the paragraph.
*/
public static byte[] SPACING_BEFORE = DocWriter.GetISOBytes("\\sb");
/**
* The NORMAL/STANDARD style.
*/
public static RtfParagraphStyle STYLE_NORMAL = new RtfParagraphStyle("Normal", "Arial", 12, Font.NORMAL, Color.BLACK);
/**
* The style for level 1 headings.
*/
public static RtfParagraphStyle STYLE_HEADING_1 = new RtfParagraphStyle("heading 1", "Normal");
/**
* The style for level 2 headings.
*/
public static RtfParagraphStyle STYLE_HEADING_2 = new RtfParagraphStyle("heading 2", "Normal");
/**
* The style for level 3 headings.
*/
public static RtfParagraphStyle STYLE_HEADING_3 = new RtfParagraphStyle("heading 3", "Normal");
/**
* Initialises the properties of the styles.
*/
static RtfParagraphStyle() {
STYLE_HEADING_1.Size = 16;
STYLE_HEADING_1.SetStyle(Font.BOLD);
STYLE_HEADING_2.Size = 14;
STYLE_HEADING_2.SetStyle(Font.BOLDITALIC);
STYLE_HEADING_3.Size = 13;
STYLE_HEADING_3.SetStyle(Font.BOLD);
}
/**
* No modification has taken place when compared to the RtfParagraphStyle this RtfParagraphStyle
* is based on. These modification markers are used to determine what needs to be
* inherited and what not from the parent RtfParagraphStyle.
*/
private const int MODIFIED_NONE = 0;
/**
* The alignment has been modified.
*/
private const int MODIFIED_ALIGNMENT = 1;
/**
* The left indentation has been modified.
*/
private const int MODIFIED_INDENT_LEFT = 2;
/**
* The right indentation has been modified.
*/
private const int MODIFIED_INDENT_RIGHT = 4;
/**
* The spacing before a paragraph has been modified.
*/
private const int MODIFIED_SPACING_BEFORE = 8;
/**
* The spacing after a paragraph has been modified.
*/
private const int MODIFIED_SPACING_AFTER = 16;
/**
* The font name has been modified.
*/
private const int MODIFIED_FONT_NAME = 32;
/**
* The font style has been modified.
*/
private const int MODIFIED_FONT_SIZE = 64;
/**
* The font size has been modified.
*/
private const int MODIFIED_FONT_STYLE = 128;
/**
* The font colour has been modified.
*/
private const int MODIFIED_FONT_COLOR = 256;
/**
* The line leading has been modified.
*/
private const int MODIFIED_LINE_LEADING = 512;
/**
* The paragraph keep together setting has been modified.
*/
private const int MODIFIED_KEEP_TOGETHER = 1024;
/**
* The paragraph keep together with next setting has been modified.
*/
private const int MODIFIED_KEEP_TOGETHER_WITH_NEXT = 2048;
/**
* The alignment of the paragraph.
*/
private int alignment = Element.ALIGN_LEFT;
/**
* The indentation for the first line
*/
private int firstLineIndent = 0;
/**
* The left indentation of the paragraph.
*/
private int indentLeft = 0;
/**
* The right indentation of the paragraph.
*/
private int indentRight = 0;
/**
* The spacing before a paragraph.
*/
private int spacingBefore = 0;
/**
* The spacing after a paragraph.
*/
private int spacingAfter = 0;
/**
* The line leading of the paragraph.
*/
private int lineLeading = 0;
/**
* Whether this RtfParagraph must stay on one page.
*/
private bool keepTogether = false;
/**
* Whether this RtfParagraph must stay on the same page as the next paragraph.
*/
private bool keepTogetherWithNext = false;
/**
* The name of this RtfParagraphStyle.
*/
private String styleName = "";
/**
* The name of the RtfParagraphStyle this RtfParagraphStyle is based on.
*/
private String basedOnName = null;
/**
* The RtfParagraphStyle this RtfParagraphStyle is based on.
*/
private RtfParagraphStyle baseStyle = null;
/**
* Which properties have been modified when compared to the base style.
*/
private int modified = MODIFIED_NONE;
/**
* The number of this RtfParagraphStyle in the stylesheet list.
*/
private int styleNumber = -1;
/**
* Constructs a new RtfParagraphStyle with the given attributes.
*
* @param styleName The name of this RtfParagraphStyle.
* @param fontName The name of the font to use for this RtfParagraphStyle.
* @param fontSize The size of the font to use for this RtfParagraphStyle.
* @param fontStyle The style of the font to use for this RtfParagraphStyle.
* @param fontColor The colour of the font to use for this RtfParagraphStyle.
*/
public RtfParagraphStyle(String styleName, String fontName, int fontSize, int fontStyle, Color fontColor) : base(null, new RtfFont(fontName, fontSize, fontStyle, fontColor)) {
this.styleName = styleName;
}
/**
* Constructs a new RtfParagraphStyle that is based on an existing RtfParagraphStyle.
*
* @param styleName The name of this RtfParagraphStyle.
* @param basedOnName The name of the RtfParagraphStyle this RtfParagraphStyle is based on.
*/
public RtfParagraphStyle(String styleName, String basedOnName) : base(null, new Font()) {
this.styleName = styleName;
this.basedOnName = basedOnName;
}
/**
* Constructs a RtfParagraphStyle from another RtfParagraphStyle.
*
* INTERNAL USE ONLY
*
* @param doc The RtfDocument this RtfParagraphStyle belongs to.
* @param style The RtfParagraphStyle to copy settings from.
*/
public RtfParagraphStyle(RtfDocument doc, RtfParagraphStyle style) : base(doc, style) {
this.document = doc;
this.styleName = style.GetStyleName();
this.alignment = style.GetAlignment();
this.firstLineIndent = (int)(style.GetFirstLineIndent() * RtfElement.TWIPS_FACTOR);
this.indentLeft = (int) (style.GetIndentLeft() * RtfElement.TWIPS_FACTOR);
this.indentRight = (int) (style.GetIndentRight() * RtfElement.TWIPS_FACTOR);
this.spacingBefore = (int) (style.GetSpacingBefore() * RtfElement.TWIPS_FACTOR);
this.spacingAfter = (int) (style.GetSpacingAfter() * RtfElement.TWIPS_FACTOR);
this.lineLeading = (int) (style.GetLineLeading() * RtfElement.TWIPS_FACTOR);
this.keepTogether = style.GetKeepTogether();
this.keepTogetherWithNext = style.GetKeepTogetherWithNext();
this.basedOnName = style.basedOnName;
this.modified = style.modified;
this.styleNumber = style.GetStyleNumber();
if (this.document != null) {
SetRtfDocument(this.document);
}
}
/**
* Gets the name of this RtfParagraphStyle.
*
* @return The name of this RtfParagraphStyle.
*/
public String GetStyleName() {
return this.styleName;
}
/**
* Gets the name of the RtfParagraphStyle this RtfParagraphStyle is based on.
*
* @return The name of the base RtfParagraphStyle.
*/
public String GetBasedOnName() {
return this.basedOnName;
}
/**
* Gets the alignment of this RtfParagraphStyle.
*
* @return The alignment of this RtfParagraphStyle.
*/
public int GetAlignment() {
return this.alignment;
}
/**
* Sets the alignment of this RtfParagraphStyle.
*
* @param alignment The alignment to use.
*/
public void SetAlignment(int alignment) {
this.modified = this.modified | MODIFIED_ALIGNMENT;
this.alignment = alignment;
}
/**
* Gets the first line indentation of this RtfParagraphStyle.
*
* @return The first line indentation of this RtfParagraphStyle.
*/
public int GetFirstLineIndent() {
return this.firstLineIndent;
}
/**
* Sets the first line indententation of this RtfParagraphStyle. It
* is relative to the left indentation.
*
* @param firstLineIndent The first line indentation to use.
*/
public void SetFirstLineIndent(int firstLineIndent) {
this.firstLineIndent = firstLineIndent;
}
/**
* Gets the left indentation of this RtfParagraphStyle.
*
* @return The left indentation of this RtfParagraphStyle.
*/
public int GetIndentLeft() {
return this.indentLeft;
}
/**
* Sets the left indentation of this RtfParagraphStyle.
*
* @param indentLeft The left indentation to use.
*/
public void SetIndentLeft(int indentLeft) {
this.modified = this.modified | MODIFIED_INDENT_LEFT;
this.indentLeft = indentLeft;
}
/**
* Gets the right indentation of this RtfParagraphStyle.
*
* @return The right indentation of this RtfParagraphStyle.
*/
public int GetIndentRight() {
return this.indentRight;
}
/**
* Sets the right indentation of this RtfParagraphStyle.
*
* @param indentRight The right indentation to use.
*/
public void SetIndentRight(int indentRight) {
this.modified = this.modified | MODIFIED_INDENT_RIGHT;
this.indentRight = indentRight;
}
/**
* Gets the space before the paragraph of this RtfParagraphStyle..
*
* @return The space before the paragraph.
*/
public int GetSpacingBefore() {
return this.spacingBefore;
}
/**
* Sets the space before the paragraph of this RtfParagraphStyle.
*
* @param spacingBefore The space before to use.
*/
public void SetSpacingBefore(int spacingBefore) {
this.modified = this.modified | MODIFIED_SPACING_BEFORE;
this.spacingBefore = spacingBefore;
}
/**
* Gets the space after the paragraph of this RtfParagraphStyle.
*
* @return The space after the paragraph.
*/
public int GetSpacingAfter() {
return this.spacingAfter;
}
/**
* Sets the space after the paragraph of this RtfParagraphStyle.
*
* @param spacingAfter The space after to use.
*/
public void SetSpacingAfter(int spacingAfter) {
this.modified = this.modified | MODIFIED_SPACING_AFTER;
this.spacingAfter = spacingAfter;
}
/**
* Sets the font name of this RtfParagraphStyle.
*
* @param fontName The font name to use
*/
public override void SetFontName(String fontName) {
this.modified = this.modified | MODIFIED_FONT_NAME;
base.SetFontName(fontName);
}
/**
* Sets the font size of this RtfParagraphStyle.
*
* @param fontSize The font size to use.
*/
public override float Size {
set {
this.modified = this.modified | MODIFIED_FONT_SIZE;
base.Size = value;
}
}
/**
* Sets the font style of this RtfParagraphStyle.
*
* @param fontStyle The font style to use.
*/
public override void SetStyle(int fontStyle) {
this.modified = this.modified | MODIFIED_FONT_STYLE;
base.SetStyle(fontStyle);
}
/**
* Sets the colour of this RtfParagraphStyle.
*
* @param color The Color to use.
*/
public void SetColor(Color color) {
this.modified = this.modified | MODIFIED_FONT_COLOR;
base.Color = color;
}
/**
* Gets the line leading of this RtfParagraphStyle.
*
* @return The line leading of this RtfParagraphStyle.
*/
public int GetLineLeading() {
return this.lineLeading;
}
/**
* Sets the line leading of this RtfParagraphStyle.
*
* @param lineLeading The line leading to use.
*/
public void SetLineLeading(int lineLeading) {
this.lineLeading = lineLeading;
this.modified = this.modified | MODIFIED_LINE_LEADING;
}
/**
* Gets whether the lines in the paragraph should be kept together in
* this RtfParagraphStyle.
*
* @return Whether the lines in the paragraph should be kept together.
*/
public bool GetKeepTogether() {
return this.keepTogether;
}
/**
* Sets whether the lines in the paragraph should be kept together in
* this RtfParagraphStyle.
*
* @param keepTogether Whether the lines in the paragraph should be kept together.
*/
public void SetKeepTogether(bool keepTogether) {
this.keepTogether = keepTogether;
this.modified = this.modified | MODIFIED_KEEP_TOGETHER;
}
/**
* Gets whether the paragraph should be kept toggether with the next in
* this RtfParagraphStyle.
*
* @return Whether the paragraph should be kept together with the next.
*/
public bool GetKeepTogetherWithNext() {
return this.keepTogetherWithNext;
}
/**
* Sets whether the paragraph should be kept together with the next in
* this RtfParagraphStyle.
*
* @param keepTogetherWithNext Whether the paragraph should be kept together with the next.
*/
public void SetKeepTogetherWithNext(bool keepTogetherWithNext) {
this.keepTogetherWithNext = keepTogetherWithNext;
this.modified = this.modified | MODIFIED_KEEP_TOGETHER_WITH_NEXT;
}
/**
* Handles the inheritance of paragraph style settings. All settings that
* have not been modified will be inherited from the base RtfParagraphStyle.
* If this RtfParagraphStyle is not based on another one, then nothing happens.
*/
public void HandleInheritance() {
if (this.basedOnName != null && this.document.GetDocumentHeader().GetRtfParagraphStyle(this.basedOnName) != null) {
this.baseStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(this.basedOnName);
this.baseStyle.HandleInheritance();
if (!((this.modified & MODIFIED_ALIGNMENT) == MODIFIED_ALIGNMENT)) {
this.alignment = this.baseStyle.GetAlignment();
}
if (!((this.modified & MODIFIED_INDENT_LEFT) == MODIFIED_INDENT_LEFT)) {
this.indentLeft = this.baseStyle.GetIndentLeft();
}
if (!((this.modified & MODIFIED_INDENT_RIGHT) == MODIFIED_INDENT_RIGHT)) {
this.indentRight = this.baseStyle.GetIndentRight();
}
if (!((this.modified & MODIFIED_SPACING_BEFORE) == MODIFIED_SPACING_BEFORE)) {
this.spacingBefore = this.baseStyle.GetSpacingBefore();
}
if (!((this.modified & MODIFIED_SPACING_AFTER) == MODIFIED_SPACING_AFTER)) {
this.spacingAfter = this.baseStyle.GetSpacingAfter();
}
if (!((this.modified & MODIFIED_FONT_NAME) == MODIFIED_FONT_NAME)) {
SetFontName(this.baseStyle.GetFontName());
}
if (!((this.modified & MODIFIED_FONT_SIZE) == MODIFIED_FONT_SIZE)) {
Size = this.baseStyle.GetFontSize();
}
if (!((this.modified & MODIFIED_FONT_STYLE) == MODIFIED_FONT_STYLE)) {
SetStyle(this.baseStyle.GetFontStyle());
}
if (!((this.modified & MODIFIED_FONT_COLOR) == MODIFIED_FONT_COLOR)) {
SetColor(this.baseStyle.Color);
}
if (!((this.modified & MODIFIED_LINE_LEADING) == MODIFIED_LINE_LEADING)) {
SetLineLeading(this.baseStyle.GetLineLeading());
}
if (!((this.modified & MODIFIED_KEEP_TOGETHER) == MODIFIED_KEEP_TOGETHER)) {
SetKeepTogether(this.baseStyle.GetKeepTogether());
}
if (!((this.modified & MODIFIED_KEEP_TOGETHER_WITH_NEXT) == MODIFIED_KEEP_TOGETHER_WITH_NEXT)) {
SetKeepTogetherWithNext(this.baseStyle.GetKeepTogetherWithNext());
}
}
}
/**
* Writes the settings of this RtfParagraphStyle.
*
*/
private void WriteParagraphSettings(Stream result) {
byte[] t;
if (this.keepTogether) {
result.Write(t = RtfParagraphStyle.KEEP_TOGETHER, 0, t.Length);
}
if (this.keepTogetherWithNext) {
result.Write(t = RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT, 0, t.Length);
}
switch (alignment) {
case Element.ALIGN_LEFT:
result.Write(t = RtfParagraphStyle.ALIGN_LEFT, 0, t.Length);
break;
case Element.ALIGN_RIGHT:
result.Write(t = RtfParagraphStyle.ALIGN_RIGHT, 0, t.Length);
break;
case Element.ALIGN_CENTER:
result.Write(t = RtfParagraphStyle.ALIGN_CENTER, 0, t.Length);
break;
case Element.ALIGN_JUSTIFIED:
case Element.ALIGN_JUSTIFIED_ALL:
result.Write(t = RtfParagraphStyle.ALIGN_JUSTIFY, 0, t.Length);
break;
}
result.Write(t = FIRST_LINE_INDENT, 0, t.Length);
result.Write(t = IntToByteArray(this.firstLineIndent), 0, t.Length);
result.Write(t = RtfParagraphStyle.INDENT_LEFT, 0, t.Length);
result.Write(t = IntToByteArray(indentLeft), 0, t.Length);
result.Write(t = RtfParagraphStyle.INDENT_RIGHT, 0, t.Length);
result.Write(t = IntToByteArray(indentRight), 0, t.Length);
if (this.spacingBefore > 0) {
result.Write(t = RtfParagraphStyle.SPACING_BEFORE, 0, t.Length);
result.Write(t = IntToByteArray(this.spacingBefore), 0, t.Length);
}
if (this.spacingAfter > 0) {
result.Write(t = RtfParagraphStyle.SPACING_AFTER, 0, t.Length);
result.Write(t = IntToByteArray(this.spacingAfter), 0, t.Length);
}
if (this.lineLeading > 0) {
result.Write(t = RtfParagraph.LINE_SPACING, 0, t.Length);
result.Write(t = IntToByteArray(this.lineLeading), 0, t.Length);
}
}
/**
* Writes the definition of this RtfParagraphStyle for the stylesheet list.
*/
public override void WriteDefinition(Stream result) {
byte[] t;
result.Write(t = DocWriter.GetISOBytes("{"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\style"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\s"), 0, t.Length);
result.Write(t = IntToByteArray(this.styleNumber), 0, t.Length);
result.Write(t = RtfElement.DELIMITER, 0, t.Length);
WriteParagraphSettings(result);
base.WriteBegin(result);
result.Write(t = RtfElement.DELIMITER, 0, t.Length);
result.Write(t = DocWriter.GetISOBytes(this.styleName), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes(";"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length);
if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) {
result.WriteByte((byte)'\n');
}
}
/**
* Writes the start information of this RtfParagraphStyle.
*
* @param result The <code>OutputStream</code> to write to.
* @throws IOException On i/o errors.
*/
public override void WriteBegin(Stream result) {
byte[] t;
result.Write(t = DocWriter.GetISOBytes("\\s"), 0, t.Length);
result.Write(t = IntToByteArray(this.styleNumber), 0, t.Length);
WriteParagraphSettings(result);
}
/**
* Unused
*/
public override void WriteEnd(Stream result) {
}
/**
* unused
*/
public override void WriteContent(Stream outp) {
}
/**
* Tests whether two RtfParagraphStyles are equal. Equality
* is determined via the name.
*/
public override bool Equals(Object o) {
if (!(o is RtfParagraphStyle)) {
return false;
}
RtfParagraphStyle paragraphStyle = (RtfParagraphStyle) o;
bool result = this.GetStyleName().Equals(paragraphStyle.GetStyleName());
return result;
}
/**
* Gets the hash code of this RtfParagraphStyle.
*/
public override int GetHashCode() {
return this.styleName.GetHashCode();
}
/**
* Gets the number of this RtfParagraphStyle in the stylesheet list.
*
* @return The number of this RtfParagraphStyle in the stylesheet list.
*/
private int GetStyleNumber() {
return this.styleNumber;
}
/**
* Sets the number of this RtfParagraphStyle in the stylesheet list.
*
* @param styleNumber The number to use.
*/
protected internal void SetStyleNumber(int styleNumber) {
this.styleNumber = styleNumber;
}
}
}

View File

@@ -0,0 +1,81 @@
using System;
/*
* $Id: RtfStyleTypes.cs,v 1.1 2008/02/14 14:52:32 psoares33 Exp $
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* 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.style {
/**
* <code>RtfStyleTypes</code> contains the different types of Stylesheet entries
* that exist in RTF.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public sealed class RtfStyleTypes {
/**
* Indicates paragraph style.
*/
public const int PARAGRAPH = 0;
/**
* Indicates character style.
*/
public const int CHARACTER = 0;
/**
* Indicates section style.
*/
public const int SECTION = 2;
/**
* Indicates Table style.
*/
public const int TABLE = 3;
/**
* Indicates table definition style.
*/
public const int TABLE_STYLE_DEFINITION = 4;
}
}

View File

@@ -0,0 +1,110 @@
using System;
using System.IO;
using System.Collections;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
namespace iTextSharp.text.rtf.style {
/**
* The RtfStylesheetList stores the RtfParagraphStyles that are used in the document.
*
* @version $Revision: 1.5 $
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
*/
public class RtfStylesheetList : RtfElement, IRtfExtendedElement {
/**
* The Hashtable containing the RtfParagraphStyles.
*/
private Hashtable styleMap = null;
/**
* Whether the default settings have been loaded.
*/
private bool defaultsLoaded = false;
/**
* Constructs a new RtfStylesheetList for the RtfDocument.
*
* @param doc The RtfDocument this RtfStylesheetList belongs to.
*/
public RtfStylesheetList(RtfDocument doc) : base(doc) {
this.styleMap = new Hashtable();
}
/**
* unused
*/
public override void WriteContent(Stream outp) {
}
/**
* Register a RtfParagraphStyle with this RtfStylesheetList.
*
* @param rtfParagraphStyle The RtfParagraphStyle to add.
*/
public void RegisterParagraphStyle(RtfParagraphStyle rtfParagraphStyle) {
RtfParagraphStyle tempStyle = new RtfParagraphStyle(this.document, rtfParagraphStyle);
tempStyle.HandleInheritance();
tempStyle.SetStyleNumber(this.styleMap.Count);
this.styleMap[tempStyle.GetStyleName()] = tempStyle;
}
/**
* Registers all default styles. If styles with the given name have already been registered,
* then they are NOT overwritten.
*/
private void RegisterDefaultStyles() {
defaultsLoaded = true;
if (!this.styleMap.ContainsKey(RtfParagraphStyle.STYLE_NORMAL.GetStyleName())) {
RegisterParagraphStyle(RtfParagraphStyle.STYLE_NORMAL);
}
if (!this.styleMap.ContainsKey(RtfParagraphStyle.STYLE_HEADING_1.GetStyleName())) {
RegisterParagraphStyle(RtfParagraphStyle.STYLE_HEADING_1);
}
if (!this.styleMap.ContainsKey(RtfParagraphStyle.STYLE_HEADING_2.GetStyleName())) {
RegisterParagraphStyle(RtfParagraphStyle.STYLE_HEADING_2);
}
if (!this.styleMap.ContainsKey(RtfParagraphStyle.STYLE_HEADING_3.GetStyleName())) {
RegisterParagraphStyle(RtfParagraphStyle.STYLE_HEADING_3);
}
}
/**
* Gets the RtfParagraphStyle with the given name. Makes sure that the defaults
* have been loaded.
*
* @param styleName The name of the RtfParagraphStyle to get.
* @return The RtfParagraphStyle with the given name or null.
*/
public RtfParagraphStyle GetRtfParagraphStyle(String styleName) {
if (!defaultsLoaded) {
RegisterDefaultStyles();
}
if (this.styleMap.ContainsKey(styleName)) {
return (RtfParagraphStyle) this.styleMap[styleName];
} else {
return null;
}
}
/**
* Writes the definition of the stylesheet list.
*/
public virtual void WriteDefinition(Stream result) {
byte[] t;
result.Write(t = DocWriter.GetISOBytes("{"), 0, t.Length);
result.Write(t = DocWriter.GetISOBytes("\\stylesheet"), 0, t.Length);
result.Write(t = RtfElement.DELIMITER, 0, t.Length);
if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) {
result.Write(t = DocWriter.GetISOBytes("\n"), 0, t.Length);
}
foreach (RtfParagraphStyle rps in this.styleMap.Values)
rps.WriteDefinition(result);
result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length);
if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) {
result.WriteByte((byte)'\n');
}
}
}
}