Esempio n. 1
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);

            rtfList.SetRtfDocument(this.rtfDoc);
            return(true);
        }
 /**
  * Removes a RtfList from the list table
  *
  * @param list The RtfList to remove
  */
 public void FreeListNumber(RtfList list)
 {
     this.listTable.FreeListNumber(list);
 }
 /**
  * Gets the number of the specified RtfList
  *
  * @param list The RtfList for which to get the number
  * @return The number of the list
  */
 public int GetListNumber(RtfList list)
 {
     return(this.listTable.GetListNumber(list));
 }
Esempio n. 4
0
        /**
         * Takes an Element subclass and returns the correct IRtfBasicElement
         * subclass, that wraps the Element subclass.
         *
         * @param element The Element to wrap
         * @return A IRtfBasicElement wrapping the Element
         * @throws DocumentException
         */
        public IRtfBasicElement MapElement(IElement element)
        {
            IRtfBasicElement rtfElement = null;

            if (element is IRtfBasicElement)
            {
                rtfElement = (IRtfBasicElement)element;
                rtfElement.SetRtfDocument(this.rtfDoc);
                return(rtfElement);
            }
            switch (element.Type)
            {
            case Element.CHUNK:
                if (((Chunk)element).GetImage() != null)
                {
                    rtfElement = new RtfImage(rtfDoc, ((Chunk)element).GetImage());
                }
                else if (((Chunk)element).HasAttributes() && ((Chunk)element).Attributes.ContainsKey(Chunk.NEWPAGE))
                {
                    rtfElement = new RtfNewPage(rtfDoc);
                }
                else
                {
                    rtfElement = new RtfChunk(rtfDoc, (Chunk)element);
                }
                break;

            case Element.PHRASE:
                rtfElement = new RtfPhrase(rtfDoc, (Phrase)element);
                break;

            case Element.PARAGRAPH:
                rtfElement = new RtfParagraph(rtfDoc, (Paragraph)element);
                break;

            case Element.ANCHOR:
                rtfElement = new RtfAnchor(rtfDoc, (Anchor)element);
                break;

            case Element.ANNOTATION:
                rtfElement = new RtfAnnotation(rtfDoc, (Annotation)element);
                break;

            case Element.IMGRAW:
            case Element.IMGTEMPLATE:
            case Element.JPEG:
                rtfElement = new RtfImage(rtfDoc, (Image)element);
                break;

            case Element.AUTHOR:
            case Element.SUBJECT:
            case Element.KEYWORDS:
            case Element.TITLE:
            case Element.PRODUCER:
            case Element.CREATIONDATE:
                rtfElement = new RtfInfoElement(rtfDoc, (Meta)element);
                break;

            case Element.LIST:
                rtfElement = new RtfList(rtfDoc, (List)element);
                break;

            case Element.LISTITEM:
                rtfElement = new RtfListItem(rtfDoc, (ListItem)element);
                break;

            case Element.SECTION:
                rtfElement = new RtfSection(rtfDoc, (Section)element);
                break;

            case Element.CHAPTER:
                rtfElement = new RtfChapter(rtfDoc, (Chapter)element);
                break;

            case Element.TABLE:
                try {
                    rtfElement = new TB.RtfTable(rtfDoc, (Table)element);
                }
                catch (InvalidCastException) {
                    rtfElement = new TB.RtfTable(rtfDoc, ((SimpleTable)element).CreateTable());
                }
                break;
            }

            return(rtfElement);
        }
