Exemplo n.º 1
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
        */
        public RtfList(RtfDocument doc, List list)
            : base(doc)
        {
            this.listNumber = document.GetDocumentHeader().GetListNumber(this);

            this.items = new ArrayList();
            if (list.SymbolIndent > 0 && list.IndentationLeft > 0) {
                this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1);
                this.leftIndent = (int) ((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR);
            } else if (list.SymbolIndent > 0) {
                this.firstIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1);
                this.leftIndent = (int) (list.SymbolIndent * RtfElement.TWIPS_FACTOR);
            } else if (list.IndentationLeft > 0) {
                this.firstIndent = 0;
                this.leftIndent = (int) (list.IndentationLeft * RtfElement.TWIPS_FACTOR);
            } else {
                this.firstIndent = 0;
                this.leftIndent = 0;
            }
            this.rightIndent = (int) (list.IndentationRight * RtfElement.TWIPS_FACTOR);
            this.symbolIndent = (int) ((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR);
            this.numbered = list.IsNumbered();

            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) {
                        this.alignment = ((ListItem) element).Alignment;
                    }
                    IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element);
                    if (rtfElement is RtfList) {
                        ((RtfList) rtfElement).SetListNumber(listNumber);
                        ((RtfList) rtfElement).SetListLevel(listLevel + 1);
                        ((RtfList) rtfElement).SetParent(this);
                    } else if (rtfElement is RtfListItem) {
                        ((RtfListItem) rtfElement).SetParent(this);
                        ((RtfListItem) rtfElement).InheritListSettings(listNumber, listLevel + 1);
                    }
                    items.Add(rtfElement);
                } catch (DocumentException ) {
                }
            }
            if (this.listLevel == 0) {
                CorrectIndentation();
            }

            fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
            fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
        }
