Initial Commit
This commit is contained in:
6
iTechSharp/iTextSharp/text/rtf/IEventListener.cs
Normal file
6
iTechSharp/iTextSharp/text/rtf/IEventListener.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text.rtf {
|
||||
public interface IEventListener {
|
||||
}
|
||||
}
|
||||
87
iTechSharp/iTextSharp/text/rtf/IRtfBasicElement.cs
Normal file
87
iTechSharp/iTextSharp/text/rtf/IRtfBasicElement.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: IRtfBasicElement.cs,v 1.4 2008/05/13 11:25:42 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 {
|
||||
|
||||
public interface IRtfBasicElement : IRtfElementInterface {
|
||||
|
||||
/**
|
||||
* Writes the element content to the given output stream.
|
||||
*
|
||||
* @param out The <code>OutputStream</code> to write the content to
|
||||
*/
|
||||
void WriteContent(Stream outp);
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfElement belongs to
|
||||
*
|
||||
* @param doc The @link{com.lowagie.text.rtf.document.RtfDocument} this <code>RtfElement</code> belongs to
|
||||
*/
|
||||
void SetRtfDocument(RtfDocument doc);
|
||||
|
||||
/**
|
||||
* Sets whether this IRtfBasicElement is in a table
|
||||
*
|
||||
* @param inTable Whether this IRtfBasicElement is in a table
|
||||
*/
|
||||
void SetInTable(bool inTable);
|
||||
|
||||
/**
|
||||
* Sets whether this IRtfBasicElement is in a header
|
||||
*
|
||||
* @param inHeader Whether this IRtfBasicElement is in a header
|
||||
*/
|
||||
void SetInHeader(bool inHeader);
|
||||
}
|
||||
}
|
||||
70
iTechSharp/iTextSharp/text/rtf/IRtfExtendedElement.cs
Normal file
70
iTechSharp/iTextSharp/text/rtf/IRtfExtendedElement.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
/*
|
||||
* $Id: IRtfExtendedElement.cs,v 1.5 2008/05/16 19:30: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 {
|
||||
|
||||
/**
|
||||
* The RtfExtendedElement interface is to be used for elements that also
|
||||
* write data into the definition part of the rtf document
|
||||
* Version: $Id: IRtfExtendedElement.cs,v 1.5 2008/05/16 19:30:12 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public interface IRtfExtendedElement : IRtfBasicElement {
|
||||
/**
|
||||
* Write the definition part of the element
|
||||
*
|
||||
* @param doc The <code>OutputStream</code> to write the element definition to
|
||||
*/
|
||||
void WriteDefinition(Stream outp);
|
||||
}
|
||||
}
|
||||
134
iTechSharp/iTextSharp/text/rtf/RtfAddableElement.cs
Normal file
134
iTechSharp/iTextSharp/text/rtf/RtfAddableElement.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfAddableElement.cs,v 1.6 2008/05/16 19:30:13 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.
|
||||
* Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
|
||||
* Copyright (C) 2006 by Mark Hall. 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 {
|
||||
|
||||
/**
|
||||
* The RtfAddableElement is the superclass for all rtf specific elements
|
||||
* that need to be added to an iText document. It is an extension of Chunk
|
||||
* and it also implements RtfBasicElement. It is an abstract class thus it
|
||||
* cannot be instantiated itself and has to be subclassed to be used.
|
||||
*
|
||||
* @version $Revision: 1.6 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public abstract class RtfAddableElement : Chunk, IRtfBasicElement {
|
||||
|
||||
/**
|
||||
* The RtfDocument this RtfAddableElement belongs to.
|
||||
*/
|
||||
protected RtfDocument doc = null;
|
||||
/**
|
||||
* Whether this RtfAddableElement is contained in a table.
|
||||
*/
|
||||
protected bool inTable = false;
|
||||
/**
|
||||
* Whether this RtfAddableElement is contained in a header.
|
||||
*/
|
||||
protected bool inHeader = false;
|
||||
|
||||
/**
|
||||
* Constructs a new RtfAddableElement. The Chunk content is
|
||||
* set to an empty string and the font to the default Font().
|
||||
*/
|
||||
public RtfAddableElement() : base("", new Font()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the element content to the given output stream.
|
||||
*/
|
||||
public abstract void WriteContent(Stream outp);
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfAddableElement belongs to.
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.doc = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfAddableElement is contained in a table.
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
this.inTable = inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfAddableElement is contained in a header/footer.
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
this.inHeader = inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an integer into its String representation and then returns the bytes
|
||||
* of that string.
|
||||
*
|
||||
* @param i The integer to convert
|
||||
* @return A byte array representing the integer
|
||||
*/
|
||||
public byte[] IntToByteArray(int i) {
|
||||
return DocWriter.GetISOBytes(i.ToString());
|
||||
}
|
||||
|
||||
/**
|
||||
* RtfAddableElement subclasses are never assumed to be empty.
|
||||
*/
|
||||
public override bool IsEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
159
iTechSharp/iTextSharp/text/rtf/RtfElement.cs
Normal file
159
iTechSharp/iTextSharp/text/rtf/RtfElement.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: RtfElement.cs,v 1.5 2008/05/16 19:30:14 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 {
|
||||
|
||||
/**
|
||||
* RtfElement is the base class for all RTF Element classes
|
||||
*
|
||||
* Version: $Id: RtfElement.cs,v 1.5 2008/05/16 19:30:14 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public abstract class RtfElement : IRtfBasicElement {
|
||||
/**
|
||||
* Constant for the beginning of a rtf group
|
||||
*/
|
||||
public static byte[] OPEN_GROUP = {(byte)'{'};
|
||||
/**
|
||||
* Constant for the end of an rtf group
|
||||
*/
|
||||
public static byte[] CLOSE_GROUP = {(byte)'}'};
|
||||
/**
|
||||
* Constant for a delimiter in rtf
|
||||
*/
|
||||
public static byte[] DELIMITER = {(byte)' '};
|
||||
/**
|
||||
* Constant for a comma delimiter in rtf
|
||||
*/
|
||||
public static byte[] COMMA_DELIMITER = {(byte)';'};
|
||||
/**
|
||||
* The factor to use for translating from iText to rtf measurments
|
||||
*/
|
||||
public const double TWIPS_FACTOR = 20;
|
||||
|
||||
/**
|
||||
* The RtfDocument this RtfElement belongs to
|
||||
*/
|
||||
protected RtfDocument document = null;
|
||||
/**
|
||||
* Whether this RtfElement is in a table
|
||||
*/
|
||||
protected bool inTable = false;
|
||||
/**
|
||||
* Whether this RtfElement is in a header
|
||||
*/
|
||||
protected bool inHeader = false;
|
||||
|
||||
/**
|
||||
* Constructs a RtfElement belonging to the specified RtfDocument.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfElement belongs to
|
||||
*/
|
||||
public RtfElement(RtfDocument doc) : base(){
|
||||
this.document = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public byte[] IntToByteArray(int i) {
|
||||
return DocWriter.GetISOBytes(i.ToString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the element content to the given output stream.
|
||||
*/
|
||||
public abstract void WriteContent(Stream outp);
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfElement belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public virtual void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this RtfElement is in a table
|
||||
*
|
||||
* @return Whether this RtfElement is in a table
|
||||
*/
|
||||
public virtual bool IsInTable() {
|
||||
return inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfElement is in a table
|
||||
*
|
||||
* @param inTable <code>True</code> if this RtfElement is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public virtual void SetInTable(bool inTable) {
|
||||
this.inTable = inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfElement is in a header
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfElement is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public virtual void SetInHeader(bool inHeader) {
|
||||
this.inHeader = inHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
173
iTechSharp/iTextSharp/text/rtf/RtfMapper.cs
Normal file
173
iTechSharp/iTextSharp/text/rtf/RtfMapper.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.field;
|
||||
using iTextSharp.text.rtf.graphic;
|
||||
using iTextSharp.text.rtf.list;
|
||||
using iTextSharp.text.rtf.table;
|
||||
using iTextSharp.text.rtf.text;
|
||||
/*
|
||||
* $Id: RtfMapper.cs,v 1.4 2008/05/16 19:30:14 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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 {
|
||||
|
||||
/**
|
||||
* The RtfMapper provides mappings between com.lowagie.text.* classes
|
||||
* and the corresponding com.lowagie.text.rtf.** classes.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfMapper {
|
||||
|
||||
/**
|
||||
* The RtfDocument this RtfMapper belongs to
|
||||
*/
|
||||
RtfDocument rtfDoc;
|
||||
|
||||
/**
|
||||
* Constructs a RtfMapper for a RtfDocument
|
||||
*
|
||||
* @param doc The RtfDocument this RtfMapper belongs to
|
||||
*/
|
||||
public RtfMapper(RtfDocument doc) {
|
||||
this.rtfDoc = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an Element subclass and returns an array of RtfBasicElement
|
||||
* subclasses, that contained the mapped RTF equivalent to the Element
|
||||
* passed in.
|
||||
*
|
||||
* @param element The Element to wrap
|
||||
* @return An array of RtfBasicElement wrapping the Element
|
||||
* @throws DocumentException
|
||||
*/
|
||||
public IRtfBasicElement[] MapElement(IElement element) {
|
||||
ArrayList rtfElements = new ArrayList();
|
||||
|
||||
if (element is IRtfBasicElement) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) element;
|
||||
rtfElement.SetRtfDocument(this.rtfDoc);
|
||||
return new IRtfBasicElement[]{rtfElement};
|
||||
}
|
||||
switch (element.Type) {
|
||||
case Element.CHUNK:
|
||||
Chunk chunk = (Chunk) element;
|
||||
if (chunk.HasAttributes()) {
|
||||
if (chunk.Attributes.ContainsKey(Chunk.IMAGE)) {
|
||||
rtfElements.Add(new RtfImage(rtfDoc, (Image) chunk.Attributes[Chunk.IMAGE]));
|
||||
} else if (chunk.Attributes.ContainsKey(Chunk.NEWPAGE)) {
|
||||
rtfElements.Add(new RtfNewPage(rtfDoc));
|
||||
} else if (chunk.Attributes.ContainsKey(Chunk.TAB)) {
|
||||
float tabPos = (float) ((Object[]) chunk.Attributes[Chunk.TAB])[1];
|
||||
RtfTab tab = new RtfTab(tabPos, RtfTab.TAB_LEFT_ALIGN);
|
||||
tab.SetRtfDocument(rtfDoc);
|
||||
rtfElements.Add(tab);
|
||||
rtfElements.Add(new RtfChunk(rtfDoc, new Chunk("\t")));
|
||||
} else {
|
||||
rtfElements.Add(new RtfChunk(rtfDoc, (Chunk) element));
|
||||
}
|
||||
} else {
|
||||
rtfElements.Add(new RtfChunk(rtfDoc, (Chunk) element));
|
||||
}
|
||||
break;
|
||||
case Element.PHRASE:
|
||||
rtfElements.Add(new RtfPhrase(rtfDoc, (Phrase) element));
|
||||
break;
|
||||
case Element.PARAGRAPH:
|
||||
rtfElements.Add(new RtfParagraph(rtfDoc, (Paragraph) element));
|
||||
break;
|
||||
case Element.ANCHOR:
|
||||
rtfElements.Add(new RtfAnchor(rtfDoc, (Anchor) element));
|
||||
break;
|
||||
case Element.ANNOTATION:
|
||||
rtfElements.Add(new RtfAnnotation(rtfDoc, (Annotation) element));
|
||||
break;
|
||||
case Element.IMGRAW:
|
||||
case Element.IMGTEMPLATE:
|
||||
case Element.JPEG:
|
||||
rtfElements.Add(new RtfImage(rtfDoc, (Image) element));
|
||||
break;
|
||||
case Element.AUTHOR:
|
||||
case Element.SUBJECT:
|
||||
case Element.KEYWORDS:
|
||||
case Element.TITLE:
|
||||
case Element.PRODUCER:
|
||||
case Element.CREATIONDATE:
|
||||
rtfElements.Add(new RtfInfoElement(rtfDoc, (Meta) element));
|
||||
break;
|
||||
case Element.LIST:
|
||||
rtfElements.Add(new RtfList(rtfDoc, (List) element));
|
||||
break;
|
||||
case Element.LISTITEM:
|
||||
rtfElements.Add(new RtfListItem(rtfDoc, (ListItem) element));
|
||||
break;
|
||||
case Element.SECTION:
|
||||
rtfElements.Add(new RtfSection(rtfDoc, (Section) element));
|
||||
break;
|
||||
case Element.CHAPTER:
|
||||
rtfElements.Add(new RtfChapter(rtfDoc, (Chapter) element));
|
||||
break;
|
||||
case Element.TABLE:
|
||||
try {
|
||||
rtfElements.Add(new RtfTable(rtfDoc, (Table) element));
|
||||
}
|
||||
catch (InvalidCastException) {
|
||||
rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable) element).CreateTable()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return (IRtfBasicElement[]) rtfElements.ToArray(typeof(IRtfBasicElement));
|
||||
}
|
||||
}
|
||||
}
|
||||
334
iTechSharp/iTextSharp/text/rtf/RtfWriter2.cs
Normal file
334
iTechSharp/iTextSharp/text/rtf/RtfWriter2.cs
Normal file
@@ -0,0 +1,334 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
/*
|
||||
* $Id: RtfWriter2.cs,v 1.11 2008/05/23 17:24: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 {
|
||||
|
||||
/**
|
||||
* The RtfWriter allows the creation of rtf documents via the iText system
|
||||
*
|
||||
* Version: $Id: RtfWriter2.cs,v 1.11 2008/05/23 17:24:11 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfWriter2 : DocWriter {
|
||||
/**
|
||||
* The RtfDocument this RtfWriter is creating
|
||||
*/
|
||||
private RtfDocument rtfDoc = null;
|
||||
|
||||
/**
|
||||
* Constructs a new RtfWriter that listens to the specified Document and
|
||||
* writes its output to the Stream.
|
||||
*
|
||||
* @param doc The Document that this RtfWriter listens to
|
||||
* @param os The Stream to write to
|
||||
*/
|
||||
protected RtfWriter2(Document doc, Stream os) : base(doc, os) {
|
||||
doc.AddDocListener(this);
|
||||
rtfDoc = new RtfDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static method to generate RtfWriters
|
||||
*
|
||||
* @param doc The Document that this RtfWriter listens to
|
||||
* @param os The Stream to write to
|
||||
* @return The new RtfWriter
|
||||
*/
|
||||
public static RtfWriter2 GetInstance(Document doc, Stream os) {
|
||||
return new RtfWriter2(doc, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the header to use
|
||||
*
|
||||
* @param hf The HeaderFooter to use
|
||||
*/
|
||||
public override HeaderFooter Header {
|
||||
set {
|
||||
this.rtfDoc.GetDocumentHeader().SetHeader(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the header
|
||||
*/
|
||||
public override void ResetHeader() {
|
||||
this.rtfDoc.GetDocumentHeader().SetHeader(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the footer to use
|
||||
*
|
||||
* @param hf The HeaderFooter to use
|
||||
*/
|
||||
public override HeaderFooter Footer {
|
||||
set {
|
||||
this.rtfDoc.GetDocumentHeader().SetFooter(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the footer
|
||||
*/
|
||||
public override void ResetFooter() {
|
||||
this.rtfDoc.GetDocumentHeader().SetFooter(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not supported in the RtfWriter
|
||||
* @param i Unused
|
||||
*/
|
||||
public override int PageCount {
|
||||
set {}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not supported in the RtfWriter
|
||||
*/
|
||||
public override void ResetPageCount() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the RtfDocument
|
||||
*/
|
||||
public override void Open() {
|
||||
base.Open();
|
||||
this.rtfDoc.Open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the RtfDocument. This causes the document to be written
|
||||
* to the specified Stream
|
||||
*/
|
||||
public override void Close() {
|
||||
if (open) {
|
||||
rtfDoc.WriteDocument(os);
|
||||
base.Close();
|
||||
this.rtfDoc = new RtfDocument();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an Element to the Document
|
||||
*
|
||||
* @param element The element to be added
|
||||
* @return <code>false</code>
|
||||
* @throws DocumentException
|
||||
*/
|
||||
public override bool Add(IElement element) {
|
||||
if (pause) {
|
||||
return false;
|
||||
}
|
||||
IRtfBasicElement[] rtfElements = rtfDoc.GetMapper().MapElement(element);
|
||||
if(rtfElements.Length != 0) {
|
||||
for (int i = 0; i < rtfElements.Length; i++) {
|
||||
if (rtfElements[i] != null) {
|
||||
rtfDoc.Add(rtfElements[i]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a page break
|
||||
*
|
||||
* @return <code>false</code>
|
||||
*/
|
||||
public override bool NewPage() {
|
||||
rtfDoc.Add(new RtfNewPage(rtfDoc));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page margins
|
||||
*
|
||||
* @param left The left margin
|
||||
* @param right The right margin
|
||||
* @param top The top margin
|
||||
* @param bottom The bottom margin
|
||||
* @return <code>false</code>
|
||||
*/
|
||||
public override bool SetMargins(float left, float right, float top, float bottom) {
|
||||
rtfDoc.GetDocumentHeader().GetPageSetting().SetMarginLeft((int) (left * RtfElement.TWIPS_FACTOR));
|
||||
rtfDoc.GetDocumentHeader().GetPageSetting().SetMarginRight((int) (right * RtfElement.TWIPS_FACTOR));
|
||||
rtfDoc.GetDocumentHeader().GetPageSetting().SetMarginTop((int) (top * RtfElement.TWIPS_FACTOR));
|
||||
rtfDoc.GetDocumentHeader().GetPageSetting().SetMarginBottom((int) (bottom * RtfElement.TWIPS_FACTOR));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the page
|
||||
*
|
||||
* @param rect A Rectangle representing the page
|
||||
* @return <code>false</code>
|
||||
*/
|
||||
public override bool SetPageSize(Rectangle rect) {
|
||||
rtfDoc.GetDocumentHeader().GetPageSetting().SetPageSize(rect);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to automagically generate table of contents entries when
|
||||
* adding Chapters or Sections.
|
||||
*
|
||||
* @param autogenerate Whether to automatically generate TOC entries
|
||||
*/
|
||||
public void SetAutogenerateTOCEntries(bool autogenerate) {
|
||||
this.rtfDoc.SetAutogenerateTOCEntries(autogenerate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfDocumentSettings that specify how the rtf document is generated.
|
||||
*
|
||||
* @return The current RtfDocumentSettings.
|
||||
*/
|
||||
public RtfDocumentSettings GetDocumentSettings() {
|
||||
return this.rtfDoc.GetDocumentSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the complete RTF document to the current RTF document being generated.
|
||||
* It will parse the font and color tables and correct the font and color references
|
||||
* so that the imported RTF document retains its formattings.
|
||||
*
|
||||
* @param documentSource The Stream to read the RTF document from.
|
||||
* @throws IOException On errors reading the RTF document.
|
||||
* @throws DocumentException On errors adding to this RTF document.
|
||||
*/
|
||||
public void ImportRtfDocument(Stream documentSource) {
|
||||
ImportRtfDocument(documentSource, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the complete RTF document to the current RTF document being generated.
|
||||
* It will parse the font and color tables and correct the font and color references
|
||||
* so that the imported RTF document retains its formattings.
|
||||
* Uses new RtfParser object.
|
||||
*
|
||||
* @param documentSource The Stream to read the RTF document from.
|
||||
* @param eventListeners The array of event listeners. May be null
|
||||
* @throws IOException
|
||||
* @throws DocumentException
|
||||
*
|
||||
* @see com.lowagie.text.rtf.parser.RtfParser
|
||||
* @see com.lowagie.text.rtf.parser.RtfParser#importRtfDocument(Reader, RtfDocument)
|
||||
* @since 2.0.8
|
||||
* @author Howard Shank
|
||||
*/
|
||||
public void ImportRtfDocument(Stream documentSource, IEventListener[] events ) {
|
||||
if(!this.open) {
|
||||
throw new DocumentException("The document must be open to import RTF documents.");
|
||||
}
|
||||
RtfParser rtfImport = new RtfParser();
|
||||
if(events != null) {
|
||||
for(int idx=0;idx<events.Length;idx++) {
|
||||
rtfImport.AddListener(events[idx]);
|
||||
}
|
||||
}
|
||||
rtfImport.ImportRtfDocument(documentSource, this.rtfDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a fragment of an RTF document to the current RTF document being generated.
|
||||
* Since this fragment doesn't contain font or color tables, all fonts and colors
|
||||
* are mapped to the default font and color. If the font and color mappings are
|
||||
* known, they can be specified via the mappings parameter.
|
||||
*
|
||||
* @param documentSource The Stream to read the RTF fragment from.
|
||||
* @param mappings The RtfImportMappings that contain font and color mappings to apply to the fragment.
|
||||
* @throws IOException On errors reading the RTF fragment.
|
||||
* @throws DocumentException On errors adding to this RTF fragment.
|
||||
*/
|
||||
public void ImportRtfFragment(Stream documentSource, RtfImportMappings mappings) {
|
||||
ImportRtfFragment(documentSource, mappings, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a fragment of an RTF document to the current RTF document being generated.
|
||||
* Since this fragment doesn't contain font or color tables, all fonts and colors
|
||||
* are mapped to the default font and color. If the font and color mappings are
|
||||
* known, they can be specified via the mappings parameter.
|
||||
* Uses new RtfParser object.
|
||||
*
|
||||
* @param documentSource The Stream to read the RTF fragment from.
|
||||
* @param mappings The RtfImportMappings that contain font and color mappings to apply to the fragment.
|
||||
* @param eventListeners The array of event listeners. May be null
|
||||
* @throws IOException On errors reading the RTF fragment.
|
||||
* @throws DocumentException On errors adding to this RTF fragment.
|
||||
*
|
||||
* @see com.lowagie.text.rtf.parser.RtfImportMappings
|
||||
* @see com.lowagie.text.rtf.parser.RtfParser
|
||||
* @see com.lowagie.text.rtf.parser.RtfParser#importRtfFragment(Reader, RtfDocument, com.lowagie.text.rtf.parser.RtfImportMappings)
|
||||
* @since 2.0.8
|
||||
* @author Howard Shank
|
||||
*/
|
||||
public void ImportRtfFragment(Stream documentSource, RtfImportMappings mappings, IEventListener[] events ) {
|
||||
if(!this.open) {
|
||||
throw new DocumentException("The document must be open to import RTF fragments.");
|
||||
}
|
||||
RtfParser rtfImport = new RtfParser();
|
||||
if(events != null) {
|
||||
for(int idx=0;idx<events.Length;idx++) {
|
||||
rtfImport.AddListener(events[idx]);
|
||||
}
|
||||
}
|
||||
rtfImport.ImportRtfFragment(documentSource, this.rtfDoc, mappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
101
iTechSharp/iTextSharp/text/rtf/direct/RtfDirectContent.cs
Normal file
101
iTechSharp/iTextSharp/text/rtf/direct/RtfDirectContent.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text;
|
||||
/**
|
||||
* $Id: RtfDirectContent.cs,v 1.6 2008/05/23 17:24:25 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.direct {
|
||||
|
||||
/**
|
||||
* The RtfDirectContent makes it possible to directly add RTF code into
|
||||
* an RTF document. This can be used to directly add RTF fragments that
|
||||
* have been created with other RTF editors. One important aspect is that
|
||||
* font and color numbers will not be modified. This means that the
|
||||
* fonts and colors visible in the final document might not be equivalent
|
||||
* with those set on the direct content.<br /><br />
|
||||
*
|
||||
* For convenience the RtfDirectContent provides a DIRECT_SOFT_LINEBREAK
|
||||
* constant that makes it possible to easily add soft line-breaks anywhere in
|
||||
* the RTF document.
|
||||
*
|
||||
* @version $Revision: 1.6 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfDirectContent : RtfAddableElement {
|
||||
/**
|
||||
* Add the DIRECT_SOFT_LINEBREAK to the Document to insert
|
||||
* a soft line-break at that position.
|
||||
*/
|
||||
public static RtfDirectContent DIRECT_SOFT_LINEBREAK = new RtfDirectContent("\\line");
|
||||
|
||||
/**
|
||||
* The direct content to add.
|
||||
*/
|
||||
private String directContent = "";
|
||||
|
||||
/**
|
||||
* Constructs a new RtfDirectContent with the content to add.
|
||||
*
|
||||
* @param directContent The content to add.
|
||||
*/
|
||||
public RtfDirectContent(String directContent) {
|
||||
this.directContent = directContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the element content to the given output stream.
|
||||
*/
|
||||
public override void WriteContent(Stream outp) {
|
||||
byte[] contentBytes = DocWriter.GetISOBytes(this.directContent);
|
||||
outp.Write(contentBytes, 0, contentBytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
99
iTechSharp/iTextSharp/text/rtf/document/RtfCodePage.cs
Normal file
99
iTechSharp/iTextSharp/text/rtf/document/RtfCodePage.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfCodePage.cs,v 1.5 2008/05/16 19:30:50 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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.document {
|
||||
|
||||
/**
|
||||
* The RtfCodePage class allows different code pages to be used in the rtf document.
|
||||
* Currently always ansi / ansicpg1252
|
||||
*
|
||||
* Version: $Id: RtfCodePage.cs,v 1.5 2008/05/16 19:30:50 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfCodePage : RtfElement, IRtfExtendedElement {
|
||||
/**
|
||||
* Constant for ansi encoded rtf documents
|
||||
*/
|
||||
private static byte[] ANSI = DocWriter.GetISOBytes("\\ansi");
|
||||
/**
|
||||
* Constant for the ansi codepage
|
||||
*/
|
||||
private static byte[] ANSI_CODEPAGE = DocWriter.GetISOBytes("\\ansicpg");
|
||||
|
||||
/**
|
||||
* Construct an RtfCodePage
|
||||
*
|
||||
* @param doc The RtfDocument this RtfCodePage belongs to
|
||||
*/
|
||||
public RtfCodePage(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* unused
|
||||
*/
|
||||
public override void WriteContent(Stream outp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the selected codepage
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
result.Write(ANSI, 0, ANSI.Length);
|
||||
result.Write(ANSI_CODEPAGE, 0, ANSI_CODEPAGE.Length);
|
||||
byte[] t = IntToByteArray(1252);
|
||||
result.Write(t, 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
347
iTechSharp/iTextSharp/text/rtf/document/RtfDocument.cs
Normal file
347
iTechSharp/iTextSharp/text/rtf/document/RtfDocument.cs
Normal file
@@ -0,0 +1,347 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document.output;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.graphic;
|
||||
/*
|
||||
* $Id: RtfDocument.cs,v 1.12 2008/05/16 19:30:50 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2003, 2004, 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.document {
|
||||
|
||||
/**
|
||||
* The RtfDocument stores all document related data and also the main data stream.
|
||||
* INTERNAL CLASS - NOT TO BE USED DIRECTLY
|
||||
*
|
||||
* Version: $Id: RtfDocument.cs,v 1.12 2008/05/16 19:30:50 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Todd Bush (Todd.Bush@canopysystems.com) [Tab support]
|
||||
*/
|
||||
public class RtfDocument : RtfElement {
|
||||
/**
|
||||
* Stores the actual document data
|
||||
*/
|
||||
private IRtfDataCache data = null;
|
||||
/**
|
||||
* The RtfMapper to use in this RtfDocument
|
||||
*/
|
||||
private RtfMapper mapper = null;
|
||||
/**
|
||||
* The RtfDocumentHeader that handles all document header methods
|
||||
*/
|
||||
private RtfDocumentHeader documentHeader = null;
|
||||
/**
|
||||
* Stores integers that have been generated as unique random numbers
|
||||
*/
|
||||
private ArrayList previousRandomInts = null;
|
||||
/**
|
||||
* Whether to automatically generate TOC entries for Chapters and Sections. Defaults to false
|
||||
*/
|
||||
private bool autogenerateTOCEntries = false;
|
||||
/**
|
||||
* The RtfDocumentSettings for this RtfDocument.
|
||||
*/
|
||||
private RtfDocumentSettings documentSettings = null;
|
||||
|
||||
/**
|
||||
* The last RtfBasicElement that was added directly to the RtfDocument.
|
||||
*/
|
||||
private IRtfBasicElement lastElementWritten = null;
|
||||
|
||||
/**
|
||||
* Constant for the Rtf document start
|
||||
*/
|
||||
private static byte[] RTF_DOCUMENT = DocWriter.GetISOBytes("\\rtf1");
|
||||
private static byte[] FSC_LINE = DocWriter.GetISOBytes("\\line ");
|
||||
private static byte[] FSC_PAR = DocWriter.GetISOBytes("\\par ");
|
||||
private static byte[] FSC_TAB = DocWriter.GetISOBytes("\\tab ");
|
||||
private static byte[] FSC_PAGE_PAR = DocWriter.GetISOBytes("\\page\\par ");
|
||||
private static byte[] FSC_NEWPAGE = DocWriter.GetISOBytes("$newpage$");
|
||||
private static byte[] FSC_BACKSLASH = DocWriter.GetISOBytes("\\");
|
||||
private static byte[] FSC_HEX_PREFIX = DocWriter.GetISOBytes("\\\'");
|
||||
private static byte[] FSC_UNI_PREFIX = DocWriter.GetISOBytes("\\u");
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* The default constructor for a RtfDocument
|
||||
*/
|
||||
public RtfDocument() : base(null) {
|
||||
this.data = new RtfMemoryCache();
|
||||
this.mapper = new RtfMapper(this);
|
||||
this.documentHeader = new RtfDocumentHeader(this);
|
||||
this.documentHeader.Init();
|
||||
this.previousRandomInts = new ArrayList();
|
||||
this.documentSettings = new RtfDocumentSettings(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* unused
|
||||
*/
|
||||
public override void WriteContent(Stream outp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the document
|
||||
*
|
||||
* @param outs The <code>Stream</code> to write the RTF document to.
|
||||
*/
|
||||
public void WriteDocument(Stream outs) {
|
||||
try {
|
||||
outs.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
outs.Write(RtfDocument.RTF_DOCUMENT, 0, RtfDocument.RTF_DOCUMENT.Length);
|
||||
this.documentHeader.WriteContent(outs);
|
||||
this.data.WriteTo(outs);
|
||||
outs.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
} catch (IOException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the RtfDocument and initialises the data cache. If the data cache is
|
||||
* set to CACHE_DISK, but the cache cannot be initialised then the memory cache
|
||||
* is used.
|
||||
*/
|
||||
public void Open() {
|
||||
try {
|
||||
switch (this.documentSettings.GetDataCacheStyle()) {
|
||||
case RtfDataCache.CACHE_MEMORY_EFFICIENT:
|
||||
this.data = new RtfEfficientMemoryCache();
|
||||
break;
|
||||
case RtfDataCache.CACHE_MEMORY:
|
||||
this.data = new RtfMemoryCache();
|
||||
break;
|
||||
case RtfDataCache.CACHE_DISK:
|
||||
this.data = new RtfDiskCache();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown");
|
||||
}
|
||||
} catch (IOException) {
|
||||
this.data = new RtfMemoryCache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an element to the rtf document
|
||||
*
|
||||
* @param element The element to add
|
||||
*/
|
||||
public void Add(IRtfBasicElement element) {
|
||||
try {
|
||||
if (element is RtfInfoElement) {
|
||||
this.documentHeader.AddInfoElement((RtfInfoElement) element);
|
||||
} else {
|
||||
if (element is RtfImage) {
|
||||
((RtfImage) element).SetTopLevelElement(true);
|
||||
}
|
||||
element.WriteContent(this.data.GetOutputStream());
|
||||
this.lastElementWritten = element;
|
||||
}
|
||||
} catch (IOException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfMapper object of this RtfDocument
|
||||
*
|
||||
* @return The RtfMapper
|
||||
*/
|
||||
public RtfMapper GetMapper() {
|
||||
return this.mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random integer that is unique with respect to the document.
|
||||
*
|
||||
* @return A random int
|
||||
*/
|
||||
public int GetRandomInt() {
|
||||
int newInt;
|
||||
do {
|
||||
lock (random) {
|
||||
newInt = random.Next(int.MaxValue - 2);
|
||||
}
|
||||
} while (this.previousRandomInts.Contains(newInt));
|
||||
this.previousRandomInts.Add(newInt);
|
||||
return newInt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfDocumentHeader of this RtfDocument
|
||||
*
|
||||
* @return The RtfDocumentHeader of this RtfDocument
|
||||
*/
|
||||
public RtfDocumentHeader GetDocumentHeader() {
|
||||
return this.documentHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the given string to the given {@link Stream} encoding the string characters.
|
||||
*
|
||||
* @param outp destination Stream
|
||||
* @param str string to write
|
||||
* @param useHex if <code>true</code> hex encoding characters is preferred to unicode encoding if possible
|
||||
* @param softLineBreaks if <code>true</code> return characters are written as soft line breaks
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void FilterSpecialChar(Stream outp, String str, bool useHex, bool softLineBreaks) {
|
||||
if (outp == null) {
|
||||
throw new ArgumentException("null OutpuStream");
|
||||
}
|
||||
|
||||
bool alwaysUseUniCode = this.documentSettings.IsAlwaysUseUnicode();
|
||||
if (str == null) {
|
||||
return;
|
||||
}
|
||||
int len = str.Length;
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
byte[] t = null;
|
||||
for (int k = 0; k < len; k++) {
|
||||
char c = str[k];
|
||||
if (c < 0x20) {
|
||||
//allow return and tab only
|
||||
if (c == '\n') {
|
||||
outp.Write(t = softLineBreaks ? FSC_LINE : FSC_PAR, 0, t.Length);
|
||||
} else if (c == '\t') {
|
||||
outp.Write(FSC_TAB, 0, FSC_TAB.Length);
|
||||
} else {
|
||||
outp.WriteByte((byte)'?');
|
||||
}
|
||||
} else if ((c == '\\') || (c == '{') || (c == '}')) {
|
||||
//escape
|
||||
outp.Write(FSC_BACKSLASH, 0, FSC_BACKSLASH.Length);
|
||||
outp.WriteByte((byte)c);
|
||||
} else if ((c == '$') && (len-k >= FSC_NEWPAGE.Length) && SubMatch(str, k, FSC_NEWPAGE)) {
|
||||
outp.Write(FSC_PAGE_PAR, 0, FSC_PAGE_PAR.Length);
|
||||
k += FSC_NEWPAGE.Length-1;
|
||||
} else {
|
||||
if ((c > 0xff) || ((c > 'z') && alwaysUseUniCode)) {
|
||||
if (useHex && (c <= 0xff)) {
|
||||
//encode as 2 char hex string
|
||||
outp.Write(FSC_HEX_PREFIX, 0, FSC_HEX_PREFIX.Length);
|
||||
outp.Write(RtfImage.byte2charLUT, c*2, 2);
|
||||
} else {
|
||||
//encode as decimal, signed short value
|
||||
outp.Write(FSC_UNI_PREFIX, 0, FSC_UNI_PREFIX.Length);
|
||||
String s = ((short)c).ToString();
|
||||
for (int x = 0; x < s.Length; x++) {
|
||||
outp.WriteByte((byte)s[x]);
|
||||
}
|
||||
outp.WriteByte((byte)'?');
|
||||
}
|
||||
} else {
|
||||
outp.WriteByte((byte)c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns <code>true</code> if <tt>m.length</tt> characters in <tt>str</tt>, starting at offset <tt>soff</tt>
|
||||
* match the bytes in the given array <tt>m</tt>.
|
||||
*
|
||||
* @param str the string to search for a match
|
||||
* @param soff the starting offset in str
|
||||
* @param m the array to match
|
||||
* @return <code>true</code> if there is match
|
||||
*/
|
||||
private static bool SubMatch(String str, int soff, byte[] m)
|
||||
{
|
||||
for (int k = 0; k < m.Length; k++) {
|
||||
if (str[soff++] != (char)m[k]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to automagically generate table of contents entries when
|
||||
* adding Chapters or Sections.
|
||||
*
|
||||
* @param autogenerate Whether to automatically generate TOC entries
|
||||
*/
|
||||
public void SetAutogenerateTOCEntries(bool autogenerate) {
|
||||
this.autogenerateTOCEntries = autogenerate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether to autmatically generate table of contents entries
|
||||
*
|
||||
* @return Wheter to automatically generate TOC entries
|
||||
*/
|
||||
public bool GetAutogenerateTOCEntries() {
|
||||
return this.autogenerateTOCEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfDocumentSettings that specify how the rtf document is generated.
|
||||
*
|
||||
* @return The current RtfDocumentSettings.
|
||||
*/
|
||||
public RtfDocumentSettings GetDocumentSettings() {
|
||||
return this.documentSettings;
|
||||
}
|
||||
/**
|
||||
* Gets the last RtfBasicElement that was directly added to the RtfDocument.
|
||||
*
|
||||
* @return The last RtfBasicElement that was directly added to the RtfDocument.
|
||||
*/
|
||||
public IRtfBasicElement GetLastElementWritten() {
|
||||
return this.lastElementWritten;
|
||||
}
|
||||
}
|
||||
}
|
||||
321
iTechSharp/iTextSharp/text/rtf/document/RtfDocumentHeader.cs
Normal file
321
iTechSharp/iTextSharp/text/rtf/document/RtfDocumentHeader.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document.output;
|
||||
using iTextSharp.text.rtf.list;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using HF = iTextSharp.text.rtf.headerfooter;
|
||||
using iTextSharp.text.rtf.headerfooter;
|
||||
//using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfDocumentHeader.cs,v 1.11 2008/05/16 19:30:51 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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.document {
|
||||
|
||||
/**
|
||||
* The RtfDocumentHeader contains all classes required for the generation of
|
||||
* the document header area.
|
||||
*
|
||||
* @version $Id: RtfDocumentHeader.cs,v 1.11 2008/05/16 19:30:51 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
*/
|
||||
public class RtfDocumentHeader : RtfElement {
|
||||
/**
|
||||
* Constant for the title page
|
||||
*/
|
||||
private static byte[] TITLE_PAGE = DocWriter.GetISOBytes("\\titlepg");
|
||||
/**
|
||||
* Constant for facing pages
|
||||
*/
|
||||
private static byte[] FACING_PAGES = DocWriter.GetISOBytes("\\facingp");
|
||||
|
||||
/**
|
||||
* The code page to use
|
||||
*/
|
||||
private RtfCodePage codePage = null;
|
||||
/**
|
||||
* Stores all the colors used in the document
|
||||
*/
|
||||
private RtfColorList colorList = null;
|
||||
/**
|
||||
* Stores all the fonts used in the document
|
||||
*/
|
||||
private RtfFontList fontList = null;
|
||||
/**
|
||||
* Manages List tables
|
||||
*/
|
||||
private RtfListTable listTable = null;
|
||||
/**
|
||||
* Stores all paragraph styles used in the document.
|
||||
*/
|
||||
private RtfStylesheetList stylesheetList = null;
|
||||
/**
|
||||
* Generator string in document
|
||||
*/
|
||||
private RtfGenerator generator = null;
|
||||
/**
|
||||
* The information group with author/subject/keywords/title/producer/creationdate data
|
||||
*/
|
||||
private RtfInfoGroup infoGroup = null;
|
||||
/**
|
||||
* The protection settings
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private RtfProtectionSetting protectionSetting = null;
|
||||
/**
|
||||
* The page settings
|
||||
*/
|
||||
private RtfPageSetting pageSetting = null;
|
||||
/**
|
||||
* The current RtfHeaderFooterGroup for the header
|
||||
*/
|
||||
private HeaderFooter header = null;
|
||||
/**
|
||||
* The current RtfHeaderFooterGroup for the footer
|
||||
*/
|
||||
private HeaderFooter footer = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfDocumentHeader for a RtfDocument
|
||||
*
|
||||
* @param doc The RtfDocument this RtfDocumentHeader belongs to
|
||||
*/
|
||||
protected internal RtfDocumentHeader(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the RtfDocumentHeader.
|
||||
*/
|
||||
protected internal void Init() {
|
||||
this.codePage = new RtfCodePage(this.document);
|
||||
this.colorList = new RtfColorList(this.document);
|
||||
this.fontList = new RtfFontList(this.document);
|
||||
this.listTable = new RtfListTable(this.document);
|
||||
this.stylesheetList = new RtfStylesheetList(this.document);
|
||||
this.infoGroup = new RtfInfoGroup(this.document);
|
||||
this.protectionSetting = new RtfProtectionSetting(this.document);
|
||||
this.pageSetting = new RtfPageSetting(this.document);
|
||||
this.header = new RtfHeaderFooterGroup(this.document, HF.RtfHeaderFooter.TYPE_HEADER);
|
||||
this.footer = new RtfHeaderFooterGroup(this.document, HF.RtfHeaderFooter.TYPE_FOOTER);
|
||||
this.generator = new RtfGenerator(this.document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the document header area.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
try {
|
||||
// This is so that all colour, font and similar information is processed once, before
|
||||
// the header section is written.
|
||||
WriteSectionDefinition(new RtfNilOutputStream());
|
||||
|
||||
this.codePage.WriteDefinition(result);
|
||||
this.fontList.WriteDefinition(result);
|
||||
this.colorList.WriteDefinition(result);
|
||||
this.stylesheetList.WriteDefinition(result);
|
||||
this.listTable.WriteDefinition(result);
|
||||
this.generator.WriteContent(result);
|
||||
this.infoGroup.WriteContent(result);
|
||||
this.protectionSetting.WriteDefinition(result);
|
||||
this.pageSetting.WriteDefinition(result);
|
||||
|
||||
WriteSectionDefinition(result);
|
||||
} catch (IOException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the section definition data
|
||||
* @param result
|
||||
*/
|
||||
public void WriteSectionDefinition(Stream result) {
|
||||
try {
|
||||
RtfHeaderFooterGroup header = ConvertHeaderFooter(this.header, HF.RtfHeaderFooter.TYPE_HEADER);
|
||||
RtfHeaderFooterGroup footer = ConvertHeaderFooter(this.footer, HF.RtfHeaderFooter.TYPE_FOOTER);
|
||||
if (header.HasTitlePage() || footer.HasTitlePage()) {
|
||||
result.Write(TITLE_PAGE, 0, TITLE_PAGE.Length);
|
||||
header.SetHasTitlePage();
|
||||
footer.SetHasTitlePage();
|
||||
}
|
||||
if (header.HasFacingPages() || footer.HasFacingPages()) {
|
||||
result.Write(FACING_PAGES, 0, FACING_PAGES.Length);
|
||||
header.SetHasFacingPages();
|
||||
footer.SetHasFacingPages();
|
||||
}
|
||||
footer.WriteContent(result);
|
||||
header.WriteContent(result);
|
||||
pageSetting.WriteSectionDefinition(result);
|
||||
} catch (IOException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the specified RtfFont
|
||||
*
|
||||
* @param font The RtfFont for which to get the number
|
||||
* @return The number of the font
|
||||
*/
|
||||
public int GetFontNumber(ST.RtfFont font) {
|
||||
return this.fontList.GetFontNumber(font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the specified RtfColor
|
||||
*
|
||||
* @param color The RtfColor for which to get the number
|
||||
* @return The number of the color
|
||||
*/
|
||||
public int GetColorNumber(ST.RtfColor color) {
|
||||
return this.colorList.GetColorNumber(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of the specified RtfList
|
||||
*
|
||||
* @param list The RtfList for which to get the number
|
||||
* @return The number of the list
|
||||
*/
|
||||
public int GetListNumber(RtfList list) {
|
||||
return this.listTable.GetListNumber(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfParagraphStyle with the given style name.
|
||||
*
|
||||
* @param styleName The style name of the RtfParagraphStyle to get.
|
||||
* @return The RtfParagraphStyle with the given style name or null.
|
||||
*/
|
||||
public RtfParagraphStyle GetRtfParagraphStyle(String styleName) {
|
||||
return this.stylesheetList.GetRtfParagraphStyle(styleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a RtfList from the list table
|
||||
*
|
||||
* @param list The RtfList to remove
|
||||
*/
|
||||
public void FreeListNumber(RtfList list) {
|
||||
this.listTable.FreeListNumber(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfPageSetting object of this RtfDocument
|
||||
*
|
||||
* @return The RtfPageSetting object
|
||||
*/
|
||||
public RtfPageSetting GetPageSetting() {
|
||||
return this.pageSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an RtfInfoElement to the list of RtfInfoElements
|
||||
*
|
||||
* @param rtfInfoElement The RtfInfoElement to add
|
||||
*/
|
||||
public void AddInfoElement(RtfInfoElement rtfInfoElement) {
|
||||
this.infoGroup.Add(rtfInfoElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current header to use
|
||||
*
|
||||
* @param header The HeaderFooter to use as header
|
||||
*/
|
||||
public void SetHeader(HeaderFooter header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current footer to use
|
||||
*
|
||||
* @param footer The HeaderFooter to use as footer
|
||||
*/
|
||||
public void SetFooter(HeaderFooter footer) {
|
||||
this.footer = footer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the RtfParagraphStyle for further use in the document.
|
||||
*
|
||||
* @param rtfParagraphStyle The RtfParagraphStyle to register.
|
||||
*/
|
||||
public void RegisterParagraphStyle(RtfParagraphStyle rtfParagraphStyle) {
|
||||
this.stylesheetList.RegisterParagraphStyle(rtfParagraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a HeaderFooter into a RtfHeaderFooterGroup. Depending on which class
|
||||
* the HeaderFooter is, the correct RtfHeaderFooterGroup is created.
|
||||
*
|
||||
* @param hf The HeaderFooter to convert.
|
||||
* @param type Whether the conversion is being done on a footer or header
|
||||
* @return The converted RtfHeaderFooterGroup.
|
||||
* @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooter
|
||||
* @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup
|
||||
*/
|
||||
private RtfHeaderFooterGroup ConvertHeaderFooter(HeaderFooter hf, int type) {
|
||||
if (hf != null) {
|
||||
if (hf is RtfHeaderFooterGroup) {
|
||||
return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooterGroup) hf, type);
|
||||
} else if (hf is RtfHeaderFooter) {
|
||||
return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooter) hf, type);
|
||||
} else {
|
||||
return new RtfHeaderFooterGroup(this.document, hf, type);
|
||||
}
|
||||
} else {
|
||||
return new RtfHeaderFooterGroup(this.document, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
566
iTechSharp/iTextSharp/text/rtf/document/RtfDocumentSettings.cs
Normal file
566
iTechSharp/iTextSharp/text/rtf/document/RtfDocumentSettings.cs
Normal file
@@ -0,0 +1,566 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.document.output;
|
||||
|
||||
/*
|
||||
* $Id: RtfDocumentSettings.cs,v 1.10 2008/05/16 19:30:51 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2003, 2004, 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.document {
|
||||
|
||||
/**
|
||||
* The RtfDocumentSettings contains output specific settings. These settings modify
|
||||
* how the actual document is then generated and some settings may mean that some
|
||||
* RTF readers can't read the document or render it wrongly.
|
||||
*
|
||||
* @version $Id: RtfDocumentSettings.cs,v 1.10 2008/05/16 19:30:51 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
*/
|
||||
public class RtfDocumentSettings {
|
||||
|
||||
/**
|
||||
* The RtfDocument this RtfDocumentSettings belongs to.
|
||||
*/
|
||||
private RtfDocument document = null;
|
||||
/**
|
||||
* Whether to also output the table row definition after the cell content.
|
||||
*/
|
||||
private bool outputTableRowDefinitionAfter = true;
|
||||
/**
|
||||
* Whether to output the line breaks that make the rtf document source more readable.
|
||||
*/
|
||||
private bool outputDebugLineBreaks = true;
|
||||
/**
|
||||
* Whether to always generate soft linebreaks for \n in Chunks.
|
||||
*/
|
||||
private bool alwaysGenerateSoftLinebreaks = false;
|
||||
/**
|
||||
* Whether to always translate characters past 'z' into unicode representations.
|
||||
*/
|
||||
private bool alwaysUseUnicode = true;
|
||||
/**
|
||||
* How to cache the document during generation. Defaults to RtfDataCache.CACHE_MEMORY;
|
||||
*/
|
||||
private int dataCacheStyle = RtfDataCache.CACHE_MEMORY;
|
||||
/**
|
||||
* Whether to write image scaling information. This is required for Word 2000, 97 and Word for Mac
|
||||
*/
|
||||
private bool writeImageScalingInformation = false;
|
||||
/**
|
||||
* Whether images should be written in order to mimick the PDF output.
|
||||
*/
|
||||
private bool imagePDFConformance = true;
|
||||
/**
|
||||
* Document protection level
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private int protectionLevel = RtfProtection.LEVEL_NONE;
|
||||
/**
|
||||
* Document protection level password hash.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private String protectionHash = null;
|
||||
/**
|
||||
* Document read password hash
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
//private String writereservhash = null; //\*\writereservhash - not implemented
|
||||
/**
|
||||
* Document recommended to be opened in read only mode.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private bool readOnlyRecommended = false;
|
||||
/**
|
||||
* Images are written as binary data and not hex encoded.
|
||||
* @since 2.1.1
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
private bool imageWrittenAsBinary = true;
|
||||
|
||||
/**
|
||||
* Constructs a new RtfDocumentSettings object.
|
||||
*
|
||||
* @param document The RtfDocument this RtfDocumentSettings belong to.
|
||||
*/
|
||||
public RtfDocumentSettings(RtfDocument document) {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to output the line breaks for increased rtf document readability.
|
||||
*
|
||||
* @return Whether to output line breaks.
|
||||
*/
|
||||
public bool IsOutputDebugLineBreaks() {
|
||||
return outputDebugLineBreaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to output the line breaks for increased rtf document readability.
|
||||
* Some line breaks may be added where the rtf specification demands it.
|
||||
*
|
||||
* @param outputDebugLineBreaks The outputDebugLineBreaks to set.
|
||||
*/
|
||||
public void SetOutputDebugLineBreaks(bool outputDebugLineBreaks) {
|
||||
this.outputDebugLineBreaks = outputDebugLineBreaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the table row definition should also be written after the cell content.
|
||||
*
|
||||
* @return Returns the outputTableRowDefinitionAfter.
|
||||
*/
|
||||
public bool IsOutputTableRowDefinitionAfter() {
|
||||
return outputTableRowDefinitionAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the table row definition should also be written after the cell content.
|
||||
* This is recommended to be set to <code>true</code> if you need Word2000 compatiblity and
|
||||
* <code>false</code> if the document should be opened in OpenOffice.org Writer.
|
||||
*
|
||||
* @param outputTableRowDefinitionAfter The outputTableRowDefinitionAfter to set.
|
||||
*/
|
||||
public void SetOutputTableRowDefinitionAfter(
|
||||
bool outputTableRowDefinitionAfter) {
|
||||
this.outputTableRowDefinitionAfter = outputTableRowDefinitionAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether all linebreaks inside Chunks are generated as soft linebreaks.
|
||||
*
|
||||
* @return <code>True</code> if soft linebreaks are generated, <code>false</code> for hard linebreaks.
|
||||
*/
|
||||
public bool IsAlwaysGenerateSoftLinebreaks() {
|
||||
return this.alwaysGenerateSoftLinebreaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to always generate soft linebreaks.
|
||||
*
|
||||
* @param alwaysGenerateSoftLinebreaks Whether to always generate soft linebreaks.
|
||||
*/
|
||||
public void SetAlwaysGenerateSoftLinebreaks(bool alwaysGenerateSoftLinebreaks) {
|
||||
this.alwaysGenerateSoftLinebreaks = alwaysGenerateSoftLinebreaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether all characters bigger than 'z' are represented as unicode.
|
||||
*
|
||||
* @return <code>True</code> if unicode representation is used, <code>false</code> otherwise.
|
||||
*/
|
||||
public bool IsAlwaysUseUnicode() {
|
||||
return this.alwaysUseUnicode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to represent all characters bigger than 'z' as unicode.
|
||||
*
|
||||
* @param alwaysUseUnicode <code>True</code> to use unicode representation, <code>false</code> otherwise.
|
||||
*/
|
||||
public void SetAlwaysUseUnicode(bool alwaysUseUnicode) {
|
||||
this.alwaysUseUnicode = alwaysUseUnicode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the RtfParagraphStyle for further use in the document. This does not need to be
|
||||
* done for the default styles in the RtfParagraphStyle object. Those are added automatically.
|
||||
*
|
||||
* @param rtfParagraphStyle The RtfParagraphStyle to register.
|
||||
*/
|
||||
public void RegisterParagraphStyle(RtfParagraphStyle rtfParagraphStyle) {
|
||||
this.document.GetDocumentHeader().RegisterParagraphStyle(rtfParagraphStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data cache style. This controls where the document is cached during
|
||||
* generation. Two cache styles are supported:
|
||||
* <ul>
|
||||
* <li>RtfDataCache.CACHE_MEMORY: The document is cached in memory. This is fast,
|
||||
* but places a limit on how big the document can get before causing
|
||||
* OutOfMemoryExceptions.</li>
|
||||
* <li>RtfDataCache.CACHE_DISK: The document is cached on disk. This is slower
|
||||
* than the CACHE_MEMORY setting, but the document size is now only constrained
|
||||
* by the amount of free disk space.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param dataCacheStyle The data cache style to set. Valid constants can be found
|
||||
* in RtfDataCache.
|
||||
* @see com.lowagie.text.rtf.document.output.output.RtfDataCache.
|
||||
*/
|
||||
public void SetDataCacheStyle(int dataCacheStyle) {
|
||||
switch (dataCacheStyle) {
|
||||
case RtfDataCache.CACHE_MEMORY_EFFICIENT:
|
||||
this.dataCacheStyle = RtfDataCache.CACHE_MEMORY_EFFICIENT;
|
||||
break;
|
||||
case RtfDataCache.CACHE_DISK:
|
||||
this.dataCacheStyle = RtfDataCache.CACHE_DISK;
|
||||
break;
|
||||
default:
|
||||
//case RtfDataCache.CACHE_MEMORY:
|
||||
this.dataCacheStyle = RtfDataCache.CACHE_MEMORY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current data cache style.
|
||||
*
|
||||
* @return The current data cache style.
|
||||
*/
|
||||
public int GetDataCacheStyle() {
|
||||
return this.dataCacheStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current setting on image PDF conformance.
|
||||
*
|
||||
* @return The current image PDF conformance.
|
||||
*/
|
||||
public bool IsImagePDFConformance() {
|
||||
return this.imagePDFConformance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the image PDF conformance setting. By default images will be added
|
||||
* as if they were displayed with 72dpi. Set this to <code>false</code>
|
||||
* if images should be generated with the Word default DPI setting.
|
||||
*
|
||||
* @param imagePDFConformance <code>True</code> if PDF equivalence is desired, <code>false</code>
|
||||
* for the default Word display.
|
||||
*/
|
||||
public void SetImagePDFConformance(bool imagePDFConformance) {
|
||||
this.imagePDFConformance = imagePDFConformance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets whether to write scaling information for images.
|
||||
*
|
||||
* @return Whether to write scaling information for images.
|
||||
*/
|
||||
public bool IsWriteImageScalingInformation() {
|
||||
return this.writeImageScalingInformation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether image scaling information should be written. This needs to be set to <code>true</code>
|
||||
* MS Word 2000, MS Word 97 and Word for Mac.
|
||||
*
|
||||
* @param writeImageScalingInformation Whether to write image scaling information.
|
||||
*/
|
||||
public void SetWriteImageScalingInformation(bool writeImageScalingInformation) {
|
||||
this.writeImageScalingInformation = writeImageScalingInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the options required for RTF documents to display correctly in MS Word 2000
|
||||
* and MS Word 97.
|
||||
* Sets <code>outputTableRowDefinitionAfter = true</code> and <code>writeImageScalingInformation = true</code>.
|
||||
*/
|
||||
public void SetOptionsForMSWord2000And97() {
|
||||
this.SetOutputTableRowDefinitionAfter(true);
|
||||
this.SetWriteImageScalingInformation(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the options required for RTF documents to display correctly in MS Word for Mac.
|
||||
* Sets <code>writeImageScalingInformation = true</code>.
|
||||
*/
|
||||
public void SetOptionsForMSWordForMac() {
|
||||
this.SetWriteImageScalingInformation(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the options required for RTF documents to display correctly in MS Word XP (2002).
|
||||
* Sets <code>writeImageScalingInformation = false</code>.
|
||||
*/
|
||||
public void SetOptionsForMSWordXP() {
|
||||
this.SetWriteImageScalingInformation(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the options required for RTF documents to display correctly in OpenOffice.Org
|
||||
* Writer.
|
||||
* Sets <code>outputTableRowDefinitionAfter = false</code>.
|
||||
*/
|
||||
public void SetOptionsForOpenOfficeOrg() {
|
||||
this.SetOutputTableRowDefinitionAfter(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level Document protecton level
|
||||
* @param pwd Document password - clear text
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public bool SetProtection(int level, String pwd) {
|
||||
bool result = false;
|
||||
if (this.protectionHash == null) {
|
||||
if (!SetProtectionLevel(level)) {
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
protectionHash = RtfProtection.GenerateHash(pwd);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.protectionHash.Equals(RtfProtection.GenerateHash(pwd))) {
|
||||
if (!SetProtectionLevel(level)) {
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
protectionHash = RtfProtection.GenerateHash(pwd);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pwd Document password - clear text
|
||||
* @return true if document unprotected, false if protection is not removed.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public bool UnprotectDocument(String pwd) {
|
||||
bool result = false;
|
||||
if (this.protectionHash.Equals(RtfProtection.GenerateHash(pwd))) {
|
||||
this.protectionLevel = RtfProtection.LEVEL_NONE;
|
||||
this.protectionHash = null;
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level Document protection level
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public bool SetProtectionLevel(int level) {
|
||||
bool result = false;
|
||||
switch (level) {
|
||||
case RtfProtection.LEVEL_NONE:
|
||||
if (this.protectionHash == null) {
|
||||
break;
|
||||
}
|
||||
goto case RtfProtection.LEVEL_ANNOTPROT;
|
||||
case RtfProtection.LEVEL_ANNOTPROT:
|
||||
case RtfProtection.LEVEL_FORMPROT:
|
||||
case RtfProtection.LEVEL_REVPROT:
|
||||
case RtfProtection.LEVEL_READPROT:
|
||||
this.protectionLevel = level;
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is not intended for general use. Please see 'public bool SetProtection(int level, String pwd)'
|
||||
* @param pwd Password HASH to set the document password hash to.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public void SetPasswordHash(String pwd) {
|
||||
if (pwd != null && pwd.Length != 8) return;
|
||||
this.protectionHash = pwd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts protection level from internal bitmap value to protlevel output value
|
||||
* @return <pre>
|
||||
* 0 = Revision protection
|
||||
* 1 = Annotation/Comment protection
|
||||
* 2 = Form protection
|
||||
* 3 = Read only protection
|
||||
* </pre>
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private int ConvertProtectionLevel() {
|
||||
int level = 0;
|
||||
switch (this.protectionLevel) {
|
||||
case RtfProtection.LEVEL_NONE:
|
||||
break;
|
||||
case RtfProtection.LEVEL_REVPROT:
|
||||
level = 0;
|
||||
break;
|
||||
case RtfProtection.LEVEL_ANNOTPROT:
|
||||
level = 1;
|
||||
break;
|
||||
case RtfProtection.LEVEL_FORMPROT:
|
||||
level = 2;
|
||||
break;
|
||||
case RtfProtection.LEVEL_READPROT:
|
||||
level = 3;
|
||||
break;
|
||||
}
|
||||
return level;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RTF document protection level
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public int GetProtectionLevelRaw() {
|
||||
return this.protectionLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RTF document protection level
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public int GetProtectionLevel() {
|
||||
return ConvertProtectionLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RTF document protection level as a byte array (byte[])
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public byte[] GetProtectionLevelBytes() {
|
||||
return DocWriter.GetISOBytes(ConvertProtectionLevel().ToString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param oldPwd Old password - clear text
|
||||
* @param newPwd New password - clear text
|
||||
* @return true if password set, false if password not set
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public bool SetNewPassword(String oldPwd, String newPwd) {
|
||||
bool result = false;
|
||||
if (this.protectionHash.Equals(RtfProtection.GenerateHash(oldPwd))) {
|
||||
this.protectionHash = RtfProtection.GenerateHash(newPwd);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the RTF flag that recommends the document be opened in read only mode.
|
||||
* @param value true if the flag is to be set, false if it is NOT to be set
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public void SetReadOnlyRecommended(bool value) {
|
||||
this.readOnlyRecommended = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RTF flag that recommends if the the document should be opened in read only mode.
|
||||
* @return true if flag is set, false if it is not set
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public bool GetReadOnlyRecommended() {
|
||||
return this.readOnlyRecommended;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if document has protection enabled.
|
||||
* @return true if protection is enabled, false if it is not enabled
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public bool IsDocumentProtected() {
|
||||
return !(this.protectionHash == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the password has as a byte array.
|
||||
* @return The bytes of the password hash as a byte array (byte[])
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public byte[] GetProtectionHashBytes() {
|
||||
return DocWriter.GetISOBytes(this.protectionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether images are written as binary data or are hex encoded.
|
||||
*
|
||||
* @param imageWrittenAsBinary <code>True</code> to write images as binary data, <code>false</code> for hex encoding.
|
||||
* @since 2.1.1
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public void SetImageWrittenAsBinary(bool imageWrittenAsBinary) {
|
||||
this.imageWrittenAsBinary = imageWrittenAsBinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether images are written as binary data or are hex encoded. Defaults to <code>true</code>.
|
||||
*
|
||||
* @since 2.1.1
|
||||
* @return <code>True</code> if images are written as binary data, <code>false</code> if hex encoded.
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public bool IsImageWrittenAsBinary() {
|
||||
return this.imageWrittenAsBinary;
|
||||
}
|
||||
}
|
||||
}
|
||||
92
iTechSharp/iTextSharp/text/rtf/document/RtfGenerator.cs
Normal file
92
iTechSharp/iTextSharp/text/rtf/document/RtfGenerator.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfGenerator.cs,v 1.3 2008/05/13 11:25:44 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Howard Shank
|
||||
*
|
||||
* 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.document {
|
||||
/**
|
||||
* The RtfGenerator creates the (\*\generator ...} element.
|
||||
*
|
||||
* @version $Id: RtfGenerator.cs,v 1.3 2008/05/13 11:25:44 psoares33 Exp $
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfGenerator : RtfElement {
|
||||
/**
|
||||
* Generator group starting tag
|
||||
*/
|
||||
private static byte[] GENERATOR = DocWriter.GetISOBytes("\\*\\generator");
|
||||
|
||||
/**
|
||||
* Constructs a <code>RtfGenerator</code> belonging to a RtfDocument
|
||||
*
|
||||
* @param doc The <code>RtfDocument</code> this <code>RtfGenerator</code> belongs to
|
||||
*/
|
||||
public RtfGenerator(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes the RTF generator group.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(GENERATOR, 0, GENERATOR.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
byte[] t;
|
||||
result.Write(t = DocWriter.GetISOBytes(Document.Version), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
168
iTechSharp/iTextSharp/text/rtf/document/RtfInfoElement.cs
Normal file
168
iTechSharp/iTextSharp/text/rtf/document/RtfInfoElement.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfInfoElement.cs,v 1.6 2008/05/16 19:30:51 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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.document {
|
||||
|
||||
/**
|
||||
* Stores one information group element. Valid elements are
|
||||
* author, title, subject, keywords, producer and creationdate.
|
||||
*
|
||||
* @version $Id: RtfInfoElement.cs,v 1.6 2008/05/16 19:30:51 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
*/
|
||||
public class RtfInfoElement : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the author element
|
||||
*/
|
||||
private static byte[] INFO_AUTHOR = DocWriter.GetISOBytes("\\author");
|
||||
/**
|
||||
* Constant for the subject element
|
||||
*/
|
||||
private static byte[] INFO_SUBJECT = DocWriter.GetISOBytes("\\subject");
|
||||
/**
|
||||
* Constant for the keywords element
|
||||
*/
|
||||
private static byte[] INFO_KEYWORDS = DocWriter.GetISOBytes("\\keywords");
|
||||
/**
|
||||
* Constant for the title element
|
||||
*/
|
||||
private static byte[] INFO_TITLE = DocWriter.GetISOBytes("\\title");
|
||||
/**
|
||||
* Constant for the producer element
|
||||
*/
|
||||
private static byte[] INFO_PRODUCER = DocWriter.GetISOBytes("\\operator");
|
||||
/**
|
||||
* Constant for the creationdate element
|
||||
*/
|
||||
private static byte[] INFO_CREATION_DATE = DocWriter.GetISOBytes("\\creationdate");
|
||||
|
||||
/**
|
||||
* The type of this RtfInfoElement. The values from Element.INFO_ELEMENT_NAME are used.
|
||||
*/
|
||||
private int infoType = -1;
|
||||
/**
|
||||
* The content of this RtfInfoElement
|
||||
*/
|
||||
private String content = "";
|
||||
|
||||
/**
|
||||
* Constructs a RtfInfoElement based on the given Meta object
|
||||
*
|
||||
* @param doc The RtfDocument this RtfInfoElement belongs to
|
||||
* @param meta The Meta object this RtfInfoElement is based on
|
||||
*/
|
||||
public RtfInfoElement(RtfDocument doc, Meta meta) : base(doc) {
|
||||
infoType = meta.Type;
|
||||
content = meta.Content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of one RTF information element.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
switch (infoType) {
|
||||
case Element.AUTHOR:
|
||||
result.Write(INFO_AUTHOR, 0, INFO_AUTHOR.Length);
|
||||
break;
|
||||
case Element.SUBJECT:
|
||||
result.Write(INFO_SUBJECT, 0, INFO_SUBJECT.Length);
|
||||
break;
|
||||
case Element.KEYWORDS:
|
||||
result.Write(INFO_KEYWORDS, 0, INFO_KEYWORDS.Length);
|
||||
break;
|
||||
case Element.TITLE:
|
||||
result.Write(INFO_TITLE, 0, INFO_TITLE.Length);
|
||||
break;
|
||||
case Element.PRODUCER:
|
||||
result.Write(INFO_PRODUCER, 0, INFO_PRODUCER.Length);
|
||||
break;
|
||||
case Element.CREATIONDATE:
|
||||
result.Write(INFO_CREATION_DATE, 0, INFO_CREATION_DATE.Length);
|
||||
break;
|
||||
default:
|
||||
result.Write(INFO_AUTHOR, 0, INFO_AUTHOR.Length);
|
||||
break;
|
||||
}
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
byte[] t;
|
||||
if (infoType == Element.CREATIONDATE) {
|
||||
t = DocWriter.GetISOBytes(ConvertDate(content));
|
||||
result.Write(t, 0, t.Length);
|
||||
} else {
|
||||
document.FilterSpecialChar(result, content, false, false);
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date from the format used by iText to the format required by
|
||||
* rtf.<br>iText: EEE MMM dd HH:mm:ss zzz yyyy - rtf: \\'yr'yyyy\\'mo'MM\\'dy'dd\\'hr'HH\\'min'mm\\'sec'ss
|
||||
*
|
||||
* @param date The date formated by iText
|
||||
* @return The date formated for rtf
|
||||
*/
|
||||
private String ConvertDate(String date) {
|
||||
DateTime d;
|
||||
try {
|
||||
d = DateTime.Parse(date);
|
||||
} catch {
|
||||
d = DateTime.Now;
|
||||
}
|
||||
return d.ToString("'\\\\yr'yyyy'\\\\mo'MM'\\\\dy'dd'\\\\hr'HH'\\\\min'mm'\\\\sec'ss");
|
||||
}
|
||||
}
|
||||
}
|
||||
125
iTechSharp/iTextSharp/text/rtf/document/RtfInfoGroup.cs
Normal file
125
iTechSharp/iTextSharp/text/rtf/document/RtfInfoGroup.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfInfoGroup.cs,v 1.6 2008/05/16 19:30:51 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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.document {
|
||||
|
||||
/**
|
||||
* The RtfInfoGroup stores information group elements.
|
||||
*
|
||||
* @version $Id: RtfInfoGroup.cs,v 1.6 2008/05/16 19:30:51 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
*/
|
||||
public class RtfInfoGroup : RtfElement {
|
||||
/**
|
||||
* Information group starting tag
|
||||
*/
|
||||
private static byte[] INFO_GROUP = DocWriter.GetISOBytes("\\info");
|
||||
|
||||
/**
|
||||
* Constant for the password element
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] INFO_PASSWORD = DocWriter.GetISOBytes("\\*\\password");
|
||||
|
||||
/**
|
||||
* The RtfInfoElements that belong to this RtfInfoGroup
|
||||
*/
|
||||
ArrayList infoElements = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfInfoGroup belonging to a RtfDocument
|
||||
*
|
||||
* @param doc The RtfDocument this RtfInfoGroup belongs to
|
||||
*/
|
||||
public RtfInfoGroup(RtfDocument doc) : base(doc) {
|
||||
infoElements = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an RtfInfoElement to the RtfInfoGroup
|
||||
*
|
||||
* @param infoElement The RtfInfoElement to add
|
||||
*/
|
||||
public void Add(RtfInfoElement infoElement) {
|
||||
this.infoElements.Add(infoElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the RTF information group and its elements.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(INFO_GROUP, 0, INFO_GROUP.Length);
|
||||
for (int i = 0; i < infoElements.Count; i++) {
|
||||
RtfInfoElement infoElement = (RtfInfoElement) infoElements[i];
|
||||
infoElement.WriteContent(result);
|
||||
}
|
||||
|
||||
// handle document protection
|
||||
if (document.GetDocumentSettings().IsDocumentProtected()) {
|
||||
byte[] t;
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(INFO_PASSWORD, 0, INFO_PASSWORD.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(t = document.GetDocumentSettings().GetProtectionHashBytes(), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
425
iTechSharp/iTextSharp/text/rtf/document/RtfPageSetting.cs
Normal file
425
iTechSharp/iTextSharp/text/rtf/document/RtfPageSetting.cs
Normal file
@@ -0,0 +1,425 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfPageSetting.cs,v 1.5 2008/05/16 19:30:51 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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.document {
|
||||
|
||||
/**
|
||||
* The RtfPageSetting stores the page size / page margins for a RtfDocument.
|
||||
* INTERNAL CLASS - NOT TO BE USED DIRECTLY
|
||||
*
|
||||
* @version $Id: RtfPageSetting.cs,v 1.5 2008/05/16 19:30:51 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
*/
|
||||
public class RtfPageSetting : RtfElement, IRtfExtendedElement {
|
||||
|
||||
/**
|
||||
* Constant for the page height
|
||||
*/
|
||||
private static byte[] PAGE_WIDTH = DocWriter.GetISOBytes("\\paperw");
|
||||
/**
|
||||
* Constant for the page width
|
||||
*/
|
||||
private static byte[] PAGE_HEIGHT = DocWriter.GetISOBytes("\\paperh");
|
||||
/**
|
||||
* Constant for the left margin
|
||||
*/
|
||||
private static byte[] MARGIN_LEFT = DocWriter.GetISOBytes("\\margl");
|
||||
/**
|
||||
* Constant for the right margin
|
||||
*/
|
||||
private static byte[] MARGIN_RIGHT = DocWriter.GetISOBytes("\\margr");
|
||||
/**
|
||||
* Constant for the top margin
|
||||
*/
|
||||
private static byte[] MARGIN_TOP = DocWriter.GetISOBytes("\\margt");
|
||||
/**
|
||||
* Constant for the bottom margin
|
||||
*/
|
||||
private static byte[] MARGIN_BOTTOM = DocWriter.GetISOBytes("\\margb");
|
||||
/**
|
||||
* Constant for landscape
|
||||
*/
|
||||
private static byte[] LANDSCAPE = DocWriter.GetISOBytes("\\lndscpsxn");
|
||||
/**
|
||||
* Constant for the section page width
|
||||
*/
|
||||
private static byte[] SECTION_PAGE_WIDTH = DocWriter.GetISOBytes("\\pgwsxn");
|
||||
/**
|
||||
* Constant for the section page height
|
||||
*/
|
||||
private static byte[] SECTION_PAGE_HEIGHT = DocWriter.GetISOBytes("\\pghsxn");
|
||||
/**
|
||||
* Constant for the section left margin
|
||||
*/
|
||||
private static byte[] SECTION_MARGIN_LEFT = DocWriter.GetISOBytes("\\marglsxn");
|
||||
/**
|
||||
* Constant for the section right margin
|
||||
*/
|
||||
private static byte[] SECTION_MARGIN_RIGHT = DocWriter.GetISOBytes("\\margrsxn");
|
||||
/**
|
||||
* Constant for the section top margin
|
||||
*/
|
||||
private static byte[] SECTION_MARGIN_TOP = DocWriter.GetISOBytes("\\margtsxn");
|
||||
/**
|
||||
* Constant for the section bottom margin
|
||||
*/
|
||||
private static byte[] SECTION_MARGIN_BOTTOM = DocWriter.GetISOBytes("\\margbsxn");
|
||||
|
||||
/**
|
||||
* The page width to use
|
||||
*/
|
||||
private int pageWidth = 11906;
|
||||
/**
|
||||
* The page height to use
|
||||
*/
|
||||
private int pageHeight = 16840;
|
||||
/**
|
||||
* The left margin to use
|
||||
*/
|
||||
private int marginLeft = 1800;
|
||||
/**
|
||||
* The right margin to use
|
||||
*/
|
||||
private int marginRight = 1800;
|
||||
/**
|
||||
* The top margin to use
|
||||
*/
|
||||
private int marginTop = 1440;
|
||||
/**
|
||||
* The bottom margin to use
|
||||
*/
|
||||
private int marginBottom = 1440;
|
||||
/**
|
||||
* Whether the page is portrait or landscape
|
||||
*/
|
||||
private bool landscape = false;
|
||||
|
||||
/**
|
||||
* Constructs a new RtfPageSetting object belonging to a RtfDocument.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPageSetting belongs to
|
||||
*/
|
||||
public RtfPageSetting(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* unused
|
||||
*/
|
||||
public override void WriteContent(Stream outp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the page size / page margin definition
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(PAGE_WIDTH, 0, PAGE_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(pageWidth), 0, t.Length);
|
||||
result.Write(PAGE_HEIGHT, 0, PAGE_HEIGHT.Length);
|
||||
result.Write(t = IntToByteArray(pageHeight), 0, t.Length);
|
||||
result.Write(MARGIN_LEFT, 0, MARGIN_LEFT.Length);
|
||||
result.Write(t = IntToByteArray(marginLeft), 0, t.Length);
|
||||
result.Write(MARGIN_RIGHT, 0, MARGIN_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray(marginRight), 0, t.Length);
|
||||
result.Write(MARGIN_TOP, 0, MARGIN_TOP.Length);
|
||||
result.Write(t = IntToByteArray(marginTop), 0, t.Length);
|
||||
result.Write(MARGIN_BOTTOM, 0, MARGIN_BOTTOM.Length);
|
||||
result.Write(t = IntToByteArray(marginBottom), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the definition part for a new section
|
||||
*
|
||||
* @return A byte array containing the definition for a new section
|
||||
*/
|
||||
public void WriteSectionDefinition(Stream result) {
|
||||
byte[] t;
|
||||
if (landscape) {
|
||||
result.Write(LANDSCAPE, 0, LANDSCAPE.Length);
|
||||
result.Write(SECTION_PAGE_WIDTH, 0, SECTION_PAGE_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(pageWidth), 0, t.Length);
|
||||
result.Write(SECTION_PAGE_HEIGHT, 0, SECTION_PAGE_HEIGHT.Length);
|
||||
result.Write(t = IntToByteArray(pageHeight), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
} else {
|
||||
result.Write(SECTION_PAGE_WIDTH, 0, SECTION_PAGE_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(pageWidth), 0, t.Length);
|
||||
result.Write(SECTION_PAGE_HEIGHT, 0, SECTION_PAGE_HEIGHT.Length);
|
||||
result.Write(t = IntToByteArray(pageHeight), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
result.Write(SECTION_MARGIN_LEFT, 0, SECTION_MARGIN_LEFT.Length);
|
||||
result.Write(t = IntToByteArray(marginLeft), 0, t.Length);
|
||||
result.Write(SECTION_MARGIN_RIGHT, 0, SECTION_MARGIN_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray(marginRight), 0, t.Length);
|
||||
result.Write(SECTION_MARGIN_TOP, 0, SECTION_MARGIN_TOP.Length);
|
||||
result.Write(t = IntToByteArray(marginTop), 0, t.Length);
|
||||
result.Write(SECTION_MARGIN_BOTTOM, 0, SECTION_MARGIN_BOTTOM.Length);
|
||||
result.Write(t = IntToByteArray(marginBottom), 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bottom margin
|
||||
*
|
||||
* @return Returns the bottom margin
|
||||
*/
|
||||
public int GetMarginBottom() {
|
||||
return marginBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bottom margin
|
||||
*
|
||||
* @param marginBottom The bottom margin to use
|
||||
*/
|
||||
public void SetMarginBottom(int marginBottom) {
|
||||
this.marginBottom = marginBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the left margin
|
||||
*
|
||||
* @return Returns the left margin
|
||||
*/
|
||||
public int GetMarginLeft() {
|
||||
return marginLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left margin to use
|
||||
*
|
||||
* @param marginLeft The left margin to use
|
||||
*/
|
||||
public void SetMarginLeft(int marginLeft) {
|
||||
this.marginLeft = marginLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the right margin
|
||||
*
|
||||
* @return Returns the right margin
|
||||
*/
|
||||
public int GetMarginRight() {
|
||||
return marginRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right margin to use
|
||||
*
|
||||
* @param marginRight The right margin to use
|
||||
*/
|
||||
public void SetMarginRight(int marginRight) {
|
||||
this.marginRight = marginRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top margin
|
||||
*
|
||||
* @return Returns the top margin
|
||||
*/
|
||||
public int GetMarginTop() {
|
||||
return marginTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the top margin to use
|
||||
*
|
||||
* @param marginTop The top margin to use
|
||||
*/
|
||||
public void SetMarginTop(int marginTop) {
|
||||
this.marginTop = marginTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page height
|
||||
*
|
||||
* @return Returns the page height
|
||||
*/
|
||||
public int GetPageHeight() {
|
||||
return pageHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page height to use
|
||||
*
|
||||
* @param pageHeight The page height to use
|
||||
*/
|
||||
public void SetPageHeight(int pageHeight) {
|
||||
this.pageHeight = pageHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page width
|
||||
*
|
||||
* @return Returns the page width
|
||||
*/
|
||||
public int GetPageWidth() {
|
||||
return pageWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the page width to use
|
||||
*
|
||||
* @param pageWidth The page width to use
|
||||
*/
|
||||
public void SetPageWidth(int pageWidth) {
|
||||
this.pageWidth = pageWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the page size to use. This method will use guessFormat to try to guess the correct
|
||||
* page format. If no format could be guessed, the sizes from the pageSize are used and
|
||||
* the landscape setting is determined by comparing width and height;
|
||||
*
|
||||
* @param pageSize The pageSize to use
|
||||
*/
|
||||
public void SetPageSize(Rectangle pageSize) {
|
||||
if (!GuessFormat(pageSize, false)) {
|
||||
this.pageWidth = (int) (pageSize.Width * TWIPS_FACTOR);
|
||||
this.pageHeight = (int) (pageSize.Height * TWIPS_FACTOR);
|
||||
this.landscape = pageWidth > pageHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tries to fit the <code>Rectangle pageSize</code> to one of the predefined PageSize rectangles.
|
||||
* If a match is found the pageWidth and pageHeight will be set according to values determined from files
|
||||
* generated by MS Word2000 and OpenOffice 641. If no match is found the method will try to match the rotated
|
||||
* Rectangle by calling itself with the parameter rotate set to true.
|
||||
*
|
||||
* @param pageSize the page size for which to guess the correct format
|
||||
* @param rotate Whether we should try to rotate the size befor guessing the format
|
||||
* @return <code>True</code> if the format was guessed, <code>false/<code> otherwise
|
||||
*/
|
||||
private bool GuessFormat(Rectangle pageSize, bool rotate) {
|
||||
if (rotate) {
|
||||
pageSize = pageSize.Rotate();
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.A3)) {
|
||||
pageWidth = 16837;
|
||||
pageHeight = 23811;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.A4)) {
|
||||
pageWidth = 11907;
|
||||
pageHeight = 16840;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.A5)) {
|
||||
pageWidth = 8391;
|
||||
pageHeight = 11907;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.A6)) {
|
||||
pageWidth = 5959;
|
||||
pageHeight = 8420;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.B4)) {
|
||||
pageWidth = 14570;
|
||||
pageHeight = 20636;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.B5)) {
|
||||
pageWidth = 10319;
|
||||
pageHeight = 14572;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.HALFLETTER)) {
|
||||
pageWidth = 7927;
|
||||
pageHeight = 12247;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.LETTER)) {
|
||||
pageWidth = 12242;
|
||||
pageHeight = 15842;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (RectEquals(pageSize, PageSize.LEGAL)) {
|
||||
pageWidth = 12252;
|
||||
pageHeight = 20163;
|
||||
landscape = rotate;
|
||||
return true;
|
||||
}
|
||||
if (!rotate && GuessFormat(pageSize, true)) {
|
||||
int x = pageWidth;
|
||||
pageWidth = pageHeight;
|
||||
pageHeight = x;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method compares to Rectangles. They are considered equal if width and height are the same
|
||||
*
|
||||
* @param rect1 The first Rectangle to compare
|
||||
* @param rect2 The second Rectangle to compare
|
||||
* @return <code>True</code> if the Rectangles equal, <code>false</code> otherwise
|
||||
*/
|
||||
private static bool RectEquals(Rectangle rect1, Rectangle rect2) {
|
||||
return (rect1.Width == rect2.Width) && (rect1.Height == rect2.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
273
iTechSharp/iTextSharp/text/rtf/document/RtfProtection.cs
Normal file
273
iTechSharp/iTextSharp/text/rtf/document/RtfProtection.cs
Normal file
@@ -0,0 +1,273 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: RtfProtection.cs,v 1.2 2008/05/13 11:25:50 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2008 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.document {
|
||||
|
||||
/**
|
||||
* <code>RtfProtection</code>
|
||||
* <pre>
|
||||
* See ECMA Specification for WordprocessingML documentProtection element.
|
||||
*
|
||||
* <strong>Reference:</strong>
|
||||
* Standard ECMA-376 1st Edition / December 2006
|
||||
* Office Open XML File Formats
|
||||
* </pre>
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public sealed class RtfProtection {
|
||||
/**
|
||||
* Default for protection level.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int LEVEL_NONE = 0x0000;
|
||||
/**
|
||||
* REVPROT
|
||||
* Mutually exclusive
|
||||
* This document is protected for revisions. The user can edit the document,
|
||||
* but revision marking cannot be disabled.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int LEVEL_REVPROT = 0x0001; // protlevel0
|
||||
/**
|
||||
* ANNNOTPROT
|
||||
* Mutually exclusive
|
||||
* This document is protected for comments (annotations).
|
||||
* The user cannot edit the document but can insert comments (annotations).
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int LEVEL_ANNOTPROT = 0x0002; // protlevel1
|
||||
/**
|
||||
* FORMPROT
|
||||
* Mutually exclusive
|
||||
* Document is protected for forms.
|
||||
* see also \allprot (forms controlword)
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int LEVEL_FORMPROT = 0x0004; // protlevel2
|
||||
/**
|
||||
* READPROT
|
||||
* Mutually exclusive but can be combined with ANNOTPROT for backward compatibility
|
||||
* Document is protected for editing, except areas marked as exceptions by \protstart and\protend
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int LEVEL_READPROT = 0x0008; // protlevel3
|
||||
|
||||
|
||||
/**
|
||||
* STYLELOCK
|
||||
*
|
||||
* The document contains styles and formatting restrictions.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int STYLELOCK = 0x0001;
|
||||
/**
|
||||
* STYLELOCKENFORCED
|
||||
*
|
||||
* The styles and formatting restrictions are being enforced.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int STYLELOCKENFORCED = 0x0002;
|
||||
/**
|
||||
* STYLELOCKBACKCOMP
|
||||
*
|
||||
* Style lockdown backward compatibility flag, indicating we emitted protection
|
||||
* keywords to get documents with styles and formatting restrictions to behave
|
||||
* in a reasonable way when opened by older versions.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int STYLELOCKBACKCOMP = 0x0004;
|
||||
/**
|
||||
* STYLELOCKBACKCOMP
|
||||
*
|
||||
* Allow AutoFormat to override styles and formatting restrictions. When style
|
||||
* protection is on, the user cannot add direct formatting. This setting allows
|
||||
* AutoFormat actions to apply direct formatting when needed.
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public const int AUTOFMTOVERRIDE = 0x0008;
|
||||
|
||||
|
||||
/**
|
||||
* <code>initialCodeArray</code> Table from ECMA-376 Specification
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static int[] initialCodeArray = {
|
||||
0xE1F0,
|
||||
0x1D0F,
|
||||
0xCC9C,
|
||||
0x84C0,
|
||||
0x110C,
|
||||
0x0E10,
|
||||
0xF1CE,
|
||||
0x313E,
|
||||
0x1872,
|
||||
0xE139,
|
||||
0xD40F,
|
||||
0x84F9,
|
||||
0x280C,
|
||||
0xA96A,
|
||||
0x4EC3
|
||||
};
|
||||
|
||||
/**
|
||||
* <code>encryptionMatrix</code> Table from ECMA-376 Specification
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static int[][] encryptionMatrix = {
|
||||
/* bit1 bit2 bit3 bit4 bit5 bit6 bit7 **bit8 is ignored** */
|
||||
/* char 1 */ new int[]{0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4},
|
||||
/* char 2 */ new int[]{0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC},
|
||||
/* char 3 */ new int[]{0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD},
|
||||
/* char 4 */ new int[]{0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C},
|
||||
/* char 5 */ new int[]{0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168},
|
||||
/* char 6 */ new int[]{0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10},
|
||||
/* char 7 */ new int[]{0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC},
|
||||
/* char 8 */ new int[]{0x47D3, 0x8FA6, 0x0F6D, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0},
|
||||
/* char 9 */ new int[]{0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9},
|
||||
/* char 10 */ new int[]{0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A},
|
||||
/* char 11 */ new int[]{0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5},
|
||||
/* char 12 */ new int[]{0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40},
|
||||
/* char 13 */ new int[]{0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0},
|
||||
/* char 14 */ new int[]{0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF},
|
||||
/* char 15 */ new int[]{0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09}
|
||||
};
|
||||
|
||||
/**
|
||||
* <code>generateHash</code> generates the password hash from a clear text string.
|
||||
*
|
||||
* @param pwd Clear text string input
|
||||
* @return hex encoded password hash
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public static String GenerateHash(String pwd) {
|
||||
String encryptedPwd="00000000";
|
||||
String password = pwd;
|
||||
|
||||
// if there is no password or the length is 0, then skip this and return "00000000" as default
|
||||
// otherwise process the password
|
||||
if (password != null && password.Length > 0) {
|
||||
int hi=0;
|
||||
int lo=0;
|
||||
|
||||
// Truncate the password to 15 characters.
|
||||
if (password.Length > 15) {
|
||||
password = password.Substring(0,15);
|
||||
}
|
||||
|
||||
// compute key's high-order word
|
||||
// initialize to table value
|
||||
hi = initialCodeArray[password.Length-1];
|
||||
|
||||
int fidx = 0;
|
||||
int idxR = password.Length-1;
|
||||
// process each character left to right.
|
||||
// check each bit and if it is set, xor the hi word with
|
||||
// the table entry for the position in password and bit position.
|
||||
for (; fidx<password.Length; fidx++,idxR--) {
|
||||
int ch = password[fidx];
|
||||
if ((ch & 0x0001)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][0];
|
||||
}
|
||||
if ((ch & 0x0002)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][1];
|
||||
}
|
||||
if ((ch & 0x0004)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][2];
|
||||
}
|
||||
if ((ch & 0x0008)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][3];
|
||||
}
|
||||
if ((ch & 0x0010)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][4];
|
||||
}
|
||||
if ((ch & 0x0020)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][5];
|
||||
}
|
||||
if ((ch & 0x0040)!= 0) {
|
||||
hi = hi ^ encryptionMatrix[idxR][6];
|
||||
}
|
||||
}
|
||||
// Compute Key's low-order word
|
||||
fidx = password.Length-1;
|
||||
lo = 0;
|
||||
// low order word is computed in reverse.
|
||||
for (;fidx>= 0; fidx--) {
|
||||
int ch = password[fidx];
|
||||
lo = (((lo >> 14) & 0x001) | (( lo << 1) & 0x7fff)) ^ ch;
|
||||
}
|
||||
// finally incorporate the password length into the low word and use value from formula
|
||||
lo = (((lo >> 14) & 0x001) | (( lo << 1) & 0x7fff)) ^ password.Length ^ 0xCE4B;
|
||||
|
||||
// correct for little-endian -
|
||||
// Java always uses big-endian. According to tests - RTF wants little-endian but is not documented
|
||||
string s = lo.ToString("x8");
|
||||
encryptedPwd = s.Substring(6,2) + s.Substring(4,2);
|
||||
s = hi.ToString("x8");
|
||||
encryptedPwd += s.Substring(6,2) + s.Substring(4,2);
|
||||
}
|
||||
return encryptedPwd;
|
||||
}
|
||||
}
|
||||
}
|
||||
182
iTechSharp/iTextSharp/text/rtf/document/RtfProtectionSetting.cs
Normal file
182
iTechSharp/iTextSharp/text/rtf/document/RtfProtectionSetting.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: RtfProtectionSetting.cs,v 1.2 2008/05/13 11:25:50 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2008 by Howard Shank
|
||||
*
|
||||
* 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.document {
|
||||
|
||||
/**
|
||||
* The RtfProtectionSetting handles document protection elements
|
||||
*
|
||||
* @version $Id: RtfProtectionSetting.cs,v 1.2 2008/05/13 11:25:50 psoares33 Exp $
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.1.1
|
||||
*/
|
||||
public class RtfProtectionSetting : RtfElement {
|
||||
/**
|
||||
* Constant for Form protection controlword
|
||||
* Mutually exclusive
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#REVPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#ANNOTPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#READPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] FORMPROT = DocWriter.GetISOBytes("\\formprot");
|
||||
/**
|
||||
* Constant for Revision protection controlword
|
||||
* Mutually exclusive
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#FORMPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#ANNOTPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#READPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] REVPROT = DocWriter.GetISOBytes("\\revprot");
|
||||
/**
|
||||
* Constant for Annotation/Comment protection controlword
|
||||
* Mutually exclusive
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#FORMPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#REVPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#READPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] ANNOTPROT = DocWriter.GetISOBytes("\\annotprot");
|
||||
/**
|
||||
* Constant for read only rotection controlword
|
||||
* Mutually exclusive - exception, can be combined with ANNOTPROT
|
||||
* for backwards compatibility
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#FORMPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#REVPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @see com.lowagie.text.rtf.document.RtfProtectionSetting#ANNOTPROT(com.lowagie.text.rtf.document.RtfProtectionSetting)
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] READPROT = DocWriter.GetISOBytes("\\readprot");
|
||||
|
||||
/**
|
||||
* Constant for protlevel controlword
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] PROTLEVEL = DocWriter.GetISOBytes("\\protlevel");
|
||||
/**
|
||||
* Constant for enforceprot controlword
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] ENFORCEPROT = DocWriter.GetISOBytes("\\enforceprot");
|
||||
|
||||
/**
|
||||
* Constant for enforceprot controlword.
|
||||
* Implemented in Microsoft Word 2007.
|
||||
*
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
private static byte[] READONLYRECOMMENDED = DocWriter.GetISOBytes("\\readonlyrecommended");
|
||||
|
||||
/**
|
||||
* Constructs a <code>RtfProtectionSetting</code> belonging to a RtfDocument
|
||||
*
|
||||
* @param doc The <code>RtfDocument</code> this <code>RtfProtectionSetting</code> belongs to
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public RtfProtectionSetting(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the RTF protection control words
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the RTF protection control words
|
||||
* @since 2.1.1
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
if (document.GetDocumentSettings().IsDocumentProtected()) {
|
||||
switch (document.GetDocumentSettings().GetProtectionLevelRaw()) {
|
||||
case RtfProtection.LEVEL_FORMPROT:
|
||||
result.Write(FORMPROT, 0, FORMPROT.Length);
|
||||
break;
|
||||
case RtfProtection.LEVEL_ANNOTPROT:
|
||||
result.Write(ANNOTPROT, 0, ANNOTPROT.Length);
|
||||
break;
|
||||
case RtfProtection.LEVEL_REVPROT:
|
||||
result.Write(REVPROT, 0, REVPROT.Length);
|
||||
break;
|
||||
case RtfProtection.LEVEL_READPROT:
|
||||
result.Write(ANNOTPROT, 0, ANNOTPROT.Length);
|
||||
result.Write(READPROT, 0, READPROT.Length);
|
||||
break;
|
||||
}
|
||||
result.Write(ENFORCEPROT, 0, ENFORCEPROT.Length); // assumes one of the above protection keywords was output.
|
||||
result.WriteByte((byte)'1');
|
||||
result.Write(PROTLEVEL, 0, PROTLEVEL.Length);
|
||||
byte[] t;
|
||||
result.Write(t = document.GetDocumentSettings().GetProtectionLevelBytes(), 0, t.Length);
|
||||
}
|
||||
|
||||
if (document.GetDocumentSettings().GetReadOnlyRecommended()) {
|
||||
result.Write(READONLYRECOMMENDED, 0, READONLYRECOMMENDED.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* $Id: IRtfDataCache.cs,v 1.4 2008/05/16 19:30:53 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.document.output {
|
||||
|
||||
/**
|
||||
* The RtfDataCache interface must be implemented by classes wishing to
|
||||
* act as caches for the rtf document data.
|
||||
*
|
||||
* @version $Revision: 1.4 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public interface IRtfDataCache {
|
||||
/**
|
||||
* Get the OutputStream that the RtfDocument can write to.
|
||||
*
|
||||
* @return The OutputStream the RtfDocument can use.
|
||||
*/
|
||||
Stream GetOutputStream();
|
||||
/**
|
||||
* Write the content of the cache into the OutputStream.
|
||||
*
|
||||
* @param target The OutputStream to write the content into.
|
||||
* @throws IOException If an error occurs reading/writing.
|
||||
*/
|
||||
void WriteTo(Stream target);
|
||||
}
|
||||
|
||||
public class RtfDataCache {
|
||||
/**
|
||||
* Constant for caching efficently into memory.
|
||||
*/
|
||||
public const int CACHE_MEMORY_EFFICIENT = 3;
|
||||
/**
|
||||
* Constant for caching into memory.
|
||||
*/
|
||||
public const int CACHE_MEMORY = 2;
|
||||
/**
|
||||
* Constant for caching to the disk.
|
||||
*/
|
||||
public const int CACHE_DISK = 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
/*
|
||||
* Copyright 2007 Thomas Bickel
|
||||
*
|
||||
* 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.document.output {
|
||||
|
||||
public class RtfByteArrayBuffer : Stream {
|
||||
private ArrayList arrays = new ArrayList();
|
||||
private byte[] buffer;
|
||||
private int pos = 0;
|
||||
private int size = 0;
|
||||
|
||||
public RtfByteArrayBuffer() : this(256) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new buffer with the given initial size.
|
||||
*
|
||||
* @param bufferSize desired initial size in bytes
|
||||
*/
|
||||
public RtfByteArrayBuffer(int bufferSize) {
|
||||
if ((bufferSize <= 0) || (bufferSize > 1<<30)) throw(new ArgumentException("bufferSize "+bufferSize));
|
||||
|
||||
int n = 1<<5;
|
||||
while(n < bufferSize) {
|
||||
n <<= 1;
|
||||
}
|
||||
buffer = new byte[n];
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close() {
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] src, int off, int len) {
|
||||
if(src == null) throw(new ArgumentNullException());
|
||||
if((off < 0) || (off > src.Length) || (len < 0) || ((off + len) > src.Length) || ((off + len) < 0)) throw new IndexOutOfRangeException();
|
||||
|
||||
WriteLoop(src, off, len);
|
||||
}
|
||||
|
||||
private void WriteLoop(byte[] src, int off, int len) {
|
||||
while(len > 0) {
|
||||
int room = buffer.Length - pos;
|
||||
int n = len > room ? room : len;
|
||||
System.Array.Copy(src, off, buffer, pos, n);
|
||||
len -= n;
|
||||
off += n;
|
||||
pos += n;
|
||||
size += n;
|
||||
if(pos == buffer.Length) FlushBuffer(len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes all bytes available in the given inputstream to this buffer.
|
||||
*
|
||||
* @param in
|
||||
* @return number of bytes written
|
||||
* @throws IOException
|
||||
*/
|
||||
public long Write(Stream inp) {
|
||||
if (inp == null) throw(new ArgumentNullException());
|
||||
long sizeStart = size;
|
||||
while (true) {
|
||||
int n = inp.Read(buffer, pos, buffer.Length - pos);
|
||||
if (n <= 0) break;
|
||||
pos += n;
|
||||
size += n;
|
||||
if(pos == buffer.Length) FlushBuffer();
|
||||
}
|
||||
return(size - sizeStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the given array to this buffer without copying (if possible).
|
||||
*
|
||||
* @param a
|
||||
*/
|
||||
public void Append(byte[] a) {
|
||||
if(a == null) throw(new ArgumentNullException());
|
||||
if(a.Length == 0) return;
|
||||
|
||||
if(a.Length <= 8) {
|
||||
Write(a, 0, a.Length);
|
||||
} else if((a.Length <= 16) && (pos > 0) && ((buffer.Length - pos) > a.Length)) {
|
||||
Write(a, 0, a.Length);
|
||||
} else {
|
||||
FlushBuffer();
|
||||
arrays.Add(a);
|
||||
size += a.Length;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Appends all arrays to this buffer without copying (if possible).
|
||||
*
|
||||
* @param a
|
||||
*/
|
||||
public void Append(byte[][] a) {
|
||||
if(a == null) throw(new ArgumentNullException());
|
||||
|
||||
for(int k = 0; k < a.Length; k++) {
|
||||
Append(a[k]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal list of byte array buffers without copying the buffer contents.
|
||||
*
|
||||
* @return an byte aray of buffers
|
||||
*/
|
||||
public byte[][] ToArrayArray()
|
||||
{
|
||||
FlushBuffer();
|
||||
byte[][] a = new byte[arrays.Count][];
|
||||
arrays.CopyTo(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new array and copies all data that has been written to this buffer to the newly allocated array.
|
||||
*
|
||||
* @return a new byte array
|
||||
*/
|
||||
public byte[] ToArray()
|
||||
{
|
||||
byte[] r = new byte[size];
|
||||
int off = 0;
|
||||
int n = arrays.Count;
|
||||
for(int k = 0; k < n; k++) {
|
||||
byte[] src = (byte[])arrays[k];
|
||||
System.Array.Copy(src, 0, r, off, src.Length);
|
||||
off += src.Length;
|
||||
}
|
||||
if(pos > 0) System.Array.Copy(buffer, 0, r, off, pos);
|
||||
return(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes all data that has been written to this buffer to the given output stream.
|
||||
*
|
||||
* @param out
|
||||
* @throws IOException
|
||||
*/
|
||||
public void WriteTo(Stream outp) {
|
||||
if(outp == null) throw(new ArgumentNullException());
|
||||
|
||||
int n = arrays.Count;
|
||||
for(int k = 0; k < n; k++) {
|
||||
byte[] src = (byte[])arrays[k];
|
||||
outp.Write(src, 0, src.Length);
|
||||
}
|
||||
if(pos > 0) outp.Write(buffer, 0, pos);
|
||||
}
|
||||
|
||||
public override void WriteByte(byte value) {
|
||||
buffer[pos] = value;
|
||||
size++;
|
||||
if(++pos == buffer.Length) FlushBuffer();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return("RtfByteArrayBuffer: size="+Size()+" #arrays="+arrays.Count+" pos="+pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this buffer.
|
||||
*/
|
||||
public void Reset() {
|
||||
arrays.Clear();
|
||||
pos = 0;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that have been written to this buffer so far.
|
||||
*
|
||||
* @return number of bytes written to this buffer
|
||||
*/
|
||||
public long Size() {
|
||||
return(size);
|
||||
}
|
||||
|
||||
private void FlushBuffer() {
|
||||
FlushBuffer(1);
|
||||
}
|
||||
|
||||
private void FlushBuffer(int reqSize) {
|
||||
if(reqSize < 0) throw(new ArgumentException());
|
||||
|
||||
if(pos == 0) return;
|
||||
|
||||
if(pos == buffer.Length) {
|
||||
//add old buffer, alloc new (possibly larger) buffer
|
||||
arrays.Add(buffer);
|
||||
int newSize = buffer.Length;
|
||||
buffer = null;
|
||||
int MAX = Math.Max(1, size>>24) << 16;
|
||||
while(newSize < MAX) {
|
||||
newSize <<= 1;
|
||||
if(newSize >= reqSize) break;
|
||||
}
|
||||
buffer = new byte[newSize];
|
||||
} else {
|
||||
//copy buffer contents to newly allocated buffer
|
||||
byte[] c = new byte[pos];
|
||||
System.Array.Copy(buffer, 0, c, 0, pos);
|
||||
arrays.Add(c);
|
||||
}
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
107
iTechSharp/iTextSharp/text/rtf/document/output/RtfDiskCache.cs
Normal file
107
iTechSharp/iTextSharp/text/rtf/document/output/RtfDiskCache.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* $Id: RtfDiskCache.cs,v 1.3 2008/05/16 19:30:53 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.document.output {
|
||||
|
||||
/**
|
||||
* The RtfFileCache is a RtfDataCache that uses a temporary file
|
||||
* to store the rtf document data. Not so fast, but doesn't use any
|
||||
* memory (just disk space).
|
||||
*
|
||||
* @version $Revision: 1.3 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfDiskCache : IRtfDataCache {
|
||||
|
||||
/**
|
||||
* The BufferedOutputStream that stores the cache data.
|
||||
*/
|
||||
private BufferedStream data = null;
|
||||
/**
|
||||
* The temporary file to store the data in.
|
||||
*/
|
||||
private string tempFile = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfFileCache. Creates the temp file.
|
||||
*
|
||||
* @throws IOException If the temporary file could not be created.
|
||||
*/
|
||||
public RtfDiskCache() {
|
||||
this.tempFile = Path.GetTempFileName();
|
||||
this.data = new BufferedStream(new FileStream(tempFile, FileMode.Create));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BufferedOutputStream to write to.
|
||||
*/
|
||||
public Stream GetOutputStream() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the temporary file into the Stream.
|
||||
*/
|
||||
public void WriteTo(Stream target) {
|
||||
this.data.Close();
|
||||
BufferedStream tempIn = new BufferedStream(new FileStream(this.tempFile, FileMode.Open));
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead = -1;
|
||||
while ((bytesRead = tempIn.Read(buffer, 0, buffer.Length)) > 0) {
|
||||
target.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
tempIn.Close();
|
||||
File.Delete(this.tempFile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* Copyright 2007 by Thomas Bickel
|
||||
*
|
||||
* 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.document.output {
|
||||
/**
|
||||
* The RtfEfficientMemoryCache is an RtfDataCache that keeps the whole rtf document
|
||||
* data in memory.
|
||||
* More efficient than {@link RtfMemoryCache}.
|
||||
*
|
||||
* @version $Id: RtfEfficientMemoryCache.cs,v 1.1 2007/05/26 20:44:49 psoares33 Exp $
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
*/
|
||||
public class RtfEfficientMemoryCache : IRtfDataCache {
|
||||
/**
|
||||
* The buffer for the rtf document data.
|
||||
*/
|
||||
private RtfByteArrayBuffer bab;
|
||||
|
||||
/**
|
||||
* Constructs a RtfMemoryCache.
|
||||
*/
|
||||
public RtfEfficientMemoryCache() {
|
||||
bab = new RtfByteArrayBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the OutputStream.
|
||||
*/
|
||||
public virtual Stream GetOutputStream() {
|
||||
return(bab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the buffer into the OutputStream.
|
||||
*/
|
||||
public virtual void WriteTo(Stream target) {
|
||||
bab.WriteTo(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* $Id: RtfMemoryCache.cs,v 1.3 2008/05/16 19:30:53 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.document.output {
|
||||
|
||||
/**
|
||||
* The RtfMemoryCache is an RtfDataCache that keeps the whole rtf document
|
||||
* data in memory. Fast but memory intensive.
|
||||
*
|
||||
* @version $Revision: 1.3 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfMemoryCache : IRtfDataCache {
|
||||
|
||||
/**
|
||||
* The buffer for the rtf document data.
|
||||
*/
|
||||
private MemoryStream data = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfMemoryCache.
|
||||
*/
|
||||
public RtfMemoryCache() {
|
||||
this.data = new MemoryStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MemoryStream.
|
||||
*/
|
||||
public Stream GetOutputStream() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the MemoryStream into the Stream.
|
||||
*/
|
||||
public void WriteTo(Stream target) {
|
||||
this.data.WriteTo(target);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
/*
|
||||
* Copyright 2007 Thomas Bickel
|
||||
*
|
||||
* 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.document.output {
|
||||
|
||||
/**
|
||||
* The RtfNilOutputStream is a dummy output stream that sends all
|
||||
* bytes to the big byte bucket in the sky. It is used to improve
|
||||
* speed in those situations where processing is required, but
|
||||
* the results are not needed.
|
||||
*
|
||||
* @version $Id: RtfNilOutputStream.cs,v 1.2 2008/05/16 19:30:53 psoares33 Exp $
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfNilOutputStream : Stream {
|
||||
private long size = 0;
|
||||
|
||||
public RtfNilOutputStream() {
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close() {
|
||||
}
|
||||
|
||||
public override void Flush() {
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] src, int off, int len) {
|
||||
if(src == null) throw(new ArgumentNullException());
|
||||
if((off < 0) || (off > src.Length) || (len < 0) || ((off + len) > src.Length) || ((off + len) < 0)) throw new IndexOutOfRangeException();
|
||||
|
||||
size += len;
|
||||
}
|
||||
|
||||
public override void WriteByte(byte value) {
|
||||
++size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that have been written to this buffer so far.
|
||||
*
|
||||
* @return number of bytes written to this buffer
|
||||
*/
|
||||
public long GetSize() {
|
||||
return(size);
|
||||
}
|
||||
}
|
||||
}
|
||||
111
iTechSharp/iTextSharp/text/rtf/field/RtfAnchor.cs
Normal file
111
iTechSharp/iTextSharp/text/rtf/field/RtfAnchor.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfAnchor.cs,v 1.7 2008/05/16 19:30:54 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 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.field {
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfAnchor : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for a hyperlink
|
||||
*/
|
||||
private static byte[] HYPERLINK = DocWriter.GetISOBytes("HYPERLINK");
|
||||
|
||||
/**
|
||||
* The url of this RtfAnchor
|
||||
*/
|
||||
private String url = "";
|
||||
/**
|
||||
* The RtfPhrase to display for the url
|
||||
*/
|
||||
private new RtfPhrase content = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfAnchor based on a RtfField
|
||||
*
|
||||
* @param doc The RtfDocument this RtfAnchor belongs to
|
||||
* @param anchor The Anchor this RtfAnchor is based on
|
||||
*/
|
||||
public RtfAnchor(RtfDocument doc, Anchor anchor) : base(doc) {
|
||||
this.url = anchor.Reference;
|
||||
this.content = new RtfPhrase(doc, anchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the field instructions for this RtfAnchor. Sets the field
|
||||
* type to HYPERLINK and then writes the url.
|
||||
*
|
||||
* @return The field instructions for this RtfAnchor
|
||||
* @throws IOException
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream result) {
|
||||
result.Write(HYPERLINK, 0, HYPERLINK.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
this.document.FilterSpecialChar(result, url, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the field result for this RtfAnchor. Writes the content
|
||||
* of the RtfPhrase.
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
content.WriteContent(outp);
|
||||
}
|
||||
}
|
||||
}
|
||||
427
iTechSharp/iTextSharp/text/rtf/field/RtfField.cs
Normal file
427
iTechSharp/iTextSharp/text/rtf/field/RtfField.cs
Normal file
@@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfField.cs,v 1.7 2008/05/16 19:30:54 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
* Uses code Copyright 2002
|
||||
* <a href="http://www.smb-tec.com">SMB</a>
|
||||
* <a href="mailto:Dirk.Weigenand@smb-tec.com">Dirk.Weigenand@smb-tec.com</a>
|
||||
*
|
||||
* 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.field {
|
||||
|
||||
/**
|
||||
* The RtfField class is an abstract base class for all rtf field functionality.
|
||||
* Subclasses only need to implement the two abstract methods writeFieldInstContent
|
||||
* and writeFieldResultContent. All other field functionality is handled by the
|
||||
* RtfField class.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Dirk.Weigenand@smb-tec.com">Dirk Weigenand</a>
|
||||
*/
|
||||
public abstract class RtfField : Chunk, iTextSharp.text.rtf.IRtfBasicElement {
|
||||
|
||||
/**
|
||||
* Constant for the beginning of a rtf group
|
||||
*/
|
||||
public static byte[] OPEN_GROUP = {(byte)'{'};
|
||||
/**
|
||||
* Constant for the end of an rtf group
|
||||
*/
|
||||
public static byte[] CLOSE_GROUP = {(byte)'}'};
|
||||
/**
|
||||
* Constant for a delimiter in rtf
|
||||
*/
|
||||
public static byte[] DELIMITER = {(byte)' '};
|
||||
/**
|
||||
* Constant for a comma delimiter in rtf
|
||||
*/
|
||||
public static byte[] COMMA_DELIMITER = {(byte)';'};
|
||||
/**
|
||||
* The factor to use for translating from iText to rtf measurments
|
||||
*/
|
||||
public const double TWIPS_FACTOR = 20;
|
||||
|
||||
/**
|
||||
* Constant for a rtf field
|
||||
*/
|
||||
private static byte[] FIELD = DocWriter.GetISOBytes("\\field");
|
||||
/**
|
||||
* Constant for a dirty field
|
||||
*/
|
||||
private static byte[] FIELD_DIRTY = DocWriter.GetISOBytes("\\flddirty");
|
||||
/**
|
||||
* Constant for a private field
|
||||
*/
|
||||
private static byte[] FIELD_PRIVATE = DocWriter.GetISOBytes("\\fldpriv");
|
||||
/**
|
||||
* Constant for a locked field
|
||||
*/
|
||||
private static byte[] FIELD_LOCKED = DocWriter.GetISOBytes("\\fldlock");
|
||||
/**
|
||||
* Constant for a edited field
|
||||
*/
|
||||
private static byte[] FIELD_EDIT = DocWriter.GetISOBytes("\\fldedit");
|
||||
/**
|
||||
* Constant for an alt field
|
||||
*/
|
||||
private static byte[] FIELD_ALT = DocWriter.GetISOBytes("\\fldalt");
|
||||
/**
|
||||
* Constant for the field instructions
|
||||
*/
|
||||
private static byte[] FIELD_INSTRUCTIONS = DocWriter.GetISOBytes("\\*\\fldinst");
|
||||
/**
|
||||
* Constant for the field result
|
||||
*/
|
||||
private static byte[] FIELD_RESULT = DocWriter.GetISOBytes("\\fldrslt");
|
||||
|
||||
/**
|
||||
* Is the field dirty
|
||||
*/
|
||||
private bool fieldDirty = false;
|
||||
/**
|
||||
* Is the field edited
|
||||
*/
|
||||
private bool fieldEdit = false;
|
||||
/**
|
||||
* Is the field locked
|
||||
*/
|
||||
private bool fieldLocked = false;
|
||||
/**
|
||||
* Is the field private
|
||||
*/
|
||||
private bool fieldPrivate = false;
|
||||
/**
|
||||
* Is it an alt field
|
||||
*/
|
||||
private bool fieldAlt = false;
|
||||
/**
|
||||
* Whether this RtfField is in a table
|
||||
*/
|
||||
private bool inTable = false;
|
||||
/**
|
||||
* Whether this RtfElement is in a header
|
||||
*/
|
||||
private bool inHeader = false;
|
||||
/**
|
||||
* The RtfDocument this RtfField belongs to
|
||||
*/
|
||||
protected RtfDocument document = null;
|
||||
/**
|
||||
* The RtfFont of this RtfField
|
||||
*/
|
||||
private new ST.RtfFont font = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfField for a RtfDocument. This is not very usefull,
|
||||
* since the RtfField by itself does not do anything. Use one of the
|
||||
* subclasses instead.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfField belongs to.
|
||||
*/
|
||||
protected RtfField(RtfDocument doc) : this(doc, new Font()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfField for a RtfDocument. This is not very usefull,
|
||||
* since the RtfField by itself does not do anything. Use one of the
|
||||
* subclasses instead.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfField belongs to.
|
||||
* @param font The Font this RtfField should use
|
||||
*/
|
||||
protected RtfField(RtfDocument doc, Font font) : base("", font) {
|
||||
this.document = doc;
|
||||
this.font = new ST.RtfFont(this.document, font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfElement belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
this.font.SetRtfDocument(this.document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field beginning. Also writes field properties.
|
||||
*
|
||||
* @return A byte array with the field beginning.
|
||||
* @throws IOException
|
||||
*/
|
||||
private void WriteFieldBegin(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(FIELD, 0, FIELD.Length);
|
||||
if (fieldDirty) result.Write(FIELD_DIRTY, 0, FIELD_DIRTY.Length);
|
||||
if (fieldEdit) result.Write(FIELD_EDIT, 0, FIELD_EDIT.Length);
|
||||
if (fieldLocked) result.Write(FIELD_LOCKED, 0, FIELD_LOCKED.Length);
|
||||
if (fieldPrivate) result.Write(FIELD_PRIVATE, 0, FIELD_PRIVATE.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the beginning of the field instruction area.
|
||||
*
|
||||
* @return The beginning of the field instruction area
|
||||
* @throws IOException
|
||||
*/
|
||||
private void WriteFieldInstBegin(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(FIELD_INSTRUCTIONS, 0, FIELD_INSTRUCTIONS.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the field instruction area. Override this
|
||||
* method in your subclasses.
|
||||
*/
|
||||
protected abstract void WriteFieldInstContent(Stream oupt);
|
||||
|
||||
/**
|
||||
* Writes the end of the field instruction area.
|
||||
*/
|
||||
private void WriteFieldInstEnd(Stream result) {
|
||||
if (fieldAlt) {
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(FIELD_ALT, 0, FIELD_ALT.Length);
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the beginning of the field result area
|
||||
*/
|
||||
private void WriteFieldResultBegin(Stream result) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(FIELD_RESULT, 0, FIELD_RESULT.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the pre-calculated field result. Override this
|
||||
* method in your subclasses.
|
||||
*/
|
||||
protected abstract void WriteFieldResultContent(Stream oupt);
|
||||
|
||||
/**
|
||||
* Writes the end of the field result area
|
||||
*/
|
||||
private void WriteFieldResultEnd(Stream result) {
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the end of the field
|
||||
*/
|
||||
private void WriteFieldEnd(Stream result) {
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes the field to the <code>OutputStream</code>.
|
||||
*/
|
||||
public virtual void WriteContent(Stream result) {
|
||||
font.WriteBegin(result);
|
||||
WriteFieldBegin(result);
|
||||
WriteFieldInstBegin(result);
|
||||
WriteFieldInstContent(result);
|
||||
WriteFieldInstEnd(result);
|
||||
WriteFieldResultBegin(result);
|
||||
WriteFieldResultContent(result);
|
||||
WriteFieldResultEnd(result);
|
||||
WriteFieldEnd(result);
|
||||
font.WriteEnd(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is an alt field
|
||||
*
|
||||
* @return Returns whether this field is an alt field
|
||||
*/
|
||||
public bool IsFieldAlt() {
|
||||
return fieldAlt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is an alt field
|
||||
*
|
||||
* @param fieldAlt The value to use
|
||||
*/
|
||||
public void SetFieldAlt(bool fieldAlt) {
|
||||
this.fieldAlt = fieldAlt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is dirty
|
||||
*
|
||||
* @return Returns whether this field is dirty
|
||||
*/
|
||||
public bool IsFieldDirty() {
|
||||
return fieldDirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is dirty
|
||||
*
|
||||
* @param fieldDirty The value to use
|
||||
*/
|
||||
public void SetFieldDirty(bool fieldDirty) {
|
||||
this.fieldDirty = fieldDirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is edited
|
||||
*
|
||||
* @return Returns whether this field is edited
|
||||
*/
|
||||
public bool IsFieldEdit() {
|
||||
return fieldEdit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is edited.
|
||||
*
|
||||
* @param fieldEdit The value to use
|
||||
*/
|
||||
public void SetFieldEdit(bool fieldEdit) {
|
||||
this.fieldEdit = fieldEdit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is locked
|
||||
*
|
||||
* @return Returns the fieldLocked.
|
||||
*/
|
||||
public bool IsFieldLocked() {
|
||||
return fieldLocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is locked
|
||||
* @param fieldLocked The value to use
|
||||
*/
|
||||
public void SetFieldLocked(bool fieldLocked) {
|
||||
this.fieldLocked = fieldLocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this field is private
|
||||
*
|
||||
* @return Returns the fieldPrivate.
|
||||
*/
|
||||
public bool IsFieldPrivate() {
|
||||
return fieldPrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this field is private
|
||||
*
|
||||
* @param fieldPrivate The value to use
|
||||
*/
|
||||
public void SetFieldPrivate(bool fieldPrivate) {
|
||||
this.fieldPrivate = fieldPrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfField is in a table
|
||||
*
|
||||
* @param inTable <code>True</code> if this RtfField is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
this.inTable = inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this <code>RtfField</code> is in a table.
|
||||
*
|
||||
* @return <code>True</code> if this <code>RtfField</code> is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public bool IsInTable() {
|
||||
return this.inTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfField is in a header
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfField is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
this.inHeader = inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this <code>RtfField</code> is in a header.
|
||||
*
|
||||
* @return <code>True</code> if this <code>RtfField</code> is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public bool IsInHeader() {
|
||||
return this.inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* An RtfField is never empty.
|
||||
*/
|
||||
public override bool IsEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Font Font {
|
||||
set {
|
||||
base.Font = value;
|
||||
font = new ST.RtfFont(document, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
iTechSharp/iTextSharp/text/rtf/field/RtfPageNumber.cs
Normal file
75
iTechSharp/iTextSharp/text/rtf/field/RtfPageNumber.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* Created on Aug 10, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
namespace iTextSharp.text.rtf.field {
|
||||
|
||||
/**
|
||||
* The RtfPageNumber provides the page number field in rtf documents.
|
||||
*
|
||||
* @version $Revision: 1.4 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*/
|
||||
public class RtfPageNumber : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for the page number
|
||||
*/
|
||||
private static byte[] PAGE_NUMBER = DocWriter.GetISOBytes("PAGE");
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber. This can be added anywhere to add a page number field.
|
||||
*/
|
||||
public RtfPageNumber() : base(null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber with a specified Font. This can be added anywhere to
|
||||
* add a page number field.
|
||||
* @param font
|
||||
*/
|
||||
public RtfPageNumber(Font font) : base(null, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber object.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPageNumber belongs to
|
||||
*/
|
||||
public RtfPageNumber(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfPageNumber object with a specific font.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPageNumber belongs to
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfPageNumber(RtfDocument doc, Font font) : base(doc, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field instruction content
|
||||
*
|
||||
* @
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream oupt) {
|
||||
oupt.Write(PAGE_NUMBER, 0, PAGE_NUMBER.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field result content
|
||||
*
|
||||
* @
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream oupt) {
|
||||
}
|
||||
}
|
||||
}
|
||||
146
iTechSharp/iTextSharp/text/rtf/field/RtfTOCEntry.cs
Normal file
146
iTechSharp/iTextSharp/text/rtf/field/RtfTOCEntry.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: RtfTOCEntry.cs,v 1.6 2008/05/23 17:24:26 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
* Uses code Copyright 2002
|
||||
* <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*
|
||||
* 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.field {
|
||||
|
||||
/**
|
||||
* The RtfTOCEntry is used together with the RtfTableOfContents to generate a table of
|
||||
* contents. Add the RtfTOCEntry in those locations in the document where table of
|
||||
* contents entries should link to
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*/
|
||||
public class RtfTOCEntry : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for the beginning of hidden text
|
||||
*/
|
||||
private static byte[] TEXT_HIDDEN_ON = DocWriter.GetISOBytes("\\v");
|
||||
/**
|
||||
* Constant for the end of hidden text
|
||||
*/
|
||||
private static byte[] TEXT_HIDDEN_OFF = DocWriter.GetISOBytes("\\v0");
|
||||
/**
|
||||
* Constant for a TOC entry with page numbers
|
||||
*/
|
||||
private static byte[] TOC_ENTRY_PAGE_NUMBER = DocWriter.GetISOBytes("\\tc");
|
||||
/**
|
||||
* Constant for a TOC entry without page numbers
|
||||
*/
|
||||
private static byte[] TOC_ENTRY_NO_PAGE_NUMBER = DocWriter.GetISOBytes("\\tcn");
|
||||
|
||||
/**
|
||||
* The entry text of this RtfTOCEntry
|
||||
*/
|
||||
private String entry = "";
|
||||
/**
|
||||
* Whether to show page numbers in the table of contents
|
||||
*/
|
||||
private bool showPageNumber = true;
|
||||
|
||||
/**
|
||||
* Constructs a RtfTOCEntry with a certain entry text.
|
||||
*
|
||||
* @param entry The entry text to display
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfTOCEntry(String entry) : base(null, new Font()) {
|
||||
if (entry != null) {
|
||||
this.entry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the RtfTOCEntry
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(TEXT_HIDDEN_ON, 0, TEXT_HIDDEN_ON.Length);
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
if (this.showPageNumber) {
|
||||
result.Write(TOC_ENTRY_PAGE_NUMBER, 0, TOC_ENTRY_PAGE_NUMBER.Length);
|
||||
} else {
|
||||
result.Write(TOC_ENTRY_NO_PAGE_NUMBER, 0, TOC_ENTRY_NO_PAGE_NUMBER.Length);
|
||||
}
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
this.document.FilterSpecialChar(result, this.entry, true, false);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(TEXT_HIDDEN_OFF, 0, TEXT_HIDDEN_OFF.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to display a page number in the table of contents, or not
|
||||
*
|
||||
* @param showPageNumber Whether to display a page number or not
|
||||
*/
|
||||
public void SetShowPageNumber(bool showPageNumber) {
|
||||
this.showPageNumber = showPageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* unused
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream outp) {
|
||||
}
|
||||
|
||||
/*
|
||||
* unused
|
||||
* @see com.lowagie.text.rtf.field.RtfField#writeFieldResultContent(java.io.OutputStream)
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
}
|
||||
}
|
||||
}
|
||||
105
iTechSharp/iTextSharp/text/rtf/field/RtfTableOfContents.cs
Normal file
105
iTechSharp/iTextSharp/text/rtf/field/RtfTableOfContents.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
/*
|
||||
* $Id: RtfTableOfContents.cs,v 1.7 2008/05/23 17:24:26 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2004 by Mark Hall
|
||||
* Uses code Copyright 2002
|
||||
* <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*
|
||||
* 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.field {
|
||||
|
||||
/**
|
||||
* The RtfTableOfContents together with multiple RtfTOCEntry objects generates a table
|
||||
* of contents. The table of contents will display no entries in the viewing program
|
||||
* and the user will have to update it first. A text to inform the user of this is
|
||||
* displayed instead.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author <a href="mailto:Steffen.Stundzig@smb-tec.com">Steffen.Stundzig@smb-tec.com</a>
|
||||
*/
|
||||
public class RtfTableOfContents : RtfField {
|
||||
|
||||
/**
|
||||
* field inst content
|
||||
*/
|
||||
private const String FIELD_INST = "TOC \\\\f \\\\h \\\\u \\\\o \"1-5\" ";
|
||||
/**
|
||||
* The default text to display
|
||||
*/
|
||||
private String defaultText = "Table of Contents - Click to update";
|
||||
|
||||
/**
|
||||
* Constructs a RtfTableOfContents. The default text is the text that is displayed
|
||||
* before the user updates the table of contents
|
||||
*
|
||||
* @param defaultText The default text to display
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfTableOfContents(String defaultText) : base(null, new Font()) {
|
||||
this.defaultText = defaultText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field instruction content
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream outp) {
|
||||
byte[] t = DocWriter.GetISOBytes(FIELD_INST);
|
||||
outp.Write(t, 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field result content
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
document.FilterSpecialChar(outp, defaultText, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
118
iTechSharp/iTextSharp/text/rtf/field/RtfTotalPageNumber.cs
Normal file
118
iTechSharp/iTextSharp/text/rtf/field/RtfTotalPageNumber.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfTotalPageNumber.cs,v 1.5 2008/05/23 17:24:26 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2005 Jose Hurtado <a href="mailto:jose.hurtado@gft.com">jose.hurtado@gft.com</a>
|
||||
* Parts Copyright 2005 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.field {
|
||||
|
||||
/**
|
||||
* The RtfTotalPageNumber provides the total number of pages field in rtf documents.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Jose Hurtado (jose.hurtado@gft.com)
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfTotalPageNumber : RtfField {
|
||||
|
||||
/**
|
||||
* Constant for arabic total page numbers.
|
||||
*/
|
||||
private static byte[] ARABIC_TOTAL_PAGES = DocWriter.GetISOBytes("NUMPAGES \\\\* Arabic");
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber. This can be added anywhere to add a total number of pages field.
|
||||
*/
|
||||
public RtfTotalPageNumber() : base(null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber with a specified Font. This can be added anywhere
|
||||
* to add a total number of pages field.
|
||||
* @param font
|
||||
*/
|
||||
public RtfTotalPageNumber(Font font) : base(null, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber object.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfTotalPageNumber belongs to
|
||||
*/
|
||||
public RtfTotalPageNumber(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTotalPageNumber object with a specific font.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfTotalPageNumber belongs to
|
||||
* @param font The Font to use
|
||||
*/
|
||||
public RtfTotalPageNumber(RtfDocument doc, Font font) : base(doc, font) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field NUMPAGES instruction with Arabic format: "NUMPAGES \\\\* Arabic".
|
||||
*/
|
||||
protected override void WriteFieldInstContent(Stream outp) {
|
||||
outp.Write(ARABIC_TOTAL_PAGES, 0, ARABIC_TOTAL_PAGES.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the field result content "1"
|
||||
*/
|
||||
protected override void WriteFieldResultContent(Stream outp) {
|
||||
byte[] t = new byte[]{(byte)'1'};
|
||||
outp.Write(t, 0, t.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
384
iTechSharp/iTextSharp/text/rtf/graphic/RtfImage.cs
Normal file
384
iTechSharp/iTextSharp/text/rtf/graphic/RtfImage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
379
iTechSharp/iTextSharp/text/rtf/graphic/RtfShape.cs
Normal file
379
iTechSharp/iTextSharp/text/rtf/graphic/RtfShape.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
249
iTechSharp/iTextSharp/text/rtf/graphic/RtfShapePosition.cs
Normal file
249
iTechSharp/iTextSharp/text/rtf/graphic/RtfShapePosition.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
356
iTechSharp/iTextSharp/text/rtf/graphic/RtfShapeProperty.cs
Normal file
356
iTechSharp/iTextSharp/text/rtf/graphic/RtfShapeProperty.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
326
iTechSharp/iTextSharp/text/rtf/headerfooter/RtfHeaderFooter.cs
Normal file
326
iTechSharp/iTextSharp/text/rtf/headerfooter/RtfHeaderFooter.cs
Normal file
@@ -0,0 +1,326 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using FD = iTextSharp.text.rtf.field;
|
||||
/*
|
||||
* Created on Aug 10, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
namespace iTextSharp.text.rtf.headerfooter {
|
||||
|
||||
/**
|
||||
* The RtfHeaderFooter represents one header or footer. This class can be used
|
||||
* directly.
|
||||
*
|
||||
* @version $Id: RtfHeaderFooter.cs,v 1.7 2008/05/16 19:30:59 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfHeaderFooter : HeaderFooter, IRtfBasicElement {
|
||||
|
||||
/**
|
||||
* Constant for the header type
|
||||
*/
|
||||
public const int TYPE_HEADER = 1;
|
||||
/**
|
||||
* Constant for the footer type
|
||||
*/
|
||||
public const int TYPE_FOOTER = 2;
|
||||
/**
|
||||
* Constant for displaying the header/footer on the first page
|
||||
*/
|
||||
public const int DISPLAY_FIRST_PAGE = 0;
|
||||
/**
|
||||
* Constant for displaying the header/footer on all pages
|
||||
*/
|
||||
public const int DISPLAY_ALL_PAGES = 1;
|
||||
/**
|
||||
* Constant for displaying the header/footer on all left hand pages
|
||||
*/
|
||||
public const int DISPLAY_LEFT_PAGES = 2;
|
||||
/**
|
||||
* Constant for displaying the header/footer on all right hand pages
|
||||
*/
|
||||
public const int DISPLAY_RIGHT_PAGES = 4;
|
||||
|
||||
/**
|
||||
* Constant for a header on all pages
|
||||
*/
|
||||
private static byte[] HEADER_ALL = DocWriter.GetISOBytes("\\header");
|
||||
/**
|
||||
* Constant for a header on the first page
|
||||
*/
|
||||
private static byte[] HEADER_FIRST = DocWriter.GetISOBytes("\\headerf");
|
||||
/**
|
||||
* Constant for a header on all left hand pages
|
||||
*/
|
||||
private static byte[] HEADER_LEFT = DocWriter.GetISOBytes("\\headerl");
|
||||
/**
|
||||
* Constant for a header on all right hand pages
|
||||
*/
|
||||
private static byte[] HEADER_RIGHT = DocWriter.GetISOBytes("\\headerr");
|
||||
/**
|
||||
* Constant for a footer on all pages
|
||||
*/
|
||||
private static byte[] FOOTER_ALL = DocWriter.GetISOBytes("\\footer");
|
||||
/**
|
||||
* Constant for a footer on the first page
|
||||
*/
|
||||
private static byte[] FOOTER_FIRST = DocWriter.GetISOBytes("\\footerf");
|
||||
/**
|
||||
* Constnat for a footer on the left hand pages
|
||||
*/
|
||||
private static byte[] FOOTER_LEFT = DocWriter.GetISOBytes("\\footerl");
|
||||
/**
|
||||
* Constant for a footer on the right hand pages
|
||||
*/
|
||||
private static byte[] FOOTER_RIGHT = DocWriter.GetISOBytes("\\footerr");
|
||||
|
||||
/**
|
||||
* The RtfDocument this RtfHeaderFooter belongs to
|
||||
*/
|
||||
private RtfDocument document = null;
|
||||
/**
|
||||
* The content of this RtfHeaderFooter
|
||||
*/
|
||||
private Object[] content = null;
|
||||
/**
|
||||
* The display type of this RtfHeaderFooter. TYPE_HEADER or TYPE_FOOTER
|
||||
*/
|
||||
private int type = TYPE_HEADER;
|
||||
/**
|
||||
* The display location of this RtfHeaderFooter. DISPLAY_FIRST_PAGE,
|
||||
* DISPLAY_LEFT_PAGES, DISPLAY_RIGHT_PAGES or DISPLAY_ALL_PAGES
|
||||
*/
|
||||
private int displayAt = DISPLAY_ALL_PAGES;
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooter based on a HeaderFooter with a certain type and displayAt
|
||||
* location. For internal use only.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
|
||||
* @param type The type of RtfHeaderFooter
|
||||
* @param displayAt The display location of this RtfHeaderFooter
|
||||
*/
|
||||
protected internal RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter, int type, int displayAt) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
this.type = type;
|
||||
this.displayAt = displayAt;
|
||||
Paragraph par = new Paragraph();
|
||||
par.Alignment = headerFooter.Alignment;
|
||||
if (headerFooter.Before != null) {
|
||||
par.Add(headerFooter.Before);
|
||||
}
|
||||
if (headerFooter.IsNumbered()) {
|
||||
par.Add(new FD.RtfPageNumber(this.document));
|
||||
}
|
||||
if (headerFooter.After != null) {
|
||||
par.Add(headerFooter.After);
|
||||
}
|
||||
try {
|
||||
this.content = new Object[1];
|
||||
if (this.document != null) {
|
||||
this.content[0] = this.document.GetMapper().MapElement(par)[0];
|
||||
((IRtfBasicElement) this.content[0]).SetInHeader(true);
|
||||
} else {
|
||||
this.content[0] = par;
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooter as a copy of an existing RtfHeaderFooter.
|
||||
* For internal use only.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param headerFooter The RtfHeaderFooter to copy
|
||||
* @param displayAt The display location of this RtfHeaderFooter
|
||||
*/
|
||||
protected internal RtfHeaderFooter(RtfDocument doc, RtfHeaderFooter headerFooter, int displayAt) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
this.content = headerFooter.GetContent();
|
||||
this.displayAt = displayAt;
|
||||
for (int i = 0; i < this.content.Length; i++) {
|
||||
if (this.content[i] is IElement) {
|
||||
try {
|
||||
this.content[i] = this.document.GetMapper().MapElement((IElement) this.content[i])[0];
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
if (this.content[i] is IRtfBasicElement) {
|
||||
((IRtfBasicElement) this.content[i]).SetInHeader(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooter for a HeaderFooter.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
|
||||
*/
|
||||
protected internal RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
Paragraph par = new Paragraph();
|
||||
par.Alignment = headerFooter.Alignment;
|
||||
if (headerFooter.Before != null) {
|
||||
par.Add(headerFooter.Before);
|
||||
}
|
||||
if (headerFooter.IsNumbered()) {
|
||||
par.Add(new FD.RtfPageNumber(this.document));
|
||||
}
|
||||
if (headerFooter.After != null) {
|
||||
par.Add(headerFooter.After);
|
||||
}
|
||||
try {
|
||||
this.content = new Object[1];
|
||||
this.content[0] = doc.GetMapper().MapElement(par)[0];
|
||||
((IRtfBasicElement) this.content[0]).SetInHeader(true);
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooter for any Element.
|
||||
*
|
||||
* @param element The Element to display as content of this RtfHeaderFooter
|
||||
*/
|
||||
public RtfHeaderFooter(IElement element) : this(new IElement[]{element}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooter for an array of Elements.
|
||||
*
|
||||
* @param elements The Elements to display as the content of this RtfHeaderFooter.
|
||||
*/
|
||||
public RtfHeaderFooter(IElement[] elements) : base(new Phrase(""), false){
|
||||
this.content = new Object[elements.Length];
|
||||
for (int i = 0; i < elements.Length; i++) {
|
||||
this.content[i] = elements[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfElement belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
if (this.document != null) {
|
||||
for (int i = 0; i < this.content.Length; i++) {
|
||||
try {
|
||||
if (this.content[i] is Element) {
|
||||
this.content[i] = this.document.GetMapper().MapElement((IElement) this.content[i])[0];
|
||||
((IRtfBasicElement) this.content[i]).SetInHeader(true);
|
||||
} else if (this.content[i] is IRtfBasicElement){
|
||||
((IRtfBasicElement) this.content[i]).SetRtfDocument(this.document);
|
||||
((IRtfBasicElement) this.content[i]).SetInHeader(true);
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of this RtfHeaderFooter.
|
||||
*/
|
||||
public virtual void WriteContent(Stream result) {
|
||||
result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
|
||||
if (this.type == TYPE_HEADER) {
|
||||
if (this.displayAt == DISPLAY_ALL_PAGES) {
|
||||
result.Write(HEADER_ALL, 0, HEADER_ALL.Length);
|
||||
} else if (this.displayAt == DISPLAY_FIRST_PAGE) {
|
||||
result.Write(HEADER_FIRST, 0, HEADER_FIRST.Length);
|
||||
} else if (this.displayAt == DISPLAY_LEFT_PAGES) {
|
||||
result.Write(HEADER_LEFT, 0, HEADER_LEFT.Length);
|
||||
} else if (this.displayAt == DISPLAY_RIGHT_PAGES) {
|
||||
result.Write(HEADER_RIGHT, 0, HEADER_RIGHT.Length);
|
||||
}
|
||||
} else {
|
||||
if (this.displayAt == DISPLAY_ALL_PAGES) {
|
||||
result.Write(FOOTER_ALL, 0, FOOTER_ALL.Length);
|
||||
} else if (this.displayAt == DISPLAY_FIRST_PAGE) {
|
||||
result.Write(FOOTER_FIRST, 0, FOOTER_FIRST.Length);
|
||||
} else if (this.displayAt == DISPLAY_LEFT_PAGES) {
|
||||
result.Write(FOOTER_LEFT, 0, FOOTER_LEFT.Length);
|
||||
} else if (this.displayAt == DISPLAY_RIGHT_PAGES) {
|
||||
result.Write(FOOTER_RIGHT, 0, FOOTER_RIGHT.Length);
|
||||
}
|
||||
}
|
||||
result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
|
||||
for (int i = 0; i < this.content.Length; i++) {
|
||||
if (this.content[i] is IRtfBasicElement) {
|
||||
IRtfBasicElement rbe = (IRtfBasicElement)this.content[i];
|
||||
rbe.WriteContent(result);
|
||||
}
|
||||
}
|
||||
result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the display location of this RtfHeaderFooter
|
||||
*
|
||||
* @param displayAt The display location to use.
|
||||
*/
|
||||
public void SetDisplayAt(int displayAt) {
|
||||
this.displayAt = displayAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of this RtfHeaderFooter
|
||||
*
|
||||
* @param type The type to use.
|
||||
*/
|
||||
public void SetType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of this RtfHeaderFooter
|
||||
*
|
||||
* @return The content of this RtfHeaderFooter
|
||||
*/
|
||||
private Object[] GetContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param inTable
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param inHeader
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alignment of this RtfHeaderFooter. Passes the setting
|
||||
* on to the contained element.
|
||||
*/
|
||||
public void SetAlignment(int alignment) {
|
||||
base.Alignment = alignment;
|
||||
for (int i = 0; i < this.content.Length; i++) {
|
||||
if (this.content[i] is Paragraph) {
|
||||
((Paragraph) this.content[i]).Alignment = alignment;
|
||||
} else if (this.content[i] is Table) {
|
||||
((Table) this.content[i]).Alignment = alignment;
|
||||
} else if (this.content[i] is Image) {
|
||||
((Image) this.content[i]).Alignment = alignment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* Created on Aug 6, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
namespace iTextSharp.text.rtf.headerfooter {
|
||||
|
||||
/**
|
||||
* The RtfHeaderFooterGroup holds 0 - 3 RtfHeaderFooters that create a group
|
||||
* of headers or footers.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfHeaderFooterGroup : HeaderFooter, IRtfBasicElement {
|
||||
|
||||
/**
|
||||
* This RtfHeaderFooterGroup contains no RtfHeaderFooter objects
|
||||
*/
|
||||
private const int MODE_NONE = 0;
|
||||
/**
|
||||
* This RtfHeaderFooterGroup contains one RtfHeaderFooter object
|
||||
*/
|
||||
private const int MODE_SINGLE = 1;
|
||||
/**
|
||||
* This RtfHeaderFooterGroup contains two or three RtfHeaderFooter objects
|
||||
*/
|
||||
private const int MODE_MULTIPLE = 2;
|
||||
|
||||
/**
|
||||
* The current mode of this RtfHeaderFooterGroup. Defaults to MODE_NONE
|
||||
*/
|
||||
private int mode = MODE_NONE;
|
||||
/**
|
||||
* The current type of this RtfHeaderFooterGroup. Defaults to RtfHeaderFooter.TYPE_HEADER
|
||||
*/
|
||||
private int type = RtfHeaderFooter.TYPE_HEADER;
|
||||
|
||||
/**
|
||||
* The RtfHeaderFooter for all pages
|
||||
*/
|
||||
private RtfHeaderFooter headerAll = null;
|
||||
/**
|
||||
* The RtfHeaderFooter for the first page
|
||||
*/
|
||||
private RtfHeaderFooter headerFirst = null;
|
||||
/**
|
||||
* The RtfHeaderFooter for the left hand pages
|
||||
*/
|
||||
private RtfHeaderFooter headerLeft = null;
|
||||
/**
|
||||
* The RtfHeaderFooter for the right hand pages
|
||||
*/
|
||||
private RtfHeaderFooter headerRight = null;
|
||||
/**
|
||||
* The RtfDocument this RtfHeaderFooterGroup belongs to
|
||||
*/
|
||||
private RtfDocument document = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderGroup to which you add headers/footers using
|
||||
* via the setHeaderFooter method.
|
||||
*
|
||||
*/
|
||||
public RtfHeaderFooterGroup() : base(new Phrase(""), false) {
|
||||
this.mode = MODE_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a certain type of RtfHeaderFooterGroup. RtfHeaderFooter.TYPE_HEADER
|
||||
* and RtfHeaderFooter.TYPE_FOOTER are valid values for type.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param type The type of RtfHeaderFooterGroup to create
|
||||
*/
|
||||
public RtfHeaderFooterGroup(RtfDocument doc, int type) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooterGroup by copying the content of the original
|
||||
* RtfHeaderFooterGroup
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param headerFooter The RtfHeaderFooterGroup to copy
|
||||
* @param type The type of RtfHeaderFooterGroup to create
|
||||
*/
|
||||
public RtfHeaderFooterGroup(RtfDocument doc, RtfHeaderFooterGroup headerFooter, int type) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
this.mode = headerFooter.GetMode();
|
||||
this.type = type;
|
||||
if (headerFooter.GetHeaderAll() != null) {
|
||||
this.headerAll = new RtfHeaderFooter(this.document, headerFooter.GetHeaderAll(), RtfHeaderFooter.DISPLAY_ALL_PAGES);
|
||||
}
|
||||
if (headerFooter.GetHeaderFirst() != null) {
|
||||
this.headerFirst = new RtfHeaderFooter(this.document, headerFooter.GetHeaderFirst(), RtfHeaderFooter.DISPLAY_FIRST_PAGE);
|
||||
}
|
||||
if (headerFooter.GetHeaderLeft() != null) {
|
||||
this.headerLeft = new RtfHeaderFooter(this.document, headerFooter.GetHeaderLeft(), RtfHeaderFooter.DISPLAY_LEFT_PAGES);
|
||||
}
|
||||
if (headerFooter.GetHeaderRight() != null) {
|
||||
this.headerRight = new RtfHeaderFooter(this.document, headerFooter.GetHeaderRight(), RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
|
||||
}
|
||||
SetType(this.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderFooterGroup for a certain RtfHeaderFooter.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param headerFooter The RtfHeaderFooter to display
|
||||
* @param type The typ of RtfHeaderFooterGroup to create
|
||||
*/
|
||||
public RtfHeaderFooterGroup(RtfDocument doc, RtfHeaderFooter headerFooter, int type) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
this.type = type;
|
||||
this.mode = MODE_SINGLE;
|
||||
headerAll = new RtfHeaderFooter(doc, headerFooter, RtfHeaderFooter.DISPLAY_ALL_PAGES);
|
||||
headerAll.SetType(this.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfHeaderGroup for a certain HeaderFooter
|
||||
*
|
||||
* @param doc The RtfDocument this RtfHeaderFooter belongs to
|
||||
* @param headerFooter The HeaderFooter to display
|
||||
* @param type The typ of RtfHeaderFooterGroup to create
|
||||
*/
|
||||
public RtfHeaderFooterGroup(RtfDocument doc, HeaderFooter headerFooter, int type) : base(new Phrase(""), false) {
|
||||
this.document = doc;
|
||||
this.type = type;
|
||||
this.mode = MODE_SINGLE;
|
||||
headerAll = new RtfHeaderFooter(doc, headerFooter, type, RtfHeaderFooter.DISPLAY_ALL_PAGES);
|
||||
headerAll.SetType(this.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfElement belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
if (headerAll != null) {
|
||||
headerAll.SetRtfDocument(this.document);
|
||||
}
|
||||
if (headerFirst != null) {
|
||||
headerFirst.SetRtfDocument(this.document);
|
||||
}
|
||||
if (headerLeft != null) {
|
||||
headerLeft.SetRtfDocument(this.document);
|
||||
}
|
||||
if (headerRight != null) {
|
||||
headerRight.SetRtfDocument(this.document);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of this RtfHeaderFooterGroup.
|
||||
*/
|
||||
public virtual void WriteContent(Stream result) {
|
||||
if (this.mode == MODE_SINGLE) {
|
||||
headerAll.WriteContent(result);
|
||||
} else if (this.mode == MODE_MULTIPLE) {
|
||||
if (headerFirst != null) {
|
||||
headerFirst.WriteContent(result);
|
||||
}
|
||||
if (headerLeft != null) {
|
||||
headerLeft.WriteContent(result);
|
||||
}
|
||||
if (headerRight != null) {
|
||||
headerRight.WriteContent(result);
|
||||
}
|
||||
if (headerAll != null) {
|
||||
headerAll.WriteContent(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a RtfHeaderFooter to be displayed at a certain position
|
||||
*
|
||||
* @param headerFooter The RtfHeaderFooter to display
|
||||
* @param displayAt The display location to use
|
||||
*/
|
||||
public void SetHeaderFooter(RtfHeaderFooter headerFooter, int displayAt) {
|
||||
this.mode = MODE_MULTIPLE;
|
||||
headerFooter.SetRtfDocument(this.document);
|
||||
headerFooter.SetType(this.type);
|
||||
headerFooter.SetDisplayAt(displayAt);
|
||||
switch (displayAt) {
|
||||
case RtfHeaderFooter.DISPLAY_ALL_PAGES:
|
||||
headerAll = headerFooter;
|
||||
break;
|
||||
case RtfHeaderFooter.DISPLAY_FIRST_PAGE:
|
||||
headerFirst = headerFooter;
|
||||
break;
|
||||
case RtfHeaderFooter.DISPLAY_LEFT_PAGES:
|
||||
headerLeft = headerFooter;
|
||||
break;
|
||||
case RtfHeaderFooter.DISPLAY_RIGHT_PAGES:
|
||||
headerRight = headerFooter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a HeaderFooter to be displayed at a certain position
|
||||
*
|
||||
* @param headerFooter The HeaderFooter to set
|
||||
* @param displayAt The display location to use
|
||||
*/
|
||||
public void SetHeaderFooter(HeaderFooter headerFooter, int displayAt) {
|
||||
this.mode = MODE_MULTIPLE;
|
||||
switch (displayAt) {
|
||||
case RtfHeaderFooter.DISPLAY_ALL_PAGES:
|
||||
headerAll = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
|
||||
break;
|
||||
case RtfHeaderFooter.DISPLAY_FIRST_PAGE:
|
||||
headerFirst = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
|
||||
break;
|
||||
case RtfHeaderFooter.DISPLAY_LEFT_PAGES:
|
||||
headerLeft = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
|
||||
break;
|
||||
case RtfHeaderFooter.DISPLAY_RIGHT_PAGES:
|
||||
headerRight = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set that this RtfHeaderFooterGroup should have a title page. If only
|
||||
* a header / footer for all pages exists, then it will be copied to the
|
||||
* first page aswell.
|
||||
*/
|
||||
public void SetHasTitlePage() {
|
||||
if (this.mode == MODE_SINGLE) {
|
||||
this.mode = MODE_MULTIPLE;
|
||||
headerFirst = new RtfHeaderFooter(this.document, headerAll, RtfHeaderFooter.DISPLAY_FIRST_PAGE);
|
||||
headerFirst.SetType(this.type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set that this RtfHeaderFooterGroup should have facing pages. If only
|
||||
* a header / footer for all pages exists, then it will be copied to the left
|
||||
* and right pages aswell.
|
||||
*/
|
||||
public void SetHasFacingPages() {
|
||||
if (this.mode == MODE_SINGLE) {
|
||||
this.mode = MODE_MULTIPLE;
|
||||
this.headerLeft = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_LEFT_PAGES);
|
||||
this.headerLeft.SetType(this.type);
|
||||
this.headerRight = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
|
||||
this.headerRight.SetType(this.type);
|
||||
this.headerAll = null;
|
||||
} else if (this.mode == MODE_MULTIPLE) {
|
||||
if (this.headerLeft == null && this.headerAll != null) {
|
||||
this.headerLeft = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_LEFT_PAGES);
|
||||
this.headerLeft.SetType(this.type);
|
||||
}
|
||||
if (this.headerRight == null && this.headerAll != null) {
|
||||
this.headerRight = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_RIGHT_PAGES);
|
||||
this.headerRight.SetType(this.type);
|
||||
}
|
||||
this.headerAll = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this RtfHeaderFooterGroup has a titlepage
|
||||
*
|
||||
* @return Whether this RtfHeaderFooterGroup has a titlepage
|
||||
*/
|
||||
public bool HasTitlePage() {
|
||||
return (headerFirst != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this RtfHeaderFooterGroup has facing pages
|
||||
*
|
||||
* @return Whether this RtfHeaderFooterGroup has facing pages
|
||||
*/
|
||||
public bool HasFacingPages() {
|
||||
return (headerLeft != null || headerRight != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param inTable
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param inHeader
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of this RtfHeaderFooterGroup. RtfHeaderFooter.TYPE_HEADER
|
||||
* or RtfHeaderFooter.TYPE_FOOTER. Also sets the type for all RtfHeaderFooters
|
||||
* of this RtfHeaderFooterGroup.
|
||||
*
|
||||
* @param type The type to use
|
||||
*/
|
||||
public void SetType(int type) {
|
||||
this.type = type;
|
||||
if (headerAll != null) {
|
||||
headerAll.SetType(this.type);
|
||||
}
|
||||
if (headerFirst != null) {
|
||||
headerFirst.SetType(this.type);
|
||||
}
|
||||
if (headerLeft != null) {
|
||||
headerLeft.SetType(this.type);
|
||||
}
|
||||
if (headerRight != null) {
|
||||
headerRight.SetType(this.type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mode of this RtfHeaderFooterGroup
|
||||
*
|
||||
* @return The mode of this RtfHeaderFooterGroup
|
||||
*/
|
||||
protected int GetMode() {
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfHeaderFooter for all pages
|
||||
*
|
||||
* @return The RtfHeaderFooter for all pages
|
||||
*/
|
||||
protected RtfHeaderFooter GetHeaderAll() {
|
||||
return headerAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfHeaderFooter for the title page
|
||||
*
|
||||
* @return The RtfHeaderFooter for the title page
|
||||
*/
|
||||
protected RtfHeaderFooter GetHeaderFirst() {
|
||||
return headerFirst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfHeaderFooter for all left hand pages
|
||||
*
|
||||
* @return The RtfHeaderFooter for all left hand pages
|
||||
*/
|
||||
protected RtfHeaderFooter GetHeaderLeft() {
|
||||
return headerLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfHeaderFooter for all right hand pages
|
||||
*
|
||||
* @return The RtfHeaderFooter for all right hand pages
|
||||
*/
|
||||
protected RtfHeaderFooter GetHeaderRight() {
|
||||
return headerRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
629
iTechSharp/iTextSharp/text/rtf/list/RtfList.cs
Normal file
629
iTechSharp/iTextSharp/text/rtf/list/RtfList.cs
Normal file
@@ -0,0 +1,629 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.factories;
|
||||
/*
|
||||
* $Id: RtfList.cs,v 1.18 2008/05/16 19:31:01 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004, 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the 'GNU LIBRARY GENERAL PUBLIC LICENSE'), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.list {
|
||||
|
||||
/**
|
||||
* The RtfList stores one List. It also provides the methods to write the
|
||||
* list declaration and the list data.
|
||||
*
|
||||
* @version $Id: RtfList.cs,v 1.18 2008/05/16 19:31:01 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Thomas Bickel (tmb99@inode.at)
|
||||
* @author Felix Satyaputra (f_satyaputra@yahoo.co.uk)
|
||||
*/
|
||||
public class RtfList : RtfElement, IRtfExtendedElement {
|
||||
|
||||
/**
|
||||
* Constant for list level
|
||||
*/
|
||||
private static byte[] LIST_LEVEL = DocWriter.GetISOBytes("\\listlevel");
|
||||
/**
|
||||
* Constant for list level style old
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_TYPE = DocWriter.GetISOBytes("\\levelnfc");
|
||||
/**
|
||||
* Constant for list level style new
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_TYPE_NEW = DocWriter.GetISOBytes("\\levelnfcn");
|
||||
/**
|
||||
* Constant for list level alignment old
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_ALIGNMENT = DocWriter.GetISOBytes("\\leveljc");
|
||||
/**
|
||||
* Constant for list level alignment new
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_ALIGNMENT_NEW = DocWriter.GetISOBytes("\\leveljcn");
|
||||
/**
|
||||
* Constant for list level start at
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_START_AT = DocWriter.GetISOBytes("\\levelstartat");
|
||||
/**
|
||||
* Constant for list level text
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_TEXT = DocWriter.GetISOBytes("\\leveltext");
|
||||
/**
|
||||
* Constant for the beginning of the list level numbered style
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_STYLE_NUMBERED_BEGIN = DocWriter.GetISOBytes("\\\'02\\\'");
|
||||
/**
|
||||
* Constant for the end of the list level numbered style
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_STYLE_NUMBERED_END = DocWriter.GetISOBytes(".;");
|
||||
/**
|
||||
* Constant for the beginning of the list level bulleted style
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_STYLE_BULLETED_BEGIN = DocWriter.GetISOBytes("\\\'01");
|
||||
/**
|
||||
* Constant for the end of the list level bulleted style
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_STYLE_BULLETED_END = DocWriter.GetISOBytes(";");
|
||||
/**
|
||||
* Constant for the beginning of the list level numbers
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_NUMBERS_BEGIN = DocWriter.GetISOBytes("\\levelnumbers");
|
||||
/**
|
||||
* Constant for the list level numbers
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_NUMBERS_NUMBERED = DocWriter.GetISOBytes("\\\'01");
|
||||
/**
|
||||
* Constant for the end of the list level numbers
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_NUMBERS_END = DocWriter.GetISOBytes(";");
|
||||
/**
|
||||
* Constant for the first indentation
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_FIRST_INDENT = DocWriter.GetISOBytes("\\fi");
|
||||
/**
|
||||
* Constant for the symbol indentation
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_SYMBOL_INDENT = DocWriter.GetISOBytes("\\tx");
|
||||
/**
|
||||
* Constant for the list level value
|
||||
*/
|
||||
private static byte[] LIST_LEVEL_NUMBER = DocWriter.GetISOBytes("\\ilvl");
|
||||
/**
|
||||
* Constant for a tab character
|
||||
*/
|
||||
private static byte[] TAB = DocWriter.GetISOBytes("\\tab");
|
||||
/**
|
||||
* Constant for the old list text
|
||||
*/
|
||||
private static byte[] LIST_TEXT = DocWriter.GetISOBytes("\\listtext");
|
||||
/**
|
||||
* Constant for the old list number end
|
||||
*/
|
||||
private static byte[] LIST_NUMBER_END = DocWriter.GetISOBytes(".");
|
||||
|
||||
private const int LIST_TYPE_BULLET = 0;
|
||||
private const int LIST_TYPE_NUMBERED = 1;
|
||||
private const int LIST_TYPE_UPPER_LETTERS = 2;
|
||||
private const int LIST_TYPE_LOWER_LETTERS = 3;
|
||||
private const int LIST_TYPE_UPPER_ROMAN = 4;
|
||||
private const int LIST_TYPE_LOWER_ROMAN = 5;
|
||||
|
||||
/**
|
||||
* The subitems of this RtfList
|
||||
*/
|
||||
private ArrayList items;
|
||||
/**
|
||||
* The level of this RtfList
|
||||
*/
|
||||
private int listLevel = 0;
|
||||
/**
|
||||
* The first indentation of this RtfList
|
||||
*/
|
||||
private int firstIndent = 0;
|
||||
/**
|
||||
* The left indentation of this RtfList
|
||||
*/
|
||||
private int leftIndent = 0;
|
||||
/**
|
||||
* The right indentation of this RtfList
|
||||
*/
|
||||
private int rightIndent = 0;
|
||||
/**
|
||||
* The symbol indentation of this RtfList
|
||||
*/
|
||||
private int symbolIndent = 0;
|
||||
/**
|
||||
* The list number of this RtfList
|
||||
*/
|
||||
private int listNumber = 1;
|
||||
/**
|
||||
* Whether this RtfList is numbered
|
||||
*/
|
||||
private int listType = LIST_TYPE_BULLET;
|
||||
/**
|
||||
* The number to start counting at
|
||||
*/
|
||||
private int listStartAt = 1;
|
||||
/**
|
||||
* The RtfFont for numbered lists
|
||||
*/
|
||||
private ST.RtfFont fontNumber;
|
||||
/**
|
||||
* The RtfFont for bulleted lists
|
||||
*/
|
||||
private ST.RtfFont fontBullet;
|
||||
/**
|
||||
* The alignment of this RtfList
|
||||
*/
|
||||
private int alignment = Element.ALIGN_LEFT;
|
||||
|
||||
/**
|
||||
* The parent List in multi-level lists.
|
||||
*/
|
||||
private RtfList parentList = null;
|
||||
/**
|
||||
* The text to use as the bullet character
|
||||
*/
|
||||
private String bulletCharacter = "\u00b7";
|
||||
|
||||
/**
|
||||
* Constructs a new RtfList for the specified List.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfList belongs to
|
||||
* @param list The List this RtfList is based on
|
||||
*/
|
||||
public RtfList(RtfDocument doc, List list) : base(doc) {
|
||||
|
||||
this.listNumber = document.GetDocumentHeader().GetListNumber(this);
|
||||
|
||||
this.items = new ArrayList();
|
||||
if (list.SymbolIndent > 0 && list.IndentationLeft > 0) {
|
||||
this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1);
|
||||
this.leftIndent = (int) ((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR);
|
||||
} else if (list.SymbolIndent > 0) {
|
||||
this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1);
|
||||
this.leftIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR);
|
||||
} else if (list.IndentationLeft > 0) {
|
||||
this.firstIndent = 0;
|
||||
this.leftIndent = (int) (list.IndentationLeft * RtfElement.TWIPS_FACTOR);
|
||||
} else {
|
||||
this.firstIndent = 0;
|
||||
this.leftIndent = 0;
|
||||
}
|
||||
this.rightIndent = (int) (list.IndentationRight * RtfElement.TWIPS_FACTOR);
|
||||
this.symbolIndent = (int) ((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR);
|
||||
if (list is RomanList) {
|
||||
if (list.Lowercase) {
|
||||
this.listType = LIST_TYPE_LOWER_ROMAN;
|
||||
} else {
|
||||
this.listType = LIST_TYPE_UPPER_ROMAN;
|
||||
}
|
||||
} else if (list.Numbered) {
|
||||
this.listType = LIST_TYPE_NUMBERED;
|
||||
} else if (list.Lettered) {
|
||||
if (list.Lowercase) {
|
||||
this.listType = LIST_TYPE_LOWER_LETTERS;
|
||||
} else {
|
||||
this.listType = LIST_TYPE_UPPER_LETTERS;
|
||||
}
|
||||
}
|
||||
this.listStartAt = list.First;
|
||||
if(this.listStartAt < 1) {
|
||||
this.listStartAt = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.Items.Count; i++) {
|
||||
try {
|
||||
IElement element = (IElement) list.Items[i];
|
||||
if (element.Type == Element.CHUNK) {
|
||||
element = new ListItem((Chunk) element);
|
||||
}
|
||||
if (element is ListItem) {
|
||||
this.alignment = ((ListItem) element).Alignment;
|
||||
}
|
||||
IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element);
|
||||
for(int j = 0; j < rtfElements.Length; j++) {
|
||||
IRtfBasicElement rtfElement = rtfElements[j];
|
||||
if (rtfElement is RtfList) {
|
||||
((RtfList) rtfElement).SetListNumber(listNumber);
|
||||
((RtfList) rtfElement).SetListLevel(listLevel + 1);
|
||||
((RtfList) rtfElement).SetParent(this);
|
||||
} else if (rtfElement is RtfListItem) {
|
||||
((RtfListItem) rtfElement).SetParent(this);
|
||||
((RtfListItem) rtfElement).InheritListSettings(listNumber, listLevel + 1);
|
||||
}
|
||||
items.Add(rtfElement);
|
||||
}
|
||||
} catch (DocumentException ) {
|
||||
}
|
||||
}
|
||||
|
||||
fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
|
||||
if (list.Symbol != null && list.Symbol.Font != null && !list.Symbol.Content.StartsWith("-") && list.Symbol.Content.Length > 0) {
|
||||
// only set this to bullet symbol is not default
|
||||
this.fontBullet = new ST.RtfFont(document, list.Symbol.Font);
|
||||
this.bulletCharacter = list.Symbol.Content.Substring(0, 1);
|
||||
} else {
|
||||
this.fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the indentation values for this <code>RtfList</code>.
|
||||
*
|
||||
* @param result The <code>OutputStream</code> to write to.
|
||||
* @throws IOException On i/o errors.
|
||||
*/
|
||||
private void WriteIndentation(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(LIST_LEVEL_FIRST_INDENT, 0, LIST_LEVEL_FIRST_INDENT.Length);
|
||||
result.Write(t = IntToByteArray(firstIndent), 0, t.Length);
|
||||
result.Write(ST.RtfParagraphStyle.INDENT_LEFT, 0, ST.RtfParagraphStyle.INDENT_LEFT.Length);
|
||||
result.Write(t = IntToByteArray(leftIndent), 0, t.Length);
|
||||
result.Write(ST.RtfParagraphStyle.INDENT_RIGHT, 0, ST.RtfParagraphStyle.INDENT_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray(rightIndent), 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the definition part of this list level
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_LEVEL, 0, LIST_LEVEL.Length);
|
||||
result.Write(LIST_LEVEL_TYPE, 0, LIST_LEVEL_TYPE.Length);
|
||||
switch (this.listType) {
|
||||
case LIST_TYPE_BULLET : result.Write(t = IntToByteArray(23), 0, t.Length); break;
|
||||
case LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(0), 0, t.Length); break;
|
||||
case LIST_TYPE_UPPER_LETTERS : result.Write(t = IntToByteArray(3), 0, t.Length); break;
|
||||
case LIST_TYPE_LOWER_LETTERS : result.Write(t = IntToByteArray(4), 0, t.Length); break;
|
||||
case LIST_TYPE_UPPER_ROMAN : result.Write(t = IntToByteArray(1), 0, t.Length); break;
|
||||
case LIST_TYPE_LOWER_ROMAN : result.Write(t = IntToByteArray(2), 0, t.Length); break;
|
||||
}
|
||||
result.Write(LIST_LEVEL_TYPE_NEW, 0, LIST_LEVEL_TYPE_NEW.Length);
|
||||
switch (this.listType) {
|
||||
case LIST_TYPE_BULLET : result.Write(t = IntToByteArray(23), 0, t.Length); break;
|
||||
case LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(0), 0, t.Length); break;
|
||||
case LIST_TYPE_UPPER_LETTERS : result.Write(t = IntToByteArray(3), 0, t.Length); break;
|
||||
case LIST_TYPE_LOWER_LETTERS : result.Write(t = IntToByteArray(4), 0, t.Length); break;
|
||||
case LIST_TYPE_UPPER_ROMAN : result.Write(t = IntToByteArray(1), 0, t.Length); break;
|
||||
case LIST_TYPE_LOWER_ROMAN : result.Write(t = IntToByteArray(2), 0, t.Length); break;
|
||||
}
|
||||
result.Write(LIST_LEVEL_ALIGNMENT, 0, LIST_LEVEL_ALIGNMENT.Length);
|
||||
result.Write(t = IntToByteArray(0), 0, t.Length);
|
||||
result.Write(LIST_LEVEL_ALIGNMENT_NEW, 0, LIST_LEVEL_ALIGNMENT_NEW.Length);
|
||||
result.Write(t = IntToByteArray(0), 0, t.Length);
|
||||
result.Write(LIST_LEVEL_START_AT, 0, LIST_LEVEL_START_AT.Length);
|
||||
result.Write(t = IntToByteArray(this.listStartAt), 0, t.Length);
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_LEVEL_TEXT, 0, LIST_LEVEL_TEXT.Length);
|
||||
if (this.listType != LIST_TYPE_BULLET) {
|
||||
result.Write(LIST_LEVEL_STYLE_NUMBERED_BEGIN, 0, LIST_LEVEL_STYLE_NUMBERED_BEGIN.Length);
|
||||
if (listLevel < 10) {
|
||||
result.Write(t = IntToByteArray(0), 0, t.Length);
|
||||
}
|
||||
result.Write(t = IntToByteArray(listLevel), 0, t.Length);
|
||||
result.Write(LIST_LEVEL_STYLE_NUMBERED_END, 0, LIST_LEVEL_STYLE_NUMBERED_END.Length);
|
||||
} else {
|
||||
result.Write(LIST_LEVEL_STYLE_BULLETED_BEGIN, 0, LIST_LEVEL_STYLE_BULLETED_BEGIN.Length);
|
||||
this.document.FilterSpecialChar(result, this.bulletCharacter, false, false);
|
||||
result.Write(LIST_LEVEL_STYLE_BULLETED_END, 0, LIST_LEVEL_STYLE_BULLETED_END.Length);
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_LEVEL_NUMBERS_BEGIN, 0, LIST_LEVEL_NUMBERS_BEGIN.Length);
|
||||
if (this.listType != LIST_TYPE_BULLET) {
|
||||
result.Write(LIST_LEVEL_NUMBERS_NUMBERED, 0, LIST_LEVEL_NUMBERS_NUMBERED.Length);
|
||||
}
|
||||
result.Write(LIST_LEVEL_NUMBERS_END, 0, LIST_LEVEL_NUMBERS_END.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(ST.RtfFontList.FONT_NUMBER, 0, ST.RtfFontList.FONT_NUMBER.Length);
|
||||
if (this.listType != LIST_TYPE_BULLET) {
|
||||
result.Write(t = IntToByteArray(fontNumber.GetFontNumber()), 0, t.Length);
|
||||
} else {
|
||||
result.Write(t = IntToByteArray(fontBullet.GetFontNumber()), 0, t.Length);
|
||||
}
|
||||
WriteIndentation(result);
|
||||
result.Write(LIST_LEVEL_SYMBOL_INDENT, 0, LIST_LEVEL_SYMBOL_INDENT.Length);
|
||||
result.Write(t = IntToByteArray(this.leftIndent), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
for (int i = 0; i < items.Count; i++) {
|
||||
RtfElement rtfElement = (RtfElement) items[i];
|
||||
if (rtfElement is RtfList) {
|
||||
RtfList rl = (RtfList)rtfElement;
|
||||
rl.WriteDefinition(result);
|
||||
break;
|
||||
} else if (rtfElement is RtfListItem) {
|
||||
RtfListItem rli = (RtfListItem) rtfElement;
|
||||
if (rli.WriteDefinition(result)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the initialisation part of the RtfList
|
||||
*
|
||||
* @return A byte array containing the initialisation part
|
||||
*/
|
||||
protected internal void WriteListBeginning(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
if (this.inTable) {
|
||||
result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
|
||||
}
|
||||
switch (this.alignment) {
|
||||
case Element.ALIGN_LEFT:
|
||||
result.Write(ST.RtfParagraphStyle.ALIGN_LEFT, 0, ST.RtfParagraphStyle.ALIGN_LEFT.Length);
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
result.Write(ST.RtfParagraphStyle.ALIGN_RIGHT, 0, ST.RtfParagraphStyle.ALIGN_RIGHT.Length);
|
||||
break;
|
||||
case Element.ALIGN_CENTER:
|
||||
result.Write(ST.RtfParagraphStyle.ALIGN_CENTER, 0, ST.RtfParagraphStyle.ALIGN_CENTER.Length);
|
||||
break;
|
||||
case Element.ALIGN_JUSTIFIED:
|
||||
case Element.ALIGN_JUSTIFIED_ALL:
|
||||
result.Write(ST.RtfParagraphStyle.ALIGN_JUSTIFY, 0, ST.RtfParagraphStyle.ALIGN_JUSTIFY.Length);
|
||||
break;
|
||||
}
|
||||
WriteIndentation(result);
|
||||
result.Write(ST.RtfFont.FONT_SIZE, 0, ST.RtfFont.FONT_SIZE.Length);
|
||||
result.Write(t = IntToByteArray(fontNumber.GetFontSize() * 2), 0, t.Length);
|
||||
if (this.symbolIndent > 0) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\tx"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.leftIndent), 0, t.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes only the list number and list level number.
|
||||
*
|
||||
* @return The list number and list level number of this RtfList.
|
||||
*/
|
||||
protected void WriteListNumbers(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(RtfListTable.LIST_NUMBER, 0, RtfListTable.LIST_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(listNumber), 0, t.Length);
|
||||
if (listLevel > 0) {
|
||||
result.Write(LIST_LEVEL_NUMBER, 0, LIST_LEVEL_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(listLevel), 0, t.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the RtfList
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
if (this.listLevel == 0) {
|
||||
CorrectIndentation();
|
||||
}
|
||||
byte[] t;
|
||||
if (!this.inTable) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
}
|
||||
int itemNr = 0;
|
||||
for (int i = 0; i < items.Count; i++) {
|
||||
RtfElement rtfElement = (RtfElement) items[i];
|
||||
if (rtfElement is RtfListItem) {
|
||||
itemNr++;
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_TEXT, 0, LIST_TEXT.Length);
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
if (this.inTable) {
|
||||
result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
|
||||
}
|
||||
result.Write(ST.RtfFontList.FONT_NUMBER, 0, ST.RtfFontList.FONT_NUMBER.Length);
|
||||
if (this.listType != LIST_TYPE_BULLET) {
|
||||
result.Write(t = IntToByteArray(fontNumber.GetFontNumber()), 0, t.Length);
|
||||
} else {
|
||||
result.Write(t = IntToByteArray(fontBullet.GetFontNumber()), 0, t.Length);
|
||||
}
|
||||
WriteIndentation(result);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
if (this.listType != LIST_TYPE_BULLET) {
|
||||
switch (this.listType) {
|
||||
case LIST_TYPE_NUMBERED : result.Write(t = IntToByteArray(itemNr), 0, t.Length); break;
|
||||
case LIST_TYPE_UPPER_LETTERS : result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;
|
||||
case LIST_TYPE_LOWER_LETTERS : result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;
|
||||
case LIST_TYPE_UPPER_ROMAN : result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;
|
||||
case LIST_TYPE_LOWER_ROMAN : result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;
|
||||
}
|
||||
result.Write(LIST_NUMBER_END, 0, LIST_NUMBER_END.Length);
|
||||
} else {
|
||||
this.document.FilterSpecialChar(result, this.bulletCharacter, true, false);
|
||||
}
|
||||
result.Write(TAB, 0, TAB.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
if (i == 0) {
|
||||
WriteListBeginning(result);
|
||||
WriteListNumbers(result);
|
||||
}
|
||||
rtfElement.WriteContent(result);
|
||||
if (i < (items.Count - 1) || !this.inTable || this.listLevel > 0) {
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
}
|
||||
result.WriteByte((byte)'\n');
|
||||
} else if (rtfElement is RtfList) {
|
||||
rtfElement.WriteContent(result);
|
||||
WriteListBeginning(result);
|
||||
WriteListNumbers(result);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
if (!this.inTable) {
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list level of this RtfList
|
||||
*
|
||||
* @return Returns the list level.
|
||||
*/
|
||||
public int GetListLevel() {
|
||||
return listLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list level of this RtfList. A list level > 0 will
|
||||
* unregister this RtfList from the RtfListTable
|
||||
*
|
||||
* @param listLevel The list level to set.
|
||||
*/
|
||||
public void SetListLevel(int listLevel) {
|
||||
this.listLevel = listLevel;
|
||||
if (this.listLevel != 0) {
|
||||
document.GetDocumentHeader().FreeListNumber(this);
|
||||
for (int i = 0; i < this.items.Count; i++) {
|
||||
if (this.items[i] is RtfList) {
|
||||
((RtfList) this.items[i]).SetListNumber(this.listNumber);
|
||||
((RtfList) this.items[i]).SetListLevel(this.listLevel + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.listNumber = document.GetDocumentHeader().GetListNumber(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent RtfList of this RtfList
|
||||
*
|
||||
* @param parent The parent RtfList to use.
|
||||
*/
|
||||
protected internal void SetParent(RtfList parent) {
|
||||
this.parentList = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this list
|
||||
*
|
||||
* @return Returns the list number.
|
||||
*/
|
||||
public int GetListNumber() {
|
||||
return listNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id of this list
|
||||
*
|
||||
* @param listNumber The list number to set.
|
||||
*/
|
||||
public void SetListNumber(int listNumber) {
|
||||
this.listNumber = listNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfList is in a table. Sets the correct inTable setting for all
|
||||
* child elements.
|
||||
*
|
||||
* @param inTable <code>True</code> if this RtfList is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public override void SetInTable(bool inTable) {
|
||||
base.SetInTable(inTable);
|
||||
for (int i = 0; i < this.items.Count; i++) {
|
||||
((IRtfBasicElement) this.items[i]).SetInTable(inTable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfList is in a header. Sets the correct inTable setting for all
|
||||
* child elements.
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfList is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public override void SetInHeader(bool inHeader) {
|
||||
base.SetInHeader(inHeader);
|
||||
for (int i = 0; i < this.items.Count; i++) {
|
||||
((IRtfBasicElement) this.items[i]).SetInHeader(inHeader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct the indentation of this RtfList by adding left/first line indentation
|
||||
* from the parent RtfList. Also calls correctIndentation on all child RtfLists.
|
||||
*/
|
||||
protected internal void CorrectIndentation() {
|
||||
if (this.parentList != null) {
|
||||
this.leftIndent = this.leftIndent + this.parentList.GetLeftIndent() + this.parentList.GetFirstIndent();
|
||||
}
|
||||
for (int i = 0; i < this.items.Count; i++) {
|
||||
if (this.items[i] is RtfList) {
|
||||
((RtfList) this.items[i]).CorrectIndentation();
|
||||
} else if (this.items[i] is RtfListItem) {
|
||||
((RtfListItem) this.items[i]).CorrectIndentation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the left indentation of this RtfList.
|
||||
*
|
||||
* @return The left indentation.
|
||||
*/
|
||||
private int GetLeftIndent() {
|
||||
return this.leftIndent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first line indentation of this RtfList.
|
||||
*
|
||||
* @return The first line indentation.
|
||||
*/
|
||||
private int GetFirstIndent() {
|
||||
return this.firstIndent;
|
||||
}
|
||||
}
|
||||
}
|
||||
187
iTechSharp/iTextSharp/text/rtf/list/RtfListItem.cs
Normal file
187
iTechSharp/iTextSharp/text/rtf/list/RtfListItem.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfListItem.cs,v 1.7 2008/05/16 19:31:02 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004, 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.list {
|
||||
|
||||
/**
|
||||
* The RtfListItem acts as a wrapper for a ListItem.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfListItem : RtfParagraph {
|
||||
|
||||
/**
|
||||
* The RtfList this RtfListItem belongs to.
|
||||
*/
|
||||
private RtfList parentList = null;
|
||||
/**
|
||||
* Whether this RtfListItem contains further RtfLists.
|
||||
*/
|
||||
private bool containsInnerList = false;
|
||||
|
||||
/**
|
||||
* Constructs a RtfListItem for a ListItem belonging to a RtfDocument.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfListItem belongs to.
|
||||
* @param listItem The ListItem this RtfListItem is based on.
|
||||
*/
|
||||
public RtfListItem(RtfDocument doc, ListItem listItem) : base(doc, listItem) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfListItem.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
if (this.paragraphStyle.GetSpacingBefore() > 0) {
|
||||
result.Write(RtfParagraphStyle.SPACING_BEFORE, 0, RtfParagraphStyle.SPACING_BEFORE.Length);
|
||||
result.Write(t = IntToByteArray(paragraphStyle.GetSpacingBefore()), 0, t.Length);
|
||||
}
|
||||
if (this.paragraphStyle.GetSpacingAfter() > 0) {
|
||||
result.Write(RtfParagraphStyle.SPACING_AFTER, 0, RtfParagraphStyle.SPACING_AFTER.Length);
|
||||
result.Write(t = IntToByteArray(this.paragraphStyle.GetSpacingAfter()), 0, t.Length);
|
||||
}
|
||||
for (int i = 0; i < chunks.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) chunks[i];
|
||||
if (rtfElement is RtfChunk) {
|
||||
((RtfChunk) rtfElement).SetSoftLineBreaks(true);
|
||||
} else if (rtfElement is RtfList) {
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
this.containsInnerList = true;
|
||||
}
|
||||
rtfElement.WriteContent(result);
|
||||
if (rtfElement is RtfList) {
|
||||
this.parentList.WriteListBeginning(result);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\tab"), 0, t.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the definition of the first element in this RtfListItem that is
|
||||
* an instanceof {@link RtfList} to the given stream.<br>
|
||||
* If this item does not contain a {@link RtfList} element nothing is written
|
||||
* and the method returns <code>false</code>.
|
||||
*
|
||||
* @param out destination stream
|
||||
* @return <code>true</code> if a RtfList definition was written, <code>false</code> otherwise
|
||||
* @throws IOException
|
||||
* @see {@link RtfList#writeDefinition(OutputStream)}
|
||||
*/
|
||||
public bool WriteDefinition(Stream outp) {
|
||||
for (int i = 0; i < chunks.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i];
|
||||
if (rtfElement is RtfList) {
|
||||
RtfList rl = (RtfList)rtfElement;
|
||||
rl.WriteDefinition(outp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit the list settings from the parent list to RtfLists that
|
||||
* are contained in this RtfListItem.
|
||||
*
|
||||
* @param listNumber The list number to inherit.
|
||||
* @param listLevel The list level to inherit.
|
||||
*/
|
||||
public void InheritListSettings(int listNumber, int listLevel) {
|
||||
for (int i = 0; i < chunks.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) chunks[i];
|
||||
if (rtfElement is RtfList) {
|
||||
((RtfList) rtfElement).SetListNumber(listNumber);
|
||||
((RtfList) rtfElement).SetListLevel(listLevel);
|
||||
((RtfList) rtfElement).SetParent(this.parentList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct the indentation of RtfLists in this RtfListItem by adding left/first line indentation
|
||||
* from the parent RtfList. Also calls correctIndentation on all child RtfLists.
|
||||
*/
|
||||
protected internal void CorrectIndentation() {
|
||||
for (int i = 0; i < chunks.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) chunks[i];
|
||||
if (rtfElement is RtfList) {
|
||||
((RtfList) rtfElement).CorrectIndentation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parent RtfList.
|
||||
*
|
||||
* @param parentList The parent RtfList to use.
|
||||
*/
|
||||
public void SetParent(RtfList parentList) {
|
||||
this.parentList = parentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this RtfListItem contains further RtfLists.
|
||||
*
|
||||
* @return Whether this RtfListItem contains further RtfLists.
|
||||
*/
|
||||
public bool IsContainsInnerList() {
|
||||
return this.containsInnerList;
|
||||
}
|
||||
}
|
||||
}
|
||||
198
iTechSharp/iTextSharp/text/rtf/list/RtfListTable.cs
Normal file
198
iTechSharp/iTextSharp/text/rtf/list/RtfListTable.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfListTable.cs,v 1.6 2008/05/16 19:31:04 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.list {
|
||||
|
||||
/**
|
||||
* The RtfListTable manages all RtfLists in one RtfDocument. It also generates
|
||||
* the list and list override tables in the document header.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfListTable : RtfElement, IRtfExtendedElement {
|
||||
|
||||
/**
|
||||
* Constant for the list number
|
||||
*/
|
||||
protected internal static byte[] LIST_NUMBER = DocWriter.GetISOBytes("\\ls");
|
||||
/**
|
||||
* Constant for the list table
|
||||
*/
|
||||
private static byte[] LIST_TABLE = DocWriter.GetISOBytes("\\*\\listtable");
|
||||
/**
|
||||
* Constant for the list
|
||||
*/
|
||||
private static byte[] LIST = DocWriter.GetISOBytes("\\list");
|
||||
/**
|
||||
* Constant for the list template id
|
||||
*/
|
||||
private static byte[] LIST_TEMPLATE_ID = DocWriter.GetISOBytes("\\listtemplateid");
|
||||
/**
|
||||
* Constant for the hybrid list
|
||||
*/
|
||||
private static byte[] LIST_HYBRID = DocWriter.GetISOBytes("\\listhybrid");
|
||||
/**
|
||||
* Constant for the list id
|
||||
*/
|
||||
private static byte[] LIST_ID = DocWriter.GetISOBytes("\\listid");
|
||||
/**
|
||||
* Constant for the list override table
|
||||
*/
|
||||
private static byte[] LIST_OVERRIDE_TABLE = DocWriter.GetISOBytes("\\*\\listoverridetable");
|
||||
/**
|
||||
* Constant for the list override
|
||||
*/
|
||||
private static byte[] LIST_OVERRIDE = DocWriter.GetISOBytes("\\listoverride");
|
||||
/**
|
||||
* Constant for the list override count
|
||||
*/
|
||||
private static byte[] LIST_OVERRIDE_COUNT = DocWriter.GetISOBytes("\\listoverridecount");
|
||||
|
||||
/**
|
||||
* The RtfLists managed by this RtfListTable
|
||||
*/
|
||||
private ArrayList lists;
|
||||
|
||||
/**
|
||||
* Constructs a RtfListTable for a RtfDocument
|
||||
*
|
||||
* @param doc The RtfDocument this RtfListTable belongs to
|
||||
*/
|
||||
public RtfListTable(RtfDocument doc) : base(doc) {
|
||||
this.lists = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* unused
|
||||
*/
|
||||
public override void WriteContent(Stream outp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the list and list override tables.
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
byte[] t;
|
||||
int[] listIds = new int[lists.Count];
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_TABLE, 0, LIST_TABLE.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
for (int i = 0; i < lists.Count; i++) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST, 0, LIST.Length);
|
||||
result.Write(LIST_TEMPLATE_ID, 0, LIST_TEMPLATE_ID.Length);
|
||||
result.Write(t = IntToByteArray(document.GetRandomInt()), 0, t.Length);
|
||||
result.Write(LIST_HYBRID, 0, LIST_HYBRID.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
RtfList rList = (RtfList)lists[i];
|
||||
rList.WriteDefinition(result);
|
||||
result.Write(LIST_ID, 0, LIST_ID.Length);
|
||||
listIds[i] = document.GetRandomInt();
|
||||
result.Write(t = IntToByteArray(listIds[i]), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_OVERRIDE_TABLE, 0, LIST_OVERRIDE_TABLE.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
for (int i = 0; i < lists.Count; i++) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(LIST_OVERRIDE, 0, LIST_OVERRIDE.Length);
|
||||
result.Write(LIST_ID, 0, LIST_ID.Length);
|
||||
result.Write(t = IntToByteArray(listIds[i]), 0, t.Length);
|
||||
result.Write(LIST_OVERRIDE_COUNT, 0, LIST_OVERRIDE_COUNT.Length);
|
||||
result.Write(t = IntToByteArray(0), 0, t.Length);
|
||||
result.Write(LIST_NUMBER, 0, LIST_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(((RtfList) lists[i]).GetListNumber()), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the specified RtfList. If the RtfList is not yet in the
|
||||
* list of RtfLists, then it is added.
|
||||
*
|
||||
* @param list The RtfList for which to get the id.
|
||||
* @return The id of the RtfList.
|
||||
*/
|
||||
public int GetListNumber(RtfList list) {
|
||||
if (lists.Contains(list)) {
|
||||
return lists.IndexOf(list);
|
||||
} else {
|
||||
lists.Add(list);
|
||||
return lists.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a RtfList from the list of RtfLists
|
||||
*
|
||||
* @param list The RtfList to remove.
|
||||
*/
|
||||
public void FreeListNumber(RtfList list) {
|
||||
int i = lists.IndexOf(list);
|
||||
if (i >= 0) {
|
||||
lists.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
86
iTechSharp/iTextSharp/text/rtf/parser/PushbackStream.cs
Normal file
86
iTechSharp/iTextSharp/text/rtf/parser/PushbackStream.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace iTextSharp.text.rtf.parser {
|
||||
public class PushbackStream : Stream {
|
||||
private int buf = -1;
|
||||
private readonly Stream s;
|
||||
|
||||
public PushbackStream(Stream s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return s.CanRead; }
|
||||
}
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return s.CanSeek; }
|
||||
}
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return s.CanWrite; }
|
||||
}
|
||||
public override long Length
|
||||
{
|
||||
get { return s.Length; }
|
||||
}
|
||||
public override long Position
|
||||
{
|
||||
get { return s.Position; }
|
||||
set { s.Position = value; }
|
||||
}
|
||||
public override void Close()
|
||||
{
|
||||
s.Close();
|
||||
}
|
||||
public override void Flush()
|
||||
{
|
||||
s.Flush();
|
||||
}
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
return s.Seek(offset, origin);
|
||||
}
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
s.SetLength(value);
|
||||
}
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
s.Write(buffer, offset, count);
|
||||
}
|
||||
public override void WriteByte(byte value)
|
||||
{
|
||||
s.WriteByte(value);
|
||||
}
|
||||
public override int ReadByte() {
|
||||
if (buf != -1) {
|
||||
int tmp = buf;
|
||||
buf = -1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return s.ReadByte();
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
||||
if (buf != -1 && count > 0) {
|
||||
// TODO Can this case be made more efficient?
|
||||
buffer[offset] = (byte) buf;
|
||||
buf = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return s.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
public virtual void Unread(int b) {
|
||||
if (buf != -1)
|
||||
throw new InvalidOperationException("Can only push back one byte");
|
||||
|
||||
buf = b & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
170
iTechSharp/iTextSharp/text/rtf/parser/RtfImportMappings.cs
Normal file
170
iTechSharp/iTextSharp/text/rtf/parser/RtfImportMappings.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
|
||||
/*
|
||||
* $Id: RtfImportMappings.cs,v 1.3 2008/05/16 19:31:06 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.parser {
|
||||
|
||||
/**
|
||||
* The RtfImportMappings make it possible to define font
|
||||
* and color mappings when using the RtfWriter2.importRtfFragment
|
||||
* method. This is necessary, because a RTF fragment does not
|
||||
* contain font or color information, just references to the
|
||||
* font and color tables.<br /><br />
|
||||
*
|
||||
* The font mappings are fontNr -> fontName and the color
|
||||
* mappigns are colorNr -> Color.
|
||||
*
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public class RtfImportMappings {
|
||||
/**
|
||||
* The fontNr to fontName mappings.
|
||||
*/
|
||||
private Hashtable fontMappings = null;
|
||||
/**
|
||||
* The colorNr to Color mappings.
|
||||
*/
|
||||
private Hashtable colorMappings = null;
|
||||
/**
|
||||
* The listNr to List mappings.
|
||||
*/
|
||||
private Hashtable listMappings = null;
|
||||
/**
|
||||
* The sytlesheetListNr to Stylesheet mappings.
|
||||
*/
|
||||
private Hashtable stylesheetListMappings = null;
|
||||
|
||||
/**
|
||||
* Constructs a new RtfImportMappings initialising the mappings.
|
||||
*/
|
||||
public RtfImportMappings() {
|
||||
this.fontMappings = new Hashtable();
|
||||
this.colorMappings = new Hashtable();
|
||||
this.listMappings = new Hashtable();
|
||||
this.stylesheetListMappings = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a font to the list of mappings.
|
||||
*
|
||||
* @param fontNr The font number.
|
||||
* @param fontName The font name.
|
||||
*/
|
||||
public void AddFont(String fontNr, String fontName) {
|
||||
this.fontMappings[fontNr] = fontName;
|
||||
}
|
||||
/**
|
||||
* Add a color to the list of mappings.
|
||||
*
|
||||
* @param colorNr The color number.
|
||||
* @param color The Color.
|
||||
*/
|
||||
public void AddColor(String colorNr, Color color) {
|
||||
this.colorMappings[colorNr] = color;
|
||||
}
|
||||
/**
|
||||
* Add a List to the list of mappings.
|
||||
*
|
||||
* @param listNr The List number.
|
||||
* @param list The List.
|
||||
*/
|
||||
public void AddList(String listNr, Color list) {
|
||||
this.listMappings[listNr] = list;
|
||||
}
|
||||
/**
|
||||
* Add a Stylesheet List to the list of mappings.
|
||||
*
|
||||
* @param stylesheetListNr The Stylesheet List number.
|
||||
* @param list The StylesheetList.
|
||||
*/
|
||||
public void AddStylesheetList(String stylesheetListNr, Color list) {
|
||||
this.stylesheetListMappings[stylesheetListNr] = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of font mappings. String to String.
|
||||
*
|
||||
* @return The font mappings.
|
||||
*/
|
||||
public Hashtable GetFontMappings() {
|
||||
return this.fontMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of color mappings. String to Color.
|
||||
*
|
||||
* @return The color mappings.
|
||||
*/
|
||||
public Hashtable GetColorMappings() {
|
||||
return this.colorMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of List mappings.
|
||||
*
|
||||
* @return The List mappings.
|
||||
*/
|
||||
public Hashtable GetListMappings() {
|
||||
return this.listMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of Stylesheet mappings. .
|
||||
*
|
||||
* @return The Stylesheet List mappings.
|
||||
*/
|
||||
public Hashtable GetStylesheetListMappings() {
|
||||
return this.stylesheetListMappings;
|
||||
}
|
||||
}
|
||||
}
|
||||
281
iTechSharp/iTextSharp/text/rtf/parser/RtfImportMgr.cs
Normal file
281
iTechSharp/iTextSharp/text/rtf/parser/RtfImportMgr.cs
Normal file
@@ -0,0 +1,281 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.list;
|
||||
using iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfImportMgr.cs,v 1.3 2008/05/16 19:31:07 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.parser {
|
||||
|
||||
/**
|
||||
* The RtfImportHeader stores the docment header information from
|
||||
* an RTF document that is being imported. Currently font and
|
||||
* color settings are stored. The RtfImportHeader maintains a mapping
|
||||
* from font and color numbers from the imported RTF document to
|
||||
* the RTF document that is the target of the import. This guarantees
|
||||
* that the merged document has the correct font and color settings.
|
||||
* It also handles other list based items that need mapping, for example
|
||||
* stylesheets and lists.
|
||||
*
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*/
|
||||
public class RtfImportMgr {
|
||||
//TODO: Add list, stylesheet, info, etc. mappings
|
||||
/**
|
||||
* The Hashtable storing the font number mappings.
|
||||
*/
|
||||
private Hashtable importFontMapping = null;
|
||||
/**
|
||||
* The Hashtable storing the color number mapings.
|
||||
*/
|
||||
private Hashtable importColorMapping = null;
|
||||
/**
|
||||
* The Hashtable storing the Stylesheet List number mapings.
|
||||
*/
|
||||
private Hashtable importStylesheetListMapping = null;
|
||||
/**
|
||||
* The Hashtable storing the List number mapings.
|
||||
*/
|
||||
private Hashtable importListMapping = null;
|
||||
/**
|
||||
* The RtfDocument to get font and color numbers from.
|
||||
*/
|
||||
private RtfDocument rtfDoc = null;
|
||||
/**
|
||||
* The Document.
|
||||
* Used for conversions, but not imports.
|
||||
*/
|
||||
private Document doc = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new RtfImportHeader.
|
||||
*
|
||||
* @param rtfDoc The RtfDocument to get font and color numbers from.
|
||||
*/
|
||||
public RtfImportMgr(RtfDocument rtfDoc, Document doc) {
|
||||
this.rtfDoc = rtfDoc;
|
||||
this.doc = doc;
|
||||
this.importFontMapping = new Hashtable();
|
||||
this.importColorMapping = new Hashtable();
|
||||
this.importStylesheetListMapping = new Hashtable();
|
||||
this.importListMapping = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a font. The font name is looked up in the RtfDocumentHeader and
|
||||
* then the mapping from original font number to actual font number is added.
|
||||
*
|
||||
* @param fontNr The original font number.
|
||||
* @param fontName The font name to look up.
|
||||
*/
|
||||
public bool ImportFont(String fontNr, String fontName) {
|
||||
RtfFont rtfFont = new RtfFont(fontName);
|
||||
if (rtfFont != null){
|
||||
rtfFont.SetRtfDocument(this.rtfDoc);
|
||||
this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Imports a font. The font name is looked up in the RtfDocumentHeader and
|
||||
* then the mapping from original font number to actual font number is added.
|
||||
*
|
||||
* @param fontNr The original font number.
|
||||
* @param fontName The font name to look up.
|
||||
* @param charset The characterset to use for the font.
|
||||
*/
|
||||
public bool ImportFont(String fontNr, String fontName, int charset) {
|
||||
RtfFont rtfFont = new RtfFont(fontName);
|
||||
if (charset>= 0)
|
||||
rtfFont.SetCharset(charset);
|
||||
if (rtfFont != null){
|
||||
rtfFont.SetRtfDocument(this.rtfDoc);
|
||||
this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Imports a font. The font name is looked up in the RtfDocumentHeader and
|
||||
* then the mapping from original font number to actual font number is added.
|
||||
*
|
||||
* @param fontNr The original font number.
|
||||
* @param fontName The font name to look up.
|
||||
* @param charset The characterset to use for the font.
|
||||
*/
|
||||
public bool ImportFont(String fontNr, String fontName, String fontFamily, int charset) {
|
||||
RtfFont rtfFont = new RtfFont(fontName);
|
||||
|
||||
if (charset>= 0)
|
||||
rtfFont.SetCharset(charset);
|
||||
if (fontFamily != null && fontFamily.Length > 0)
|
||||
rtfFont.SetFamily(fontFamily);
|
||||
if (rtfFont != null){
|
||||
rtfFont.SetRtfDocument(this.rtfDoc);
|
||||
this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Performs the mapping from the original font number to the actual
|
||||
* font number in the resulting RTF document. If the font number was not
|
||||
* seen during import (thus no mapping) then 0 is returned, guaranteeing
|
||||
* that the font number is always valid.
|
||||
*
|
||||
* @param fontNr The font number to map.
|
||||
* @return The mapped font number.
|
||||
*/
|
||||
public String MapFontNr(String fontNr) {
|
||||
if (this.importFontMapping.ContainsKey(fontNr)) {
|
||||
return (String) this.importFontMapping[fontNr];
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a color value. The color number for the color defined
|
||||
* by its red, green and blue values is determined and then the
|
||||
* resulting mapping is added.
|
||||
*
|
||||
* @param colorNr The original color number.
|
||||
* @param color The color to import.
|
||||
*/
|
||||
public void ImportColor(String colorNr, Color color) {
|
||||
RtfColor rtfColor = new RtfColor(this.rtfDoc, color);
|
||||
this.importColorMapping[colorNr] = rtfColor.GetColorNumber().ToString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the mapping from the original font number to the actual font
|
||||
* number used in the RTF document. If the color number was not
|
||||
* seen during import (thus no mapping) then 0 is returned, guaranteeing
|
||||
* that the color number is always valid.
|
||||
*
|
||||
* @param colorNr The color number to map.
|
||||
* @return The mapped color number
|
||||
*/
|
||||
public String MapColorNr(String colorNr) {
|
||||
if (this.importColorMapping.ContainsKey(colorNr)) {
|
||||
return (String) this.importColorMapping[colorNr];
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a List value. The List number for the List defined
|
||||
* is determined and then the resulting mapping is added.
|
||||
*/
|
||||
public void ImportList(String listNr, List list) {
|
||||
RtfList rtfList = new RtfList(this.rtfDoc, list);
|
||||
|
||||
//if(rtfList != null){
|
||||
//rtfList.SetRtfDocument(this.rtfDoc);
|
||||
this.importStylesheetListMapping[listNr] = this.rtfDoc.GetDocumentHeader().GetListNumber(rtfList).ToString();
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the mapping from the original list number to the actual
|
||||
* list number in the resulting RTF document. If the list number was not
|
||||
* seen during import (thus no mapping) then 0 is returned, guaranteeing
|
||||
* that the list number is always valid.
|
||||
*/
|
||||
public String MapListNr(String listNr) {
|
||||
if (this.importListMapping.ContainsKey(listNr)) {
|
||||
return (String) this.importListMapping[listNr];
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a stylesheet list value. The stylesheet number for the stylesheet defined
|
||||
* is determined and then the resulting mapping is added.
|
||||
*/
|
||||
public bool ImportStylesheetList(String listNr, List listIn) {
|
||||
RtfList rtfList = new RtfList(this.rtfDoc, listIn);
|
||||
|
||||
if (rtfList != null){
|
||||
rtfList.SetRtfDocument(this.rtfDoc);
|
||||
//this.importStylesheetListMapping[listNr] = Integer.ToString(this.rtfDoc.GetDocumentHeader().GetRtfParagraphStyle(styleName)(rtfList));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Performs the mapping from the original stylesheet number to the actual
|
||||
* stylesheet number in the resulting RTF document. If the stylesheet number was not
|
||||
* seen during import (thus no mapping) then 0 is returned, guaranteeing
|
||||
* that the stylesheet number is always valid.
|
||||
*/
|
||||
public String MapStylesheetListNr(String listNr) {
|
||||
if (this.importStylesheetListMapping.ContainsKey(listNr)) {
|
||||
return (String) this.importStylesheetListMapping[listNr];
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1457
iTechSharp/iTextSharp/text/rtf/parser/RtfParser.cs
Normal file
1457
iTechSharp/iTextSharp/text/rtf/parser/RtfParser.cs
Normal file
File diff suppressed because it is too large
Load Diff
138
iTechSharp/iTextSharp/text/rtf/parser/RtfParserState.cs
Normal file
138
iTechSharp/iTextSharp/text/rtf/parser/RtfParserState.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
using iTextSharp.text.rtf.parser.destinations;
|
||||
using iTextSharp.text.rtf.parser.properties;
|
||||
/*
|
||||
* $Id: RtfParserState.cs,v 1.2 2008/05/13 11:25:58 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.parser {
|
||||
|
||||
/**
|
||||
* The <code>RtfParserState</code> contains the state information
|
||||
* for the parser. The current state object is pushed/popped in a stack
|
||||
* when a group change is made.
|
||||
*
|
||||
* When an open group is encountered, the current state is copied and
|
||||
* then pushed on the top of the stack
|
||||
* When a close group is encountered, the current state is overwritten with
|
||||
* the popped value from the top of the stack
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfParserState {
|
||||
/**
|
||||
* The parser state.
|
||||
*/
|
||||
public int parserState = RtfParser.PARSER_IN_UNKNOWN;
|
||||
/**
|
||||
* The tokeniser state.
|
||||
*/
|
||||
public int tokeniserState = RtfParser.TOKENISER_STATE_IN_UNKOWN;
|
||||
/**
|
||||
* The control word set as the group handler.
|
||||
*/
|
||||
public Object groupHandler = null;
|
||||
/**
|
||||
* The parsed value for the current group/control word.
|
||||
*/
|
||||
public StringBuilder text = null;
|
||||
/**
|
||||
* Stack containing control word handlers. There could be multiple
|
||||
* control words in a group.
|
||||
*/
|
||||
public Stack ctrlWordHandlers = null;
|
||||
/**
|
||||
* The current control word handler.
|
||||
*/
|
||||
public Object ctrlWordHandler = null;
|
||||
/**
|
||||
* The current destination.
|
||||
*/
|
||||
public RtfDestination destination = null;
|
||||
/**
|
||||
* Flag indicating if this is an extended destination \* control word
|
||||
*/
|
||||
public bool isExtendedDestination = false;
|
||||
/**
|
||||
* Flag to indicate if last token was an open group token '{'
|
||||
*/
|
||||
public bool newGroup = false;
|
||||
|
||||
public RtfProperty properties = null;
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
*/
|
||||
public RtfParserState() {
|
||||
this.text = new StringBuilder();
|
||||
this.ctrlWordHandlers = new Stack();
|
||||
this.properties = new RtfProperty();
|
||||
this.destination = RtfDestinationNull.GetInstance();
|
||||
this.newGroup = false;
|
||||
}
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param orig The object to copy
|
||||
*/
|
||||
public RtfParserState(RtfParserState orig) {
|
||||
this.properties = orig.properties;
|
||||
this.parserState = orig.parserState;
|
||||
this.tokeniserState = orig.tokeniserState;
|
||||
this.groupHandler = null;
|
||||
this.destination = orig.destination;
|
||||
this.text = new StringBuilder();
|
||||
this.ctrlWordHandlers = new Stack();
|
||||
this.destination = orig.destination;
|
||||
this.newGroup = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
/*
|
||||
* $Id: IRtfCtrlWordListener.cs,v 1.2 2008/05/13 11:25:58 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.parser.ctrlwords {
|
||||
|
||||
/**
|
||||
* <code>RtfCtrlWordListener</code> interface for handling events.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public interface IRtfCtrlWordListener : IEventListener {
|
||||
/**
|
||||
*
|
||||
* @return null or modified copy of the ctrlWordData object
|
||||
*/
|
||||
RtfCtrlWordData BeforeCtrlWord(RtfCtrlWordData ctrlWordData);
|
||||
/**
|
||||
*
|
||||
* @return null or modified copy of the ctrlWordData object
|
||||
*/
|
||||
RtfCtrlWordData OnCtrlWord(RtfCtrlWordData ctrlWordData);
|
||||
/**
|
||||
*
|
||||
* @return null or modified copy of the ctrlWordData object
|
||||
*/
|
||||
RtfCtrlWordData AfterCtrlWord(RtfCtrlWordData ctrlWordData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.parser.properties;
|
||||
/* $Id: RtfCtrlWordData.cs,v 1.2 2008/05/13 11:25:58 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.parser.ctrlwords {
|
||||
|
||||
/**
|
||||
* The control word and parameter information as parsed by the parser.
|
||||
* Contains the control word,
|
||||
* Flag indicating if there is a parameter.
|
||||
* The parameter value as a string.
|
||||
* Flag indicating the parameter is positive or negative.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfCtrlWordData {
|
||||
public String prefix = "";
|
||||
public String suffix = "";
|
||||
/**
|
||||
* The control word found by the parser
|
||||
*/
|
||||
public String ctrlWord = "";
|
||||
/**
|
||||
* Flag indicating if this keyword has a parameter.
|
||||
*/
|
||||
public bool hasParam = false;
|
||||
/**
|
||||
* The parameter for the control word.
|
||||
*/
|
||||
public String param = "";
|
||||
/**
|
||||
* Flag indicating if parameter is positive or negative.
|
||||
*/
|
||||
public bool isNeg = false;
|
||||
/**
|
||||
* Flag indicating a new group
|
||||
*/
|
||||
public bool newGroup = false;
|
||||
/**
|
||||
* Flag indicating if this object has been modified.
|
||||
*/
|
||||
public bool modified = false;
|
||||
|
||||
public int ctrlWordType = RtfCtrlWordType.UNIDENTIFIED;
|
||||
public String specialHandler = "";
|
||||
|
||||
/**
|
||||
* Return the parameter value as an integer (int) value.
|
||||
*
|
||||
* @return
|
||||
* Returns the parameter value as an int vlaue.
|
||||
*/
|
||||
public int IntValue() {
|
||||
int value;
|
||||
value = int.Parse(this.param);
|
||||
if (this.isNeg) value = (-value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parameter value as a long value
|
||||
*
|
||||
* @return
|
||||
* Returns the parameter value as a long value
|
||||
*/
|
||||
public long LongValue() {
|
||||
long value;
|
||||
value = long.Parse(this.param);
|
||||
if (this.isNeg) value = (-value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
String outp = "";
|
||||
outp = this.prefix + this.ctrlWord;
|
||||
if (this.hasParam) {
|
||||
if (this.isNeg) outp += "-";
|
||||
outp += this.param;
|
||||
}
|
||||
outp += this.suffix;
|
||||
return outp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.destinations;
|
||||
using iTextSharp.text.rtf.parser.properties;
|
||||
using iTextSharp.text.rtf.direct;
|
||||
|
||||
/* $Id: RtfCtrlWordHandler.cs,v 1.3 2008/05/13 11:25:58 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.parser.ctrlwords {
|
||||
|
||||
/**
|
||||
* <code>RtfCtrlWordBase</code> is the base class for all
|
||||
* control word handlers to extend from.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfCtrlWordHandler {
|
||||
/**
|
||||
* Debug flag - internal use
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private static bool debug = false;
|
||||
|
||||
/**
|
||||
* Local variable referencing the parser object.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected RtfParser rtfParser = null;
|
||||
/**
|
||||
* The control word for this class.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected String ctrlWord = "";
|
||||
/**
|
||||
* The default value for this control word.
|
||||
* Not all control words use a default parameter value.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected int defaultParameterValue = 0;
|
||||
/**
|
||||
* Does this control word use the default value?
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected bool passDefaultParameterValue = false;
|
||||
/**
|
||||
* Control Word type. Destination, toggle, value, etc.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected int ctrlWordType = RtfCtrlWordType.UNIDENTIFIED;
|
||||
/**
|
||||
* Class, property, etc.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected String specialHandler = "";
|
||||
/**
|
||||
* What version of the RTF spec the control word was introduced.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected float rtfVersionSupported = -1.0f; // -1.0 unknown. Each class should override this as implemented.
|
||||
/**
|
||||
* The control word as parsed by the parser.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected RtfCtrlWordData ctrlWordData = null;
|
||||
/**
|
||||
* String containing the value of "{" or "" (blank) depending on if this is the
|
||||
* first control word in a group.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected String groupPrefix = "";
|
||||
/**
|
||||
* The prefix for all control words.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected String ctrlWordPrefix = "\\";
|
||||
/**
|
||||
* The prefix for all control words.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected String ctrlWordSuffix = " ";
|
||||
|
||||
/**
|
||||
* Constructor:
|
||||
*
|
||||
* @param rtfParser
|
||||
* The parser for this control word.
|
||||
* @param ctrlWord
|
||||
* The string value of this control word.
|
||||
* @param defaultParameterValue
|
||||
* The default value of this control word. Not all control words have values.
|
||||
* @param passDefaultParameterValue
|
||||
* Flag indicating if this control word should use the default value.
|
||||
* @param ctrlWordType
|
||||
* Indicator of the type of control word this is. DESTINATION|DESTINATION_EX|VALUE|FLAG|TOGGLE|SYMBOL
|
||||
* @param prefix
|
||||
* String to prefix the ctrl word with. "\" or "\*\" are the 2 used values.
|
||||
* @param suffix
|
||||
* String to add as suffix to the ctrl word. " " and "" are the 2 used values.
|
||||
* @param specialHandler
|
||||
* If TOGGLE then the property name as String (propertyGroup.propertyName format ex. "character.bold")
|
||||
* If FLAG then the property name as String (propertyGroup.propertyName format ex. "character.bold")
|
||||
* If VALUE then the property name as String (propertyGroup.propertyName format ex. "character.bold")
|
||||
* If SYMBOL then the character to use for substitution as String
|
||||
* If DESTINATION|DESTINATION_EX then the RtfDestination class name as String
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public RtfCtrlWordHandler(RtfParser rtfParser, String ctrlWord, int defaultParameterValue, bool passDefaultParameterValue,
|
||||
int ctrlWordType, String prefix, String suffix, String specialHandler) {
|
||||
this.rtfParser = rtfParser;
|
||||
this.ctrlWord = ctrlWord;
|
||||
this.defaultParameterValue = defaultParameterValue;
|
||||
this.passDefaultParameterValue = passDefaultParameterValue;
|
||||
this.ctrlWordType = ctrlWordType;
|
||||
this.ctrlWordPrefix = prefix;
|
||||
this.ctrlWordSuffix = suffix;
|
||||
this.specialHandler = specialHandler;
|
||||
|
||||
if (this.ctrlWordType == RtfCtrlWordType.DESTINATION || this.ctrlWordType == RtfCtrlWordType.DESTINATION_EX){
|
||||
if (this.specialHandler == null) {
|
||||
this.specialHandler = "RtfDestinationNull";
|
||||
}
|
||||
String arg1 = ""; // stylesheet value - S, CS, TS
|
||||
RtfDestinationMgr.AddDestination(this.ctrlWord, new Object[] { this.specialHandler, arg1 });
|
||||
} else {
|
||||
if (this.ctrlWordType == RtfCtrlWordType.SYMBOL){
|
||||
|
||||
} else {
|
||||
if (this.specialHandler == null) {
|
||||
this.specialHandler = this.ctrlWord; // if null, make the property the name of the ctrl word
|
||||
} else {
|
||||
if (this.specialHandler.Length > 1 && this.specialHandler.EndsWith(".")) {
|
||||
this.specialHandler += this.ctrlWord; // if string length>1 and ends with a period, it's a group. Add ctrlWord
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The primary control word handler method.
|
||||
* Called by the parser once it has a control word and parameter if applicable.
|
||||
*
|
||||
* @param ctrlWordDataIn
|
||||
* The control word and associated parameter if applicable.
|
||||
* @return
|
||||
* <code>true</code> or <code>false</code> if the control word was handled.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public bool HandleControlword(RtfCtrlWordData ctrlWordDataIn){
|
||||
bool result = false;
|
||||
this.ctrlWordData = ctrlWordDataIn;
|
||||
RtfDestination dest = null;
|
||||
bool handled = false;
|
||||
|
||||
this.ctrlWordData.prefix = this.ctrlWordPrefix;
|
||||
this.ctrlWordData.suffix = this.ctrlWordSuffix;
|
||||
this.ctrlWordData.newGroup = this.rtfParser.GetState().newGroup;
|
||||
this.ctrlWordData.ctrlWordType = this.ctrlWordType;
|
||||
this.ctrlWordData.specialHandler = this.specialHandler;
|
||||
|
||||
if (!this.ctrlWordData.hasParam && this.passDefaultParameterValue) {
|
||||
this.ctrlWordData.hasParam = true;
|
||||
this.ctrlWordData.param = this.defaultParameterValue.ToString();
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
PrintDebug("handleKeyword: [" + this.ctrlWordData.ctrlWord + "] param=" + ctrlWordDataIn.param);
|
||||
RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel()+1, "RtfCtrlWordHandler debug Start: " + this.ctrlWordData.ctrlWord + " ");
|
||||
}
|
||||
if (this.ctrlWordData.ctrlWord.Equals("*")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!BeforeControlWord()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (this.ctrlWordType) {
|
||||
case RtfCtrlWordType.FLAG:
|
||||
case RtfCtrlWordType.TOGGLE:
|
||||
case RtfCtrlWordType.VALUE:
|
||||
dest = (RtfDestination)this.rtfParser.GetCurrentDestination();
|
||||
if (dest != null) {
|
||||
handled = dest.HandleControlWord(this.ctrlWordData);
|
||||
}
|
||||
break;
|
||||
|
||||
case RtfCtrlWordType.SYMBOL:
|
||||
dest = (RtfDestination)this.rtfParser.GetCurrentDestination();
|
||||
if (dest != null) {
|
||||
String data = null;
|
||||
// if doing an import, then put the control word in the output stream through the character handler
|
||||
if (this.rtfParser.IsImport()) {
|
||||
data = this.ctrlWordPrefix + this.ctrlWordData.ctrlWord + this.ctrlWordSuffix;
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
data = this.specialHandler;
|
||||
}
|
||||
|
||||
// If there is a substitute character, process the character.
|
||||
// If no substitute character, then provide special handling in the destination for the ctrl word.
|
||||
if (data != null) {
|
||||
foreach (char cc in data.ToCharArray()) {
|
||||
handled = dest.HandleCharacter((int)cc);
|
||||
}
|
||||
} else {
|
||||
handled = dest.HandleControlWord(this.ctrlWordData);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RtfCtrlWordType.DESTINATION_EX:
|
||||
case RtfCtrlWordType.DESTINATION:
|
||||
// set the destination
|
||||
int x=0;
|
||||
if(this.ctrlWord == "shppict" || this.ctrlWord == "nonshppict") {
|
||||
x++;
|
||||
}
|
||||
handled = this.rtfParser.SetCurrentDestination(this.ctrlWord);
|
||||
// let destination handle the ctrl word now.
|
||||
dest = (RtfDestination)this.rtfParser.GetCurrentDestination();
|
||||
if(dest != null) {
|
||||
if(dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT) {
|
||||
handled = dest.HandleControlWord(this.ctrlWordData);
|
||||
}
|
||||
else {
|
||||
this.rtfParser.SetTokeniserState(dest.GetNewTokeniserState());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
AfterControlWord();
|
||||
|
||||
if (debug) {
|
||||
RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel()+1, "RtfCtrlWordHandler debug End: " + this.ctrlWordData.ctrlWord + " ");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-processing before the control word.
|
||||
*
|
||||
* If return value is true, no further processing will be performed on
|
||||
* this control word.
|
||||
*
|
||||
* @return <code>false</code> = stop processing, <code>true</code> = continue processing
|
||||
* @since 2.0.8
|
||||
*/
|
||||
//Primary purpose is for \* control word and event handling.
|
||||
protected bool BeforeControlWord() {
|
||||
if (debug) PrintDebug("beforeControlWord");
|
||||
// TODO: This is where events would be triggered
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Handle the control word.
|
||||
*
|
||||
* @return <code>true</code> if control word was handled, <code>false</code> if it was not handled.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected bool OnControlWord() {
|
||||
if (debug) PrintDebug("onCtrlWord");
|
||||
// TODO: This is where events would be triggered
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Post-processing after the control word.
|
||||
*
|
||||
* @return <code>false</code> = stop processing, <code>true</code> = continue processing
|
||||
* @since 2.0.8
|
||||
*/
|
||||
protected bool AfterControlWord() {
|
||||
if (debug) PrintDebug("afterControlWord");
|
||||
// TODO: This is where events would be triggered
|
||||
return true;
|
||||
}
|
||||
|
||||
// public String CtrlWordString() {
|
||||
// //String out = ctrlWordPrefix + this.ctrlWord;
|
||||
// String out = "";
|
||||
// if (this.bExtendedDestination) {
|
||||
// out += "\\*";
|
||||
// }
|
||||
// out = ctrlWordPrefix + this.ctrlWordData.ctrlWord;
|
||||
// if (this.ctrlWordData.hasParam) {
|
||||
// if (this.ctrlWordData.isNeg) out += "-";
|
||||
// out += this.ctrlWordData.param;
|
||||
// } else {
|
||||
// if (this.passDefaultParameterValue == true) {
|
||||
// out += Integer.ToString(this.defaultParameterValue);
|
||||
// }
|
||||
// }
|
||||
// out += this.ctrlWordSuffix;
|
||||
// return out;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Debug function to print class/method
|
||||
* @param txt The <code>String</code> to output.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private void PrintDebug(String txt) {
|
||||
Console.Out.WriteLine(this.GetType().Name + " : " + txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
1903
iTechSharp/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordMap.cs
Normal file
1903
iTechSharp/iTextSharp/text/rtf/parser/ctrlwords/RtfCtrlWordMap.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
/*
|
||||
* $Id: RtfCtrlWordMgr.cs,v 1.2 2008/05/13 11:25:59 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.parser.ctrlwords {
|
||||
|
||||
/**
|
||||
* <code>RtfCtrlWordMgr</code> handles the dispatching of control words from
|
||||
* the table of known control words.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public sealed class RtfCtrlWordMgr {
|
||||
public static bool debug = false;
|
||||
public static bool debugFound = false;
|
||||
public static bool debugNotFound = true;
|
||||
private PushbackStream reader = null;
|
||||
private RtfParser rtfParser = null;
|
||||
private RtfCtrlWordMap ctrlWordMap = null;
|
||||
|
||||
/** The <code>RtfCtrlWordListener</code>. */
|
||||
private ArrayList listeners = new ArrayList();
|
||||
|
||||
// // TIMING DEBUG INFO
|
||||
// private long endTime = 0;
|
||||
// private Date endDate = null;
|
||||
// private long endFree = 0;
|
||||
// private DecimalFormat df = new DecimalFormat("#,##0");
|
||||
// private Date startDate = new Date();
|
||||
// private long startTime = System.CurrentTimeMillis();
|
||||
// private long startFree = Runtime.GetRuntime().FreeMemory();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param rtfParser The parser object this manager works with.
|
||||
* @param reader the PushbackReader from the tokeniser.
|
||||
*/
|
||||
public RtfCtrlWordMgr(RtfParser rtfParser, PushbackStream reader) {
|
||||
this.rtfParser = rtfParser; // set the parser
|
||||
this.reader = reader; // set the reader value
|
||||
ctrlWordMap = new RtfCtrlWordMap(rtfParser);
|
||||
|
||||
// // TIMING DEBUG INFO
|
||||
// endFree = Runtime.GetRuntime().FreeMemory();
|
||||
// endTime = System.CurrentTimeMillis();
|
||||
// endDate = new Date();
|
||||
// Console.Out.WriteLine("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
|
||||
// Console.Out.WriteLine("RtfCtrlWordMgr end date : " + endDate.ToLocaleString());
|
||||
// Console.Out.WriteLine(" Elapsed time : " + Long.ToString(endTime - startTime) + " milliseconds.");
|
||||
// Console.Out.WriteLine("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
|
||||
// Console.Out.WriteLine("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
|
||||
// Console.Out.WriteLine("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal to control word manager class.
|
||||
*
|
||||
* @param ctrlWordData The <code>RtfCtrlWordData</code> object with control word and param
|
||||
* @param groupLevel The current document group parsing level
|
||||
* @return errOK if ok, otherwise an error code.
|
||||
*/
|
||||
public int HandleKeyword(RtfCtrlWordData ctrlWordData, int groupLevel) {
|
||||
//TODO: May be used for event handling.
|
||||
int result = RtfParser.errOK;
|
||||
|
||||
// Call before handler event here
|
||||
BeforeCtrlWord(ctrlWordData);
|
||||
|
||||
result = DispatchKeyword(ctrlWordData, groupLevel);
|
||||
|
||||
// call after handler event here
|
||||
AfterCtrlWord(ctrlWordData);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the token to the correct control word handling object.
|
||||
*
|
||||
* @param ctrlWordData The <code>RtfCtrlWordData</code> object with control word and param
|
||||
* @param groupLevel The current document group parsing level
|
||||
* @return errOK if ok, otherwise an error code.
|
||||
*/
|
||||
private int DispatchKeyword(RtfCtrlWordData ctrlWordData, int groupLevel) {
|
||||
int result = RtfParser.errOK;
|
||||
if (ctrlWordData != null) {
|
||||
RtfCtrlWordHandler ctrlWord = ctrlWordMap.GetCtrlWordHandler(ctrlWordData.ctrlWord);
|
||||
if (ctrlWord != null) {
|
||||
ctrlWord.HandleControlword(ctrlWordData);
|
||||
if (debug && debugFound) {
|
||||
Console.Out.WriteLine("Keyword found:" +
|
||||
" New:" + ctrlWordData.ctrlWord +
|
||||
" Param:" + ctrlWordData.param +
|
||||
" bParam=" + ctrlWordData.hasParam.ToString());
|
||||
}
|
||||
} else {
|
||||
result = RtfParser.errCtrlWordNotFound;
|
||||
//result = RtfParser2.errAssertion;
|
||||
if (debug && debugNotFound) {
|
||||
Console.Out.WriteLine("Keyword unknown:" +
|
||||
" New:" + ctrlWordData.ctrlWord +
|
||||
" Param:" + ctrlWordData.param +
|
||||
" bParam=" + ctrlWordData.hasParam.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// listener methods
|
||||
|
||||
/**
|
||||
* Adds a <CODE>RtfCtrlWordListener</CODE> to the <CODE>RtfCtrlWordMgr</CODE>.
|
||||
*
|
||||
* @param listener
|
||||
* the new RtfCtrlWordListener.
|
||||
*/
|
||||
public void AddRtfCtrlWordListener(IRtfCtrlWordListener listener) {
|
||||
listeners.Add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a <CODE>RtfCtrlWordListener</CODE> from the <CODE>RtfCtrlWordMgr</CODE>.
|
||||
*
|
||||
* @param listener
|
||||
* the RtfCtrlWordListener that has to be removed.
|
||||
*/
|
||||
public void RemoveRtfCtrlWordListener(IRtfCtrlWordListener listener) {
|
||||
listeners.Remove(listener);
|
||||
}
|
||||
|
||||
private bool BeforeCtrlWord(RtfCtrlWordData ctrlWordData) {
|
||||
foreach (IRtfCtrlWordListener listener in listeners) {
|
||||
listener.BeforeCtrlWord(ctrlWordData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OnCtrlWord(RtfCtrlWordData ctrlWordData) {
|
||||
foreach (IRtfCtrlWordListener listener in listeners) {
|
||||
listener.OnCtrlWord(ctrlWordData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool AfterCtrlWord(RtfCtrlWordData ctrlWordData) {
|
||||
foreach (IRtfCtrlWordListener listener in listeners) {
|
||||
listener.AfterCtrlWord(ctrlWordData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
|
||||
/* $Id: RtfCtrlWordType.cs,v 1.2 2008/05/13 11:25:59 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.parser.ctrlwords {
|
||||
/**
|
||||
* <code>RtfCtrlWordType</code> indicates the type of control word.
|
||||
*
|
||||
* RTF control words are divided up into:
|
||||
* Destination, Flag, Value, Toggle, Symbol.
|
||||
*
|
||||
* Destination: The current destination for values and text to be sent.
|
||||
* Flag: 0/1 value types. Represents true/false, on/off value types.
|
||||
* Toggle: Flips a Flag value on/off.
|
||||
* Value: an Integer value data type. (Exception: Some control words this is a long data value type)
|
||||
* Symbol: Special RTF characters such as \{, \} and others.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public sealed class RtfCtrlWordType {
|
||||
/**
|
||||
* Control word is unidentified.
|
||||
*/
|
||||
public const int UNIDENTIFIED = -1;
|
||||
/**
|
||||
* Control word is a destination.
|
||||
*/
|
||||
public const int DESTINATION = 0;
|
||||
/**
|
||||
* Control word is a newer destination.
|
||||
*/
|
||||
public const int DESTINATION_EX = 1;
|
||||
/**
|
||||
* Control word is a flag.
|
||||
*/
|
||||
public const int FLAG = 2;
|
||||
/**
|
||||
* Control word is a value.
|
||||
*/
|
||||
public const int VALUE = 3;
|
||||
/**
|
||||
* Control word is a flag toggle.
|
||||
*/
|
||||
public const int TOGGLE = 4;
|
||||
/**
|
||||
* Control word is a special symbol.
|
||||
*/
|
||||
public const int SYMBOL = 5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: IRtfDestinationListener.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationListener</code> interface for handling events.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public interface IRtfDestinationListener : IEventListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RtfCtrlWordData BeforeCtrlWord(RtfCtrlWordData ctrlWordData);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RtfCtrlWordData OnCtrlWord(RtfCtrlWordData ctrlWordData);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RtfCtrlWordData AfterCtrlWord(RtfCtrlWordData ctrlWordData);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int BeforeCharacter(int ch);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int OnCharacter(int ch);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int AfterCharacter(int ch);
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
bool OnOpenGroup();
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
bool OnCloseGroup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestination.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestination</code> is the base class for destinations according
|
||||
* to the RTF Specification. All destinations must extend from this class.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public abstract class RtfDestination {
|
||||
/** Parser object */
|
||||
protected RtfParser rtfParser = null;
|
||||
|
||||
/** Is data in destination modified? */
|
||||
protected bool modified = false;
|
||||
|
||||
/** The last control word handled by this destination */
|
||||
protected RtfCtrlWordData lastCtrlWord = null;
|
||||
|
||||
/** The <code>RtfDestinationListener</code>. */
|
||||
private static ArrayList listeners = new ArrayList();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public RtfDestination() {
|
||||
rtfParser = null;
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
* @param parser <code>RtfParser</code> object.
|
||||
*/
|
||||
public RtfDestination(RtfParser parser) {
|
||||
this.rtfParser = parser;
|
||||
}
|
||||
/**
|
||||
* Set the parser to use with the RtfDestination object.
|
||||
*
|
||||
* @param parser The RtfParser object.
|
||||
*/
|
||||
public virtual void SetParser(RtfParser parser) {
|
||||
if (this.rtfParser != null && this.rtfParser.Equals(parser)) return;
|
||||
this.rtfParser = parser;
|
||||
}
|
||||
/**
|
||||
* Clean up when destination is closed.
|
||||
* @return true if handled, false if not handled
|
||||
*/
|
||||
public abstract bool CloseDestination();
|
||||
/**
|
||||
* Handle a new subgroup contained within this group
|
||||
* @return true if handled, false if not handled
|
||||
*/
|
||||
public abstract bool HandleOpeningSubGroup();
|
||||
/**
|
||||
* Clean up when group is closed.
|
||||
* @return true if handled, false if not handled
|
||||
*/
|
||||
public abstract bool HandleCloseGroup();
|
||||
|
||||
/**
|
||||
* Setup when group is opened.
|
||||
* @return true if handled, false if not handled
|
||||
*/
|
||||
public abstract bool HandleOpenGroup();
|
||||
/**
|
||||
* Handle text for this destination
|
||||
* @return true if handled, false if not handled
|
||||
*/
|
||||
public abstract bool HandleCharacter(int ch);
|
||||
/**
|
||||
* Handle control word for this destination
|
||||
* @param ctrlWordData The control word and parameter information object
|
||||
* @return true if handled, false if not handled
|
||||
*/
|
||||
public abstract bool HandleControlWord(RtfCtrlWordData ctrlWordData);
|
||||
/**
|
||||
* Method to set this object to the default values. Must be implemented in child class.
|
||||
*/
|
||||
public abstract void SetToDefaults();
|
||||
|
||||
/**
|
||||
* Method to indicate if data in this destination has changed.
|
||||
* @return true if modified, false if not modified.
|
||||
*/
|
||||
public bool IsModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
// listener methods
|
||||
|
||||
/**
|
||||
* Adds a <CODE>RtfDestinationListener</CODE> to the <CODE>RtfDestinationMgr</CODE>.
|
||||
*
|
||||
* @param listener
|
||||
* the new RtfDestinationListener.
|
||||
*/
|
||||
public bool AddListener(IRtfDestinationListener listener) {
|
||||
listeners.Add(listener);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a <CODE>RtfDestinationListener</CODE> from the <CODE>RtfDestinationMgr</CODE>.
|
||||
*
|
||||
* @param listener
|
||||
* the RtfCtrlWordListener that has to be removed.
|
||||
*/
|
||||
public bool RemoveListener(IRtfDestinationListener listener) {
|
||||
int i = listeners.IndexOf(listener);
|
||||
if (i >= 0) {
|
||||
listeners.RemoveAt(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected RtfCtrlWordData BeforeCtrlWord(RtfCtrlWordData ctrlWordData) {
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.BeforeCtrlWord(ctrlWordData);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected RtfCtrlWordData OnCtrlWord(RtfCtrlWordData ctrlWordData){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.OnCtrlWord(ctrlWordData);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected RtfCtrlWordData AfterCtrlWord(RtfCtrlWordData ctrlWordData){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.AfterCtrlWord(ctrlWordData);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected int BeforeCharacter(int ch){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.BeforeCharacter(ch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected int OnCharacter(int ch){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.OnCharacter(ch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected int AfterCharacter(int ch){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.AfterCharacter(ch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected bool OnOpenGroup(){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.OnOpenGroup();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected bool OnCloseGroup(){
|
||||
foreach (IRtfDestinationListener listener in listeners) {
|
||||
listener.OnCloseGroup();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual int GetNewTokeniserState() {
|
||||
return RtfParser.TOKENISER_IGNORE_RESULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
using iTextSharp.text.rtf.parser.enumerations;
|
||||
/*
|
||||
* $Id: RtfDestinationColorTable.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationColorTable</code> handles data destined for the color table destination
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfDestinationColorTable : RtfDestination {
|
||||
|
||||
/**
|
||||
* The RtfImportHeader to add color mappings to.
|
||||
*/
|
||||
private RtfImportMgr importHeader = null;
|
||||
/**
|
||||
* The number of the current color being parsed.
|
||||
*/
|
||||
private int colorNr = 0;
|
||||
/**
|
||||
* The red component of the current color being parsed.
|
||||
*/
|
||||
private int red = -1;
|
||||
/**
|
||||
* The green component of the current color being parsed.
|
||||
*/
|
||||
private int green = -1;
|
||||
/**
|
||||
* The blue component of the current color being parsed.
|
||||
*/
|
||||
private int blue = -1;
|
||||
/*
|
||||
* Color themes - Introduced Word 2007
|
||||
*/
|
||||
/**
|
||||
* Specifies the tint when specifying a theme color.
|
||||
* RTF control word ctint
|
||||
*
|
||||
* 0 - 255: 0 = full Tint(white), 255 = no tint.
|
||||
* Default value: 255
|
||||
*
|
||||
* If tint is specified and is less than 255, cshade must equal 255.
|
||||
* ctint/cshade are mutually exclusive
|
||||
*
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#cshade
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#themeColor
|
||||
*/
|
||||
private int ctint = 255;
|
||||
/**
|
||||
* Specifies the shade when specifying a theme color.
|
||||
* RTF control word cshade
|
||||
*
|
||||
* 0 - 255: 0 = full Shade(black), 255 = no shade.
|
||||
* Default value: 255
|
||||
*
|
||||
* If shade is specified and is less than 255, ctint must equal 255.
|
||||
* cshade/ctint are mutually exclusive
|
||||
*
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#ctint
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#themeColor
|
||||
*/
|
||||
private int cshade = 255;
|
||||
/**
|
||||
* Specifies the use of a theme color.
|
||||
*
|
||||
* @see com.lowagie.text.rtf.parser.enumerations.RtfColorThemes
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#ctint
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#cshade
|
||||
*/
|
||||
private int themeColor = RtfColorThemes.THEME_UNDEFINED;
|
||||
/**
|
||||
* Color map object for conversions
|
||||
*/
|
||||
private Hashtable colorMap = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public RtfDestinationColorTable() : base(null) {
|
||||
colorMap = new Hashtable();
|
||||
this.colorNr = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new RtfColorTableParser.
|
||||
*
|
||||
* @param importHeader The RtfImportHeader to add the color mappings to.
|
||||
*/
|
||||
public RtfDestinationColorTable(RtfParser parser) : base(parser) {
|
||||
colorMap = new Hashtable();
|
||||
this.colorNr = 0;
|
||||
this.importHeader = parser.GetImportManager();
|
||||
this.SetToDefaults();
|
||||
}
|
||||
|
||||
public override void SetParser(RtfParser parser) {
|
||||
this.rtfParser = parser;
|
||||
colorMap = new Hashtable();
|
||||
this.colorNr = 0;
|
||||
this.importHeader = parser.GetImportManager();
|
||||
this.SetToDefaults();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CloseDestination() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleCloseGroup() {
|
||||
ProcessColor();
|
||||
return true;
|
||||
}
|
||||
public override bool HandleOpenGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleCharacter(int ch) {
|
||||
// color elements end with a semicolon (;)
|
||||
if ((char)ch == ';') {
|
||||
this.ProcessColor();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
if (ctrlWordData.ctrlWord.Equals("blue")) this.SetBlue(ctrlWordData.IntValue());
|
||||
if (ctrlWordData.ctrlWord.Equals("red")) this.SetRed(ctrlWordData.IntValue());
|
||||
if (ctrlWordData.ctrlWord.Equals("green")) this.SetGreen(ctrlWordData.IntValue());
|
||||
if (ctrlWordData.ctrlWord.Equals("cshade")) this.SetShade(ctrlWordData.IntValue());
|
||||
if (ctrlWordData.ctrlWord.Equals("ctint")) this.SetTint(ctrlWordData.IntValue());
|
||||
//if(ctrlWordData.ctrlWord.Equals("cmaindarkone")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("cmainlightone")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("cmaindarktwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("cmainlighttwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("caccentone")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("caccenttwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("caccentthree")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("caccentfour")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("caccentfive")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("caccentsix")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("chyperlink")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("cfollowedhyperlink")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("cbackgroundone")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("ctextone")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("cbacgroundtwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
//if(ctrlWordData.ctrlWord.Equals("ctexttwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values.
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
this.red = -1;
|
||||
this.green = -1;
|
||||
this.blue = -1;
|
||||
this.ctint = 255;
|
||||
this.cshade = 255;
|
||||
this.themeColor = RtfColorThemes.THEME_UNDEFINED;
|
||||
// do not reset colorNr
|
||||
}
|
||||
/**
|
||||
* Processes the color triplet parsed from the document.
|
||||
* Add it to the import mapping so colors can be mapped when encountered
|
||||
* in the RTF import or conversion.
|
||||
*/
|
||||
private void ProcessColor() {
|
||||
if (red != -1 && green != -1 && blue != -1) {
|
||||
if (this.rtfParser.IsImport()) {
|
||||
this.importHeader.ImportColor(this.colorNr.ToString(), new Color(this.red, this.green, this.blue));
|
||||
}
|
||||
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
colorMap[this.colorNr.ToString()] = new Color(this.red, this.green, this.blue);
|
||||
}
|
||||
}
|
||||
this.SetToDefaults();
|
||||
this.colorNr++;
|
||||
}
|
||||
/**
|
||||
* Set the red color to value.
|
||||
* @param value Value to set red to.
|
||||
*/
|
||||
private void SetRed(int value) {
|
||||
if (value >= 0 && value <= 255) {
|
||||
this.red = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the green color value.
|
||||
* @param value Value to set green to.
|
||||
*/
|
||||
private void SetGreen(int value) {
|
||||
if (value >= 0 && value <= 255) {
|
||||
this.green = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the blue color value.
|
||||
* @param value Value to set blue to.
|
||||
*/
|
||||
private void SetBlue(int value) {
|
||||
if (value >= 0 && value <= 255) {
|
||||
this.blue = value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the tint value
|
||||
* @param value Value to set the tint to
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#ctint
|
||||
*/
|
||||
private void SetTint(int value) {
|
||||
if (value >= 0 && value <= 255) {
|
||||
this.ctint = value;
|
||||
if (value >= 0 && value <255) {
|
||||
this.cshade = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the shade value
|
||||
* @param value Value to set the shade to
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#cshade
|
||||
*/
|
||||
private void SetShade(int value) {
|
||||
if (value >= 0 && value <= 255) {
|
||||
this.cshade = value;
|
||||
if (value >= 0 && value <255) {
|
||||
this.ctint = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the theme color value.
|
||||
* @param value Value to set the theme color to
|
||||
* @see com.lowagie.text.rtf.parser.enumerations.RtfColorThemes
|
||||
*/
|
||||
private void SetThemeColor(int value) {
|
||||
if (value >= RtfColorThemes.THEME_UNDEFINED && value <= RtfColorThemes.THEME_MAX) {
|
||||
this.themeColor = value;
|
||||
} else {
|
||||
this.themeColor = RtfColorThemes.THEME_UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
// conversion functions
|
||||
/**
|
||||
* Get the <code>Color</code> object that is mapped to the key.
|
||||
* @param key The map number.
|
||||
* *@return <code>Color</code> object from the map. null if key does not exist.
|
||||
*/
|
||||
public Color GetColor(String key) {
|
||||
return (Color)colorMap[key];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.direct;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
using iTextSharp.text.rtf.parser.properties;
|
||||
/*
|
||||
* $Id: RtfDestinationDocument.cs,v 1.4 2008/05/13 11:26:00 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.parser.destinations {
|
||||
/**
|
||||
* <code>RtfDestinationDocument</code> handles data destined for the document destination
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
*/
|
||||
public sealed class RtfDestinationDocument : RtfDestination, IRtfPropertyListener {
|
||||
|
||||
|
||||
/**
|
||||
* The RtfDocument object.
|
||||
*
|
||||
* @see com.lowagie.text.rtf.document.RtfDocument
|
||||
*/
|
||||
private RtfDocument rtfDoc = null;
|
||||
|
||||
/**
|
||||
* The iText Document object.
|
||||
*
|
||||
* @see com.lowagie.text.Document
|
||||
*/
|
||||
private Document doc = null;
|
||||
|
||||
private StringBuilder buffer = null;
|
||||
/**
|
||||
* Indicates the parser action. Import or Conversion.
|
||||
*
|
||||
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_UNIDENTIFIED
|
||||
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_CONVERT
|
||||
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_IMPORT_FRAGMENT
|
||||
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_IMPORT_FULL
|
||||
*/
|
||||
private int conversionType = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates the current table level being processed
|
||||
*/
|
||||
private int tableLevel = 0;
|
||||
|
||||
private static ArrayList IMPORT_IGNORED_CTRLWORDS = new ArrayList(new string[]{
|
||||
"rtf",
|
||||
"ansicpg",
|
||||
"deff",
|
||||
"ansi",
|
||||
"mac",
|
||||
"pca",
|
||||
"pc",
|
||||
"stshfdbch",
|
||||
"stshfloch",
|
||||
"stshfhich",
|
||||
"stshfbi",
|
||||
"deflang",
|
||||
"deflangfe",
|
||||
"adeflang",
|
||||
"adeflangfe"
|
||||
}
|
||||
);
|
||||
private static ArrayList CONVERT_IGNORED_CTRLWORDS = new ArrayList(new string[]{"rtf"});
|
||||
|
||||
private Paragraph iTextParagraph = null;
|
||||
|
||||
public RtfDestinationDocument() : base(null) {
|
||||
}
|
||||
/**
|
||||
* Constructs a new <code>RtfDestinationDocument</code> using
|
||||
* the parameters to initialize the object.
|
||||
* @param rtfDoc The <code>RtfDocument</code> this works with.
|
||||
* @param doc The iText <code>Document</code> this works with.
|
||||
* @param type The type of conversion being done.
|
||||
*/
|
||||
public RtfDestinationDocument(RtfParser parser) : base (parser){
|
||||
this.rtfDoc = parser.GetRtfDocument();
|
||||
this.doc = parser.GetDocument();
|
||||
this.conversionType = parser.GetConversionType();
|
||||
SetToDefaults();
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
this.rtfParser.GetState().properties.AddRtfPropertyListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetParser(RtfParser parser) {
|
||||
this.rtfParser = parser;
|
||||
this.rtfDoc = parser.GetRtfDocument();
|
||||
this.doc = parser.GetDocument();
|
||||
this.conversionType = parser.GetConversionType();
|
||||
SetToDefaults();
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
this.rtfParser.GetState().properties.AddRtfPropertyListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (this.buffer.Length>0) {
|
||||
WriteBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
this.rtfParser.GetState().properties.RemoveRtfPropertyListener(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
this.OnOpenGroup(); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
if (this.iTextParagraph == null) this.iTextParagraph = new Paragraph();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (this.buffer.Length>0) {
|
||||
WriteBuffer();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
this.OnCloseGroup(); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (this.buffer.Length>0) {
|
||||
WriteBuffer();
|
||||
}
|
||||
WriteText("}");
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
if (this.buffer.Length > 0 && this.iTextParagraph == null) {
|
||||
this.iTextParagraph = new Paragraph();
|
||||
}
|
||||
if (this.buffer.Length > 0 ) {
|
||||
Chunk chunk = new Chunk();
|
||||
chunk.Append(this.buffer.ToString());
|
||||
this.iTextParagraph.Add(chunk);
|
||||
}
|
||||
if (this.iTextParagraph != null) {
|
||||
AddParagraphToDocument();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
bool result = true;
|
||||
this.OnCharacter(ch); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (buffer.Length > 254) {
|
||||
this.WriteBuffer();
|
||||
}
|
||||
buffer.Append((char)ch);
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
buffer.Append((char)ch);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
bool result = false;
|
||||
this.OnCtrlWord(ctrlWordData); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
// map font information
|
||||
if (ctrlWordData.ctrlWord.Equals("f")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapFontNr(ctrlWordData.param);}
|
||||
|
||||
// map color information
|
||||
//colors
|
||||
if (ctrlWordData.ctrlWord.Equals("cb")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
if (ctrlWordData.ctrlWord.Equals("cf")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
//cells
|
||||
if (ctrlWordData.ctrlWord.Equals("clcbpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
if (ctrlWordData.ctrlWord.Equals("clcbpatraw")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
if (ctrlWordData.ctrlWord.Equals("clcfpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
if (ctrlWordData.ctrlWord.Equals("clcfpatraw")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
//table rows
|
||||
if (ctrlWordData.ctrlWord.Equals("trcfpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
if (ctrlWordData.ctrlWord.Equals("trcbpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
//paragraph border
|
||||
if (ctrlWordData.ctrlWord.Equals("brdrcf")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
if (ctrlWordData.ctrlWord.Equals("par")) { AddParagraphToDocument(); }
|
||||
// Set Font
|
||||
if (ctrlWordData.ctrlWord.Equals("f")) {}
|
||||
|
||||
// color information
|
||||
//colors
|
||||
if (ctrlWordData.ctrlWord.Equals("cb")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cf")) {}
|
||||
//cells
|
||||
if (ctrlWordData.ctrlWord.Equals("clcbpat")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clcbpatraw")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clcfpat")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clcfpatraw")) {}
|
||||
//table rows
|
||||
if (ctrlWordData.ctrlWord.Equals("trcfpat")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trcbpat")) {}
|
||||
//paragraph border
|
||||
if (ctrlWordData.ctrlWord.Equals("brdrcf")) {}
|
||||
|
||||
/* TABLES */
|
||||
if (ctrlWordData.ctrlWord.Equals("trowd")) /*Beginning of row*/ { tableLevel++;}
|
||||
if (ctrlWordData.ctrlWord.Equals("cell")) /*End of Cell Denotes the end of a table cell*/ {
|
||||
// String ctl = ctrlWordData.ctrlWord;
|
||||
// System.out.Print("cell found");
|
||||
}
|
||||
if (ctrlWordData.ctrlWord.Equals("row")) /*End of row*/ { tableLevel++;}
|
||||
if (ctrlWordData.ctrlWord.Equals("lastrow")) /*Last row of the table*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("row")) /*End of row*/ { tableLevel++;}
|
||||
if (ctrlWordData.ctrlWord.Equals("irow")) /*param is the row index of this row.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("irowband")) /*param is the row index of the row, adjusted to account for header rows. A header row has a value of -1.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tcelld")) /*Sets table cell defaults*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("nestcell")) /*Denotes the end of a nested cell.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("nestrow")) /*Denotes the end of a nested row*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("nesttableprops")) /*Defines the properties of a nested table. This is a destination control word*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("nonesttables")) /*Contains text for readers that do not understand nested tables. This destination should be ignored by readers that support nested tables.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trgaph")) /*Half the space between the cells of a table row in twips.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cellx")) /*param Defines the right boundary of a table cell, including its half of the space between cells.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clmgf")) /*The first cell in a range of table cells to be merged.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clmrg")) /*Contents of the table cell are merged with those of the preceding cell*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clvmgf")) /*The first cell in a range of table cells to be vertically merged.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clvmrg")) /*Contents of the table cell are vertically merged with those of the preceding cell*/ {}
|
||||
/* TABLE: table row revision tracking */
|
||||
if (ctrlWordData.ctrlWord.Equals("trauth")) /*With revision tracking enabled, this control word identifies the author of changes to a table row's properties. N refers to a value in the revision table*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trdate")) /*With revision tracking enabled, this control word identifies the date of a revision*/ {}
|
||||
/* TABLE: Autoformatting flags */
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkborder")) /*Flag sets table autoformat to format borders*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkshading")) /*Flag sets table autoformat to affect shading.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkfont")) /*Flag sets table autoformat to affect font*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkcolor")) /*Flag sets table autoformat to affect color*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkbestfit")) /*Flag sets table autoformat to apply best fit*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkhdrrows")) /*Flag sets table autoformat to format the first (header) row*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllklastrow")) /*Flag sets table autoformat to format the last row.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllkhdrcols")) /*Flag sets table autoformat to format the first (header) column*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllklastcol")) /*Flag sets table autoformat to format the last column*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllknorowband")) /*Specifies row banding conditional formatting shall not be applied*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tbllknocolband")) /*Specifies column banding conditional formatting shall not be applied.*/ {}
|
||||
/* TABLE: Row Formatting */
|
||||
if (ctrlWordData.ctrlWord.Equals("taprtl")) /*Table direction is right to left*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trautofit")) /*param = AutoFit:
|
||||
0 No AutoFit (default).
|
||||
1 AutoFit is on for the row. Overridden by \clwWidthN and \trwWidthN in any table row.
|
||||
*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trhdr")) /*Table row header. This row should appear at the top of every page on which the current table appears*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trkeep")) /*Keep table row together. This row cannot be split by a page break. This property is assumed to be off unless the control word is present*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trkeepfollow")) /*Keep row in the same page as the following row.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trleft")) /*Position in twips of the leftmost edge of the table with respect to the left edge of its column.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trqc")) /*Centers a table row with respect to its containing column.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trql")) /*Left-justifies a table row with respect to its containing column.*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trqr")) /*Right-justifies a table row with respect to its containing column*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trrh")) /*Height of a table row in twips. When 0, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line*/ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddt")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddfb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddfl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddfr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpaddft")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdt")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdfl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdft")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdfb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trspdfr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trwWidth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trftsWidth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trwWidthB")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trftsWidthB")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trftsWidthB")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trwWidthA")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trftsWidthA")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tblind")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tblindtype")) /* */ {}
|
||||
/*TABLE: Row shading and Background Colors*/
|
||||
if (ctrlWordData.ctrlWord.Equals("trcbpat")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trcfpat")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trpat")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trshdng")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgbdiag")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgcross")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdcross")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdkbdiag")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdkcross")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdkdcross")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdkfdiag")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdkhor")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgdkvert")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgfdiag")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbghoriz")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbgvert")) /* */ {}
|
||||
/* TABLE: Cell Formatting*/
|
||||
if (ctrlWordData.ctrlWord.Equals("clFitText")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clNoWrap")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadt")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadfl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadft")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadfb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clpadfr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clwWidth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clftsWidth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clhidemark")) /* */ {}
|
||||
/* TABLE: Compared Table Cells */
|
||||
if (ctrlWordData.ctrlWord.Equals("clins")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cldel")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clmrgd")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clmrgdr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clsplit")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clsplitr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clinsauth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clinsdttm")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cldelauth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cldeldttm")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clmrgdauth")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clmrgddttm")) /* */ {}
|
||||
/*TABLE: Position Wrapped Tables (The following properties must be the same for all rows in the table.)*/
|
||||
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtLeft")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtRight")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtTop")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtBottom")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tabsnoovrlp")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tphcol")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tphmrg")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tphpg")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposnegx")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposnegy")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposx")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposxc")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposxi")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposxl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposxo")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposxr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposy")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposyb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposyc")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposyil")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposyin")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposyout")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tposyt")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tpvmrg")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tpvpara")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tpvpg")) /* */ {}
|
||||
/* TABLE: Bidirectional Controls */
|
||||
if (ctrlWordData.ctrlWord.Equals("rtlrow")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("ltrrow")) /* */ {}
|
||||
/* TABLE: Row Borders */
|
||||
if (ctrlWordData.ctrlWord.Equals("trbrdrt")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbrdrl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbrdrb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbrdrr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbrdrh")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("trbrdrv")) /* */ {}
|
||||
/* TABLE: Cell Borders */
|
||||
if (ctrlWordData.ctrlWord.Equals("brdrnil")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clbrdrb")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clbrdrt")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clbrdrl")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("clbrdrr")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cldglu")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("cldgll")) /* */ {}
|
||||
if (ctrlWordData.ctrlWord.Equals("")) /* */ {}
|
||||
}
|
||||
if (ctrlWordData.ctrlWordType == RtfCtrlWordType.TOGGLE) {
|
||||
this.rtfParser.GetState().properties.ToggleProperty(ctrlWordData);//ctrlWordData.specialHandler);
|
||||
}
|
||||
|
||||
if (ctrlWordData.ctrlWordType == RtfCtrlWordType.FLAG ||
|
||||
ctrlWordData.ctrlWordType == RtfCtrlWordType.VALUE) {
|
||||
this.rtfParser.GetState().properties.SetProperty(ctrlWordData);//ctrlWordData.specialHandler, ctrlWordData.param);
|
||||
}
|
||||
|
||||
switch (conversionType) {
|
||||
case RtfParser.TYPE_IMPORT_FULL:
|
||||
if (!IMPORT_IGNORED_CTRLWORDS.Contains(ctrlWordData.ctrlWord)) {
|
||||
WriteBuffer();
|
||||
WriteText(ctrlWordData.ToString());
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
case RtfParser.TYPE_IMPORT_FRAGMENT:
|
||||
if (!IMPORT_IGNORED_CTRLWORDS.Contains(ctrlWordData.ctrlWord)) {
|
||||
WriteBuffer();
|
||||
WriteText(ctrlWordData.ToString());
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
case RtfParser.TYPE_CONVERT:
|
||||
if (IMPORT_IGNORED_CTRLWORDS.Contains(ctrlWordData.ctrlWord) == false) {
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
default: // error because is should be an import or convert
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Write the accumulated buffer to the destination.
|
||||
* Used for direct content
|
||||
*/
|
||||
private void WriteBuffer() {
|
||||
WriteText(this.buffer.ToString());
|
||||
SetToDefaults();
|
||||
}
|
||||
/**
|
||||
* Write the string value to the destiation.
|
||||
* Used for direct content
|
||||
* @param value
|
||||
*/
|
||||
private void WriteText(String value) {
|
||||
if (this.rtfParser.IsNewGroup()) {
|
||||
this.rtfDoc.Add(new RtfDirectContent("{"));
|
||||
this.rtfParser.SetNewGroup(false);
|
||||
}
|
||||
if (value.Length > 0) {
|
||||
this.rtfDoc.Add(new RtfDirectContent(value));
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
this.buffer = new StringBuilder();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.properties.RtfPropertyListener#afterChange(java.lang.String)
|
||||
*/
|
||||
public void AfterPropertyChange(String propertyName) {
|
||||
if (propertyName.StartsWith(RtfProperty.CHARACTER)) {
|
||||
} else {
|
||||
if (propertyName.StartsWith(RtfProperty.PARAGRAPH)) {
|
||||
} else {
|
||||
if (propertyName.StartsWith(RtfProperty.SECTION)) {
|
||||
} else {
|
||||
if (propertyName.StartsWith(RtfProperty.DOCUMENT)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.properties.RtfPropertyListener#beforeChange(java.lang.String)
|
||||
*/
|
||||
public void BeforePropertyChange(String propertyName) {
|
||||
// do we have any text to do anything with?
|
||||
// if not, then just return without action.
|
||||
if (this.buffer.Length == 0) return;
|
||||
|
||||
if (propertyName.StartsWith(RtfProperty.CHARACTER)) {
|
||||
// this is a character change,
|
||||
// add a new chunck to the current paragraph using current character settings.
|
||||
Chunk chunk = new Chunk();
|
||||
chunk.Append(this.buffer.ToString());
|
||||
this.buffer = new StringBuilder(255);
|
||||
Hashtable charProperties = this.rtfParser.GetState().properties.GetProperties(RtfProperty.CHARACTER);
|
||||
String defFont = (String)charProperties[RtfProperty.CHARACTER_FONT];
|
||||
if (defFont == null) defFont = "0";
|
||||
RtfDestinationFontTable fontTable = (RtfDestinationFontTable)this.rtfParser.GetDestination("fonttbl");
|
||||
Font currFont = fontTable.GetFont(defFont);
|
||||
int fs = Font.NORMAL;
|
||||
if (charProperties.ContainsKey(RtfProperty.CHARACTER_BOLD)) fs |= Font.BOLD;
|
||||
if (charProperties.ContainsKey(RtfProperty.CHARACTER_ITALIC)) fs |= Font.ITALIC;
|
||||
if (charProperties.ContainsKey(RtfProperty.CHARACTER_UNDERLINE)) fs |= Font.UNDERLINE;
|
||||
Font useFont = FontFactory.GetFont(currFont.Familyname, 12, fs, new Color(0,0,0));
|
||||
|
||||
|
||||
chunk.Font = useFont;
|
||||
if (iTextParagraph == null) this.iTextParagraph = new Paragraph();
|
||||
this.iTextParagraph.Add(chunk);
|
||||
|
||||
} else {
|
||||
if (propertyName.StartsWith(RtfProperty.PARAGRAPH)) {
|
||||
// this is a paragraph change. what do we do?
|
||||
} else {
|
||||
if (propertyName.StartsWith(RtfProperty.SECTION)) {
|
||||
|
||||
} else {
|
||||
if (propertyName.StartsWith(RtfProperty.DOCUMENT)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddParagraphToDocument() {
|
||||
if (this.iTextParagraph != null) {
|
||||
try {
|
||||
this.rtfParser.GetDocument().Add(this.iTextParagraph);
|
||||
} catch {
|
||||
}
|
||||
this.iTextParagraph = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,600 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.direct;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationFontTable.cs,v 1.4 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationFontTable</code> handles data destined for the font table destination
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public sealed class RtfDestinationFontTable : RtfDestination {
|
||||
/**
|
||||
* The RtfImportHeader to add font mappings to.
|
||||
*/
|
||||
private RtfImportMgr importHeader = null;
|
||||
/**
|
||||
* The theme (Office 2007)
|
||||
*/
|
||||
private String themeFont = "";
|
||||
/**
|
||||
* The number of the font being parsed.
|
||||
*/
|
||||
private String fontNr = "";
|
||||
/**
|
||||
* The family of the font being parsed.
|
||||
*/
|
||||
private String fontFamily = "";
|
||||
/**
|
||||
* The \charset value
|
||||
*/
|
||||
private String charset = "";
|
||||
private const String CHARSET_DEFAULT = "0";
|
||||
/**
|
||||
* The \fprq
|
||||
*/
|
||||
private int fprq = 0;
|
||||
/**
|
||||
* The \*\panose font matching value if primary font is not available.
|
||||
*/
|
||||
private String panose = "";
|
||||
/**
|
||||
* The \*\fname
|
||||
*/
|
||||
//private String nontaggedname = "";
|
||||
/**
|
||||
* The name of the font being parsed.
|
||||
*/
|
||||
private String fontName = "";
|
||||
/**
|
||||
* The \falt alternate font if primary font is not available.
|
||||
*/
|
||||
private String falt = "";
|
||||
/**
|
||||
* The \falt alternate font if primary font is not available.
|
||||
*/
|
||||
//private String fontemb = "";
|
||||
/**
|
||||
* The \falt alternate font if primary font is not available.
|
||||
*/
|
||||
//private String fontType = "";
|
||||
/**
|
||||
* The \falt alternate font if primary font is not available.
|
||||
*/
|
||||
//private String fontFile = "";
|
||||
/**
|
||||
* The \falt alternate font if primary font is not available.
|
||||
*/
|
||||
//private String fontFileCpg = "";
|
||||
/**
|
||||
* The \fbias value
|
||||
*/
|
||||
private int fbias = 0;
|
||||
/**
|
||||
* The \cpg value
|
||||
*/
|
||||
private String cpg = "";
|
||||
/**
|
||||
* The \fnil, \fttruetype value
|
||||
*/
|
||||
private String trueType = "";
|
||||
|
||||
/**
|
||||
* state flag to handle different parsing of a font element
|
||||
*/
|
||||
private int state = 0;
|
||||
/* state values */
|
||||
/** Normal */
|
||||
private const int SETTING_NORMAL = 0;
|
||||
/** \falt */
|
||||
private const int SETTING_ALTERNATE = 1;
|
||||
/** \fname */
|
||||
private const int SETTING_FONTNAME = 2;
|
||||
/** \panose */
|
||||
private const int SETTING_PANOSE = 3;
|
||||
/** \fontemb */
|
||||
private const int SETTING_FONT_EMBED = 4;
|
||||
/** \ffile */
|
||||
private const int SETTING_FONT_FILE = 5;
|
||||
|
||||
/**
|
||||
* Convert font mapping to <code>FontFactory</code> font objects.
|
||||
*/
|
||||
private Hashtable fontMap = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public RtfDestinationFontTable() : base(null) {
|
||||
}
|
||||
/**
|
||||
* Constructs a new RtfFontTableParser.
|
||||
*
|
||||
* @param importHeader The RtfImportHeader to add font mappings to.
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public RtfDestinationFontTable(RtfParser parser) : base(parser) {
|
||||
this.Init(true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setParser(com.lowagie.text.rtf.parser.RtfParser)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override void SetParser(RtfParser parser) {
|
||||
if (this.rtfParser != null && this.rtfParser.Equals(parser)) return;
|
||||
this.rtfParser = parser;
|
||||
this.Init(true);
|
||||
}
|
||||
/**
|
||||
* Initialize the object.
|
||||
*
|
||||
* @param importFonts true to import the fonts into the FontFactory, false do not load fonts
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private void Init(bool importFonts) {
|
||||
fontMap = new Hashtable();
|
||||
if (this.rtfParser != null) {
|
||||
this.importHeader = this.rtfParser.GetImportManager();
|
||||
}
|
||||
this.SetToDefaults();
|
||||
if (importFonts) {
|
||||
ImportSystemFonts();
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
if (this.state == SETTING_NORMAL) {
|
||||
ProcessFont();
|
||||
}
|
||||
this.state = SETTING_NORMAL;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(char[])
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
switch (this.state) {
|
||||
case SETTING_NORMAL:
|
||||
this.fontName += (char)ch;
|
||||
break;
|
||||
case SETTING_ALTERNATE:
|
||||
this.falt += (char)ch;
|
||||
break;
|
||||
case SETTING_PANOSE:
|
||||
this.panose += (char)ch;
|
||||
break;
|
||||
case SETTING_FONT_EMBED:
|
||||
break;
|
||||
case SETTING_FONT_FILE:
|
||||
break;
|
||||
case SETTING_FONTNAME:
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleControlWord(com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
bool result = true;
|
||||
// just let fonttbl fall through and set last ctrl word object.
|
||||
|
||||
if (ctrlWordData.ctrlWord.Equals("f")) { this.SetFontNumber(ctrlWordData.param); result=true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("fcharset")) { this.SetCharset(ctrlWordData.param); result=true; }
|
||||
|
||||
// font families
|
||||
if (ctrlWordData.ctrlWord.Equals("fnil")) { this.SetFontFamily("roman"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("froman")) { this.SetFontFamily("roman"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fswiss")) { this.SetFontFamily("swiss"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fmodern")) { this.SetFontFamily("modern"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fscript")) { this.SetFontFamily("script"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fdecor")) { this.SetFontFamily("decor"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("ftech")) { this.SetFontFamily("tech"); result=true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fbidi")) { this.SetFontFamily("bidi"); result=true; }
|
||||
// pitch
|
||||
if (ctrlWordData.ctrlWord.Equals("fprq")) { this.SetPitch(ctrlWordData.param); result=true; }
|
||||
// bias
|
||||
if (ctrlWordData.ctrlWord.Equals("fbias")) { this.SetBias(ctrlWordData.param); result=true; }
|
||||
// theme font information
|
||||
if (ctrlWordData.ctrlWord.Equals("flomajor")) { this.SetThemeFont("flomajor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fhimajor")) { this.SetThemeFont("fhimajor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fdbmajor")) { this.SetThemeFont("fdbmajor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fbimajor")) { this.SetThemeFont("fbimajor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("flominor")) { this.SetThemeFont("flominor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fhiminor")) { this.SetThemeFont("fhiminor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fdbminor")) { this.SetThemeFont("fdbminor"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fbiminor")) { this.SetThemeFont("fbiminor"); result= true; }
|
||||
|
||||
// panose
|
||||
if (ctrlWordData.ctrlWord.Equals("panose")) {state = SETTING_PANOSE; result = true; }
|
||||
|
||||
// \*\fname
|
||||
// <font name> #PCDATA
|
||||
if (ctrlWordData.ctrlWord.Equals("fname")) {state = SETTING_FONTNAME; result = true; }
|
||||
|
||||
// \*\falt
|
||||
if (ctrlWordData.ctrlWord.Equals("falt")) { state = SETTING_ALTERNATE; result = true; }
|
||||
|
||||
// \*\fontemb
|
||||
if (ctrlWordData.ctrlWord.Equals("fontemb")) { state = SETTING_FONT_EMBED; result = true; }
|
||||
|
||||
// font type
|
||||
if (ctrlWordData.ctrlWord.Equals("ftnil")) { this.SetTrueType("ftnil"); result= true; }
|
||||
if (ctrlWordData.ctrlWord.Equals("fttruetype")) { this.SetTrueType("fttruetype"); result= true; }
|
||||
|
||||
// \*\fontfile
|
||||
if (ctrlWordData.ctrlWord.Equals("fontemb")) { state = SETTING_FONT_FILE; result = true; }
|
||||
|
||||
// codepage
|
||||
if (ctrlWordData.ctrlWord.Equals("cpg")) { this.SetCodePage(ctrlWordData.param); result= true; }
|
||||
|
||||
this.lastCtrlWord = ctrlWordData;
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Set the code page
|
||||
* @param value The code page value
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetCodePage(String value) {
|
||||
this.cpg = value;
|
||||
}
|
||||
/**
|
||||
* Set the TrueTtype type
|
||||
* @param value The type
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetTrueType(String value) {
|
||||
this.trueType = value;
|
||||
}
|
||||
/**
|
||||
* Set the font pitch
|
||||
* @param value Pitch value
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetPitch(String value) {
|
||||
this.fprq = int.Parse(value);
|
||||
}
|
||||
/**
|
||||
* Set the font bias
|
||||
* @param value Bias value
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetBias(String value) {
|
||||
this.fbias = int.Parse(value);
|
||||
}
|
||||
/**
|
||||
* Set the font theme
|
||||
*
|
||||
* @param themeFont Theme value
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetThemeFont(String themeFont) {
|
||||
this.themeFont = themeFont;
|
||||
}
|
||||
/**
|
||||
* Set the font name to the parsed value.
|
||||
*
|
||||
* @param fontName The font name.
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetFontName(String fontName) {
|
||||
this.fontName = fontName;
|
||||
}
|
||||
/**
|
||||
* Set the font family to the parsed value.
|
||||
*
|
||||
* @param fontFamily The font family.
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetFontFamily(String fontFamily) {
|
||||
this.fontFamily = fontFamily;
|
||||
}
|
||||
/**
|
||||
* Set the font number to the parsed value.
|
||||
* This is used for mapping fonts to the new font numbers
|
||||
*
|
||||
* @param fontNr The font number.
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetFontNumber(String fontNr) {
|
||||
this.fontNr = fontNr;
|
||||
}
|
||||
/**
|
||||
* Set the alternate font name.
|
||||
*
|
||||
* @param fontAlternate The falt font value
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetFontAlternate(String fontAlternate) {
|
||||
this.falt = fontAlternate;
|
||||
}
|
||||
/**
|
||||
* Set the character-set to the parsed value.
|
||||
*
|
||||
* @param charset The charset value
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetCharset(String charset) {
|
||||
if (charset.Length == 0) {
|
||||
charset = "0";
|
||||
}
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
this.themeFont = "";
|
||||
this.fontNr = "";
|
||||
this.fontName = "";
|
||||
this.fontFamily = "";
|
||||
|
||||
this.charset = "";
|
||||
this.fprq = 0;
|
||||
this.panose = "";
|
||||
//this.nontaggedname = "";
|
||||
this.falt = "";
|
||||
//this.fontemb = "";
|
||||
//this.fontType = "";
|
||||
//this.fontFile = "";
|
||||
//this.fontFileCpg = "";
|
||||
this.fbias = 0;
|
||||
this.cpg = "";
|
||||
this.trueType = "";
|
||||
this.state = SETTING_NORMAL;
|
||||
}
|
||||
/**
|
||||
* Process the font information that was parsed from the input.
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private void ProcessFont() {
|
||||
this.fontName = this.fontName.Trim();
|
||||
if (fontName.Length == 0) return;
|
||||
if (fontNr.Length == 0) return;
|
||||
|
||||
if (fontName.Length>0 && fontName.IndexOf(';') >= 0) {
|
||||
fontName = fontName.Substring(0,fontName.IndexOf(';'));
|
||||
}
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
//TODO: If primary font fails, use the alternate
|
||||
//TODO: Problem: RtfFont defaults family to \froman and doesn't allow any other family.
|
||||
// if you set the family, it changes the font name and not the family in the Font.java class.
|
||||
|
||||
// if (this.fontFamily.Length() > 0) {
|
||||
// if (this.importHeader.ImportFont(this.fontNr, this.fontName, this.fontFamily, Integer.ParseInt(this.charset)) == false) {
|
||||
// if (this.falt.Length() > 0) {
|
||||
// this.importHeader.ImportFont(this.fontNr, this.falt, this.fontFamily, Integer.ParseInt(this.charset));
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
if (!this.importHeader.ImportFont(this.fontNr, this.fontName, int.Parse(this.charset==""?CHARSET_DEFAULT:this.charset))) {
|
||||
if (this.falt.Length > 0) {
|
||||
this.importHeader.ImportFont(this.fontNr, this.falt, int.Parse(this.charset==""?CHARSET_DEFAULT:this.charset));
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
// This could probably be written as a better font matching function
|
||||
|
||||
String fName = this.fontName; // work variable for trimming name if needed.
|
||||
Font f1 = Createfont(fName);
|
||||
if (f1.BaseFont == null && this.falt.Length>0)
|
||||
f1 = Createfont(this.falt);
|
||||
|
||||
if (f1.BaseFont == null) {
|
||||
// Did not find a font, let's try a substring of the first name.
|
||||
if (FontFactory.COURIER.IndexOf(fName) > -1 ) {
|
||||
f1 = FontFactory.GetFont(FontFactory.COURIER);
|
||||
} else if (FontFactory.HELVETICA.IndexOf(fName) > -1 ) {
|
||||
f1 = FontFactory.GetFont(FontFactory.HELVETICA);
|
||||
} else if (FontFactory.TIMES.IndexOf(fName) > -1 ) {
|
||||
f1 = FontFactory.GetFont(FontFactory.TIMES);
|
||||
} else if (FontFactory.SYMBOL.IndexOf(fName) > -1 ) {
|
||||
f1 = FontFactory.GetFont(FontFactory.SYMBOL);
|
||||
} else if (FontFactory.ZAPFDINGBATS.IndexOf(fName) > -1 ) {
|
||||
f1 = FontFactory.GetFont(FontFactory.ZAPFDINGBATS);
|
||||
} else {
|
||||
// we did not find a matching font in any form.
|
||||
// default to HELVETICA for now.
|
||||
f1 = FontFactory.GetFont(FontFactory.HELVETICA);
|
||||
}
|
||||
}
|
||||
fontMap[this.fontNr] = f1;
|
||||
//System.out.Println(f1.GetFamilyname());
|
||||
}
|
||||
this.SetToDefaults();
|
||||
}
|
||||
/**
|
||||
* Create a font via the <code>FontFactory</code>
|
||||
*
|
||||
* @param fontName The font name to create
|
||||
* @return The created <code>Font</code> object
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private Font Createfont(String fontName) {
|
||||
Font f1 = null;
|
||||
int pos=-1;
|
||||
do {
|
||||
f1 = FontFactory.GetFont(fontName);
|
||||
|
||||
if (f1.BaseFont != null) break; // found a font, exit the do/while
|
||||
|
||||
pos = fontName.LastIndexOf(' '); // find the last space
|
||||
if (pos>0) {
|
||||
fontName = fontName.Substring(0, pos ); // truncate it to the last space
|
||||
}
|
||||
} while (pos>0);
|
||||
return f1;
|
||||
}
|
||||
/**
|
||||
* Get a <code>Font</code> object from the font map object
|
||||
*
|
||||
* @param key The font number to get
|
||||
* @return The mapped <code>Font</code> object.
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public Font GetFont(String key) {
|
||||
return (Font) fontMap[key];
|
||||
}
|
||||
/**
|
||||
* Load system fonts into the static <code>FontFactory</code> object
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
private void ImportSystemFonts() {
|
||||
FontFactory.RegisterDirectories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to load the environment variables.
|
||||
*
|
||||
* @return Properties object with environment variable information
|
||||
* @throws Throwable
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
// private Properties GetEnvironmentVariables() {
|
||||
// Properties environmentVariables = new Properties();
|
||||
// String operatingSystem = System.GetProperty("os.name").ToLowerCase();
|
||||
// Runtime runtime = Runtime.GetRuntime();
|
||||
// Process process = null;
|
||||
// if (operatingSystem.IndexOf("windows 95") > -1
|
||||
// || operatingSystem.IndexOf("windows 98") > -1
|
||||
// || operatingSystem.IndexOf("me") > -1) {
|
||||
// process = runtime.Exec("command.com /c set");
|
||||
// } else if ((operatingSystem.IndexOf("nt") > -1)
|
||||
// || (operatingSystem.IndexOf("windows 2000") > -1)
|
||||
// || (operatingSystem.IndexOf("windows xp") > -1)
|
||||
// || (operatingSystem.IndexOf("windows 2003") > -1)) {
|
||||
// process = runtime.Exec("cmd.exe /c set");
|
||||
// } else {
|
||||
// process = runtime.Exec("env");
|
||||
// }
|
||||
// BufferedReader environmentStream = new BufferedReader(new InputStreamReader(process.GetInputStream()));
|
||||
// String inputLine = "";
|
||||
// int idx = -1;
|
||||
// while ((inputLine = environmentStream.ReadLine()) != null) {
|
||||
// idx = inputLine.IndexOf('=');
|
||||
// environmentVariables.SetProperty(inputLine.Substring(0, idx),
|
||||
// inputLine.Substring(idx + 1));
|
||||
// }
|
||||
// return environmentVariables;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationInfo.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationInfo</code> handles data destined for the info destination
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfDestinationInfo : RtfDestination {
|
||||
private String elementName = "";
|
||||
private String text = "";
|
||||
|
||||
|
||||
public RtfDestinationInfo() : base(null) {
|
||||
}
|
||||
/**
|
||||
* Constructs a new RtfDestinationInfo.
|
||||
*
|
||||
* @param parser The RtfParser object.
|
||||
*/
|
||||
public RtfDestinationInfo(RtfParser parser, String elementname) : base(parser) {
|
||||
SetToDefaults();
|
||||
this.elementName = elementname;
|
||||
}
|
||||
public override void SetParser(RtfParser parser) {
|
||||
this.rtfParser = parser;
|
||||
this.SetToDefaults();
|
||||
}
|
||||
public void SetElementName(String value) {
|
||||
this.elementName = value;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
if (this.text.Length > 0) {
|
||||
Document doc = this.rtfParser.GetDocument();
|
||||
if (doc != null) {
|
||||
if (this.elementName.Equals("author")){
|
||||
doc.AddAuthor(this.text);
|
||||
}
|
||||
if (this.elementName.Equals("title")){
|
||||
doc.AddTitle(this.text);
|
||||
}
|
||||
if (this.elementName.Equals("subject")){
|
||||
doc.AddSubject(this.text);
|
||||
}
|
||||
} else {
|
||||
RtfDocument rtfDoc = this.rtfParser.GetRtfDocument();
|
||||
if (rtfDoc != null) {
|
||||
if (this.elementName.Equals("author")){
|
||||
Meta meta = new Meta(this.elementName, this.text);
|
||||
RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta);
|
||||
rtfDoc.GetDocumentHeader().AddInfoElement(elem);
|
||||
}
|
||||
if (this.elementName.Equals("title")){
|
||||
Meta meta = new Meta(this.elementName, this.text);
|
||||
RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta);
|
||||
rtfDoc.GetDocumentHeader().AddInfoElement(elem);
|
||||
}
|
||||
if (this.elementName.Equals("subject")){
|
||||
Meta meta = new Meta(this.elementName, this.text);
|
||||
RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta);
|
||||
rtfDoc.GetDocumentHeader().AddInfoElement(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.SetToDefaults();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(char[])
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
this.text += (char)ch;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleControlWord(com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData)
|
||||
*/
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
elementName = ctrlWordData.ctrlWord;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setToDefaults()
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
this.text = "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationListTable.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationListTable</code> handles data destined for the List Table destination
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
*/
|
||||
public class RtfDestinationListTable : RtfDestination {
|
||||
/**
|
||||
* The RtfImportHeader to add List mappings to.
|
||||
*/
|
||||
private RtfImportMgr importHeader = null;
|
||||
|
||||
public RtfDestinationListTable() : base(null) {
|
||||
}
|
||||
|
||||
public RtfDestinationListTable(RtfParser parser) : base(parser) {
|
||||
this.importHeader = parser.GetImportManager();
|
||||
}
|
||||
|
||||
public override void SetParser(RtfParser parser) {
|
||||
this.rtfParser = parser;
|
||||
this.importHeader = parser.GetImportManager();
|
||||
this.SetToDefaults();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
bool result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setToDefaults()
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationMgr.cs,v 1.4 2008/05/13 11:26:00 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2007 by Howard Shank
|
||||
*
|
||||
* 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationMgr</code> manages destination objects for the parser
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public sealed class RtfDestinationMgr {
|
||||
/*
|
||||
* Destinations
|
||||
*/
|
||||
private static RtfDestinationMgr instance = null;
|
||||
|
||||
/**
|
||||
* CtrlWord <-> Destination map object.
|
||||
*
|
||||
* Maps control words to their destinations objects.
|
||||
* Null destination is a special destination used for
|
||||
* discarding unwanted data. This is primarily used when
|
||||
* skipping groups, binary data or unwanted/unknown data.
|
||||
*/
|
||||
private static Hashtable destinations = new Hashtable(300, 0.95f);
|
||||
/**
|
||||
* Destination objects.
|
||||
* There is only one of each destination.
|
||||
*/
|
||||
private static Hashtable destinationObjects = new Hashtable(10, 0.95f);
|
||||
|
||||
private static bool ignoreUnknownDestinations = false;
|
||||
|
||||
private static RtfParser rtfParser = null;
|
||||
|
||||
/**
|
||||
* String representation of null destination.
|
||||
*/
|
||||
public const String DESTINATION_NULL = "null";
|
||||
/**
|
||||
* String representation of document destination.
|
||||
*/
|
||||
public const String DESTINATION_DOCUMENT = "document";
|
||||
|
||||
/**
|
||||
* Hidden default constructor becuase
|
||||
*/
|
||||
private RtfDestinationMgr() {
|
||||
}
|
||||
|
||||
public static void SetParser(RtfParser parser) {
|
||||
rtfParser = parser;
|
||||
}
|
||||
public static RtfDestinationMgr GetInstance() {
|
||||
lock(destinations) {
|
||||
if (instance == null) {
|
||||
instance = new RtfDestinationMgr();
|
||||
// 2 required destinations for all documents
|
||||
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_DOCUMENT, new Object[] { "RtfDestinationDocument", "" } );
|
||||
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_NULL, new Object[] { "RtfDestinationNull", "" } );
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
public static RtfDestinationMgr GetInstance(RtfParser parser) {
|
||||
lock(destinations) {
|
||||
RtfDestinationMgr.SetParser(parser);
|
||||
if (instance == null) {
|
||||
instance = new RtfDestinationMgr();
|
||||
// 2 required destinations for all documents
|
||||
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_DOCUMENT, new Object[] { "RtfDestinationDocument", "" } );
|
||||
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_NULL, new Object[] { "RtfDestinationNull", "" } );
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static RtfDestination GetDestination(String destination) {
|
||||
RtfDestination dest = null;
|
||||
if (destinations.ContainsKey(destination)) {
|
||||
dest = (RtfDestination)destinations[destination];
|
||||
} else {
|
||||
if (ignoreUnknownDestinations) {
|
||||
dest = (RtfDestination)destinations[DESTINATION_NULL];
|
||||
} else {
|
||||
dest = (RtfDestination)destinations[DESTINATION_DOCUMENT];
|
||||
}
|
||||
}
|
||||
dest.SetParser(RtfDestinationMgr.rtfParser);
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static bool AddDestination(String destination, Object[] args) {
|
||||
if (destinations.ContainsKey(destination)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String thisClass = "iTextSharp.text.rtf.parser.destinations." + (String)args[0];
|
||||
|
||||
if (thisClass.IndexOf("RtfDestinationNull") >= 0) {
|
||||
destinations[destination] = RtfDestinationNull.GetInstance();
|
||||
return true;
|
||||
}
|
||||
|
||||
Type value = null;
|
||||
|
||||
try {
|
||||
value = Type.GetType(thisClass);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (value == null)
|
||||
return false;
|
||||
|
||||
RtfDestination c = null;
|
||||
|
||||
if (destinationObjects.ContainsKey(value.Name)) {
|
||||
c = (RtfDestination)destinationObjects[value.Name];
|
||||
} else {
|
||||
try {
|
||||
c = (RtfDestination)value.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[0], null).Invoke(null);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
c.SetParser(rtfParser);
|
||||
|
||||
if (value.Equals(typeof(RtfDestinationInfo))) {
|
||||
((RtfDestinationInfo)c).SetElementName(destination);
|
||||
}
|
||||
|
||||
if (value.Equals(typeof(RtfDestinationStylesheetTable))) {
|
||||
((RtfDestinationStylesheetTable)c).SetElementName(destination);
|
||||
((RtfDestinationStylesheetTable)c).SetType((String)args[1]);
|
||||
}
|
||||
|
||||
destinations[destination] = c;
|
||||
destinationObjects[value.Name] = c;
|
||||
return true;
|
||||
}
|
||||
|
||||
// listener methods
|
||||
|
||||
/**
|
||||
* Adds a <CODE>RtfDestinationListener</CODE> to the appropriate <CODE>RtfDestination</CODE>.
|
||||
*
|
||||
* @param destination the destination string for the listener
|
||||
* @param listener
|
||||
* the new RtfDestinationListener.
|
||||
*/
|
||||
public static bool AddListener(String destination, IRtfDestinationListener listener) {
|
||||
RtfDestination dest = GetDestination(destination);
|
||||
if (dest != null) {
|
||||
return dest.AddListener(listener);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a <CODE>RtfDestinationListener</CODE> from the appropriate <CODE>RtfDestination</CODE>.
|
||||
*
|
||||
* @param destination the destination string for the listener
|
||||
* @param listener
|
||||
* the RtfCtrlWordListener that has to be removed.
|
||||
*/
|
||||
public static bool RemoveListener(String destination, IRtfDestinationListener listener) {
|
||||
RtfDestination dest = GetDestination(destination);
|
||||
if (dest != null) {
|
||||
return dest.RemoveListener(listener);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationNull.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationNull</code> is for discarded entries. They go nowhere.
|
||||
* If a control word destination is unknown or ignored, this is the destination
|
||||
* that should be set.
|
||||
*
|
||||
* All methods return true indicating they were handled.
|
||||
*
|
||||
* This is a unique destination in that it is a singleton.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public sealed class RtfDestinationNull : RtfDestination {
|
||||
private static RtfDestinationNull instance = new RtfDestinationNull();
|
||||
/**
|
||||
* Constructs a new RtfDestinationNull.
|
||||
*
|
||||
* This constructor is hidden for internal use only.
|
||||
*/
|
||||
private RtfDestinationNull() : base() {
|
||||
}
|
||||
/**
|
||||
* Constructs a new RtfDestinationNull.
|
||||
*
|
||||
* This constructor is hidden for internal use only.
|
||||
*
|
||||
* @param parser Unused value
|
||||
*/
|
||||
private RtfDestinationNull(RtfParser parser) : base(null) {
|
||||
}
|
||||
/**
|
||||
* Get the singleton instance of RtfDestinationNull object.
|
||||
*/
|
||||
static public RtfDestinationNull GetInstance() {
|
||||
return instance;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
}
|
||||
|
||||
// Interface definitions
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleControlWord(com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData)
|
||||
*/
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String GetName() {
|
||||
return typeof(RtfDestinationNull).Name;
|
||||
}
|
||||
|
||||
public override int GetNewTokeniserState() {
|
||||
return RtfParser.TOKENISER_SKIP_GROUP;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.rtf.direct;
|
||||
using iTextSharp.text.rtf.graphic;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationShppict.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationShppict</code> handles data destined for picture destinations
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfDestinationShppict : RtfDestination {
|
||||
private ByteBuffer data = null;
|
||||
|
||||
private StringBuilder hexChars = new StringBuilder(0);
|
||||
private StringBuilder buffer = new StringBuilder();
|
||||
|
||||
/* picttype */
|
||||
private int pictureType = Image.ORIGINAL_NONE;
|
||||
public const int ORIGINAL_NONE = 0;
|
||||
public const int ORIGINAL_GIF = 3;
|
||||
public const int ORIGINAL_TIFF = 5;
|
||||
public const int ORIGINAL_PS = 7;
|
||||
|
||||
// emfblip - EMF (nhanced metafile) - NOT HANDLED
|
||||
// pngblip int ORIGINAL_PNG = 2;
|
||||
// jpegblip Image.ORIGINAL_JPEG = 1; ORIGINAL_JPEG2000 = 8;
|
||||
|
||||
// shppict - Destination
|
||||
// nonshpict - Destination - SKIP THIS
|
||||
// macpict - Mac QuickDraw- NOT HANDLED
|
||||
// pmmetafileN - OS/2 Metafile - NOT HANDLED
|
||||
// N * Meaning
|
||||
// 0x0004 PU_ARBITRARY
|
||||
// 0x0008 PU_PELS
|
||||
// 0x000C PU_LOMETRIC
|
||||
// 0x0010 PU_HIMETRIC
|
||||
// 0x0014 PU_LOENGLISH
|
||||
// 0x0018 PU_HIENGLISH
|
||||
// 0x001C PU_TWIPS
|
||||
//private int pmmetafile = 0;
|
||||
// wmetafileN Image.RIGINAL_WMF = 6;
|
||||
// N * Type
|
||||
// 1 = MM_TEXT
|
||||
// 2 = M_LOMETRIC
|
||||
// 3 = MM_HIMETRIC
|
||||
// 4 = MM_LOENGLISH
|
||||
// 5 = MM_HIENGLISH
|
||||
// 6 = MM_TWIPS
|
||||
// 7 = MM_ISOTROPIC
|
||||
// 8 = MM_ANISOTROPIC
|
||||
// dibitmapN - DIB - Convert to BMP?
|
||||
// wbitmapN Image.ORIGINAL_BMP = 4;
|
||||
|
||||
/* bitapinfo */
|
||||
// wbmbitspixelN - number of bits per pixel - 1 monochrome, 4 16 color, 8 256 color, 24 RGB - Default 1
|
||||
//private int bitsPerPixel = 1;
|
||||
// wbmplanesN - number of color planes - must be 1
|
||||
//private int planes = 1;
|
||||
// wbmwidthbytesN - number of bytes in each raster line
|
||||
//private int widthBytes = 0;
|
||||
|
||||
|
||||
|
||||
/* pictsize */
|
||||
// picwN Ext field if the picture is a Windows metafile; picture width in pixels if the picture is a bitmap or
|
||||
// from quickdraw
|
||||
private long width = 0;
|
||||
// pichN
|
||||
private long height = 0;
|
||||
// picwgoalN
|
||||
private long desiredWidth = 0;
|
||||
// picgoalN
|
||||
private long desiredHeight = 0;
|
||||
// picscalexN
|
||||
private int scaleX = 100;
|
||||
// picscaleyN
|
||||
private int scaleY = 100;
|
||||
// picscaled - macpict setting
|
||||
//private bool scaled = false;
|
||||
// picprop
|
||||
//private bool inlinePicture = false;
|
||||
// defshp
|
||||
//private bool wordArt = false;
|
||||
// piccroptN
|
||||
private int cropTop = 0;
|
||||
// piccropbN
|
||||
private int cropBottom = 0;
|
||||
// piccroplN
|
||||
private int cropLeft = 0;
|
||||
// piccroprN
|
||||
private int cropRight = 0;
|
||||
|
||||
/* metafileinfo */
|
||||
// picbmp
|
||||
//private bool bitmap = false;
|
||||
//picbppN - Valid 1,4,8,24
|
||||
//private int bbp = 1;
|
||||
|
||||
/* data */
|
||||
// binN
|
||||
// 0 = HEX, 1 = BINARY
|
||||
public const int FORMAT_HEXADECIMAL = 0;
|
||||
public const int FORMAT_BINARY = 1;
|
||||
private int dataFormat = FORMAT_HEXADECIMAL;
|
||||
private long binaryLength = 0;
|
||||
// blipupiN
|
||||
//private int unitsPerInch = 0;
|
||||
// bliptagN
|
||||
//private String tag = "";
|
||||
private const int NORMAL = 0;
|
||||
private const int BLIPUID = 1;
|
||||
|
||||
//private int state = NORMAL;
|
||||
/**
|
||||
* Constant for converting pixels to twips
|
||||
*/
|
||||
private const int PIXEL_TWIPS_FACTOR = 15;
|
||||
|
||||
private MemoryStream dataOS = null;
|
||||
|
||||
public RtfDestinationShppict() : base(null) {
|
||||
this.pictureType = pictureType; //get rid of a warning
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new RtfDestinationShppict.
|
||||
*/
|
||||
public RtfDestinationShppict(RtfParser parser) : base(parser) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (this.buffer.Length>0) {
|
||||
WriteBuffer();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
this.OnCloseGroup(); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (this.buffer.Length>0) {
|
||||
WriteBuffer();
|
||||
}
|
||||
if (dataOS != null) {
|
||||
AddImage();
|
||||
dataOS = null;
|
||||
}
|
||||
this.WriteText("}");
|
||||
return true;
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool AddImage() {
|
||||
Image img = null;
|
||||
try {
|
||||
img = Image.GetInstance(dataOS.ToArray());
|
||||
} catch {
|
||||
}
|
||||
// if (img != null) {
|
||||
// FileOutputStream out =null;
|
||||
// try {
|
||||
// out = new FileOutputStream("c:\\test.png");
|
||||
// out.Write(img.GetOriginalData());
|
||||
// out.Close();
|
||||
// } catch (FileNotFoundException e1) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e1.PrintStackTrace();
|
||||
// } catch (IOException e1) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e1.PrintStackTrace();
|
||||
// }
|
||||
|
||||
if (img != null) {
|
||||
img.ScaleAbsolute((float)this.desiredWidth/PIXEL_TWIPS_FACTOR, (float)this.desiredHeight/PIXEL_TWIPS_FACTOR);
|
||||
img.ScaleAbsolute((float)this.width/PIXEL_TWIPS_FACTOR, (float)this.height/PIXEL_TWIPS_FACTOR);
|
||||
img.ScalePercent((float)this.scaleX, this.scaleY);
|
||||
|
||||
try {
|
||||
if (this.rtfParser.IsImport()) {
|
||||
RtfDocument rtfDoc = this.rtfParser.GetRtfDocument();
|
||||
RtfImage rtfImage = new RtfImage(rtfDoc, img);
|
||||
rtfDoc.Add(rtfImage);
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
this.rtfParser.GetDocument().Add(img);
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
dataFormat = FORMAT_HEXADECIMAL;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
this.OnOpenGroup(); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (this.buffer.Length>0) {
|
||||
WriteBuffer();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
if (buffer.Length > 254)
|
||||
WriteBuffer();
|
||||
}
|
||||
if (data == null) data = new ByteBuffer();
|
||||
switch (dataFormat) {
|
||||
case FORMAT_HEXADECIMAL:
|
||||
hexChars.Append(ch);
|
||||
if (hexChars.Length == 2) {
|
||||
try {
|
||||
data.Append((char)int.Parse(hexChars.ToString(), NumberStyles.HexNumber));
|
||||
} catch {
|
||||
}
|
||||
hexChars = new StringBuilder();
|
||||
}
|
||||
break;
|
||||
case FORMAT_BINARY:
|
||||
if (dataOS == null) {
|
||||
dataOS = new MemoryStream();
|
||||
}
|
||||
// HGS - FIX ME IF PROBLEM!
|
||||
dataOS.WriteByte((byte)ch);
|
||||
// PNG signature should be.
|
||||
// (decimal) 137 80 78 71 13 10 26 10
|
||||
// (hexadecimal) 89 50 4e 47 0d 0a 1a 0a
|
||||
// (ASCII C notation) \211 P N G \r \n \032 \n
|
||||
|
||||
binaryLength--;
|
||||
if (binaryLength == 0) { dataFormat = FORMAT_HEXADECIMAL; }
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
bool result = false;
|
||||
bool skipCtrlWord = false;
|
||||
if (this.rtfParser.IsImport()) {
|
||||
skipCtrlWord = true;
|
||||
if (ctrlWordData.ctrlWord.Equals("shppict")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("nonshppict")) { // never gets here because this is a destination set to null
|
||||
skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;
|
||||
}
|
||||
if (ctrlWordData.ctrlWord.Equals("blipuid")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picprop")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pict")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("emfblip")) { result = true; pictureType = Image.ORIGINAL_NONE;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pngblip")) { result = true; pictureType = Image.ORIGINAL_PNG;}
|
||||
if (ctrlWordData.ctrlWord.Equals("jepgblip")) { result = true; pictureType = Image.ORIGINAL_JPEG;}
|
||||
if (ctrlWordData.ctrlWord.Equals("macpict")) { result = true; pictureType = Image.ORIGINAL_NONE;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pmmetafile")) { result = true; pictureType = Image.ORIGINAL_NONE;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wmetafile")) { result = true; pictureType = Image.ORIGINAL_WMF;}
|
||||
if (ctrlWordData.ctrlWord.Equals("dibitmap")) { result = true; pictureType = Image.ORIGINAL_NONE;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wbitmap")) { result = true; pictureType = Image.ORIGINAL_BMP;}
|
||||
/* bitmap information */
|
||||
if (ctrlWordData.ctrlWord.Equals("wbmbitspixel")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wbmplanes")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wbmwidthbytes")) { result = true;}
|
||||
/* picture size, scaling and cropping */
|
||||
if (ctrlWordData.ctrlWord.Equals("picw")) { this.width = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pich")) { this.height = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picwgoal")) { this.desiredWidth = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pichgoal")) { this.desiredHeight = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picscalex")) { this.scaleX = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picscaley")) { this.scaleY = ctrlWordData.IntValue();result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picscaled")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picprop")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("defshp")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropt")) { this.cropTop = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropb")) { this.cropBottom = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropl")) { this.cropLeft = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropr")) { this.cropRight = ctrlWordData.IntValue(); result = true;}
|
||||
/* metafile information */
|
||||
if (ctrlWordData.ctrlWord.Equals("picbmp")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picbpp")) { result = true;}
|
||||
/* picture data */
|
||||
if (ctrlWordData.ctrlWord.Equals("bin")) {
|
||||
this.dataFormat = FORMAT_BINARY;
|
||||
// set length to param
|
||||
this.binaryLength = ctrlWordData.LongValue();
|
||||
this.rtfParser.SetTokeniserStateBinary(binaryLength);
|
||||
result = true;
|
||||
}
|
||||
if (ctrlWordData.ctrlWord.Equals("blipupi")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("blipuid")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("bliptag")) { result = true;}
|
||||
}
|
||||
if (this.rtfParser.IsConvert()) {
|
||||
if (ctrlWordData.ctrlWord.Equals("shppict")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("nonshppict")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("blipuid")) { result = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pict")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("emfblip")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pngblip")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("jepgblip")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("macpict")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pmmetafile")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wmetafile")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("dibitmap")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wbitmap")) { result = true;}
|
||||
/* bitmap information */
|
||||
if (ctrlWordData.ctrlWord.Equals("wbmbitspixel")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wbmplanes")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("wbmwidthbytes")) { result = true;}
|
||||
/* picture size, scaling and cropping */
|
||||
if (ctrlWordData.ctrlWord.Equals("picw")) { this.width = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pich")) { this.height = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picwgoal")) { this.desiredWidth = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("pichgoal")) { this.desiredHeight = ctrlWordData.LongValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picscalex")) { this.scaleX = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picscaley")) { this.scaleY = ctrlWordData.IntValue();result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picscaled")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picprop")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("defshp")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropt")) { this.cropTop = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropb")) { this.cropBottom = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropl")) { this.cropLeft = ctrlWordData.IntValue(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("piccropr")) { this.cropRight = ctrlWordData.IntValue(); result = true;}
|
||||
/* metafile information */
|
||||
if (ctrlWordData.ctrlWord.Equals("picbmp")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("picbpp")) { result = true;}
|
||||
/* picture data */
|
||||
if(ctrlWordData.ctrlWord.Equals("bin")) {
|
||||
dataFormat = FORMAT_BINARY; result = true;
|
||||
}
|
||||
if (ctrlWordData.ctrlWord.Equals("blipupi")) { result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("blipuid")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
|
||||
if (ctrlWordData.ctrlWord.Equals("bliptag")) { result = true;}
|
||||
|
||||
}
|
||||
if (!skipCtrlWord) {
|
||||
switch (this.rtfParser.GetConversionType()) {
|
||||
case RtfParser.TYPE_IMPORT_FULL:
|
||||
WriteBuffer();
|
||||
WriteText(ctrlWordData.ToString());
|
||||
result = true;
|
||||
break;
|
||||
case RtfParser.TYPE_IMPORT_FRAGMENT:
|
||||
WriteBuffer();
|
||||
WriteText(ctrlWordData.ToString());
|
||||
result = true;
|
||||
break;
|
||||
case RtfParser.TYPE_CONVERT:
|
||||
result = true;
|
||||
break;
|
||||
default: // error because is should be an import or convert
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
|
||||
this.buffer = new StringBuilder();
|
||||
this.data = null;
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.desiredWidth = 0;
|
||||
this.desiredHeight = 0;
|
||||
this.scaleX = 100;
|
||||
this.scaleY = 100;
|
||||
//this.scaled = false;
|
||||
//this.inlinePicture = false;
|
||||
//this.wordArt = false;
|
||||
this.cropTop = 0;
|
||||
this.cropBottom = 0;
|
||||
this.cropLeft = 0;
|
||||
this.cropRight = 0;
|
||||
//this.bitmap = false;
|
||||
//this.bbp = 1;
|
||||
this.dataFormat = FORMAT_HEXADECIMAL;
|
||||
this.binaryLength = 0;
|
||||
//this.unitsPerInch = 0;
|
||||
//this.tag = "";
|
||||
}
|
||||
|
||||
private void WriteBuffer() {
|
||||
WriteText(this.buffer.ToString());
|
||||
}
|
||||
private void WriteText(String value) {
|
||||
if (this.rtfParser.GetState().newGroup) {
|
||||
this.rtfParser.GetRtfDocument().Add(new RtfDirectContent("{"));
|
||||
this.rtfParser.GetState().newGroup = false;
|
||||
}
|
||||
if (value.Length > 0) {
|
||||
this.rtfParser.GetRtfDocument().Add(new RtfDirectContent(value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,585 @@
|
||||
using System;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
/*
|
||||
* $Id: RtfDestinationStylesheetTable.cs,v 1.2 2008/05/13 11:26:00 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.parser.destinations {
|
||||
|
||||
/**
|
||||
* <code>RtfDestinationStylesheetTable</code> handles data destined for the
|
||||
* Stylesheet Table destination
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
*/
|
||||
public class RtfDestinationStylesheetTable : RtfDestination {
|
||||
private String styleName = "";
|
||||
/**
|
||||
* <code>RtfParagraphStyle</code> object for setting styleshee values
|
||||
* as they are parsed from the input.
|
||||
*/
|
||||
//private RtfParagraphStyle rtfParagraphStyle = null;
|
||||
|
||||
private String elementName = "";
|
||||
|
||||
/**
|
||||
* RTF Style number from stylesheet table.
|
||||
*/
|
||||
private int styleNr = 0;
|
||||
|
||||
/**
|
||||
* What kind of style is this, Paragraph or Character or Table
|
||||
*/
|
||||
private int styleType = RtfStyleTypes.PARAGRAPH;
|
||||
|
||||
// Alignment
|
||||
/**
|
||||
* Alignment - page 85
|
||||
* \qc, \qj, \ql, \qr, \qd, \qkN, \qt
|
||||
*/
|
||||
private int alignment = Element.ALIGN_LEFT;
|
||||
/**
|
||||
* Percentage of line occupied by Kashida justification (0 <20> low, 10 <20> medium, 20 <20> high).
|
||||
* \qkN
|
||||
*/
|
||||
private int justificationPercentage = 0;
|
||||
|
||||
// Indentation
|
||||
/**
|
||||
* First line indentation.
|
||||
*/
|
||||
private int firstLineIndent = 0;
|
||||
/**
|
||||
* Left indentation
|
||||
*/
|
||||
private int leftIndent = 0;
|
||||
/**
|
||||
* Right indentation
|
||||
*/
|
||||
private int rightIndent = 0;
|
||||
/**
|
||||
* Automatically adjust right indentation when docunent grid is defined
|
||||
*/
|
||||
private int adustRightIndent = 0;
|
||||
/**
|
||||
* Mirror indents?
|
||||
*/
|
||||
private int mirrorIndent = 0;
|
||||
|
||||
// Document Foratting Properties
|
||||
/**
|
||||
* Override orphan/widow control.
|
||||
*/
|
||||
private int overrideWidowControl = -1;
|
||||
|
||||
// Asian Typography
|
||||
/**
|
||||
* auto spacing betwee DBC and English
|
||||
*/
|
||||
private int AutoSpaceBetweenDBCEnglish = 0;
|
||||
/**
|
||||
* auto spacing betwee DBC and numbers
|
||||
*/
|
||||
private int AutoSpaceBetweenDBCNumbers = 0;
|
||||
/**
|
||||
* No Character wrapping
|
||||
*/
|
||||
private int noCharacterWrapping = 0;
|
||||
/**
|
||||
* No Word wrapping
|
||||
*/
|
||||
private int noWordWrapping = 0;
|
||||
/**
|
||||
* No overflow period and comma
|
||||
*/
|
||||
private int noOverflowPeriodComma = 0;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
/**
|
||||
* The RtfImportHeader to add color mappings to.
|
||||
*/
|
||||
private RtfImportMgr importHeader = null;
|
||||
private String type = "";
|
||||
|
||||
public RtfDestinationStylesheetTable() : base(null) {
|
||||
}
|
||||
|
||||
public RtfDestinationStylesheetTable(RtfParser parser, String type) : base(parser){
|
||||
this.importHeader = parser.GetImportManager();
|
||||
this.type = type;
|
||||
}
|
||||
public override void SetParser(RtfParser parser) {
|
||||
this.rtfParser = parser;
|
||||
this.importHeader = parser.GetImportManager();
|
||||
}
|
||||
public void SetType(String value) {
|
||||
this.type = value;
|
||||
}
|
||||
public void SetElementName(String value) {
|
||||
this.elementName = value;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
|
||||
*/
|
||||
public override bool HandleOpeningSubGroup() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
|
||||
*/
|
||||
public override bool CloseDestination() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
|
||||
bool result = true;
|
||||
this.OnCtrlWord(ctrlWordData); // event handler
|
||||
|
||||
if (this.rtfParser.IsImport()) {
|
||||
// information
|
||||
if (ctrlWordData.ctrlWord.Equals("s")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("cs")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("ds")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("ts")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("tsrowd")) {}
|
||||
|
||||
if (ctrlWordData.ctrlWord.Equals("keycode")) {}
|
||||
if (ctrlWordData.ctrlWord.Equals("shift")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("ctrl")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("alt")) { }
|
||||
//cells
|
||||
if (ctrlWordData.ctrlWord.Equals("fn")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("additive")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("sbasedon")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("snext")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("sautoupd")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("shidden")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("slink")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("slocked")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("spersonal")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("scompose")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("sreply")) { }
|
||||
/* FORMATTING */
|
||||
// brdrdef/parfmt/apoctl/tabdef/shading/chrfmt
|
||||
|
||||
|
||||
|
||||
if (ctrlWordData.ctrlWord.Equals("styrsid")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("ssemihidden")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("sqformat")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("spriority")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("sunhideused")) { }
|
||||
|
||||
/* TABLE STYLES */
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellwidth")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellwidthfts")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddt")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddl")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddr")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddb")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddft"))/*0-auto, 3-twips*/ { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddfl"))/*0-auto, 3-twips*/ { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddfr"))/*0-auto, 3-twips*/ { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellpaddfb"))/*0-auto, 3-twips*/ { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsvertalt")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsvertalc")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsvertalb")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsnowrap")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellcfpat")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscellcbpat")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgbdiag")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgfdiag")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgcross")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgdcross")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgdkcross ")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgdkdcross")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbghoriz")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgvert")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgdkhor")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbgdkvert")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrt")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrb")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrl")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrr")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrh")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrv")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrdgl")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tsbrdrdgr")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscbandsh")) { }
|
||||
if (ctrlWordData.ctrlWord.Equals("tscbandsv")) { }
|
||||
}
|
||||
if (ctrlWordData.ctrlWordType == RtfCtrlWordType.FLAG ||
|
||||
ctrlWordData.ctrlWordType == RtfCtrlWordType.TOGGLE ||
|
||||
ctrlWordData.ctrlWordType == RtfCtrlWordType.VALUE) {
|
||||
this.rtfParser.GetState().properties.SetProperty(ctrlWordData);
|
||||
}
|
||||
|
||||
switch (this.rtfParser.GetConversionType()) {
|
||||
case RtfParser.TYPE_IMPORT_FULL:
|
||||
result = true;
|
||||
break;
|
||||
case RtfParser.TYPE_IMPORT_FRAGMENT:
|
||||
result = true;
|
||||
break;
|
||||
case RtfParser.TYPE_CONVERT:
|
||||
result = true;
|
||||
break;
|
||||
default: // error because is should be an import or convert
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
|
||||
*/
|
||||
public override bool HandleCloseGroup() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
|
||||
*/
|
||||
public override bool HandleOpenGroup() {
|
||||
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
|
||||
*/
|
||||
public override bool HandleCharacter(int ch) {
|
||||
styleName += (char)ch;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CreateNewStyle() {
|
||||
//public RtfParagraphStyle(String styleName, String fontName, int fontSize, int fontStyle, Color fontColor)
|
||||
//this.rtfParagraphStyle = new RtfParagraphStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the justification percentage from parsed value.
|
||||
* @param percent The justification percentage
|
||||
* @return The justification percentage
|
||||
*/
|
||||
public int SetJustificationPercentage(int percent) {
|
||||
this.justificationPercentage = percent;
|
||||
return this.justificationPercentage;
|
||||
}
|
||||
/**
|
||||
* Get the justification percentage.
|
||||
* @return The justification percentage value.
|
||||
*/
|
||||
public int GetJustificationPercentage() {
|
||||
return this.justificationPercentage;
|
||||
}
|
||||
/**
|
||||
* Set the alignment value from the parsed value.
|
||||
* @param alignment The alignment value.
|
||||
* @return The alignment value.
|
||||
*/
|
||||
public int SetAlignment(int alignment) {
|
||||
this.alignment = alignment;
|
||||
return this.alignment;
|
||||
}
|
||||
/**
|
||||
* Get the alignment value.
|
||||
* @return The alignment value.
|
||||
*/
|
||||
public int GetAlignment() {
|
||||
return this.alignment;
|
||||
}
|
||||
/**
|
||||
* Get the first line indent value.
|
||||
*
|
||||
* @return the firstLineIndent
|
||||
*/
|
||||
public int GetFirstLineIndent() {
|
||||
return firstLineIndent;
|
||||
}
|
||||
/**
|
||||
* Set the first line indent value.
|
||||
* @param firstLineIndent the firstLineIndent to set
|
||||
*/
|
||||
public void SetFirstLineIndent(int firstLineIndent) {
|
||||
this.firstLineIndent = firstLineIndent;
|
||||
}
|
||||
/**
|
||||
* Get the left indent value
|
||||
* @return the left indent
|
||||
*/
|
||||
public int GetIndent() {
|
||||
return leftIndent;
|
||||
}
|
||||
/**
|
||||
* Set the left indent value from the value parsed.
|
||||
* @param indent the left indent value.
|
||||
*/
|
||||
public void SetIndent(int indent) {
|
||||
this.leftIndent = indent;
|
||||
}
|
||||
/**
|
||||
* Get the right indent adjustment value
|
||||
* @return the adustRightIndent value
|
||||
*/
|
||||
public int GetAdustRightIndent() {
|
||||
return adustRightIndent;
|
||||
}
|
||||
/**
|
||||
* Set the right indent adjustment value
|
||||
* @param adustRightIndent the adustRightIndent to set
|
||||
*/
|
||||
public void SetAdustRightIndent(int adustRightIndent) {
|
||||
this.adustRightIndent = adustRightIndent;
|
||||
}
|
||||
/**
|
||||
* Get the left indent value
|
||||
* @return the leftIndent
|
||||
*/
|
||||
public int GetLeftIndent() {
|
||||
return leftIndent;
|
||||
}
|
||||
/**
|
||||
* Set the left indent value
|
||||
* @param leftIndent the leftIndent to set
|
||||
*/
|
||||
public void SetLeftIndent(int leftIndent) {
|
||||
this.leftIndent = leftIndent;
|
||||
}
|
||||
/**
|
||||
* Get the value indicating if document has mirrored indents.
|
||||
*
|
||||
* @return the mirrorIndent
|
||||
*/
|
||||
public int GetMirrorIndent() {
|
||||
return mirrorIndent;
|
||||
}
|
||||
/**
|
||||
* Set the mirrored indent value from the parsed value.
|
||||
*
|
||||
* @param mirrorIndent the mirrorIndent to set
|
||||
*/
|
||||
public void SetMirrorIndent(int mirrorIndent) {
|
||||
this.mirrorIndent = mirrorIndent;
|
||||
}
|
||||
/**
|
||||
* Get the right indent value.
|
||||
*
|
||||
* @return the rightIndent
|
||||
*/
|
||||
public int GetRightIndent() {
|
||||
return rightIndent;
|
||||
}
|
||||
/**
|
||||
* Set the right indent value.
|
||||
*
|
||||
* @param rightIndent the rightIndent to set
|
||||
*/
|
||||
public void SetRightIndent(int rightIndent) {
|
||||
this.rightIndent = rightIndent;
|
||||
}
|
||||
/**
|
||||
* Get the ovirride widow control value.
|
||||
*
|
||||
* @return the overrideWidowControl
|
||||
*/
|
||||
public int GetOverrideWidowControl() {
|
||||
return overrideWidowControl;
|
||||
}
|
||||
/**
|
||||
* Set the override widow control.
|
||||
*
|
||||
* @param overrideWidowControl the overrideWidowControl to set
|
||||
*/
|
||||
public void SetOverrideWidowControl(int overrideWidowControl) {
|
||||
this.overrideWidowControl = overrideWidowControl;
|
||||
}
|
||||
/**
|
||||
* Get the auto space between DBC and English indicator.
|
||||
*
|
||||
* @return the autoSpaceBetweenDBCEnglish
|
||||
*/
|
||||
public int GetAutoSpaceBetweenDBCEnglish() {
|
||||
return AutoSpaceBetweenDBCEnglish;
|
||||
}
|
||||
/**
|
||||
* Set the auto space between DBC and English indicator.
|
||||
*
|
||||
* @param autoSpaceBetweenDBCEnglish the autoSpaceBetweenDBCEnglish to set
|
||||
*/
|
||||
public void SetAutoSpaceBetweenDBCEnglish(int autoSpaceBetweenDBCEnglish) {
|
||||
AutoSpaceBetweenDBCEnglish = autoSpaceBetweenDBCEnglish;
|
||||
}
|
||||
/**
|
||||
* Get the auto space between DBC and Numbers indicator.
|
||||
* @return the autoSpaceBetweenDBCNumbers
|
||||
*/
|
||||
public int GetAutoSpaceBetweenDBCNumbers() {
|
||||
return AutoSpaceBetweenDBCNumbers;
|
||||
}
|
||||
/**
|
||||
* Set the auto space between DBC and Numbers indicator.
|
||||
* @param autoSpaceBetweenDBCNumbers the autoSpaceBetweenDBCNumbers to set
|
||||
*/
|
||||
public void SetAutoSpaceBetweenDBCNumbers(int autoSpaceBetweenDBCNumbers) {
|
||||
AutoSpaceBetweenDBCNumbers = autoSpaceBetweenDBCNumbers;
|
||||
}
|
||||
/**
|
||||
* Get no character wrapping indicator.
|
||||
*
|
||||
* @return the noCharacterWrapping
|
||||
*/
|
||||
public int GetNoCharacterWrapping() {
|
||||
return noCharacterWrapping;
|
||||
}
|
||||
/**
|
||||
* Set the no character wrapping indicator from parsed value
|
||||
*
|
||||
* @param noCharacterWrapping the noCharacterWrapping to set
|
||||
*/
|
||||
public void SetNoCharacterWrapping(int noCharacterWrapping) {
|
||||
this.noCharacterWrapping = noCharacterWrapping;
|
||||
}
|
||||
/**
|
||||
* Get the no overflow period comma indicator.
|
||||
*
|
||||
* @return the noOverflowPeriodComma
|
||||
*/
|
||||
public int GetNoOverflowPeriodComma() {
|
||||
return noOverflowPeriodComma;
|
||||
}
|
||||
/**
|
||||
* Set the no overflow period comma indicator from the parsed value.
|
||||
*
|
||||
* @param noOverflowPeriodComma the noOverflowPeriodComma to set
|
||||
*/
|
||||
public void SetNoOverflowPeriodComma(int noOverflowPeriodComma) {
|
||||
this.noOverflowPeriodComma = noOverflowPeriodComma;
|
||||
}
|
||||
/**
|
||||
* Get the no word wrapping indicator.
|
||||
*
|
||||
* @return the noWordWrapping
|
||||
*/
|
||||
public int GetNoWordWrapping() {
|
||||
return noWordWrapping;
|
||||
}
|
||||
/**
|
||||
* Set the no word wrapping indicator from the parsed value.
|
||||
*
|
||||
* @param noWordWrapping the noWordWrapping to set
|
||||
*/
|
||||
public void SetNoWordWrapping(int noWordWrapping) {
|
||||
this.noWordWrapping = noWordWrapping;
|
||||
}
|
||||
/**
|
||||
* Get this style number.
|
||||
*
|
||||
* @return the styleNr
|
||||
*/
|
||||
public int GetStyleNr() {
|
||||
return styleNr;
|
||||
}
|
||||
/**
|
||||
* Set this style number from the parsed value.
|
||||
*
|
||||
* @param styleNr the styleNr to set
|
||||
*/
|
||||
public void SetStyleNr(int styleNr) {
|
||||
this.styleNr = styleNr;
|
||||
}
|
||||
/**
|
||||
* Get this style type.
|
||||
* For example Style, Character Style, etc.
|
||||
*
|
||||
* @return the styleType
|
||||
*/
|
||||
public int GetStyleType() {
|
||||
return styleType;
|
||||
}
|
||||
/**
|
||||
* Set the style type.
|
||||
*
|
||||
* @param styleType the styleType to set
|
||||
*/
|
||||
public void SetStyleType(int styleType) {
|
||||
this.styleType = styleType;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setToDefaults()
|
||||
*/
|
||||
public override void SetToDefaults() {
|
||||
styleName = "";
|
||||
styleNr = 0;
|
||||
alignment = Element.ALIGN_LEFT;
|
||||
justificationPercentage = 0;
|
||||
firstLineIndent = 0;
|
||||
leftIndent = 0;
|
||||
rightIndent = 0;
|
||||
adustRightIndent = 0;
|
||||
mirrorIndent = 0;
|
||||
overrideWidowControl = -1;
|
||||
AutoSpaceBetweenDBCEnglish = 0;
|
||||
AutoSpaceBetweenDBCNumbers = 0;
|
||||
noCharacterWrapping = 0;
|
||||
noWordWrapping = 0;
|
||||
noOverflowPeriodComma = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace iTextSharp.text.rtf.parser.enumerations {
|
||||
|
||||
/**
|
||||
* Specifies the color theme values for use in Color Tables.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public sealed class RtfColorThemes {
|
||||
public const int THEME_UNDEFINED = -1;
|
||||
public const int THEME_MAINDARKONE = 0;
|
||||
public const int THEME_MAINDARKTWO = 1;
|
||||
public const int THEME_MAINLIGHTONE = 2;
|
||||
public const int THEME_MAINLIGHTTWO = 3;
|
||||
public const int THEME_ACCENTONE = 4;
|
||||
public const int THEME_ACCENTTWO = 5;
|
||||
public const int THEME_ACCENTTHREE = 6;
|
||||
public const int THEME_ACCENTFOUR = 7;
|
||||
public const int THEME_ACCENTFIVE = 8;
|
||||
public const int THEME_ACCENTSIX = 9;
|
||||
public const int THEME_HYPERLINK = 10;
|
||||
public const int THEME_FOLLOWEDHYPERLINK = 11;
|
||||
public const int THEME_BACKGROUNDONE = 12;
|
||||
public const int THEME_TEXTONE = 13;
|
||||
public const int THEME_BACKGROUNDTWO = 14;
|
||||
public const int THEME_TEXTTWO = 15;
|
||||
public const int THEME_MAX = 15;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
/*
|
||||
* $Id: RtfParserException.cs,v 1.2 2008/05/13 11:26:02 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.parser.exceptions {
|
||||
|
||||
/*
|
||||
* Signals that an error has occurred in a <CODE>RtfParser</CODE>.
|
||||
*/
|
||||
/**
|
||||
* <code>RtfParserException</code> is the exception object thrown by
|
||||
* the parser
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfParserException : Exception {
|
||||
/**
|
||||
* Creates a RtfParserException object.
|
||||
* @param ex an exception that has to be turned into a RtfParserException
|
||||
*/
|
||||
public RtfParserException(Exception ex) : base("", ex) {
|
||||
}
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>RtfParserException</CODE> whithout a message.
|
||||
*/
|
||||
public RtfParserException() : base() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>RtfParserException</code> with a message.
|
||||
*
|
||||
* @param message a message describing the exception
|
||||
*/
|
||||
public RtfParserException(String message) : base(message) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace iTextSharp.text.rtf.parser.exceptions {
|
||||
|
||||
public class RtfUnknownCtrlWordException : RtfParserException {
|
||||
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Constructs a <CODE>RtfParserException</CODE> whithout a message.
|
||||
*/
|
||||
public RtfUnknownCtrlWordException() : base("Unknown control word.") {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using iTextSharp.text.rtf.parser;
|
||||
/*
|
||||
* $Id: IRtfPropertyListener.cs,v 1.2 2008/05/13 11:26:03 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.parser.properties {
|
||||
|
||||
/**
|
||||
* <code>RtfPropertyListener</code> interface for handling events.
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
*
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public interface IRtfPropertyListener : IEventListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void BeforePropertyChange(String propertyName);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void AfterPropertyChange(String propertyName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/* $Id: RtfCtrlWordPropertyType.cs,v 1.3 2008/05/13 11:26:03 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.parser.properties {
|
||||
|
||||
public class RtfCtrlWordPropertyType {
|
||||
public const int UNIDENTIFIED = -1;
|
||||
public const int PROPERTY = 0;
|
||||
public const int CHARACTER = 1;
|
||||
public const int SPECIAL = 2;
|
||||
public const int DESTINATION = 3;
|
||||
}
|
||||
}
|
||||
575
iTechSharp/iTextSharp/text/rtf/parser/properties/RtfProperty.cs
Normal file
575
iTechSharp/iTextSharp/text/rtf/parser/properties/RtfProperty.cs
Normal file
@@ -0,0 +1,575 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.parser.ctrlwords;
|
||||
|
||||
/* $Id: RtfProperty.cs,v 1.3 2008/05/13 11:26:03 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.parser.properties {
|
||||
|
||||
/**
|
||||
* <code>RtfProperty</code> handles document, paragraph, etc. property values
|
||||
*
|
||||
* @author Howard Shank (hgshank@yahoo.com)
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public class RtfProperty {
|
||||
public const int OFF = 0;
|
||||
public const int ON = 1;
|
||||
|
||||
/* property groups */
|
||||
public const String COLOR = "color.";
|
||||
public const String CHARACTER = "character.";
|
||||
public const String PARAGRAPH = "paragraph.";
|
||||
public const String SECTION = "section.";
|
||||
public const String DOCUMENT = "document.";
|
||||
|
||||
/* color properties */
|
||||
public const String COLOR_FG = COLOR + "fg"; //Color Object
|
||||
public const String COLOR_BG = COLOR + "bg"; //Color Object
|
||||
|
||||
/* character properties */
|
||||
public const String CHARACTER_BOLD = CHARACTER + "bold";
|
||||
public const String CHARACTER_UNDERLINE = CHARACTER + "underline";
|
||||
public const String CHARACTER_ITALIC = CHARACTER + "italic";
|
||||
public const String CHARACTER_SIZE = CHARACTER + "size";
|
||||
public const String CHARACTER_FONT = CHARACTER + "font";
|
||||
public const String CHARACTER_STYLE = CHARACTER + "style";
|
||||
|
||||
/* paragraph properties */
|
||||
/** Justify left */
|
||||
public const int JUSTIFY_LEFT = 0;
|
||||
/** Justify right */
|
||||
public const int JUSTIFY_RIGHT = 1;
|
||||
/** Justify center */
|
||||
public const int JUSTIFY_CENTER = 2;
|
||||
/** Justify full */
|
||||
public const int JUSTIFY_FULL = 3;
|
||||
|
||||
public const String PARAGRAPH_INDENT_LEFT = PARAGRAPH + "indentLeft"; // twips
|
||||
public const String PARAGRAPH_INDENT_RIGHT = PARAGRAPH + "indentRight"; // twips
|
||||
public const String PARAGRAPH_INDENT_FIRST_LINE = PARAGRAPH + "indentFirstLine"; // twips
|
||||
public const String PARAGRAPH_JUSTIFICATION = PARAGRAPH + "justification";
|
||||
|
||||
public const String PARAGRAPH_BORDER = PARAGRAPH + "border";
|
||||
public const String PARAGRAPH_BORDER_CELL = PARAGRAPH + "borderCell";
|
||||
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_NIL = 0;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_BOTTOM = 1;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_TOP = 2;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_LEFT = 4;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_RIGHT = 8;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_DIAGONAL_UL_LR = 16;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_DIAGONAL_UR_LL = 32;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_TABLE_HORIZONTAL = 64;
|
||||
/** possible border settting */
|
||||
public const int PARAGRAPH_BORDER_TABLE_VERTICAL = 128;
|
||||
|
||||
/* section properties */
|
||||
/** Decimal number format */
|
||||
public const int PGN_DECIMAL = 0;
|
||||
/** Uppercase Roman Numeral */
|
||||
public const int PGN_ROMAN_NUMERAL_UPPERCASE = 1;
|
||||
/** Lowercase Roman Numeral */
|
||||
public const int PGN_ROMAN_NUMERAL_LOWERCASE = 2;
|
||||
/** Uppercase Letter */
|
||||
public const int PGN_LETTER_UPPERCASE = 3;
|
||||
/** Lowercase Letter */
|
||||
public const int PGN_LETTER_LOWERCASE = 4;
|
||||
/** Section Break None */
|
||||
public const int SBK_NONE = 0;
|
||||
/** Section Break Column break */
|
||||
public const int SBK_COLUMN = 1;
|
||||
/** Section Break Even page break */
|
||||
public const int SBK_EVEN = 2;
|
||||
/** Section Break Odd page break */
|
||||
public const int SBK_ODD = 3;
|
||||
/** Section Break Page break */
|
||||
public const int SBK_PAGE = 4;
|
||||
|
||||
public const String SECTION_NUMBER_OF_COLUMNS = SECTION + "numberOfColumns";
|
||||
public const String SECTION_BREAK_TYPE = SECTION + "SectionBreakType";
|
||||
public const String SECTION_PAGE_NUMBER_POSITION_X = SECTION + "pageNumberPositionX";
|
||||
public const String SECTION_PAGE_NUMBER_POSITION_Y = SECTION + "pageNumberPositionY";
|
||||
public const String SECTION_PAGE_NUMBER_FORMAT = SECTION + "pageNumberFormat";
|
||||
|
||||
/* document properties */
|
||||
/** Portrait orientation */
|
||||
public const String PAGE_PORTRAIT = "0";
|
||||
/** Landscape orientation */
|
||||
public const String PAGE_LANDSCAPE = "1";
|
||||
|
||||
public const String DOCUMENT_PAGE_WIDTH_TWIPS = DOCUMENT + "pageWidthTwips";
|
||||
public const String DOCUMENT_PAGE_HEIGHT_TWIPS = DOCUMENT + "pageHeightTwips";
|
||||
public const String DOCUMENT_MARGIN_LEFT_TWIPS = DOCUMENT + "marginLeftTwips";
|
||||
public const String DOCUMENT_MARGIN_TOP_TWIPS = DOCUMENT + "marginTopTwips";
|
||||
public const String DOCUMENT_MARGIN_RIGHT_TWIPS = DOCUMENT + "marginRightTwips";
|
||||
public const String DOCUMENT_MARGIN_BOTTOM_TWIPS = DOCUMENT + "marginBottomTwips";
|
||||
public const String DOCUMENT_PAGE_NUMBER_START = DOCUMENT + "pageNumberStart";
|
||||
public const String DOCUMENT_ENABLE_FACING_PAGES = DOCUMENT + "enableFacingPages";
|
||||
public const String DOCUMENT_PAGE_ORIENTATION = DOCUMENT + "pageOrientation";
|
||||
public const String DOCUMENT_DEFAULT_FONT_NUMER = DOCUMENT + "defaultFontNumber";
|
||||
|
||||
/** Properties for this RtfProperty object */
|
||||
protected Hashtable properties = new Hashtable();
|
||||
|
||||
private bool modifiedCharacter = false;
|
||||
private bool modifiedParagraph = false;
|
||||
private bool modifiedSection = false;
|
||||
private bool modifiedDocument = false;
|
||||
|
||||
|
||||
/** The <code>RtfPropertyListener</code>. */
|
||||
private ArrayList listeners = new ArrayList();
|
||||
/**
|
||||
* Set all property objects to default values.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetToDefault() {
|
||||
SetToDefault(COLOR);
|
||||
SetToDefault(CHARACTER);
|
||||
SetToDefault(PARAGRAPH);
|
||||
SetToDefault(SECTION);
|
||||
SetToDefault(DOCUMENT);
|
||||
}
|
||||
/**
|
||||
* Set individual property group to default values.
|
||||
* @param propertyGroup <code>String</code> name of the property group to set to default.
|
||||
* @since 2.0.8
|
||||
*/
|
||||
public void SetToDefault(String propertyGroup) {
|
||||
if (COLOR.Equals(propertyGroup)) {
|
||||
SetProperty(COLOR_FG, new Color(0,0,0));
|
||||
SetProperty(COLOR_BG, new Color(255,255,255));
|
||||
return;
|
||||
}
|
||||
if (CHARACTER.Equals(propertyGroup)) {
|
||||
SetProperty(CHARACTER_BOLD, 0);
|
||||
SetProperty(CHARACTER_UNDERLINE, 0);
|
||||
SetProperty(CHARACTER_ITALIC, 0);
|
||||
SetProperty(CHARACTER_SIZE, 24);// 1/2 pt sizes
|
||||
SetProperty(CHARACTER_FONT, 0);
|
||||
return;
|
||||
}
|
||||
if (PARAGRAPH.Equals(propertyGroup)) {
|
||||
SetProperty(PARAGRAPH_INDENT_LEFT, 0);
|
||||
SetProperty(PARAGRAPH_INDENT_RIGHT, 0);
|
||||
SetProperty(PARAGRAPH_INDENT_FIRST_LINE, 0);
|
||||
SetProperty(PARAGRAPH_JUSTIFICATION, JUSTIFY_LEFT);
|
||||
SetProperty(PARAGRAPH_BORDER, PARAGRAPH_BORDER_NIL);
|
||||
SetProperty(PARAGRAPH_BORDER_CELL, PARAGRAPH_BORDER_NIL);
|
||||
return;
|
||||
}
|
||||
if (SECTION.Equals(propertyGroup)) {
|
||||
SetProperty(SECTION_NUMBER_OF_COLUMNS, 0);
|
||||
SetProperty(SECTION_BREAK_TYPE, SBK_NONE);
|
||||
SetProperty(SECTION_PAGE_NUMBER_POSITION_X, 0);
|
||||
SetProperty(SECTION_PAGE_NUMBER_POSITION_Y, 0);
|
||||
SetProperty(SECTION_PAGE_NUMBER_FORMAT, PGN_DECIMAL);
|
||||
return;
|
||||
}
|
||||
if (DOCUMENT.Equals(propertyGroup)) {
|
||||
SetProperty(DOCUMENT_PAGE_WIDTH_TWIPS, 12240);
|
||||
SetProperty(DOCUMENT_PAGE_HEIGHT_TWIPS, 15480);
|
||||
SetProperty(DOCUMENT_MARGIN_LEFT_TWIPS, 1800);
|
||||
SetProperty(DOCUMENT_MARGIN_TOP_TWIPS, 1440);
|
||||
SetProperty(DOCUMENT_MARGIN_RIGHT_TWIPS, 1800);
|
||||
SetProperty(DOCUMENT_MARGIN_BOTTOM_TWIPS, 1440);
|
||||
SetProperty(DOCUMENT_PAGE_NUMBER_START, 1);
|
||||
SetProperty(DOCUMENT_ENABLE_FACING_PAGES, 1);
|
||||
SetProperty(DOCUMENT_PAGE_ORIENTATION, PAGE_PORTRAIT);
|
||||
SetProperty(DOCUMENT_DEFAULT_FONT_NUMER, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggle the value of the property identified by the <code>RtfCtrlWordData.specialHandler</code> parameter.
|
||||
* Toggle values are assumed to be integer values per the RTF spec with a value of 0=off or 1=on.
|
||||
*
|
||||
* @param ctrlWordData The property name to set
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code> or <i>blank</i>
|
||||
*/
|
||||
public bool ToggleProperty(RtfCtrlWordData ctrlWordData) { //String propertyName) {
|
||||
|
||||
String propertyName = ctrlWordData.specialHandler;
|
||||
|
||||
if (propertyName == null || propertyName.Length == 0) return false;
|
||||
|
||||
Object propertyValue = GetProperty(propertyName);
|
||||
if (propertyValue == null) {
|
||||
propertyValue = RtfProperty.ON;
|
||||
} else {
|
||||
if (propertyValue is int) {
|
||||
int value = (int)propertyValue;
|
||||
if (value != 0) {
|
||||
RemoveProperty(propertyName);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (propertyValue is long) {
|
||||
long value = (long)propertyValue;
|
||||
if (value != 0) {
|
||||
RemoveProperty(propertyName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetProperty(propertyName, propertyValue);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Set the value of the property identified by the parameter.
|
||||
*
|
||||
* @param ctrlWordData The controlword with the name to set
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> or <code>propertyValue</code> is <code>null</code>
|
||||
*/
|
||||
public bool SetProperty(RtfCtrlWordData ctrlWordData) { //String propertyName, Object propertyValueNew) {
|
||||
String propertyName = ctrlWordData.specialHandler;
|
||||
Object propertyValueNew = ctrlWordData.param;
|
||||
// depending on the control word, set mulitiple or reset settings, etc.
|
||||
//if pard then reset settings
|
||||
//
|
||||
SetProperty(propertyName, propertyValueNew);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Set the value of the property identified by the parameter.
|
||||
*
|
||||
* @param propertyName The property name to set
|
||||
* @param propertyValueNew The object to set the property value to
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> or <code>propertyValue</code> is <code>null</code>
|
||||
*/
|
||||
private bool SetProperty(String propertyName, Object propertyValueNew) {
|
||||
if (propertyName == null || propertyValueNew == null) return false;
|
||||
|
||||
Object propertyValueOld = GetProperty(propertyName);
|
||||
if (propertyValueOld is int && propertyValueNew is int) {
|
||||
int valueOld = (int)propertyValueOld;
|
||||
int valueNew = (int)propertyValueNew;
|
||||
if (valueOld==valueNew) return true;
|
||||
} else {
|
||||
if (propertyValueOld is long && propertyValueNew is long) {
|
||||
long valueOld = (long)propertyValueOld;
|
||||
long valueNew = (long)propertyValueNew;
|
||||
if (valueOld==valueNew) return true;
|
||||
}
|
||||
}
|
||||
BeforeChange(propertyName);
|
||||
properties[propertyName] = propertyValueNew;
|
||||
AfterChange(propertyName);
|
||||
SetModified(propertyName, true);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Set the value of the property identified by the parameter.
|
||||
*
|
||||
* @param propertyName The property name to set
|
||||
* @param propertyValue The object to set the property value to
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
|
||||
*/
|
||||
private bool SetProperty(String propertyName, int propertyValueNew) {
|
||||
if (propertyName == null) return false;
|
||||
Object propertyValueOld = GetProperty(propertyName);
|
||||
if (propertyValueOld is int) {
|
||||
int valueOld = (int)propertyValueOld;
|
||||
if (valueOld==propertyValueNew) return true;
|
||||
}
|
||||
BeforeChange(propertyName);
|
||||
properties[propertyName] = propertyValueNew;
|
||||
AfterChange(propertyName);
|
||||
SetModified(propertyName, true);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Add the value of the property identified by the parameter.
|
||||
*
|
||||
* @param propertyName The property name to set
|
||||
* @param propertyValue The object to set the property value to
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
|
||||
*/
|
||||
private bool AddToProperty(String propertyName, int propertyValue) {
|
||||
if (propertyName == null) return false;
|
||||
int value = (int)properties[propertyName];
|
||||
if ((value | propertyValue) == value) return true;
|
||||
value |= propertyValue;
|
||||
BeforeChange(propertyName);
|
||||
properties[propertyName] = value;
|
||||
AfterChange(propertyName);
|
||||
SetModified(propertyName, true);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Set the value of the property identified by the parameter.
|
||||
*
|
||||
* @param propertyName The property name to set
|
||||
* @param propertyValue The object to set the property value to
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
|
||||
*/
|
||||
private bool SetProperty(String propertyName, long propertyValueNew) {
|
||||
if (propertyName == null) return false;
|
||||
Object propertyValueOld = GetProperty(propertyName);
|
||||
if (propertyValueOld is long) {
|
||||
long valueOld = (long)propertyValueOld;
|
||||
if (valueOld==propertyValueNew) return true;
|
||||
}
|
||||
BeforeChange(propertyName);
|
||||
properties[propertyName] = propertyValueNew;
|
||||
AfterChange(propertyName);
|
||||
SetModified(propertyName, true);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Add the value of the property identified by the parameter.
|
||||
*
|
||||
* @param propertyName The property name to set
|
||||
* @param propertyValue The object to set the property value to
|
||||
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
|
||||
*/
|
||||
private bool AddToProperty(String propertyName, long propertyValue) {
|
||||
if (propertyName == null) return false;
|
||||
long value = (long)properties[propertyName];
|
||||
if ((value | propertyValue) == value) return true;
|
||||
value |= propertyValue;
|
||||
BeforeChange(propertyName);
|
||||
properties[propertyName] = value;
|
||||
AfterChange(propertyName);
|
||||
SetModified(propertyName, true);
|
||||
return true;
|
||||
}
|
||||
private bool RemoveProperty(String propertyName) {
|
||||
if (propertyName == null) return false;
|
||||
if (properties.ContainsKey(propertyName)) {
|
||||
BeforeChange(propertyName);
|
||||
properties.Remove(propertyName);
|
||||
AfterChange(propertyName);
|
||||
SetModified(propertyName, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Get the value of the property identified by the parameter.
|
||||
*
|
||||
* @param propertyName String containing the property name to get
|
||||
* @return Property Object requested or null if not found in map.
|
||||
*/
|
||||
public Object GetProperty(String propertyName) {
|
||||
return properties[propertyName];
|
||||
}
|
||||
/**
|
||||
* Get a group of properties.
|
||||
*
|
||||
* @param propertyGroup The group name to obtain.
|
||||
* @return Properties object with requested values.
|
||||
*/
|
||||
public Hashtable GetProperties(String propertyGroup) {
|
||||
Hashtable props = new Hashtable();
|
||||
if (properties.Count != 0) {
|
||||
//properties.get
|
||||
foreach (String key in properties.Keys) {
|
||||
if (key.StartsWith(propertyGroup)) {
|
||||
props[key] = properties[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the modified
|
||||
*/
|
||||
public bool IsModified() {
|
||||
return modifiedCharacter || modifiedParagraph || modifiedSection || modifiedDocument;
|
||||
}
|
||||
/**
|
||||
* @param propertyName the propertyName that is modified
|
||||
* @param modified the modified to set
|
||||
*/
|
||||
public void SetModified(String propertyName, bool modified) {
|
||||
if (propertyName.StartsWith(CHARACTER)) {
|
||||
this.SetModifiedCharacter(modified);
|
||||
} else {
|
||||
if (propertyName.StartsWith(PARAGRAPH)) {
|
||||
this.SetModifiedParagraph(modified);
|
||||
} else {
|
||||
if (propertyName.StartsWith(SECTION)) {
|
||||
this.SetModifiedSection(modified);
|
||||
} else {
|
||||
if (propertyName.StartsWith(DOCUMENT)) {
|
||||
this.SetModifiedDocument(modified);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return the modifiedCharacter
|
||||
*/
|
||||
public bool IsModifiedCharacter() {
|
||||
return modifiedCharacter;
|
||||
}
|
||||
/**
|
||||
* @param modifiedCharacter the modifiedCharacter to set
|
||||
*/
|
||||
public void SetModifiedCharacter(bool modifiedCharacter) {
|
||||
this.modifiedCharacter = modifiedCharacter;
|
||||
}
|
||||
/**
|
||||
* @return the modifiedParagraph
|
||||
*/
|
||||
public bool IsModifiedParagraph() {
|
||||
return modifiedParagraph;
|
||||
}
|
||||
/**
|
||||
* @param modifiedParagraph the modifiedParagraph to set
|
||||
*/
|
||||
public void SetModifiedParagraph(bool modifiedParagraph) {
|
||||
this.modifiedParagraph = modifiedParagraph;
|
||||
}
|
||||
/**
|
||||
* @return the modifiedSection
|
||||
*/
|
||||
public bool IsModifiedSection() {
|
||||
return modifiedSection;
|
||||
}
|
||||
/**
|
||||
* @param modifiedSection the modifiedSection to set
|
||||
*/
|
||||
public void SetModifiedSection(bool modifiedSection) {
|
||||
this.modifiedSection = modifiedSection;
|
||||
}
|
||||
/**
|
||||
* @return the modifiedDocument
|
||||
*/
|
||||
public bool IsModifiedDocument() {
|
||||
return modifiedDocument;
|
||||
}
|
||||
/**
|
||||
* @param modifiedDocument the modifiedDocument to set
|
||||
*/
|
||||
public void SetModifiedDocument(bool modifiedDocument) {
|
||||
this.modifiedDocument = modifiedDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <CODE>RtfPropertyListener</CODE> to the <CODE>RtfProperty</CODE>.
|
||||
*
|
||||
* @param listener
|
||||
* the new RtfPropertyListener.
|
||||
*/
|
||||
public void AddRtfPropertyListener(IRtfPropertyListener listener) {
|
||||
listeners.Add(listener);
|
||||
}
|
||||
/**
|
||||
* Removes a <CODE>RtfPropertyListener</CODE> from the <CODE>RtfProperty</CODE>.
|
||||
*
|
||||
* @param listener
|
||||
* the new RtfPropertyListener.
|
||||
*/
|
||||
public void RemoveRtfPropertyListener(IRtfPropertyListener listener) {
|
||||
listeners.Remove(listener);
|
||||
}
|
||||
|
||||
public void BeforeChange(String propertyName) {
|
||||
// call listener for all
|
||||
foreach (IRtfPropertyListener listener in listeners) {
|
||||
listener.BeforePropertyChange(propertyName);
|
||||
}
|
||||
|
||||
if (propertyName.StartsWith(CHARACTER)) {
|
||||
// call listener for character chane
|
||||
} else {
|
||||
if (propertyName.StartsWith(PARAGRAPH)) {
|
||||
// call listener for paragraph change
|
||||
} else {
|
||||
if (propertyName.StartsWith(SECTION)) {
|
||||
// call listener for section change
|
||||
} else {
|
||||
if (propertyName.StartsWith(DOCUMENT)) {
|
||||
// call listener for document change
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AfterChange(String propertyName) {
|
||||
// call listener for all
|
||||
foreach (IRtfPropertyListener listener in listeners) {
|
||||
listener.AfterPropertyChange(propertyName);
|
||||
}
|
||||
|
||||
if (propertyName.StartsWith(CHARACTER)) {
|
||||
// call listener for character chane
|
||||
} else {
|
||||
if (propertyName.StartsWith(PARAGRAPH)) {
|
||||
// call listener for paragraph change
|
||||
} else {
|
||||
if (propertyName.StartsWith(SECTION)) {
|
||||
// call listener for section change
|
||||
} else {
|
||||
if (propertyName.StartsWith(DOCUMENT)) {
|
||||
// call listener for document change
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
285
iTechSharp/iTextSharp/text/rtf/style/RtfColor.cs
Normal file
285
iTechSharp/iTextSharp/text/rtf/style/RtfColor.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
131
iTechSharp/iTextSharp/text/rtf/style/RtfColorList.cs
Normal file
131
iTechSharp/iTextSharp/text/rtf/style/RtfColorList.cs
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
730
iTechSharp/iTextSharp/text/rtf/style/RtfFont.cs
Normal file
730
iTechSharp/iTextSharp/text/rtf/style/RtfFont.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
147
iTechSharp/iTextSharp/text/rtf/style/RtfFontList.cs
Normal file
147
iTechSharp/iTextSharp/text/rtf/style/RtfFontList.cs
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
675
iTechSharp/iTextSharp/text/rtf/style/RtfParagraphStyle.cs
Normal file
675
iTechSharp/iTextSharp/text/rtf/style/RtfParagraphStyle.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
81
iTechSharp/iTextSharp/text/rtf/style/RtfStyleTypes.cs
Normal file
81
iTechSharp/iTextSharp/text/rtf/style/RtfStyleTypes.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
110
iTechSharp/iTextSharp/text/rtf/style/RtfStylesheetList.cs
Normal file
110
iTechSharp/iTextSharp/text/rtf/style/RtfStylesheetList.cs
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
561
iTechSharp/iTextSharp/text/rtf/table/RtfBorder.cs
Normal file
561
iTechSharp/iTextSharp/text/rtf/table/RtfBorder.cs
Normal file
@@ -0,0 +1,561 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfBorder.cs,v 1.6 2008/05/16 19:31:18 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfBorder handle one row or cell border.
|
||||
* INTERNAL USE ONLY
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Unknown
|
||||
*/
|
||||
public class RtfBorder : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the left row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_LEFT = DocWriter.GetISOBytes("\\trbrdrl");
|
||||
/**
|
||||
* Constant for the top row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_TOP = DocWriter.GetISOBytes("\\trbrdrt");
|
||||
/**
|
||||
* Constant for the right row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_RIGHT = DocWriter.GetISOBytes("\\trbrdrr");
|
||||
/**
|
||||
* Constant for the bottom row border
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_BOTTOM = DocWriter.GetISOBytes("\\trbrdrb");
|
||||
/**
|
||||
* Constant for the horizontal line
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_HORIZONTAL = DocWriter.GetISOBytes("\\trbrdrh");
|
||||
/**
|
||||
* Constant for the vertical line
|
||||
*/
|
||||
protected internal static byte[] ROW_BORDER_VERTICAL = DocWriter.GetISOBytes("\\trbrdrv");
|
||||
/**
|
||||
* Constant for the left cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_LEFT = DocWriter.GetISOBytes("\\clbrdrl");
|
||||
/**
|
||||
* Constant for the top cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_TOP = DocWriter.GetISOBytes("\\clbrdrt");
|
||||
/**
|
||||
* Constant for the right cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_RIGHT = DocWriter.GetISOBytes("\\clbrdrr");
|
||||
/**
|
||||
* Constant for the bottom cell border
|
||||
*/
|
||||
protected internal static byte[] CELL_BORDER_BOTTOM = DocWriter.GetISOBytes("\\clbrdrb");
|
||||
/**
|
||||
* Constant for the border width
|
||||
*/
|
||||
protected internal static byte[] BORDER_WIDTH = DocWriter.GetISOBytes("\\brdrw");
|
||||
/**
|
||||
* Constant for the border colour number
|
||||
*/
|
||||
protected internal static byte[] BORDER_COLOR_NUMBER = DocWriter.GetISOBytes("\\brdrcf");
|
||||
/**
|
||||
* Constant for the single border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_SINGLE = DocWriter.GetISOBytes("\\brdrs");
|
||||
/**
|
||||
* Constant for the double thick border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOUBLE_THICK = DocWriter.GetISOBytes("\\brdrth");
|
||||
/**
|
||||
* Constant for the shadowed border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_SHADOWED = DocWriter.GetISOBytes("\\brdrsh");
|
||||
/**
|
||||
* Constant for the dotted border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOTTED = DocWriter.GetISOBytes("\\brdrdot");
|
||||
/**
|
||||
* Constant for the dashed border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DASHED = DocWriter.GetISOBytes("\\brdrdash");
|
||||
/**
|
||||
* Constant for the hairline border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_HAIRLINE = DocWriter.GetISOBytes("\\brdrhair");
|
||||
/**
|
||||
* Constant for the double border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOUBLE = DocWriter.GetISOBytes("\\brdrdb");
|
||||
/**
|
||||
* Constant for the dot dash border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOT_DASH = DocWriter.GetISOBytes("\\brdrdashd");
|
||||
/**
|
||||
* Constant for the dot dot dash border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOT_DOT_DASH = DocWriter.GetISOBytes("\\brdrdashdd");
|
||||
/**
|
||||
* Constant for the triple border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_TRIPLE = DocWriter.GetISOBytes("\\brdrtriple");
|
||||
/**
|
||||
* Constant for the thick thin border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THICK_THIN = DocWriter.GetISOBytes("\\brdrtnthsg");
|
||||
/**
|
||||
* Constant for the thin thick border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK = DocWriter.GetISOBytes("\\brdrthtnsg");
|
||||
/**
|
||||
* Constant for the thin thick thin border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_THIN = DocWriter.GetISOBytes("\\brdrtnthtnsg");
|
||||
/**
|
||||
* Constant for the thick thin medium border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THICK_THIN_MED = DocWriter.GetISOBytes("\\brdrtnthmg");
|
||||
/**
|
||||
* Constant for the thin thick medium border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_MED = DocWriter.GetISOBytes("\\brdrthtnmg");
|
||||
/**
|
||||
* Constant for the thin thick thin medium border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_THIN_MED = DocWriter.GetISOBytes("\\brdrtnthtnmg");
|
||||
/**
|
||||
* Constant for the thick thin large border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THICK_THIN_LARGE = DocWriter.GetISOBytes("\\brdrtnthlg");
|
||||
/**
|
||||
* Constant for the thin thick large border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_LARGE = DocWriter.GetISOBytes("\\brdrthtnlg");
|
||||
/**
|
||||
* Constant for the thin thick thin large border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_THIN_THICK_THIN_LARGE = DocWriter.GetISOBytes("\\brdrtnthtnlg");
|
||||
/**
|
||||
* Constant for the wavy border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_WAVY = DocWriter.GetISOBytes("\\brdrwavy");
|
||||
/**
|
||||
* Constant for the double wavy border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_DOUBLE_WAVY = DocWriter.GetISOBytes("\\brdrwavydb");
|
||||
/**
|
||||
* Constant for the striped border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_STRIPED = DocWriter.GetISOBytes("\\brdrdashdotstr");
|
||||
/**
|
||||
* Constant for the embossed border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_EMBOSS = DocWriter.GetISOBytes("\\brdremboss");
|
||||
/**
|
||||
* Constant for the engraved border style
|
||||
*/
|
||||
protected internal static byte[] BORDER_STYLE_ENGRAVE = DocWriter.GetISOBytes("\\brdrengrave");
|
||||
|
||||
/**
|
||||
* Constant for a row border
|
||||
*/
|
||||
protected internal const int ROW_BORDER = 1;
|
||||
/**
|
||||
* Constant for a cell border
|
||||
*/
|
||||
protected internal const int CELL_BORDER = 2;
|
||||
|
||||
/**
|
||||
* This border is no border :-)
|
||||
*/
|
||||
protected internal const int NO_BORDER = 0;
|
||||
/**
|
||||
* Constant for a left border
|
||||
*/
|
||||
protected internal const int LEFT_BORDER = 1;
|
||||
/**
|
||||
* Constant for a top border
|
||||
*/
|
||||
protected internal const int TOP_BORDER = 2;
|
||||
/**
|
||||
* Constant for a right border
|
||||
*/
|
||||
protected internal const int RIGHT_BORDER = 4;
|
||||
/**
|
||||
* Constant for a bottom border
|
||||
*/
|
||||
protected internal const int BOTTOM_BORDER = 8;
|
||||
/**
|
||||
* Constant for a box (left, top, right, bottom) border
|
||||
*/
|
||||
protected internal const int BOX_BORDER = 15;
|
||||
/**
|
||||
* Constant for a vertical line
|
||||
*/
|
||||
protected internal const int VERTICAL_BORDER = 16;
|
||||
/**
|
||||
* Constant for a horizontal line
|
||||
*/
|
||||
protected internal const int HORIZONTAL_BORDER = 32;
|
||||
|
||||
/**
|
||||
* Constant for a border with no border
|
||||
*/
|
||||
public const int BORDER_NONE = 0;
|
||||
/**
|
||||
* Constant for a single border
|
||||
*/
|
||||
public const int BORDER_SINGLE = 1;
|
||||
/**
|
||||
* Constant for a double thick border
|
||||
*/
|
||||
public const int BORDER_DOUBLE_THICK = 2;
|
||||
/**
|
||||
* Constant for a shadowed border
|
||||
*/
|
||||
public const int BORDER_SHADOWED = 3;
|
||||
/**
|
||||
* Constant for a dotted border
|
||||
*/
|
||||
public const int BORDER_DOTTED = 4;
|
||||
/**
|
||||
* Constant for a dashed border
|
||||
*/
|
||||
public const int BORDER_DASHED = 5;
|
||||
/**
|
||||
* Constant for a hairline border
|
||||
*/
|
||||
public const int BORDER_HAIRLINE = 6;
|
||||
/**
|
||||
* Constant for a double border
|
||||
*/
|
||||
public const int BORDER_DOUBLE = 7;
|
||||
/**
|
||||
* Constant for a dot dash border
|
||||
*/
|
||||
public const int BORDER_DOT_DASH = 8;
|
||||
/**
|
||||
* Constant for a dot dot dash border
|
||||
*/
|
||||
public const int BORDER_DOT_DOT_DASH = 9;
|
||||
/**
|
||||
* Constant for a triple border
|
||||
*/
|
||||
public const int BORDER_TRIPLE = 10;
|
||||
/**
|
||||
* Constant for a thick thin border
|
||||
*/
|
||||
public const int BORDER_THICK_THIN = 11;
|
||||
/**
|
||||
* Constant for a thin thick border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK = 12;
|
||||
/**
|
||||
* Constant for a thin thick thin border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_THIN = 13;
|
||||
/**
|
||||
* Constant for a thick thin medium border
|
||||
*/
|
||||
public const int BORDER_THICK_THIN_MED = 14;
|
||||
/**
|
||||
* Constant for a thin thick medium border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_MED = 15;
|
||||
/**
|
||||
* Constant for a thin thick thin medium border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_THIN_MED = 16;
|
||||
/**
|
||||
* Constant for a thick thin large border
|
||||
*/
|
||||
public const int BORDER_THICK_THIN_LARGE = 17;
|
||||
/**
|
||||
* Constant for a thin thick large border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_LARGE = 18;
|
||||
/**
|
||||
* Constant for a thin thick thin large border
|
||||
*/
|
||||
public const int BORDER_THIN_THICK_THIN_LARGE = 19;
|
||||
/**
|
||||
* Constant for a wavy border
|
||||
*/
|
||||
public const int BORDER_WAVY = 20;
|
||||
/**
|
||||
* Constant for a double wavy border
|
||||
*/
|
||||
public const int BORDER_DOUBLE_WAVY = 21;
|
||||
/**
|
||||
* Constant for a striped border
|
||||
*/
|
||||
public const int BORDER_STRIPED = 22;
|
||||
/**
|
||||
* Constant for an embossed border
|
||||
*/
|
||||
public const int BORDER_EMBOSS = 23;
|
||||
/**
|
||||
* Constant for an engraved border
|
||||
*/
|
||||
public const int BORDER_ENGRAVE = 24;
|
||||
|
||||
/**
|
||||
* The type of this RtfBorder
|
||||
*/
|
||||
private int borderType = ROW_BORDER;
|
||||
/**
|
||||
* The position of this RtfBorder
|
||||
*/
|
||||
private int borderPosition = NO_BORDER;
|
||||
/**
|
||||
* The style of this RtfBorder
|
||||
*/
|
||||
private int borderStyle = BORDER_NONE;
|
||||
/**
|
||||
* The width of this RtfBorder
|
||||
*/
|
||||
private int borderWidth = 20;
|
||||
/**
|
||||
* The colour of this RtfBorder
|
||||
*/
|
||||
private RtfColor borderColor = null;
|
||||
|
||||
/**
|
||||
* Makes a copy of the given RtfBorder
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorder belongs to
|
||||
* @param borderType The border type of this RtfBorder
|
||||
* @param border The RtfBorder to copy
|
||||
*/
|
||||
protected internal RtfBorder(RtfDocument doc, int borderType, RtfBorder border) : base(doc) {
|
||||
this.borderType = borderType;
|
||||
this.borderPosition = border.GetBorderPosition();
|
||||
this.borderStyle = border.GetBorderStyle();
|
||||
this.borderWidth = border.GetBorderWidth();
|
||||
this.borderColor = new RtfColor(this.document, border.GetBorderColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorder
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorder belongs to
|
||||
* @param borderType The type of border this RtfBorder is
|
||||
* @param borderPosition The position of this RtfBorder
|
||||
* @param borderStyle The style of this RtfBorder
|
||||
* @param borderWidth The width of this RtfBorder
|
||||
* @param borderColor The colour of this RtfBorder
|
||||
*/
|
||||
protected internal RtfBorder(RtfDocument doc, int borderType, int borderPosition, int borderStyle, float borderWidth, Color borderColor) : base(doc) {
|
||||
this.borderType = borderType;
|
||||
this.borderPosition = borderPosition;
|
||||
this.borderStyle = borderStyle;
|
||||
this.borderWidth = (int) Math.Min((borderWidth * TWIPS_FACTOR), 75);
|
||||
if (this.borderWidth == 0) {
|
||||
this.borderStyle = BORDER_NONE;
|
||||
}
|
||||
if (borderColor == null) {
|
||||
this.borderColor = new RtfColor(this.document, new Color(0, 0, 0));
|
||||
} else {
|
||||
this.borderColor = new RtfColor(this.document, borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the RtfBorder settings
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
if (this.borderStyle == BORDER_NONE || this.borderPosition == NO_BORDER || this.borderWidth == 0) {
|
||||
return;
|
||||
}
|
||||
byte[] t;
|
||||
if (this.borderType == ROW_BORDER) {
|
||||
switch (this.borderPosition) {
|
||||
case LEFT_BORDER:
|
||||
result.Write(ROW_BORDER_LEFT, 0, ROW_BORDER_LEFT.Length);
|
||||
break;
|
||||
case TOP_BORDER:
|
||||
result.Write(ROW_BORDER_TOP, 0, ROW_BORDER_TOP.Length);
|
||||
break;
|
||||
case RIGHT_BORDER:
|
||||
result.Write(ROW_BORDER_RIGHT, 0, ROW_BORDER_RIGHT.Length);
|
||||
break;
|
||||
case BOTTOM_BORDER:
|
||||
result.Write(ROW_BORDER_BOTTOM, 0, ROW_BORDER_BOTTOM.Length);
|
||||
break;
|
||||
case HORIZONTAL_BORDER:
|
||||
result.Write(ROW_BORDER_HORIZONTAL, 0, ROW_BORDER_HORIZONTAL.Length);
|
||||
break;
|
||||
case VERTICAL_BORDER:
|
||||
result.Write(ROW_BORDER_VERTICAL, 0, ROW_BORDER_VERTICAL.Length);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
result.Write(t = WriteBorderStyle(), 0, t.Length);
|
||||
result.Write(BORDER_WIDTH, 0, BORDER_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(this.borderWidth), 0, t.Length);
|
||||
result.Write(BORDER_COLOR_NUMBER, 0, BORDER_COLOR_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(this.borderColor.GetColorNumber()), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
} else if (this.borderType == CELL_BORDER) {
|
||||
switch (this.borderPosition) {
|
||||
case LEFT_BORDER:
|
||||
result.Write(CELL_BORDER_LEFT, 0, CELL_BORDER_LEFT.Length);
|
||||
break;
|
||||
case TOP_BORDER:
|
||||
result.Write(CELL_BORDER_TOP, 0, CELL_BORDER_TOP.Length);
|
||||
break;
|
||||
case RIGHT_BORDER:
|
||||
result.Write(CELL_BORDER_RIGHT, 0, CELL_BORDER_RIGHT.Length);
|
||||
break;
|
||||
case BOTTOM_BORDER:
|
||||
result.Write(CELL_BORDER_BOTTOM, 0, CELL_BORDER_BOTTOM.Length);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
result.Write(t = WriteBorderStyle(), 0, t.Length);
|
||||
result.Write(BORDER_WIDTH, 0, BORDER_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(this.borderWidth), 0, t.Length);
|
||||
result.Write(BORDER_COLOR_NUMBER, 0, BORDER_COLOR_NUMBER.Length);
|
||||
result.Write(t = IntToByteArray(this.borderColor.GetColorNumber()), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the style of this RtfBorder
|
||||
*
|
||||
* @return A byte array containing the style of this RtfBorder
|
||||
*/
|
||||
private byte[] WriteBorderStyle() {
|
||||
switch (this.borderStyle) {
|
||||
case BORDER_NONE : return new byte[0];
|
||||
case BORDER_SINGLE : return BORDER_STYLE_SINGLE;
|
||||
case BORDER_DOUBLE_THICK : return BORDER_STYLE_DOUBLE_THICK;
|
||||
case BORDER_SHADOWED : return BORDER_STYLE_SHADOWED;
|
||||
case BORDER_DOTTED : return BORDER_STYLE_DOTTED;
|
||||
case BORDER_DASHED : return BORDER_STYLE_DASHED;
|
||||
case BORDER_HAIRLINE : return BORDER_STYLE_HAIRLINE;
|
||||
case BORDER_DOUBLE : return BORDER_STYLE_DOUBLE;
|
||||
case BORDER_DOT_DASH : return BORDER_STYLE_DOT_DASH;
|
||||
case BORDER_DOT_DOT_DASH : return BORDER_STYLE_DOT_DOT_DASH;
|
||||
case BORDER_TRIPLE : return BORDER_STYLE_TRIPLE;
|
||||
case BORDER_THICK_THIN : return BORDER_STYLE_THICK_THIN;
|
||||
case BORDER_THIN_THICK : return BORDER_STYLE_THIN_THICK;
|
||||
case BORDER_THIN_THICK_THIN : return BORDER_STYLE_THIN_THICK_THIN;
|
||||
case BORDER_THICK_THIN_MED : return BORDER_STYLE_THICK_THIN_MED;
|
||||
case BORDER_THIN_THICK_MED : return BORDER_STYLE_THIN_THICK_MED;
|
||||
case BORDER_THIN_THICK_THIN_MED : return BORDER_STYLE_THIN_THICK_THIN_MED;
|
||||
case BORDER_THICK_THIN_LARGE : return BORDER_STYLE_THICK_THIN_LARGE;
|
||||
case BORDER_THIN_THICK_LARGE : return BORDER_STYLE_THIN_THICK_LARGE;
|
||||
case BORDER_THIN_THICK_THIN_LARGE : return BORDER_STYLE_THIN_THICK_THIN_LARGE;
|
||||
case BORDER_WAVY : return BORDER_STYLE_WAVY;
|
||||
case BORDER_DOUBLE_WAVY : return BORDER_STYLE_DOUBLE_WAVY;
|
||||
case BORDER_STRIPED : return BORDER_STYLE_STRIPED;
|
||||
case BORDER_EMBOSS : return BORDER_STYLE_EMBOSS;
|
||||
case BORDER_ENGRAVE : return BORDER_STYLE_ENGRAVE;
|
||||
default : return BORDER_STYLE_SINGLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the colour of this RtfBorder
|
||||
*
|
||||
* @return Returns RtfColor of this RtfBorder
|
||||
*/
|
||||
protected RtfColor GetBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of this RtfBorder
|
||||
* @return Returns the position of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderPosition() {
|
||||
return borderPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the style of this RtfBorder
|
||||
*
|
||||
* @return Returns the style of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderStyle() {
|
||||
return borderStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of this RtfBorder
|
||||
*
|
||||
* @return Returns the type of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderType() {
|
||||
return borderType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of this RtfBorder
|
||||
*
|
||||
* @return Returns the width of this RtfBorder
|
||||
*/
|
||||
protected int GetBorderWidth() {
|
||||
return borderWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
213
iTechSharp/iTextSharp/text/rtf/table/RtfBorderGroup.cs
Normal file
213
iTechSharp/iTextSharp/text/rtf/table/RtfBorderGroup.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfBorderGroup.cs,v 1.5 2008/05/16 19:31:18 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfBorderGroup represents a collection of RtfBorders to use in a RtfCell
|
||||
* or RtfTable.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfBorderGroup : RtfElement {
|
||||
/**
|
||||
* The type of borders this RtfBorderGroup contains.
|
||||
* RtfBorder.ROW_BORDER or RtfBorder.CELL_BORDER
|
||||
*/
|
||||
private int borderType = RtfBorder.ROW_BORDER;
|
||||
/**
|
||||
* The borders in this RtfBorderGroup
|
||||
*/
|
||||
private Hashtable borders = null;
|
||||
|
||||
/**
|
||||
* Constructs an empty RtfBorderGroup.
|
||||
*/
|
||||
public RtfBorderGroup() : base(null) {
|
||||
this.borders = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorderGroup with on border style for multiple borders.
|
||||
*
|
||||
* @param bordersToAdd The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX)
|
||||
* @param borderStyle The style of border to add (from RtfBorder)
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
public RtfBorderGroup(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) : base(null) {
|
||||
this.borders = new Hashtable();
|
||||
AddBorder(bordersToAdd, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorderGroup based on another RtfBorderGroup.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorderGroup belongs to
|
||||
* @param borderType The type of borders this RtfBorderGroup contains
|
||||
* @param borderGroup The RtfBorderGroup to use as a base
|
||||
*/
|
||||
protected internal RtfBorderGroup(RtfDocument doc, int borderType, RtfBorderGroup borderGroup) : base(doc) {
|
||||
this.borders = new Hashtable();
|
||||
this.borderType = borderType;
|
||||
if (borderGroup != null) {
|
||||
foreach (DictionaryEntry entry in borderGroup.GetBorders()) {
|
||||
int borderPos = (int)entry.Key;
|
||||
RtfBorder border = (RtfBorder)entry.Value;
|
||||
this.borders[borderPos] = new RtfBorder(this.document, this.borderType, border);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfBorderGroup with certain borders
|
||||
*
|
||||
* @param doc The RtfDocument this RtfBorderGroup belongs to
|
||||
* @param borderType The type of borders this RtfBorderGroup contains
|
||||
* @param bordersToUse The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX)
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
protected internal RtfBorderGroup(RtfDocument doc, int borderType, int bordersToUse, float borderWidth, Color borderColor) : base(doc) {
|
||||
this.borderType = borderType;
|
||||
this.borders = new Hashtable();
|
||||
AddBorder(bordersToUse, RtfBorder.BORDER_SINGLE, borderWidth, borderColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a border in the Hashtable of borders
|
||||
*
|
||||
* @param borderPosition The position of this RtfBorder
|
||||
* @param borderStyle The type of borders this RtfBorderGroup contains
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
private void SetBorder(int borderPosition, int borderStyle, float borderWidth, Color borderColor) {
|
||||
RtfBorder border = new RtfBorder(this.document, this.borderType, borderPosition, borderStyle, borderWidth, borderColor);
|
||||
this.borders[borderPosition] = border;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds borders to the RtfBorderGroup
|
||||
*
|
||||
* @param bordersToAdd The borders to add (Rectangle.LEFT, Rectangle.RIGHT, Rectangle.TOP, Rectangle.BOTTOM, Rectangle.BOX)
|
||||
* @param borderStyle The style of border to add (from RtfBorder)
|
||||
* @param borderWidth The border width to use
|
||||
* @param borderColor The border color to use
|
||||
*/
|
||||
public void AddBorder(int bordersToAdd, int borderStyle, float borderWidth, Color borderColor) {
|
||||
if ((bordersToAdd & Rectangle.LEFT_BORDER) == Rectangle.LEFT_BORDER) {
|
||||
SetBorder(RtfBorder.LEFT_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.TOP_BORDER) == Rectangle.TOP_BORDER) {
|
||||
SetBorder(RtfBorder.TOP_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.RIGHT_BORDER) == Rectangle.RIGHT_BORDER) {
|
||||
SetBorder(RtfBorder.RIGHT_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.BOTTOM_BORDER) == Rectangle.BOTTOM_BORDER) {
|
||||
SetBorder(RtfBorder.BOTTOM_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
if ((bordersToAdd & Rectangle.BOX) == Rectangle.BOX && this.borderType == RtfBorder.ROW_BORDER) {
|
||||
SetBorder(RtfBorder.VERTICAL_BORDER, borderStyle, borderWidth, borderColor);
|
||||
SetBorder(RtfBorder.HORIZONTAL_BORDER, borderStyle, borderWidth, borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes borders from the list of borders
|
||||
*
|
||||
* @param bordersToRemove The borders to remove (from Rectangle)
|
||||
*/
|
||||
public void RemoveBorder(int bordersToRemove) {
|
||||
if ((bordersToRemove & Rectangle.LEFT_BORDER) == Rectangle.LEFT_BORDER) {
|
||||
this.borders.Remove(RtfBorder.LEFT_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.TOP_BORDER) == Rectangle.TOP_BORDER) {
|
||||
this.borders.Remove(RtfBorder.TOP_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.RIGHT_BORDER) == Rectangle.RIGHT_BORDER) {
|
||||
this.borders.Remove(RtfBorder.RIGHT_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.BOTTOM_BORDER) == Rectangle.BOTTOM_BORDER) {
|
||||
this.borders.Remove(RtfBorder.BOTTOM_BORDER);
|
||||
}
|
||||
if ((bordersToRemove & Rectangle.BOX) == Rectangle.BOX && this.borderType == RtfBorder.ROW_BORDER) {
|
||||
this.borders.Remove(RtfBorder.VERTICAL_BORDER);
|
||||
this.borders.Remove(RtfBorder.HORIZONTAL_BORDER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the borders of this RtfBorderGroup
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
foreach (RtfBorder rb in this.borders.Values) {
|
||||
rb.WriteContent(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RtfBorders of this RtfBorderGroup
|
||||
*
|
||||
* @return The RtfBorders of this RtfBorderGroup
|
||||
*/
|
||||
protected internal Hashtable GetBorders() {
|
||||
return this.borders;
|
||||
}
|
||||
}
|
||||
}
|
||||
493
iTechSharp/iTextSharp/text/rtf/table/RtfCell.cs
Normal file
493
iTechSharp/iTextSharp/text/rtf/table/RtfCell.cs
Normal file
@@ -0,0 +1,493 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.util;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using iTextSharp.text.rtf.text;
|
||||
/*
|
||||
* $Id: RtfCell.cs,v 1.14 2008/05/16 19:31:18 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfCell wraps a Cell, but can also be added directly to a Table.
|
||||
* The RtfCell is an extension of Cell, that supports a multitude of different
|
||||
* borderstyles.
|
||||
*
|
||||
* @version $Id: RtfCell.cs,v 1.14 2008/05/16 19:31:18 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Steffen Stundzig
|
||||
* @author Benoit WIART <b.wiart@proxiad.com>
|
||||
* @see com.lowagie.text.rtf.table.RtfBorder
|
||||
*/
|
||||
public class RtfCell : Cell, IRtfExtendedElement {
|
||||
|
||||
/**
|
||||
* This cell is not merged
|
||||
*/
|
||||
private const int MERGE_NONE = 0;
|
||||
/**
|
||||
* This cell is the parent cell of a vertical merge operation
|
||||
*/
|
||||
private const int MERGE_VERT_PARENT = 1;
|
||||
/**
|
||||
* This cell is a child cell of a vertical merge operation
|
||||
*/
|
||||
private const int MERGE_VERT_CHILD = 2;
|
||||
|
||||
/**
|
||||
* The parent RtfRow of this RtfCell
|
||||
*/
|
||||
private RtfRow parentRow = null;
|
||||
/**
|
||||
* The content of this RtfCell
|
||||
*/
|
||||
private ArrayList content = null;
|
||||
/**
|
||||
* The right margin of this RtfCell
|
||||
*/
|
||||
private int cellRight = 0;
|
||||
/**
|
||||
* The width of this RtfCell
|
||||
*/
|
||||
private int cellWidth = 0;
|
||||
/**
|
||||
* The borders of this RtfCell
|
||||
*/
|
||||
private RtfBorderGroup borders = null;
|
||||
/**
|
||||
* The background color of this RtfCell
|
||||
*/
|
||||
private new RtfColor backgroundColor = null;
|
||||
/**
|
||||
* The padding of this RtfCell
|
||||
*/
|
||||
private int cellPadding = 0;
|
||||
/**
|
||||
* The merge type of this RtfCell
|
||||
*/
|
||||
private int mergeType = MERGE_NONE;
|
||||
/**
|
||||
* The RtfDocument this RtfCell belongs to
|
||||
*/
|
||||
private RtfDocument document = null;
|
||||
/**
|
||||
* Whether this RtfCell is in a header
|
||||
*/
|
||||
private bool inHeader = false;
|
||||
/**
|
||||
* Whether this RtfCell is a placeholder for a removed table cell.
|
||||
*/
|
||||
private bool deleted = false;
|
||||
|
||||
/**
|
||||
* Constructs an empty RtfCell
|
||||
*/
|
||||
public RtfCell() : base() {
|
||||
this.borders = new RtfBorderGroup();
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfCell based upon a String
|
||||
*
|
||||
* @param content The String to base the RtfCell on
|
||||
*/
|
||||
public RtfCell(String content) : base(content) {
|
||||
this.borders = new RtfBorderGroup();
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfCell based upon an Element
|
||||
*
|
||||
* @param element The Element to base the RtfCell on
|
||||
* @throws BadElementException If the Element is not valid
|
||||
*/
|
||||
public RtfCell(IElement element) : base(element) {
|
||||
this.borders = new RtfBorderGroup();
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a deleted RtfCell.
|
||||
*
|
||||
* @param deleted Whether this RtfCell is actually deleted.
|
||||
*/
|
||||
protected internal RtfCell(bool deleted) : base() {
|
||||
this.deleted = deleted;
|
||||
verticalAlignment = Element.ALIGN_MIDDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfCell based on a Cell.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfCell belongs to
|
||||
* @param row The RtfRow this RtfCell lies in
|
||||
* @param cell The Cell to base this RtfCell on
|
||||
*/
|
||||
protected internal RtfCell(RtfDocument doc, RtfRow row, Cell cell) {
|
||||
this.document = doc;
|
||||
this.parentRow = row;
|
||||
ImportCell(cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports the Cell properties into the RtfCell
|
||||
*
|
||||
* @param cell The Cell to import
|
||||
*/
|
||||
private void ImportCell(Cell cell) {
|
||||
this.content = new ArrayList();
|
||||
|
||||
if (cell == null) {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders());
|
||||
return;
|
||||
}
|
||||
|
||||
this.colspan = cell.Colspan;
|
||||
this.rowspan = cell.Rowspan;
|
||||
if (cell.Rowspan > 1) {
|
||||
this.mergeType = MERGE_VERT_PARENT;
|
||||
}
|
||||
if (cell is RtfCell) {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, ((RtfCell) cell).GetBorders());
|
||||
} else {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor);
|
||||
}
|
||||
this.verticalAlignment = cell.VerticalAlignment;
|
||||
if (cell.BackgroundColor == null) {
|
||||
this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
|
||||
} else {
|
||||
this.backgroundColor = new RtfColor(this.document, cell.BackgroundColor);
|
||||
}
|
||||
|
||||
this.cellPadding = (int) this.parentRow.GetParentTable().GetCellPadding();
|
||||
|
||||
Paragraph container = null;
|
||||
foreach (IElement element in cell.Elements) {
|
||||
try {
|
||||
// should we wrap it in a paragraph
|
||||
if (!(element is Paragraph) && !(element is List)) {
|
||||
if (container != null) {
|
||||
container.Add(element);
|
||||
} else {
|
||||
container = new Paragraph();
|
||||
container.Alignment = cell.HorizontalAlignment;
|
||||
container.Add(element);
|
||||
}
|
||||
} else {
|
||||
if (container != null) {
|
||||
IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container);
|
||||
for(int i = 0; i < rtfElements.Length; i++) {
|
||||
rtfElements[i].SetInTable(true);
|
||||
this.content.Add(rtfElements[i]);
|
||||
}
|
||||
container = null;
|
||||
}
|
||||
// if horizontal alignment is undefined overwrite
|
||||
// with that of enclosing cell
|
||||
if (element is Paragraph && ((Paragraph) element).Alignment == Element.ALIGN_UNDEFINED) {
|
||||
((Paragraph) element).Alignment = cell.HorizontalAlignment;
|
||||
}
|
||||
|
||||
IRtfBasicElement[] rtfElements2 = this.document.GetMapper().MapElement(element);
|
||||
for(int i = 0; i < rtfElements2.Length; i++) {
|
||||
rtfElements2[i].SetInTable(true);
|
||||
this.content.Add(rtfElements2[i]);
|
||||
}
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
if (container != null) {
|
||||
try {
|
||||
IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container);
|
||||
for(int i = 0; i < rtfElements.Length; i++) {
|
||||
rtfElements[i].SetInTable(true);
|
||||
this.content.Add(rtfElements[i]);
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the cell definition part of this RtfCell
|
||||
*
|
||||
* @return A byte array with the cell definition
|
||||
*/
|
||||
public virtual void WriteDefinition(Stream result) {
|
||||
byte[] t;
|
||||
if (this.mergeType == MERGE_VERT_PARENT) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvmgf"), 0, t.Length);
|
||||
} else if (this.mergeType == MERGE_VERT_CHILD) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvmrg"), 0, t.Length);
|
||||
}
|
||||
switch (verticalAlignment) {
|
||||
case Element.ALIGN_BOTTOM:
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvertalb"), 0, t.Length);
|
||||
break;
|
||||
case Element.ALIGN_CENTER:
|
||||
case Element.ALIGN_MIDDLE:
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvertalc"), 0, t.Length);
|
||||
break;
|
||||
case Element.ALIGN_TOP:
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clvertalt"), 0, t.Length);
|
||||
break;
|
||||
}
|
||||
this.borders.WriteContent(result);
|
||||
|
||||
if (this.backgroundColor != null) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clcbpat"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.backgroundColor.GetColorNumber()), 0, t.Length);
|
||||
}
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clftsWidth3"), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clwWidth"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellWidth), 0, t.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
if (this.cellPadding > 0) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadl"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadt"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadr"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadb"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadfl3"), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadft3"), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadfr3"), 0, t.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes("\\clpadfb3"), 0, t.Length);
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\cellx"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.cellRight), 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of this RtfCell
|
||||
*/
|
||||
public virtual void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
if (this.content.Count == 0) {
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
if (this.parentRow.GetParentTable().GetTableFitToPage()) {
|
||||
result.Write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT, 0, RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT.Length);
|
||||
}
|
||||
result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
|
||||
} else {
|
||||
for (int i = 0; i < this.content.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) this.content[i];
|
||||
if (rtfElement is RtfParagraph) {
|
||||
((RtfParagraph) rtfElement).SetKeepTogetherWithNext(this.parentRow.GetParentTable().GetTableFitToPage());
|
||||
}
|
||||
rtfElement.WriteContent(result);
|
||||
if (rtfElement is RtfParagraph && i < (this.content.Count - 1)) {
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\cell"), 0, t.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right margin of this cell. Used in merge operations
|
||||
*
|
||||
* @param cellRight The right margin to use
|
||||
*/
|
||||
protected internal void SetCellRight(int cellRight) {
|
||||
this.cellRight = cellRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the right margin of this RtfCell
|
||||
*
|
||||
* @return The right margin of this RtfCell.
|
||||
*/
|
||||
protected internal int GetCellRight() {
|
||||
return this.cellRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cell width of this RtfCell. Used in merge operations.
|
||||
*
|
||||
* @param cellWidth The cell width to use
|
||||
*/
|
||||
protected internal void SetCellWidth(int cellWidth) {
|
||||
this.cellWidth = cellWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell width of this RtfCell
|
||||
*
|
||||
* @return The cell width of this RtfCell
|
||||
*/
|
||||
protected internal int GetCellWidth() {
|
||||
return this.cellWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell padding of this RtfCell
|
||||
*
|
||||
* @return The cell padding of this RtfCell
|
||||
*/
|
||||
protected internal int GetCellpadding() {
|
||||
return this.cellPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the borders of this RtfCell
|
||||
*
|
||||
* @return The borders of this RtfCell
|
||||
*/
|
||||
protected internal RtfBorderGroup GetBorders() {
|
||||
return this.borders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the borders of this RtfCell
|
||||
*
|
||||
* @param borderGroup The RtfBorderGroup to use as borders
|
||||
*/
|
||||
public void SetBorders(RtfBorderGroup borderGroup) {
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, borderGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color of this RtfCell
|
||||
*
|
||||
* @return The background color of this RtfCell
|
||||
*/
|
||||
protected internal RtfColor GetRtfBackgroundColor() {
|
||||
return this.backgroundColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge this cell into the parent cell.
|
||||
*
|
||||
* @param mergeParent The RtfCell to merge with
|
||||
*/
|
||||
protected internal void SetCellMergeChild(RtfCell mergeParent) {
|
||||
this.mergeType = MERGE_VERT_CHILD;
|
||||
this.cellWidth = mergeParent.GetCellWidth();
|
||||
this.cellRight = mergeParent.GetCellRight();
|
||||
this.cellPadding = mergeParent.GetCellpadding();
|
||||
this.borders = mergeParent.GetBorders();
|
||||
this.verticalAlignment = mergeParent.VerticalAlignment;
|
||||
this.backgroundColor = mergeParent.GetRtfBackgroundColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfCell belongs to
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public void SetRtfDocument(RtfDocument doc) {
|
||||
this.document = doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused
|
||||
* @param inTable
|
||||
*/
|
||||
public void SetInTable(bool inTable) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfCell is in a header
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfCell is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public void SetInHeader(bool inHeader) {
|
||||
this.inHeader = inHeader;
|
||||
for (int i = 0; i < this.content.Count; i++) {
|
||||
((IRtfBasicElement) this.content[i]).SetInHeader(inHeader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this <code>RtfCell</code> is in a header
|
||||
*
|
||||
* @return <code>True</code> if this <code>RtfCell</code> is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public bool IsInHeader() {
|
||||
return this.inHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an integer into its String representation and then returns the bytes
|
||||
* of that string.
|
||||
*
|
||||
* @param i The integer to convert
|
||||
* @return A byte array representing the integer
|
||||
*/
|
||||
private byte[] IntToByteArray(int i) {
|
||||
return DocWriter.GetISOBytes(i.ToString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this RtfCell is a placeholder for
|
||||
* a table cell that has been removed due to col/row spanning.
|
||||
*
|
||||
* @return <code>True</code> if this RtfCell is deleted, <code>false</code> otherwise.
|
||||
*/
|
||||
public bool IsDeleted() {
|
||||
return this.deleted;
|
||||
}
|
||||
}
|
||||
}
|
||||
377
iTechSharp/iTextSharp/text/rtf/table/RtfRow.cs
Normal file
377
iTechSharp/iTextSharp/text/rtf/table/RtfRow.cs
Normal file
@@ -0,0 +1,377 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfRow.cs,v 1.10 2008/05/16 19:31:19 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004, 2005 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfRow wraps one Row for a RtfTable.
|
||||
* INTERNAL USE ONLY
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Steffen Stundzig
|
||||
* @author Lorenz Maierhofer <larry@sbox.tugraz.at>
|
||||
*/
|
||||
public class RtfRow : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the RtfRow beginning
|
||||
*/
|
||||
private static byte[] ROW_BEGIN = DocWriter.GetISOBytes("\\trowd");
|
||||
/**
|
||||
* Constant for the RtfRow width style
|
||||
*/
|
||||
private static byte[] ROW_WIDTH_STYLE = DocWriter.GetISOBytes("\\trftsWidth3");
|
||||
/**
|
||||
* Constant for the RtfRow width
|
||||
*/
|
||||
private static byte[] ROW_WIDTH = DocWriter.GetISOBytes("\\trwWidth");
|
||||
/**
|
||||
* Constant to specify that this RtfRow are not to be broken across pages
|
||||
*/
|
||||
private static byte[] ROW_KEEP_TOGETHER = DocWriter.GetISOBytes("\\trkeep");
|
||||
/**
|
||||
* Constant to specify that this is a header RtfRow
|
||||
*/
|
||||
private static byte[] ROW_HEADER_ROW = DocWriter.GetISOBytes("\\trhdr");
|
||||
/**
|
||||
* Constant for left alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_LEFT = DocWriter.GetISOBytes("\\trql");
|
||||
/**
|
||||
* Constant for right alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_RIGHT = DocWriter.GetISOBytes("\\trqr");
|
||||
/**
|
||||
* Constant for center alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_CENTER = DocWriter.GetISOBytes("\\trqc");
|
||||
/**
|
||||
* Constant for justified alignment of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_ALIGN_JUSTIFIED = DocWriter.GetISOBytes("\\trqj");
|
||||
/**
|
||||
* Constant for the graph style of this RtfRow
|
||||
*/
|
||||
private static byte[] ROW_GRAPH = DocWriter.GetISOBytes("\\trgaph10");
|
||||
/**
|
||||
* Constant for the cell left spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_LEFT = DocWriter.GetISOBytes("\\trspdl");
|
||||
/**
|
||||
* Constant for the cell top spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_TOP = DocWriter.GetISOBytes("\\trspdt");
|
||||
/**
|
||||
* Constant for the cell right spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_RIGHT = DocWriter.GetISOBytes("\\trspdr");
|
||||
/**
|
||||
* Constant for the cell bottom spacing
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_BOTTOM = DocWriter.GetISOBytes("\\trspdb");
|
||||
/**
|
||||
* Constant for the cell left spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_LEFT_STYLE = DocWriter.GetISOBytes("\\trspdfl3");
|
||||
/**
|
||||
* Constant for the cell top spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_TOP_STYLE = DocWriter.GetISOBytes("\\trspdft3");
|
||||
/**
|
||||
* Constant for the cell right spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_RIGHT_STYLE = DocWriter.GetISOBytes("\\trspdfr3");
|
||||
/**
|
||||
* Constant for the cell bottom spacing style
|
||||
*/
|
||||
private static byte[] ROW_CELL_SPACING_BOTTOM_STYLE = DocWriter.GetISOBytes("\\trspdfb3");
|
||||
/**
|
||||
* Constant for the cell left padding
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_LEFT = DocWriter.GetISOBytes("\\trpaddl");
|
||||
/**
|
||||
* Constant for the cell right padding
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_RIGHT = DocWriter.GetISOBytes("\\trpaddr");
|
||||
/**
|
||||
* Constant for the cell left padding style
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_LEFT_STYLE = DocWriter.GetISOBytes("\\trpaddfl3");
|
||||
/**
|
||||
* Constant for the cell right padding style
|
||||
*/
|
||||
private static byte[] ROW_CELL_PADDING_RIGHT_STYLE = DocWriter.GetISOBytes("\\trpaddfr3");
|
||||
/**
|
||||
* Constant for the end of a row
|
||||
*/
|
||||
private static byte[] ROW_END = DocWriter.GetISOBytes("\\row");
|
||||
|
||||
/**
|
||||
* The RtfTable this RtfRow belongs to
|
||||
*/
|
||||
private RtfTable parentTable = null;
|
||||
/**
|
||||
* The cells of this RtfRow
|
||||
*/
|
||||
private ArrayList cells = null;
|
||||
/**
|
||||
* The width of this row
|
||||
*/
|
||||
private int width = 0;
|
||||
/**
|
||||
* The row number
|
||||
*/
|
||||
private int rowNumber = 0;
|
||||
|
||||
/**
|
||||
* Constructs a RtfRow for a Row.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfRow belongs to
|
||||
* @param rtfTable The RtfTable this RtfRow belongs to
|
||||
* @param row The Row this RtfRow is based on
|
||||
* @param rowNumber The number of this row
|
||||
*/
|
||||
protected internal RtfRow(RtfDocument doc, RtfTable rtfTable, Row row, int rowNumber) : base(doc) {
|
||||
this.parentTable = rtfTable;
|
||||
this.rowNumber = rowNumber;
|
||||
ImportRow(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a Row and copies all settings
|
||||
*
|
||||
* @param row The Row to import
|
||||
*/
|
||||
private void ImportRow(Row row) {
|
||||
this.cells = new ArrayList();
|
||||
this.width = this.document.GetDocumentHeader().GetPageSetting().GetPageWidth() - this.document.GetDocumentHeader().GetPageSetting().GetMarginLeft() - this.document.GetDocumentHeader().GetPageSetting().GetMarginRight();
|
||||
this.width = (int) (this.width * this.parentTable.GetTableWidthPercent() / 100);
|
||||
|
||||
int cellRight = 0;
|
||||
int cellWidth = 0;
|
||||
for (int i = 0; i < row.Columns; i++) {
|
||||
cellWidth = (int) (this.width * this.parentTable.GetProportionalWidths()[i] / 100);
|
||||
cellRight = cellRight + cellWidth;
|
||||
|
||||
Cell cell = (Cell) row.GetCell(i);
|
||||
RtfCell rtfCell = new RtfCell(this.document, this, cell);
|
||||
rtfCell.SetCellRight(cellRight);
|
||||
rtfCell.SetCellWidth(cellWidth);
|
||||
this.cells.Add(rtfCell);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a second pass over all cells to handle cell row/column spanning.
|
||||
*/
|
||||
protected internal void HandleCellSpanning() {
|
||||
RtfCell deletedCell = new RtfCell(true);
|
||||
for (int i = 0; i < this.cells.Count; i++) {
|
||||
RtfCell rtfCell = (RtfCell) this.cells[i];
|
||||
if (rtfCell.Colspan > 1) {
|
||||
int cSpan = rtfCell.Colspan;
|
||||
for (int j = i + 1; j < i + cSpan; j++) {
|
||||
if (j < this.cells.Count) {
|
||||
RtfCell rtfCellMerge = (RtfCell) this.cells[j];
|
||||
rtfCell.SetCellRight(rtfCell.GetCellRight() + rtfCellMerge.GetCellWidth());
|
||||
rtfCell.SetCellWidth(rtfCell.GetCellWidth() + rtfCellMerge.GetCellWidth());
|
||||
this.cells[j] = deletedCell;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rtfCell.Rowspan > 1) {
|
||||
ArrayList rows = this.parentTable.GetRows();
|
||||
for (int j = 1; j < rtfCell.Rowspan; j++) {
|
||||
RtfRow mergeRow = (RtfRow) rows[this.rowNumber + j];
|
||||
if (this.rowNumber + j < rows.Count) {
|
||||
RtfCell rtfCellMerge = (RtfCell) mergeRow.GetCells()[i];
|
||||
rtfCellMerge.SetCellMergeChild(rtfCell);
|
||||
}
|
||||
if (rtfCell.Colspan > 1) {
|
||||
int cSpan = rtfCell.Colspan;
|
||||
for (int k = i + 1; k < i + cSpan; k++) {
|
||||
if (k < mergeRow.GetCells().Count) {
|
||||
mergeRow.GetCells()[k] = deletedCell;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the deleted RtfCells from the total RtfCells.
|
||||
*/
|
||||
protected internal void CleanRow() {
|
||||
int i = 0;
|
||||
while (i < this.cells.Count) {
|
||||
if (((RtfCell) this.cells[i]).IsDeleted()) {
|
||||
this.cells.RemoveAt(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the row definition/settings.
|
||||
*
|
||||
* @param result The <code>OutputStream</code> to write the definitions to.
|
||||
*/
|
||||
private void WriteRowDefinition(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(ROW_BEGIN, 0, ROW_BEGIN.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
result.Write(ROW_WIDTH_STYLE, 0, ROW_WIDTH_STYLE.Length);
|
||||
result.Write(ROW_WIDTH, 0, ROW_WIDTH.Length);
|
||||
result.Write(t = IntToByteArray(this.width), 0, t.Length);
|
||||
if (this.parentTable.GetCellsFitToPage()) {
|
||||
result.Write(ROW_KEEP_TOGETHER, 0, ROW_KEEP_TOGETHER.Length);
|
||||
}
|
||||
if (this.rowNumber <= this.parentTable.GetHeaderRows()) {
|
||||
result.Write(ROW_HEADER_ROW, 0, ROW_HEADER_ROW.Length);
|
||||
}
|
||||
switch (this.parentTable.GetAlignment()) {
|
||||
case Element.ALIGN_LEFT:
|
||||
result.Write(ROW_ALIGN_LEFT, 0, ROW_ALIGN_LEFT.Length);
|
||||
break;
|
||||
case Element.ALIGN_RIGHT:
|
||||
result.Write(ROW_ALIGN_RIGHT, 0, ROW_ALIGN_RIGHT.Length);
|
||||
break;
|
||||
case Element.ALIGN_CENTER:
|
||||
result.Write(ROW_ALIGN_CENTER, 0, ROW_ALIGN_CENTER.Length);
|
||||
break;
|
||||
case Element.ALIGN_JUSTIFIED:
|
||||
case Element.ALIGN_JUSTIFIED_ALL:
|
||||
result.Write(ROW_ALIGN_JUSTIFIED, 0, ROW_ALIGN_JUSTIFIED.Length);
|
||||
break;
|
||||
}
|
||||
result.Write(ROW_GRAPH, 0, ROW_GRAPH.Length);
|
||||
|
||||
this.parentTable.GetBorders().WriteContent(result);
|
||||
|
||||
if (this.parentTable.GetCellSpacing() > 0) {
|
||||
result.Write(ROW_CELL_SPACING_LEFT, 0, ROW_CELL_SPACING_LEFT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_LEFT_STYLE, 0, ROW_CELL_SPACING_LEFT_STYLE.Length);
|
||||
result.Write(ROW_CELL_SPACING_TOP, 0, ROW_CELL_SPACING_TOP.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_TOP_STYLE, 0, ROW_CELL_SPACING_TOP_STYLE.Length);
|
||||
result.Write(ROW_CELL_SPACING_RIGHT, 0, ROW_CELL_SPACING_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_RIGHT_STYLE, 0, ROW_CELL_SPACING_RIGHT_STYLE.Length);
|
||||
result.Write(ROW_CELL_SPACING_BOTTOM, 0, ROW_CELL_SPACING_BOTTOM.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellSpacing() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_SPACING_BOTTOM_STYLE, 0, ROW_CELL_SPACING_BOTTOM_STYLE.Length);
|
||||
}
|
||||
|
||||
result.Write(ROW_CELL_PADDING_LEFT, 0, ROW_CELL_PADDING_LEFT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellPadding() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_PADDING_RIGHT, 0, ROW_CELL_PADDING_RIGHT.Length);
|
||||
result.Write(t = IntToByteArray((int) (this.parentTable.GetCellPadding() / 2)), 0, t.Length);
|
||||
result.Write(ROW_CELL_PADDING_LEFT_STYLE, 0, ROW_CELL_PADDING_LEFT_STYLE.Length);
|
||||
result.Write(ROW_CELL_PADDING_RIGHT_STYLE, 0, ROW_CELL_PADDING_RIGHT_STYLE.Length);
|
||||
|
||||
result.WriteByte((byte)'\n');
|
||||
|
||||
for (int i = 0; i < this.cells.Count; i++) {
|
||||
RtfCell rtfCell = (RtfCell) this.cells[i];
|
||||
rtfCell.WriteDefinition(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfRow
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
WriteRowDefinition(result);
|
||||
|
||||
for (int i = 0; i < this.cells.Count; i++) {
|
||||
RtfCell rtfCell = (RtfCell) this.cells[i];
|
||||
rtfCell.WriteContent(result);
|
||||
}
|
||||
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
|
||||
if (this.document.GetDocumentSettings().IsOutputTableRowDefinitionAfter()) {
|
||||
WriteRowDefinition(result);
|
||||
}
|
||||
|
||||
result.Write(ROW_END, 0, ROW_END.Length);
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent RtfTable of this RtfRow
|
||||
*
|
||||
* @return The parent RtfTable of this RtfRow
|
||||
*/
|
||||
protected internal RtfTable GetParentTable() {
|
||||
return this.parentTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cells of this RtfRow
|
||||
*
|
||||
* @return The cells of this RtfRow
|
||||
*/
|
||||
protected internal ArrayList GetCells() {
|
||||
return this.cells;
|
||||
}
|
||||
}
|
||||
}
|
||||
271
iTechSharp/iTextSharp/text/rtf/table/RtfTable.cs
Normal file
271
iTechSharp/iTextSharp/text/rtf/table/RtfTable.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.text;
|
||||
using iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfTable.cs,v 1.9 2008/05/23 17:24:29 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): all the names of the contributors are added in the source code
|
||||
* where applicable.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of the
|
||||
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
|
||||
* provisions of LGPL are applicable instead of those above. If you wish to
|
||||
* allow use of your version of this file only under the terms of the LGPL
|
||||
* License and not to allow others to use your version of this file under
|
||||
* the MPL, indicate your decision by deleting the provisions above and
|
||||
* replace them with the notice and other provisions required by the LGPL.
|
||||
* If you do not delete the provisions above, a recipient may use your version
|
||||
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MPL as stated above or under the terms of the GNU
|
||||
* Library General Public License as published by the Free Software Foundation;
|
||||
* either version 2 of the License, or any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
|
||||
* details.
|
||||
*
|
||||
* If you didn't download this code from the following link, you should check if
|
||||
* you aren't using an obsolete version:
|
||||
* http://www.lowagie.com/iText/
|
||||
*/
|
||||
|
||||
namespace iTextSharp.text.rtf.table {
|
||||
|
||||
/**
|
||||
* The RtfTable wraps a Table.
|
||||
* INTERNAL USE ONLY
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
* @author Steffen Stundzig
|
||||
* @author Benoit WIART <b.wiart@proxiad.com>
|
||||
*/
|
||||
public class RtfTable : RtfElement {
|
||||
|
||||
/**
|
||||
* The rows of this RtfTable
|
||||
*/
|
||||
private ArrayList rows = null;
|
||||
/**
|
||||
* The percentage of the page width that this RtfTable covers
|
||||
*/
|
||||
private float tableWidthPercent = 80;
|
||||
/**
|
||||
* An array with the proportional widths of the cells in each row
|
||||
*/
|
||||
private float[] proportionalWidths = null;
|
||||
/**
|
||||
* The cell padding
|
||||
*/
|
||||
private float cellPadding = 0;
|
||||
/**
|
||||
* The cell spacing
|
||||
*/
|
||||
private float cellSpacing = 0;
|
||||
/**
|
||||
* The border style of this RtfTable
|
||||
*/
|
||||
private RtfBorderGroup borders = null;
|
||||
/**
|
||||
* The alignment of this RtfTable
|
||||
*/
|
||||
private int alignment = Element.ALIGN_CENTER;
|
||||
/**
|
||||
* Whether the cells in this RtfTable must fit in a page
|
||||
*/
|
||||
private bool cellsFitToPage = false;
|
||||
/**
|
||||
* Whether the whole RtfTable must fit in a page
|
||||
*/
|
||||
private bool tableFitToPage = false;
|
||||
/**
|
||||
* The number of header rows in this RtfTable
|
||||
*/
|
||||
private int headerRows = 0;
|
||||
/**
|
||||
* The offset from the previous text
|
||||
*/
|
||||
private int offset = -1;
|
||||
|
||||
/**
|
||||
* Constructs a RtfTable based on a Table for a RtfDocument.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfTable belongs to
|
||||
* @param table The Table that this RtfTable wraps
|
||||
*/
|
||||
public RtfTable(RtfDocument doc, Table table) : base(doc) {
|
||||
table.Complete();
|
||||
ImportTable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports the rows and settings from the Table into this
|
||||
* RtfTable.
|
||||
*
|
||||
* @param table The source Table
|
||||
*/
|
||||
private void ImportTable(Table table) {
|
||||
this.rows = new ArrayList();
|
||||
this.tableWidthPercent = table.Width;
|
||||
this.proportionalWidths = table.ProportionalWidths;
|
||||
this.cellPadding = (float) (table.Cellpadding * TWIPS_FACTOR);
|
||||
this.cellSpacing = (float) (table.Cellspacing * TWIPS_FACTOR);
|
||||
this.borders = new RtfBorderGroup(this.document, RtfBorder.ROW_BORDER, table.Border, table.BorderWidth, table.BorderColor);
|
||||
this.alignment = table.Alignment;
|
||||
|
||||
int i = 0;
|
||||
foreach (Row row in table) {
|
||||
this.rows.Add(new RtfRow(this.document, this, row, i));
|
||||
i++;
|
||||
}
|
||||
for (i = 0; i < this.rows.Count; i++) {
|
||||
((RtfRow) this.rows[i]).HandleCellSpanning();
|
||||
((RtfRow) this.rows[i]).CleanRow();
|
||||
}
|
||||
this.headerRows = table.LastHeaderRow;
|
||||
this.cellsFitToPage = table.CellsFitPage;
|
||||
this.tableFitToPage = table.TableFitsPage;
|
||||
if (!float.IsNaN(table.Offset)) {
|
||||
this.offset = (int) (table.Offset * 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfTable
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
if (!inHeader) {
|
||||
if(this.offset != -1) {
|
||||
result.Write(RtfFont.FONT_SIZE, 0, RtfFont.FONT_SIZE.Length);
|
||||
byte[] t;
|
||||
result.Write(t = IntToByteArray(this.offset), 0, t.Length);
|
||||
}
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.rows.Count; i++) {
|
||||
RtfElement re = (RtfElement)this.rows[i];
|
||||
re.WriteContent(result);
|
||||
}
|
||||
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alignment of this RtfTable
|
||||
*
|
||||
* @return The alignment of this RtfTable.
|
||||
*/
|
||||
protected internal int GetAlignment() {
|
||||
return alignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the borders of this RtfTable
|
||||
*
|
||||
* @return The borders of this RtfTable.
|
||||
*/
|
||||
protected internal RtfBorderGroup GetBorders() {
|
||||
return this.borders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell padding of this RtfTable
|
||||
*
|
||||
* @return The cell padding of this RtfTable.
|
||||
*/
|
||||
protected internal float GetCellPadding() {
|
||||
return cellPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cell spacing of this RtfTable
|
||||
*
|
||||
* @return The cell spacing of this RtfTable.
|
||||
*/
|
||||
protected internal float GetCellSpacing() {
|
||||
return cellSpacing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the proportional cell widths of this RtfTable
|
||||
*
|
||||
* @return The proportional widths of this RtfTable.
|
||||
*/
|
||||
protected internal float[] GetProportionalWidths() {
|
||||
return (float[]) proportionalWidths.Clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the percentage of the page width this RtfTable covers
|
||||
*
|
||||
* @return The percentage of the page width.
|
||||
*/
|
||||
protected internal float GetTableWidthPercent() {
|
||||
return tableWidthPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rows of this RtfTable
|
||||
*
|
||||
* @return The rows of this RtfTable
|
||||
*/
|
||||
protected internal ArrayList GetRows() {
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cellsFitToPage setting of this RtfTable.
|
||||
*
|
||||
* @return The cellsFitToPage setting of this RtfTable.
|
||||
*/
|
||||
protected internal bool GetCellsFitToPage() {
|
||||
return this.cellsFitToPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tableFitToPage setting of this RtfTable.
|
||||
*
|
||||
* @return The tableFitToPage setting of this RtfTable.
|
||||
*/
|
||||
protected internal bool GetTableFitToPage() {
|
||||
return this.tableFitToPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of header rows of this RtfTable
|
||||
*
|
||||
* @return The number of header rows
|
||||
*/
|
||||
protected internal int GetHeaderRows() {
|
||||
return this.headerRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
123
iTechSharp/iTextSharp/text/rtf/text/RtfAnnotation.cs
Normal file
123
iTechSharp/iTextSharp/text/rtf/text/RtfAnnotation.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfAnnotation.cs,v 1.5 2008/05/16 19:31:23 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.text {
|
||||
|
||||
/**
|
||||
* The RtfAnnotation provides support for adding Annotations to the rtf document.
|
||||
* Only simple Annotations with Title / Content are supported.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfAnnotation : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the id of the annotation
|
||||
*/
|
||||
private static byte[] ANNOTATION_ID = DocWriter.GetISOBytes("\\*\\atnid");
|
||||
/**
|
||||
* Constant for the author of the annotation
|
||||
*/
|
||||
private static byte[] ANNOTATION_AUTHOR = DocWriter.GetISOBytes("\\*\\atnauthor");
|
||||
/**
|
||||
* Constant for the actual annotation
|
||||
*/
|
||||
private static byte[] ANNOTATION = DocWriter.GetISOBytes("\\*\\annotation");
|
||||
|
||||
/**
|
||||
* The title of this RtfAnnotation
|
||||
*/
|
||||
private String title = "";
|
||||
/**
|
||||
* The content of this RtfAnnotation
|
||||
*/
|
||||
private String content = "";
|
||||
|
||||
/**
|
||||
* Constructs a RtfAnnotation based on an Annotation.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfAnnotation belongs to
|
||||
* @param annotation The Annotation this RtfAnnotation is based off
|
||||
*/
|
||||
public RtfAnnotation(RtfDocument doc, Annotation annotation) : base(doc) {
|
||||
title = annotation.Title;
|
||||
content = annotation.Content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the RtfAnnotation
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(ANNOTATION_ID, 0, ANNOTATION_ID.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(t = IntToByteArray(document.GetRandomInt()), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(ANNOTATION_AUTHOR, 0, ANNOTATION_AUTHOR.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes(title), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
result.Write(ANNOTATION, 0, ANNOTATION.Length);
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
result.Write(t = DocWriter.GetISOBytes(content), 0, t.Length);
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
iTechSharp/iTextSharp/text/rtf/text/RtfChapter.cs
Normal file
96
iTechSharp/iTextSharp/text/rtf/text/RtfChapter.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* $Id: RtfChapter.cs,v 1.7 2008/05/16 19:31:23 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002 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.text {
|
||||
|
||||
/**
|
||||
* The RtfChapter wraps a Chapter element.
|
||||
* INTERNAL CLASS
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfChapter : RtfSection {
|
||||
|
||||
/**
|
||||
* Constructs a RtfChapter for a given Chapter
|
||||
*
|
||||
* @param doc The RtfDocument this RtfChapter belongs to
|
||||
* @param chapter The Chapter this RtfChapter is based on
|
||||
*/
|
||||
public RtfChapter(RtfDocument doc, Chapter chapter) : base(doc, chapter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the RtfChapter and its contents
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
if (this.document.GetLastElementWritten() != null && !(this.document.GetLastElementWritten() is RtfChapter)) {
|
||||
result.Write(t = DocWriter.GetISOBytes("\\page"), 0, t.Length);
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\sectd"), 0, t.Length);
|
||||
document.GetDocumentHeader().WriteSectionDefinition(result);
|
||||
if (this.title != null) {
|
||||
this.title.WriteContent(result);
|
||||
}
|
||||
for (int i = 0; i < items.Count; i++) {
|
||||
IRtfBasicElement rbe = (IRtfBasicElement)items[i];
|
||||
rbe.WriteContent(result);
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\sect"), 0, t.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
191
iTechSharp/iTextSharp/text/rtf/text/RtfChunk.cs
Normal file
191
iTechSharp/iTextSharp/text/rtf/text/RtfChunk.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfChunk.cs,v 1.7 2008/05/16 19:31:24 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.text {
|
||||
|
||||
/**
|
||||
* The RtfChunk contains one piece of text. The smallest text element available
|
||||
* in iText.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfChunk : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the subscript flag
|
||||
*/
|
||||
private static byte[] FONT_SUBSCRIPT = DocWriter.GetISOBytes("\\sub");
|
||||
/**
|
||||
* Constant for the superscript flag
|
||||
*/
|
||||
private static byte[] FONT_SUPERSCRIPT = DocWriter.GetISOBytes("\\super");
|
||||
/**
|
||||
* Constant for the end of sub / superscript flag
|
||||
*/
|
||||
private static byte[] FONT_END_SUPER_SUBSCRIPT = DocWriter.GetISOBytes("\\nosupersub");
|
||||
/**
|
||||
* Constant for background colour.
|
||||
*/
|
||||
private static byte[] BACKGROUND_COLOR = DocWriter.GetISOBytes("\\chcbpat");
|
||||
|
||||
/**
|
||||
* The font of this RtfChunk
|
||||
*/
|
||||
private ST.RtfFont font = null;
|
||||
/**
|
||||
* The actual content of this RtfChunk
|
||||
*/
|
||||
private String content = "";
|
||||
/**
|
||||
* Whether to use soft line breaks instead of hard ones.
|
||||
*/
|
||||
private bool softLineBreaks = false;
|
||||
/**
|
||||
* The super / subscript of this RtfChunk
|
||||
*/
|
||||
private float superSubScript = 0;
|
||||
/**
|
||||
* An optional background colour.
|
||||
*/
|
||||
private RtfColor background = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfChunk based on the content of a Chunk
|
||||
*
|
||||
* @param doc The RtfDocument that this Chunk belongs to
|
||||
* @param chunk The Chunk that this RtfChunk is based on
|
||||
*/
|
||||
public RtfChunk(RtfDocument doc, Chunk chunk) : base(doc) {
|
||||
|
||||
if (chunk == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunk.Attributes != null && chunk.Attributes[Chunk.SUBSUPSCRIPT] != null) {
|
||||
this.superSubScript = (float)chunk.Attributes[Chunk.SUBSUPSCRIPT];
|
||||
}
|
||||
if (chunk.Attributes != null && chunk.Attributes[Chunk.BACKGROUND] != null) {
|
||||
this.background = new RtfColor(this.document, (Color) ((Object[]) chunk.Attributes[Chunk.BACKGROUND])[0]);
|
||||
}
|
||||
font = new ST.RtfFont(doc, chunk.Font);
|
||||
content = chunk.Content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfChunk. First the font information
|
||||
* is written, then the content, and then more font information
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
if (this.background != null) {
|
||||
result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
|
||||
}
|
||||
|
||||
font.WriteBegin(result);
|
||||
if (superSubScript < 0) {
|
||||
result.Write(FONT_SUBSCRIPT, 0, FONT_SUBSCRIPT.Length);
|
||||
} else if (superSubScript > 0) {
|
||||
result.Write(FONT_SUPERSCRIPT, 0, FONT_SUPERSCRIPT.Length);
|
||||
}
|
||||
if (this.background != null) {
|
||||
result.Write(BACKGROUND_COLOR, 0, BACKGROUND_COLOR.Length);
|
||||
result.Write(t = IntToByteArray(this.background.GetColorNumber()), 0, t.Length);
|
||||
}
|
||||
result.Write(DELIMITER, 0, DELIMITER.Length);
|
||||
|
||||
document.FilterSpecialChar(result, content, false, softLineBreaks || this.document.GetDocumentSettings().IsAlwaysGenerateSoftLinebreaks());
|
||||
|
||||
if (superSubScript != 0) {
|
||||
result.Write(FONT_END_SUPER_SUBSCRIPT, 0, FONT_END_SUPER_SUBSCRIPT.Length);
|
||||
}
|
||||
font.WriteEnd(result);
|
||||
|
||||
if (this.background != null) {
|
||||
result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfChunk belongs to.
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public override void SetRtfDocument(RtfDocument doc) {
|
||||
base.SetRtfDocument(doc);
|
||||
this.font.SetRtfDocument(this.document);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to use soft line breaks instead of default hard ones.
|
||||
*
|
||||
* @param softLineBreaks whether to use soft line breaks instead of default hard ones.
|
||||
*/
|
||||
public void SetSoftLineBreaks(bool softLineBreaks) {
|
||||
this.softLineBreaks = softLineBreaks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to use soft line breaks instead of default hard ones.
|
||||
*
|
||||
* @return whether to use soft line breaks instead of default hard ones.
|
||||
*/
|
||||
public bool GetSoftLineBreaks() {
|
||||
return this.softLineBreaks;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
iTechSharp/iTextSharp/text/rtf/text/RtfNewPage.cs
Normal file
44
iTechSharp/iTextSharp/text/rtf/text/RtfNewPage.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
/*
|
||||
* Created on Aug 12, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
namespace iTextSharp.text.rtf.text {
|
||||
|
||||
|
||||
/**
|
||||
* The RtfNewPage creates a new page. INTERNAL CLASS
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfNewPage : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for a new page
|
||||
*/
|
||||
public static byte[] NEW_PAGE = DocWriter.GetISOBytes("\\page");
|
||||
|
||||
/**
|
||||
* Constructs a RtfNewPage
|
||||
*
|
||||
* @param doc The RtfDocument this RtfNewPage belongs to
|
||||
*/
|
||||
public RtfNewPage(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a new page
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(NEW_PAGE, 0, NEW_PAGE.Length);
|
||||
result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
196
iTechSharp/iTextSharp/text/rtf/text/RtfParagraph.cs
Normal file
196
iTechSharp/iTextSharp/text/rtf/text/RtfParagraph.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.graphic;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
/*
|
||||
* $Id: RtfParagraph.cs,v 1.11 2008/05/16 19:31:24 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.text {
|
||||
|
||||
/**
|
||||
* The RtfParagraph is an extension of the RtfPhrase that adds alignment and
|
||||
* indentation properties. It wraps a Paragraph.
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfParagraph : RtfPhrase {
|
||||
|
||||
/**
|
||||
* Constant for the end of a paragraph
|
||||
*/
|
||||
public static byte[] PARAGRAPH = DocWriter.GetISOBytes("\\par");
|
||||
/**
|
||||
* An optional RtfParagraphStyle to use for styling.
|
||||
*/
|
||||
protected ST.RtfParagraphStyle paragraphStyle = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfParagraph belongs to
|
||||
* @param paragraph The Paragraph that this RtfParagraph is based on
|
||||
*/
|
||||
public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc) {
|
||||
ST.RtfFont baseFont = null;
|
||||
if (paragraph.Font is ST.RtfParagraphStyle) {
|
||||
this.paragraphStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle) paragraph.Font).GetStyleName());
|
||||
baseFont = this.paragraphStyle;
|
||||
} else {
|
||||
baseFont = new ST.RtfFont(this.document, paragraph.Font);
|
||||
this.paragraphStyle = new ST.RtfParagraphStyle(this.document, this.document.GetDocumentHeader().GetRtfParagraphStyle("Normal"));
|
||||
this.paragraphStyle.SetAlignment(paragraph.Alignment);
|
||||
this.paragraphStyle.SetFirstLineIndent((int) (paragraph.FirstLineIndent * RtfElement.TWIPS_FACTOR));
|
||||
this.paragraphStyle.SetIndentLeft((int) (paragraph.IndentationLeft * RtfElement.TWIPS_FACTOR));
|
||||
this.paragraphStyle.SetIndentRight((int) (paragraph.IndentationRight * RtfElement.TWIPS_FACTOR));
|
||||
this.paragraphStyle.SetSpacingBefore((int) (paragraph.SpacingBefore * RtfElement.TWIPS_FACTOR));
|
||||
this.paragraphStyle.SetSpacingAfter((int) (paragraph.SpacingAfter * RtfElement.TWIPS_FACTOR));
|
||||
if (paragraph.HasLeading()) {
|
||||
this.paragraphStyle.SetLineLeading((int) (paragraph.Leading * RtfElement.TWIPS_FACTOR));
|
||||
}
|
||||
this.paragraphStyle.SetKeepTogether(paragraph.KeepTogether);
|
||||
}
|
||||
|
||||
for (int i = 0; i < paragraph.Count; i++) {
|
||||
IElement chunk = (IElement) paragraph[i];
|
||||
if (chunk is Chunk) {
|
||||
((Chunk) chunk).Font = baseFont.Difference(((Chunk) chunk).Font);
|
||||
} else if (chunk is RtfImage) {
|
||||
((RtfImage) chunks[i]).SetAlignment(this.paragraphStyle.GetAlignment());
|
||||
}
|
||||
try {
|
||||
IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
|
||||
for(int j = 0; j < rtfElements.Length; j++) {
|
||||
chunks.Add(rtfElements[j]);
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this RtfParagraph must stay on the same page as the next one.
|
||||
*
|
||||
* @param keepTogetherWithNext Whether this RtfParagraph must keep together with the next.
|
||||
*/
|
||||
public void SetKeepTogetherWithNext(bool keepTogetherWithNext) {
|
||||
this.paragraphStyle.SetKeepTogetherWithNext(keepTogetherWithNext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of this RtfParagraph. First paragraph specific data is written
|
||||
* and then the RtfChunks of this RtfParagraph are added.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(PARAGRAPH_DEFAULTS, 0, PARAGRAPH_DEFAULTS.Length);
|
||||
result.Write(PLAIN, 0, PLAIN.Length);
|
||||
if (inTable) {
|
||||
result.Write(IN_TABLE, 0, IN_TABLE.Length);
|
||||
}
|
||||
if(this.paragraphStyle != null) {
|
||||
this.paragraphStyle.WriteBegin(result);
|
||||
}
|
||||
result.Write(PLAIN, 0, PLAIN.Length);
|
||||
for (int i = 0; i < chunks.Count; i++) {
|
||||
IRtfBasicElement rbe = (IRtfBasicElement)chunks[i];
|
||||
rbe.WriteContent(result);
|
||||
}
|
||||
if(this.paragraphStyle != null) {
|
||||
this.paragraphStyle.WriteEnd(result);
|
||||
}
|
||||
if (!inTable) {
|
||||
result.Write(PARAGRAPH, 0, PARAGRAPH.Length);
|
||||
}
|
||||
if(this.document.GetDocumentSettings().IsOutputDebugLineBreaks()) {
|
||||
result.WriteByte((byte)'\n');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the left indentation of this RtfParagraph.
|
||||
*
|
||||
* @return The left indentation.
|
||||
*/
|
||||
public int GetIndentLeft() {
|
||||
return this.paragraphStyle.GetIndentLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the left indentation of this RtfParagraph.
|
||||
*
|
||||
* @param indentLeft The left indentation to use.
|
||||
*/
|
||||
public void SetIndentLeft(int indentLeft) {
|
||||
this.paragraphStyle.SetIndentLeft(indentLeft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the right indentation of this RtfParagraph.
|
||||
*
|
||||
* @return The right indentation.
|
||||
*/
|
||||
public int GetIndentRight() {
|
||||
return this.paragraphStyle.GetIndentRight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right indentation of this RtfParagraph.
|
||||
*
|
||||
* @param indentRight The right indentation to use.
|
||||
*/
|
||||
public void SetIndentRight(int indentRight) {
|
||||
this.paragraphStyle.SetIndentRight(indentRight);
|
||||
}
|
||||
}
|
||||
}
|
||||
198
iTechSharp/iTextSharp/text/rtf/text/RtfPhrase.cs
Normal file
198
iTechSharp/iTextSharp/text/rtf/text/RtfPhrase.cs
Normal file
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.style;
|
||||
using ST = iTextSharp.text.rtf.style;
|
||||
|
||||
/*
|
||||
* $Id: RtfPhrase.cs,v 1.10 2008/05/16 19:31:24 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.text {
|
||||
|
||||
/**
|
||||
* The RtfPhrase contains multiple RtfChunks
|
||||
*
|
||||
* @version $Id: RtfPhrase.cs,v 1.10 2008/05/16 19:31:24 psoares33 Exp $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfPhrase : RtfElement {
|
||||
|
||||
/**
|
||||
* Constant for the resetting of the paragraph defaults
|
||||
*/
|
||||
public static byte[] PARAGRAPH_DEFAULTS = DocWriter.GetISOBytes("\\pard");
|
||||
/**
|
||||
* Constant for resetting of font settings to their defaults
|
||||
*/
|
||||
public static byte[] PLAIN = DocWriter.GetISOBytes("\\plain");
|
||||
/**
|
||||
* Constant for phrase in a table indication
|
||||
*/
|
||||
public static byte[] IN_TABLE = DocWriter.GetISOBytes("\\intbl");
|
||||
/**
|
||||
* Constant for the line spacing.
|
||||
*/
|
||||
public static byte[] LINE_SPACING = DocWriter.GetISOBytes("\\sl");
|
||||
|
||||
/**
|
||||
* ArrayList containing the RtfChunks of this RtfPhrase
|
||||
*/
|
||||
protected ArrayList chunks = new ArrayList();
|
||||
/**
|
||||
* The height of each line.
|
||||
*/
|
||||
private int lineLeading = 0;
|
||||
|
||||
/**
|
||||
* A basically empty constructor that is used by the RtfParagraph.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPhrase belongs to.
|
||||
*/
|
||||
protected internal RtfPhrase(RtfDocument doc) : base(doc) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new RtfPhrase for the RtfDocument with the given Phrase
|
||||
*
|
||||
* @param doc The RtfDocument this RtfPhrase belongs to
|
||||
* @param phrase The Phrase this RtfPhrase is based on
|
||||
*/
|
||||
public RtfPhrase(RtfDocument doc, Phrase phrase) : base(doc) {
|
||||
|
||||
if (phrase == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (phrase.HasLeading()) {
|
||||
this.lineLeading = (int) (phrase.Leading * TWIPS_FACTOR);
|
||||
} else {
|
||||
this.lineLeading = 0;
|
||||
}
|
||||
|
||||
ST.RtfFont phraseFont = new ST.RtfFont(null, phrase.Font);
|
||||
for (int i = 0; i < phrase.Count; i++) {
|
||||
IElement chunk = (IElement) phrase[i];
|
||||
if (chunk is Chunk) {
|
||||
((Chunk) chunk).Font = phraseFont.Difference(((Chunk) chunk).Font);
|
||||
}
|
||||
try {
|
||||
IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
|
||||
for (int j = 0; j < rtfElements.Length; j++) {
|
||||
chunks.Add(rtfElements[j]);
|
||||
}
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of this RtfPhrase. First resets to the paragraph defaults
|
||||
* then if the RtfPhrase is in a RtfCell a marker for this is written and finally
|
||||
* the RtfChunks of this RtfPhrase are written.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
result.Write(PARAGRAPH_DEFAULTS, 0, PARAGRAPH_DEFAULTS.Length);
|
||||
result.Write(PLAIN, 0, PLAIN.Length);
|
||||
if (inTable) {
|
||||
result.Write(IN_TABLE, 0, IN_TABLE.Length);
|
||||
}
|
||||
if (this.lineLeading > 0) {
|
||||
result.Write(LINE_SPACING, 0, LINE_SPACING.Length);
|
||||
result.Write(t = IntToByteArray(this.lineLeading), 0, t.Length);
|
||||
}
|
||||
foreach (IRtfBasicElement rbe in chunks) {
|
||||
rbe.WriteContent(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfPhrase is in a table. Sets the correct inTable setting for all
|
||||
* child elements.
|
||||
*
|
||||
* @param inTable <code>True</code> if this RtfPhrase is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public override void SetInTable(bool inTable) {
|
||||
base.SetInTable(inTable);
|
||||
for (int i = 0; i < this.chunks.Count; i++) {
|
||||
((IRtfBasicElement) this.chunks[i]).SetInTable(inTable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfPhrase is in a header. Sets the correct inTable setting for all
|
||||
* child elements.
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfPhrase is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public override void SetInHeader(bool inHeader) {
|
||||
base.SetInHeader(inHeader);
|
||||
for (int i = 0; i < this.chunks.Count; i++) {
|
||||
((IRtfBasicElement) this.chunks[i]).SetInHeader(inHeader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RtfDocument this RtfPhrase belongs to. Also sets the RtfDocument for all child
|
||||
* elements.
|
||||
*
|
||||
* @param doc The RtfDocument to use
|
||||
*/
|
||||
public override void SetRtfDocument(RtfDocument doc) {
|
||||
base.SetRtfDocument(doc);
|
||||
for (int i = 0; i < this.chunks.Count; i++) {
|
||||
((IRtfBasicElement) this.chunks[i]).SetRtfDocument(this.document);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
183
iTechSharp/iTextSharp/text/rtf/text/RtfSection.cs
Normal file
183
iTechSharp/iTextSharp/text/rtf/text/RtfSection.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf.document;
|
||||
using iTextSharp.text.rtf.field;
|
||||
using FD = iTextSharp.text.rtf.field;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfSection.cs,v 1.9 2008/05/16 19:31:24 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.text {
|
||||
|
||||
/**
|
||||
* The RtfSection wraps a Section element.
|
||||
* INTERNAL CLASS
|
||||
*
|
||||
* @version $Version:$
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfSection : RtfElement {
|
||||
|
||||
/**
|
||||
* The title paragraph of this RtfSection
|
||||
*/
|
||||
protected RtfParagraph title = null;
|
||||
/**
|
||||
* The sub-items of this RtfSection
|
||||
*/
|
||||
protected ArrayList items = null;
|
||||
|
||||
/**
|
||||
* Constructs a RtfSection for a given Section. If the autogenerateTOCEntries
|
||||
* property of the RtfDocument is set and the title is not empty then a TOC entry
|
||||
* is generated for the title.
|
||||
*
|
||||
* @param doc The RtfDocument this RtfSection belongs to
|
||||
* @param section The Section this RtfSection is based on
|
||||
*/
|
||||
public RtfSection(RtfDocument doc, Section section) : base(doc) {
|
||||
items = new ArrayList();
|
||||
try {
|
||||
if (section.Title != null) {
|
||||
this.title = (RtfParagraph) doc.GetMapper().MapElement(section.Title)[0];
|
||||
}
|
||||
if (document.GetAutogenerateTOCEntries()) {
|
||||
StringBuilder titleText = new StringBuilder();
|
||||
foreach (IElement element in section.Title) {
|
||||
if (element.Type == Element.CHUNK) {
|
||||
titleText.Append(((Chunk) element).Content);
|
||||
}
|
||||
}
|
||||
if (titleText.ToString().Trim().Length > 0) {
|
||||
FD.RtfTOCEntry tocEntry = new FD.RtfTOCEntry(titleText.ToString());
|
||||
tocEntry.SetRtfDocument(this.document);
|
||||
this.items.Add(tocEntry);
|
||||
}
|
||||
}
|
||||
foreach (IElement element in section) {
|
||||
IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element);
|
||||
for (int i = 0; i < rtfElements.Length; i++) {
|
||||
if (rtfElements[i] != null) {
|
||||
items.Add(rtfElements[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateIndentation(section.IndentationLeft, section.IndentationRight, section.Indentation);
|
||||
} catch (DocumentException) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this RtfSection and its contents
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
|
||||
if (this.title != null) {
|
||||
this.title.WriteContent(result);
|
||||
}
|
||||
foreach (IRtfBasicElement rbe in items) {
|
||||
rbe.WriteContent(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfSection is in a table. Sets the correct inTable setting for all
|
||||
* child elements.
|
||||
*
|
||||
* @param inTable <code>True</code> if this RtfSection is in a table, <code>false</code> otherwise
|
||||
*/
|
||||
public override void SetInTable(bool inTable) {
|
||||
base.SetInTable(inTable);
|
||||
for (int i = 0; i < this.items.Count; i++) {
|
||||
((IRtfBasicElement) this.items[i]).SetInTable(inTable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this RtfSection is in a header. Sets the correct inTable setting for all
|
||||
* child elements.
|
||||
*
|
||||
* @param inHeader <code>True</code> if this RtfSection is in a header, <code>false</code> otherwise
|
||||
*/
|
||||
public override void SetInHeader(bool inHeader) {
|
||||
base.SetInHeader(inHeader);
|
||||
for (int i = 0; i < this.items.Count; i++) {
|
||||
((IRtfBasicElement) this.items[i]).SetInHeader(inHeader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the left, right and content indentation of all RtfParagraph and RtfSection
|
||||
* elements that this RtfSection contains.
|
||||
*
|
||||
* @param indentLeft The left indentation to add.
|
||||
* @param indentRight The right indentation to add.
|
||||
* @param indentContent The content indentation to add.
|
||||
*/
|
||||
private void UpdateIndentation(float indentLeft, float indentRight, float indentContent) {
|
||||
if(this.title != null) {
|
||||
this.title.SetIndentLeft((int) (this.title.GetIndentLeft() + indentLeft * RtfElement.TWIPS_FACTOR));
|
||||
this.title.SetIndentRight((int) (this.title.GetIndentRight() + indentRight * RtfElement.TWIPS_FACTOR));
|
||||
}
|
||||
for(int i = 0; i < this.items.Count; i++) {
|
||||
IRtfBasicElement rtfElement = (IRtfBasicElement) this.items[i];
|
||||
if(rtfElement is RtfSection) {
|
||||
((RtfSection) rtfElement).UpdateIndentation(indentLeft + indentContent, indentRight, 0);
|
||||
} else if(rtfElement is RtfParagraph) {
|
||||
((RtfParagraph) rtfElement).SetIndentLeft((int) (((RtfParagraph) rtfElement).GetIndentLeft() + (indentLeft + indentContent) * RtfElement.TWIPS_FACTOR));
|
||||
((RtfParagraph) rtfElement).SetIndentRight((int) (((RtfParagraph) rtfElement).GetIndentRight() + indentRight * RtfElement.TWIPS_FACTOR));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
135
iTechSharp/iTextSharp/text/rtf/text/RtfTab.cs
Normal file
135
iTechSharp/iTextSharp/text/rtf/text/RtfTab.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfTab.cs,v 1.5 2008/05/23 17:24:29 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
* Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
|
||||
* Copyright (C) 2006 by Mark Hall. 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.text {
|
||||
|
||||
/**
|
||||
* The RtfTab encapsulates a tab position and tab type in a paragraph.
|
||||
* To add tabs to a paragraph construct new RtfTab objects with the desired
|
||||
* tab position and alignment and then add them to the paragraph. In the actual
|
||||
* text the tabs are then defined as standard \t characters.<br /><br />
|
||||
*
|
||||
* <code>RtfTab tab = new RtfTab(300, RtfTab.TAB_LEFT_ALIGN);<br />
|
||||
* Paragraph para = new Paragraph();<br />
|
||||
* para.Add(tab);<br />
|
||||
* para.Add("This paragraph has a\ttab defined.");</code>
|
||||
*
|
||||
* @version $Revision: 1.5 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfTab : RtfAddableElement {
|
||||
|
||||
/**
|
||||
* A tab where the text is left aligned.
|
||||
*/
|
||||
public const int TAB_LEFT_ALIGN = 0;
|
||||
/**
|
||||
* A tab where the text is centre aligned.
|
||||
*/
|
||||
public const int TAB_CENTER_ALIGN = 1;
|
||||
/**
|
||||
* A tab where the text is right aligned.
|
||||
*/
|
||||
public const int TAB_RIGHT_ALIGN = 2;
|
||||
/**
|
||||
* A tab where the text is aligned on the decimal character. Which
|
||||
* character that is depends on the language settings of the viewer.
|
||||
*/
|
||||
public const int TAB_DECIMAL_ALIGN = 3;
|
||||
|
||||
/**
|
||||
* The tab position in twips.
|
||||
*/
|
||||
private int position = 0;
|
||||
/**
|
||||
* The tab alignment.
|
||||
*/
|
||||
private int type = TAB_LEFT_ALIGN;
|
||||
|
||||
/**
|
||||
* Constructs a new RtfTab with the given position and type. The position
|
||||
* is in standard iText points. The type is one of the tab alignment
|
||||
* constants defined in the RtfTab.
|
||||
*
|
||||
* @param position The position of the tab in points.
|
||||
* @param type The tab type constant.
|
||||
*/
|
||||
public RtfTab(float position, int type) {
|
||||
this.position = (int) Math.Round(position * RtfElement.TWIPS_FACTOR);
|
||||
switch (type) {
|
||||
case TAB_LEFT_ALIGN: this.type = TAB_LEFT_ALIGN; break;
|
||||
case TAB_CENTER_ALIGN: this.type = TAB_CENTER_ALIGN; break;
|
||||
case TAB_RIGHT_ALIGN: this.type = TAB_RIGHT_ALIGN; break;
|
||||
case TAB_DECIMAL_ALIGN: this.type = TAB_DECIMAL_ALIGN; break;
|
||||
default: this.type = TAB_LEFT_ALIGN; break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the tab settings.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
byte[] t;
|
||||
switch (this.type) {
|
||||
case TAB_CENTER_ALIGN: result.Write(t = DocWriter.GetISOBytes("\\tqc"), 0, t.Length); break;
|
||||
case TAB_RIGHT_ALIGN: result.Write(t = DocWriter.GetISOBytes("\\tqr"), 0, t.Length); break;
|
||||
case TAB_DECIMAL_ALIGN: result.Write(t = DocWriter.GetISOBytes("\\tqdec"), 0, t.Length); break;
|
||||
}
|
||||
result.Write(t = DocWriter.GetISOBytes("\\tx"), 0, t.Length);
|
||||
result.Write(t = IntToByteArray(this.position), 0, t.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
121
iTechSharp/iTextSharp/text/rtf/text/RtfTabGroup.cs
Normal file
121
iTechSharp/iTextSharp/text/rtf/text/RtfTabGroup.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.rtf;
|
||||
/*
|
||||
* $Id: RtfTabGroup.cs,v 1.5 2008/05/23 17:24:29 psoares33 Exp $
|
||||
*
|
||||
*
|
||||
* Copyright 2001, 2002, 2003, 2004 by Mark Hall
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is 'iText, a free JAVA-PDF library'.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
|
||||
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
|
||||
* All Rights Reserved.
|
||||
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
|
||||
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
|
||||
* Co-Developer of the code is Mark Hall. Portions created by the Co-Developer are
|
||||
* Copyright (C) 2006 by Mark Hall. 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.text {
|
||||
|
||||
/**
|
||||
* The RtfTabGroup is a convenience class if the same tabs are to be added
|
||||
* to multiple paragraphs.<br /><br />
|
||||
*
|
||||
* <code>RtfTabGroup tabs = new RtfTabGroup();<br />
|
||||
* tabs.Add(new RtfTab(70, RtfTab.TAB_LEFT_ALIGN));<br />
|
||||
* tabs.Add(new RtfTab(160, RtfTab.TAB_CENTER_ALIGN));<br />
|
||||
* tabs.Add(new RtfTab(250, RtfTab.TAB_DECIMAL_ALIGN));<br />
|
||||
* tabs.Add(new RtfTab(500, RtfTab.TAB_RIGHT_ALIGN));<br />
|
||||
* Paragraph para = new Paragraph();<br />
|
||||
* para.Add(tabs);<br />
|
||||
* para.Add("\tLeft aligned\tCentre aligned\t12,45\tRight aligned");</code>
|
||||
*
|
||||
* @version $Revision: 1.5 $
|
||||
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
|
||||
*/
|
||||
public class RtfTabGroup : RtfAddableElement {
|
||||
/**
|
||||
* The tabs to add.
|
||||
*/
|
||||
private ArrayList tabs = null;
|
||||
|
||||
/**
|
||||
* Constructs an empty RtfTabGroup.
|
||||
*/
|
||||
public RtfTabGroup() {
|
||||
this.tabs = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a RtfTabGroup with a set of tabs.
|
||||
*
|
||||
* @param tabs An ArrayList with the RtfTabs to group in this RtfTabGroup.
|
||||
*/
|
||||
public RtfTabGroup(ArrayList tabs) {
|
||||
this.tabs = new ArrayList();
|
||||
for (int i = 0; i < tabs.Count; i++) {
|
||||
if (tabs[i] is RtfTab) {
|
||||
this.tabs.Add(tabs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a RtfTab to the list of grouped tabs.
|
||||
*
|
||||
* @param tab The RtfTab to add.
|
||||
*/
|
||||
public void Add(RtfTab tab) {
|
||||
this.tabs.Add(tab);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines the tab output form all grouped tabs.
|
||||
*/
|
||||
public override void WriteContent(Stream result) {
|
||||
foreach (RtfTab rt in tabs) {
|
||||
rt.WriteContent(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user