Beispiel #1
0
        /**
         * Constructs a new RtfPhrase for the RtfDocument with the given Phrase
         *
         * @param doc The RtfDocument this RtfPhrase belongs to
         * @param phrase The Phrase this RtfPhrase is based on
         */
        public RtfPhrase(RtfDocument doc, Phrase phrase) : base(doc)
        {
            if (phrase == null)
            {
                return;
            }

            if (phrase.HasLeading())
            {
                this.lineLeading = (int)(phrase.Leading * TWIPS_FACTOR);
            }
            else
            {
                this.lineLeading = 0;
            }

            ST.RtfFont phraseFont = new ST.RtfFont(null, phrase.Font);
            for (int i = 0; i < phrase.Count; i++)
            {
                IElement chunk = (IElement)phrase[i];
                if (chunk is Chunk)
                {
                    ((Chunk)chunk).Font = phraseFont.Difference(((Chunk)chunk).Font);
                }
                try {
                    IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
                    for (int j = 0; j < rtfElements.Length; j++)
                    {
                        chunks.Add(rtfElements[j]);
                    }
                } catch (DocumentException) {
                }
            }
        }
Beispiel #2
0
        /**
         * Tests for equality of RtfFonts. RtfFonts are equal if their fontName,
         * fontSize, fontStyle and fontSuperSubscript are equal
         *
         * @param obj The RtfFont to compare with this RtfFont
         * @return <code>True</code> if the RtfFonts are equal, <code>false</code> otherwise
         */
        public override bool Equals(Object obj)
        {
            if (!(obj is RtfFont))
            {
                return(false);
            }
            RtfFont font   = (RtfFont)obj;
            bool    result = true;

            result = result & this.fontName.Equals(font.GetFontName());
            return(result);
        }
