Exemple #1
0
        /**
         * Writes the definition of this RtfParagraphStyle for the stylesheet list.
         */
        public override byte[] WriteDefinition()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                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(this.styleNumber), 0, t.Length);
                result.Write(t = RtfElement.DELIMITER, 0, t.Length);
                result.Write(t = WriteParagraphSettings(), 0, t.Length);
                result.Write(t = base.WriteBegin(), 0, t.Length);
                result.Write(t = RtfElement.DELIMITER, 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes(this.styleName), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes(";"), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length);
                if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks())
                {
                    result.WriteByte((byte)'\n');
                }
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #2
0
        /**
         * Writes the definition of the stylesheet list.
         */
        public virtual byte[] WriteDefinition()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                result.Write(t = DocWriter.GetISOBytes("{"), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\stylesheet"), 0, t.Length);
                result.Write(t = RtfElement.DELIMITER, 0, t.Length);
                if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks())
                {
                    result.Write(t = DocWriter.GetISOBytes("\n"), 0, t.Length);
                }
                foreach (RtfParagraphStyle it in this.styleMap.Values)
                {
                    result.Write(t = (it).WriteDefinition(), 0, t.Length);
                }
                result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length);
                if (this.document.GetDocumentSettings().IsOutputDebugLineBreaks())
                {
                    result.WriteByte((byte)'\n');
                }
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #3
0
 /**
  * Write the content of this RtfCell
  */
 public virtual void WriteContent(Stream result)
 {
     byte[] t;
     if (this.content.Count == 0)
     {
         result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
         if (this.parentRow.GetParentTable().GetTableFitToPage())
         {
             result.Write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT, 0, RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT.Length);
         }
         result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
     }
     else
     {
         for (int i = 0; i < this.content.Count; i++)
         {
             IRtfBasicElement rtfElement = (IRtfBasicElement)this.content[i];
             if (rtfElement is RtfParagraph)
             {
                 ((RtfParagraph)rtfElement).SetKeepTogetherWithNext(this.parentRow.GetParentTable().GetTableFitToPage());
             }
             rtfElement.WriteContent(result);
             if (rtfElement is RtfParagraph && i < (this.content.Count - 1))
             {
                 result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
             }
         }
     }
     result.Write(t = DocWriter.GetISOBytes("\\cell"), 0, t.Length);
 }
