Exemple #1
0
 /// <summary>
 /// (non-Javadoc)
 /// @see com.lowagie.text.rtf.direct.RtfDestination#closeDestination()
 /// </summary>
 public override bool CloseDestination()
 {
     if (_newList != null)
     {
         RtfParser.GetRtfDocument().Add(_newList);
     }
     return(true);
 }
Exemple #2
0
 /// <summary>
 /// (non-Javadoc)
 /// @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
 /// </summary>
 public override bool HandleCloseGroup()
 {
     _currentSubGroupCount--;
     if (_newList != null && _currentSubGroupCount == 0)
     {
         _importHeader.ImportList(_currentListMappingNumber.ToString(), _newList.GetListNumber().ToString());
         RtfParser.GetRtfDocument().Add(_newList);
     }
     return(true);
 }
 /// <summary>
 /// Constructs a new  RtfDestinationDocument  using
 /// the parameters to initialize the object.
 /// </summary>
 public RtfDestinationDocument(RtfParser parser) : base(parser)
 {
     _rtfDoc = parser.GetRtfDocument();
     _doc = parser.GetDocument();
     _conversionType = parser.GetConversionType();
     SetToDefaults();
     if (RtfParser.IsConvert())
     {
         RtfParser.GetState().Properties.AddRtfPropertyListener(this);
     }
 }
 public override void SetParser(RtfParser parser)
 {
     RtfParser = parser;
     _rtfDoc = parser.GetRtfDocument();
     _doc = parser.GetDocument();
     _conversionType = parser.GetConversionType();
     SetToDefaults();
     if (RtfParser.IsConvert())
     {
         RtfParser.GetState().Properties.AddRtfPropertyListener(this);
     }
 }
 private void writeText(string value)
 {
     if (RtfParser.GetState().NewGroup)
     {
         RtfParser.GetRtfDocument().Add(new RtfDirectContent("{"));
         RtfParser.GetState().NewGroup = false;
     }
     if (value.Length > 0)
     {
         RtfParser.GetRtfDocument().Add(new RtfDirectContent(value));
     }
 }