Beispiel #3
0
        /**
         * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
         *
         * @param doc The RtfDocument this RtfParagraph belongs to
         * @param paragraph The Paragraph that this RtfParagraph is based on
         */
        public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc)
        {
            ST.RtfFont baseFont = null;
            if (paragraph.Font is ST.RtfParagraphStyle)
            {
                this.paragraphStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle)paragraph.Font).GetStyleName());
                baseFont            = this.paragraphStyle;
            }
            else
            {
                baseFont            = new ST.RtfFont(this.document, paragraph.Font);
                this.paragraphStyle = new ST.RtfParagraphStyle(this.document, this.document.GetDocumentHeader().GetRtfParagraphStyle("Normal"));
                this.paragraphStyle.SetAlignment(paragraph.Alignment);
                this.paragraphStyle.SetFirstLineIndent((int)(paragraph.FirstLineIndent * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetIndentLeft((int)(paragraph.IndentationLeft * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetIndentRight((int)(paragraph.IndentationRight * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetSpacingBefore((int)(paragraph.SpacingBefore * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetSpacingAfter((int)(paragraph.SpacingAfter * RtfElement.TWIPS_FACTOR));
                if (paragraph.HasLeading())
                {
                    this.paragraphStyle.SetLineLeading((int)(paragraph.Leading * RtfElement.TWIPS_FACTOR));
                }
                this.paragraphStyle.SetKeepTogether(paragraph.KeepTogether);
            }

            for (int i = 0; i < paragraph.Count; i++)
            {
                IElement chunk = (IElement)paragraph[i];
                if (chunk is Chunk)
                {
                    ((Chunk)chunk).Font = baseFont.Difference(((Chunk)chunk).Font);
                }
                else if (chunk is RtfImage)
                {
                    ((RtfImage)chunks[i]).SetAlignment(this.paragraphStyle.GetAlignment());
                }
                try {
                    IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
                    for (int j = 0; j < rtfElements.Length; j++)
                    {
                        chunks.Add(rtfElements[j]);
                    }
                } catch (DocumentException) {
                }
            }
        }
Beispiel #4
0
        /**
         * Constructs a RtfChunk based on the content of a Chunk
         *
         * @param doc The RtfDocument that this Chunk belongs to
         * @param chunk The Chunk that this RtfChunk is based on
         */
        public RtfChunk(RtfDocument doc, Chunk chunk) : base(doc)
        {
            if (chunk == null)
            {
                return;
            }

            if (chunk.Attributes != null && chunk.Attributes[Chunk.SUBSUPSCRIPT] != null)
            {
                this.superSubScript = (float)chunk.Attributes[Chunk.SUBSUPSCRIPT];
            }
            if (chunk.Attributes != null && chunk.Attributes[Chunk.BACKGROUND] != null)
            {
                this.background = new RtfColor(this.document, (Color)((Object[])chunk.Attributes[Chunk.BACKGROUND])[0]);
            }
            font    = new ST.RtfFont(doc, chunk.Font);
            content = chunk.Content;
        }
Beispiel #5
0
 /**
  * Writes the definition of the font list
  */
 public virtual void WriteDefinition(Stream result)
 {
     byte[] t;
     result.Write(DEFAULT_FONT, 0, DEFAULT_FONT.Length);
     result.Write(t = IntToByteArray(0), 0, t.Length);
     result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
     result.Write(FONT_TABLE, 0, FONT_TABLE.Length);
     for (int i = 0; i < fontList.Count; i++)
     {
         result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
         result.Write(FONT_NUMBER, 0, FONT_NUMBER.Length);
         result.Write(t = IntToByteArray(i), 0, t.Length);
         RtfFont rf = (RtfFont)fontList[i];
         rf.WriteDefinition(result);
         result.Write(COMMA_DELIMITER, 0, COMMA_DELIMITER.Length);
         result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
     }
     result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
     this.document.OutputDebugLinebreak(result);
 }
Beispiel #6
0
        /**
         * Gets the index of the font in the list of fonts. If the font does not
         * exist in the list, it is added.
         *
         * @param font The font to get the id for
         * @return The index of the font
         */
        public int GetFontNumber(RtfFont font)
        {
            if (font is RtfParagraphStyle)
            {
                font = new RtfFont(this.document, (RtfParagraphStyle)font);
            }
            int fontIndex = -1;

            for (int i = 0; i < fontList.Count; i++)
            {
                if (fontList[i].Equals(font))
                {
                    fontIndex = i;
                }
            }
            if (fontIndex == -1)
            {
                fontIndex = fontList.Count;
                fontList.Add(font);
            }
            return(fontIndex);
        }
Beispiel #7
0
 /**
 * Constructs a RtfField for a RtfDocument. This is not very usefull,
 * since the RtfField by itself does not do anything. Use one of the
 * subclasses instead.
 *
 * @param doc The RtfDocument this RtfField belongs to.
 * @param font The Font this RtfField should use
 */
 protected RtfField(RtfDocument doc, Font font)
     : base("", font)
 {
     this.document = doc;
     this.font = new ST.RtfFont(this.document, font);
 }
Beispiel #8
0
 /**
 * @param fontNumber the fontNumber to set
 */
 public void SetFontNumber(RtfFont fontNumber)
 {
     this.fontNumber = fontNumber;
 }
Beispiel #9
0
 /**
 * @param fontBullet the fontBullet to set
 */
 public void SetFontBullet(RtfFont fontBullet)
 {
     this.fontBullet = fontBullet;
 }
Beispiel #10
0
 /**
 * set the bullet font
 * @param f
 */
 public void SetBulletFont(Font f)
 {
     this.fontBullet = new RtfFont(document, f);
 }
Beispiel #11
0
 public RtfListLevel(RtfListLevel ll)
     : base(ll.document)
 {
     templateID = document.GetRandomInt();
     this.alignment = ll.alignment;
     this.bulletCharacter = ll.bulletCharacter;
     this.firstIndent = ll.firstIndent;
     this.fontBullet = ll.fontBullet;
     this.fontNumber = ll.fontNumber;
     this.inHeader = ll.inHeader;
     this.inTable = ll.inTable;
     this.leftIndent = ll.leftIndent;
     this.listLevel = ll.listLevel;
     this.listNoRestart = ll.listNoRestart;
     this.listStartAt = ll.listStartAt;
     this.listType = ll.listType;
     this.parent = ll.parent;
     this.rightIndent = ll.rightIndent;
     this.symbolIndent = ll.symbolIndent;
 }
Beispiel #12
0
 /**
 * Gets the index of the font in the list of fonts. If the font does not
 * exist in the list, it is added.
 *
 * @param font The font to get the id for
 * @return The index of the font
 */
 public int GetFontNumber(RtfFont font)
 {
     if(font is RtfParagraphStyle) {
         font = new RtfFont(this.document, (RtfParagraphStyle) font);
     }
     int fontIndex = -1;
     for (int i = 0; i < fontList.Count; i++) {
         if (fontList[i].Equals(font)) {
             fontIndex = i;
         }
     }
     if (fontIndex == -1) {
         fontIndex = fontList.Count;
         fontList.Add(font);
     }
     return fontIndex;
 }
Beispiel #13
0
 /**
  * Constructs a RtfField for a RtfDocument. This is not very usefull,
  * since the RtfField by itself does not do anything. Use one of the
  * subclasses instead.
  *
  * @param doc The RtfDocument this RtfField belongs to.
  * @param font The Font this RtfField should use
  */
 protected RtfField(RtfDocument doc, Font font) : base("", font)
 {
     this.document = doc;
     this.font     = new ST.RtfFont(this.document, font);
 }
Beispiel #14
0
        /**
        * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
        *
        * @param doc The RtfDocument this RtfParagraph belongs to
        * @param paragraph The Paragraph that this RtfParagraph is based on
        */
        public RtfParagraph(RtfDocument doc, Paragraph paragraph)
            : base(doc)
        {
            ST.RtfFont baseFont = null;
            if (paragraph.Font is ST.RtfParagraphStyle) {
                this.paragraphStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle) paragraph.Font).GetStyleName());
                baseFont = this.paragraphStyle;
            } else {
                baseFont = new ST.RtfFont(this.document, paragraph.Font);
                this.paragraphStyle = new ST.RtfParagraphStyle(this.document, this.document.GetDocumentHeader().GetRtfParagraphStyle("Normal"));
                this.paragraphStyle.SetAlignment(paragraph.Alignment);
                this.paragraphStyle.SetFirstLineIndent((int) (paragraph.FirstLineIndent * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetIndentLeft((int) (paragraph.IndentationLeft * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetIndentRight((int) (paragraph.IndentationRight * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetSpacingBefore((int) (paragraph.SpacingBefore * RtfElement.TWIPS_FACTOR));
                this.paragraphStyle.SetSpacingAfter((int) (paragraph.SpacingAfter * RtfElement.TWIPS_FACTOR));
                if (paragraph.HasLeading()) {
                    this.paragraphStyle.SetLineLeading((int) (paragraph.Leading * RtfElement.TWIPS_FACTOR));
                }
                this.paragraphStyle.SetKeepTogether(paragraph.KeepTogether);
            }

            for (int i = 0; i < paragraph.Count; i++) {
                IElement chunk = (IElement) paragraph[i];
                if (chunk is Chunk) {
                    ((Chunk) chunk).Font = baseFont.Difference(((Chunk) chunk).Font);
                } else if (chunk is RtfImage) {
                    ((RtfImage) chunks[i]).SetAlignment(this.paragraphStyle.GetAlignment());
                }
                try {
                    IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
                    for(int j = 0; j < rtfElements.Length; j++) {
                        chunks.Add(rtfElements[j]);
                    }
                } catch (DocumentException) {
                }
            }
        }
Beispiel #15
0
        /**
        * Constructs a new RtfPhrase for the RtfDocument with the given Phrase
        *
        * @param doc The RtfDocument this RtfPhrase belongs to
        * @param phrase The Phrase this RtfPhrase is based on
        */
        public RtfPhrase(RtfDocument doc, Phrase phrase)
            : base(doc)
        {
            if (phrase == null) {
                return;
            }

            if (phrase.HasLeading()) {
                this.lineLeading = (int) (phrase.Leading * TWIPS_FACTOR);
            } else {
                this.lineLeading = 0;
            }

            ST.RtfFont phraseFont = new ST.RtfFont(null, phrase.Font);
            for (int i = 0; i < phrase.Count; i++) {
                IElement chunk = (IElement) phrase[i];
                if (chunk is Chunk) {
                    ((Chunk) chunk).Font = phraseFont.Difference(((Chunk) chunk).Font);
                }
                try {
                    IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk);
                    for (int j = 0; j < rtfElements.Length; j++) {
                        chunks.Add(rtfElements[j]);
                    }
                } catch (DocumentException) {
                }
            }
        }
Beispiel #16
0
        /**
        * Constructs a RtfChunk based on the content of a Chunk
        *
        * @param doc The RtfDocument that this Chunk belongs to
        * @param chunk The Chunk that this RtfChunk is based on
        */
        public RtfChunk(RtfDocument doc, Chunk chunk)
            : base(doc)
        {
            if (chunk == null) {
                return;
            }

            if (chunk.Attributes != null && chunk.Attributes[Chunk.SUBSUPSCRIPT] != null) {
                this.superSubScript = (float)chunk.Attributes[Chunk.SUBSUPSCRIPT];
            }
            if (chunk.Attributes != null && chunk.Attributes[Chunk.BACKGROUND] != null) {
                this.background = new RtfColor(this.document, (Color) ((Object[]) chunk.Attributes[Chunk.BACKGROUND])[0]);
            }
            font = new ST.RtfFont(doc, chunk.Font);
            content = chunk.Content;
        }
Beispiel #17
0
        /**
        * Imports a font. The font name is looked up in the RtfDocumentHeader and
        * then the mapping from original font number to actual font number is added.
        *
        * @param fontNr The original font number.
        * @param fontName The font name to look up.
        * @param charset The characterset to use for the font.
        */
        public bool ImportFont(String fontNr, String fontName, String fontFamily, int charset)
        {
            RtfFont rtfFont = new RtfFont(fontName);

            if (charset>= 0)
                rtfFont.SetCharset(charset);
            if (fontFamily != null && fontFamily.Length > 0)
                rtfFont.SetFamily(fontFamily);
            rtfFont.SetRtfDocument(this.rtfDoc);
            this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
            return true;
        }
Beispiel #18
0
 /**
 * Imports a font. The font name is looked up in the RtfDocumentHeader and
 * then the mapping from original font number to actual font number is added.
 *
 * @param fontNr The original font number.
 * @param fontName The font name to look up.
 */
 public bool ImportFont(String fontNr, String fontName)
 {
     RtfFont rtfFont = new RtfFont(fontName);
     if (rtfFont != null){
         rtfFont.SetRtfDocument(this.rtfDoc);
         this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
         return true;
     } else {
         return false;
     }
 }
 /**
  * Gets the number of the specified RtfFont
  *
  * @param font The RtfFont for which to get the number
  * @return The number of the font
  */
 public int GetFontNumber(ST.RtfFont font)
 {
     return(this.fontList.GetFontNumber(font));
 }