Initial Commit

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

View File

@@ -0,0 +1,86 @@
using System;
using System.IO;
namespace iTextSharp.text.rtf.parser {
public class PushbackStream : Stream {
private int buf = -1;
private readonly Stream s;
public PushbackStream(Stream s) {
this.s = s;
}
public override bool CanRead
{
get { return s.CanRead; }
}
public override bool CanSeek
{
get { return s.CanSeek; }
}
public override bool CanWrite
{
get { return s.CanWrite; }
}
public override long Length
{
get { return s.Length; }
}
public override long Position
{
get { return s.Position; }
set { s.Position = value; }
}
public override void Close()
{
s.Close();
}
public override void Flush()
{
s.Flush();
}
public override long Seek(long offset, SeekOrigin origin)
{
return s.Seek(offset, origin);
}
public override void SetLength(long value)
{
s.SetLength(value);
}
public override void Write(byte[] buffer, int offset, int count)
{
s.Write(buffer, offset, count);
}
public override void WriteByte(byte value)
{
s.WriteByte(value);
}
public override int ReadByte() {
if (buf != -1) {
int tmp = buf;
buf = -1;
return tmp;
}
return s.ReadByte();
}
public override int Read(byte[] buffer, int offset, int count) {
if (buf != -1 && count > 0) {
// TODO Can this case be made more efficient?
buffer[offset] = (byte) buf;
buf = -1;
return 1;
}
return s.Read(buffer, offset, count);
}
public virtual void Unread(int b) {
if (buf != -1)
throw new InvalidOperationException("Can only push back one byte");
buf = b & 0xFF;
}
}
}

View File

@@ -0,0 +1,170 @@
using System;
using System.Collections;
using iTextSharp.text;
/*
* $Id: RtfImportMappings.cs,v 1.3 2008/05/16 19:31:06 psoares33 Exp $
*
*
* Copyright 2006 by Mark Hall
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser {
/**
* The RtfImportMappings make it possible to define font
* and color mappings when using the RtfWriter2.importRtfFragment
* method. This is necessary, because a RTF fragment does not
* contain font or color information, just references to the
* font and color tables.<br /><br />
*
* The font mappings are fontNr -&gt; fontName and the color
* mappigns are colorNr -&gt; Color.
*
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
* @author Howard Shank (hgshank@yahoo.com)
*/
public class RtfImportMappings {
/**
* The fontNr to fontName mappings.
*/
private Hashtable fontMappings = null;
/**
* The colorNr to Color mappings.
*/
private Hashtable colorMappings = null;
/**
* The listNr to List mappings.
*/
private Hashtable listMappings = null;
/**
* The sytlesheetListNr to Stylesheet mappings.
*/
private Hashtable stylesheetListMappings = null;
/**
* Constructs a new RtfImportMappings initialising the mappings.
*/
public RtfImportMappings() {
this.fontMappings = new Hashtable();
this.colorMappings = new Hashtable();
this.listMappings = new Hashtable();
this.stylesheetListMappings = new Hashtable();
}
/**
* Add a font to the list of mappings.
*
* @param fontNr The font number.
* @param fontName The font name.
*/
public void AddFont(String fontNr, String fontName) {
this.fontMappings[fontNr] = fontName;
}
/**
* Add a color to the list of mappings.
*
* @param colorNr The color number.
* @param color The Color.
*/
public void AddColor(String colorNr, Color color) {
this.colorMappings[colorNr] = color;
}
/**
* Add a List to the list of mappings.
*
* @param listNr The List number.
* @param list The List.
*/
public void AddList(String listNr, Color list) {
this.listMappings[listNr] = list;
}
/**
* Add a Stylesheet List to the list of mappings.
*
* @param stylesheetListNr The Stylesheet List number.
* @param list The StylesheetList.
*/
public void AddStylesheetList(String stylesheetListNr, Color list) {
this.stylesheetListMappings[stylesheetListNr] = list;
}
/**
* Gets the list of font mappings. String to String.
*
* @return The font mappings.
*/
public Hashtable GetFontMappings() {
return this.fontMappings;
}
/**
* Gets the list of color mappings. String to Color.
*
* @return The color mappings.
*/
public Hashtable GetColorMappings() {
return this.colorMappings;
}
/**
* Gets the list of List mappings.
*
* @return The List mappings.
*/
public Hashtable GetListMappings() {
return this.listMappings;
}
/**
* Gets the list of Stylesheet mappings. .
*
* @return The Stylesheet List mappings.
*/
public Hashtable GetStylesheetListMappings() {
return this.stylesheetListMappings;
}
}
}

View File

@@ -0,0 +1,281 @@
using System;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.list;
using iTextSharp.text.rtf.style;
/*
* $Id: RtfImportMgr.cs,v 1.3 2008/05/16 19:31:07 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser {
/**
* The RtfImportHeader stores the docment header information from
* an RTF document that is being imported. Currently font and
* color settings are stored. The RtfImportHeader maintains a mapping
* from font and color numbers from the imported RTF document to
* the RTF document that is the target of the import. This guarantees
* that the merged document has the correct font and color settings.
* It also handles other list based items that need mapping, for example
* stylesheets and lists.
*
* @author Mark Hall (Mark.Hall@mail.room3b.eu)
* @author Howard Shank (hgshank@yahoo.com)
*/
public class RtfImportMgr {
//TODO: Add list, stylesheet, info, etc. mappings
/**
* The Hashtable storing the font number mappings.
*/
private Hashtable importFontMapping = null;
/**
* The Hashtable storing the color number mapings.
*/
private Hashtable importColorMapping = null;
/**
* The Hashtable storing the Stylesheet List number mapings.
*/
private Hashtable importStylesheetListMapping = null;
/**
* The Hashtable storing the List number mapings.
*/
private Hashtable importListMapping = null;
/**
* The RtfDocument to get font and color numbers from.
*/
private RtfDocument rtfDoc = null;
/**
* The Document.
* Used for conversions, but not imports.
*/
private Document doc = null;
/**
* Constructs a new RtfImportHeader.
*
* @param rtfDoc The RtfDocument to get font and color numbers from.
*/
public RtfImportMgr(RtfDocument rtfDoc, Document doc) {
this.rtfDoc = rtfDoc;
this.doc = doc;
this.importFontMapping = new Hashtable();
this.importColorMapping = new Hashtable();
this.importStylesheetListMapping = new Hashtable();
this.importListMapping = new Hashtable();
}
/**
* Imports a font. The font name is looked up in the RtfDocumentHeader and
* then the mapping from original font number to actual font number is added.
*
* @param fontNr The original font number.
* @param fontName The font name to look up.
*/
public bool ImportFont(String fontNr, String fontName) {
RtfFont rtfFont = new RtfFont(fontName);
if (rtfFont != null){
rtfFont.SetRtfDocument(this.rtfDoc);
this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
return true;
} else {
return false;
}
}
/**
* Imports a font. The font name is looked up in the RtfDocumentHeader and
* then the mapping from original font number to actual font number is added.
*
* @param fontNr The original font number.
* @param fontName The font name to look up.
* @param charset The characterset to use for the font.
*/
public bool ImportFont(String fontNr, String fontName, int charset) {
RtfFont rtfFont = new RtfFont(fontName);
if (charset>= 0)
rtfFont.SetCharset(charset);
if (rtfFont != null){
rtfFont.SetRtfDocument(this.rtfDoc);
this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
return true;
} else {
return false;
}
}
/**
* Imports a font. The font name is looked up in the RtfDocumentHeader and
* then the mapping from original font number to actual font number is added.
*
* @param fontNr The original font number.
* @param fontName The font name to look up.
* @param charset The characterset to use for the font.
*/
public bool ImportFont(String fontNr, String fontName, String fontFamily, int charset) {
RtfFont rtfFont = new RtfFont(fontName);
if (charset>= 0)
rtfFont.SetCharset(charset);
if (fontFamily != null && fontFamily.Length > 0)
rtfFont.SetFamily(fontFamily);
if (rtfFont != null){
rtfFont.SetRtfDocument(this.rtfDoc);
this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
return true;
} else {
return false;
}
}
/**
* Performs the mapping from the original font number to the actual
* font number in the resulting RTF document. If the font number was not
* seen during import (thus no mapping) then 0 is returned, guaranteeing
* that the font number is always valid.
*
* @param fontNr The font number to map.
* @return The mapped font number.
*/
public String MapFontNr(String fontNr) {
if (this.importFontMapping.ContainsKey(fontNr)) {
return (String) this.importFontMapping[fontNr];
} else {
return "0";
}
}
/**
* Imports a color value. The color number for the color defined
* by its red, green and blue values is determined and then the
* resulting mapping is added.
*
* @param colorNr The original color number.
* @param color The color to import.
*/
public void ImportColor(String colorNr, Color color) {
RtfColor rtfColor = new RtfColor(this.rtfDoc, color);
this.importColorMapping[colorNr] = rtfColor.GetColorNumber().ToString();
}
/**
* Performs the mapping from the original font number to the actual font
* number used in the RTF document. If the color number was not
* seen during import (thus no mapping) then 0 is returned, guaranteeing
* that the color number is always valid.
*
* @param colorNr The color number to map.
* @return The mapped color number
*/
public String MapColorNr(String colorNr) {
if (this.importColorMapping.ContainsKey(colorNr)) {
return (String) this.importColorMapping[colorNr];
} else {
return "0";
}
}
/**
* Imports a List value. The List number for the List defined
* is determined and then the resulting mapping is added.
*/
public void ImportList(String listNr, List list) {
RtfList rtfList = new RtfList(this.rtfDoc, list);
//if(rtfList != null){
//rtfList.SetRtfDocument(this.rtfDoc);
this.importStylesheetListMapping[listNr] = this.rtfDoc.GetDocumentHeader().GetListNumber(rtfList).ToString();
// return true;
// } else {
// return false;
// }
}
/**
* Performs the mapping from the original list number to the actual
* list number in the resulting RTF document. If the list number was not
* seen during import (thus no mapping) then 0 is returned, guaranteeing
* that the list number is always valid.
*/
public String MapListNr(String listNr) {
if (this.importListMapping.ContainsKey(listNr)) {
return (String) this.importListMapping[listNr];
} else {
return "0";
}
}
/**
* Imports a stylesheet list value. The stylesheet number for the stylesheet defined
* is determined and then the resulting mapping is added.
*/
public bool ImportStylesheetList(String listNr, List listIn) {
RtfList rtfList = new RtfList(this.rtfDoc, listIn);
if (rtfList != null){
rtfList.SetRtfDocument(this.rtfDoc);
//this.importStylesheetListMapping[listNr] = Integer.ToString(this.rtfDoc.GetDocumentHeader().GetRtfParagraphStyle(styleName)(rtfList));
return true;
} else {
return false;
}
}
/**
* Performs the mapping from the original stylesheet number to the actual
* stylesheet number in the resulting RTF document. If the stylesheet number was not
* seen during import (thus no mapping) then 0 is returned, guaranteeing
* that the stylesheet number is always valid.
*/
public String MapStylesheetListNr(String listNr) {
if (this.importStylesheetListMapping.ContainsKey(listNr)) {
return (String) this.importStylesheetListMapping[listNr];
} else {
return "0";
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,138 @@
using System;
using System.Collections;
using System.Text;
using iTextSharp.text.rtf.parser.ctrlwords;
using iTextSharp.text.rtf.parser.destinations;
using iTextSharp.text.rtf.parser.properties;
/*
* $Id: RtfParserState.cs,v 1.2 2008/05/13 11:25:58 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser {
/**
* The <code>RtfParserState</code> contains the state information
* for the parser. The current state object is pushed/popped in a stack
* when a group change is made.
*
* When an open group is encountered, the current state is copied and
* then pushed on the top of the stack
* When a close group is encountered, the current state is overwritten with
* the popped value from the top of the stack
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfParserState {
/**
* The parser state.
*/
public int parserState = RtfParser.PARSER_IN_UNKNOWN;
/**
* The tokeniser state.
*/
public int tokeniserState = RtfParser.TOKENISER_STATE_IN_UNKOWN;
/**
* The control word set as the group handler.
*/
public Object groupHandler = null;
/**
* The parsed value for the current group/control word.
*/
public StringBuilder text = null;
/**
* Stack containing control word handlers. There could be multiple
* control words in a group.
*/
public Stack ctrlWordHandlers = null;
/**
* The current control word handler.
*/
public Object ctrlWordHandler = null;
/**
* The current destination.
*/
public RtfDestination destination = null;
/**
* Flag indicating if this is an extended destination \* control word
*/
public bool isExtendedDestination = false;
/**
* Flag to indicate if last token was an open group token '{'
*/
public bool newGroup = false;
public RtfProperty properties = null;
/**
* Default constructor
*
*/
public RtfParserState() {
this.text = new StringBuilder();
this.ctrlWordHandlers = new Stack();
this.properties = new RtfProperty();
this.destination = RtfDestinationNull.GetInstance();
this.newGroup = false;
}
/**
* Copy constructor
* @param orig The object to copy
*/
public RtfParserState(RtfParserState orig) {
this.properties = orig.properties;
this.parserState = orig.parserState;
this.tokeniserState = orig.tokeniserState;
this.groupHandler = null;
this.destination = orig.destination;
this.text = new StringBuilder();
this.ctrlWordHandlers = new Stack();
this.destination = orig.destination;
this.newGroup = false;
}
}
}

View File

@@ -0,0 +1,78 @@
using System;
using iTextSharp.text.rtf.parser;
/*
* $Id: IRtfCtrlWordListener.cs,v 1.2 2008/05/13 11:25:58 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.ctrlwords {
/**
* <code>RtfCtrlWordListener</code> interface for handling events.
*
* @author Howard Shank (hgshank@yahoo.com)
*
* @since 2.0.8
*/
public interface IRtfCtrlWordListener : IEventListener {
/**
*
* @return null or modified copy of the ctrlWordData object
*/
RtfCtrlWordData BeforeCtrlWord(RtfCtrlWordData ctrlWordData);
/**
*
* @return null or modified copy of the ctrlWordData object
*/
RtfCtrlWordData OnCtrlWord(RtfCtrlWordData ctrlWordData);
/**
*
* @return null or modified copy of the ctrlWordData object
*/
RtfCtrlWordData AfterCtrlWord(RtfCtrlWordData ctrlWordData);
}
}

View File

@@ -0,0 +1,132 @@
using System;
using iTextSharp.text.rtf.parser.properties;
/* $Id: RtfCtrlWordData.cs,v 1.2 2008/05/13 11:25:58 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.ctrlwords {
/**
* The control word and parameter information as parsed by the parser.
* Contains the control word,
* Flag indicating if there is a parameter.
* The parameter value as a string.
* Flag indicating the parameter is positive or negative.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfCtrlWordData {
public String prefix = "";
public String suffix = "";
/**
* The control word found by the parser
*/
public String ctrlWord = "";
/**
* Flag indicating if this keyword has a parameter.
*/
public bool hasParam = false;
/**
* The parameter for the control word.
*/
public String param = "";
/**
* Flag indicating if parameter is positive or negative.
*/
public bool isNeg = false;
/**
* Flag indicating a new group
*/
public bool newGroup = false;
/**
* Flag indicating if this object has been modified.
*/
public bool modified = false;
public int ctrlWordType = RtfCtrlWordType.UNIDENTIFIED;
public String specialHandler = "";
/**
* Return the parameter value as an integer (int) value.
*
* @return
* Returns the parameter value as an int vlaue.
*/
public int IntValue() {
int value;
value = int.Parse(this.param);
if (this.isNeg) value = (-value);
return value;
}
/**
* Return the parameter value as a long value
*
* @return
* Returns the parameter value as a long value
*/
public long LongValue() {
long value;
value = long.Parse(this.param);
if (this.isNeg) value = (-value);
return value;
}
public override String ToString() {
String outp = "";
outp = this.prefix + this.ctrlWord;
if (this.hasParam) {
if (this.isNeg) outp += "-";
outp += this.param;
}
outp += this.suffix;
return outp;
}
}
}

View File