Exemple #4
0
        /**
         * Write the cell definition part of this RtfCell
         *
         * @return A byte array with the cell definition
         */
        public virtual void WriteDefinition(Stream result)
        {
            byte[] t;
            if (this.mergeType == MERGE_VERT_PARENT)
            {
                result.Write(t = DocWriter.GetISOBytes("\\clvmgf"), 0, t.Length);
            }
            else if (this.mergeType == MERGE_VERT_CHILD)
            {
                result.Write(t = DocWriter.GetISOBytes("\\clvmrg"), 0, t.Length);
            }
            switch (verticalAlignment)
            {
            case Element.ALIGN_BOTTOM:
                result.Write(t = DocWriter.GetISOBytes("\\clvertalb"), 0, t.Length);
                break;

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

            case Element.ALIGN_TOP:
                result.Write(t = DocWriter.GetISOBytes("\\clvertalt"), 0, t.Length);
                break;
            }
            this.borders.WriteContent(result);

            if (this.backgroundColor != null)
            {
                result.Write(t = DocWriter.GetISOBytes("\\clcbpat"), 0, t.Length);
                result.Write(t = IntToByteArray(this.backgroundColor.GetColorNumber()), 0, t.Length);
            }
            this.document.OutputDebugLinebreak(result);

            result.Write(t = DocWriter.GetISOBytes("\\clftsWidth3"), 0, t.Length);
            this.document.OutputDebugLinebreak(result);

            result.Write(t = DocWriter.GetISOBytes("\\clwWidth"), 0, t.Length);
            result.Write(t = IntToByteArray(this.cellWidth), 0, t.Length);
            this.document.OutputDebugLinebreak(result);

            if (this.cellPadding > 0)
            {
                result.Write(t = DocWriter.GetISOBytes("\\clpadl"), 0, t.Length);
                result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\clpadt"), 0, t.Length);
                result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\clpadr"), 0, t.Length);
                result.Write(t = IntToByteArray(this.cellPadding / 2), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\clpadb"), 0, t.Length);
                result.Write(t = IntToByteArray(this.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(this.cellRight), 0, t.Length);
        }
Exemple #5
0
        /**
         * Writes the RtfChapter and its contents
         *
         * @return A byte array containing the RtfChapter and its contents
         */
        public override byte[] Write()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                if (this.document.GetLastElementWritten() != null && !(this.document.GetLastElementWritten() is RtfChapter))
                {
                    result.Write(t = DocWriter.GetISOBytes("\\page"), 0, t.Length);
                }
                result.Write(t = DocWriter.GetISOBytes("\\sectd"), 0, t.Length);
                result.Write(t = document.GetDocumentHeader().WriteSectionDefinition(), 0, t.Length);
                if (this.title != null)
                {
                    result.Write(t = this.title.Write(), 0, t.Length);
                }
                for (int i = 0; i < items.Count; i++)
                {
                    result.Write(t = ((IRtfBasicElement)items[i]).Write(), 0, t.Length);
                }
                result.Write(t = DocWriter.GetISOBytes("\\sect"), 0, t.Length);
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #6
0
        private void WriteField(Stream outp)
        {
            // always hide the toc entry
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            outp.WriteByte((byte)'v');

            // tc field entry
            outp.WriteByte(RtfWriter.openGroup);
            outp.WriteByte(RtfWriter.escape);
            byte[] t;
            if (!hidePageNumber)
            {
                t = DocWriter.GetISOBytes("tc");
                outp.Write(t, 0, t.Length);
            }
            else
            {
                t = DocWriter.GetISOBytes("tcn");
                outp.Write(t, 0, t.Length);
            }
            outp.WriteByte(RtfWriter.delimiter);
            t = DocWriter.GetISOBytes(RtfWriter.FilterSpecialChar(entryName, true));
            outp.Write(t, 0, t.Length);
            outp.WriteByte(RtfWriter.delimiter);
            outp.WriteByte(RtfWriter.closeGroup);

            outp.WriteByte(RtfWriter.closeGroup);
        }
Exemple #7
0
 /**
  * Writes the start information of this RtfParagraphStyle.
  *
  * @param result The <code>OutputStream</code> to write to.
  * @throws IOException On i/o errors.
  */
 public override void WriteBegin(Stream result)
 {
     byte[] t;
     result.Write(t = DocWriter.GetISOBytes("\\s"), 0, t.Length);
     result.Write(t = IntToByteArray(this.styleNumber), 0, t.Length);
     WriteParagraphSettings(result);
 }
Exemple #8
0
        /**
         * Writes the content of the RtfAnnotation
         *
         * @return The content of this RtfAnnotation
         */
        public override byte[] Write()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
                result.Write(ANNOTATION_ID, 0, ANNOTATION_ID.Length);
                result.Write(DELIMITER, 0, DELIMITER.Length);
                result.Write(t = IntToByteArray(document.GetRandomInt()), 0, t.Length);
                result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
                result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
                result.Write(ANNOTATION_AUTHOR, 0, ANNOTATION_AUTHOR.Length);
                result.Write(DELIMITER, 0, DELIMITER.Length);
                result.Write(t = DocWriter.GetISOBytes(title), 0, t.Length);
                result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
                result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
                result.Write(ANNOTATION, 0, ANNOTATION.Length);
                result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
                result.Write(DELIMITER, 0, DELIMITER.Length);
                result.Write(t = DocWriter.GetISOBytes(content), 0, t.Length);
                result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #9
0
        /**
         * Writes the content of this RtfListItem.
         *
         * @return A byte array with the content of this RtfListItem.
         */
        public override byte[] Write()
        {
            MemoryStream result = new MemoryStream();

            try {
                byte[] t;
                for (int i = 0; i < chunks.Count; i++)
                {
                    IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i];
                    if (rtfElement is RtfChunk)
                    {
                        ((RtfChunk)rtfElement).SetSoftLineBreaks(true);
                    }
                    else if (rtfElement is RtfList)
                    {
                        result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
                        this.containsInnerList = true;
                    }
                    result.Write(t = rtfElement.Write(), 0, t.Length);
                    if (rtfElement is RtfList)
                    {
                        result.Write(t = this.parentList.WriteListBeginning(), 0, t.Length);
                        result.Write(t = DocWriter.GetISOBytes("\\tab"), 0, t.Length);
                    }
                }
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #10
0
 /**
  * method for writing custom stuff to the Field Result part of an
  * RtfField.
  * @param outp
  * @throws IOException
  */
 public override void WriteRtfFieldResultStuff(Stream outp)
 {
     if (null != fieldResult)
     {
         byte[] t = DocWriter.GetISOBytes(fieldResult.Trim());
         outp.Write(t, 0, t.Length);
     }
 }
Exemple #11
0
 /**
  * Appends a <CODE>string</CODE> to the buffer. The <CODE>string</CODE> is
  * converted according to the encoding ISO-8859-1.
  * @param str the <CODE>string</CODE> to be appended
  * @return a reference to this <CODE>ByteBuffer</CODE> object
  */
 virtual public ByteBuffer Append(string str)
 {
     if (str != null)
     {
         return(Append(DocWriter.GetISOBytes(str)));
     }
     return(this);
 }
Exemple #12
0
 /**
  * write this RtfField into a stream using the writer given as
  * first argument.
  * @param writer the RtfWriter to use to write this RtfField
  * @param outp the Stream to write this RtfField into.
  * @throws IOException
  */
 public override void Write(RtfWriter writer, Stream outp)
 {
     writer.WriteInitialFontSignature(outp, this);
     byte[] t = DocWriter.GetISOBytes(content);
     outp.Write(t, 0, t.Length);
     writer.WriteFinishingFontSignature(outp, this);
     base.Write(writer, outp);
 }
Exemple #13
0
        /**
         * Get the RTF control word for <code>style</code>
         * @param style a style value
         * @return a byte array corresponding with a style control word
         */
        protected internal static byte[] GetStyleControlWord(int style)
        {
            switch (style)
            {
            case BORDER_UNDEFINED: return(DocWriter.GetISOBytes("brdrs"));

            case BORDER_SINGLE: return(DocWriter.GetISOBytes("brdrs"));

            case BORDER_DOUBLE_THICK: return(DocWriter.GetISOBytes("brdrth"));

            case BORDER_SHADOWED: return(DocWriter.GetISOBytes("brdrsh"));

            case BORDER_DOTTED: return(DocWriter.GetISOBytes("brdrdot"));

            case BORDER_DASHED: return(DocWriter.GetISOBytes("brdrdash"));

            case BORDER_HAIRLINE: return(DocWriter.GetISOBytes("brdrhair"));

            case BORDER_DOUBLE: return(DocWriter.GetISOBytes("brdrdb"));

            case BORDER_DOT_DASH: return(DocWriter.GetISOBytes("brdrdashd"));

            case BORDER_DOT_DOT_DASH: return(DocWriter.GetISOBytes("brdrdashdd"));

            case BORDER_TRIPLE: return(DocWriter.GetISOBytes("brdrtriple"));

            case BORDER_THICK_THIN: return(DocWriter.GetISOBytes("brdrtnthsg"));

            case BORDER_THIN_THICK: return(DocWriter.GetISOBytes("brdrthtnsg"));

            case BORDER_THIN_THICK_THIN: return(DocWriter.GetISOBytes("brdrtnthtnsg"));

            case BORDER_THICK_THIN_MED: return(DocWriter.GetISOBytes("brdrtnthmg"));

            case BORDER_THIN_THICK_MED: return(DocWriter.GetISOBytes("brdrthtnmg"));

            case BORDER_THIN_THICK_THIN_MED: return(DocWriter.GetISOBytes("brdrtnthtnmg"));

            case BORDER_THICK_THIN_LARGE: return(DocWriter.GetISOBytes("brdrtnthlg"));

            case BORDER_THIN_THICK_LARGE: return(DocWriter.GetISOBytes("brdrthtnlg"));

            case BORDER_THIN_THICK_THIN_LARGE: return(DocWriter.GetISOBytes("brdrtnthtnlg"));

            case BORDER_WAVY: return(DocWriter.GetISOBytes("brdrwavy"));

            case BORDER_DOUBLE_WAVY: return(DocWriter.GetISOBytes("brdrwavydb"));

            case BORDER_STRIPED: return(DocWriter.GetISOBytes("brdrdashdotstr"));

            case BORDER_EMBOSS: return(DocWriter.GetISOBytes("brdremboss"));

            case BORDER_ENGRAVE: return(DocWriter.GetISOBytes("brdrengrave"));
            }

            return(DocWriter.GetISOBytes("brdrs"));
        }
Exemple #14
0
        virtual public bool ReadKey(PdfDictionary enc, byte[] password)
        {
            if (password == null)
            {
                password = new byte[0];
            }
            byte[]  oValue     = DocWriter.GetISOBytes(enc.Get(PdfName.O).ToString());
            byte[]  uValue     = DocWriter.GetISOBytes(enc.Get(PdfName.U).ToString());
            byte[]  oeValue    = DocWriter.GetISOBytes(enc.Get(PdfName.OE).ToString());
            byte[]  ueValue    = DocWriter.GetISOBytes(enc.Get(PdfName.UE).ToString());
            byte[]  perms      = DocWriter.GetISOBytes(enc.Get(PdfName.PERMS).ToString());
            bool    isUserPass = false;
            IDigest md         = DigestUtilities.GetDigest("SHA-256");

            md.BlockUpdate(password, 0, Math.Min(password.Length, 127));
            md.BlockUpdate(oValue, VALIDATION_SALT_OFFSET, SALT_LENGHT);
            md.BlockUpdate(uValue, 0, OU_LENGHT);
            byte[]            hash        = DigestUtilities.DoFinal(md);
            bool              isOwnerPass = CompareArray(hash, oValue, 32);
            AESCipherCBCnoPad ac;

            if (isOwnerPass)
            {
                md.BlockUpdate(password, 0, Math.Min(password.Length, 127));
                md.BlockUpdate(oValue, KEY_SALT_OFFSET, SALT_LENGHT);
                md.BlockUpdate(uValue, 0, OU_LENGHT);
                md.DoFinal(hash, 0);
                ac  = new AESCipherCBCnoPad(false, hash);
                key = ac.ProcessBlock(oeValue, 0, oeValue.Length);
            }
            else
            {
                md.BlockUpdate(password, 0, Math.Min(password.Length, 127));
                md.BlockUpdate(uValue, VALIDATION_SALT_OFFSET, SALT_LENGHT);
                md.DoFinal(hash, 0);
                isUserPass = CompareArray(hash, uValue, 32);
                if (!isUserPass)
                {
                    throw new BadPasswordException(MessageLocalization.GetComposedMessage("bad.user.password"));
                }
                md.BlockUpdate(password, 0, Math.Min(password.Length, 127));
                md.BlockUpdate(uValue, KEY_SALT_OFFSET, SALT_LENGHT);
                md.DoFinal(hash, 0);
                ac  = new AESCipherCBCnoPad(false, hash);
                key = ac.ProcessBlock(ueValue, 0, ueValue.Length);
            }
            ac = new AESCipherCBCnoPad(false, key);
            byte[] decPerms = ac.ProcessBlock(perms, 0, perms.Length);
            if (decPerms[9] != (byte)'a' || decPerms[10] != (byte)'d' || decPerms[11] != (byte)'b')
            {
                throw new BadPasswordException(MessageLocalization.GetComposedMessage("bad.user.password"));
            }
            permissions = (decPerms[0] & 0xff) | ((decPerms[1] & 0xff) << 8)
                          | ((decPerms[2] & 0xff) << 16) | ((decPerms[2] & 0xff) << 24);
            encryptMetadata = decPerms[8] == (byte)'T';
            return(isOwnerPass);
        }
Exemple #15
0
 /**
  * Writes the RTF generator group.
  */
 public override void WriteContent(Stream result)
 {
     result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
     result.Write(GENERATOR, 0, GENERATOR.Length);
     result.Write(DELIMITER, 0, DELIMITER.Length);
     byte[] t;
     result.Write(t = DocWriter.GetISOBytes(Legacy.Text.Document.Version), 0, t.Length);
     result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
     this.document.OutputDebugLinebreak(result);
 }
Exemple #16
0
        /**
         * Write the field instructions for this RtfAnchor. Sets the field
         * type to HYPERLINK and then writes the url.
         *
         * @return The field instructions for this RtfAnchor
         * @throws IOException
         */
        protected override byte[] WriteFieldInstContent()
        {
            MemoryStream result = new MemoryStream();

            result.Write(HYPERLINK, 0, HYPERLINK.Length);
            result.Write(DELIMITER, 0, DELIMITER.Length);
            byte[] t;
            result.Write(t = DocWriter.GetISOBytes(url), 0, t.Length);

            return(result.ToArray());
        }
Exemple #17
0
 /**
  * Writes eficiently to a stream
  *
  * @param os the stream to write to
  * @throws IOException on write error
  */
 internal protected 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);
 }
Exemple #18
0
        /**
         * Write this RtfShapePosition.
         */
        public override byte[] Write()
        {
            MemoryStream result = new MemoryStream();

            try {
                byte[] t;
                result.Write(t = DocWriter.GetISOBytes("\\shpleft"), 0, t.Length);
                result.Write(t = IntToByteArray(this.left), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\shptop"), 0, t.Length);
                result.Write(t = IntToByteArray(this.top), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\shpright"), 0, t.Length);
                result.Write(t = IntToByteArray(this.right), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\shpbottom"), 0, t.Length);
                result.Write(t = IntToByteArray(this.bottom), 0, t.Length);
                result.Write(t = DocWriter.GetISOBytes("\\shpz"), 0, t.Length);
                result.Write(t = IntToByteArray(this.zOrder), 0, t.Length);
                switch (this.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 (this.ignoreXRelative)
                {
                    result.Write(t = DocWriter.GetISOBytes("\\shpbxignore"), 0, t.Length);
                }
                switch (this.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 (this.ignoreYRelative)
                {
                    result.Write(t = DocWriter.GetISOBytes("\\shpbyignore"), 0, t.Length);
                }
                if (this.shapeBelowText)
                {
                    result.Write(t = DocWriter.GetISOBytes("\\shpfblwtxt1"), 0, t.Length);
                }
                else
                {
                    result.Write(t = DocWriter.GetISOBytes("\\shpfblwtxt0"), 0, t.Length);
                }
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #19
0
        /**
         * Writes this RtfInfoElement
         *
         * @return A byte array containing the RtfInfoElement data
         */
        public override byte[] Write()
        {
            MemoryStream result = new MemoryStream();

            try {
                result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
                switch (infoType)
                {
                case Element.AUTHOR:
                    result.Write(INFO_AUTHOR, 0, INFO_AUTHOR.Length);
                    break;

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

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

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

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

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

                default:
                    result.Write(INFO_AUTHOR, 0, INFO_AUTHOR.Length);
                    break;
                }
                result.Write(DELIMITER, 0, DELIMITER.Length);
                byte[] t;
                if (infoType == Element.CREATIONDATE)
                {
                    t = DocWriter.GetISOBytes(ConvertDate(content));
                }
                else
                {
                    t = DocWriter.GetISOBytes(content);
                }
                result.Write(t, 0, t.Length);
                result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #20
0
        /**
         * Writes the start information of this RtfParagraphStyle.
         */
        public override byte[] WriteBegin()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                result.Write(t = DocWriter.GetISOBytes("\\s"), 0, t.Length);
                result.Write(t = IntToByteArray(this.styleNumber), 0, t.Length);
                result.Write(t = WriteParagraphSettings(), 0, t.Length);
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #21
0
        /**
         * Writes the content of this RtfListItem.
         */
        public override void WriteContent(Stream result)
        {
            byte[] t;
            if (this.paragraphStyle.GetSpacingBefore() > 0)
            {
                result.Write(RtfParagraphStyle.SPACING_BEFORE, 0, RtfParagraphStyle.SPACING_BEFORE.Length);
                result.Write(t = IntToByteArray(paragraphStyle.GetSpacingBefore()), 0, t.Length);
            }
            if (this.paragraphStyle.GetSpacingAfter() > 0)
            {
                result.Write(RtfParagraphStyle.SPACING_AFTER, 0, RtfParagraphStyle.SPACING_AFTER.Length);
                result.Write(t = IntToByteArray(this.paragraphStyle.GetSpacingAfter()), 0, t.Length);
            }
            if (this.paragraphStyle.GetLineLeading() > 0)
            {
                result.Write(RtfParagraph.LINE_SPACING, 0, RtfParagraph.LINE_SPACING.Length);
                result.Write(t = IntToByteArray(this.paragraphStyle.GetLineLeading()), 0, t.Length);
            }
            for (int i = 0; i < chunks.Count; i++)
            {
                IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i];
                if (rtfElement is RtfChunk)
                {
                    ((RtfChunk)rtfElement).SetSoftLineBreaks(true);
                }
                else if (rtfElement is RtfList)
                {
                    result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length);
                    this.containsInnerList = true;
                }
                rtfElement.WriteContent(result);
                if (rtfElement is RtfList)
                {
                    switch (this.parentList.GetLevelFollowValue())
                    {
                    case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING:
                        break;

                    case RtfListLevel.LIST_LEVEL_FOLLOW_TAB:
                        this.parentList.WriteListBeginning(result);
                        result.Write(RtfList.TAB, 0, RtfList.TAB.Length);
                        break;

                    case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE:
                        this.parentList.WriteListBeginning(result);
                        result.Write(t = DocWriter.GetISOBytes(" "), 0, t.Length);
                        break;
                    }
                }
            }
        }
 /**
  * Writes the definition of the stylesheet list.
  */
 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 = RtfElement.DELIMITER, 0, t.Length);
     this.document.OutputDebugLinebreak(result);
     foreach (RtfParagraphStyle rps in this.styleMap.Values)
     {
         rps.WriteDefinition(result);
     }
     result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length);
     this.document.OutputDebugLinebreak(result);
 }
        /**
         * Writes the tab settings.
         */
        public override void WriteContent(Stream result)
        {
            byte[] t;
            switch (this.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(this.position), 0, t.Length);
        }
Exemple #24
0
        /**
         * Writes the font definition
         *
         * @return A byte array with the font definition
         */
        public virtual byte[] WriteDefinition()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                result.Write(FONT_FAMILY, 0, FONT_FAMILY.Length);
                result.Write(FONT_CHARSET, 0, FONT_CHARSET.Length);
                result.Write(t = IntToByteArray(charset), 0, t.Length);
                result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length);
                result.Write(t = DocWriter.GetISOBytes(document.FilterSpecialChar(fontName, true, false)), 0, t.Length);
            } catch (IOException) {
            }
            return(result.ToArray());
        }
Exemple #25
0
 /**
  * Writes the definition of this RtfParagraphStyle for the stylesheet list.
  */
 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(this.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(this.styleName), 0, t.Length);
     result.Write(t = DocWriter.GetISOBytes(";"), 0, t.Length);
     result.Write(t = DocWriter.GetISOBytes("}"), 0, t.Length);
     this.document.OutputDebugLinebreak(result);
 }
Exemple #26
0
        /**
         * Writes the content of one RTF information element.
         */
        public override void WriteContent(Stream result)
        {
            result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
            switch (infoType)
            {
            case Element.AUTHOR:
                result.Write(INFO_AUTHOR, 0, INFO_AUTHOR.Length);
                break;

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

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

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

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

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

            default:
                result.Write(INFO_AUTHOR, 0, INFO_AUTHOR.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(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
        }
Exemple #27
0
        /**
         * Writes eficiently to a stream
         *
         * @param os the stream to write to
         * @throws IOException on write error
         */
        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);
            int type = objecti.Type;

            if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME && type != PdfObject.STRING)
            {
                os.WriteByte((byte)' ');
            }
            objecti.ToPdf(writer, os);
            os.Write(ENDOBJ, 0, ENDOBJ.Length);
        }
Exemple #28
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);
        }
