コード例 #1
0
        /// <summary>
        /// Write the cell definition part of this RtfCell
        /// </summary>
        /// <returns>A byte array with the cell definition</returns>
        public virtual void WriteDefinition(Stream result)
        {
            byte[] t;
            if (_mergeType == MergeVertParent)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\clvmgf"), 0, t.Length);
            }
            else if (_mergeType == MergeVertChild)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\clvmrg"), 0, t.Length);
            }
            switch (verticalAlignment)
            {
            case ALIGN_BOTTOM:
                result.Write(t = DocWriter.GetIsoBytes("\\clvertalb"), 0, t.Length);
                break;

            case ALIGN_CENTER:
            case ALIGN_MIDDLE:
                result.Write(t = DocWriter.GetIsoBytes("\\clvertalc"), 0, t.Length);
                break;

            case ALIGN_TOP:
                result.Write(t = DocWriter.GetIsoBytes("\\clvertalt"), 0, t.Length);
                break;
            }
            _borders.WriteContent(result);

            if (_backgroundColor != null)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\clcbpat"), 0, t.Length);
                result.Write(t = intToByteArray(_backgroundColor.GetColorNumber()), 0, t.Length);
            }
            _document.OutputDebugLinebreak(result);

            result.Write(t = DocWriter.GetIsoBytes("\\clftsWidth3"), 0, t.Length);
            _document.OutputDebugLinebreak(result);

            result.Write(t = DocWriter.GetIsoBytes("\\clwWidth"), 0, t.Length);
            result.Write(t = intToByteArray(_cellWidth), 0, t.Length);
            _document.OutputDebugLinebreak(result);

            if (_cellPadding > 0)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\clpadl"), 0, t.Length);
                result.Write(t = intToByteArray(_cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadt"), 0, t.Length);
                result.Write(t = intToByteArray(_cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadr"), 0, t.Length);
                result.Write(t = intToByteArray(_cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadb"), 0, t.Length);
                result.Write(t = intToByteArray(_cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadfl3"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadft3"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadfr3"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\clpadfb3"), 0, t.Length);
            }
            result.Write(t = DocWriter.GetIsoBytes("\\cellx"), 0, t.Length);
            result.Write(t = intToByteArray(_cellRight), 0, t.Length);
        }
コード例 #2
0
 /// <summary>
 /// Writes the start information of this RtfParagraphStyle.
 /// @throws IOException On i/o errors.
 /// </summary>
 /// <param name="result">The  OutputStream  to write to.</param>
 public override void WriteBegin(Stream result)
 {
     byte[] t;
     result.Write(t = DocWriter.GetIsoBytes("\\s"), 0, t.Length);
     result.Write(t = IntToByteArray(_styleNumber), 0, t.Length);
     writeParagraphSettings(result);
 }
コード例 #3
0
 /// <summary>
 /// Write the content of this RtfCell
 /// </summary>
 public virtual void WriteContent(Stream result)
 {
     byte[] t;
     if (_content.Count == 0)
     {
         result.Write(RtfPhrase.ParagraphDefaults, 0, RtfPhrase.ParagraphDefaults.Length);
         if (_parentRow.GetParentTable().GetTableFitToPage())
         {
             result.Write(RtfParagraphStyle.KeepTogetherWithNext, 0, RtfParagraphStyle.KeepTogetherWithNext.Length);
         }
         result.Write(RtfPhrase.InTable, 0, RtfPhrase.InTable.Length);
     }
     else
     {
         for (var i = 0; i < _content.Count; i++)
         {
             var rtfElement = (IRtfBasicElement)_content[i];
             if (rtfElement is RtfParagraph)
             {
                 ((RtfParagraph)rtfElement).SetKeepTogetherWithNext(_parentRow.GetParentTable().GetTableFitToPage());
             }
             rtfElement.WriteContent(result);
             if (rtfElement is RtfParagraph && i < (_content.Count - 1))
             {
                 result.Write(RtfParagraph.Paragraph, 0, RtfParagraph.Paragraph.Length);
             }
         }
     }
     result.Write(t = DocWriter.GetIsoBytes("\\cell"), 0, t.Length);
 }
コード例 #4
0
 /// <summary>
 /// Appends a  string  to the buffer. The  string  is
 /// converted according to the encoding ISO-8859-1.
 /// </summary>
 /// <param name="str">the  string  to be appended</param>
 /// <returns>a reference to this  ByteBuffer  object</returns>
 public ByteBuffer Append(string str)
 {
     if (str != null)
     {
         return(Append(DocWriter.GetIsoBytes(str)));
     }
     return(this);
 }
コード例 #5
0
 /// <summary>
 /// Writes the RTF generator group.
 /// </summary>
 public override void WriteContent(Stream result)
 {
     result.Write(OpenGroup, 0, OpenGroup.Length);
     result.Write(_generator, 0, _generator.Length);
     result.Write(Delimiter, 0, Delimiter.Length);
     byte[] t;
     result.Write(t = DocWriter.GetIsoBytes(iTextSharp.text.Document.Version), 0, t.Length);
     result.Write(CloseGroup, 0, CloseGroup.Length);
     Document.OutputDebugLinebreak(result);
 }
コード例 #6
0
 /// <summary>
 /// Writes eficiently to a stream
 /// @throws IOException on write error
 /// </summary>
 /// <param name="os">the stream to write to</param>
 internal void WriteTo(Stream os)
 {
     byte[] tmp = DocWriter.GetIsoBytes(Number.ToString());
     os.Write(tmp, 0, tmp.Length);
     os.WriteByte((byte)' ');
     tmp = DocWriter.GetIsoBytes(Generation.ToString());
     os.Write(tmp, 0, tmp.Length);
     os.Write(Startobj, 0, Startobj.Length);
     Objecti.ToPdf(Writer, os);
     os.Write(Endobj, 0, Endobj.Length);
 }
コード例 #7
0
        /// <summary>
        /// Writes the content of this RtfListItem.
        /// </summary>
        public override void WriteContent(Stream result)
        {
            byte[] t;
            if (ParagraphStyle.GetSpacingBefore() > 0)
            {
                result.Write(RtfParagraphStyle.SpacingBefore, 0, RtfParagraphStyle.SpacingBefore.Length);
                result.Write(t = IntToByteArray(ParagraphStyle.GetSpacingBefore()), 0, t.Length);
            }
            if (ParagraphStyle.GetSpacingAfter() > 0)
            {
                result.Write(RtfParagraphStyle.SpacingAfter, 0, RtfParagraphStyle.SpacingAfter.Length);
                result.Write(t = IntToByteArray(ParagraphStyle.GetSpacingAfter()), 0, t.Length);
            }
            if (ParagraphStyle.GetLineLeading() > 0)
            {
                result.Write(LineSpacing, 0, LineSpacing.Length);
                result.Write(t = IntToByteArray(ParagraphStyle.GetLineLeading()), 0, t.Length);
            }
            for (var i = 0; i < Chunks.Count; i++)
            {
                var rtfElement = (IRtfBasicElement)Chunks[i];
                if (rtfElement is RtfChunk)
                {
                    ((RtfChunk)rtfElement).SetSoftLineBreaks(true);
                }
                else if (rtfElement is RtfList)
                {
                    result.Write(Paragraph, 0, Paragraph.Length);
                    _containsInnerList = true;
                }
                rtfElement.WriteContent(result);
                if (rtfElement is RtfList)
                {
                    switch (_parentList.GetLevelFollowValue())
                    {
                    case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING:
                        break;

                    case RtfListLevel.LIST_LEVEL_FOLLOW_TAB:
                        _parentList.WriteListBeginning(result);
                        result.Write(RtfList.Tab, 0, RtfList.Tab.Length);
                        break;

                    case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE:
                        _parentList.WriteListBeginning(result);
                        result.Write(t = DocWriter.GetIsoBytes(" "), 0, t.Length);
                        break;
                    }
                }
            }
        }
コード例 #8
0
 /// <summary>
 /// Writes the definition of the stylesheet list.
 /// </summary>
 public virtual void WriteDefinition(Stream result)
 {
     byte[] t;
     result.Write(t = DocWriter.GetIsoBytes("{"), 0, t.Length);
     result.Write(t = DocWriter.GetIsoBytes("\\stylesheet"), 0, t.Length);
     result.Write(t = Delimiter, 0, t.Length);
     Document.OutputDebugLinebreak(result);
     foreach (RtfParagraphStyle rps in _styleMap.Values)
     {
         rps.WriteDefinition(result);
     }
     result.Write(t = DocWriter.GetIsoBytes("}"), 0, t.Length);
     Document.OutputDebugLinebreak(result);
 }
コード例 #9
0
        /// <summary>
        /// Writes the tab settings.
        /// </summary>
        public override void WriteContent(Stream result)
        {
            byte[] t;
            switch (_type)
            {
            case TAB_CENTER_ALIGN: result.Write(t = DocWriter.GetIsoBytes("\\tqc"), 0, t.Length); break;

            case TAB_RIGHT_ALIGN: result.Write(t = DocWriter.GetIsoBytes("\\tqr"), 0, t.Length); break;

            case TAB_DECIMAL_ALIGN: result.Write(t = DocWriter.GetIsoBytes("\\tqdec"), 0, t.Length); break;
            }
            result.Write(t = DocWriter.GetIsoBytes("\\tx"), 0, t.Length);
            result.Write(t = IntToByteArray(_position), 0, t.Length);
        }
コード例 #10
0
 /// <summary>
 /// Writes the definition of this RtfParagraphStyle for the stylesheet list.
 /// </summary>
 public override void WriteDefinition(Stream result)
 {
     byte[] t;
     result.Write(t = DocWriter.GetIsoBytes("{"), 0, t.Length);
     result.Write(t = DocWriter.GetIsoBytes("\\style"), 0, t.Length);
     result.Write(t = DocWriter.GetIsoBytes("\\s"), 0, t.Length);
     result.Write(t = IntToByteArray(_styleNumber), 0, t.Length);
     result.Write(t = RtfElement.Delimiter, 0, t.Length);
     writeParagraphSettings(result);
     base.WriteBegin(result);
     result.Write(t = RtfElement.Delimiter, 0, t.Length);
     result.Write(t = DocWriter.GetIsoBytes(_styleName), 0, t.Length);
     result.Write(t = DocWriter.GetIsoBytes(";"), 0, t.Length);
     result.Write(t = DocWriter.GetIsoBytes("}"), 0, t.Length);
     Document.OutputDebugLinebreak(result);
 }
コード例 #11
0
        /// <summary>
        /// Write this RtfShapePosition.
        /// </summary>
        public override void WriteContent(Stream result)
        {
            byte[] t;
            result.Write(t = DocWriter.GetIsoBytes("\\shpleft"), 0, t.Length);
            result.Write(t = IntToByteArray(_left), 0, t.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\shptop"), 0, t.Length);
            result.Write(t = IntToByteArray(_top), 0, t.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\shpright"), 0, t.Length);
            result.Write(t = IntToByteArray(_right), 0, t.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\shpbottom"), 0, t.Length);
            result.Write(t = IntToByteArray(_bottom), 0, t.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\shpz"), 0, t.Length);
            result.Write(t = IntToByteArray(_zOrder), 0, t.Length);
            switch (_xRelativePos)
            {
            case POSITION_X_RELATIVE_PAGE: result.Write(t = DocWriter.GetIsoBytes("\\shpbxpage"), 0, t.Length); break;

            case POSITION_X_RELATIVE_MARGIN: result.Write(t = DocWriter.GetIsoBytes("\\shpbxmargin"), 0, t.Length); break;

            case POSITION_X_RELATIVE_COLUMN: result.Write(t = DocWriter.GetIsoBytes("\\shpbxcolumn"), 0, t.Length); break;
            }
            if (_ignoreXRelative)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\shpbxignore"), 0, t.Length);
            }
            switch (_yRelativePos)
            {
            case POSITION_Y_RELATIVE_PAGE: result.Write(t = DocWriter.GetIsoBytes("\\shpbypage"), 0, t.Length); break;

            case POSITION_Y_RELATIVE_MARGIN: result.Write(t = DocWriter.GetIsoBytes("\\shpbymargin"), 0, t.Length); break;

            case POSITION_Y_RELATIVE_PARAGRAPH: result.Write(t = DocWriter.GetIsoBytes("\\shpbypara"), 0, t.Length); break;
            }
            if (_ignoreYRelative)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\shpbyignore"), 0, t.Length);
            }
            if (_shapeBelowText)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\shpfblwtxt1"), 0, t.Length);
            }
            else
            {
                result.Write(t = DocWriter.GetIsoBytes("\\shpfblwtxt0"), 0, t.Length);
            }
        }
コード例 #12
0
        /// <summary>
        /// Writes the content of one RTF information element.
        /// </summary>
        public override void WriteContent(Stream result)
        {
            result.Write(OpenGroup, 0, OpenGroup.Length);
            switch (_infoType)
            {
            case Element.AUTHOR:
                result.Write(_infoAuthor, 0, _infoAuthor.Length);
                break;

            case Element.SUBJECT:
                result.Write(_infoSubject, 0, _infoSubject.Length);
                break;

            case Element.KEYWORDS:
                result.Write(_infoKeywords, 0, _infoKeywords.Length);
                break;

            case Element.TITLE:
                result.Write(_infoTitle, 0, _infoTitle.Length);
                break;

            case Element.PRODUCER:
                result.Write(_infoProducer, 0, _infoProducer.Length);
                break;

            case Element.CREATIONDATE:
                result.Write(_infoCreationDate, 0, _infoCreationDate.Length);
                break;

            default:
                result.Write(_infoAuthor, 0, _infoAuthor.Length);
                break;
            }
            result.Write(Delimiter, 0, Delimiter.Length);
            byte[] t;
            if (_infoType == Element.CREATIONDATE)
            {
                t = DocWriter.GetIsoBytes(convertDate(_content));
                result.Write(t, 0, t.Length);
            }
            else
            {
                Document.FilterSpecialChar(result, _content, false, false);
            }
            result.Write(CloseGroup, 0, CloseGroup.Length);
        }
コード例 #13
0
        /// <summary>
        /// @throws IOException
        /// @since 2.1.3
        /// </summary>
        /// <param name="result"></param>
        /// <param name="itemNr"></param>
        /// <param name="listLevel"></param>
        protected void WriteListTextBlock(Stream result, int itemNr, RtfListLevel listLevel)
        {
            byte[] t;
            result.Write(OpenGroup, 0, OpenGroup.Length);
            result.Write(ListText, 0, ListText.Length);
            result.Write(RtfPhrase.ParagraphDefaults, 0, RtfPhrase.ParagraphDefaults.Length);
            if (InTable)
            {
                result.Write(RtfPhrase.InTable, 0, RtfPhrase.InTable.Length);
            }
            result.Write(RtfFontList.FontNumber, 0, RtfFontList.FontNumber.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(ListNumberEnd, 0, ListNumberEnd.Length);
            }
            else
            {
                Document.FilterSpecialChar(result, listLevel.GetBulletCharacter(), true, false);
            }
            result.Write(Tab, 0, Tab.Length);
            result.Write(CloseGroup, 0, CloseGroup.Length);
        }
コード例 #14
0
 /// <summary>
 /// Writes the content of the RtfAnnotation
 /// </summary>
 public override void WriteContent(Stream result)
 {
     byte[] t;
     result.Write(OpenGroup, 0, OpenGroup.Length);
     result.Write(_annotationId, 0, _annotationId.Length);
     result.Write(Delimiter, 0, Delimiter.Length);
     result.Write(t = IntToByteArray(Document.GetRandomInt()), 0, t.Length);
     result.Write(CloseGroup, 0, CloseGroup.Length);
     result.Write(OpenGroup, 0, OpenGroup.Length);
     result.Write(_annotationAuthor, 0, _annotationAuthor.Length);
     result.Write(Delimiter, 0, Delimiter.Length);
     result.Write(t = DocWriter.GetIsoBytes(_title), 0, t.Length);
     result.Write(CloseGroup, 0, CloseGroup.Length);
     result.Write(OpenGroup, 0, OpenGroup.Length);
     result.Write(_annotation, 0, _annotation.Length);
     result.Write(RtfPhrase.ParagraphDefaults, 0, RtfPhrase.ParagraphDefaults.Length);
     result.Write(Delimiter, 0, Delimiter.Length);
     result.Write(t = DocWriter.GetIsoBytes(_content), 0, t.Length);
     result.Write(CloseGroup, 0, CloseGroup.Length);
 }
コード例 #15
0
 /// <summary>
 /// Writes the RtfChapter and its contents
 /// </summary>
 public override void WriteContent(Stream result)
 {
     byte[] t;
     if (Document.GetLastElementWritten() != null && !(Document.GetLastElementWritten() is RtfChapter))
     {
         result.Write(t = DocWriter.GetIsoBytes("\\page"), 0, t.Length);
     }
     result.Write(t = DocWriter.GetIsoBytes("\\sectd"), 0, t.Length);
     Document.GetDocumentHeader().WriteSectionDefinition(result);
     if (Title != null)
     {
         Title.WriteContent(result);
     }
     for (var i = 0; i < Items.Count; i++)
     {
         var rbe = (IRtfBasicElement)Items[i];
         rbe.WriteContent(result);
     }
     result.Write(t = DocWriter.GetIsoBytes("\\sect"), 0, t.Length);
 }
コード例 #16
0
 /// <summary>
 /// Sets the encryption options for this document. The userPassword and the
 /// ownerPassword can be null or have zero length. In this case the ownerPassword
 /// is replaced by a random string. The open permissions for the document can be
 /// AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
 /// AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
 /// The permissions can be combined by ORing them.
 /// Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
 /// @throws DocumentException if the document is already open
 /// </summary>
 /// <param name="encryptionType">the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.</param>
 /// <param name="userPassword">the user password. Can be null or empty</param>
 /// <param name="ownerPassword">the owner password. Can be null or empty</param>
 /// <param name="permissions">the user permissions</param>
 public void SetEncryption(int encryptionType, string userPassword, string ownerPassword, int permissions)
 {
     SetEncryption(DocWriter.GetIsoBytes(userPassword), DocWriter.GetIsoBytes(ownerPassword), permissions, encryptionType);
 }
コード例 #17
0
 /// <summary>
 /// Transforms an integer into its String representation and then returns the bytes
 /// of that string.
 /// </summary>
 /// <param name="i">The integer to convert</param>
 /// <returns>A byte array representing the integer</returns>
 private byte[] intToByteArray(int i)
 {
     return(DocWriter.GetIsoBytes(i.ToString()));
 }
コード例 #18
0
        /// <summary>
        /// Writes the RtfShape. Some settings are automatically translated into
        /// or require other properties and these are set first.
        /// </summary>
        public override void WriteContent(Stream result)
        {
            _shapeNr = Doc.GetRandomInt();

            _properties["ShapeType"] = new RtfShapeProperty("ShapeType", _type);
            if (_position.IsShapeBelowText())
            {
                _properties["fBehindDocument"] = new RtfShapeProperty("fBehindDocument", true);
            }
            if (InTable)
            {
                _properties["fLayoutInCell"] = new RtfShapeProperty("fLayoutInCell", true);
            }
            if (_properties.ContainsKey("posh"))
            {
                _position.SetIgnoreXRelative(true);
            }
            if (_properties.ContainsKey("posv"))
            {
                _position.SetIgnoreYRelative(true);
            }

            byte[] t;
            result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\shp"), 0, t.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\shplid"), 0, t.Length);
            result.Write(t = IntToByteArray(_shapeNr), 0, t.Length);
            _position.WriteContent(result);
            switch (_wrapping)
            {
            case SHAPE_WRAP_NONE:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr3"), 0, t.Length);
                break;

            case SHAPE_WRAP_TOP_BOTTOM:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr1"), 0, t.Length);
                break;

            case SHAPE_WRAP_BOTH:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr2"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk0"), 0, t.Length);
                break;

            case SHAPE_WRAP_LEFT:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr2"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk1"), 0, t.Length);
                break;

            case SHAPE_WRAP_RIGHT:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr2"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk2"), 0, t.Length);
                break;

            case SHAPE_WRAP_LARGEST:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr2"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk3"), 0, t.Length);
                break;

            case SHAPE_WRAP_TIGHT_BOTH:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr4"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk0"), 0, t.Length);
                break;

            case SHAPE_WRAP_TIGHT_LEFT:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr4"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk1"), 0, t.Length);
                break;

            case SHAPE_WRAP_TIGHT_RIGHT:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr4"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk2"), 0, t.Length);
                break;

            case SHAPE_WRAP_TIGHT_LARGEST:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr4"), 0, t.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shpwrk3"), 0, t.Length);
                break;

            case SHAPE_WRAP_THROUGH:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr5"), 0, t.Length);
                break;

            default:
                result.Write(t = DocWriter.GetIsoBytes("\\shpwr3"), 0, t.Length);
                break;
            }
            if (InHeader)
            {
                result.Write(t = DocWriter.GetIsoBytes("\\shpfhdr1"), 0, t.Length);
            }
            if (Doc.GetDocumentSettings().IsOutputDebugLineBreaks())
            {
                result.WriteByte((byte)'\n');
            }
            result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
            result.Write(t = DocWriter.GetIsoBytes("\\*\\shpinst"), 0, t.Length);
            foreach (RtfShapeProperty rsp in _properties.Values)
            {
                rsp.WriteContent(result);
            }
            if (!_shapeText.Equals(""))
            {
                result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length);
                result.Write(t = DocWriter.GetIsoBytes("\\shptxt"), 0, t.Length);
                result.Write(RtfElement.Delimiter, 0, RtfElement.Delimiter.Length);
                result.Write(t = DocWriter.GetIsoBytes(_shapeText), 0, t.Length);
                result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
            }
            result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
            Doc.OutputDebugLinebreak(result);
            result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length);
        }