@@ -0,0 +1,358 @@
using System;
using iTextSharp.text.rtf;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.destinations;
using iTextSharp.text.rtf.parser.properties;
using iTextSharp.text.rtf.direct;
/* $Id: RtfCtrlWordHandler.cs,v 1.3 2008/05/13 11:25:58 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.ctrlwords {
/**
* <code>RtfCtrlWordBase</code> is the base class for all
* control word handlers to extend from.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfCtrlWordHandler {
/**
* Debug flag - internal use
* @since 2.0.8
*/
private static bool debug = false;
/**
* Local variable referencing the parser object.
* @since 2.0.8
*/
protected RtfParser rtfParser = null;
/**
* The control word for this class.
* @since 2.0.8
*/
protected String ctrlWord = "";
/**
* The default value for this control word.
* Not all control words use a default parameter value.
* @since 2.0.8
*/
protected int defaultParameterValue = 0;
/**
* Does this control word use the default value?
* @since 2.0.8
*/
protected bool passDefaultParameterValue = false;
/**
* Control Word type. Destination, toggle, value, etc.
* @since 2.0.8
*/
protected int ctrlWordType = RtfCtrlWordType.UNIDENTIFIED;
/**
* Class, property, etc.
* @since 2.0.8
*/
protected String specialHandler = "";
/**
* What version of the RTF spec the control word was introduced.
* @since 2.0.8
*/
protected float rtfVersionSupported = -1.0f; // -1.0 unknown. Each class should override this as implemented.
/**
* The control word as parsed by the parser.
* @since 2.0.8
*/
protected RtfCtrlWordData ctrlWordData = null;
/**
* String containing the value of "{" or "" (blank) depending on if this is the
* first control word in a group.
* @since 2.0.8
*/
protected String groupPrefix = "";
/**
* The prefix for all control words.
* @since 2.0.8
*/
protected String ctrlWordPrefix = "\\";
/**
* The prefix for all control words.
* @since 2.0.8
*/
protected String ctrlWordSuffix = " ";
/**
* Constructor:
*
* @param rtfParser
* The parser for this control word.
* @param ctrlWord
* The string value of this control word.
* @param defaultParameterValue
* The default value of this control word. Not all control words have values.
* @param passDefaultParameterValue
* Flag indicating if this control word should use the default value.
* @param ctrlWordType
* Indicator of the type of control word this is. DESTINATION|DESTINATION_EX|VALUE|FLAG|TOGGLE|SYMBOL
* @param prefix
* String to prefix the ctrl word with. "\" or "\*\" are the 2 used values.
* @param suffix
* String to add as suffix to the ctrl word. " " and "" are the 2 used values.
* @param specialHandler
* If TOGGLE then the property name as String (propertyGroup.propertyName format ex. "character.bold")
* If FLAG then the property name as String (propertyGroup.propertyName format ex. "character.bold")
* If VALUE then the property name as String (propertyGroup.propertyName format ex. "character.bold")
* If SYMBOL then the character to use for substitution as String
* If DESTINATION|DESTINATION_EX then the RtfDestination class name as String
*
* @since 2.0.8
*/
public RtfCtrlWordHandler(RtfParser rtfParser, String ctrlWord, int defaultParameterValue, bool passDefaultParameterValue,
int ctrlWordType, String prefix, String suffix, String specialHandler) {
this.rtfParser = rtfParser;
this.ctrlWord = ctrlWord;
this.defaultParameterValue = defaultParameterValue;
this.passDefaultParameterValue = passDefaultParameterValue;
this.ctrlWordType = ctrlWordType;
this.ctrlWordPrefix = prefix;
this.ctrlWordSuffix = suffix;
this.specialHandler = specialHandler;
if (this.ctrlWordType == RtfCtrlWordType.DESTINATION || this.ctrlWordType == RtfCtrlWordType.DESTINATION_EX){
if (this.specialHandler == null) {
this.specialHandler = "RtfDestinationNull";
}
String arg1 = ""; // stylesheet value - S, CS, TS
RtfDestinationMgr.AddDestination(this.ctrlWord, new Object[] { this.specialHandler, arg1 });
} else {
if (this.ctrlWordType == RtfCtrlWordType.SYMBOL){
} else {
if (this.specialHandler == null) {
this.specialHandler = this.ctrlWord; // if null, make the property the name of the ctrl word
} else {
if (this.specialHandler.Length > 1 && this.specialHandler.EndsWith(".")) {
this.specialHandler += this.ctrlWord; // if string length>1 and ends with a period, it's a group. Add ctrlWord
}
}
}
}
}
/**
* The primary control word handler method.
* Called by the parser once it has a control word and parameter if applicable.
*
* @param ctrlWordDataIn
* The control word and associated parameter if applicable.
* @return
* <code>true</code> or <code>false</code> if the control word was handled.
* @since 2.0.8
*/
public bool HandleControlword(RtfCtrlWordData ctrlWordDataIn){
bool result = false;
this.ctrlWordData = ctrlWordDataIn;
RtfDestination dest = null;
bool handled = false;
this.ctrlWordData.prefix = this.ctrlWordPrefix;
this.ctrlWordData.suffix = this.ctrlWordSuffix;
this.ctrlWordData.newGroup = this.rtfParser.GetState().newGroup;
this.ctrlWordData.ctrlWordType = this.ctrlWordType;
this.ctrlWordData.specialHandler = this.specialHandler;
if (!this.ctrlWordData.hasParam && this.passDefaultParameterValue) {
this.ctrlWordData.hasParam = true;
this.ctrlWordData.param = this.defaultParameterValue.ToString();
}
if (debug) {
PrintDebug("handleKeyword: [" + this.ctrlWordData.ctrlWord + "] param=" + ctrlWordDataIn.param);
RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel()+1, "RtfCtrlWordHandler debug Start: " + this.ctrlWordData.ctrlWord + " ");
}
if (this.ctrlWordData.ctrlWord.Equals("*")) {
return true;
}
if (!BeforeControlWord()) {
return true;
}
switch (this.ctrlWordType) {
case RtfCtrlWordType.FLAG:
case RtfCtrlWordType.TOGGLE:
case RtfCtrlWordType.VALUE:
dest = (RtfDestination)this.rtfParser.GetCurrentDestination();
if (dest != null) {
handled = dest.HandleControlWord(this.ctrlWordData);
}
break;
case RtfCtrlWordType.SYMBOL:
dest = (RtfDestination)this.rtfParser.GetCurrentDestination();
if (dest != null) {
String data = null;
// if doing an import, then put the control word in the output stream through the character handler
if (this.rtfParser.IsImport()) {
data = this.ctrlWordPrefix + this.ctrlWordData.ctrlWord + this.ctrlWordSuffix;
}
if (this.rtfParser.IsConvert()) {
data = this.specialHandler;
}
// If there is a substitute character, process the character.
// If no substitute character, then provide special handling in the destination for the ctrl word.
if (data != null) {
foreach (char cc in data.ToCharArray()) {
handled = dest.HandleCharacter((int)cc);
}
} else {
handled = dest.HandleControlWord(this.ctrlWordData);
}
}
break;
case RtfCtrlWordType.DESTINATION_EX:
case RtfCtrlWordType.DESTINATION:
// set the destination
int x=0;
if(this.ctrlWord == "shppict" || this.ctrlWord == "nonshppict") {
x++;
}
handled = this.rtfParser.SetCurrentDestination(this.ctrlWord);
// let destination handle the ctrl word now.
dest = (RtfDestination)this.rtfParser.GetCurrentDestination();
if(dest != null) {
if(dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT) {
handled = dest.HandleControlWord(this.ctrlWordData);
}
else {
this.rtfParser.SetTokeniserState(dest.GetNewTokeniserState());
}
}
break;
}
AfterControlWord();
if (debug) {
RtfParser.OutputDebug(this.rtfParser.GetRtfDocument(), this.rtfParser.GetLevel()+1, "RtfCtrlWordHandler debug End: " + this.ctrlWordData.ctrlWord + " ");
}
return result;
}
/**
* Pre-processing before the control word.
*
* If return value is true, no further processing will be performed on
* this control word.
*
* @return <code>false</code> = stop processing, <code>true</code> = continue processing
* @since 2.0.8
*/
//Primary purpose is for \* control word and event handling.
protected bool BeforeControlWord() {
if (debug) PrintDebug("beforeControlWord");
// TODO: This is where events would be triggered
return true;
}
/**
* Handle the control word.
*
* @return <code>true</code> if control word was handled, <code>false</code> if it was not handled.
* @since 2.0.8
*/
protected bool OnControlWord() {
if (debug) PrintDebug("onCtrlWord");
// TODO: This is where events would be triggered
return false;
}
/**
* Post-processing after the control word.
*
* @return <code>false</code> = stop processing, <code>true</code> = continue processing
* @since 2.0.8
*/
protected bool AfterControlWord() {
if (debug) PrintDebug("afterControlWord");
// TODO: This is where events would be triggered
return true;
}
// public String CtrlWordString() {
// //String out = ctrlWordPrefix + this.ctrlWord;
// String out = "";
// if (this.bExtendedDestination) {
// out += "\\*";
// }
// out = ctrlWordPrefix + this.ctrlWordData.ctrlWord;
// if (this.ctrlWordData.hasParam) {
// if (this.ctrlWordData.isNeg) out += "-";
// out += this.ctrlWordData.param;
// } else {
// if (this.passDefaultParameterValue == true) {
// out += Integer.ToString(this.defaultParameterValue);
// }
// }
// out += this.ctrlWordSuffix;
// return out;
// }
/**
* Debug function to print class/method
* @param txt The <code>String</code> to output.
* @since 2.0.8
*/
private void PrintDebug(String txt) {
Console.Out.WriteLine(this.GetType().Name + " : " + txt);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,204 @@
using System;
using System.Collections;
using iTextSharp.text.rtf.parser;
/*
* $Id: RtfCtrlWordMgr.cs,v 1.2 2008/05/13 11:25:59 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.ctrlwords {
/**
* <code>RtfCtrlWordMgr</code> handles the dispatching of control words from
* the table of known control words.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public sealed class RtfCtrlWordMgr {
public static bool debug = false;
public static bool debugFound = false;
public static bool debugNotFound = true;
private PushbackStream reader = null;
private RtfParser rtfParser = null;
private RtfCtrlWordMap ctrlWordMap = null;
/** The <code>RtfCtrlWordListener</code>. */
private ArrayList listeners = new ArrayList();
// // TIMING DEBUG INFO
// private long endTime = 0;
// private Date endDate = null;
// private long endFree = 0;
// private DecimalFormat df = new DecimalFormat("#,##0");
// private Date startDate = new Date();
// private long startTime = System.CurrentTimeMillis();
// private long startFree = Runtime.GetRuntime().FreeMemory();
/**
* Constructor
* @param rtfParser The parser object this manager works with.
* @param reader the PushbackReader from the tokeniser.
*/
public RtfCtrlWordMgr(RtfParser rtfParser, PushbackStream reader) {
this.rtfParser = rtfParser; // set the parser
this.reader = reader; // set the reader value
ctrlWordMap = new RtfCtrlWordMap(rtfParser);
// // TIMING DEBUG INFO
// endFree = Runtime.GetRuntime().FreeMemory();
// endTime = System.CurrentTimeMillis();
// endDate = new Date();
// Console.Out.WriteLine("RtfCtrlWordMgr start date: " + startDate.ToLocaleString());
// Console.Out.WriteLine("RtfCtrlWordMgr end date : " + endDate.ToLocaleString());
// Console.Out.WriteLine(" Elapsed time : " + Long.ToString(endTime - startTime) + " milliseconds.");
// Console.Out.WriteLine("Begin Constructor RtfCtrlWordMgr , free mem is " + df.Format(startFree / 1024) + "k");
// Console.Out.WriteLine("End Constructor RtfCtrlWordMgr , free mem is " + df.Format(endFree / 1024) + "k");
// Console.Out.WriteLine("RtfCtrlWordMgr used approximately " + df.Format((startFree - endFree) / 1024) + "k");
}
/**
* Internal to control word manager class.
*
* @param ctrlWordData The <code>RtfCtrlWordData</code> object with control word and param
* @param groupLevel The current document group parsing level
* @return errOK if ok, otherwise an error code.
*/
public int HandleKeyword(RtfCtrlWordData ctrlWordData, int groupLevel) {
//TODO: May be used for event handling.
int result = RtfParser.errOK;
// Call before handler event here
BeforeCtrlWord(ctrlWordData);
result = DispatchKeyword(ctrlWordData, groupLevel);
// call after handler event here
AfterCtrlWord(ctrlWordData);
return result;
}
/**
* Dispatch the token to the correct control word handling object.
*
* @param ctrlWordData The <code>RtfCtrlWordData</code> object with control word and param
* @param groupLevel The current document group parsing level
* @return errOK if ok, otherwise an error code.
*/
private int DispatchKeyword(RtfCtrlWordData ctrlWordData, int groupLevel) {
int result = RtfParser.errOK;
if (ctrlWordData != null) {
RtfCtrlWordHandler ctrlWord = ctrlWordMap.GetCtrlWordHandler(ctrlWordData.ctrlWord);
if (ctrlWord != null) {
ctrlWord.HandleControlword(ctrlWordData);
if (debug && debugFound) {
Console.Out.WriteLine("Keyword found:" +
" New:" + ctrlWordData.ctrlWord +
" Param:" + ctrlWordData.param +
" bParam=" + ctrlWordData.hasParam.ToString());
}
} else {
result = RtfParser.errCtrlWordNotFound;
//result = RtfParser2.errAssertion;
if (debug && debugNotFound) {
Console.Out.WriteLine("Keyword unknown:" +
" New:" + ctrlWordData.ctrlWord +
" Param:" + ctrlWordData.param +
" bParam=" + ctrlWordData.hasParam.ToString());
}
}
}
return result;
}
// listener methods
/**
* Adds a <CODE>RtfCtrlWordListener</CODE> to the <CODE>RtfCtrlWordMgr</CODE>.
*
* @param listener
* the new RtfCtrlWordListener.
*/
public void AddRtfCtrlWordListener(IRtfCtrlWordListener listener) {
listeners.Add(listener);
}
/**
* Removes a <CODE>RtfCtrlWordListener</CODE> from the <CODE>RtfCtrlWordMgr</CODE>.
*
* @param listener
* the RtfCtrlWordListener that has to be removed.
*/
public void RemoveRtfCtrlWordListener(IRtfCtrlWordListener listener) {
listeners.Remove(listener);
}
private bool BeforeCtrlWord(RtfCtrlWordData ctrlWordData) {
foreach (IRtfCtrlWordListener listener in listeners) {
listener.BeforeCtrlWord(ctrlWordData);
}
return true;
}
private bool OnCtrlWord(RtfCtrlWordData ctrlWordData) {
foreach (IRtfCtrlWordListener listener in listeners) {
listener.OnCtrlWord(ctrlWordData);
}
return true;
}
private bool AfterCtrlWord(RtfCtrlWordData ctrlWordData) {
foreach (IRtfCtrlWordListener listener in listeners) {
listener.AfterCtrlWord(ctrlWordData);
}
return true;
}
}
}

View File

@@ -0,0 +1,97 @@
using System;
/* $Id: RtfCtrlWordType.cs,v 1.2 2008/05/13 11:25:59 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.ctrlwords {
/**
* <code>RtfCtrlWordType</code> indicates the type of control word.
*
* RTF control words are divided up into:
* Destination, Flag, Value, Toggle, Symbol.
*
* Destination: The current destination for values and text to be sent.
* Flag: 0/1 value types. Represents true/false, on/off value types.
* Toggle: Flips a Flag value on/off.
* Value: an Integer value data type. (Exception: Some control words this is a long data value type)
* Symbol: Special RTF characters such as \{, \} and others.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public sealed class RtfCtrlWordType {
/**
* Control word is unidentified.
*/
public const int UNIDENTIFIED = -1;
/**
* Control word is a destination.
*/
public const int DESTINATION = 0;
/**
* Control word is a newer destination.
*/
public const int DESTINATION_EX = 1;
/**
* Control word is a flag.
*/
public const int FLAG = 2;
/**
* Control word is a value.
*/
public const int VALUE = 3;
/**
* Control word is a flag toggle.
*/
public const int TOGGLE = 4;
/**
* Control word is a special symbol.
*/
public const int SYMBOL = 5;
}
}

View File

@@ -0,0 +1,98 @@
using System;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: IRtfDestinationListener.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationListener</code> interface for handling events.
*
* @author Howard Shank (hgshank@yahoo.com)
*
* @since 2.0.8
*/
public interface IRtfDestinationListener : IEventListener {
/**
*
*/
RtfCtrlWordData BeforeCtrlWord(RtfCtrlWordData ctrlWordData);
/**
*
*/
RtfCtrlWordData OnCtrlWord(RtfCtrlWordData ctrlWordData);
/**
*
*/
RtfCtrlWordData AfterCtrlWord(RtfCtrlWordData ctrlWordData);
/**
*
*/
int BeforeCharacter(int ch);
/**
*
*/
int OnCharacter(int ch);
/**
*
*/
int AfterCharacter(int ch);
/**
*
* @return
*/
bool OnOpenGroup();
/**
*
* @return
*/
bool OnCloseGroup();
}
}

View File

@@ -0,0 +1,254 @@
using System;
using System.Collections;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestination.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestination</code> is the base class for destinations according
* to the RTF Specification. All destinations must extend from this class.
*
* @author Howard Shank (hgshank@yahoo.com
*
* @since 2.0.8
*/
public abstract class RtfDestination {
/** Parser object */
protected RtfParser rtfParser = null;
/** Is data in destination modified? */
protected bool modified = false;
/** The last control word handled by this destination */
protected RtfCtrlWordData lastCtrlWord = null;
/** The <code>RtfDestinationListener</code>. */
private static ArrayList listeners = new ArrayList();
/**
* Constructor.
*/
public RtfDestination() {
rtfParser = null;
}
/**
* Constructor
* @param parser <code>RtfParser</code> object.
*/
public RtfDestination(RtfParser parser) {
this.rtfParser = parser;
}
/**
* Set the parser to use with the RtfDestination object.
*
* @param parser The RtfParser object.
*/
public virtual void SetParser(RtfParser parser) {
if (this.rtfParser != null && this.rtfParser.Equals(parser)) return;
this.rtfParser = parser;
}
/**
* Clean up when destination is closed.
* @return true if handled, false if not handled
*/
public abstract bool CloseDestination();
/**
* Handle a new subgroup contained within this group
* @return true if handled, false if not handled
*/
public abstract bool HandleOpeningSubGroup();
/**
* Clean up when group is closed.
* @return true if handled, false if not handled
*/
public abstract bool HandleCloseGroup();
/**
* Setup when group is opened.
* @return true if handled, false if not handled
*/
public abstract bool HandleOpenGroup();
/**
* Handle text for this destination
* @return true if handled, false if not handled
*/
public abstract bool HandleCharacter(int ch);
/**
* Handle control word for this destination
* @param ctrlWordData The control word and parameter information object
* @return true if handled, false if not handled
*/
public abstract bool HandleControlWord(RtfCtrlWordData ctrlWordData);
/**
* Method to set this object to the default values. Must be implemented in child class.
*/
public abstract void SetToDefaults();
/**
* Method to indicate if data in this destination has changed.
* @return true if modified, false if not modified.
*/
public bool IsModified() {
return modified;
}
// listener methods
/**
* Adds a <CODE>RtfDestinationListener</CODE> to the <CODE>RtfDestinationMgr</CODE>.
*
* @param listener
* the new RtfDestinationListener.
*/
public bool AddListener(IRtfDestinationListener listener) {
listeners.Add(listener);
return true;
}
/**
* Removes a <CODE>RtfDestinationListener</CODE> from the <CODE>RtfDestinationMgr</CODE>.
*
* @param listener
* the RtfCtrlWordListener that has to be removed.
*/
public bool RemoveListener(IRtfDestinationListener listener) {
int i = listeners.IndexOf(listener);
if (i >= 0) {
listeners.RemoveAt(i);
return true;
}
return false;
}
protected RtfCtrlWordData BeforeCtrlWord(RtfCtrlWordData ctrlWordData) {
foreach (IRtfDestinationListener listener in listeners) {
listener.BeforeCtrlWord(ctrlWordData);
}
return null;
}
/**
*
*/
protected RtfCtrlWordData OnCtrlWord(RtfCtrlWordData ctrlWordData){
foreach (IRtfDestinationListener listener in listeners) {
listener.OnCtrlWord(ctrlWordData);
}
return null;
}
/**
*
*/
protected RtfCtrlWordData AfterCtrlWord(RtfCtrlWordData ctrlWordData){
foreach (IRtfDestinationListener listener in listeners) {
listener.AfterCtrlWord(ctrlWordData);
}
return null;
}
/**
*
*/
protected int BeforeCharacter(int ch){
foreach (IRtfDestinationListener listener in listeners) {
listener.BeforeCharacter(ch);
}
return 0;
}
/**
*
*/
protected int OnCharacter(int ch){
foreach (IRtfDestinationListener listener in listeners) {
listener.OnCharacter(ch);
}
return 0;
}
/**
*
*/
protected int AfterCharacter(int ch){
foreach (IRtfDestinationListener listener in listeners) {
listener.AfterCharacter(ch);
}
return 0;
}
/**
*
* @return
*/
protected bool OnOpenGroup(){
foreach (IRtfDestinationListener listener in listeners) {
listener.OnOpenGroup();
}
return true;
}
/**
*
* @return
*/
protected bool OnCloseGroup(){
foreach (IRtfDestinationListener listener in listeners) {
listener.OnCloseGroup();
}
return true;
}
public virtual int GetNewTokeniserState() {
return RtfParser.TOKENISER_IGNORE_RESULT;
}
}
}

View File

@@ -0,0 +1,317 @@
using System;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
using iTextSharp.text.rtf.parser.enumerations;
/*
* $Id: RtfDestinationColorTable.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationColorTable</code> handles data destined for the color table destination
*
* @author Howard Shank (hgshank@yahoo.com)
*
* @since 2.0.8
*/
public class RtfDestinationColorTable : RtfDestination {
/**
* The RtfImportHeader to add color mappings to.
*/
private RtfImportMgr importHeader = null;
/**
* The number of the current color being parsed.
*/
private int colorNr = 0;
/**
* The red component of the current color being parsed.
*/
private int red = -1;
/**
* The green component of the current color being parsed.
*/
private int green = -1;
/**
* The blue component of the current color being parsed.
*/
private int blue = -1;
/*
* Color themes - Introduced Word 2007
*/
/**
* Specifies the tint when specifying a theme color.
* RTF control word ctint
*
* 0 - 255: 0 = full Tint(white), 255 = no tint.
* Default value: 255
*
* If tint is specified and is less than 255, cshade must equal 255.
* ctint/cshade are mutually exclusive
*
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#cshade
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#themeColor
*/
private int ctint = 255;
/**
* Specifies the shade when specifying a theme color.
* RTF control word cshade
*
* 0 - 255: 0 = full Shade(black), 255 = no shade.
* Default value: 255
*
* If shade is specified and is less than 255, ctint must equal 255.
* cshade/ctint are mutually exclusive
*
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#ctint
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#themeColor
*/
private int cshade = 255;
/**
* Specifies the use of a theme color.
*
* @see com.lowagie.text.rtf.parser.enumerations.RtfColorThemes
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#ctint
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#cshade
*/
private int themeColor = RtfColorThemes.THEME_UNDEFINED;
/**
* Color map object for conversions
*/
private Hashtable colorMap = null;
/**
* Constructor.
*/
public RtfDestinationColorTable() : base(null) {
colorMap = new Hashtable();
this.colorNr = 0;
}
/**
* Constructs a new RtfColorTableParser.
*
* @param importHeader The RtfImportHeader to add the color mappings to.
*/
public RtfDestinationColorTable(RtfParser parser) : base(parser) {
colorMap = new Hashtable();
this.colorNr = 0;
this.importHeader = parser.GetImportManager();
this.SetToDefaults();
}
public override void SetParser(RtfParser parser) {
this.rtfParser = parser;
colorMap = new Hashtable();
this.colorNr = 0;
this.importHeader = parser.GetImportManager();
this.SetToDefaults();
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
return true;
}
public override bool CloseDestination() {
return true;
}
public override bool HandleCloseGroup() {
ProcessColor();
return true;
}
public override bool HandleOpenGroup() {
return true;
}
public override bool HandleCharacter(int ch) {
// color elements end with a semicolon (;)
if ((char)ch == ';') {
this.ProcessColor();
}
return true;
}
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
if (ctrlWordData.ctrlWord.Equals("blue")) this.SetBlue(ctrlWordData.IntValue());
if (ctrlWordData.ctrlWord.Equals("red")) this.SetRed(ctrlWordData.IntValue());
if (ctrlWordData.ctrlWord.Equals("green")) this.SetGreen(ctrlWordData.IntValue());
if (ctrlWordData.ctrlWord.Equals("cshade")) this.SetShade(ctrlWordData.IntValue());
if (ctrlWordData.ctrlWord.Equals("ctint")) this.SetTint(ctrlWordData.IntValue());
//if(ctrlWordData.ctrlWord.Equals("cmaindarkone")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("cmainlightone")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("cmaindarktwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("cmainlighttwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("caccentone")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("caccenttwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("caccentthree")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("caccentfour")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("caccentfive")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("caccentsix")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("chyperlink")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("cfollowedhyperlink")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("cbackgroundone")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("ctextone")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("cbacgroundtwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
//if(ctrlWordData.ctrlWord.Equals("ctexttwo")) this.SetThemeColor(ctrlWordData.ctrlWord);
return true;
}
/**
* Set default values.
*/
public override void SetToDefaults() {
this.red = -1;
this.green = -1;
this.blue = -1;
this.ctint = 255;
this.cshade = 255;
this.themeColor = RtfColorThemes.THEME_UNDEFINED;
// do not reset colorNr
}
/**
* Processes the color triplet parsed from the document.
* Add it to the import mapping so colors can be mapped when encountered
* in the RTF import or conversion.
*/
private void ProcessColor() {
if (red != -1 && green != -1 && blue != -1) {
if (this.rtfParser.IsImport()) {
this.importHeader.ImportColor(this.colorNr.ToString(), new Color(this.red, this.green, this.blue));
}
if (this.rtfParser.IsConvert()) {
colorMap[this.colorNr.ToString()] = new Color(this.red, this.green, this.blue);
}
}
this.SetToDefaults();
this.colorNr++;
}
/**
* Set the red color to value.
* @param value Value to set red to.
*/
private void SetRed(int value) {
if (value >= 0 && value <= 255) {
this.red = value;
}
}
/**
* Set the green color value.
* @param value Value to set green to.
*/
private void SetGreen(int value) {
if (value >= 0 && value <= 255) {
this.green = value;
}
}
/**
* Set the blue color value.
* @param value Value to set blue to.
*/
private void SetBlue(int value) {
if (value >= 0 && value <= 255) {
this.blue = value;
}
}
/**
* Set the tint value
* @param value Value to set the tint to
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#ctint
*/
private void SetTint(int value) {
if (value >= 0 && value <= 255) {
this.ctint = value;
if (value >= 0 && value <255) {
this.cshade = 255;
}
}
}
/**
* Set the shade value
* @param value Value to set the shade to
* @see com.lowagie.text.rtf.parser.destinations.RtfDestinationColorTable#cshade
*/
private void SetShade(int value) {
if (value >= 0 && value <= 255) {
this.cshade = value;
if (value >= 0 && value <255) {
this.ctint = 255;
}
}
}
/**
* Set the theme color value.
* @param value Value to set the theme color to
* @see com.lowagie.text.rtf.parser.enumerations.RtfColorThemes
*/
private void SetThemeColor(int value) {
if (value >= RtfColorThemes.THEME_UNDEFINED && value <= RtfColorThemes.THEME_MAX) {
this.themeColor = value;
} else {
this.themeColor = RtfColorThemes.THEME_UNDEFINED;
}
}
// conversion functions
/**
* Get the <code>Color</code> object that is mapped to the key.
* @param key The map number.
* *@return <code>Color</code> object from the map. null if key does not exist.
*/
public Color GetColor(String key) {
return (Color)colorMap[key];
}
}
}

View File

