コード例 #1
0
            public RTFParaWrap(RTFBuilder builder)
            {
                _builder = builder;
                int len = _builder._sb.Length;

                if (_builder._sf.Alignment == StringAlignment.Center)
                {
                    _builder._sb.Append("\\qc");
                }
                else if (_builder._sf.Alignment == StringAlignment.Far)
                {
                    _builder._sb.Append("\\qr");
                }
                if (_builder._firstLineIndent > 0)
                {
                    _builder._sb.Append("\\fi" + _builder._firstLineIndent);
                }
                if (_builder._lineIndent > 0)
                {
                    _builder._sb.Append("\\li" + _builder._lineIndent);
                }


                if (_builder._sb.Length > len)
                {
                    _builder._sb.Append(" ");
                }
            }
コード例 #2
0
            public RTFFormatWrap(RTFBuilder builder)
            {
                _builder = builder;
                if (_builder._unwrapped)
                {
                    return;
                }

                StringBuilder sb = _builder._sb;

                int len = _builder._sb.Length;

                if (_builder._sf.Alignment == StringAlignment.Center)
                {
                    sb.Append("\\qc");
                }
                else if (_builder._sf.Alignment == StringAlignment.Far)
                {
                    sb.Append("\\qr");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Bold) == System.Drawing.FontStyle.Bold)
                {
                    sb.Append("\\b");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Italic) == System.Drawing.FontStyle.Italic)
                {
                    sb.Append("\\i");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Underline) == System.Drawing.FontStyle.Underline)
                {
                    sb.Append("\\ul");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Strikeout) == System.Drawing.FontStyle.Strikeout)
                {
                    sb.Append("\\strike");
                }

                if (_builder._fontSize != _builder.DefaultFontSize)
                {
                    sb.AppendFormat("\\fs{0}", _builder._fontSize);
                }
                if (_builder._font != 0)
                {
                    sb.AppendFormat("\\f{0}", _builder._font);
                }
                if (_builder._forecolor != _builder.Defaultforecolor)
                {
                    sb.AppendFormat("\\cf{0}", _builder.IndexOf(_builder._forecolor));
                }
                if (_builder._backcolor != _builder.DefaultBackColor)
                {
                    sb.AppendFormat("\\highlight{0}", _builder.IndexOf(_builder._backcolor));
                }


                if (sb.Length > len)
                {
                    sb.Append(" ");
                }
            }
コード例 #3
0
            public RTFParaWrap(RTFBuilder builder)
            {
                this._builder = builder;
                int len = this._builder._sb.Length;
                if (this._builder._sf.Alignment == StringAlignment.Center)
                {
                    this._builder._sb.Append("\\qc");
                }
                else if (this._builder._sf.Alignment == StringAlignment.Far)
                {
                    this._builder._sb.Append("\\qr");
                }
                if (this._builder._firstLineIndent > 0)
                {
                    this._builder._sb.Append("\\fi" + this._builder._firstLineIndent);
                }
                if (this._builder._lineIndent > 0)
                {
                    this._builder._sb.Append("\\li" + this._builder._lineIndent);
                }


                if (this._builder._sb.Length > len)
                {
                    this._builder._sb.Append(" ");
                }
            }
コード例 #4
0
            public RTFFormatWrap(RTFBuilder builder)
            {
                _builder = builder;
                if (_builder._unwrapped)
                {
                    return;
                }

                StringBuilder sb = _builder._sb;

                int len = _builder._sb.Length;

                if (_builder._sf.Alignment == StringAlignment.Center)
                {
                    sb.Append("\\qc");
                }
                else if (_builder._sf.Alignment == StringAlignment.Far)
                {
                    sb.Append("\\qr");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Bold) == System.Drawing.FontStyle.Bold)
                {
                    sb.Append("\\b");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Italic) == System.Drawing.FontStyle.Italic)
                {
                    sb.Append("\\i");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Underline) == System.Drawing.FontStyle.Underline)
                {
                    sb.Append("\\ul");
                }
                if ((_builder._fontStyle & System.Drawing.FontStyle.Strikeout) == System.Drawing.FontStyle.Strikeout)
                {
                    sb.Append("\\strike");
                }

                if (_builder._fontSize != _builder.DefaultFontSize)
                {
                    sb.AppendFormat("\\fs{0}", _builder._fontSize);
                }
                if (_builder._font != 0)
                {
                    sb.AppendFormat("\\f{0}", _builder._font);
                }
                if (_builder._forecolor != _builder.Defaultforecolor)
                {
                    sb.AppendFormat("\\cf{0}", _builder.IndexOf(_builder._forecolor));
                }
                if (_builder._backcolor != _builder.DefaultBackColor)
                {
                    sb.AppendFormat("\\highlight{0}", _builder.IndexOf(_builder._backcolor));
                }


                if (sb.Length > len)
                {
                    sb.Append(" ");
                }
            }
