Initial Commit
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user