コード例 #19
0
        /// <summary>
        /// Constructs a  PdfContents -object, containing text and general graphics.
        /// @throws BadPdfFormatException on error
        /// </summary>
        /// <param name="under">the direct content that is under all others</param>
        /// <param name="content">the graphics in a page</param>
        /// <param name="text">the text in a page</param>
        /// <param name="secondContent">the direct content that is over all others</param>
        /// <param name="page"></param>
        internal PdfContents(PdfContentByte under, PdfContentByte content, PdfContentByte text, PdfContentByte secondContent, Rectangle page)
        {
            Stream ostr = null;

            StreamBytes = new MemoryStream();
            if (Document.Compress)
            {
                Compressed = true;
                ostr       = new ZDeflaterOutputStream(StreamBytes, text.PdfWriter.CompressionLevel);
            }
            else
            {
                ostr = StreamBytes;
            }
            int rotation = page.Rotation;

            byte[] tmp;
            switch (rotation)
            {
            case 90:
                ostr.Write(Rotate90, 0, Rotate90.Length);
                tmp = DocWriter.GetIsoBytes(ByteBuffer.FormatDouble(page.Top));
                ostr.Write(tmp, 0, tmp.Length);
                ostr.WriteByte((byte)' ');
                ostr.WriteByte((byte)'0');
                ostr.Write(Rotatefinal, 0, Rotatefinal.Length);
                break;

            case 180:
                ostr.Write(Rotate180, 0, Rotate180.Length);
                tmp = DocWriter.GetIsoBytes(ByteBuffer.FormatDouble(page.Right));
                ostr.Write(tmp, 0, tmp.Length);
                ostr.WriteByte((byte)' ');
                tmp = DocWriter.GetIsoBytes(ByteBuffer.FormatDouble(page.Top));
                ostr.Write(tmp, 0, tmp.Length);
                ostr.Write(Rotatefinal, 0, Rotatefinal.Length);
                break;

            case 270:
                ostr.Write(Rotate270, 0, Rotate270.Length);
                ostr.WriteByte((byte)'0');
                ostr.WriteByte((byte)' ');
                tmp = DocWriter.GetIsoBytes(ByteBuffer.FormatDouble(page.Right));
                ostr.Write(tmp, 0, tmp.Length);
                ostr.Write(Rotatefinal, 0, Rotatefinal.Length);
                break;
            }
            if (under.Size > 0)
            {
                ostr.Write(Savestate, 0, Savestate.Length);
                under.InternalBuffer.WriteTo(ostr);
                ostr.Write(Restorestate, 0, Restorestate.Length);
            }
            if (content.Size > 0)
            {
                ostr.Write(Savestate, 0, Savestate.Length);
                content.InternalBuffer.WriteTo(ostr);
                ostr.Write(Restorestate, 0, Restorestate.Length);
            }
            if (text != null)
            {
                ostr.Write(Savestate, 0, Savestate.Length);
                text.InternalBuffer.WriteTo(ostr);
                ostr.Write(Restorestate, 0, Restorestate.Length);
            }
            if (secondContent.Size > 0)
            {
                secondContent.InternalBuffer.WriteTo(ostr);
            }

            if (ostr is ZDeflaterOutputStream)
            {
                ((ZDeflaterOutputStream)ostr).Finish();
            }
            Put(PdfName.LENGTH, new PdfNumber(StreamBytes.Length));
            if (Compressed)
            {
                Put(PdfName.Filter, PdfName.Flatedecode);
            }
        }
