示例#1
0
        /**
         * Writes the content of the RtfList
         * @since 2.1.3
         */
        public override void WriteContent(Stream result)
        {
            if (!this.inTable)
            {
                result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
            }

            int itemNr = 0;

            if (items != null)
            {
                for (int i = 0; i < items.Count; i++)
                {
                    RtfElement thisRtfElement = (RtfElement)items[i];
                    //thisRtfElement.WriteContent(result);
                    if (thisRtfElement is RtfListItem)
                    {
                        itemNr++;
                        RtfListItem  rtfElement = (RtfListItem)thisRtfElement;
                        RtfListLevel listLevel  = rtfElement.GetParent();
                        if (listLevel.GetListLevel() == 0)
                        {
                            CorrectIndentation();
                        }

                        if (i == 0)
                        {
                            listLevel.WriteListBeginning(result);
                            WriteListNumbers(result);
                        }

                        WriteListTextBlock(result, itemNr, listLevel);

                        rtfElement.WriteContent(result);

                        if (i < (items.Count - 1) || !this.inTable || listLevel.GetListType() > 0) // TODO Fix no paragraph on last list item in tables
                        {
                            result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
                        }
                        this.document.OutputDebugLinebreak(result);
                    }
                    else if (thisRtfElement is RtfList)
                    {
                        ((RtfList)thisRtfElement).WriteContent(result);
                        //              ((RtfList)thisRtfElement).WriteListBeginning(result);
                        WriteListNumbers(result);
                        this.document.OutputDebugLinebreak(result);
                    }
                }
            }
            if (!this.inTable)
            {
                result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
                result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
            }
        }
示例#2
0
 /**
  * Create a default set of listlevels
  * @since 2.1.3
  */
 protected void CreateDefaultLevels()
 {
     this.listLevels = new ArrayList();  // listlevels
     for (int i = 0; i <= 8; i++)
     {
         // create a list level
         RtfListLevel ll = new RtfListLevel(this.document);
         ll.SetListType(RtfListLevel.LIST_TYPE_NUMBERED);
         ll.SetFirstIndent(0);
         ll.SetLeftIndent(0);
         ll.SetLevelTextNumber(i);
         ll.SetTentative(true);
         ll.CorrectIndentation();
         this.listLevels.Add(ll);
     }
 }
示例#3
0
        /**
         *
         * @param result
         * @param itemNr
         * @param listLevel
         * @throws IOException
         * @since 2.1.3
         */
        protected void WriteListTextBlock(Stream result, int itemNr, RtfListLevel listLevel)
        {
            byte[] t;
            result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
            result.Write(RtfList.LIST_TEXT, 0, RtfList.LIST_TEXT.Length);
            result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
            if (this.inTable)
            {
                result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
            }
            result.Write(RtfFontList.FONT_NUMBER, 0, RtfFontList.FONT_NUMBER.Length);
            if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET)
            {
                result.Write(t = IntToByteArray(listLevel.GetFontNumber().GetFontNumber()), 0, t.Length);
            }
            else
            {
                result.Write(t = IntToByteArray(listLevel.GetFontBullet().GetFontNumber()), 0, t.Length);
            }
            listLevel.WriteIndentation(result);
            result.Write(DELIMITER, 0, DELIMITER.Length);
            if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET)
            {
                switch (listLevel.GetListType())
                {
                case RtfListLevel.LIST_TYPE_NUMBERED: result.Write(t = IntToByteArray(itemNr), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_UPPER_LETTERS: result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_LOWER_LETTERS: result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_UPPER_ROMAN: result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_LOWER_ROMAN: result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;
                }
                result.Write(LIST_NUMBER_END, 0, LIST_NUMBER_END.Length);
            }
            else
            {
                this.document.FilterSpecialChar(result, listLevel.GetBulletCharacter(), true, false);
            }
            result.Write(TAB, 0, TAB.Length);
            result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
        }
示例#4
0
 public RtfListLevel(RtfListLevel ll) : base(ll.document)
 {
     templateID           = document.GetRandomInt();
     this.alignment       = ll.alignment;
     this.bulletCharacter = ll.bulletCharacter;
     this.firstIndent     = ll.firstIndent;
     this.fontBullet      = ll.fontBullet;
     this.fontNumber      = ll.fontNumber;
     this.inHeader        = ll.inHeader;
     this.inTable         = ll.inTable;
     this.leftIndent      = ll.leftIndent;
     this.listLevel       = ll.listLevel;
     this.listNoRestart   = ll.listNoRestart;
     this.listStartAt     = ll.listStartAt;
     this.listType        = ll.listType;
     this.parent          = ll.parent;
     this.rightIndent     = ll.rightIndent;
     this.symbolIndent    = ll.symbolIndent;
 }