Exemple #6
0
 /// <summary>
 /// (non-Javadoc)
 /// @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd()
 /// </summary>
 public override bool HandleCloseGroup()
 {
     if (_text.Length > 0)
     {
         var doc = RtfParser.GetDocument();
         if (doc != null)
         {
             if (_elementName.Equals("author"))
             {
                 doc.AddAuthor(_text);
             }
             if (_elementName.Equals("title"))
             {
                 doc.AddTitle(_text);
             }
             if (_elementName.Equals("subject"))
             {
                 doc.AddSubject(_text);
             }
         }
         else
         {
             var rtfDoc = RtfParser.GetRtfDocument();
             if (rtfDoc != null)
             {
                 if (_elementName.Equals("author"))
                 {
                     var meta = new Meta(_elementName, _text);
                     var elem = new RtfInfoElement(rtfDoc, meta);
                     rtfDoc.GetDocumentHeader().AddInfoElement(elem);
                 }
                 if (_elementName.Equals("title"))
                 {
                     var meta = new Meta(_elementName, _text);
                     var elem = new RtfInfoElement(rtfDoc, meta);
                     rtfDoc.GetDocumentHeader().AddInfoElement(elem);
                 }
                 if (_elementName.Equals("subject"))
                 {
                     var meta = new Meta(_elementName, _text);
                     var elem = new RtfInfoElement(rtfDoc, meta);
                     rtfDoc.GetDocumentHeader().AddInfoElement(elem);
                 }
             }
         }
         SetToDefaults();
     }
     return(true);
 }
        /// <summary>
        /// The primary control word handler method.
        /// Called by the parser once it has a control word and parameter if applicable.
        /// The control word and associated parameter if applicable.
        ///  true  or  false  if the control word was handled.
        /// @since 2.0.8
        /// </summary>
        /// <param name="ctrlWordDataIn"></param>
        /// <returns></returns>
        public bool HandleControlword(RtfCtrlWordData ctrlWordDataIn)
        {
            bool result = false;

            CtrlWordData = ctrlWordDataIn;
            RtfDestination dest    = null;
            bool           handled = false;

            CtrlWordData.Prefix         = CtrlWordPrefix;
            CtrlWordData.Suffix         = CtrlWordSuffix;
            CtrlWordData.NewGroup       = RtfParser.GetState().NewGroup;
            CtrlWordData.CtrlWordType   = CtrlWordType;
            CtrlWordData.SpecialHandler = SpecialHandler;

            if (!CtrlWordData.HasParam && PassDefaultParameterValue)
            {
                CtrlWordData.HasParam = true;
                CtrlWordData.Param    = DefaultParameterValue.ToString();
            }

            if (_debug)
            {
                printDebug("handleKeyword: [" + CtrlWordData.CtrlWord + "] param=" + ctrlWordDataIn.Param);
                RtfParser.OutputDebug(RtfParser.GetRtfDocument(), RtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug Start: " + CtrlWordData.CtrlWord + " ");
            }
            if (CtrlWordData.CtrlWord.Equals("*"))
            {
                return(true);
            }

            if (!BeforeControlWord())
            {
                return(true);
            }

            switch (CtrlWordType)
            {
            case RtfCtrlWordType.FLAG:
            case RtfCtrlWordType.TOGGLE:
            case RtfCtrlWordType.VALUE:
                dest = RtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    handled = dest.HandleControlWord(CtrlWordData);
                }
                break;

            case RtfCtrlWordType.SYMBOL:
                dest = 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 (RtfParser.IsImport())
                    {
                        data = CtrlWordPrefix + CtrlWordData.CtrlWord + CtrlWordSuffix;
                    }
                    if (RtfParser.IsConvert())
                    {
                        data = 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)
                        {
                            handled = dest.HandleCharacter(cc);
                        }
                    }
                    else
                    {
                        handled = dest.HandleControlWord(CtrlWordData);
                    }
                }
                break;

            case RtfCtrlWordType.DESTINATION_EX:
            case RtfCtrlWordType.DESTINATION:
                // set the destination
                int x = 0;
                if (CtrlWord == "shppict" || CtrlWord == "nonshppict")
                {
                    x++;
                }
                handled = RtfParser.SetCurrentDestination(CtrlWord);
                // let destination handle the ctrl word now.
                dest = RtfParser.GetCurrentDestination();
                if (dest != null)
                {
                    if (dest.GetNewTokeniserState() == RtfParser.TOKENISER_IGNORE_RESULT)
                    {
                        handled = dest.HandleControlWord(CtrlWordData);
                    }
                    else
                    {
                        RtfParser.SetTokeniserState(dest.GetNewTokeniserState());
                    }
                }
                break;
            }

            AfterControlWord();

            if (_debug)
            {
                RtfParser.OutputDebug(RtfParser.GetRtfDocument(), RtfParser.GetLevel() + 1, "RtfCtrlWordHandler debug End: " + CtrlWordData.CtrlWord + " ");
            }

            return(result);
        }