コード例 #5
0
ファイル: RTFRenderer.cs プロジェクト: figment/tesvsnip
        public static void GetFormattedData(this Record rec, RTFBuilder rb)
        {
            try
            {
                rb.FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize).ForeColor(KnownColor.DarkGray).AppendLine("[Formatted information]");
                rb.Reset();

                RecordStructure recordStructure;
                if (!RecordStructure.Records.TryGetValue(rec.Name, out recordStructure))
                {
                    return;
                }

                rb.FontStyle(FontStyle.Bold).ForeColor(KnownColor.DarkBlue).FontSize(rb.DefaultFontSize + 4).AppendLine(recordStructure.description);
                foreach (var subrec in rec.SubRecords)
                {
                    if (subrec.Structure == null || subrec.Structure.elements == null || subrec.Structure.notininfo)
                    {
                        continue;
                    }

                    rb.AppendLine();
                    subrec.GetFormattedData(rb);
                }
            }
            catch
            {
                rb.ForeColor(KnownColor.Red).Append("Warning: An error occurred while processing the record. It may not conform to the structure defined in RecordStructure.xml");
            }
        }
コード例 #6
0
ファイル: RTFRenderer.cs プロジェクト: figment/tesvsnip
 public static void GetFormattedData(this BaseRecord rec, RTFBuilder rb)
 {
     if (rec is Record )
         ((Record)rec).GetFormattedData(rb);
     else if (rec is SubRecord)
         ((SubRecord)rec).GetFormattedData(rb);
     else
         rb.Append(rec.GetDesc());
 }
コード例 #7
0
            internal RTFCellDefinitionBuilder(RTFBuilder builder, StringBuilder definitionBuilder, RTFCellDefinition cellDefinition)
            {
                this._builder = builder;

                this._definitionBuilder = definitionBuilder;
                this._cellDefinition = cellDefinition;


                this.AppendDefinition();
            }
コード例 #8
0
            internal RTFCellDefinitionBuilder(RTFBuilder builder, StringBuilder definitionBuilder,
                                              RTFCellDefinition cellDefinition)
            {
                _builder = builder;

                _definitionBuilder = definitionBuilder;
                _cellDefinition = cellDefinition;

                AppendDefinition();
            }
コード例 #9
0
            internal RTFCellDefinitionBuilder(RTFBuilder builder, StringBuilder definitionBuilder, RTFCellDefinition cellDefinition)
            {
                this._builder = builder;

                this._definitionBuilder = definitionBuilder;
                this._cellDefinition    = cellDefinition;


                this.AppendDefinition();
            }
コード例 #10
0
            internal RTFCellDefinitionBuilder(RTFBuilder builder, StringBuilder definitionBuilder,
                                              RTFCellDefinition cellDefinition)
            {
                _builder = builder;

                _definitionBuilder = definitionBuilder;
                _cellDefinition    = cellDefinition;


                AppendDefinition();
            }
コード例 #11
0
 protected void Dispose(bool disposing)
 {
     if (disposing && this._builder != null)
     {
         this._builder._sb.AppendLine("\\cell ");
     }
     this._builder = null;
     if (disposing)
     {
         GC.SuppressFinalize(this);
     }
 }
コード例 #12
0
ファイル: RTFCell.cs プロジェクト: WildGenie/SmartFormat.NET
 protected void Dispose(bool disposing)
 {
     if (disposing && this._builder != null)
     {
         this._builder._sb.AppendLine("\\cell ");
     }
     this._builder = null;
     if (disposing)
     {
         GC.SuppressFinalize(this);
     }
 }
コード例 #13
0
ファイル: RichTextView.cs プロジェクト: rxantos/tesv-snip
        public void UpdateRecord(BaseRecord sc)
        {
            if (sc == null)
            {
                UpdateText("");
                return;
            }
            FontLangInfo defLang;
            if (!Encoding.TryGetFontInfo(Properties.Settings.Default.LocalizationName, out defLang))
                defLang = new FontLangInfo(1252, 1033, 0);

            var rb = new RTFBuilder(RTFFont.Arial, 16, defLang.lcid, defLang.charset);
            sc.GetFormattedHeader(rb);
            sc.GetFormattedData(rb);
            this.rtfInfo.Rtf = rb.ToString();            
        }
コード例 #14
0
        public static string MergeRTFFiles(IEnumerable<Chapter> chapters)
        {
            var rtfBuilder = new RTFBuilder();

            foreach (var chapter in chapters)
            {
                rtfBuilder.BackColor(KnownColor.White);
                rtfBuilder.Font(RTFFont.CenturyGothic);
                rtfBuilder.FontSize(14);
                rtfBuilder.Alignment(StringAlignment.Center);
                rtfBuilder.AppendLine("\"" + chapter.ChapterName + "\"");
                rtfBuilder.AppendRTF(chapter.RTF);
            }

            return rtfBuilder.ToString();
        }
