Paragraph Run Inconsistencies

A

Adam

I have run into an issue with Paragraph runs in text.

To replicate the issue, in visio, make a shape with some text, then a
bulleted list, then some text at the bottom.

You should get three rows in the Paragraphs section of this shape (one for
the text above the bullets, one for the bullets, one for the text below the
bullets).

Now select the first bullet, unbullet it, then rebullet it.

You will now have four rows in the Paragraphs section (one for the text
above the bullets, one for the first bullet, one for the remaining bullets,
and one for the text below the bullets).

Now do a run through the Characters collection using visParaPropRow. You
will get a count of three, not four.

Ouch! Why does this hurt? If you do a Characters.ParaPropsRow(0) on the text
underneath your bullets, it will return 3 instead of 4, so if you want to
know if this fourth line is bulleted, you are stuck. visBulletIndex won't
give you the right value.

This is probably an edge case, but in my application, where I am converting
visio shapes with text into html, it is frustrating not being able to figure
out with certainty whether or not a line of text is bulletted.

Any ideas on a workaround?
 
P

Paul Herber

I have run into an issue with Paragraph runs in text.

To replicate the issue, in visio, make a shape with some text, then a
bulleted list, then some text at the bottom.

You should get three rows in the Paragraphs section of this shape (one for
the text above the bullets, one for the bullets, one for the text below the
bullets).

Now select the first bullet, unbullet it, then rebullet it.

You will now have four rows in the Paragraphs section (one for the text
above the bullets, one for the first bullet, one for the remaining bullets,
and one for the text below the bullets).

Now do a run through the Characters collection using visParaPropRow. You
will get a count of three, not four.

Ouch! Why does this hurt? If you do a Characters.ParaPropsRow(0) on the text
underneath your bullets, it will return 3 instead of 4, so if you want to
know if this fourth line is bulleted, you are stuck. visBulletIndex won't
give you the right value.

This is probably an edge case, but in my application, where I am converting
visio shapes with text into html, it is frustrating not being able to figure
out with certainty whether or not a line of text is bulletted.

Any ideas on a workaround?

When you unbullet, then rebullet it looks like Visio doesn't know that
you want the bullet line to be part of the next bullet line, a very
reasonable assumption.
When you look at the paragraph rows you could look for adjacent
duplicates.
 
A

Adam

It kind of defeats the purpose of paragraph runs, though.

Visio's documentation says that the only reason to have a paragraph run is
to indicate a CHANGE in formatting.

To see some more weird behavior, add two lines above the bullets. Do the
trick to get your extra bullet line, then select one of the two lines above
and center it then uncenter it. The extra bullet row disappears. It seems
that visio recalculates the paragraph runs if you do this.
 
A

Adam

Well I wrote a workaround for this. I apologize in advance if there is
sloppiness in the code---I just wanted to get it done.

There are three functions below.

TranslateParaRow <- Call this from your function if you want the "real"
paraproprow from a mychars.ParaPropsRow(0).

HasParaPropsIssue <- Checks to see if there is a difference between what
ParaPropsRow will report and what the actual property rows are.

HasSameParaProps <- compares two paraprops rows and tells you if they are
the same.

Essentially the code creates a lookup table for translating the paraprops
rows to real property rows.

Public Function TranslateParaRow(ParaPropsNum As Integer, myshape As Shape)
As Integer

'Do a quick check and make sure we actually have the issue.
If Not HasParaPropsIssue(myshape) Then
TranslateParaRow = ParaPropsNum
Exit Function
End If

Dim rownum As Integer

Dim mysect As Visio.Section

Set mysect = myshape.Section(VisSectionIndices.visSectionParagraph)

Dim curRow As Visio.Row
Dim prevRow As Visio.Row

Dim RowTranslation()

ReDim RowTranslation(0)

Dim parapropsrow As Integer
parapropsrow = 0

Dim numActualRows As Integer
numActualRows = myshape.RowCount(VisSectionIndices.visSectionParagraph)

For rownum = 1 To numActualRows - 1
Set curRow = mysect(rownum)

Set prevRow = mysect(rownum - 1)
If Not HasSameParaProps(curRow, prevRow) Then
parapropsrow = parapropsrow + 1
ReDim Preserve RowTranslation(UBound(RowTranslation) + 1)
End If
RowTranslation(parapropsrow) = rownum

Next rownum

TranslateParaRow = RowTranslation(ParaPropsNum)

End Function

Private Function HasParaPropsIssue(myshape As Shape) As Boolean

Dim mychars As Visio.Characters
Dim c As Integer
Dim numchars As Integer
Dim runBegin As Integer
Dim runEnd As Integer
runBegin = 0
runEnd = 1
Dim myrunformatting As Integer

Set mychars = myshape.Characters

Dim runCount As Integer

Dim propCount As Integer

numchars = myshape.CharCount

myrunformatting = 0
runCount = 0

c = 0
'Get runcount
Do While c < numchars
mychars.Begin = c
mychars.End = c + 1

runBegin = mychars.runBegin(VisRunTypes.visParaPropRow)
runEnd = mychars.runEnd(VisRunTypes.visParaPropRow)

mychars.Begin = runBegin
mychars.End = runEnd

runCount = runCount + 1

myrunformatting =
myshape.CellsSRC(VisSectionIndices.visSectionParagraph, runCount - 1,
VisCellIndices.visBulletIndex).Formula

c = runEnd

Loop

HasParaPropsIssue = (runCount <>
myshape.RowCount(VisSectionIndices.visSectionParagraph))

End Function
Private Function HasSameParaProps(row1 As Visio.Row, row2 As Visio.Row) As
Boolean

HasSameParaProps = _
row1.Cell(VisCellIndices.visIndentFirst) =
row2.Cell(VisCellIndices.visIndentFirst) _
And row1.Cell(VisCellIndices.visIndentLeft) =
row2.Cell(VisCellIndices.visIndentLeft) _
And row1.Cell(VisCellIndices.visIndentRight) =
row2.Cell(VisCellIndices.visIndentRight) _
And row1.Cell(VisCellIndices.visSpaceLine) =
row2.Cell(VisCellIndices.visSpaceLine) _
And row1.Cell(VisCellIndices.visSpaceBefore) =
row2.Cell(VisCellIndices.visSpaceBefore) _
And row1.Cell(VisCellIndices.visHorzAlign) =
row2.Cell(VisCellIndices.visHorzAlign) _
And row1.Cell(VisCellIndices.visBulletIndex) =
row2.Cell(VisCellIndices.visBulletIndex) _
And row1.Cell(VisCellIndices.visBulletString) =
row2.Cell(VisCellIndices.visBulletString) _
And row1.Cell(VisCellIndices.visBulletFont) =
row2.Cell(VisCellIndices.visBulletFont) _
And row1.Cell(VisCellIndices.visLocalizeBulletFont) =
row2.Cell(VisCellIndices.visLocalizeBulletFont) _
And row1.Cell(VisCellIndices.visTextPosAfterBullet) =
row2.Cell(VisCellIndices.visTextPosAfterBullet) _
And row1.Cell(VisCellIndices.visBulletFontSize) =
row2.Cell(VisCellIndices.visBulletFontSize) _
And row1.Cell(VisCellIndices.visFlags) =
row2.Cell(VisCellIndices.visFlags)

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top