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,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;
}
}