Exemple #8
0
        public override bool HandleControlWord(RtfCtrlWordData ctrlWordData)
        {
            var result       = true;
            var skipCtrlWord = false;

            if (RtfParser.IsImport())
            {
                skipCtrlWord = true;
                if (ctrlWordData.CtrlWord.Equals("listtable"))
                {
                    result = true;
                    _currentListMappingNumber = 0;
                }
                else
                /* Picture info for icons/images for lists */
                if (ctrlWordData.CtrlWord.Equals("listpicture"))    /* DESTINATION */
                {
                    skipCtrlWord = true;
                    // this.rtfParser.SetTokeniserStateSkipGroup();
                    result = true;
                }
                else
                /* list */
                if (ctrlWordData.CtrlWord.Equals("list"))     /* DESTINATION */
                {
                    skipCtrlWord = true;
                    _newList     = new RtfList(RtfParser.GetRtfDocument());
                    _newList.SetListType(RtfList.LIST_TYPE_NORMAL); // set default
                    _currentLevel = -1;
                    _currentListMappingNumber++;
                    _currentSubGroupCount = 0;
                    result = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("listtemplateid")) /* // List item*/
                {
                    // ignore this because it gets regenerated in every document
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("listsimple")) /* // List item*/
                {
                    // is value 0 or 1
                    if (ctrlWordData.HasParam && ctrlWordData.Param == "1")
                    {
                        _newList.SetListType(RtfList.LIST_TYPE_SIMPLE);
                    }
                    else
                    {
                        _newList.SetListType(RtfList.LIST_TYPE_NORMAL);
                    }
                    skipCtrlWord = true;
                    result       = true;
                    // this gets set internally. Don't think it should be imported
                }
                else if (ctrlWordData.CtrlWord.Equals("listhybrid")) /* // List item*/
                {
                    _newList.SetListType(RtfList.LIST_TYPE_HYBRID);
                    skipCtrlWord = true;
                    result       = true;
                    // this gets set internally. Don't think it should be imported
                }
                else if (ctrlWordData.CtrlWord.Equals("listrestarthdn")) /* // List item*/
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("listid"))
                {    // List item cannot be between -1 and -5
                    // needs to be mapped for imports and is recreated
                    // we have the new id and the old id. Just add it to the mapping table here.
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("listname"))/* // List item*/
                {
                    _newList.SetName(ctrlWordData.Param);
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("liststyleid"))/* // List item*/
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("liststylename"))/* // List item*/
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else
                /* listlevel */
                if (ctrlWordData.CtrlWord.Equals("listlevel"))   /* DESTINATION There are 1 or 9 listlevels per list */
                {
                    _currentLevel++;
                    _currentListLevel = _newList.GetListLevel(_currentLevel);
                    _currentListLevel.SetTentative(false);
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("leveljc"))
                { // listlevel item justify
                    // this is the old number. Only use it if the current type is not set
                    if (_currentListLevel.GetAlignment() == RtfListLevel.LIST_TYPE_UNKNOWN)
                    {
                        switch (ctrlWordData.IntValue())
                        {
                        case 0:
                            _currentListLevel.SetAlignment(Element.ALIGN_LEFT);
                            break;

                        case 1:
                            _currentListLevel.SetAlignment(Element.ALIGN_CENTER);
                            break;

                        case 2:
                            _currentListLevel.SetAlignment(Element.ALIGN_RIGHT);
                            break;
                        }
                    }
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("leveljcn"))
                { // listlevel item
                    //justify
                    // if this exists, use it and it overrides the old setting
                    switch (ctrlWordData.IntValue())
                    {
                    case 0:
                        _currentListLevel.SetAlignment(Element.ALIGN_LEFT);
                        break;

                    case 1:
                        _currentListLevel.SetAlignment(Element.ALIGN_CENTER);
                        break;

                    case 2:
                        _currentListLevel.SetAlignment(Element.ALIGN_RIGHT);
                        break;
                    }
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelstartat"))
                {
                    _currentListLevel.SetListStartAt(ctrlWordData.IntValue());
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("lvltentative"))
                {
                    _currentListLevel.SetTentative(true);
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelold"))
                {
                    // old style. ignore
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelprev"))
                {
                    // old style. ignore
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelprevspace"))
                {
                    // old style. ignore
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelspace"))
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelindent"))
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("leveltext"))
                {/* FIX */
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelfollow"))
                {
                    _currentListLevel.SetLevelFollowValue(ctrlWordData.IntValue());
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levellegal"))
                {
                    _currentListLevel.SetLegal(ctrlWordData.Param == "1");
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelnorestart"))
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("chrfmt"))
                {/* FIX */
                    // set an attribute pair
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelpicture"))
                {
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("li"))
                {
                    // set an attribute pair
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("fi"))
                {
                    // set an attribute pair
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("jclisttab"))
                {
                    // set an attribute pair
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("tx"))
                {
                    // set an attribute pair
                    skipCtrlWord = true;
                    result       = true;
                }
                else
                /* number */
                if (ctrlWordData.CtrlWord.Equals("levelnfc"))   /* old style */
                {
                    if (_currentListLevel.GetListType() == RtfListLevel.LIST_TYPE_UNKNOWN)
                    {
                        _currentListLevel.SetListType(ctrlWordData.IntValue() + RtfListLevel.LIST_TYPE_BASE);
                    }
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.CtrlWord.Equals("levelnfcn")) /* new style takes priority over levelnfc.*/
                {
                    _currentListLevel.SetListType(ctrlWordData.IntValue() + RtfListLevel.LIST_TYPE_BASE);
                    skipCtrlWord = true;
                    result       = true;
                }
                else
                /* level text */
                if (ctrlWordData.CtrlWord.Equals("leveltemplateid"))
                {
                    // ignore. this value is regenerated in each document.
                    skipCtrlWord = true;
                    result       = true;
                }
                else
                /* levelnumber */
                if (ctrlWordData.CtrlWord.Equals("levelnumbers"))
                {
                    skipCtrlWord = true;
                    result       = true;
                }
            }

            if (RtfParser.IsConvert())
            {
                if (ctrlWordData.CtrlWord.Equals("shppict"))
                {
                    result = true;
                }
                if (ctrlWordData.CtrlWord.Equals("nonshppict"))
                {
                    skipCtrlWord = true;
                    RtfParser.SetTokeniserStateSkipGroup();
                    result = true;
                }
            }
            if (!skipCtrlWord)
            {
                switch (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);
        }