コード例 #20
0
        public void WriteDefinition(Stream result)
        {
            byte[] t;
            result.Write(OpenGroup, 0, OpenGroup.Length);
            result.Write(_listLevel, 0, _listLevel.Length);
            result.Write(_listLevelType, 0, _listLevelType.Length);
            switch (_listType)
            {
            case LIST_TYPE_BULLET: result.Write(t = IntToByteArray(23), 0, t.Length); break;

            case LIST_TYPE_NUMBERED: result.Write(t = IntToByteArray(0), 0, t.Length); break;

            case LIST_TYPE_UPPER_LETTERS: result.Write(t = IntToByteArray(3), 0, t.Length); break;

            case LIST_TYPE_LOWER_LETTERS: result.Write(t = IntToByteArray(4), 0, t.Length); break;

            case LIST_TYPE_UPPER_ROMAN: result.Write(t = IntToByteArray(1), 0, t.Length); break;

            case LIST_TYPE_LOWER_ROMAN: result.Write(t = IntToByteArray(2), 0, t.Length); break;

            /* New types */
            case LIST_TYPE_ARABIC: result.Write(t = IntToByteArray(0), 0, t.Length); break;

            case LIST_TYPE_UPPERCASE_ROMAN_NUMERAL: result.Write(t = IntToByteArray(1), 0, t.Length); break;

            case LIST_TYPE_LOWERCASE_ROMAN_NUMERAL: result.Write(t = IntToByteArray(2), 0, t.Length); break;

            case LIST_TYPE_UPPERCASE_LETTER: result.Write(t = IntToByteArray(3), 0, t.Length); break;

            case LIST_TYPE_ORDINAL_NUMBER: result.Write(t = IntToByteArray(4), 0, t.Length); break;

            case LIST_TYPE_CARDINAL_TEXT_NUMBER: result.Write(t = IntToByteArray(5), 0, t.Length); break;

            case LIST_TYPE_ORDINAL_TEXT_NUMBER: result.Write(t = IntToByteArray(6), 0, t.Length); break;

            case LIST_TYPE_LOWERCASE_LETTER: result.Write(t = IntToByteArray(7), 0, t.Length); break;

            case LIST_TYPE_ARABIC_LEADING_ZERO: result.Write(t = IntToByteArray(22), 0, t.Length); break;

            case LIST_TYPE_NO_NUMBER: result.Write(t = IntToByteArray(255), 0, t.Length); break;

            default:        // catch all for other unsupported types
                if (_listType >= LIST_TYPE_BASE)
                {
                    result.Write(t = IntToByteArray(_listType - LIST_TYPE_BASE), 0, t.Length);
                }
                break;
            }

            result.Write(_listLevelTypeNew, 0, _listLevelTypeNew.Length);
            switch (_listType)
            {
            case LIST_TYPE_BULLET: result.Write(t = IntToByteArray(23), 0, t.Length); break;

            case LIST_TYPE_NUMBERED: result.Write(t = IntToByteArray(0), 0, t.Length); break;

            case LIST_TYPE_UPPER_LETTERS: result.Write(t = IntToByteArray(3), 0, t.Length); break;

            case LIST_TYPE_LOWER_LETTERS: result.Write(t = IntToByteArray(4), 0, t.Length); break;

            case LIST_TYPE_UPPER_ROMAN: result.Write(t = IntToByteArray(1), 0, t.Length); break;

            case LIST_TYPE_LOWER_ROMAN: result.Write(t = IntToByteArray(2), 0, t.Length); break;

            /* New types */
            case LIST_TYPE_ARABIC: result.Write(t = IntToByteArray(0), 0, t.Length); break;

            case LIST_TYPE_UPPERCASE_ROMAN_NUMERAL: result.Write(t = IntToByteArray(1), 0, t.Length); break;

            case LIST_TYPE_LOWERCASE_ROMAN_NUMERAL: result.Write(t = IntToByteArray(2), 0, t.Length); break;

            case LIST_TYPE_UPPERCASE_LETTER: result.Write(t = IntToByteArray(3), 0, t.Length); break;

            case LIST_TYPE_ORDINAL_NUMBER: result.Write(t = IntToByteArray(4), 0, t.Length); break;

            case LIST_TYPE_CARDINAL_TEXT_NUMBER: result.Write(t = IntToByteArray(5), 0, t.Length); break;

            case LIST_TYPE_ORDINAL_TEXT_NUMBER: result.Write(t = IntToByteArray(6), 0, t.Length); break;

            case LIST_TYPE_LOWERCASE_LETTER: result.Write(t = IntToByteArray(7), 0, t.Length); break;

            case LIST_TYPE_ARABIC_LEADING_ZERO: result.Write(t = IntToByteArray(22), 0, t.Length); break;

            case LIST_TYPE_NO_NUMBER: result.Write(t = IntToByteArray(255), 0, t.Length); break;

            default:        // catch all for other unsupported types
                if (_listType >= LIST_TYPE_BASE)
                {
                    result.Write(t = IntToByteArray(_listType - LIST_TYPE_BASE), 0, t.Length);
                }
                break;
            }
            result.Write(_listLevelAlignment, 0, _listLevelAlignment.Length);
            result.Write(t = IntToByteArray(0), 0, t.Length);
            result.Write(_listLevelAlignmentNew, 0, _listLevelAlignmentNew.Length);
            result.Write(t = IntToByteArray(0), 0, t.Length);
            result.Write(_listLevelFolow, 0, _listLevelFolow.Length);
            result.Write(t = IntToByteArray(_levelFollowValue), 0, t.Length);
            result.Write(_listLevelStartAt, 0, _listLevelStartAt.Length);
            result.Write(t = IntToByteArray(_listStartAt), 0, t.Length);
            if (_isTentative)
            {
                result.Write(_listLevelTentative, 0, _listLevelTentative.Length);
            }
            if (_isLegal)
            {
                result.Write(_listLevelLegal, 0, _listLevelLegal.Length);
            }
            result.Write(_listLevelSpace, 0, _listLevelSpace.Length);
            result.Write(t = IntToByteArray(0), 0, t.Length);
            result.Write(_listLevelIndent, 0, _listLevelIndent.Length);
            result.Write(t = IntToByteArray(0), 0, t.Length);
            if (_levelPicture != -1)
            {
                result.Write(_listLevelPicture, 0, _listLevelPicture.Length);
                result.Write(t = IntToByteArray(_levelPicture), 0, t.Length);
            }

            result.Write(OpenGroup, 0, OpenGroup.Length); // { leveltext
            result.Write(_listLevelText, 0, _listLevelText.Length);
            result.Write(_listLevelTemplateId, 0, _listLevelTemplateId.Length);
            result.Write(t = IntToByteArray(_templateId), 0, t.Length);

            /* NEVER seperate the LEVELTEXT elements with a return in between
             * them or it will not fuction correctly!
             */
            // TODO Needs to be rewritten to support 1-9 levels, not just simple single level
            if (_listType != LIST_TYPE_BULLET)
            {
                result.Write(_listLevelStyleNumberedBegin, 0, _listLevelStyleNumberedBegin.Length);
                if (_levelTextNumber < 10)
                {
                    result.Write(t = IntToByteArray(0), 0, t.Length);
                }
                result.Write(t = IntToByteArray(_levelTextNumber), 0, t.Length);
                result.Write(_listLevelStyleNumberedEnd, 0, _listLevelStyleNumberedEnd.Length);
            }
            else
            {
                result.Write(_listLevelStyleBulletedBegin, 0, _listLevelStyleBulletedBegin.Length);
                Document.FilterSpecialChar(result, _bulletCharacter, false, false);
                result.Write(_listLevelStyleBulletedEnd, 0, _listLevelStyleBulletedEnd.Length);
            }
            result.Write(CloseGroup, 0, CloseGroup.Length); // } leveltext

            result.Write(OpenGroup, 0, OpenGroup.Length);   // { levelnumbers
            result.Write(_listLevelNumbersBegin, 0, _listLevelNumbersBegin.Length);
            if (_listType != LIST_TYPE_BULLET)
            {
                result.Write(_listLevelNumbersNumbered, 0, _listLevelNumbersNumbered.Length);
            }
            result.Write(_listLevelNumbersEnd, 0, _listLevelNumbersEnd.Length);
            result.Write(CloseGroup, 0, CloseGroup.Length);// { levelnumbers

            // write properties now
            result.Write(RtfFontList.FontNumber, 0, RtfFontList.FontNumber.Length);
            if (_listType != LIST_TYPE_BULLET)
            {
                result.Write(t = IntToByteArray(_fontNumber.GetFontNumber()), 0, t.Length);
            }
            else
            {
                result.Write(t = IntToByteArray(_fontBullet.GetFontNumber()), 0, t.Length);
            }
            result.Write(t = DocWriter.GetIsoBytes("\\cf"), 0, t.Length);
            //        document.GetDocumentHeader().GetColorNumber(new RtfColor(this.document,this.GetFontNumber().GetColor()));
            result.Write(t = IntToByteArray(Document.GetDocumentHeader().GetColorNumber(new RtfColor(Document, GetFontNumber().Color))), 0, t.Length);

            WriteIndentation(result);
            result.Write(CloseGroup, 0, CloseGroup.Length);
            Document.OutputDebugLinebreak(result);
        }
