Наследование: iTextSharp.text.Font, IRtfExtendedElement
Пример #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.LeadingDefined)
            {
                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 {
                    chunks.Add(doc.GetMapper().MapElement(chunk));
                } catch (DocumentException) {
                }
            }
        }
Пример #2
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) {
                }
            }
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
        /// </summary>
        /// <param name="doc">The RtfDocument this RtfParagraph belongs to</param>
        /// <param name="paragraph">The Paragraph that this RtfParagraph is based on</param>
        public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc)
        {
            ST.RtfFont baseFont = null;
            if (paragraph.Font is ST.RtfParagraphStyle)
            {
                ParagraphStyle = Document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle)paragraph.Font).GetStyleName());
                baseFont       = ParagraphStyle;
            }
            else
            {
                baseFont       = new ST.RtfFont(Document, paragraph.Font);
                ParagraphStyle = new ST.RtfParagraphStyle(Document, Document.GetDocumentHeader().GetRtfParagraphStyle("Normal"));
                ParagraphStyle.SetAlignment(paragraph.Alignment);
                ParagraphStyle.SetFirstLineIndent((int)(paragraph.FirstLineIndent * TWIPS_FACTOR));
                ParagraphStyle.SetIndentLeft((int)(paragraph.IndentationLeft * TWIPS_FACTOR));
                ParagraphStyle.SetIndentRight((int)(paragraph.IndentationRight * TWIPS_FACTOR));
                ParagraphStyle.SetSpacingBefore((int)(paragraph.SpacingBefore * TWIPS_FACTOR));
                ParagraphStyle.SetSpacingAfter((int)(paragraph.SpacingAfter * TWIPS_FACTOR));
                if (paragraph.HasLeading())
                {
                    ParagraphStyle.SetLineLeading((int)(paragraph.Leading * TWIPS_FACTOR));
                }
                ParagraphStyle.SetKeepTogether(paragraph.KeepTogether);
            }

            for (var i = 0; i < paragraph.Count; i++)
            {
                var 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(ParagraphStyle.GetAlignment());
                }
                try
                {
                    var rtfElements = doc.GetMapper().MapElement(chunk);
                    for (var j = 0; j < rtfElements.Length; j++)
                    {
                        Chunks.Add(rtfElements[j]);
                    }
                }
                catch (DocumentException)
                {
                }
            }
        }
Пример #5
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;
        }
 /// <summary>
 /// Writes the definition of the font list
 /// </summary>
 public virtual void WriteDefinition(Stream result)
 {
     byte[] t;
     result.Write(_defaultFont, 0, _defaultFont.Length);
     result.Write(t = IntToByteArray(0), 0, t.Length);
     result.Write(OpenGroup, 0, OpenGroup.Length);
     result.Write(_fontTable, 0, _fontTable.Length);
     for (int i = 0; i < _fontList.Count; i++)
     {
         result.Write(OpenGroup, 0, OpenGroup.Length);
         result.Write(FontNumber, 0, FontNumber.Length);
         result.Write(t = IntToByteArray(i), 0, t.Length);
         RtfFont rf = (RtfFont)_fontList[i];
         rf.WriteDefinition(result);
         result.Write(CommaDelimiter, 0, CommaDelimiter.Length);
         result.Write(CloseGroup, 0, CloseGroup.Length);
     }
     result.Write(CloseGroup, 0, CloseGroup.Length);
     Document.OutputDebugLinebreak(result);
 }
 /**
  * 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);
 }
Пример #8
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.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.LeadingDefined)
                {
                    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 {
                    chunks.Add(doc.GetMapper().MapElement(chunk));
                } catch (DocumentException) {
                }
            }
        }
        /// <summary>
        /// Gets the index of the font in the list of fonts. If the font does not
        /// exist in the list, it is added.
        /// </summary>
        /// <param name="font">The font to get the id for</param>
        /// <returns>The index of the font</returns>
        public int GetFontNumber(RtfFont font)
        {
            if (font is RtfParagraphStyle)
            {
                font = new RtfFont(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);
        }
Пример #10
0
        /**
        * Constructs a new RtfList for the specified List.
        *
        * @param doc The RtfDocument this RtfList belongs to
        * @param list The List this RtfList is based on
        */
        public RtfList(RtfDocument doc, List list)
            : base(doc)
        {
            this.listNumber = document.GetDocumentHeader().GetListNumber(this);

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

            for (int i = 0; i < list.Items.Count; i++) {
                try {
                    IElement element = (IElement) list.Items[i];
                    if (element.Type == Element.CHUNK) {
                        element = new ListItem((Chunk) element);
                    }
                    if (element is ListItem) {
                        this.alignment = ((ListItem) element).Alignment;
                    }
                    IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element);
                    if (rtfElement is RtfList) {
                        ((RtfList) rtfElement).SetListNumber(listNumber);
                        ((RtfList) rtfElement).SetListLevel(listLevel + 1);
                        ((RtfList) rtfElement).SetParent(this);
                    } else if (rtfElement is RtfListItem) {
                        ((RtfListItem) rtfElement).SetParent(this);
                        ((RtfListItem) rtfElement).InheritListSettings(listNumber, listLevel + 1);
                    }
                    items.Add(rtfElement);
                } catch (DocumentException ) {
                }
            }
            if (this.listLevel == 0) {
                CorrectIndentation();
            }

            fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
            fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
        }