Exemple #29
0
        /**
         * Extracts the image data from the Image. The data is formated for direct inclusion
         * in a rtf document
         *
         * @param image The Image for which to extract the content
         * @return The image data formated for the rtf document
         * @throws DocumentException If an error occurs accessing the image content
         */
        private byte[] GetImage(Image image)
        {
            MemoryStream imageTemp = new MemoryStream();

            try {
                Stream imageIn;
                if (imageType == Image.ORIGINAL_BMP)
                {
                    imageIn = new MemoryStream(MetaDo.WrapBMP(image));
                }
                else
                {
                    if (image.OriginalData == null)
                    {
                        imageIn = WebRequest.Create(image.Url).GetResponse().GetResponseStream();
                    }
                    else
                    {
                        imageIn = new MemoryStream(image.OriginalData);
                    }
                    if (imageType == Image.ORIGINAL_WMF)   //remove the placeable header
                    {
                        Image.Skip(imageIn, 22);
                    }
                }
                int buffer = 0;
                int count  = 0;
                while ((buffer = imageIn.ReadByte()) != -1)
                {
                    String helperStr = buffer.ToString("X2");
                    byte[] t         = DocWriter.GetISOBytes(helperStr);
                    imageTemp.Write(t, 0, t.Length);
                    count++;
                    if (count == 64)
                    {
                        imageTemp.WriteByte((byte)'\n');
                        count = 0;
                    }
                }
            } catch (IOException ioe) {
                throw new DocumentException(ioe.ToString());
            }
            return(imageTemp.ToArray());
        }
