Пример #1
0
        private static string GetKnownFontString(RtfFont font)
        {
            switch (font)
            {
            case RtfFont.Arial:
                return(@"{{\f{0}\fswiss\fprq2\fcharset0 Arial;}}");

            case RtfFont.Calibri:
                return(@"{{\f{0}\fnil\fcharset0 Calibri;}}");

            case RtfFont.Consolas:
                return(@"{{\f{0}\fmodern\fprq1\fcharset0 Consolas;}}");

            case RtfFont.CourierNew:
                return(@"{{\f{0}\fmodern\fprq1\fcharset0 Courier New;}}");

            case RtfFont.Impact:
                return(@"{{\f{0}\fswiss\fprq2\fcharset0 Impact;}}");

            case RtfFont.LucidaConsole:
                return(@"{{\f{0}\fmodern\fprq1\fcharset0 Lucida Console;}}");

            case RtfFont.MSSansSerif:
                return(@"{{\f{0}\fswiss\fprq2\fcharset0 MS Reference Sans Serif;}}");

            case RtfFont.Symbol:
                return(@"{{\f{0}\ftech\fcharset0 Symbol;}}");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        /// <summary>
        /// Process one font
        /// </summary>
        /// <param name="item"></param>
        private void _ProcessRtfBlockFontOne(Parsing.ParsedItem item)
        {   // for example: \f0\fswiss\fcharset238{\*\fname Arial;}Arial CE;
            //              \f2\fmodern\fprq1\fcharset0 Envy Code R;
            if (!item.HasItems)
            {
                return;
            }
            RtfFont rtfFont = new RtfFont();

            for (int index = 0; index < item.ItemCount; index++)
            {
                Parsing.ParsedItem          subItem  = item.Items[index];
                Parsing.IParsedItemExtended eSubItem = subItem as Parsing.IParsedItemExtended;
                if (subItem.HasItems)
                {
                    if (index == 0)
                    {                                 // Font number in table:
                        rtfFont.Key = item.TextInner; // f2
                    }
                    else
                    {
                        string rtfValue;
                        string rtfEntity = GetRtfEntityFirst(subItem, out rtfValue);     // "fswiss", "fcharset"+"238",
                        switch (rtfEntity)
                        {
                        case "fswiss":
                        case "fmodern":
                        case "fnil":
                            rtfFont.Family = rtfEntity;
                            break;

                        case "fprq":
                            break;

                        case "fcharset":
                            rtfFont.CharSet = rtfValue;
                            this._ProcessRtfBlockFontName(item, ref index, rtfFont);
                            break;

                        default:
                            this._ProcessAddRtfError("FontItem", rtfEntity);
                            break;
                        }
                    }
                }
            }

            if (rtfFont.IsValid)
            {
                if (this._Fonts.ContainsKey(rtfFont.Key))
                {
                    this._Fonts[rtfFont.Key] = rtfFont;
                }
                else
                {
                    this._Fonts.Add(rtfFont.Key, rtfFont);
                }
            }
        }
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="fontNr">The original font number.</param>
        /// <param name="fontName">The font name to look up.</param>
        public bool ImportFont(string fontNr, string fontName)
        {
            RtfFont rtfFont = new RtfFont(fontName);

            rtfFont.SetRtfDocument(_rtfDoc);
            _importFontMapping[fontNr] = _rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
            return(true);
        }
Пример #4
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, int charset)
        {
            RtfFont rtfFont = new RtfFont(fontName);

            if (charset >= 0)
            {
                rtfFont.SetCharset(charset);
            }
            rtfFont.SetRtfDocument(this.rtfDoc);
            this.importFontMapping[fontNr] = this.rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
            return(true);
        }
Пример #5
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="fontNr">The original font number.</param>
        /// <param name="fontName">The font name to look up.</param>
        /// <param name="charset">The characterset to use for the font.</param>
        public bool ImportFont(string fontNr, string fontName, int charset)
        {
            var rtfFont = new RtfFont(fontName);

            if (charset >= 0)
            {
                rtfFont.SetCharset(charset);
            }

            rtfFont.SetRtfDocument(_rtfDoc);
            _importFontMapping[fontNr] = _rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
            return(true);
        }
Пример #6
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);
            }
        }
Пример #7
0
        public RtfBuilder(RtfFont defaultFont, float defaultFontSize)
        {
            buffer = new StringBuilder();

            fontIndex = IndexOfFont(defaultFont);

            this.defaultFontSize = defaultFontSize;
            fontSize             = defaultFontSize;

            usedColors.Add(defaultForeColor);
            usedColors.Add(defaultBackColor);

            fontStyle = FontStyle.Regular;
            foreColor = defaultForeColor;
            backColor = defaultBackColor;
        }
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="fontNr">The original font number.</param>
        /// <param name="fontName">The font name to look up.</param>
        /// <param name="fontFamily"></param>
        /// <param name="charset">The characterset to use for the font.</param>
        public bool ImportFont(string fontNr, string fontName, string fontFamily, int charset)
        {
            RtfFont rtfFont = new RtfFont(fontName);

            if (charset >= 0)
            {
                rtfFont.SetCharset(charset);
            }
            if (!string.IsNullOrEmpty(fontFamily))
            {
                rtfFont.SetFamily(fontFamily);
            }
            rtfFont.SetRtfDocument(_rtfDoc);
            _importFontMapping[fontNr] = _rtfDoc.GetDocumentHeader().GetFontNumber(rtfFont).ToString();
            return(true);
        }