コード例 #15
0
            protected void Dispose(bool disposing)
            {
                if (this._builder != null)
                {
                    this._builder._sb.AppendLine("\\row");
                    //_builder._sb.AppendLine();
                    this._builder._sb.AppendLine("{");
                    this._builder._sb.Append(this._definitionBuilder.ToString());

                    this._builder._sb.AppendLine("}");
                }
                this._builder = null;
                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }
コード例 #16
0
ファイル: Record.cs プロジェクト: rxantos/tesv-snip
        public override void GetFormattedHeader(RTFBuilder rb)
        {
            rb.FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize + 4).ForeColor(KnownColor.DarkGray).AppendLine("[Record]");

            rb.Append("Type: ").FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize + 2).AppendFormat("{0}", Name).AppendLine();
            rb.Append("FormID: ").FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize + 2).ForeColor(KnownColor.DarkRed).AppendFormat("{0:X8}", this.FormID).AppendLine();

            if (this.Flags1 != 0)
            {
                rb.AppendLineFormat("Flags 1: {0:X8} : ({1} : Level = {2})", this.Flags1, FlagDefs.GetRecFlags1Desc(this.Flags1), compressLevel.ToString());
            }
            else
                rb.AppendLineFormat("Flags 1: {0:X8}", this.Flags1);

            //rb.AppendLineFormat("OLD --> Flags 3: \t{0:X8}", this.Flags3);
            rb.AppendLineFormat("Version Control Info: {0:X8}", this.Flags2);

            //rb.AppendLineFormat("OLD --> Flags 3: \t{0:X8}", this.Flags3);
            rb.AppendLineFormat("Flags 2: {0:X4}", (this.Flags3 >> 16));
            rb.AppendLineFormat("Form Version: {0:X4} : {1}", ((this.Flags3 << 16) >> 16), ((this.Flags3 << 16) >> 16));

            rb.AppendLineFormat("Size: {0:N0}", this.Size);
            rb.AppendLineFormat("Subrecords: {0}", this.SubRecords.Count);
            rb.AppendPara();
        }
コード例 #17
0
 public RTFBuilderUnWrapped(RTFBuilder builder)
 {
     this.wrapped             = new RTFFormatWrap(builder);
     this._builder            = builder;
     this._builder._unwrapped = true;
 }
コード例 #18
0
ファイル: RTFOutput.cs プロジェクト: kukawski/SmartFormat
 public void Clear()
 {
     //output.Clear();
     output = new RTFBuilder();
 }
コード例 #19
0
 public RTFBuilderUnWrapped(RTFBuilder builder)
 {
     this.wrapped = new RTFFormatWrap(builder);
     this._builder = builder;
     this._builder._unwrapped = true;
 }
コード例 #20
0
 public RTFCell(RTFBuilder builder, RTFCellDefinition cellDefinition)
 {
     this._builder            = builder;
     this._cellDefinition     = cellDefinition;
     this._firstAccessContent = true;
 }
コード例 #21
0
ファイル: Form1.cs プロジェクト: randomgeekdom/StorySuite
        private void button1_Click(object sender, EventArgs e)
        {
            RTFBuilderbase sb = new RTFBuilder();

            BuilderCode(sb);

            this.richTextBox1.Rtf = sb.ToString();
        }
コード例 #22
0
ファイル: RTFRow.cs プロジェクト: randomgeekdom/StorySuite
            protected void Dispose(bool disposing)
            {
                if (_builder != null)
                {
                    _builder._sb.AppendLine("\\row");
                    //_builder._sb.AppendLine();
                    _builder._sb.AppendLine("{");
                    _builder._sb.Append(_definitionBuilder);

                    _builder._sb.AppendLine("}");
                }
                _builder = null;
                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }
コード例 #23
0
ファイル: RTFImage.cs プロジェクト: WildGenie/SmartFormat.NET
 public RTFImage(RTFBuilder builder)
 {
     this._builder = builder;
     this.sb = new StringBuilder();
 }