Exemple #30
0
        /**
         * Writes the content of this RtfChunk. First the font information
         * is written, then the content, and then more font information
         *
         * @return A byte array with the content of this RtfChunk
         */
        public override byte[] Write()
        {
            MemoryStream result = new MemoryStream();

            byte[] t;
            try {
                if (this.background != null)
                {
                    result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
                }

                result.Write(t = font.WriteBegin(), 0, t.Length);
                if (superSubScript < 0)
                {
                    result.Write(FONT_SUBSCRIPT, 0, FONT_SUBSCRIPT.Length);
                }
                else if (superSubScript > 0)
                {
                    result.Write(FONT_SUPERSCRIPT, 0, FONT_SUPERSCRIPT.Length);
                }
                if (this.background != null)
                {
                    result.Write(HIGHLIGHT, 0, HIGHLIGHT.Length);
                    result.Write(t = IntToByteArray(this.background.GetColorNumber()), 0, t.Length);
                }
                result.Write(DELIMITER, 0, DELIMITER.Length);

                result.Write(t = DocWriter.GetISOBytes(document.FilterSpecialChar(content, false, softLineBreaks || this.document.GetDocumentSettings().IsAlwaysGenerateSoftLinebreaks())), 0, t.Length);

                if (superSubScript != 0)
                {
                    result.Write(FONT_END_SUPER_SUBSCRIPT, 0, FONT_END_SUPER_SUBSCRIPT.Length);
                }
                result.Write(t = font.WriteEnd(), 0, t.Length);

                if (this.background != null)
                {
                    result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
                }
            } catch (IOException) {
            }
            return(result.ToArray());
        }