Пример #9
0
        /// <summary>
        /// Constructs a RtfChunk based on the content of a Chunk
        /// </summary>
        /// <param name="doc">The RtfDocument that this Chunk belongs to</param>
        /// <param name="chunk">The Chunk that this RtfChunk is based on</param>
        public RtfChunk(RtfDocument doc, Chunk chunk) : base(doc)
        {
            if (chunk == null)
            {
                return;
            }

            if (chunk.Attributes != null && chunk.Attributes[Chunk.SUBSUPSCRIPT] != null)
            {
                _superSubScript = (float)chunk.Attributes[Chunk.SUBSUPSCRIPT];
            }
            if (chunk.Attributes != null && chunk.Attributes[Chunk.BACKGROUND] != null)
            {
                _background = new RtfColor(Document, (BaseColor)((object[])chunk.Attributes[Chunk.BACKGROUND])[0]);
            }
            _font    = new RtfFont(doc, chunk.Font);
            _content = chunk.Content;
        }
 public RtfListLevel(RtfListLevel ll) : base(ll.Document)
 {
     _templateId      = Document.GetRandomInt();
     _alignment       = ll._alignment;
     _bulletCharacter = ll._bulletCharacter;
     _firstIndent     = ll._firstIndent;
     _fontBullet      = ll._fontBullet;
     _fontNumber      = ll._fontNumber;
     InHeader         = ll.InHeader;
     InTable          = ll.InTable;
     _leftIndent      = ll._leftIndent;
     listLevel        = ll.listLevel;
     _listNoRestart   = ll._listNoRestart;
     _listStartAt     = ll._listStartAt;
     _listType        = ll._listType;
     _parent          = ll._parent;
     _rightIndent     = ll._rightIndent;
     _symbolIndent    = ll._symbolIndent;
 }
Пример #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;
 }
Пример #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);
 }
 /// <summary>
 /// </summary>
 /// <param name="fontNumber">the fontNumber to set</param>
 public void SetFontNumber(RtfFont fontNumber)
 {
     _fontNumber = fontNumber;
 }
Пример #16
0
 /// <summary>
 /// Inserta un nueva fuente en la tabla de fuentes.
 /// </summary>
 /// <param name="index">Indice de la fuente a insertar.</param>
 /// <param name="RtfFont">Nueva fuente a insertar.</param>
 public void AddFont(int index, RtfFont font)
 {
     fonts.Add(index, font);
 }
 /// <summary>
 /// set the bullet font
 /// </summary>
 /// <param name="f"></param>
 public void SetBulletFont(Font f)
 {
     _fontBullet = new RtfFont(Document, f);
 }
 /// <summary>
 /// </summary>
 /// <param name="fontBullet">the fontBullet to set</param>
 public void SetFontBullet(RtfFont fontBullet)
 {
     _fontBullet = fontBullet;
 }
Пример #19
0
        public RtfBuilder SetFont(RtfFont font)
        {
            fontIndex = IndexOfFont(font);

            return(this);
        }
Пример #20
0
 /// <summary>
 /// Gets the number of the specified RtfFont
 /// </summary>
 /// <param name="font">The RtfFont for which to get the number</param>
 /// <returns>The number of the font</returns>
 public int GetFontNumber(RtfFont font)
 {
     return(_fontList.GetFontNumber(font));
 }
Пример #21
0
 /// <summary>
 /// Inserta un nueva fuente en la tabla de fuentes.
 /// </summary>
 /// <param name="index">Indice de la fuente a insertar.</param>
 /// <param name="RtfFont">Nueva fuente a insertar.</param>
 public void AddFont(int index, RtfFont font)
 {
     fonts.Add(index, font);
 }
Пример #22
0
 private int IndexOfFont(RtfFont font)
 {
     return(IndexOfRawFont(GetKnownFontString(font)));
 }
Пример #23
0
 /// <summary>
 /// Process font name
 /// </summary>
 /// <param name="item"></param>
 /// <param name="index"></param>
 /// <param name="rtfFont"></param>
 private void _ProcessRtfBlockFontName(Parsing.ParsedItem item, ref int index, RtfFont rtfFont)
 {
     index++;
     while (index < item.ItemCount)
     {
         Parsing.ParsedItem subItem = item.Items[index];
         index++;
         if (subItem.ItemType == Data.Parsing.ItemType.Text)
         {
             rtfFont.Name = subItem.Text.TrimEnd(';', ' ');
             break;
         }
     }
 }