@@ -0,0 +1,592 @@
using System;
using System.Collections;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.direct;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
using iTextSharp.text.rtf.parser.properties;
/*
* $Id: RtfDestinationDocument.cs,v 1.4 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationDocument</code> handles data destined for the document destination
*
* @author Howard Shank (hgshank@yahoo.com)
*
*/
public sealed class RtfDestinationDocument : RtfDestination, IRtfPropertyListener {
/**
* The RtfDocument object.
*
* @see com.lowagie.text.rtf.document.RtfDocument
*/
private RtfDocument rtfDoc = null;
/**
* The iText Document object.
*
* @see com.lowagie.text.Document
*/
private Document doc = null;
private StringBuilder buffer = null;
/**
* Indicates the parser action. Import or Conversion.
*
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_UNIDENTIFIED
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_CONVERT
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_IMPORT_FRAGMENT
* @see com.lowagie.text.rtf.direct.RtfParser#TYPE_IMPORT_FULL
*/
private int conversionType = 0;
/**
* Indicates the current table level being processed
*/
private int tableLevel = 0;
private static ArrayList IMPORT_IGNORED_CTRLWORDS = new ArrayList(new string[]{
"rtf",
"ansicpg",
"deff",
"ansi",
"mac",
"pca",
"pc",
"stshfdbch",
"stshfloch",
"stshfhich",
"stshfbi",
"deflang",
"deflangfe",
"adeflang",
"adeflangfe"
}
);
private static ArrayList CONVERT_IGNORED_CTRLWORDS = new ArrayList(new string[]{"rtf"});
private Paragraph iTextParagraph = null;
public RtfDestinationDocument() : base(null) {
}
/**
* Constructs a new <code>RtfDestinationDocument</code> using
* the parameters to initialize the object.
* @param rtfDoc The <code>RtfDocument</code> this works with.
* @param doc The iText <code>Document</code> this works with.
* @param type The type of conversion being done.
*/
public RtfDestinationDocument(RtfParser parser) : base (parser){
this.rtfDoc = parser.GetRtfDocument();
this.doc = parser.GetDocument();
this.conversionType = parser.GetConversionType();
SetToDefaults();
if (this.rtfParser.IsConvert()) {
this.rtfParser.GetState().properties.AddRtfPropertyListener(this);
}
}
public override void SetParser(RtfParser parser) {
this.rtfParser = parser;
this.rtfDoc = parser.GetRtfDocument();
this.doc = parser.GetDocument();
this.conversionType = parser.GetConversionType();
SetToDefaults();
if (this.rtfParser.IsConvert()) {
this.rtfParser.GetState().properties.AddRtfPropertyListener(this);
}
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*/
public override bool CloseDestination() {
if (this.rtfParser.IsImport()) {
if (this.buffer.Length>0) {
WriteBuffer();
}
}
this.rtfParser.GetState().properties.RemoveRtfPropertyListener(this);
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*/
public override bool HandleOpenGroup() {
this.OnOpenGroup(); // event handler
if (this.rtfParser.IsImport()) {
}
if (this.rtfParser.IsConvert()) {
if (this.iTextParagraph == null) this.iTextParagraph = new Paragraph();
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
if (this.rtfParser.IsImport()) {
if (this.buffer.Length>0) {
WriteBuffer();
}
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*/
public override bool HandleCloseGroup() {
this.OnCloseGroup(); // event handler
if (this.rtfParser.IsImport()) {
if (this.buffer.Length>0) {
WriteBuffer();
}
WriteText("}");
}
if (this.rtfParser.IsConvert()) {
if (this.buffer.Length > 0 && this.iTextParagraph == null) {
this.iTextParagraph = new Paragraph();
}
if (this.buffer.Length > 0 ) {
Chunk chunk = new Chunk();
chunk.Append(this.buffer.ToString());
this.iTextParagraph.Add(chunk);
}
if (this.iTextParagraph != null) {
AddParagraphToDocument();
}
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
*/
public override bool HandleCharacter(int ch) {
bool result = true;
this.OnCharacter(ch); // event handler
if (this.rtfParser.IsImport()) {
if (buffer.Length > 254) {
this.WriteBuffer();
}
buffer.Append((char)ch);
}
if (this.rtfParser.IsConvert()) {
buffer.Append((char)ch);
}
return result;
}
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
bool result = false;
this.OnCtrlWord(ctrlWordData); // event handler
if (this.rtfParser.IsImport()) {
// map font information
if (ctrlWordData.ctrlWord.Equals("f")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapFontNr(ctrlWordData.param);}
// map color information
//colors
if (ctrlWordData.ctrlWord.Equals("cb")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
if (ctrlWordData.ctrlWord.Equals("cf")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
//cells
if (ctrlWordData.ctrlWord.Equals("clcbpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
if (ctrlWordData.ctrlWord.Equals("clcbpatraw")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
if (ctrlWordData.ctrlWord.Equals("clcfpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
if (ctrlWordData.ctrlWord.Equals("clcfpatraw")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
//table rows
if (ctrlWordData.ctrlWord.Equals("trcfpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
if (ctrlWordData.ctrlWord.Equals("trcbpat")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
//paragraph border
if (ctrlWordData.ctrlWord.Equals("brdrcf")) { ctrlWordData.param = this.rtfParser.GetImportManager().MapColorNr(ctrlWordData.param);}
}
if (this.rtfParser.IsConvert()) {
if (ctrlWordData.ctrlWord.Equals("par")) { AddParagraphToDocument(); }
// Set Font
if (ctrlWordData.ctrlWord.Equals("f")) {}
// color information
//colors
if (ctrlWordData.ctrlWord.Equals("cb")) {}
if (ctrlWordData.ctrlWord.Equals("cf")) {}
//cells
if (ctrlWordData.ctrlWord.Equals("clcbpat")) {}
if (ctrlWordData.ctrlWord.Equals("clcbpatraw")) {}
if (ctrlWordData.ctrlWord.Equals("clcfpat")) {}
if (ctrlWordData.ctrlWord.Equals("clcfpatraw")) {}
//table rows
if (ctrlWordData.ctrlWord.Equals("trcfpat")) {}
if (ctrlWordData.ctrlWord.Equals("trcbpat")) {}
//paragraph border
if (ctrlWordData.ctrlWord.Equals("brdrcf")) {}
/* TABLES */
if (ctrlWordData.ctrlWord.Equals("trowd")) /*Beginning of row*/ { tableLevel++;}
if (ctrlWordData.ctrlWord.Equals("cell")) /*End of Cell Denotes the end of a table cell*/ {
// String ctl = ctrlWordData.ctrlWord;
// System.out.Print("cell found");
}
if (ctrlWordData.ctrlWord.Equals("row")) /*End of row*/ { tableLevel++;}
if (ctrlWordData.ctrlWord.Equals("lastrow")) /*Last row of the table*/ {}
if (ctrlWordData.ctrlWord.Equals("row")) /*End of row*/ { tableLevel++;}
if (ctrlWordData.ctrlWord.Equals("irow")) /*param is the row index of this row.*/ {}
if (ctrlWordData.ctrlWord.Equals("irowband")) /*param is the row index of the row, adjusted to account for header rows. A header row has a value of -1.*/ {}
if (ctrlWordData.ctrlWord.Equals("tcelld")) /*Sets table cell defaults*/ {}
if (ctrlWordData.ctrlWord.Equals("nestcell")) /*Denotes the end of a nested cell.*/ {}
if (ctrlWordData.ctrlWord.Equals("nestrow")) /*Denotes the end of a nested row*/ {}
if (ctrlWordData.ctrlWord.Equals("nesttableprops")) /*Defines the properties of a nested table. This is a destination control word*/ {}
if (ctrlWordData.ctrlWord.Equals("nonesttables")) /*Contains text for readers that do not understand nested tables. This destination should be ignored by readers that support nested tables.*/ {}
if (ctrlWordData.ctrlWord.Equals("trgaph")) /*Half the space between the cells of a table row in twips.*/ {}
if (ctrlWordData.ctrlWord.Equals("cellx")) /*param Defines the right boundary of a table cell, including its half of the space between cells.*/ {}
if (ctrlWordData.ctrlWord.Equals("clmgf")) /*The first cell in a range of table cells to be merged.*/ {}
if (ctrlWordData.ctrlWord.Equals("clmrg")) /*Contents of the table cell are merged with those of the preceding cell*/ {}
if (ctrlWordData.ctrlWord.Equals("clvmgf")) /*The first cell in a range of table cells to be vertically merged.*/ {}
if (ctrlWordData.ctrlWord.Equals("clvmrg")) /*Contents of the table cell are vertically merged with those of the preceding cell*/ {}
/* TABLE: table row revision tracking */
if (ctrlWordData.ctrlWord.Equals("trauth")) /*With revision tracking enabled, this control word identifies the author of changes to a table row's properties. N refers to a value in the revision table*/ {}
if (ctrlWordData.ctrlWord.Equals("trdate")) /*With revision tracking enabled, this control word identifies the date of a revision*/ {}
/* TABLE: Autoformatting flags */
if (ctrlWordData.ctrlWord.Equals("tbllkborder")) /*Flag sets table autoformat to format borders*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllkshading")) /*Flag sets table autoformat to affect shading.*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllkfont")) /*Flag sets table autoformat to affect font*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllkcolor")) /*Flag sets table autoformat to affect color*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllkbestfit")) /*Flag sets table autoformat to apply best fit*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllkhdrrows")) /*Flag sets table autoformat to format the first (header) row*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllklastrow")) /*Flag sets table autoformat to format the last row.*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllkhdrcols")) /*Flag sets table autoformat to format the first (header) column*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllklastcol")) /*Flag sets table autoformat to format the last column*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllknorowband")) /*Specifies row banding conditional formatting shall not be applied*/ {}
if (ctrlWordData.ctrlWord.Equals("tbllknocolband")) /*Specifies column banding conditional formatting shall not be applied.*/ {}
/* TABLE: Row Formatting */
if (ctrlWordData.ctrlWord.Equals("taprtl")) /*Table direction is right to left*/ {}
if (ctrlWordData.ctrlWord.Equals("trautofit")) /*param = AutoFit:
0 No AutoFit (default).
1 AutoFit is on for the row. Overridden by \clwWidthN and \trwWidthN in any table row.
*/ {}
if (ctrlWordData.ctrlWord.Equals("trhdr")) /*Table row header. This row should appear at the top of every page on which the current table appears*/ {}
if (ctrlWordData.ctrlWord.Equals("trkeep")) /*Keep table row together. This row cannot be split by a page break. This property is assumed to be off unless the control word is present*/ {}
if (ctrlWordData.ctrlWord.Equals("trkeepfollow")) /*Keep row in the same page as the following row.*/ {}
if (ctrlWordData.ctrlWord.Equals("trleft")) /*Position in twips of the leftmost edge of the table with respect to the left edge of its column.*/ {}
if (ctrlWordData.ctrlWord.Equals("trqc")) /*Centers a table row with respect to its containing column.*/ {}
if (ctrlWordData.ctrlWord.Equals("trql")) /*Left-justifies a table row with respect to its containing column.*/ {}
if (ctrlWordData.ctrlWord.Equals("trqr")) /*Right-justifies a table row with respect to its containing column*/ {}
if (ctrlWordData.ctrlWord.Equals("trrh")) /*Height of a table row in twips. When 0, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line*/ {}
if (ctrlWordData.ctrlWord.Equals("trpaddb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddt")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddfb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddfl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddfr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpaddft")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdt")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdfl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdft")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdfb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trspdfr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trwWidth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trftsWidth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trwWidthB")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trftsWidthB")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trftsWidthB")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trwWidthA")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trftsWidthA")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tblind")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tblindtype")) /* */ {}
/*TABLE: Row shading and Background Colors*/
if (ctrlWordData.ctrlWord.Equals("trcbpat")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trcfpat")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trpat")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trshdng")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgbdiag")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgcross")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdcross")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdkbdiag")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdkcross")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdkdcross")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdkfdiag")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdkhor")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgdkvert")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgfdiag")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbghoriz")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbgvert")) /* */ {}
/* TABLE: Cell Formatting*/
if (ctrlWordData.ctrlWord.Equals("clFitText")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clNoWrap")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadt")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadfl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadft")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadfb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clpadfr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clwWidth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clftsWidth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clhidemark")) /* */ {}
/* TABLE: Compared Table Cells */
if (ctrlWordData.ctrlWord.Equals("clins")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("cldel")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clmrgd")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clmrgdr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clsplit")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clsplitr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clinsauth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clinsdttm")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("cldelauth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("cldeldttm")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clmrgdauth")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clmrgddttm")) /* */ {}
/*TABLE: Position Wrapped Tables (The following properties must be the same for all rows in the table.)*/
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtLeft")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtRight")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtTop")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tdfrmtxtBottom")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tabsnoovrlp")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tphcol")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tphmrg")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tphpg")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposnegx")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposnegy")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposx")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposxc")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposxi")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposxl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposxo")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposxr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposy")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposyb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposyc")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposyil")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposyin")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposyout")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tposyt")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tpvmrg")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tpvpara")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("tpvpg")) /* */ {}
/* TABLE: Bidirectional Controls */
if (ctrlWordData.ctrlWord.Equals("rtlrow")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("ltrrow")) /* */ {}
/* TABLE: Row Borders */
if (ctrlWordData.ctrlWord.Equals("trbrdrt")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbrdrl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbrdrb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbrdrr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbrdrh")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("trbrdrv")) /* */ {}
/* TABLE: Cell Borders */
if (ctrlWordData.ctrlWord.Equals("brdrnil")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clbrdrb")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clbrdrt")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clbrdrl")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("clbrdrr")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("cldglu")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("cldgll")) /* */ {}
if (ctrlWordData.ctrlWord.Equals("")) /* */ {}
}
if (ctrlWordData.ctrlWordType == RtfCtrlWordType.TOGGLE) {
this.rtfParser.GetState().properties.ToggleProperty(ctrlWordData);//ctrlWordData.specialHandler);
}
if (ctrlWordData.ctrlWordType == RtfCtrlWordType.FLAG ||
ctrlWordData.ctrlWordType == RtfCtrlWordType.VALUE) {
this.rtfParser.GetState().properties.SetProperty(ctrlWordData);//ctrlWordData.specialHandler, ctrlWordData.param);
}
switch (conversionType) {
case RtfParser.TYPE_IMPORT_FULL:
if (!IMPORT_IGNORED_CTRLWORDS.Contains(ctrlWordData.ctrlWord)) {
WriteBuffer();
WriteText(ctrlWordData.ToString());
}
result = true;
break;
case RtfParser.TYPE_IMPORT_FRAGMENT:
if (!IMPORT_IGNORED_CTRLWORDS.Contains(ctrlWordData.ctrlWord)) {
WriteBuffer();
WriteText(ctrlWordData.ToString());
}
result = true;
break;
case RtfParser.TYPE_CONVERT:
if (IMPORT_IGNORED_CTRLWORDS.Contains(ctrlWordData.ctrlWord) == false) {
}
result = true;
break;
default: // error because is should be an import or convert
result = false;
break;
}
return result;
}
/**
* Write the accumulated buffer to the destination.
* Used for direct content
*/
private void WriteBuffer() {
WriteText(this.buffer.ToString());
SetToDefaults();
}
/**
* Write the string value to the destiation.
* Used for direct content
* @param value
*/
private void WriteText(String value) {
if (this.rtfParser.IsNewGroup()) {
this.rtfDoc.Add(new RtfDirectContent("{"));
this.rtfParser.SetNewGroup(false);
}
if (value.Length > 0) {
this.rtfDoc.Add(new RtfDirectContent(value));
}
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
*/
public override void SetToDefaults() {
this.buffer = new StringBuilder();
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.properties.RtfPropertyListener#afterChange(java.lang.String)
*/
public void AfterPropertyChange(String propertyName) {
if (propertyName.StartsWith(RtfProperty.CHARACTER)) {
} else {
if (propertyName.StartsWith(RtfProperty.PARAGRAPH)) {
} else {
if (propertyName.StartsWith(RtfProperty.SECTION)) {
} else {
if (propertyName.StartsWith(RtfProperty.DOCUMENT)) {
}
}
}
}
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.properties.RtfPropertyListener#beforeChange(java.lang.String)
*/
public void BeforePropertyChange(String propertyName) {
// do we have any text to do anything with?
// if not, then just return without action.
if (this.buffer.Length == 0) return;
if (propertyName.StartsWith(RtfProperty.CHARACTER)) {
// this is a character change,
// add a new chunck to the current paragraph using current character settings.
Chunk chunk = new Chunk();
chunk.Append(this.buffer.ToString());
this.buffer = new StringBuilder(255);
Hashtable charProperties = this.rtfParser.GetState().properties.GetProperties(RtfProperty.CHARACTER);
String defFont = (String)charProperties[RtfProperty.CHARACTER_FONT];
if (defFont == null) defFont = "0";
RtfDestinationFontTable fontTable = (RtfDestinationFontTable)this.rtfParser.GetDestination("fonttbl");
Font currFont = fontTable.GetFont(defFont);
int fs = Font.NORMAL;
if (charProperties.ContainsKey(RtfProperty.CHARACTER_BOLD)) fs |= Font.BOLD;
if (charProperties.ContainsKey(RtfProperty.CHARACTER_ITALIC)) fs |= Font.ITALIC;
if (charProperties.ContainsKey(RtfProperty.CHARACTER_UNDERLINE)) fs |= Font.UNDERLINE;
Font useFont = FontFactory.GetFont(currFont.Familyname, 12, fs, new Color(0,0,0));
chunk.Font = useFont;
if (iTextParagraph == null) this.iTextParagraph = new Paragraph();
this.iTextParagraph.Add(chunk);
} else {
if (propertyName.StartsWith(RtfProperty.PARAGRAPH)) {
// this is a paragraph change. what do we do?
} else {
if (propertyName.StartsWith(RtfProperty.SECTION)) {
} else {
if (propertyName.StartsWith(RtfProperty.DOCUMENT)) {
}
}
}
}
}
private void AddParagraphToDocument() {
if (this.iTextParagraph != null) {
try {
this.rtfParser.GetDocument().Add(this.iTextParagraph);
} catch {
}
this.iTextParagraph = null;
}
}
}
}

View File

@@ -0,0 +1,600 @@
using System;
using System.Collections;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.rtf.direct;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationFontTable.cs,v 1.4 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationFontTable</code> handles data destined for the font table destination
*
* @author Howard Shank (hgshank@yahoo.com)
*
* @since 2.0.8
*/
public sealed class RtfDestinationFontTable : RtfDestination {
/**
* The RtfImportHeader to add font mappings to.
*/
private RtfImportMgr importHeader = null;
/**
* The theme (Office 2007)
*/
private String themeFont = "";
/**
* The number of the font being parsed.
*/
private String fontNr = "";
/**
* The family of the font being parsed.
*/
private String fontFamily = "";
/**
* The \charset value
*/
private String charset = "";
private const String CHARSET_DEFAULT = "0";
/**
* The \fprq
*/
private int fprq = 0;
/**
* The \*\panose font matching value if primary font is not available.
*/
private String panose = "";
/**
* The \*\fname
*/
//private String nontaggedname = "";
/**
* The name of the font being parsed.
*/
private String fontName = "";
/**
* The \falt alternate font if primary font is not available.
*/
private String falt = "";
/**
* The \falt alternate font if primary font is not available.
*/
//private String fontemb = "";
/**
* The \falt alternate font if primary font is not available.
*/
//private String fontType = "";
/**
* The \falt alternate font if primary font is not available.
*/
//private String fontFile = "";
/**
* The \falt alternate font if primary font is not available.
*/
//private String fontFileCpg = "";
/**
* The \fbias value
*/
private int fbias = 0;
/**
* The \cpg value
*/
private String cpg = "";
/**
* The \fnil, \fttruetype value
*/
private String trueType = "";
/**
* state flag to handle different parsing of a font element
*/
private int state = 0;
/* state values */
/** Normal */
private const int SETTING_NORMAL = 0;
/** \falt */
private const int SETTING_ALTERNATE = 1;
/** \fname */
private const int SETTING_FONTNAME = 2;
/** \panose */
private const int SETTING_PANOSE = 3;
/** \fontemb */
private const int SETTING_FONT_EMBED = 4;
/** \ffile */
private const int SETTING_FONT_FILE = 5;
/**
* Convert font mapping to <code>FontFactory</code> font objects.
*/
private Hashtable fontMap = null;
/**
* Constructor
*/
public RtfDestinationFontTable() : base(null) {
}
/**
* Constructs a new RtfFontTableParser.
*
* @param importHeader The RtfImportHeader to add font mappings to.
*
* @since 2.0.8
*/
public RtfDestinationFontTable(RtfParser parser) : base(parser) {
this.Init(true);
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setParser(com.lowagie.text.rtf.parser.RtfParser)
*
* @since 2.0.8
*/
public override void SetParser(RtfParser parser) {
if (this.rtfParser != null && this.rtfParser.Equals(parser)) return;
this.rtfParser = parser;
this.Init(true);
}
/**
* Initialize the object.
*
* @param importFonts true to import the fonts into the FontFactory, false do not load fonts
*
* @since 2.0.8
*/
private void Init(bool importFonts) {
fontMap = new Hashtable();
if (this.rtfParser != null) {
this.importHeader = this.rtfParser.GetImportManager();
}
this.SetToDefaults();
if (importFonts) {
ImportSystemFonts();
}
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*
* @since 2.0.8
*/
public override bool HandleOpeningSubGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*
* @since 2.0.8
*/
public override bool CloseDestination() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*
* @since 2.0.8
*/
public override bool HandleCloseGroup() {
if (this.state == SETTING_NORMAL) {
ProcessFont();
}
this.state = SETTING_NORMAL;
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*
* @since 2.0.8
*/
public override bool HandleOpenGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(char[])
*
* @since 2.0.8
*/
public override bool HandleCharacter(int ch) {
switch (this.state) {
case SETTING_NORMAL:
this.fontName += (char)ch;
break;
case SETTING_ALTERNATE:
this.falt += (char)ch;
break;
case SETTING_PANOSE:
this.panose += (char)ch;
break;
case SETTING_FONT_EMBED:
break;
case SETTING_FONT_FILE:
break;
case SETTING_FONTNAME:
break;
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleControlWord(com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData)
*
* @since 2.0.8
*/
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
bool result = true;
// just let fonttbl fall through and set last ctrl word object.
if (ctrlWordData.ctrlWord.Equals("f")) { this.SetFontNumber(ctrlWordData.param); result=true;}
if (ctrlWordData.ctrlWord.Equals("fcharset")) { this.SetCharset(ctrlWordData.param); result=true; }
// font families
if (ctrlWordData.ctrlWord.Equals("fnil")) { this.SetFontFamily("roman"); result=true; }
if (ctrlWordData.ctrlWord.Equals("froman")) { this.SetFontFamily("roman"); result=true; }
if (ctrlWordData.ctrlWord.Equals("fswiss")) { this.SetFontFamily("swiss"); result=true; }
if (ctrlWordData.ctrlWord.Equals("fmodern")) { this.SetFontFamily("modern"); result=true; }
if (ctrlWordData.ctrlWord.Equals("fscript")) { this.SetFontFamily("script"); result=true; }
if (ctrlWordData.ctrlWord.Equals("fdecor")) { this.SetFontFamily("decor"); result=true; }
if (ctrlWordData.ctrlWord.Equals("ftech")) { this.SetFontFamily("tech"); result=true; }
if (ctrlWordData.ctrlWord.Equals("fbidi")) { this.SetFontFamily("bidi"); result=true; }
// pitch
if (ctrlWordData.ctrlWord.Equals("fprq")) { this.SetPitch(ctrlWordData.param); result=true; }
// bias
if (ctrlWordData.ctrlWord.Equals("fbias")) { this.SetBias(ctrlWordData.param); result=true; }
// theme font information
if (ctrlWordData.ctrlWord.Equals("flomajor")) { this.SetThemeFont("flomajor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fhimajor")) { this.SetThemeFont("fhimajor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fdbmajor")) { this.SetThemeFont("fdbmajor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fbimajor")) { this.SetThemeFont("fbimajor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("flominor")) { this.SetThemeFont("flominor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fhiminor")) { this.SetThemeFont("fhiminor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fdbminor")) { this.SetThemeFont("fdbminor"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fbiminor")) { this.SetThemeFont("fbiminor"); result= true; }
// panose
if (ctrlWordData.ctrlWord.Equals("panose")) {state = SETTING_PANOSE; result = true; }
// \*\fname
// <font name> #PCDATA
if (ctrlWordData.ctrlWord.Equals("fname")) {state = SETTING_FONTNAME; result = true; }
// \*\falt
if (ctrlWordData.ctrlWord.Equals("falt")) { state = SETTING_ALTERNATE; result = true; }
// \*\fontemb
if (ctrlWordData.ctrlWord.Equals("fontemb")) { state = SETTING_FONT_EMBED; result = true; }
// font type
if (ctrlWordData.ctrlWord.Equals("ftnil")) { this.SetTrueType("ftnil"); result= true; }
if (ctrlWordData.ctrlWord.Equals("fttruetype")) { this.SetTrueType("fttruetype"); result= true; }
// \*\fontfile
if (ctrlWordData.ctrlWord.Equals("fontemb")) { state = SETTING_FONT_FILE; result = true; }
// codepage
if (ctrlWordData.ctrlWord.Equals("cpg")) { this.SetCodePage(ctrlWordData.param); result= true; }
this.lastCtrlWord = ctrlWordData;
return result;
}
/**
* Set the code page
* @param value The code page value
*
* @since 2.0.8
*/
public void SetCodePage(String value) {
this.cpg = value;
}
/**
* Set the TrueTtype type
* @param value The type
*
* @since 2.0.8
*/
public void SetTrueType(String value) {
this.trueType = value;
}
/**
* Set the font pitch
* @param value Pitch value
*
* @since 2.0.8
*/
public void SetPitch(String value) {
this.fprq = int.Parse(value);
}
/**
* Set the font bias
* @param value Bias value
*
* @since 2.0.8
*/
public void SetBias(String value) {
this.fbias = int.Parse(value);
}
/**
* Set the font theme
*
* @param themeFont Theme value
*
* @since 2.0.8
*/
public void SetThemeFont(String themeFont) {
this.themeFont = themeFont;
}
/**
* Set the font name to the parsed value.
*
* @param fontName The font name.
*
* @since 2.0.8
*/
public void SetFontName(String fontName) {
this.fontName = fontName;
}
/**
* Set the font family to the parsed value.
*
* @param fontFamily The font family.
*
* @since 2.0.8
*/
public void SetFontFamily(String fontFamily) {
this.fontFamily = fontFamily;
}
/**
* Set the font number to the parsed value.
* This is used for mapping fonts to the new font numbers
*
* @param fontNr The font number.
*
* @since 2.0.8
*/
public void SetFontNumber(String fontNr) {
this.fontNr = fontNr;
}
/**
* Set the alternate font name.
*
* @param fontAlternate The falt font value
*
* @since 2.0.8
*/
public void SetFontAlternate(String fontAlternate) {
this.falt = fontAlternate;
}
/**
* Set the character-set to the parsed value.
*
* @param charset The charset value
*
* @since 2.0.8
*/
public void SetCharset(String charset) {
if (charset.Length == 0) {
charset = "0";
}
this.charset = charset;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
*
* @since 2.0.8
*/
public override void SetToDefaults() {
this.themeFont = "";
this.fontNr = "";
this.fontName = "";
this.fontFamily = "";
this.charset = "";
this.fprq = 0;
this.panose = "";
//this.nontaggedname = "";
this.falt = "";
//this.fontemb = "";
//this.fontType = "";
//this.fontFile = "";
//this.fontFileCpg = "";
this.fbias = 0;
this.cpg = "";
this.trueType = "";
this.state = SETTING_NORMAL;
}
/**
* Process the font information that was parsed from the input.
*
* @since 2.0.8
*/
private void ProcessFont() {
this.fontName = this.fontName.Trim();
if (fontName.Length == 0) return;
if (fontNr.Length == 0) return;
if (fontName.Length>0 && fontName.IndexOf(';') >= 0) {
fontName = fontName.Substring(0,fontName.IndexOf(';'));
}
if (this.rtfParser.IsImport()) {
//TODO: If primary font fails, use the alternate
//TODO: Problem: RtfFont defaults family to \froman and doesn't allow any other family.
// if you set the family, it changes the font name and not the family in the Font.java class.
// if (this.fontFamily.Length() > 0) {
// if (this.importHeader.ImportFont(this.fontNr, this.fontName, this.fontFamily, Integer.ParseInt(this.charset)) == false) {
// if (this.falt.Length() > 0) {
// this.importHeader.ImportFont(this.fontNr, this.falt, this.fontFamily, Integer.ParseInt(this.charset));
// }
// }
// } else {
if (!this.importHeader.ImportFont(this.fontNr, this.fontName, int.Parse(this.charset==""?CHARSET_DEFAULT:this.charset))) {
if (this.falt.Length > 0) {
this.importHeader.ImportFont(this.fontNr, this.falt, int.Parse(this.charset==""?CHARSET_DEFAULT:this.charset));
}
}
// }
}
if (this.rtfParser.IsConvert()) {
// This could probably be written as a better font matching function
String fName = this.fontName; // work variable for trimming name if needed.
Font f1 = Createfont(fName);
if (f1.BaseFont == null && this.falt.Length>0)
f1 = Createfont(this.falt);
if (f1.BaseFont == null) {
// Did not find a font, let's try a substring of the first name.
if (FontFactory.COURIER.IndexOf(fName) > -1 ) {
f1 = FontFactory.GetFont(FontFactory.COURIER);
} else if (FontFactory.HELVETICA.IndexOf(fName) > -1 ) {
f1 = FontFactory.GetFont(FontFactory.HELVETICA);
} else if (FontFactory.TIMES.IndexOf(fName) > -1 ) {
f1 = FontFactory.GetFont(FontFactory.TIMES);
} else if (FontFactory.SYMBOL.IndexOf(fName) > -1 ) {
f1 = FontFactory.GetFont(FontFactory.SYMBOL);
} else if (FontFactory.ZAPFDINGBATS.IndexOf(fName) > -1 ) {
f1 = FontFactory.GetFont(FontFactory.ZAPFDINGBATS);
} else {
// we did not find a matching font in any form.
// default to HELVETICA for now.
f1 = FontFactory.GetFont(FontFactory.HELVETICA);
}
}
fontMap[this.fontNr] = f1;
//System.out.Println(f1.GetFamilyname());
}
this.SetToDefaults();
}
/**
* Create a font via the <code>FontFactory</code>
*
* @param fontName The font name to create
* @return The created <code>Font</code> object
*
* @since 2.0.8
*/
private Font Createfont(String fontName) {
Font f1 = null;
int pos=-1;
do {
f1 = FontFactory.GetFont(fontName);
if (f1.BaseFont != null) break; // found a font, exit the do/while
pos = fontName.LastIndexOf(' '); // find the last space
if (pos>0) {
fontName = fontName.Substring(0, pos ); // truncate it to the last space
}
} while (pos>0);
return f1;
}
/**
* Get a <code>Font</code> object from the font map object
*
* @param key The font number to get
* @return The mapped <code>Font</code> object.
*
* @since 2.0.8
*/
public Font GetFont(String key) {
return (Font) fontMap[key];
}
/**
* Load system fonts into the static <code>FontFactory</code> object
*
* @since 2.0.8
*/
private void ImportSystemFonts() {
FontFactory.RegisterDirectories();
}
/**
* Utility method to load the environment variables.
*
* @return Properties object with environment variable information
* @throws Throwable
*
* @since 2.0.8
*/
// private Properties GetEnvironmentVariables() {
// Properties environmentVariables = new Properties();
// String operatingSystem = System.GetProperty("os.name").ToLowerCase();
// Runtime runtime = Runtime.GetRuntime();
// Process process = null;
// if (operatingSystem.IndexOf("windows 95") > -1
// || operatingSystem.IndexOf("windows 98") > -1
// || operatingSystem.IndexOf("me") > -1) {
// process = runtime.Exec("command.com /c set");
// } else if ((operatingSystem.IndexOf("nt") > -1)
// || (operatingSystem.IndexOf("windows 2000") > -1)
// || (operatingSystem.IndexOf("windows xp") > -1)
// || (operatingSystem.IndexOf("windows 2003") > -1)) {
// process = runtime.Exec("cmd.exe /c set");
// } else {
// process = runtime.Exec("env");
// }
// BufferedReader environmentStream = new BufferedReader(new InputStreamReader(process.GetInputStream()));
// String inputLine = "";
// int idx = -1;
// while ((inputLine = environmentStream.ReadLine()) != null) {
// idx = inputLine.IndexOf('=');
// environmentVariables.SetProperty(inputLine.Substring(0, idx),
// inputLine.Substring(idx + 1));
// }
// return environmentVariables;
// }
}
}

View File

@@ -0,0 +1,174 @@
using System;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationInfo.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationInfo</code> handles data destined for the info destination
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfDestinationInfo : RtfDestination {
private String elementName = "";
private String text = "";
public RtfDestinationInfo() : base(null) {
}
/**
* Constructs a new RtfDestinationInfo.
*
* @param parser The RtfParser object.
*/
public RtfDestinationInfo(RtfParser parser, String elementname) : base(parser) {
SetToDefaults();
this.elementName = elementname;
}
public override void SetParser(RtfParser parser) {
this.rtfParser = parser;
this.SetToDefaults();
}
public void SetElementName(String value) {
this.elementName = value;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*/
public override bool CloseDestination() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*/
public override bool HandleCloseGroup() {
if (this.text.Length > 0) {
Document doc = this.rtfParser.GetDocument();
if (doc != null) {
if (this.elementName.Equals("author")){
doc.AddAuthor(this.text);
}
if (this.elementName.Equals("title")){
doc.AddTitle(this.text);
}
if (this.elementName.Equals("subject")){
doc.AddSubject(this.text);
}
} else {
RtfDocument rtfDoc = this.rtfParser.GetRtfDocument();
if (rtfDoc != null) {
if (this.elementName.Equals("author")){
Meta meta = new Meta(this.elementName, this.text);
RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta);
rtfDoc.GetDocumentHeader().AddInfoElement(elem);
}
if (this.elementName.Equals("title")){
Meta meta = new Meta(this.elementName, this.text);
RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta);
rtfDoc.GetDocumentHeader().AddInfoElement(elem);
}
if (this.elementName.Equals("subject")){
Meta meta = new Meta(this.elementName, this.text);
RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta);
rtfDoc.GetDocumentHeader().AddInfoElement(elem);
}
}
}
this.SetToDefaults();
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*/
public override bool HandleOpenGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(char[])
*/
public override bool HandleCharacter(int ch) {
this.text += (char)ch;
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleControlWord(com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData)
*/
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
elementName = ctrlWordData.ctrlWord;
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setToDefaults()
*/
public override void SetToDefaults() {
this.text = "";
}
}
}

View File

@@ -0,0 +1,130 @@
using System;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationListTable.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationListTable</code> handles data destined for the List Table destination
*
* @author Howard Shank (hgshank@yahoo.com)
*
*/
public class RtfDestinationListTable : RtfDestination {
/**
* The RtfImportHeader to add List mappings to.
*/
private RtfImportMgr importHeader = null;
public RtfDestinationListTable() : base(null) {
}
public RtfDestinationListTable(RtfParser parser) : base(parser) {
this.importHeader = parser.GetImportManager();
}
public override void SetParser(RtfParser parser) {
this.rtfParser = parser;
this.importHeader = parser.GetImportManager();
this.SetToDefaults();
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*/
public override bool CloseDestination() {
// TODO Auto-generated method stub
return true;
}
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
bool result = true;
return result;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*/
public override bool HandleCloseGroup() {
// TODO Auto-generated method stub
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*/
public override bool HandleOpenGroup() {
// TODO Auto-generated method stub
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
*/
public override bool HandleCharacter(int ch) {
// TODO Auto-generated method stub
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setToDefaults()
*/
public override void SetToDefaults() {
// TODO Auto-generated method stub
}
}
}

View File

@@ -0,0 +1,227 @@
using System;
using System.Collections;
using System.Reflection;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationMgr.cs,v 1.4 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationMgr</code> manages destination objects for the parser
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public sealed class RtfDestinationMgr {
/*
* Destinations
*/
private static RtfDestinationMgr instance = null;
/**
* CtrlWord <-> Destination map object.
*
* Maps control words to their destinations objects.
* Null destination is a special destination used for
* discarding unwanted data. This is primarily used when
* skipping groups, binary data or unwanted/unknown data.
*/
private static Hashtable destinations = new Hashtable(300, 0.95f);
/**
* Destination objects.
* There is only one of each destination.
*/
private static Hashtable destinationObjects = new Hashtable(10, 0.95f);
private static bool ignoreUnknownDestinations = false;
private static RtfParser rtfParser = null;
/**
* String representation of null destination.
*/
public const String DESTINATION_NULL = "null";
/**
* String representation of document destination.
*/
public const String DESTINATION_DOCUMENT = "document";
/**
* Hidden default constructor becuase
*/
private RtfDestinationMgr() {
}
public static void SetParser(RtfParser parser) {
rtfParser = parser;
}
public static RtfDestinationMgr GetInstance() {
lock(destinations) {
if (instance == null) {
instance = new RtfDestinationMgr();
// 2 required destinations for all documents
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_DOCUMENT, new Object[] { "RtfDestinationDocument", "" } );
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_NULL, new Object[] { "RtfDestinationNull", "" } );
}
return instance;
}
}
public static RtfDestinationMgr GetInstance(RtfParser parser) {
lock(destinations) {
RtfDestinationMgr.SetParser(parser);
if (instance == null) {
instance = new RtfDestinationMgr();
// 2 required destinations for all documents
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_DOCUMENT, new Object[] { "RtfDestinationDocument", "" } );
RtfDestinationMgr.AddDestination(RtfDestinationMgr.DESTINATION_NULL, new Object[] { "RtfDestinationNull", "" } );
}
return instance;
}
}
public static RtfDestination GetDestination(String destination) {
RtfDestination dest = null;
if (destinations.ContainsKey(destination)) {
dest = (RtfDestination)destinations[destination];
} else {
if (ignoreUnknownDestinations) {
dest = (RtfDestination)destinations[DESTINATION_NULL];
} else {
dest = (RtfDestination)destinations[DESTINATION_DOCUMENT];
}
}
dest.SetParser(RtfDestinationMgr.rtfParser);
return dest;
}
public static bool AddDestination(String destination, Object[] args) {
if (destinations.ContainsKey(destination)) {
return true;
}
String thisClass = "iTextSharp.text.rtf.parser.destinations." + (String)args[0];
if (thisClass.IndexOf("RtfDestinationNull") >= 0) {
destinations[destination] = RtfDestinationNull.GetInstance();
return true;
}
Type value = null;
try {
value = Type.GetType(thisClass);
} catch {
return false;
}
if (value == null)
return false;
RtfDestination c = null;
if (destinationObjects.ContainsKey(value.Name)) {
c = (RtfDestination)destinationObjects[value.Name];
} else {
try {
c = (RtfDestination)value.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[0], null).Invoke(null);
} catch {
return false;
}
}
c.SetParser(rtfParser);
if (value.Equals(typeof(RtfDestinationInfo))) {
((RtfDestinationInfo)c).SetElementName(destination);
}
if (value.Equals(typeof(RtfDestinationStylesheetTable))) {
((RtfDestinationStylesheetTable)c).SetElementName(destination);
((RtfDestinationStylesheetTable)c).SetType((String)args[1]);
}
destinations[destination] = c;
destinationObjects[value.Name] = c;
return true;
}
// listener methods
/**
* Adds a <CODE>RtfDestinationListener</CODE> to the appropriate <CODE>RtfDestination</CODE>.
*
* @param destination the destination string for the listener
* @param listener
* the new RtfDestinationListener.
*/
public static bool AddListener(String destination, IRtfDestinationListener listener) {
RtfDestination dest = GetDestination(destination);
if (dest != null) {
return dest.AddListener(listener);
}
return false;
}
/**
* Removes a <CODE>RtfDestinationListener</CODE> from the appropriate <CODE>RtfDestination</CODE>.
*
* @param destination the destination string for the listener
* @param listener
* the RtfCtrlWordListener that has to be removed.
*/
public static bool RemoveListener(String destination, IRtfDestinationListener listener) {
RtfDestination dest = GetDestination(destination);
if (dest != null) {
return dest.RemoveListener(listener);
}
return false;
}
}
}

View File

@@ -0,0 +1,147 @@
using System;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationNull.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationNull</code> is for discarded entries. They go nowhere.
* If a control word destination is unknown or ignored, this is the destination
* that should be set.
*
* All methods return true indicating they were handled.
*
* This is a unique destination in that it is a singleton.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public sealed class RtfDestinationNull : RtfDestination {
private static RtfDestinationNull instance = new RtfDestinationNull();
/**
* Constructs a new RtfDestinationNull.
*
* This constructor is hidden for internal use only.
*/
private RtfDestinationNull() : base() {
}
/**
* Constructs a new RtfDestinationNull.
*
* This constructor is hidden for internal use only.
*
* @param parser Unused value
*/
private RtfDestinationNull(RtfParser parser) : base(null) {
}
/**
* Get the singleton instance of RtfDestinationNull object.
*/
static public RtfDestinationNull GetInstance() {
return instance;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
*/
public override void SetToDefaults() {
}
// Interface definitions
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*/
public override bool CloseDestination() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*/
public override bool HandleCloseGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*/
public override bool HandleOpenGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
*/
public override bool HandleCharacter(int ch) {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleControlWord(com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordData)
*/
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
return true;
}
public static String GetName() {
return typeof(RtfDestinationNull).Name;
}
public override int GetNewTokeniserState() {
return RtfParser.TOKENISER_SKIP_GROUP;
}
}
}

View File

@@ -0,0 +1,488 @@
using System;
using System.IO;
using System.Text;
using System.Globalization;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.rtf.direct;
using iTextSharp.text.rtf.graphic;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.document;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationShppict.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationShppict</code> handles data destined for picture destinations
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfDestinationShppict : RtfDestination {
private ByteBuffer data = null;
private StringBuilder hexChars = new StringBuilder(0);
private StringBuilder buffer = new StringBuilder();
/* picttype */
private int pictureType = Image.ORIGINAL_NONE;
public const int ORIGINAL_NONE = 0;
public const int ORIGINAL_GIF = 3;
public const int ORIGINAL_TIFF = 5;
public const int ORIGINAL_PS = 7;
// emfblip - EMF (nhanced metafile) - NOT HANDLED
// pngblip int ORIGINAL_PNG = 2;
// jpegblip Image.ORIGINAL_JPEG = 1; ORIGINAL_JPEG2000 = 8;
// shppict - Destination
// nonshpict - Destination - SKIP THIS
// macpict - Mac QuickDraw- NOT HANDLED
// pmmetafileN - OS/2 Metafile - NOT HANDLED
// N * Meaning
// 0x0004 PU_ARBITRARY
// 0x0008 PU_PELS
// 0x000C PU_LOMETRIC
// 0x0010 PU_HIMETRIC
// 0x0014 PU_LOENGLISH
// 0x0018 PU_HIENGLISH
// 0x001C PU_TWIPS
//private int pmmetafile = 0;
// wmetafileN Image.RIGINAL_WMF = 6;
// N * Type
// 1 = MM_TEXT
// 2 = M_LOMETRIC
// 3 = MM_HIMETRIC
// 4 = MM_LOENGLISH
// 5 = MM_HIENGLISH
// 6 = MM_TWIPS
// 7 = MM_ISOTROPIC
// 8 = MM_ANISOTROPIC
// dibitmapN - DIB - Convert to BMP?
// wbitmapN Image.ORIGINAL_BMP = 4;
/* bitapinfo */
// wbmbitspixelN - number of bits per pixel - 1 monochrome, 4 16 color, 8 256 color, 24 RGB - Default 1
//private int bitsPerPixel = 1;
// wbmplanesN - number of color planes - must be 1
//private int planes = 1;
// wbmwidthbytesN - number of bytes in each raster line
//private int widthBytes = 0;
/* pictsize */
// picwN Ext field if the picture is a Windows metafile; picture width in pixels if the picture is a bitmap or
// from quickdraw
private long width = 0;
// pichN
private long height = 0;
// picwgoalN
private long desiredWidth = 0;
// picgoalN
private long desiredHeight = 0;
// picscalexN
private int scaleX = 100;
// picscaleyN
private int scaleY = 100;
// picscaled - macpict setting
//private bool scaled = false;
// picprop
//private bool inlinePicture = false;
// defshp
//private bool wordArt = false;
// piccroptN
private int cropTop = 0;
// piccropbN
private int cropBottom = 0;
// piccroplN
private int cropLeft = 0;
// piccroprN
private int cropRight = 0;
/* metafileinfo */
// picbmp
//private bool bitmap = false;
//picbppN - Valid 1,4,8,24
//private int bbp = 1;
/* data */
// binN
// 0 = HEX, 1 = BINARY
public const int FORMAT_HEXADECIMAL = 0;
public const int FORMAT_BINARY = 1;
private int dataFormat = FORMAT_HEXADECIMAL;
private long binaryLength = 0;
// blipupiN
//private int unitsPerInch = 0;
// bliptagN
//private String tag = "";
private const int NORMAL = 0;
private const int BLIPUID = 1;
//private int state = NORMAL;
/**
* Constant for converting pixels to twips
*/
private const int PIXEL_TWIPS_FACTOR = 15;
private MemoryStream dataOS = null;
public RtfDestinationShppict() : base(null) {
this.pictureType = pictureType; //get rid of a warning
}
/**
* Constructs a new RtfDestinationShppict.
*/
public RtfDestinationShppict(RtfParser parser) : base(parser) {
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*/
public override bool CloseDestination() {
if (this.rtfParser.IsImport()) {
if (this.buffer.Length>0) {
WriteBuffer();
}
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*/
public override bool HandleCloseGroup() {
this.OnCloseGroup(); // event handler
if (this.rtfParser.IsImport()) {
if (this.buffer.Length>0) {
WriteBuffer();
}
if (dataOS != null) {
AddImage();
dataOS = null;
}
this.WriteText("}");
return true;
}
if (this.rtfParser.IsConvert()) {
}
return true;
}
private bool AddImage() {
Image img = null;
try {
img = Image.GetInstance(dataOS.ToArray());
} catch {
}
// if (img != null) {
// FileOutputStream out =null;
// try {
// out = new FileOutputStream("c:\\test.png");
// out.Write(img.GetOriginalData());
// out.Close();
// } catch (FileNotFoundException e1) {
// // TODO Auto-generated catch block
// e1.PrintStackTrace();
// } catch (IOException e1) {
// // TODO Auto-generated catch block
// e1.PrintStackTrace();
// }
if (img != null) {
img.ScaleAbsolute((float)this.desiredWidth/PIXEL_TWIPS_FACTOR, (float)this.desiredHeight/PIXEL_TWIPS_FACTOR);
img.ScaleAbsolute((float)this.width/PIXEL_TWIPS_FACTOR, (float)this.height/PIXEL_TWIPS_FACTOR);
img.ScalePercent((float)this.scaleX, this.scaleY);
try {
if (this.rtfParser.IsImport()) {
RtfDocument rtfDoc = this.rtfParser.GetRtfDocument();
RtfImage rtfImage = new RtfImage(rtfDoc, img);
rtfDoc.Add(rtfImage);
}
if (this.rtfParser.IsConvert()) {
this.rtfParser.GetDocument().Add(img);
}
} catch {
}
}
dataFormat = FORMAT_HEXADECIMAL;
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*/
public override bool HandleOpenGroup() {
this.OnOpenGroup(); // event handler
if (this.rtfParser.IsImport()) {
}
if (this.rtfParser.IsConvert()) {
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
if (this.rtfParser.IsImport()) {
if (this.buffer.Length>0) {
WriteBuffer();
}
}
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
*/
public override bool HandleCharacter(int ch) {
if (this.rtfParser.IsImport()) {
if (buffer.Length > 254)
WriteBuffer();
}
if (data == null) data = new ByteBuffer();
switch (dataFormat) {
case FORMAT_HEXADECIMAL:
hexChars.Append(ch);
if (hexChars.Length == 2) {
try {
data.Append((char)int.Parse(hexChars.ToString(), NumberStyles.HexNumber));
} catch {
}
hexChars = new StringBuilder();
}
break;
case FORMAT_BINARY:
if (dataOS == null) {
dataOS = new MemoryStream();
}
// HGS - FIX ME IF PROBLEM!
dataOS.WriteByte((byte)ch);
// PNG signature should be.
// (decimal) 137 80 78 71 13 10 26 10
// (hexadecimal) 89 50 4e 47 0d 0a 1a 0a
// (ASCII C notation) \211 P N G \r \n \032 \n
binaryLength--;
if (binaryLength == 0) { dataFormat = FORMAT_HEXADECIMAL; }
break;
}
return true;
}
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
bool result = false;
bool skipCtrlWord = false;
if (this.rtfParser.IsImport()) {
skipCtrlWord = true;
if (ctrlWordData.ctrlWord.Equals("shppict")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("nonshppict")) { // never gets here because this is a destination set to null
skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;
}
if (ctrlWordData.ctrlWord.Equals("blipuid")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picprop")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("pict")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("emfblip")) { result = true; pictureType = Image.ORIGINAL_NONE;}
if (ctrlWordData.ctrlWord.Equals("pngblip")) { result = true; pictureType = Image.ORIGINAL_PNG;}
if (ctrlWordData.ctrlWord.Equals("jepgblip")) { result = true; pictureType = Image.ORIGINAL_JPEG;}
if (ctrlWordData.ctrlWord.Equals("macpict")) { result = true; pictureType = Image.ORIGINAL_NONE;}
if (ctrlWordData.ctrlWord.Equals("pmmetafile")) { result = true; pictureType = Image.ORIGINAL_NONE;}
if (ctrlWordData.ctrlWord.Equals("wmetafile")) { result = true; pictureType = Image.ORIGINAL_WMF;}
if (ctrlWordData.ctrlWord.Equals("dibitmap")) { result = true; pictureType = Image.ORIGINAL_NONE;}
if (ctrlWordData.ctrlWord.Equals("wbitmap")) { result = true; pictureType = Image.ORIGINAL_BMP;}
/* bitmap information */
if (ctrlWordData.ctrlWord.Equals("wbmbitspixel")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("wbmplanes")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("wbmwidthbytes")) { result = true;}
/* picture size, scaling and cropping */
if (ctrlWordData.ctrlWord.Equals("picw")) { this.width = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("pich")) { this.height = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picwgoal")) { this.desiredWidth = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("pichgoal")) { this.desiredHeight = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picscalex")) { this.scaleX = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picscaley")) { this.scaleY = ctrlWordData.IntValue();result = true;}
if (ctrlWordData.ctrlWord.Equals("picscaled")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("picprop")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("defshp")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropt")) { this.cropTop = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropb")) { this.cropBottom = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropl")) { this.cropLeft = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropr")) { this.cropRight = ctrlWordData.IntValue(); result = true;}
/* metafile information */
if (ctrlWordData.ctrlWord.Equals("picbmp")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("picbpp")) { result = true;}
/* picture data */
if (ctrlWordData.ctrlWord.Equals("bin")) {
this.dataFormat = FORMAT_BINARY;
// set length to param
this.binaryLength = ctrlWordData.LongValue();
this.rtfParser.SetTokeniserStateBinary(binaryLength);
result = true;
}
if (ctrlWordData.ctrlWord.Equals("blipupi")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("blipuid")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("bliptag")) { result = true;}
}
if (this.rtfParser.IsConvert()) {
if (ctrlWordData.ctrlWord.Equals("shppict")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("nonshppict")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("blipuid")) { result = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("pict")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("emfblip")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("pngblip")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("jepgblip")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("macpict")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("pmmetafile")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("wmetafile")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("dibitmap")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("wbitmap")) { result = true;}
/* bitmap information */
if (ctrlWordData.ctrlWord.Equals("wbmbitspixel")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("wbmplanes")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("wbmwidthbytes")) { result = true;}
/* picture size, scaling and cropping */
if (ctrlWordData.ctrlWord.Equals("picw")) { this.width = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("pich")) { this.height = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picwgoal")) { this.desiredWidth = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("pichgoal")) { this.desiredHeight = ctrlWordData.LongValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picscalex")) { this.scaleX = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("picscaley")) { this.scaleY = ctrlWordData.IntValue();result = true;}
if (ctrlWordData.ctrlWord.Equals("picscaled")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("picprop")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("defshp")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropt")) { this.cropTop = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropb")) { this.cropBottom = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropl")) { this.cropLeft = ctrlWordData.IntValue(); result = true;}
if (ctrlWordData.ctrlWord.Equals("piccropr")) { this.cropRight = ctrlWordData.IntValue(); result = true;}
/* metafile information */
if (ctrlWordData.ctrlWord.Equals("picbmp")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("picbpp")) { result = true;}
/* picture data */
if(ctrlWordData.ctrlWord.Equals("bin")) {
dataFormat = FORMAT_BINARY; result = true;
}
if (ctrlWordData.ctrlWord.Equals("blipupi")) { result = true;}
if (ctrlWordData.ctrlWord.Equals("blipuid")) { skipCtrlWord = true; this.rtfParser.SetTokeniserStateSkipGroup(); result = true;}
if (ctrlWordData.ctrlWord.Equals("bliptag")) { result = true;}
}
if (!skipCtrlWord) {
switch (this.rtfParser.GetConversionType()) {
case RtfParser.TYPE_IMPORT_FULL:
WriteBuffer();
WriteText(ctrlWordData.ToString());
result = true;
break;
case RtfParser.TYPE_IMPORT_FRAGMENT:
WriteBuffer();
WriteText(ctrlWordData.ToString());
result = true;
break;
case RtfParser.TYPE_CONVERT:
result = true;
break;
default: // error because is should be an import or convert
result = false;
break;
}
}
return result;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#setDefaults()
*/
public override void SetToDefaults() {
this.buffer = new StringBuilder();
this.data = null;
this.width = 0;
this.height = 0;
this.desiredWidth = 0;
this.desiredHeight = 0;
this.scaleX = 100;
this.scaleY = 100;
//this.scaled = false;
//this.inlinePicture = false;
//this.wordArt = false;
this.cropTop = 0;
this.cropBottom = 0;
this.cropLeft = 0;
this.cropRight = 0;
//this.bitmap = false;
//this.bbp = 1;
this.dataFormat = FORMAT_HEXADECIMAL;
this.binaryLength = 0;
//this.unitsPerInch = 0;
//this.tag = "";
}
private void WriteBuffer() {
WriteText(this.buffer.ToString());
}
private void WriteText(String value) {
if (this.rtfParser.GetState().newGroup) {
this.rtfParser.GetRtfDocument().Add(new RtfDirectContent("{"));
this.rtfParser.GetState().newGroup = false;
}
if (value.Length > 0) {
this.rtfParser.GetRtfDocument().Add(new RtfDirectContent(value));
}
}
}
}

View File

@@ -0,0 +1,585 @@
using System;
using iTextSharp.text;
using iTextSharp.text.rtf.style;
using iTextSharp.text.rtf.parser;
using iTextSharp.text.rtf.parser.ctrlwords;
/*
* $Id: RtfDestinationStylesheetTable.cs,v 1.2 2008/05/13 11:26:00 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.destinations {
/**
* <code>RtfDestinationStylesheetTable</code> handles data destined for the
* Stylesheet Table destination
*
* @author Howard Shank (hgshank@yahoo.com)
*
*/
public class RtfDestinationStylesheetTable : RtfDestination {
private String styleName = "";
/**
* <code>RtfParagraphStyle</code> object for setting styleshee values
* as they are parsed from the input.
*/
//private RtfParagraphStyle rtfParagraphStyle = null;
private String elementName = "";
/**
* RTF Style number from stylesheet table.
*/
private int styleNr = 0;
/**
* What kind of style is this, Paragraph or Character or Table
*/
private int styleType = RtfStyleTypes.PARAGRAPH;
// Alignment
/**
* Alignment - page 85
* \qc, \qj, \ql, \qr, \qd, \qkN, \qt
*/
private int alignment = Element.ALIGN_LEFT;
/**
* Percentage of line occupied by Kashida justification (0 <20> low, 10 <20> medium, 20 <20> high).
* \qkN
*/
private int justificationPercentage = 0;
// Indentation
/**
* First line indentation.
*/
private int firstLineIndent = 0;
/**
* Left indentation
*/
private int leftIndent = 0;
/**
* Right indentation
*/
private int rightIndent = 0;
/**
* Automatically adjust right indentation when docunent grid is defined
*/
private int adustRightIndent = 0;
/**
* Mirror indents?
*/
private int mirrorIndent = 0;
// Document Foratting Properties
/**
* Override orphan/widow control.
*/
private int overrideWidowControl = -1;
// Asian Typography
/**
* auto spacing betwee DBC and English
*/
private int AutoSpaceBetweenDBCEnglish = 0;
/**
* auto spacing betwee DBC and numbers
*/
private int AutoSpaceBetweenDBCNumbers = 0;
/**
* No Character wrapping
*/
private int noCharacterWrapping = 0;
/**
* No Word wrapping
*/
private int noWordWrapping = 0;
/**
* No overflow period and comma
*/
private int noOverflowPeriodComma = 0;
//////////////////////////////////////////////////////
/**
* The RtfImportHeader to add color mappings to.
*/
private RtfImportMgr importHeader = null;
private String type = "";
public RtfDestinationStylesheetTable() : base(null) {
}
public RtfDestinationStylesheetTable(RtfParser parser, String type) : base(parser){
this.importHeader = parser.GetImportManager();
this.type = type;
}
public override void SetParser(RtfParser parser) {
this.rtfParser = parser;
this.importHeader = parser.GetImportManager();
}
public void SetType(String value) {
this.type = value;
}
public void SetElementName(String value) {
this.elementName = value;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#handleOpenNewGroup()
*/
public override bool HandleOpeningSubGroup() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
*/
public override bool CloseDestination() {
return true;
}
public override bool HandleControlWord(RtfCtrlWordData ctrlWordData) {
bool result = true;
this.OnCtrlWord(ctrlWordData); // event handler
if (this.rtfParser.IsImport()) {
// information
if (ctrlWordData.ctrlWord.Equals("s")) { }
if (ctrlWordData.ctrlWord.Equals("cs")) {}
if (ctrlWordData.ctrlWord.Equals("ds")) {}
if (ctrlWordData.ctrlWord.Equals("ts")) {}
if (ctrlWordData.ctrlWord.Equals("tsrowd")) {}
if (ctrlWordData.ctrlWord.Equals("keycode")) {}
if (ctrlWordData.ctrlWord.Equals("shift")) { }
if (ctrlWordData.ctrlWord.Equals("ctrl")) { }
if (ctrlWordData.ctrlWord.Equals("alt")) { }
//cells
if (ctrlWordData.ctrlWord.Equals("fn")) { }
if (ctrlWordData.ctrlWord.Equals("additive")) { }
if (ctrlWordData.ctrlWord.Equals("sbasedon")) { }
if (ctrlWordData.ctrlWord.Equals("snext")) { }
if (ctrlWordData.ctrlWord.Equals("sautoupd")) { }
if (ctrlWordData.ctrlWord.Equals("shidden")) { }
if (ctrlWordData.ctrlWord.Equals("slink")) { }
if (ctrlWordData.ctrlWord.Equals("slocked")) { }
if (ctrlWordData.ctrlWord.Equals("spersonal")) { }
if (ctrlWordData.ctrlWord.Equals("scompose")) { }
if (ctrlWordData.ctrlWord.Equals("sreply")) { }
/* FORMATTING */
// brdrdef/parfmt/apoctl/tabdef/shading/chrfmt
if (ctrlWordData.ctrlWord.Equals("styrsid")) { }
if (ctrlWordData.ctrlWord.Equals("ssemihidden")) { }
if (ctrlWordData.ctrlWord.Equals("sqformat")) { }
if (ctrlWordData.ctrlWord.Equals("spriority")) { }
if (ctrlWordData.ctrlWord.Equals("sunhideused")) { }
/* TABLE STYLES */
if (ctrlWordData.ctrlWord.Equals("tscellwidth")) { }
if (ctrlWordData.ctrlWord.Equals("tscellwidthfts")) { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddt")) { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddl")) { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddr")) { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddb")) { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddft"))/*0-auto, 3-twips*/ { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddfl"))/*0-auto, 3-twips*/ { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddfr"))/*0-auto, 3-twips*/ { }
if (ctrlWordData.ctrlWord.Equals("tscellpaddfb"))/*0-auto, 3-twips*/ { }
if (ctrlWordData.ctrlWord.Equals("tsvertalt")) { }
if (ctrlWordData.ctrlWord.Equals("tsvertalc")) { }
if (ctrlWordData.ctrlWord.Equals("tsvertalb")) { }
if (ctrlWordData.ctrlWord.Equals("tsnowrap")) { }
if (ctrlWordData.ctrlWord.Equals("tscellcfpat")) { }
if (ctrlWordData.ctrlWord.Equals("tscellcbpat")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgbdiag")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgfdiag")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgcross")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgdcross")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgdkcross ")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgdkdcross")) { }
if (ctrlWordData.ctrlWord.Equals("tsbghoriz")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgvert")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgdkhor")) { }
if (ctrlWordData.ctrlWord.Equals("tsbgdkvert")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrt")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrb")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrl")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrr")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrh")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrv")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrdgl")) { }
if (ctrlWordData.ctrlWord.Equals("tsbrdrdgr")) { }
if (ctrlWordData.ctrlWord.Equals("tscbandsh")) { }
if (ctrlWordData.ctrlWord.Equals("tscbandsv")) { }
}
if (ctrlWordData.ctrlWordType == RtfCtrlWordType.FLAG ||
ctrlWordData.ctrlWordType == RtfCtrlWordType.TOGGLE ||
ctrlWordData.ctrlWordType == RtfCtrlWordType.VALUE) {
this.rtfParser.GetState().properties.SetProperty(ctrlWordData);
}
switch (this.rtfParser.GetConversionType()) {
case RtfParser.TYPE_IMPORT_FULL:
result = true;
break;
case RtfParser.TYPE_IMPORT_FRAGMENT:
result = true;
break;
case RtfParser.TYPE_CONVERT:
result = true;
break;
default: // error because is should be an import or convert
result = false;
break;
}
return result;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
*/
public override bool HandleCloseGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupStart()
*/
public override bool HandleOpenGroup() {
return true;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.direct.RtfDestination#handleCharacter(int)
*/
public override bool HandleCharacter(int ch) {
styleName += (char)ch;
return true;
}
public void CreateNewStyle() {
//public RtfParagraphStyle(String styleName, String fontName, int fontSize, int fontStyle, Color fontColor)
//this.rtfParagraphStyle = new RtfParagraphStyle();
}
/**
* Set the justification percentage from parsed value.
* @param percent The justification percentage
* @return The justification percentage
*/
public int SetJustificationPercentage(int percent) {
this.justificationPercentage = percent;
return this.justificationPercentage;
}
/**
* Get the justification percentage.
* @return The justification percentage value.
*/
public int GetJustificationPercentage() {
return this.justificationPercentage;
}
/**
* Set the alignment value from the parsed value.
* @param alignment The alignment value.
* @return The alignment value.
*/
public int SetAlignment(int alignment) {
this.alignment = alignment;
return this.alignment;
}
/**
* Get the alignment value.
* @return The alignment value.
*/
public int GetAlignment() {
return this.alignment;
}
/**
* Get the first line indent value.
*
* @return the firstLineIndent
*/
public int GetFirstLineIndent() {
return firstLineIndent;
}
/**
* Set the first line indent value.
* @param firstLineIndent the firstLineIndent to set
*/
public void SetFirstLineIndent(int firstLineIndent) {
this.firstLineIndent = firstLineIndent;
}
/**
* Get the left indent value
* @return the left indent
*/
public int GetIndent() {
return leftIndent;
}
/**
* Set the left indent value from the value parsed.
* @param indent the left indent value.
*/
public void SetIndent(int indent) {
this.leftIndent = indent;
}
/**
* Get the right indent adjustment value
* @return the adustRightIndent value
*/
public int GetAdustRightIndent() {
return adustRightIndent;
}
/**
* Set the right indent adjustment value
* @param adustRightIndent the adustRightIndent to set
*/
public void SetAdustRightIndent(int adustRightIndent) {
this.adustRightIndent = adustRightIndent;
}
/**
* Get the left indent value
* @return the leftIndent
*/
public int GetLeftIndent() {
return leftIndent;
}
/**
* Set the left indent value
* @param leftIndent the leftIndent to set
*/
public void SetLeftIndent(int leftIndent) {
this.leftIndent = leftIndent;
}
/**
* Get the value indicating if document has mirrored indents.
*
* @return the mirrorIndent
*/
public int GetMirrorIndent() {
return mirrorIndent;
}
/**
* Set the mirrored indent value from the parsed value.
*
* @param mirrorIndent the mirrorIndent to set
*/
public void SetMirrorIndent(int mirrorIndent) {
this.mirrorIndent = mirrorIndent;
}
/**
* Get the right indent value.
*
* @return the rightIndent
*/
public int GetRightIndent() {
return rightIndent;
}
/**
* Set the right indent value.
*
* @param rightIndent the rightIndent to set
*/
public void SetRightIndent(int rightIndent) {
this.rightIndent = rightIndent;
}
/**
* Get the ovirride widow control value.
*
* @return the overrideWidowControl
*/
public int GetOverrideWidowControl() {
return overrideWidowControl;
}
/**
* Set the override widow control.
*
* @param overrideWidowControl the overrideWidowControl to set
*/
public void SetOverrideWidowControl(int overrideWidowControl) {
this.overrideWidowControl = overrideWidowControl;
}
/**
* Get the auto space between DBC and English indicator.
*
* @return the autoSpaceBetweenDBCEnglish
*/
public int GetAutoSpaceBetweenDBCEnglish() {
return AutoSpaceBetweenDBCEnglish;
}
/**
* Set the auto space between DBC and English indicator.
*
* @param autoSpaceBetweenDBCEnglish the autoSpaceBetweenDBCEnglish to set
*/
public void SetAutoSpaceBetweenDBCEnglish(int autoSpaceBetweenDBCEnglish) {
AutoSpaceBetweenDBCEnglish = autoSpaceBetweenDBCEnglish;
}
/**
* Get the auto space between DBC and Numbers indicator.
* @return the autoSpaceBetweenDBCNumbers
*/
public int GetAutoSpaceBetweenDBCNumbers() {
return AutoSpaceBetweenDBCNumbers;
}
/**
* Set the auto space between DBC and Numbers indicator.
* @param autoSpaceBetweenDBCNumbers the autoSpaceBetweenDBCNumbers to set
*/
public void SetAutoSpaceBetweenDBCNumbers(int autoSpaceBetweenDBCNumbers) {
AutoSpaceBetweenDBCNumbers = autoSpaceBetweenDBCNumbers;
}
/**
* Get no character wrapping indicator.
*
* @return the noCharacterWrapping
*/
public int GetNoCharacterWrapping() {
return noCharacterWrapping;
}
/**
* Set the no character wrapping indicator from parsed value
*
* @param noCharacterWrapping the noCharacterWrapping to set
*/
public void SetNoCharacterWrapping(int noCharacterWrapping) {
this.noCharacterWrapping = noCharacterWrapping;
}
/**
* Get the no overflow period comma indicator.
*
* @return the noOverflowPeriodComma
*/
public int GetNoOverflowPeriodComma() {
return noOverflowPeriodComma;
}
/**
* Set the no overflow period comma indicator from the parsed value.
*
* @param noOverflowPeriodComma the noOverflowPeriodComma to set
*/
public void SetNoOverflowPeriodComma(int noOverflowPeriodComma) {
this.noOverflowPeriodComma = noOverflowPeriodComma;
}
/**
* Get the no word wrapping indicator.
*
* @return the noWordWrapping
*/
public int GetNoWordWrapping() {
return noWordWrapping;
}
/**
* Set the no word wrapping indicator from the parsed value.
*
* @param noWordWrapping the noWordWrapping to set
*/
public void SetNoWordWrapping(int noWordWrapping) {
this.noWordWrapping = noWordWrapping;
}
/**
* Get this style number.
*
* @return the styleNr
*/
public int GetStyleNr() {
return styleNr;
}
/**
* Set this style number from the parsed value.
*
* @param styleNr the styleNr to set
*/
public void SetStyleNr(int styleNr) {
this.styleNr = styleNr;
}
/**
* Get this style type.
* For example Style, Character Style, etc.
*
* @return the styleType
*/
public int GetStyleType() {
return styleType;
}
/**
* Set the style type.
*
* @param styleType the styleType to set
*/
public void SetStyleType(int styleType) {
this.styleType = styleType;
}
/* (non-Javadoc)
* @see com.lowagie.text.rtf.parser.destinations.RtfDestination#setToDefaults()
*/
public override void SetToDefaults() {
styleName = "";
styleNr = 0;
alignment = Element.ALIGN_LEFT;
justificationPercentage = 0;
firstLineIndent = 0;
leftIndent = 0;
rightIndent = 0;
adustRightIndent = 0;
mirrorIndent = 0;
overrideWidowControl = -1;
AutoSpaceBetweenDBCEnglish = 0;
AutoSpaceBetweenDBCNumbers = 0;
noCharacterWrapping = 0;
noWordWrapping = 0;
noOverflowPeriodComma = 0;
}
}
}