コード例 #24
0
            internal RTFRow(RTFBuilder builder, RTFRowDefinition rowDefinition, RTFCellDefinition[] cellDefinitions)
            {
                if (builder == null)
                {
                    throw new ArgumentNullException("builder");
                }
                if (cellDefinitions == null)
                {
                    throw new ArgumentNullException("cellDefinitions");
                }
                if (rowDefinition.RowWidth == 0)
                {
                    throw new ArgumentNullException("rowDefinition.RowWidth");
                }
                if (cellDefinitions.Length == 0)
                {
                    throw new ArgumentNullException("cellDefinitions.Length");
                }
                this._definitionBuilder = new StringBuilder();


                this._rowDefinition   = rowDefinition;
                this._cellDefinitions = cellDefinitions;
                this._builder         = builder;

                StringBuilder sb = this._definitionBuilder;

                sb.Append("\\trowd\\trgaph115\\trleft-115");
                sb.AppendLine("\\trautofit1"); //AutoFit: ON
                this.TableCellBorderSide();
                this.BorderDef();
                //Pad();


                // \trhdr    Table row header. This row should appear at the top of every page on which the current table appears.
                // \trkeep    Keep table row together. This row cannot be split by a page break. This property is assumed to be off unless the control word is present.
                //\trleftN    Position in twips of the leftmost edge of the table with respect to the left edge of its column.
                //\trqc    Centers a table row with respect to its containing column.
                //\trql    Left-justifies a table row with respect to its containing column.
                //\trqr    Right-justifies a table row with respect to its containing column.
                //\trrhN    Height of a table row in twips. When 0, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line.
                //\trpaddbN    Default bottom cell margin or padding for the row.
                //\trpaddlN    Default left cell margin or padding for the row.
                //\trpaddrN    Default right cell margin or padding for the row.
                //\trpaddtN    Default top cell margin or padding for the row.
                //\trpaddfbN    Units for \trpaddbN:
                //0    Null. Ignore \trpaddbN in favor of \trgaphN (Word 97 style padding).
                //3    Twips.
                //\trpaddflN    Units for \trpaddlN:
                //0    Null. Ignore \trpaddlN in favor of \trgaphN (Word 97 style padding).
                //3    Twips.
                //\trpaddfrN    Units for \trpaddrN:
                //0    Null. Ignore \trpaddrN in favor of \trgaphN (Word 97 style padding).
                //3    Twips.
                //\trpaddftN    Units for \trpaddtN:
                //0    Null. Ignore \trpaddtN in favor of \trgaphN (Word 97 style padding).
                //3    Twips.


                this._cells = new List <RTFCellDefinitionBuilder>();
                int x = 0;

                foreach (RTFCellDefinition item in this._cellDefinitions)
                {
                    item.SetX(x);
                    x += (int)(item.CellWidthRaw * TWIPSA4);
                    this._cells.Add(new RTFCellDefinitionBuilder(this._builder, this._definitionBuilder, item));
                }
                this._builder._sb.Append(this._definitionBuilder.ToString());
            }
コード例 #25
0
ファイル: Form1.cs プロジェクト: randomgeekdom/StorySuite
 /// <summary>
 /// Merges the contents of 2 RichTextBoxes
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void button4_Click(object sender, EventArgs e)
 {
     RTFBuilderbase sb = new RTFBuilder();
     BuilderCode(sb);
     this.richTextBox3.Rtf = sb.ToString();
     this.richTextBox4.Rtf = sb.ToString();
     sb.Clear();
     sb.AppendRTFDocument(this.richTextBox3.Rtf);
     sb.AppendRTFDocument(this.richTextBox4.Rtf);
     this.richTextBox2.Rtf = sb.ToString();
 }
コード例 #26
0
ファイル: Form1.cs プロジェクト: randomgeekdom/StorySuite
        /// <summary>
        /// Merges the output of one RtfBuilder into another
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void button3_Click(object sender, EventArgs e)
        {
            RTFBuilderbase sb = new RTFBuilder();

            BuilderCode(sb);
            RTFBuilderbase sb2 = new RTFBuilder();
            BuilderCode(sb2);
            sb.AppendRTFDocument(sb2.ToString());
            this.richTextBox2.Rtf = sb.ToString();
        }
コード例 #27
0
ファイル: BaseRecord.cs プロジェクト: rxantos/tesv-snip
 public virtual void GetFormattedData(RTFBuilder rb)
 {
     rb.Append(this.GetDesc());
 }
コード例 #28
0
 public RTFImage(RTFBuilder builder)
 {
     this._builder = builder;
     this.sb       = new StringBuilder();
 }
コード例 #29
0
ファイル: BaseRecord.cs プロジェクト: rxantos/tesv-snip
 public virtual void GetFormattedHeader(RTFBuilder rb)
 {
 }
コード例 #30
0
ファイル: RTFImage.cs プロジェクト: jfbauer1/tesvsnip
 public RTFImage(RTFBuilder builder)
 {
     _builder = builder;
     sb       = new StringBuilder();
 }