コード例 #21
0
 /// <summary>
 /// Returns the version as a byte[].
 /// </summary>
 /// <param name="version">the version character</param>
 public byte[] GetVersionAsByteArray(char version)
 {
     return(DocWriter.GetIsoBytes(GetVersionAsName(version).ToString().Substring(1)));
 }
コード例 #22
0
 /// <summary>
 /// Sets the encryption options for this document. The userPassword and the
 /// ownerPassword can be null or have zero length. In this case the ownerPassword
 /// is replaced by a random string. The open permissions for the document can be
 /// AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
 /// AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
 /// The permissions can be combined by ORing them.
 /// @throws DocumentException if the document is already open
 /// </summary>
 /// <param name="strength">true for 128 bit key length. false for 40 bit key length</param>
 /// <param name="userPassword">the user password. Can be null or empty</param>
 /// <param name="ownerPassword">the owner password. Can be null or empty</param>
 /// <param name="permissions">the user permissions</param>
 public void SetEncryption(bool strength, string userPassword, string ownerPassword, int permissions)
 {
     SetEncryption(DocWriter.GetIsoBytes(userPassword), DocWriter.GetIsoBytes(ownerPassword), permissions, strength);
 }
コード例 #23
0
        /// <summary>
        /// Writes the element content to the given output stream.
        /// </summary>
        public override void WriteContent(Stream outp)
        {
            var contentBytes = DocWriter.GetIsoBytes(_directContent);

            outp.Write(contentBytes, 0, contentBytes.Length);
        }
