[Solved] Modify character properties within Writer selection
Posted: Thu Apr 04, 2013 9:41 pm
In a Writer Basic macro, I am trying to decrease/increase the font size of every character within the selection. This subroutine works well, but operates over the whole document, not just the selection. Can I limit the range to the selected text?
Code: Select all
Sub FontDown
rem Increase the font of each character in selection by 1.
Dim CharHeight As Long, oSel as Object, oTC as Object
Dim oParEnum as Object, oPar as Object, oSecEnum as Object, oSec as Object
Dim oVC as Object, oText As Object
oText = ThisComponent.Text
oSel = ThisComponent.CurrentSelection.getByIndex(0) 'get the current selection
oTC = oText.createTextCursorByRange(oSel) ' and span it with a cursor
rem Scan the cursor range for chunks of given text size.
rem (Doesn't work - affects the whole document)
oParEnum = oTC.Text.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService("com.sun.star.text.Paragraph") Then
oSecEnum = oPar.createEnumeration()
Do While oSecEnum.hasMoreElements()
oSec = oSecEnum.nextElement()
If oSec.TextPortionType = "Text" Then
CharHeight = oSec.CharHeight
oSec.CharHeight = CharHeight - 1
End If
Loop
End If
Loop
End Sub