View File

@@ -0,0 +1,29 @@
namespace iTextSharp.text.rtf.parser.enumerations {
/**
* Specifies the color theme values for use in Color Tables.
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public sealed class RtfColorThemes {
public const int THEME_UNDEFINED = -1;
public const int THEME_MAINDARKONE = 0;
public const int THEME_MAINDARKTWO = 1;
public const int THEME_MAINLIGHTONE = 2;
public const int THEME_MAINLIGHTTWO = 3;
public const int THEME_ACCENTONE = 4;
public const int THEME_ACCENTTWO = 5;
public const int THEME_ACCENTTHREE = 6;
public const int THEME_ACCENTFOUR = 7;
public const int THEME_ACCENTFIVE = 8;
public const int THEME_ACCENTSIX = 9;
public const int THEME_HYPERLINK = 10;
public const int THEME_FOLLOWEDHYPERLINK = 11;
public const int THEME_BACKGROUNDONE = 12;
public const int THEME_TEXTONE = 13;
public const int THEME_BACKGROUNDTWO = 14;
public const int THEME_TEXTTWO = 15;
public const int THEME_MAX = 15;
}
}

View File

@@ -0,0 +1,87 @@
using System;
/*
* $Id: RtfParserException.cs,v 1.2 2008/05/13 11:26:02 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.exceptions {
/*
* Signals that an error has occurred in a <CODE>RtfParser</CODE>.
*/
/**
* <code>RtfParserException</code> is the exception object thrown by
* the parser
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfParserException : Exception {
/**
* Creates a RtfParserException object.
* @param ex an exception that has to be turned into a RtfParserException
*/
public RtfParserException(Exception ex) : base("", ex) {
}
// constructors
/**
* Constructs a <CODE>RtfParserException</CODE> whithout a message.
*/
public RtfParserException() : base() {
}
/**
* Constructs a <code>RtfParserException</code> with a message.
*
* @param message a message describing the exception
*/
public RtfParserException(String message) : base(message) {
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
namespace iTextSharp.text.rtf.parser.exceptions {
public class RtfUnknownCtrlWordException : RtfParserException {
// constructors
/**
* Constructs a <CODE>RtfParserException</CODE> whithout a message.
*/
public RtfUnknownCtrlWordException() : base("Unknown control word.") {
}
}
}

View File

@@ -0,0 +1,71 @@
using System;
using iTextSharp.text.rtf.parser;
/*
* $Id: IRtfPropertyListener.cs,v 1.2 2008/05/13 11:26:03 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.properties {
/**
* <code>RtfPropertyListener</code> interface for handling events.
*
* @author Howard Shank (hgshank@yahoo.com)
*
* @since 2.0.8
*/
public interface IRtfPropertyListener : IEventListener {
/**
*
*/
void BeforePropertyChange(String propertyName);
/**
*
*/
void AfterPropertyChange(String propertyName);
}
}

View File

@@ -0,0 +1,58 @@
/* $Id: RtfCtrlWordPropertyType.cs,v 1.3 2008/05/13 11:26:03 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.properties {
public class RtfCtrlWordPropertyType {
public const int UNIDENTIFIED = -1;
public const int PROPERTY = 0;
public const int CHARACTER = 1;
public const int SPECIAL = 2;
public const int DESTINATION = 3;
}
}

View File

@@ -0,0 +1,575 @@
using System;
using System.Collections;
using iTextSharp.text;
using iTextSharp.text.rtf.parser.ctrlwords;
/* $Id: RtfProperty.cs,v 1.3 2008/05/13 11:26:03 psoares33 Exp $
*
*
* Copyright 2007 by Howard Shank (hgshank@yahoo.com)
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999-2006 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000-2006 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
namespace iTextSharp.text.rtf.parser.properties {
/**
* <code>RtfProperty</code> handles document, paragraph, etc. property values
*
* @author Howard Shank (hgshank@yahoo.com)
* @since 2.0.8
*/
public class RtfProperty {
public const int OFF = 0;
public const int ON = 1;
/* property groups */
public const String COLOR = "color.";
public const String CHARACTER = "character.";
public const String PARAGRAPH = "paragraph.";
public const String SECTION = "section.";
public const String DOCUMENT = "document.";
/* color properties */
public const String COLOR_FG = COLOR + "fg"; //Color Object
public const String COLOR_BG = COLOR + "bg"; //Color Object
/* character properties */
public const String CHARACTER_BOLD = CHARACTER + "bold";
public const String CHARACTER_UNDERLINE = CHARACTER + "underline";
public const String CHARACTER_ITALIC = CHARACTER + "italic";
public const String CHARACTER_SIZE = CHARACTER + "size";
public const String CHARACTER_FONT = CHARACTER + "font";
public const String CHARACTER_STYLE = CHARACTER + "style";
/* paragraph properties */
/** Justify left */
public const int JUSTIFY_LEFT = 0;
/** Justify right */
public const int JUSTIFY_RIGHT = 1;
/** Justify center */
public const int JUSTIFY_CENTER = 2;
/** Justify full */
public const int JUSTIFY_FULL = 3;
public const String PARAGRAPH_INDENT_LEFT = PARAGRAPH + "indentLeft"; // twips
public const String PARAGRAPH_INDENT_RIGHT = PARAGRAPH + "indentRight"; // twips
public const String PARAGRAPH_INDENT_FIRST_LINE = PARAGRAPH + "indentFirstLine"; // twips
public const String PARAGRAPH_JUSTIFICATION = PARAGRAPH + "justification";
public const String PARAGRAPH_BORDER = PARAGRAPH + "border";
public const String PARAGRAPH_BORDER_CELL = PARAGRAPH + "borderCell";
/** possible border settting */
public const int PARAGRAPH_BORDER_NIL = 0;
/** possible border settting */
public const int PARAGRAPH_BORDER_BOTTOM = 1;
/** possible border settting */
public const int PARAGRAPH_BORDER_TOP = 2;
/** possible border settting */
public const int PARAGRAPH_BORDER_LEFT = 4;
/** possible border settting */
public const int PARAGRAPH_BORDER_RIGHT = 8;
/** possible border settting */
public const int PARAGRAPH_BORDER_DIAGONAL_UL_LR = 16;
/** possible border settting */
public const int PARAGRAPH_BORDER_DIAGONAL_UR_LL = 32;
/** possible border settting */
public const int PARAGRAPH_BORDER_TABLE_HORIZONTAL = 64;
/** possible border settting */
public const int PARAGRAPH_BORDER_TABLE_VERTICAL = 128;
/* section properties */
/** Decimal number format */
public const int PGN_DECIMAL = 0;
/** Uppercase Roman Numeral */
public const int PGN_ROMAN_NUMERAL_UPPERCASE = 1;
/** Lowercase Roman Numeral */
public const int PGN_ROMAN_NUMERAL_LOWERCASE = 2;
/** Uppercase Letter */
public const int PGN_LETTER_UPPERCASE = 3;
/** Lowercase Letter */
public const int PGN_LETTER_LOWERCASE = 4;
/** Section Break None */
public const int SBK_NONE = 0;
/** Section Break Column break */
public const int SBK_COLUMN = 1;
/** Section Break Even page break */
public const int SBK_EVEN = 2;
/** Section Break Odd page break */
public const int SBK_ODD = 3;
/** Section Break Page break */
public const int SBK_PAGE = 4;
public const String SECTION_NUMBER_OF_COLUMNS = SECTION + "numberOfColumns";
public const String SECTION_BREAK_TYPE = SECTION + "SectionBreakType";
public const String SECTION_PAGE_NUMBER_POSITION_X = SECTION + "pageNumberPositionX";
public const String SECTION_PAGE_NUMBER_POSITION_Y = SECTION + "pageNumberPositionY";
public const String SECTION_PAGE_NUMBER_FORMAT = SECTION + "pageNumberFormat";
/* document properties */
/** Portrait orientation */
public const String PAGE_PORTRAIT = "0";
/** Landscape orientation */
public const String PAGE_LANDSCAPE = "1";
public const String DOCUMENT_PAGE_WIDTH_TWIPS = DOCUMENT + "pageWidthTwips";
public const String DOCUMENT_PAGE_HEIGHT_TWIPS = DOCUMENT + "pageHeightTwips";
public const String DOCUMENT_MARGIN_LEFT_TWIPS = DOCUMENT + "marginLeftTwips";
public const String DOCUMENT_MARGIN_TOP_TWIPS = DOCUMENT + "marginTopTwips";
public const String DOCUMENT_MARGIN_RIGHT_TWIPS = DOCUMENT + "marginRightTwips";
public const String DOCUMENT_MARGIN_BOTTOM_TWIPS = DOCUMENT + "marginBottomTwips";
public const String DOCUMENT_PAGE_NUMBER_START = DOCUMENT + "pageNumberStart";
public const String DOCUMENT_ENABLE_FACING_PAGES = DOCUMENT + "enableFacingPages";
public const String DOCUMENT_PAGE_ORIENTATION = DOCUMENT + "pageOrientation";
public const String DOCUMENT_DEFAULT_FONT_NUMER = DOCUMENT + "defaultFontNumber";
/** Properties for this RtfProperty object */
protected Hashtable properties = new Hashtable();
private bool modifiedCharacter = false;
private bool modifiedParagraph = false;
private bool modifiedSection = false;
private bool modifiedDocument = false;
/** The <code>RtfPropertyListener</code>. */
private ArrayList listeners = new ArrayList();
/**
* Set all property objects to default values.
* @since 2.0.8
*/
public void SetToDefault() {
SetToDefault(COLOR);
SetToDefault(CHARACTER);
SetToDefault(PARAGRAPH);
SetToDefault(SECTION);
SetToDefault(DOCUMENT);
}
/**
* Set individual property group to default values.
* @param propertyGroup <code>String</code> name of the property group to set to default.
* @since 2.0.8
*/
public void SetToDefault(String propertyGroup) {
if (COLOR.Equals(propertyGroup)) {
SetProperty(COLOR_FG, new Color(0,0,0));
SetProperty(COLOR_BG, new Color(255,255,255));
return;
}
if (CHARACTER.Equals(propertyGroup)) {
SetProperty(CHARACTER_BOLD, 0);
SetProperty(CHARACTER_UNDERLINE, 0);
SetProperty(CHARACTER_ITALIC, 0);
SetProperty(CHARACTER_SIZE, 24);// 1/2 pt sizes
SetProperty(CHARACTER_FONT, 0);
return;
}
if (PARAGRAPH.Equals(propertyGroup)) {
SetProperty(PARAGRAPH_INDENT_LEFT, 0);
SetProperty(PARAGRAPH_INDENT_RIGHT, 0);
SetProperty(PARAGRAPH_INDENT_FIRST_LINE, 0);
SetProperty(PARAGRAPH_JUSTIFICATION, JUSTIFY_LEFT);
SetProperty(PARAGRAPH_BORDER, PARAGRAPH_BORDER_NIL);
SetProperty(PARAGRAPH_BORDER_CELL, PARAGRAPH_BORDER_NIL);
return;
}
if (SECTION.Equals(propertyGroup)) {
SetProperty(SECTION_NUMBER_OF_COLUMNS, 0);
SetProperty(SECTION_BREAK_TYPE, SBK_NONE);
SetProperty(SECTION_PAGE_NUMBER_POSITION_X, 0);
SetProperty(SECTION_PAGE_NUMBER_POSITION_Y, 0);
SetProperty(SECTION_PAGE_NUMBER_FORMAT, PGN_DECIMAL);
return;
}
if (DOCUMENT.Equals(propertyGroup)) {
SetProperty(DOCUMENT_PAGE_WIDTH_TWIPS, 12240);
SetProperty(DOCUMENT_PAGE_HEIGHT_TWIPS, 15480);
SetProperty(DOCUMENT_MARGIN_LEFT_TWIPS, 1800);
SetProperty(DOCUMENT_MARGIN_TOP_TWIPS, 1440);
SetProperty(DOCUMENT_MARGIN_RIGHT_TWIPS, 1800);
SetProperty(DOCUMENT_MARGIN_BOTTOM_TWIPS, 1440);
SetProperty(DOCUMENT_PAGE_NUMBER_START, 1);
SetProperty(DOCUMENT_ENABLE_FACING_PAGES, 1);
SetProperty(DOCUMENT_PAGE_ORIENTATION, PAGE_PORTRAIT);
SetProperty(DOCUMENT_DEFAULT_FONT_NUMER, 0);
return;
}
}
/**
* Toggle the value of the property identified by the <code>RtfCtrlWordData.specialHandler</code> parameter.
* Toggle values are assumed to be integer values per the RTF spec with a value of 0=off or 1=on.
*
* @param ctrlWordData The property name to set
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code> or <i>blank</i>
*/
public bool ToggleProperty(RtfCtrlWordData ctrlWordData) { //String propertyName) {
String propertyName = ctrlWordData.specialHandler;
if (propertyName == null || propertyName.Length == 0) return false;
Object propertyValue = GetProperty(propertyName);
if (propertyValue == null) {
propertyValue = RtfProperty.ON;
} else {
if (propertyValue is int) {
int value = (int)propertyValue;
if (value != 0) {
RemoveProperty(propertyName);
}
return true;
} else {
if (propertyValue is long) {
long value = (long)propertyValue;
if (value != 0) {
RemoveProperty(propertyName);
}
return true;
}
}
}
SetProperty(propertyName, propertyValue);
return true;
}
/**
* Set the value of the property identified by the parameter.
*
* @param ctrlWordData The controlword with the name to set
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> or <code>propertyValue</code> is <code>null</code>
*/
public bool SetProperty(RtfCtrlWordData ctrlWordData) { //String propertyName, Object propertyValueNew) {
String propertyName = ctrlWordData.specialHandler;
Object propertyValueNew = ctrlWordData.param;
// depending on the control word, set mulitiple or reset settings, etc.
//if pard then reset settings
//
SetProperty(propertyName, propertyValueNew);
return true;
}
/**
* Set the value of the property identified by the parameter.
*
* @param propertyName The property name to set
* @param propertyValueNew The object to set the property value to
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> or <code>propertyValue</code> is <code>null</code>
*/
private bool SetProperty(String propertyName, Object propertyValueNew) {
if (propertyName == null || propertyValueNew == null) return false;
Object propertyValueOld = GetProperty(propertyName);
if (propertyValueOld is int && propertyValueNew is int) {
int valueOld = (int)propertyValueOld;
int valueNew = (int)propertyValueNew;
if (valueOld==valueNew) return true;
} else {
if (propertyValueOld is long && propertyValueNew is long) {
long valueOld = (long)propertyValueOld;
long valueNew = (long)propertyValueNew;
if (valueOld==valueNew) return true;
}
}
BeforeChange(propertyName);
properties[propertyName] = propertyValueNew;
AfterChange(propertyName);
SetModified(propertyName, true);
return true;
}
/**
* Set the value of the property identified by the parameter.
*
* @param propertyName The property name to set
* @param propertyValue The object to set the property value to
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
*/
private bool SetProperty(String propertyName, int propertyValueNew) {
if (propertyName == null) return false;
Object propertyValueOld = GetProperty(propertyName);
if (propertyValueOld is int) {
int valueOld = (int)propertyValueOld;
if (valueOld==propertyValueNew) return true;
}
BeforeChange(propertyName);
properties[propertyName] = propertyValueNew;
AfterChange(propertyName);
SetModified(propertyName, true);
return true;
}
/**
* Add the value of the property identified by the parameter.
*
* @param propertyName The property name to set
* @param propertyValue The object to set the property value to
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
*/
private bool AddToProperty(String propertyName, int propertyValue) {
if (propertyName == null) return false;
int value = (int)properties[propertyName];
if ((value | propertyValue) == value) return true;
value |= propertyValue;
BeforeChange(propertyName);
properties[propertyName] = value;
AfterChange(propertyName);
SetModified(propertyName, true);
return true;
}
/**
* Set the value of the property identified by the parameter.
*
* @param propertyName The property name to set
* @param propertyValue The object to set the property value to
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
*/
private bool SetProperty(String propertyName, long propertyValueNew) {
if (propertyName == null) return false;
Object propertyValueOld = GetProperty(propertyName);
if (propertyValueOld is long) {
long valueOld = (long)propertyValueOld;
if (valueOld==propertyValueNew) return true;
}
BeforeChange(propertyName);
properties[propertyName] = propertyValueNew;
AfterChange(propertyName);
SetModified(propertyName, true);
return true;
}
/**
* Add the value of the property identified by the parameter.
*
* @param propertyName The property name to set
* @param propertyValue The object to set the property value to
* @return <code>true</code> for handled or <code>false</code> if <code>propertyName</code> is <code>null</code>
*/
private bool AddToProperty(String propertyName, long propertyValue) {
if (propertyName == null) return false;
long value = (long)properties[propertyName];
if ((value | propertyValue) == value) return true;
value |= propertyValue;
BeforeChange(propertyName);
properties[propertyName] = value;
AfterChange(propertyName);
SetModified(propertyName, true);
return true;
}
private bool RemoveProperty(String propertyName) {
if (propertyName == null) return false;
if (properties.ContainsKey(propertyName)) {
BeforeChange(propertyName);
properties.Remove(propertyName);
AfterChange(propertyName);
SetModified(propertyName, true);
}
return true;
}
/**
* Get the value of the property identified by the parameter.
*
* @param propertyName String containing the property name to get
* @return Property Object requested or null if not found in map.
*/
public Object GetProperty(String propertyName) {
return properties[propertyName];
}
/**
* Get a group of properties.
*
* @param propertyGroup The group name to obtain.
* @return Properties object with requested values.
*/
public Hashtable GetProperties(String propertyGroup) {
Hashtable props = new Hashtable();
if (properties.Count != 0) {
//properties.get
foreach (String key in properties.Keys) {
if (key.StartsWith(propertyGroup)) {
props[key] = properties[key];
}
}
}
return props;
}
/**
* @return the modified
*/
public bool IsModified() {
return modifiedCharacter || modifiedParagraph || modifiedSection || modifiedDocument;
}
/**
* @param propertyName the propertyName that is modified
* @param modified the modified to set
*/
public void SetModified(String propertyName, bool modified) {
if (propertyName.StartsWith(CHARACTER)) {
this.SetModifiedCharacter(modified);
} else {
if (propertyName.StartsWith(PARAGRAPH)) {
this.SetModifiedParagraph(modified);
} else {
if (propertyName.StartsWith(SECTION)) {
this.SetModifiedSection(modified);
} else {
if (propertyName.StartsWith(DOCUMENT)) {
this.SetModifiedDocument(modified);
}
}
}
}
}
/**
* @return the modifiedCharacter
*/
public bool IsModifiedCharacter() {
return modifiedCharacter;
}
/**
* @param modifiedCharacter the modifiedCharacter to set
*/
public void SetModifiedCharacter(bool modifiedCharacter) {
this.modifiedCharacter = modifiedCharacter;
}
/**
* @return the modifiedParagraph
*/
public bool IsModifiedParagraph() {
return modifiedParagraph;
}
/**
* @param modifiedParagraph the modifiedParagraph to set
*/
public void SetModifiedParagraph(bool modifiedParagraph) {
this.modifiedParagraph = modifiedParagraph;
}
/**
* @return the modifiedSection
*/
public bool IsModifiedSection() {
return modifiedSection;
}
/**
* @param modifiedSection the modifiedSection to set
*/
public void SetModifiedSection(bool modifiedSection) {
this.modifiedSection = modifiedSection;
}
/**
* @return the modifiedDocument
*/
public bool IsModifiedDocument() {
return modifiedDocument;
}
/**
* @param modifiedDocument the modifiedDocument to set
*/
public void SetModifiedDocument(bool modifiedDocument) {
this.modifiedDocument = modifiedDocument;
}
/**
* Adds a <CODE>RtfPropertyListener</CODE> to the <CODE>RtfProperty</CODE>.
*
* @param listener
* the new RtfPropertyListener.
*/
public void AddRtfPropertyListener(IRtfPropertyListener listener) {
listeners.Add(listener);
}
/**
* Removes a <CODE>RtfPropertyListener</CODE> from the <CODE>RtfProperty</CODE>.
*
* @param listener
* the new RtfPropertyListener.
*/
public void RemoveRtfPropertyListener(IRtfPropertyListener listener) {
listeners.Remove(listener);
}
public void BeforeChange(String propertyName) {
// call listener for all
foreach (IRtfPropertyListener listener in listeners) {
listener.BeforePropertyChange(propertyName);
}
if (propertyName.StartsWith(CHARACTER)) {
// call listener for character chane
} else {
if (propertyName.StartsWith(PARAGRAPH)) {
// call listener for paragraph change
} else {
if (propertyName.StartsWith(SECTION)) {
// call listener for section change
} else {
if (propertyName.StartsWith(DOCUMENT)) {
// call listener for document change
}
}
}
}
}
public void AfterChange(String propertyName) {
// call listener for all
foreach (IRtfPropertyListener listener in listeners) {
listener.AfterPropertyChange(propertyName);
}
if (propertyName.StartsWith(CHARACTER)) {
// call listener for character chane
} else {
if (propertyName.StartsWith(PARAGRAPH)) {
// call listener for paragraph change
} else {
if (propertyName.StartsWith(SECTION)) {
// call listener for section change
} else {
if (propertyName.StartsWith(DOCUMENT)) {
// call listener for document change
}
}
}
}
}
}
}