コード例 #31
0
ファイル: RTFRow.cs プロジェクト: randomgeekdom/StorySuite
            internal RTFRow(RTFBuilder builder, RTFRowDefinition rowDefinition, RTFCellDefinition[] cellDefinitions)
            {
                if (builder == null)
                {
                    throw new ArgumentNullException("builder");
                }
                if (cellDefinitions == null)
                {
                    throw new ArgumentNullException("cellDefinitions");
                }
                if (rowDefinition.RowWidth == 0)
                {
                    throw new ArgumentNullException("rowDefinition.RowWidth");
                }
                if (cellDefinitions.Length == 0)
                {
                    throw new ArgumentNullException("cellDefinitions.Length");
                }
                _definitionBuilder = new StringBuilder();

                _rowDefinition = rowDefinition;
                _cellDefinitions = cellDefinitions;
                _builder = builder;

                var sb = _definitionBuilder;

                sb.Append("\\trowd\\trgaph115\\trleft-115");
                sb.AppendLine("\\trautofit1"); //AutoFit: ON
                TableCellBorderSide();
                BorderDef();
                //Pad();

                // \trhdr	Table row header. This row should appear at the top of every page on which the current table appears.
                // \trkeep	Keep table row together. This row cannot be split by a page break. This property is assumed to be off unless the control word is present.
                //\trleftN	Position in twips of the leftmost edge of the table with respect to the left edge of its column.
                //\trqc	Centers a table row with respect to its containing column.
                //\trql	Left-justifies a table row with respect to its containing column.
                //\trqr	Right-justifies a table row with respect to its containing column.
                //\trrhN	Height of a table row in twips. When 0, the height is sufficient for all the text in the line; when positive, the height is guaranteed to be at least the specified height; when negative, the absolute value of the height is used, regardless of the height of the text in the line.
                //\trpaddbN	Default bottom cell margin or padding for the row.
                //\trpaddlN	Default left cell margin or padding for the row.
                //\trpaddrN	Default right cell margin or padding for the row.
                //\trpaddtN	Default top cell margin or padding for the row.
                //\trpaddfbN	Units for \trpaddbN:
                //0	Null. Ignore \trpaddbN in favor of \trgaphN (Word 97 style padding).
                //3	Twips.
                //\trpaddflN	Units for \trpaddlN:
                //0	Null. Ignore \trpaddlN in favor of \trgaphN (Word 97 style padding).
                //3	Twips.
                //\trpaddfrN	Units for \trpaddrN:
                //0	Null. Ignore \trpaddrN in favor of \trgaphN (Word 97 style padding).
                //3	Twips.
                //\trpaddftN	Units for \trpaddtN:
                //0	Null. Ignore \trpaddtN in favor of \trgaphN (Word 97 style padding).
                //3	Twips.

                _cells = new List<RTFCellDefinitionBuilder>();
                var x = 0;
                foreach (var item in _cellDefinitions)
                {
                    item.SetX(x);
                    x += (int) (item.CellWidthRaw*TWIPSA4);
                    _cells.Add(new RTFCellDefinitionBuilder(_builder, _definitionBuilder, item));
                }
                _builder._sb.Append(_definitionBuilder);
            }