Пример #11
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;
 }
Пример #12
0
 /**
 * @param fontBullet the fontBullet to set
 */
 public void SetFontBullet(RtfFont fontBullet) {
     this.fontBullet = fontBullet;
 }
Пример #13
0
 /**
 * @param fontNumber the fontNumber to set
 */
 public void SetFontNumber(RtfFont fontNumber) {
     this.fontNumber = fontNumber;
 }
Пример #14
0
 /**
 * set the bullet font
 * @param f
 */
 public void SetBulletFont(Font f) {
     this.fontBullet = new RtfFont(document, f);
 }
Пример #15
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;
 }
Пример #16
0
 /// <summary>
 /// 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.
 /// </summary>
 /// <param name="doc">The RtfDocument this RtfField belongs to.</param>
 /// <param name="font">The Font this RtfField should use</param>
 protected RtfField(RtfDocument doc, Font font) : base("", font)
 {
     Document = doc;
     _font    = new ST.RtfFont(Document, font);
 }
Пример #17
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) {
         }
     }
 }
Пример #18
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;
        }
Пример #19
0
        /**
         * Constructs a new RtfList for the specified List.
         *
         * @param doc The RtfDocument this RtfList belongs to
         * @param list The List this RtfList is based on
         */
        public RtfList(RtfDocument doc, List list) : base(doc)
        {
            this.listNumber = document.GetDocumentHeader().GetListNumber(this);

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

            for (int i = 0; i < list.Items.Count; i++)
            {
                try {
                    IElement element = (IElement)list.Items[i];
                    if (element.Type == Element.CHUNK)
                    {
                        element = new ListItem((Chunk)element);
                    }
                    if (element is ListItem)
                    {
                        this.alignment = ((ListItem)element).Alignment;
                    }
                    IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element);
                    if (rtfElement is RtfList)
                    {
                        ((RtfList)rtfElement).SetListNumber(listNumber);
                        ((RtfList)rtfElement).SetListLevel(listLevel + 1);
                        ((RtfList)rtfElement).SetParent(this);
                    }
                    else if (rtfElement is RtfListItem)
                    {
                        ((RtfListItem)rtfElement).SetParent(this);
                        ((RtfListItem)rtfElement).InheritListSettings(listNumber, listLevel + 1);
                    }
                    items.Add(rtfElement);
                } catch (DocumentException) {
                }
            }
            if (this.listLevel == 0)
            {
                CorrectIndentation();
            }

            fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
            fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
        }
Пример #20
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);
 }
Пример #21
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 void ImportFont(String fontNr, String fontName)
 {
     iTextSharp.text.rtf.style.RtfFont rtfFont = new iTextSharp.text.rtf.style.RtfFont(fontName);
     rtfFont.SetRtfDocument(this.rtfDoc);
     this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
 }
Пример #22
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;
        }
Пример #23
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;
     }
 }
Пример #24
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.LeadingDefined) {
                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 {
                    chunks.Add(doc.GetMapper().MapElement(chunk));
                } catch (DocumentException) {
                }
            }
        }
Пример #25
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 void ImportFont(String fontNr, String fontName)
 {
     iTextSharp.text.rtf.style.RtfFont rtfFont = new iTextSharp.text.rtf.style.RtfFont(fontName);
     rtfFont.SetRtfDocument(this.rtfDoc);
     this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
 }
Пример #26
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) {
         }
     }
 }
 /**
  * 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));
 }
Пример #28
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);
 }