I am writing a libreoffice basic macro which is supposed to shrink and hide all text which is not bold and not highlighted. I am taking inspiration from Andrew Pitonyak’s OOME_4 document, listing 368. However, when I run the macro, it behaves inconsistently. When a paragraph has one, or two areas that are highlighted, it works perfectly. However, on three or more, it only hides the first part of the paragraph (see images below). Also, sometimes it will hide bolded text. I have no idea why it is acting in this way, is there another way to accomplish this?
Before macro:
After macro:
Before macro:
After macro:
Here is the code:
Sub InvisibiliyOn
REM original code : Alex Savitsky
REM modified by : Laurent Godard
REM modified by : Andrew Pitonyak
REM The purpose of this macro is to surround all BOLD elements with {{ }}
REM and change the Bold attribute to NORMAL by using a regular expression.
Dim oReplace
Dim SrchAttributes(1) as new com.sun.star.beans.PropertyValue
Dim ReplAttributes(1) as new com.sun.star.beans.PropertyValue
oReplace = ThisComponent.createReplaceDescriptor()
oReplace.SearchString = ".*" 'Regular expression. Match any text
oReplace.ReplaceString = "&" 'Note the & places the found text back
oReplace.SearchRegularExpression=True 'Use regular expressions
oReplace.searchStyles=True 'We want to search styles
oReplace.searchAll=True 'Do the entire document
REM This is the attribute to find
SrchAttributes(0).Name = "CharBackTransparent"
SrchAttributes(0).Value = true
SrchAttributes(1).Name = "CharWeight"
SrchAttributes(1).Value =com.sun.star.awt.FontWeight.NORMAL
REM This is the attribute to replace it with
ReplAttributes(0).Name = "CharColor"
ReplAttributes(0).Value =16777215
ReplAttributes(1).Name = "CharHeight"
ReplAttributes(1).Value = 4
REM Set the attributes in the replace descriptor
oReplace.SetSearchAttributes(SrchAttributes())
oReplace.SetReplaceAttributes(ReplAttributes())
REM Now do the work!
ThisComponent.replaceAll(oReplace)
End Sub