Welcome to MSDN Blogs Sign in | Join | Help

Visio: Automation to simplify text formatting

Summary for the impatient: VisioAutoExt (http://www.codeplex.com/visioautoext) now lets you more easily create richly formatted text

It's relatively easy to control the formatting for all the text for a shape. Previously I simplified this by adding these extension methods to the Visio.Shape class:

Shape.SetTextColor(... )

Shape.SetTextFont(... )

Shape.SetTextHorizontalAlignment( ... )

etc.

With Visio 2007's object model, for more richly formatted text, working with specific regions of text is a very cumbersome. Version 2.3 of VisioAutoExt tries to address this by adding this extension method ..

 

Shape.SetTextMarkup( ... )

In short, feed it some XML with formatting instructions and you'll get a nicely formatted block of text. It's not at the stage where you can dump in HTML have it just work, but it's a step in that direction. And certainly much easier than learning about and using Characters.set_CharProps( ... )

 

How simple?

Below is some code from the DemoTextMarkup project in the solution:

 

Sample 1

            string text1 = @"
<text font=""Calibri"" size=""15"" color=""#ff0000"">
    Calibri 15pt [red]
    <text font=""Segoe UI"" size=""20"" color=""#0000ff"">
        Segoe UI 20 pt [blue]
        <text italic=""1"" halign=""left"" color=""#505050"">
        This text is in italic (left) [gray]
            <text bold=""1"" italic=""1"" halign=""right"">
                This should be bold italic (right)
            </text>
            <text bold=""1"" halign=""middle"">
                This should be bold in the middle
            </text>
        </text>
    </text>
    Calibri 15pt
</text>";

            Visio.Application visio = VisioUtil.LaunchVisioApplication();
            Visio.Document doc = visio.CreateDocument(new Isotope.Drawing.Size(30, 10));
            Visio.Page page = doc.Pages[1];
            Visio.Shape shape;

            shape = page.DrawRectangle(0, 0, 10, 8);
            shape.SetTextMarkup(text1);

 

This generates this output:

 

image

 

Sample 2

 

            string text2 = @"
    <text size=""20"" font=""Segoe UI""> The lines should be bulleted

<text bullets=""1"" halign=""left""> This a demonstration of <text bold=""1"">bold</text> text
A demonstration of <text italic=""1"">italic</text> text
Formatting can be combined to form <text bold=""1"" italic=""1"">bold italic</text>
This world is <text underline=""1"" >underlined</text>
</text>

The bullets have ended.
</text> ";

            shape = page.DrawRectangle(10, 0, 20, 8);
            shape.SetTextMarkup(text2);

 

 

image

 

Sample 3

 

            string text3 = @"
    <text size=""20"" font=""Segoe UI"" halign=""left""> The lines below should be indented

<text indent=""25"">
indent 25
</text>
<text indent=""50"">
indent 50
</text>
<text indent=""75"">
indent 75
</text>
<text indent=""100"">
indent 100
</text>

w
The indenting has ended.
</text> ";

            shape = page.DrawRectangle(20, 0, 30, 8);
            shape.SetTextMarkup(text3);

 

 

image

 

Use the Source

VisioAutoExt v 2.3 on CodePlex: http://www.codeplex.com/visioautoext

Published Thursday, December 27, 2007 6:01 PM by saveenr

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# MSDN Blog Postings &raquo; Visio: Automation to simplify text formatting

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker