ianmcr wrote:
Hi,
I am working on an export filter for producing accessible HTML. I first
iterate through the document and insert bookmarks at the start of each page
to indicate an automatic page break. I then iterate through the document
creating a new HTML page at each page break.
I need to compare the names of the names of the bookmarks as a iterate
trhough the text.
In the following example, I need to differentiate between "PageBreakMarker"
and "_1118825921".
- <text:p text:style-name="P4">
<text:bookmark text:name="PageBreakMarker" />
<text:bookmark-start text:name="_1118825921" />
<text:bookmark-end text:name="_1118825921" />
- <draw:frame ... />
</draw:frame>
</text:p>
I can detect a bookmark by the following:
Reference<XPropertySet> xPropertySet(currentXTextRange, UNO_QUERY);
Any aPortionType =
xPropertySet->getPropertyValue(rtl::OUString::createFromAscii("TextPortionType"));
rtl::OUString oPortionType;
if (aPortionType >>= oPortionType)
{
return (portionType == "Bookmark");
}
How do I find the name of the programatic name of the bookmark (ie. the
strings "PageBreakMarker" or "_1118825921" )?
Note that I do not bother iterating over text in tables and such, but if
you had one, it would find the name...
Sub IteratePortions()
Dim oText
Dim oEnum
Dim oPara
Dim oParaEnum
Dim oPortion
Dim oPortionCursor
Dim sPortionString$
oText = ThisComponent.getText()
oEnum = oText.createEnumeration ()
Do While oEnum.hasMoreElements
oPara = oEnum.nextElement
If oPara.supportsService("com.sun.star.text.Paragraph") Then
oParaEnum = oPara.createEnumeration ()
Do While oParaEnum.hasMoreElements ()
oPortion = oParaEnum.nextElement
Select Case oPortion.TextPortionType
Case "Text"
'oPortionCursor = oText.createTextCursorByRange (oPortion, 0)
oPortionCursor = oText.createTextCursorByRange (oPortion)
sPortionString = oPortionCursor.getString ()
Case "Bookmark"
Print FindBookmarkName(oPortion)
Case Else
'Print oPortion.TextPortionType()
End Select
Loop
End If
Loop
End Sub
Function FindBookmarkName(oPortion) As String
Dim oText
Dim oMarks
Dim oMark
Dim oCurs
Dim i As Integer
oText = oPortion.getText()
oMarks = ThisComponent.getBookmarks()
For i = 0 To oMarks.getCount() - 1
oMark = oMarks.getByIndex(i)
If EqualUNOObjects(oMark.getAnchor().getText(), oText) Then
'Inspect(oMark.getAnchor().getStart())
If (oText.compareRegionEnds (oPortion, oMark.getAnchor()) = 0 AND _
oText.compareRegionStarts (oPortion, oMark.getAnchor()) = 0) Then
FindBookmarkName = oMark.getName()
End If
End If
Next
End Function
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]