示例#1
0
        public void SetText(IVisio.Shape shape)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            // First just set all the text
            string full_doc_inner_text = this.GetInnerText();

            shape.Text = full_doc_inner_text;

            // Find all the regions needing formatting
            var markupinfo        = this.GetMarkupInfo();
            var regions_to_format = markupinfo.FormatRegions.Where(region => region.Length >= 1).ToList();


            var default_chars_bias = IVisio.VisCharsBias.visBiasLeft;


            var writer = new FormulaWriterSRC();

            foreach (var region in regions_to_format)
            {
                // Apply character formatting
                var charcells = region.Element.CharacterFormatting;
                if (charcells != null)
                {
                    var chars = shape.Characters;
                    chars.Begin = region.Start;
                    chars.End   = region.End;
                    chars.CharProps[ShapeSheet.SRCConstants.CharColor.Cell] = 0;
                    short rownum = chars.CharPropsRow[(short)default_chars_bias];

                    if (rownum < 0)
                    {
                        throw new AutomationException("Could not create Character row");
                    }

                    writer.Clear();
                    charcells.ApplyFormulas(writer, rownum);
                    writer.Commit(shape);
                }

                // Apply paragraph formatting
                var paracells = region.Element.ParagraphFormatting;
                if (paracells != null)
                {
                    var chars = shape.Characters;
                    chars.Begin = region.Start;
                    chars.End   = region.End;
                    chars.ParaProps[ShapeSheet.SRCConstants.Para_Bullet.Cell] = 0;
                    short rownum = chars.ParaPropsRow[(short)default_chars_bias];

                    if (rownum < 0)
                    {
                        throw new AutomationException("Could not create Paragraph row");
                    }

                    writer.Clear();
                    paracells.ApplyFormulas(writer, rownum);
                    writer.Commit(shape);
                }
            }

            // Insert the fields
            // note: Fields are added in reverse because it is simpler to keep track of the insertion positions
            foreach (var field_region in markupinfo.FieldRegions.Where(region => region.Length >= 1).Reverse())
            {
                var chars = shape.Characters;
                chars.Begin = field_region.Start;
                chars.End   = field_region.End;
                chars.AddField((short)field_region.Field.Category, (short)field_region.Field.Code,
                               (short)field_region.Field.Format);
                var fr = field_region;
            }
        }