コード例 #32
0
ファイル: RTFRenderer.cs プロジェクト: figment/tesvsnip
        public static void GetFormattedData(this SubRecord rec, RTFBuilder s)
        {
            SubrecordStructure ss = rec.Structure;
            if (ss == null || ss.elements == null)
            {
                s.Append("String:\t").AppendLine(rec.GetStrData()).AppendLine();
                s.Append("Hex: \t").AppendLine(rec.GetHexData());
                s.AppendPara();
                return;
            }

            bool addTerminatingParagraph = false;
            try
            {
                var p = rec.GetPlugin();

                dFormIDLookupI formIDLookup = p.LookupFormID;
                dLStringLookup strLookup = p.LookupFormStrings;
                dFormIDLookupR formIDLookupR = p.GetRecordByID;

                // Table of items
                var table = new List<List<RTFCellDefinition>>();

                // set up elements
                float maxWidth = 0;
                int maxFirstCellWidth = 0;

                var elems = rec.EnumerateElements(true).Where(x => x.Structure != null && !x.Structure.notininfo).ToList();
                if (elems.Count == 0)
                {
                    return;
                }

                foreach (var element in elems)
                {
                    Size sz = s.MeasureText(element.Structure.name);
                    int width = Math.Max(sz.Width / 11, 10);

                    // approximate convert pixels to twips as the rtflib has crap documentation
                    if (width > maxFirstCellWidth)
                    {
                        maxFirstCellWidth = width;
                    }
                }

                foreach (var element in elems)
                {
                    var row = new List<RTFCellDefinition>();
                    table.Add(row);
                    var sselem = element.Structure;
                    bool hasOptions = sselem.options != null && sselem.options.Length > 0;
                    bool hasFlags = sselem.flags != null && sselem.flags.Length > 1;

                    // setup borders for header
                    var value = element.Value;
                    var nameCell = new RTFCellDefinition(maxFirstCellWidth, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty);
                    row.Add(nameCell);
                    switch (sselem.type)
                    {
                        case ElementValueType.FormID:
                            row.Add(new RTFCellDefinition(12, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            row.Add(new RTFCellDefinition(30, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));

                            // Optional Add cell for
                            break;
                        case ElementValueType.LString:
                            row.Add(new RTFCellDefinition(12, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            row.Add(new RTFCellDefinition(30, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            break;

                        case ElementValueType.BString:
                        case ElementValueType.IString:
                        case ElementValueType.String:
                            row.Add(new RTFCellDefinition(42, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            break;
                        case ElementValueType.Int:
                        case ElementValueType.UInt:
                        case ElementValueType.Byte:
                        case ElementValueType.SByte:
                        case ElementValueType.Short:
                        case ElementValueType.UShort:
                        case ElementValueType.Float:
                            row.Add(new RTFCellDefinition(20, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            row.Add(new RTFCellDefinition(30, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            break;
                        case ElementValueType.Blob:
                            row.Add(new RTFCellDefinition(42, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            break;
                        case ElementValueType.Str4:
                            row.Add(new RTFCellDefinition(42, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            break;
                        default:
                            row.Add(new RTFCellDefinition(42, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty));
                            break;
                    }

                    maxWidth = Math.Max(maxWidth, row.Sum(x => x.CellWidthRaw));
                }

                var rowWidth = (int)(maxWidth * 100.0f);
                var pd = new Padding { All = 50 };

                var hdrd = new RTFRowDefinition(rowWidth, RTFAlignment.TopLeft, RTFBorderSide.Default, 15, SystemColors.WindowText, pd);
                var hdrcds = new[] { new RTFCellDefinition(rowWidth, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 15, Color.DarkGray, Padding.Empty) };

                addTerminatingParagraph = true;
                s.Reset();
                using (IRTFRow ie = s.CreateRow(hdrd, hdrcds))
                {
                    foreach (var item in ie)
                    {
                        var rb = item.Content;
                        item.Content.FontSize(s.DefaultFontSize + 1).FontStyle(FontStyle.Bold).ForeColor(KnownColor.DarkCyan).AppendFormat("{0} ({1})", ss.name, ss.desc);
                    }
                }

                for (int rowIdx = 0; rowIdx < elems.Count; ++rowIdx)
                {
                    var rd = new RTFRowDefinition(rowWidth, RTFAlignment.TopLeft, RTFBorderSide.Default, 15, SystemColors.WindowText, pd);
                    var cds = table[rowIdx];
                    var elem = elems[rowIdx];
                    var sselem = elem.Structure;
                    var value = elem.Value;

                    string recprefix = null;
                    Record record = null;
                    string strValue = null; // value to display
                    string strDesc = null; // first description
                    string strDesc2 = null; // second description
                    bool hasOptions = sselem.options != null && sselem.options.Length > 0;
                    bool hasFlags = sselem.flags != null && sselem.flags.Length > 1;

                    if (!string.IsNullOrWhiteSpace(elem.Structure.funcr))
                    {
                        if (elem.Type == ElementValueType.Float) value = PyInterpreter.ExecuteFunction<float>(elem, FunctionOperation.ForReading);
                        else if (elem.Type == ElementValueType.Int) value = PyInterpreter.ExecuteFunction<int>(elem, FunctionOperation.ForReading);
                        else if (elem.Type == ElementValueType.Short) value = PyInterpreter.ExecuteFunction<short>(elem, FunctionOperation.ForReading);
                        else if (elem.Type == ElementValueType.UShort) value = PyInterpreter.ExecuteFunction<ushort>(elem, FunctionOperation.ForReading);
                        else if (elem.Type == ElementValueType.UInt) value = PyInterpreter.ExecuteFunction<uint>(elem, FunctionOperation.ForReading);
                    }

                    // Pre row write caching to avoid expensive duplicate calls between cells
                    switch (sselem.type)
                    {
                        case ElementValueType.FormID:
                            {
                                var id = (uint)value;
                                strValue = id.ToString("X8");
                                if (id != 0)
                                {
                                    record = formIDLookupR != null ? formIDLookupR(id) : null;
                                }

                                if (record != null)
                                {
                                    var pref = record.GetPlugin();
                                    recprefix = pref != null ? string.Format("{0}@{1}", pref.Name, record.Name) : record.Name;
                                    strDesc = record.DescriptiveName;
                                    var full = record.SubRecords.FirstOrDefault(x => x.Name == "FULL");
                                    if (full != null)
                                    {
                                        // split the cell 2 in 2 if full name found
                                        var data = new ArraySegment<byte>(full.GetReadonlyData());
                                        bool isString = TypeConverter.IsLikelyString(data);
                                        string lvalue = isString ? full.GetStrData() : strLookup != null ? strLookup(TypeConverter.h2i(data)) : null;
                                        if (!string.IsNullOrEmpty(lvalue))
                                        {
                                            var first = cds[cds.Count - 1];
                                            Size sz = s.MeasureText(lvalue);
                                            int width = Math.Min(40, Math.Max(sz.Width / 12, 10));

                                            // approximate convert pixels to twips as the rtflib has crap documentation
                                            var second = new RTFCellDefinition(width, RTFAlignment.MiddleLeft, RTFBorderSide.Default, 0, Color.DarkGray, Padding.Empty);
                                            cds.Add(second);
                                            strDesc2 = lvalue;
                                        }
                                    }
                                }
                            }

                            break;
                        case ElementValueType.LString:
                            {
                                if (elem.Type == ElementValueType.String)
                                {
                                    strValue = string.Empty;
                                    strDesc = value.ToString();
                                }
                                else if (TypeConverter.IsLikelyString(elem.Data))
                                {
                                    strValue = string.Empty;
                                    strDesc = TypeConverter.GetString(elem.Data);
                                }
                                else
                                {
                                    uint id = TypeConverter.h2i(elem.Data);
                                    strValue = id.ToString("X8");
                                    strDesc = strLookup != null ? strLookup(id) : null;
                                }
                            }

                            break;
                        case ElementValueType.Blob:
                            strValue = TypeConverter.GetHexData(elem.Data);
                            break;
                        case ElementValueType.SByte:
                        case ElementValueType.Int:
                        case ElementValueType.Short:
                            {
                                if (sselem.hexview || hasFlags)
                                {
                                    if (sselem.hexviewwithdec)
                                        strValue = string.Format(string.Format("{{0:X{0}}}", elem.Data.Count * 2), value) + string.Format(" : {0}", value);
                                    else
                                        strValue = string.Format(string.Format("{{0:X{0}}}", elem.Data.Count * 2), value);
                                }
                                else
                                {
                                    strValue = value == null ? string.Empty : value.ToString();
                                }

                                if (hasOptions)
                                {
                                    int intVal = Convert.ToInt32(value);
                                    for (int k = 0; k < sselem.options.Length; k += 2)
                                    {
                                        int intValOption;
                                        if (int.TryParse(sselem.options[k + 1], out intValOption) && intVal == intValOption)
                                        {
                                            strDesc = sselem.options[k];
                                        }
                                    }
                                }
                                else if (hasFlags)
                                {
                                    int intVal = Convert.ToInt32(value);
                                    var tmp2 = new StringBuilder();
                                    for (int k = 0; k < sselem.flags.Length; k++)
                                    {
                                        if ((intVal & (1 << k)) != 0)
                                        {
                                            if (tmp2.Length > 0)
                                            {
                                                tmp2.Append(", ");
                                            }

                                            tmp2.Append(sselem.flags[k]);
                                        }
                                    }

                                    strDesc = tmp2.ToString();
                                }
                            }

                            break;

                        case ElementValueType.UInt:
                        case ElementValueType.Byte:
                        case ElementValueType.UShort:
                            {
                                if (sselem.hexview || hasFlags)
                                {
                                    if (sselem.hexviewwithdec)
                                        strValue = string.Format(string.Format("{{0:X{0}}}", elem.Data.Count * 2), value) + string.Format(" : {0}", value);
                                    else
                                        strValue = string.Format(string.Format("{{0:X{0}}}", elem.Data.Count * 2), value);
                                }
                                else
                                {
                                    strValue = value == null ? string.Empty : value.ToString();
                                }

                                if (hasOptions)
                                {
                                    uint intVal = Convert.ToUInt32(value);
                                    for (int k = 0; k < sselem.options.Length; k += 2)
                                    {
                                        if (intVal == uint.Parse(sselem.options[k + 1]))
                                        {
                                            strDesc = sselem.options[k];
                                        }
                                    }
                                }
                                else if (hasFlags)
                                {
                                    uint intVal = Convert.ToUInt32(value);
                                    var tmp2 = new StringBuilder();
                                    for (int k = 0; k < sselem.flags.Length; k++)
                                    {
                                        if ((intVal & (1 << k)) != 0)
                                        {
                                            if (tmp2.Length > 0)
                                            {
                                                tmp2.Append(", ");
                                            }

                                            tmp2.Append(sselem.flags[k]);
                                        }
                                    }

                                    strDesc = tmp2.ToString();
                                }
                            }

                            break;
                        case ElementValueType.Str4:
                            strValue = TypeConverter.GetString(elem.Data);
                            break;
                        case ElementValueType.BString:
                            strValue = TypeConverter.GetBString(elem.Data);
                            break;
                        case ElementValueType.IString:
                            strValue = TypeConverter.GetIString(elem.Data);
                            break;
                        default:
                            strValue = value == null ? string.Empty : value.ToString();
                            break;
                    }

                    // Now create row and fill in cells
                    using (IRTFRow ie = s.CreateRow(rd, cds))
                    {
                        int colIdx = 0;
                        IEnumerator<IBuilderContent> ie2 = ie.GetEnumerator();
                        for (bool ok = ie2.MoveNext(); ok; ok = ie2.MoveNext(), ++colIdx)
                        {
                            using (var item = ie2.Current)
                            {
                                var rb = item.Content;
                                if (colIdx == 0)
                                {
                                    // name
                                    rb.FontStyle(FontStyle.Bold).Append(sselem.name);
                                }
                                else if (colIdx == 1)
                                {
                                    // value
                                    switch (sselem.type)
                                    {
                                        case ElementValueType.FormID:
                                            if (((uint)value) == 0)
                                            {
                                                rb.Append(strValue);
                                            }
                                            else if (record != null)
                                            {
                                                RTFRenderer.AppendLink(rb, strValue, record.GetLink());
                                            }
                                            else if (!string.IsNullOrEmpty(sselem.FormIDType))
                                            {
                                                RTFRenderer.AppendLink(rb, strValue, string.Format("{0}:{1}", sselem.FormIDType, strValue));
                                            }
                                            else
                                            {
                                                RTFRenderer.AppendLink(rb, strValue, string.Format("XXXX:{0}", strValue));
                                            }

                                            break;
                                        default:
                                            rb.Append(strValue);
                                            break;
                                    }
                                }
                                else if (colIdx == 2)
                                {
                                    // desc
                                    if (!string.IsNullOrEmpty(strDesc))
                                    {
                                        rb.Append(strDesc);
                                    }
                                }
                                else if (colIdx == 3)
                                {
                                    // desc2
                                    if (!string.IsNullOrEmpty(strDesc2))
                                    {
                                        rb.Append(strDesc2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                s.AppendLine("Warning: Subrecord doesn't seem to match the expected structure");
            }
            finally
            {
                if (addTerminatingParagraph)
                {
                    s.Reset();
                    s.AppendPara();
                }
            }
        }
コード例 #33
0
 public RTFBuilderUnWrapped(RTFBuilder builder)
 {
     wrapped = new RTFFormatWrap(builder);
     _builder = builder;
     _builder._unwrapped = true;
 }
コード例 #34
0
ファイル: RTFRow.cs プロジェクト: WildGenie/SmartFormat.NET
            protected void Dispose(bool disposing)
            {
                if (this._builder != null)
                {
                    this._builder._sb.AppendLine("\\row");
                    //_builder._sb.AppendLine();
                    this._builder._sb.AppendLine("{");
                    this._builder._sb.Append(this._definitionBuilder.ToString());

                    this._builder._sb.AppendLine("}");
                }
                this._builder = null;
                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }
コード例 #35
0
ファイル: RTFRenderer.cs プロジェクト: figment/tesvsnip
 public static void GetFormattedHeader(this SubRecord rec, RTFBuilder s)
 {
     s.FontStyle(FontStyle.Bold).FontSize(s.DefaultFontSize + 4).ForeColor(KnownColor.DarkGray).AppendLine("[Subrecord data]");
 }
コード例 #36
0
ファイル: RTFImage.cs プロジェクト: randomgeekdom/StorySuite
 public RTFImage(RTFBuilder builder)
 {
     _builder = builder;
     sb = new StringBuilder();
 }
コード例 #37
0
ファイル: RTFCell.cs プロジェクト: WildGenie/SmartFormat.NET
 public RTFCell(RTFBuilder builder, RTFCellDefinition cellDefinition)
 {
     this._builder = builder;
     this._cellDefinition = cellDefinition;
     this._firstAccessContent = true;
 }
コード例 #38
0
ファイル: Record.cs プロジェクト: rxantos/tesv-snip
        public override void GetFormattedHeader(RTFBuilder rb)
        {
            rb.FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize + 4).ForeColor(KnownColor.DarkGray).AppendLine(
                "[Record]");


            rb.Append("Type: \t").FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize + 2).AppendFormat("{0}", Name).
                AppendLine();
            rb.Append("FormID: \t").FontStyle(FontStyle.Bold).FontSize(rb.DefaultFontSize + 2).ForeColor(
                KnownColor.DarkRed).AppendFormat("{0:X8}", FormID).AppendLine();
            rb.AppendLineFormat("Flags 1: \t{0:X8}", Flags1);
            if (Flags1 != 0) rb.AppendLineFormat(" ({0})", FlagDefs.GetRecFlags1Desc(Flags1));
            rb.AppendLineFormat("Flags 2: \t{0:X8}", Flags2);
            rb.AppendLineFormat("Flags 3: \t{0:X8}", Flags3);
            rb.AppendLineFormat("Size: \t{0:N0}", Size);
            rb.AppendLineFormat("Subrecords:\t{0}", SubRecords.Count);
            rb.AppendPara();
        }
コード例 #39
0
 public RTFBuilderUnWrapped(RTFBuilder builder)
 {
     wrapped             = new RTFFormatWrap(builder);
     _builder            = builder;
     _builder._unwrapped = true;
 }
コード例 #40
0
ファイル: RTFRenderer.cs プロジェクト: figment/tesvsnip
 public static void GetFormattedHeader(this BaseRecord rec, RTFBuilder rb)
 {
     if (rec is Record)
         ((Record)rec).GetFormattedHeader(rb);
     else if (rec is SubRecord)
         ((SubRecord)rec).GetFormattedHeader(rb);
 }