Inheritance: iTextSharp.text.rtf.RtfElement
        /**
         * Write this RtfShapePosition.
         */
        public override void WriteContent(Stream result)
        {
            byte[] t;
            result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
            result.Write(t = DocWriter.GetISOBytes("\\sp"), 0, t.Length);
            result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
            result.Write(t = DocWriter.GetISOBytes("\\sn"), 0, t.Length);
            result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
            result.Write(t = DocWriter.GetISOBytes(this.name), 0, t.Length);
            result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
            result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
            result.Write(t = DocWriter.GetISOBytes("\\sv"), 0, t.Length);
            result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
            switch (this.type)
            {
            case PROPERTY_TYPE_LONG:
            case PROPERTY_TYPE_DOUBLE:
                result.Write(t = DocWriter.GetISOBytes(this.value.ToString()), 0, t.Length);
                break;

            case PROPERTY_TYPE_BOOLEAN:
                if ((bool)this.value)
                {
                    result.Write(t = DocWriter.GetISOBytes("1"), 0, t.Length);
                }
                else
                {
                    result.Write(t = DocWriter.GetISOBytes("0"), 0, t.Length);
                }
                break;

            case PROPERTY_TYPE_COLOR:
                Color color = (Color)this.value;
                result.Write(t = IntToByteArray(color.R | (color.G << 8) | (color.B << 16)), 0, t.Length);
                break;

            case PROPERTY_TYPE_ARRAY:
                if (this.value is int[])
                {
                    int[] values = (int[])this.value;
                    result.Write(t = DocWriter.GetISOBytes("4;"), 0, t.Length);
                    result.Write(t = IntToByteArray(values.Length), 0, t.Length);
                    result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
                    for (int i = 0; i < values.Length; i++)
                    {
                        result.Write(t = IntToByteArray(values[i]), 0, t.Length);
                        if (i < values.Length - 1)
                        {
                            result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
                        }
                    }
                }
                else if (this.value is Point[])
                {
                    Point[] values = (Point[])this.value;
                    result.Write(t = DocWriter.GetISOBytes("8;"), 0, t.Length);
                    result.Write(t = IntToByteArray(values.Length), 0, t.Length);
                    result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
                    for (int i = 0; i < values.Length; i++)
                    {
                        result.Write(t = DocWriter.GetISOBytes("("), 0, t.Length);
                        result.Write(t = IntToByteArray(values[i].X), 0, t.Length);
                        result.Write(t = DocWriter.GetISOBytes(","), 0, t.Length);
                        result.Write(t = IntToByteArray(values[i].Y), 0, t.Length);
                        result.Write(t = DocWriter.GetISOBytes(")"), 0, t.Length);
                        if (i < values.Length - 1)
                        {
                            result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
                        }
                    }
                }
                break;

            case PROPERTY_TYPE_IMAGE:
                Image    image = (Image)this.value;
                RtfImage img   = new RtfImage(this.doc, image);
                img.SetTopLevelElement(true);
                result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
                img.WriteContent(result);
                result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
                break;
            }
            result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
            result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 /**
 * Write this RtfShapePosition.
 */
 public override void WriteContent(Stream result)
 {
     byte[] t;
     result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
     result.Write(t = DocWriter.GetISOBytes("\\sp"), 0, t.Length);
     result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
     result.Write(t = DocWriter.GetISOBytes("\\sn"), 0, t.Length);
     result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
     result.Write(t = DocWriter.GetISOBytes(this.name), 0, t.Length);
     result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
     result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
     result.Write(t = DocWriter.GetISOBytes("\\sv"), 0, t.Length);
     result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
     switch (this.type) {
     case PROPERTY_TYPE_LONG:
     case PROPERTY_TYPE_DOUBLE:
         result.Write(t = DocWriter.GetISOBytes(this.value.ToString()), 0, t.Length);
         break;
     case PROPERTY_TYPE_BOOLEAN:
         if ((bool)this.value) {
             result.Write(t = DocWriter.GetISOBytes("1"), 0, t.Length);
         } else {
             result.Write(t = DocWriter.GetISOBytes("0"), 0, t.Length);
         }
         break;
     case PROPERTY_TYPE_COLOR:
         Color color = (Color) this.value;
         result.Write(t = IntToByteArray(color.R | (color.G << 8) | (color.B << 16)), 0, t.Length);
         break;
     case PROPERTY_TYPE_ARRAY:
         if (this.value is int[]) {
             int[] values = (int[]) this.value;
             result.Write(t = DocWriter.GetISOBytes("4;"), 0, t.Length);
             result.Write(t = IntToByteArray(values.Length), 0, t.Length);
             result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
             for (int i = 0; i < values.Length; i++) {
                 result.Write(t = IntToByteArray(values[i]), 0, t.Length);
                 if (i < values.Length - 1) {
                     result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
                 }
             }
         } else if (this.value is Point[]) {
             Point[] values = (Point[]) this.value;
             result.Write(t = DocWriter.GetISOBytes("8;"), 0, t.Length);
             result.Write(t = IntToByteArray(values.Length), 0, t.Length);
             result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
             for (int i = 0; i < values.Length; i++) {
                 result.Write(t = DocWriter.GetISOBytes("("), 0, t.Length);
                 result.Write(t = IntToByteArray(values[i].X), 0, t.Length);
                 result.Write(t = DocWriter.GetISOBytes(","), 0, t.Length);
                 result.Write(t = IntToByteArray(values[i].Y), 0, t.Length);
                 result.Write(t = DocWriter.GetISOBytes(")"), 0, t.Length);
                 if (i < values.Length - 1) {
                     result.Write(RtfElement.COMMA_DELIMITER, 0, RtfElement.COMMA_DELIMITER.Length);
                 }
             }
         }
         break;
     case PROPERTY_TYPE_IMAGE:
         Image image = (Image)this.value;
         RtfImage img = new RtfImage(this.doc, image);
         img.SetTopLevelElement(true);
         result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length);
         img.WriteContent(result);
         result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
         break;
     }
     result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
     result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Write this RtfShapePosition.
        /// </summary>
        public override void WriteContent(Stream result)
        {
            byte[] t;
            result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\sp"), 0, t.Length);
            result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\sn"), 0, t.Length);
            result.Write(RtfElement.Delimiter, 0, RtfElement.Delimiter.Length);
            result.Write(t = DocWriter.GetIsoBytes(_name), 0, t.Length);
            result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
            result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\sv"), 0, t.Length);
            result.Write(RtfElement.Delimiter, 0, RtfElement.Delimiter.Length);
            switch (_type)
            {
            case PropertyTypeLong:
            case PropertyTypeDouble:
                result.Write(t = DocWriter.GetIsoBytes(_value.ToString()), 0, t.Length);
                break;

            case PropertyTypeBoolean:
                if ((bool)_value)
                {
                    result.Write(t = DocWriter.GetIsoBytes("1"), 0, t.Length);
                }
                else
                {
                    result.Write(t = DocWriter.GetIsoBytes("0"), 0, t.Length);
                }
                break;

            case PropertyTypeColor:
                var color = (BaseColor)_value;
                result.Write(t = IntToByteArray(color.R | (color.G << 8) | (color.B << 16)), 0, t.Length);
                break;

            case PropertyTypeArray:
                if (_value is int[])
                {
                    var values = (int[])_value;
                    result.Write(t = DocWriter.GetIsoBytes("4;"), 0, t.Length);
                    result.Write(t = IntToByteArray(values.Length), 0, t.Length);
                    result.Write(RtfElement.CommaDelimiter, 0, RtfElement.CommaDelimiter.Length);
                    for (var i = 0; i < values.Length; i++)
                    {
                        result.Write(t = IntToByteArray(values[i]), 0, t.Length);
                        if (i < values.Length - 1)
                        {
                            result.Write(RtfElement.CommaDelimiter, 0, RtfElement.CommaDelimiter.Length);
                        }
                    }
                }
                else if (_value is Point[])
                {
                    var values = (Point[])_value;
                    result.Write(t = DocWriter.GetIsoBytes("8;"), 0, t.Length);
                    result.Write(t = IntToByteArray(values.Length), 0, t.Length);
                    result.Write(RtfElement.CommaDelimiter, 0, RtfElement.CommaDelimiter.Length);
                    for (var i = 0; i < values.Length; i++)
                    {
                        result.Write(t = DocWriter.GetIsoBytes("("), 0, t.Length);
                        result.Write(t = IntToByteArray(values[i].X), 0, t.Length);
                        result.Write(t = DocWriter.GetIsoBytes(","), 0, t.Length);
                        result.Write(t = IntToByteArray(values[i].Y), 0, t.Length);
                        result.Write(t = DocWriter.GetIsoBytes(")"), 0, t.Length);
                        if (i < values.Length - 1)
                        {
                            result.Write(RtfElement.CommaDelimiter, 0, RtfElement.CommaDelimiter.Length);
                        }
                    }
                }
                break;

            case PropertyTypeImage:
                var image = (Image)_value;
                var img   = new RtfImage(Doc, image);
                img.SetTopLevelElement(true);
                result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
                img.WriteContent(result);
                result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
                break;
            }
            result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
            result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
        }