Esempio n. 5
0
        public override bool HandleControlWord(RtfCtrlWordData ctrlWordData)
        {
            bool result       = true;
            bool skipCtrlWord = false;

            if (this.rtfParser.IsImport())
            {
                skipCtrlWord = true;
                if (ctrlWordData.ctrlWord.Equals("listtable"))
                {
                    result = true;
                    this.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;
                    this.newList = new RtfList(this.rtfParser.GetRtfDocument());
                    this.newList.SetListType(RtfList.LIST_TYPE_NORMAL); // set default
                    this.currentLevel = -1;
                    this.currentListMappingNumber++;
                    this.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")
                    {
                        this.newList.SetListType(RtfList.LIST_TYPE_SIMPLE);
                    }
                    else
                    {
                        this.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*/
                {
                    this.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*/
                {
                    this.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 */
                {
                    this.currentLevel++;
                    this.currentListLevel = this.newList.GetListLevel(this.currentLevel);
                    this.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 (this.currentListLevel.GetAlignment() == RtfListLevel.LIST_TYPE_UNKNOWN)
                    {
                        switch (ctrlWordData.IntValue())
                        {
                        case 0:
                            this.currentListLevel.SetAlignment(Element.ALIGN_LEFT);
                            break;

                        case 1:
                            this.currentListLevel.SetAlignment(Element.ALIGN_CENTER);
                            break;

                        case 2:
                            this.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:
                        this.currentListLevel.SetAlignment(Element.ALIGN_LEFT);
                        break;

                    case 1:
                        this.currentListLevel.SetAlignment(Element.ALIGN_CENTER);
                        break;

                    case 2:
                        this.currentListLevel.SetAlignment(Element.ALIGN_RIGHT);
                        break;
                    }
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.ctrlWord.Equals("levelstartat"))
                {
                    this.currentListLevel.SetListStartAt(ctrlWordData.IntValue());
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.ctrlWord.Equals("lvltentative"))
                {
                    this.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"))
                {
                    this.currentListLevel.SetLevelFollowValue(ctrlWordData.IntValue());
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.ctrlWord.Equals("levellegal"))
                {
                    this.currentListLevel.SetLegal(ctrlWordData.param == "1"?true:false);
                    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 (this.currentListLevel.GetListType() == RtfListLevel.LIST_TYPE_UNKNOWN)
                    {
                        this.currentListLevel.SetListType(ctrlWordData.IntValue() + RtfListLevel.LIST_TYPE_BASE);
                    }
                    skipCtrlWord = true;
                    result       = true;
                }
                else if (ctrlWordData.ctrlWord.Equals("levelnfcn"))   /* new style takes priority over levelnfc.*/
                {
                    this.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 (this.rtfParser.IsConvert())
            {
                if (ctrlWordData.ctrlWord.Equals("shppict"))
                {
                    result = true;
                }
                if (ctrlWordData.ctrlWord.Equals("nonshppict"))
                {
                    skipCtrlWord = true;
                    this.rtfParser.SetTokeniserStateSkipGroup();
                    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);
        }
Esempio n. 6
0
        private void ReadListTable(Reader reader)
        {
            ListTable = new ListTable();
            while (reader.ReadToken() != null)
            {
                if (reader.TokenType == RtfTokenType.GroupEnd)
                    break;

                if (reader.TokenType == RtfTokenType.GroupStart)
                {
                    var firstRead = true;
                    RtfList currentList = null;
                    var level = reader.Level;
                    while (reader.ReadToken() != null)
                    {
                        if (reader.TokenType == RtfTokenType.GroupEnd)
                        {
                            if (reader.Level < level)
                            {
                                break;
                            }
                        }
                        else if (reader.TokenType == RtfTokenType.GroupStart)
                        {
                            // if meet nested level , then ignore
                            //reader.ReadToken();
                            //ReadToEndGround(reader);
                            //reader.ReadToken();
                        }
                        if (firstRead)
                        {
                            if (reader.CurrentToken.Key != "list")
                            {
                                // 不是以list开头,忽略掉
                                ReadToEndGround(reader);
                                reader.ReadToken();
                                break;
                            }
                            currentList = new RtfList();
                            ListTable.Add(currentList);
                            firstRead = false;
                        }

                        switch (reader.CurrentToken.Key)
                        {
                            case "listtemplateid":
                                currentList.ListTemplateId = reader.CurrentToken.Param;
                                break;

                            case "listid":
                                currentList.ListId = reader.CurrentToken.Param;
                                break;

                            case "listhybrid":
                                currentList.ListHybrid = true;
                                break;

                            case "levelfollow":
                                currentList.LevelFollow = reader.CurrentToken.Param;
                                break;

                            case "levelstartat":
                                currentList.LevelStartAt = reader.CurrentToken.Param;
                                break;

                            case "levelnfc":
                                if (currentList.LevelNfc == RtfLevelNumberType.None)
                                    currentList.LevelNfc = (RtfLevelNumberType) reader.CurrentToken.Param;
                                break;

                            case "levelnfcn":
                                if (currentList.LevelNfc == RtfLevelNumberType.None)
                                    currentList.LevelNfc = (RtfLevelNumberType) reader.CurrentToken.Param;
                                break;

                            case "leveljc":
                                currentList.LevelJc = reader.CurrentToken.Param;
                                break;

                            case "leveltext":
                                if (string.IsNullOrEmpty(currentList.LevelText))
                                {
                                    var text = ReadInnerText(reader, true);
                                    if (text != null && text.Length > 2)
                                    {
                                        int len = text[0];
                                        len = Math.Min(len, text.Length - 1);
                                        text = text.Substring(1, len);
                                    }
                                    currentList.LevelText = text;
                                }
                                break;

                            case "f":
                                currentList.FontName = FontTable.GetFontName(reader.CurrentToken.Param);
                                break;
                        }
                    }
                }
            } 
        }