Exemplo n.º 2
0
 /**
 * Write a <code>List</code>
 *
 * @param list The <code>List</code> to be written
 * @param outp The <code>MemoryStream</code> to write to
 *
 * @throws    IOException
 * @throws    DocumentException
 */
 private void WriteList(List list, MemoryStream outp)
 {
     int type = 0;
     int align = 0;
     int fontNr = AddFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
     if (!list.IsNumbered()) type = 23;
     if (listLevel == 0) {
         maxListLevel = 0;
         listtable.WriteByte(openGroup);
         listtable.WriteByte(escape);
         listtable.Write(listDefinition, 0, listDefinition.Length);
         int i = GetRandomInt();
         listtable.WriteByte(escape);
         listtable.Write(listTemplateID, 0, listTemplateID.Length);
         WriteInt(listtable, i);
         listtable.WriteByte(escape);
         listtable.Write(hybridList, 0, hybridList.Length);
         listtable.WriteByte((byte) '\n');
     }
     if (listLevel >= maxListLevel) {
         maxListLevel++;
         listtable.WriteByte(openGroup);
         listtable.WriteByte(escape);
         listtable.Write(listLevelDefinition, 0, listLevelDefinition.Length);
         listtable.WriteByte(escape);
         listtable.Write(listLevelTypeOld, 0, listLevelTypeOld.Length);
         WriteInt(listtable, type);
         listtable.WriteByte(escape);
         listtable.Write(listLevelTypeNew, 0, listLevelTypeNew.Length);
         WriteInt(listtable, type);
         listtable.WriteByte(escape);
         listtable.Write(listLevelAlignOld, 0, listLevelAlignOld.Length);
         WriteInt(listtable, align);
         listtable.WriteByte(escape);
         listtable.Write(listLevelAlignNew, 0, listLevelAlignNew.Length);
         WriteInt(listtable, align);
         listtable.WriteByte(escape);
         listtable.Write(listLevelStartAt, 0, listLevelStartAt.Length);
         WriteInt(listtable, 1);
         listtable.WriteByte(openGroup);
         listtable.WriteByte(escape);
         listtable.Write(listLevelTextDefinition, 0, listLevelTextDefinition.Length);
         listtable.WriteByte(escape);
         listtable.Write(listLevelTextLength, 0, listLevelTextLength.Length);
         if (list.IsNumbered()) {
             WriteInt(listtable, 2);
         } else {
             WriteInt(listtable, 1);
         }
         listtable.WriteByte(escape);
         if (list.IsNumbered()) {
             listtable.Write(listLevelTextStyleNumbers, 0, listLevelTextStyleNumbers.Length);
         } else {
             listtable.Write(listLevelTextStyleBullet, 0, listLevelTextStyleBullet.Length);
         }
         listtable.WriteByte(commaDelimiter);
         listtable.WriteByte(closeGroup);
         listtable.WriteByte(openGroup);
         listtable.WriteByte(escape);
         listtable.Write(listLevelNumbersDefinition, 0, listLevelNumbersDefinition.Length);
         if (list.IsNumbered()) {
             listtable.WriteByte(delimiter);
             listtable.Write(listLevelNumbers, 0, listLevelNumbers.Length);
             WriteInt(listtable, listLevel + 1);
         }
         listtable.WriteByte(commaDelimiter);
         listtable.WriteByte(closeGroup);
         if (!list.IsNumbered()) {
             listtable.WriteByte(escape);
             listtable.WriteByte(fontNumber);
             WriteInt(listtable, fontNr);
         }
         listtable.WriteByte(escape);
         listtable.Write(firstIndent, 0, firstIndent.Length);
         WriteInt(listtable, (int) (list.IndentationLeft * TWIPSFACTOR * -1));
         listtable.WriteByte(escape);
         listtable.Write(listIndent, 0, listIndent.Length);
         WriteInt(listtable, (int) ((list.IndentationLeft + list.SymbolIndent) * TWIPSFACTOR));
         listtable.WriteByte(escape);
         listtable.Write(rightIndent, 0, rightIndent.Length);
         WriteInt(listtable, (int) (list.IndentationRight * TWIPSFACTOR));
         listtable.WriteByte(escape);
         listtable.Write(tabStop, 0, tabStop.Length);
         WriteInt(listtable, (int) (list.SymbolIndent * TWIPSFACTOR));
         listtable.WriteByte(closeGroup);
         listtable.WriteByte((byte) '\n');
     }
     // Actual List Begin in Content
     outp.WriteByte(escape);
     outp.Write(paragraphDefaults, 0, paragraphDefaults.Length);
     outp.WriteByte(escape);
     outp.Write(alignLeft, 0, alignLeft.Length);
     outp.WriteByte(escape);
     outp.Write(firstIndent, 0, firstIndent.Length);
     WriteInt(outp, (int) (list.IndentationLeft * TWIPSFACTOR * -1));
     outp.WriteByte(escape);
     outp.Write(listIndent, 0, listIndent.Length);
     WriteInt(outp, (int) ((list.IndentationLeft + list.SymbolIndent) * TWIPSFACTOR));
     outp.WriteByte(escape);
     outp.Write(rightIndent, 0, rightIndent.Length);
     WriteInt(outp, (int) (list.IndentationRight * TWIPSFACTOR));
     outp.WriteByte(escape);
     outp.Write(fontSize, 0, fontSize.Length);
     WriteInt(outp, 20);
     outp.WriteByte(escape);
     outp.Write(listBegin, 0, listBegin.Length);
     WriteInt(outp, currentListID);
     if (listLevel > 0) {
         outp.WriteByte(escape);
         outp.Write(listCurrentLevel, 0, listCurrentLevel.Length);
         WriteInt(outp, listLevel);
     }
     outp.WriteByte(openGroup);
     ListIterator listItems = new ListIterator(list.Items);
     IElement listElem;
     int count = 1;
     while (listItems.HasNext()) {
         listElem = (IElement) listItems.Next();
         if (listElem.Type == Element.CHUNK) {
             listElem = new ListItem((Chunk) listElem);
         }
         if (listElem.Type == Element.LISTITEM) {
             outp.WriteByte(openGroup);
             outp.WriteByte(escape);
             outp.Write(listTextOld, 0, listTextOld.Length);
             outp.WriteByte(escape);
             outp.Write(paragraphDefaults, 0, paragraphDefaults.Length);
             outp.WriteByte(escape);
             outp.WriteByte(fontNumber);
             if (list.IsNumbered()) {
                 WriteInt(outp, AddFont(new Font(Font.TIMES_ROMAN, Font.NORMAL, 10, new Color(0, 0, 0))));
             } else {
                 WriteInt(outp, fontNr);
             }
             outp.WriteByte(escape);
             outp.Write(firstIndent, 0, firstIndent.Length);
             WriteInt(outp, (int) (list.IndentationLeft * TWIPSFACTOR * -1));
             outp.WriteByte(escape);
             outp.Write(listIndent, 0, listIndent.Length);
             WriteInt(outp, (int) ((list.IndentationLeft + list.SymbolIndent) * TWIPSFACTOR));
             outp.WriteByte(escape);
             outp.Write(rightIndent, 0, rightIndent.Length);
             WriteInt(outp, (int) (list.IndentationRight * TWIPSFACTOR));
             outp.WriteByte(delimiter);
             if (list.IsNumbered()) {
                 WriteInt(outp, count);
                 outp.WriteByte((byte)'.');
             } else {
                 outp.WriteByte(escape);
                 outp.Write(listBulletOld, 0, listBulletOld.Length);
             }
             outp.WriteByte(escape);
             outp.Write(tab, 0, tab.Length);
             outp.WriteByte(closeGroup);
             WriteListElement((ListItem) listElem, outp);
             count++;
         } else if (listElem.Type == Element.LIST) {
             listLevel++;
             WriteList((List) listElem, outp);
             listLevel--;
             outp.WriteByte(escape);
             outp.Write(paragraphDefaults, 0, paragraphDefaults.Length);
             outp.WriteByte(escape);
             outp.Write(alignLeft, 0, alignLeft.Length);
             outp.WriteByte(escape);
             outp.Write(firstIndent, 0, firstIndent.Length);
             WriteInt(outp, (int) (list.IndentationLeft * TWIPSFACTOR * -1));
             outp.WriteByte(escape);
             outp.Write(listIndent, 0, listIndent.Length);
             WriteInt(outp, (int) ((list.IndentationLeft + list.SymbolIndent) * TWIPSFACTOR));
             outp.WriteByte(escape);
             outp.Write(rightIndent, 0, rightIndent.Length);
             WriteInt(outp, (int) (list.IndentationRight * TWIPSFACTOR));
             outp.WriteByte(escape);
             outp.Write(fontSize, 0, fontSize.Length);
             WriteInt(outp, 20);
             outp.WriteByte(escape);
             outp.Write(listBegin, 0, listBegin.Length);
             WriteInt(outp, currentListID);
             if (listLevel > 0) {
                 outp.WriteByte(escape);
                 outp.Write(listCurrentLevel, 0, listCurrentLevel.Length);
                 WriteInt(outp, listLevel);
             }
         }
         outp.WriteByte((byte) '\n');
     }
     outp.WriteByte(closeGroup);
     if (listLevel == 0) {
         int i = GetRandomInt();
         listtable.WriteByte(escape);
         listtable.Write(listID, 0, listID.Length);
         WriteInt(listtable, i);
         listtable.WriteByte(closeGroup);
         listtable.WriteByte((byte) '\n');
         listoverride.WriteByte(openGroup);
         listoverride.WriteByte(escape);
         listoverride.Write(listOverride, 0, listOverride.Length);
         listoverride.WriteByte(escape);
         listoverride.Write(listID, 0, listID.Length);
         WriteInt(listoverride, i);
         listoverride.WriteByte(escape);
         listoverride.Write(listOverrideCount, 0, listOverrideCount.Length);
         WriteInt(listoverride, 0);
         listoverride.WriteByte(escape);
         listoverride.Write(listBegin, 0, listBegin.Length);
         WriteInt(listoverride, currentListID);
         currentListID++;
         listoverride.WriteByte(closeGroup);
         listoverride.WriteByte((byte) '\n');
     }
     outp.WriteByte(escape);
     outp.Write(paragraphDefaults, 0, paragraphDefaults.Length);
 }