コード例 #24
0
        /// <summary>
        /// Writes the field instruction content
        /// </summary>
        protected override void WriteFieldInstContent(Stream outp)
        {
            var t = DocWriter.GetIsoBytes(FieldInst);

            outp.Write(t, 0, t.Length);
        }
コード例 #25
0
 /// <summary>
 /// Obtain the password has as a byte array.
 /// @since 2.1.1
 /// @author Howard Shank ([email protected])
 /// </summary>
 /// <returns>The bytes of the password hash as a byte array (byte[])</returns>
 public byte[] GetProtectionHashBytes()
 {
     return(DocWriter.GetIsoBytes(_protectionHash));
 }
コード例 #26
0
 /// <summary>
 /// @since 2.1.1
 /// @author Howard Shank ([email protected])
 /// </summary>
 /// <returns>RTF document protection level as a byte array (byte[])</returns>
 public byte[] GetProtectionLevelBytes()
 {
     return(DocWriter.GetIsoBytes(convertProtectionLevel().ToString()));
 }
コード例 #27
0
 /// <summary>
 /// Transforms an integer into its String representation and then returns the bytes
 /// of that string.
 /// </summary>
 /// <param name="i">The integer to convert</param>
 /// <returns>A byte array representing the integer</returns>
 protected byte[] IntToByteArray(int i)
 {
     return(DocWriter.GetIsoBytes(i.ToString()));
 }
コード例 #28
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);
        }