示例#5
0
 /**
  * Set the parent RtfList.
  *
  * @param parentList The parent RtfList to use.
  */
 public void SetParent(RtfListLevel parentList)
 {
     this.parentList = parentList;
 }
示例#6
0
        /**
         * Constructs a new RtfList for the specified List.
         *
         * @param doc The RtfDocument this RtfList belongs to
         * @param list The List this RtfList is based on
         * @since 2.1.3
         */
        public RtfList(RtfDocument doc, List list) : base(doc)
        {
            // setup the listlevels
            // Then, setup the list data below

            // setup 1 listlevel if it's a simple list
            // setup 9 if it's a regular list
            // setup 9 if it's a hybrid list (default)
            CreateDefaultLevels();

            this.items = new ArrayList();       // list content
            RtfListLevel ll = (RtfListLevel)this.listLevels[0];

            // get the list number or create a new one adding it to the table
            this.listNumber = document.GetDocumentHeader().GetListNumber(this);

            if (list.SymbolIndent > 0 && list.IndentationLeft > 0)
            {
                ll.SetFirstIndent((int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1));
                ll.SetLeftIndent((int)((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR));
            }
            else if (list.SymbolIndent > 0)
            {
                ll.SetFirstIndent((int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1));
                ll.SetLeftIndent((int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR));
            }
            else if (list.IndentationLeft > 0)
            {
                ll.SetFirstIndent(0);
                ll.SetLeftIndent((int)(list.IndentationLeft * RtfElement.TWIPS_FACTOR));
            }
            else
            {
                ll.SetFirstIndent(0);
                ll.SetLeftIndent(0);
            }
            ll.SetRightIndent((int)(list.IndentationRight * RtfElement.TWIPS_FACTOR));
            ll.SetSymbolIndent((int)((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR));
            ll.CorrectIndentation();
            ll.SetTentative(false);

            if (list is RomanList)
            {
                if (list.Lowercase)
                {
                    ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_ROMAN);
                }
                else
                {
                    ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_ROMAN);
                }
            }
            else if (list.Numbered)
            {
                ll.SetListType(RtfListLevel.LIST_TYPE_NUMBERED);
            }
            else if (list.Lettered)
            {
                if (list.Lowercase)
                {
                    ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_LETTERS);
                }
                else
                {
                    ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_LETTERS);
                }
            }
            else
            {
                //          Paragraph p = new Paragraph();
                //          p.Add(new Chunk(list.GetPreSymbol()) );
                //          p.Add(list.GetSymbol());
                //          p.Add(new Chunk(list.GetPostSymbol()) );
                //          ll.SetBulletChunk(list.GetSymbol());
                ll.SetBulletCharacter(list.PreSymbol + list.Symbol.Content + list.PostSymbol);
                ll.SetListType(RtfListLevel.LIST_TYPE_BULLET);
            }

            // now setup the actual list contents.
            for (int i = 0; i < list.Items.Count; i++)
            {
                try {
                    IElement element = (IElement)list.Items[i];

                    if (element.Type == Element.CHUNK)
                    {
                        element = new ListItem((Chunk)element);
                    }
                    if (element is ListItem)
                    {
                        ll.SetAlignment(((ListItem)element).Alignment);
                    }
                    IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element);
                    for (int j = 0; j < rtfElements.Length; j++)
                    {
                        IRtfBasicElement rtfElement = rtfElements[j];
                        if (rtfElement is RtfList)
                        {
                            ((RtfList)rtfElement).SetParentList(this);
                        }
                        else if (rtfElement is RtfListItem)
                        {
                            ((RtfListItem)rtfElement).SetParent(ll);
                        }
                        ll.SetFontNumber(new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))));
                        if (list.Symbol != null && list.Symbol.Font != null && !list.Symbol.Content.StartsWith("-") && list.Symbol.Content.Length > 0)
                        {
                            // only set this to bullet symbol is not default
                            ll.SetBulletFont(list.Symbol.Font);
                            ll.SetBulletCharacter(list.Symbol.Content.Substring(0, 1));
                        }
                        else
                        if (list.Symbol != null && list.Symbol.Font != null)
                        {
                            ll.SetBulletFont(list.Symbol.Font);
                        }
                        else
                        {
                            ll.SetBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
                        }
                        items.Add(rtfElement);
                    }
                } catch (DocumentException) {
                }
            }
        }
示例#7
0
 /**
  * @param listLevelParent the listLevelParent to set
  */
 public void SetListLevelParent(RtfListLevel listLevelParent)
 {
     this.listLevelParent = listLevelParent;
 }