cleanandvalidate/Redaction/Clean.xba

2185 lines
No EOL
80 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Clean" script:language="StarBasic">Sub mark95
End Sub
Dim DocumentLoaded as Boolean
Sub cleanButton
Dim config As Object
config = initRedactionConfiguration()
If ThisComponent.isReadonly Then
MsgBox(getTranslation(&quot;documentIsReadOnly&quot;))
Exit Sub
EndIf
If config.getPropertyValue(&quot;predefined_template&quot;) = &quot;false&quot; Then
configureStyleFileDialog()
EndIf
If config.getPropertyValue(&quot;complexity&quot;) = &quot;user&quot; then
quietStartDialog()
Else
makerUpMenu()
EndIf
End Sub
Dim advancedCleaningDialog As Object
Private Sub makerUpMenu
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
advancedCleaningDialog = CreateUnoDialog(DialogLibraries.Redaction.CleaningDialog)
advancedCleaningDialog.getControl(&quot;fontsInStyles&quot;).Label = getTranslation(&quot;advancedMenuReplaceFontsInStyles&quot;)
advancedCleaningDialog.getControl(&quot;symbolsConversion&quot;).Label = getTranslation(&quot;advancedMenuSymbolsConversion&quot;)
advancedCleaningDialog.getControl(&quot;cleanFormatting&quot;).Label = getTranslation(&quot;advancedMenuCleanFormatting&quot;)
advancedCleaningDialog.getControl(&quot;replaceWhiteBackground&quot;).Label = getTranslation(&quot;advancedMenuReplaceWhiteBackground&quot;)
advancedCleaningDialog.getControl(&quot;removeUnusedStyles&quot;).Label = getTranslation(&quot;advancedMenuRemoveUnusedStyles&quot;)
advancedCleaningDialog.getControl(&quot;removeLinks&quot;).Label = getTranslation(&quot;advancedMenuRemoveLinks&quot;)
advancedCleaningDialog.getControl(&quot;removeAllFields&quot;).Label = getTranslation(&quot;advancedMenuRemoveAllFields&quot;)
advancedCleaningDialog.getControl(&quot;removeBookmarks&quot;).Label = getTranslation(&quot;advancedMenuRemoveBookmarks&quot;)
advancedCleaningDialog.getControl(&quot;configTables&quot;).Label = getTranslation(&quot;advancedMenuConfigTables&quot;)
advancedCleaningDialog.getControl(&quot;configAnchors&quot;).Label = getTranslation(&quot;advancedMenuConfigAnchors&quot;)
advancedCleaningDialog.getControl(&quot;fixMistakes&quot;).Label = getTranslation(&quot;advancedMenuFixMistakes&quot;)
advancedCleaningDialog.getControl(&quot;fixDOI&quot;).Label = getTranslation(&quot;advancedMenuFixDOI&quot;)
advancedCleaningDialog.getControl(&quot;replaceNumHyphen&quot;).Label = getTranslation(&quot;replaceNumHyphen&quot;)
advancedCleaningDialog.getControl(&quot;removeInitPageBreak&quot;).Label = getTranslation(&quot;advancedMenuRemoveInitPageBreak&quot;)
advancedCleaningDialog.getControl(&quot;removePageStyles&quot;).Label = getTranslation(&quot;advancedMenuRemovePageStyles&quot;)
advancedCleaningDialog.getControl(&quot;loadStandardStyles&quot;).Label = getTranslation(&quot;advancedMenuLoadStandardStyles&quot;)
advancedCleaningDialog.getControl(&quot;removeManualPageBreaks&quot;).Label = getTranslation(&quot;advancedMenuRemoveManualPageBreaks&quot;)
advancedCleaningDialog.getControl(&quot;removeBasic&quot;).Label = getTranslation(&quot;advancedMenuRemoveBasic&quot;)
advancedCleaningDialog.getControl(&quot;resetChapterNumberingRules&quot;).Label = getTranslation(&quot;advancedMenuResetChapterNumberingRules&quot;)
advancedCleaningDialog.getControl(&quot;convertFontsToCharStyles&quot;).Label = getTranslation(&quot;advancedMenuconvertFontsToCharStyles&quot;)
advancedCleaningDialog.getControl(&quot;fixBrokenCharBackTransparent&quot;).Label = getTranslation(&quot;fixBrokenCharBackTransparentMenuItem&quot;)
advancedCleaningDialog.getControl(&quot;removeNotTransparentBackgrounds&quot;).Label = getTranslation(&quot;removeNotTransparentBackgrounds&quot;)
advancedCleaningDialog.getControl(&quot;fixDiacriticKerning&quot;).Label = getTranslation(&quot;fixDiacriticKerning&quot;)
advancedCleaningDialog.getControl(&quot;Cancel&quot;).Label = getTranslation(&quot;buttonCancel&quot;)
advancedCleaningDialog.getControl(&quot;OK&quot;).Label = getTranslation(&quot;buttonOK&quot;)
advancedCleaningDialog.getControl(&quot;buttonLoad&quot;).Label = getTranslation(&quot;buttonLoad&quot;)
advancedCleaningDialog.Title = getTranslation(&quot;advancedMenuDialogTitle&quot;)
setAdvancedDialogDescription()
advancedCleaningDialog.setVisible(true)
Select Case advancedCleaningDialog.Execute()
Case 1
cleanAccordingTo(advancedCleaningDialog)
Case 0
End Select
advancedCleaningDialog.dispose()
Exit sub
End Sub
Private Sub cleanAccordingTo(dialog As Object)
Dim statusIndicator as Object
Dim openTrackChanges As Boolean
openTrackChanges = false
dialog.setVisible(false)
saveDocument
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusStarted&quot;),100)
doNotTrack
If dialog.getControl(&quot;loadStandardStyles&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;resaving&quot;),100)
saveAsDocAndBackToODT
EndIf
If dialog.getControl(&quot;fontsInStyles&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusReplaceFontsInStyles&quot;),100)
replaceStyleFonts
EndIf
If dialog.getControl(&quot;symbolsConversion&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusConvertSymbolsInTargetFonts&quot;),100)
unicodeSymbolsConversion
EndIf
If dialog.getControl(&quot;cleanFormatting&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusCleaningManualFormatting&quot;),100)
cleanFormatting
EndIf
If dialog.getControl(&quot;replaceWhiteBackground&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusReplaceWhiteBackground&quot;),100)
replaceWhiteBackgroundWithTransparent
EndIf
If dialog.getControl(&quot;removeUnusedStyles&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusRemovedUnusedStyles&quot;),100)
removeUnusedStyles
EndIf
If dialog.getControl(&quot;removeLinks&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusRemoveLinks&quot;),100)
removeHyperlinks
EndIf
If dialog.getControl(&quot;removeAllFields&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusRemoveAllFields&quot;),100)
removeAllFields
EndIf
If dialog.getControl(&quot;removeBookmarks&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusRemoveBookmarks&quot;),100)
disposeAllBookmarks
EndIf
If dialog.getControl(&quot;configTables&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusConfigureTables&quot;),100)
fixTableWidth
EndIf
If dialog.getControl(&quot;configAnchors&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusConfigureImagesAnchors&quot;),100)
fixDrawingAnchors
EndIf
If dialog.getControl(&quot;fixMistakes&quot;).state = 1 Then
saveAndreload()
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusFixFrequentMistakes&quot;),100)
fixFrequentMistakes
EndIf
If dialog.getControl(&quot;fixDOI&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusFixingDOI&quot;),100)
openTrackChanges = true
fixDOI
EndIf
If dialog.getControl(&quot;replaceNumHyphen&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;replaceNumHyphenStatus&quot;),100)
openTrackChanges = true
replaceNumHyphen
EndIf
If dialog.getControl(&quot;removeInitPageBreak&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusRemovePageBreakAtStart&quot;),100)
removeFirstElementPageBreak
EndIf
If dialog.getControl(&quot;removePageStyles&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusRemoveCustomPageStyles&quot;),100)
removeUserPageStyles
EndIf
If dialog.getControl(&quot;loadStandardStyles&quot;).state = 1 Then
statusIndicator.Start(getTranslation(&quot;statusLoadingStylesFromTemplate&quot;),100)
loadArticleStyles
EndIf
If dialog.getControl(&quot;removeManualPageBreaks&quot;).state = 1 Then
removeManualPageBreaks
EndIf
If dialog.getControl(&quot;removeBasic&quot;).state = 1 Then
removeLibs
EndIf
If dialog.getControl(&quot;resetChapterNumberingRules&quot;).state = 1 Then
resetChapterNumberingRules
EndIf
If dialog.getControl(&quot;convertFontsToCharStyles&quot;).state = 1 Then
convertFontsToCharStyles()
EndIf
If dialog.getControl(&quot;fixBrokenCharBackTransparent&quot;).state = 1 Then
fixBrokenCharBackTransparent()
EndIf
If dialog.getControl(&quot;removeNotTransparentBackgrounds&quot;).state = 1 Then
fixColoredBackgroundInDoc()
EndIf
If dialog.getControl(&quot;fixDiacriticKerning&quot;).state = 1 Then
fixDiacriticKerning()
EndIf
statusIndicator.end()
saveAndreload()
MsgBox getTranslation(&quot;cleaningFinished&quot;)
If openTrackChanges Then
showTrackedChanges
Endif
End Sub
Private Sub removeLibs
Dim docBasic as Object
docBasic = ThisComponent.BasicLibraries
Dim libs() As String
libs = docBasic.getElementNames()
Dim libName As String
Dim i As Integer
For i = LBound(libs) To UBound(libs)
libName = libs(i)
docBasic.removeLibrary(libName)
Next i
End Sub
Private Sub quietCleaning
Dim description As String
Dim statusIndicator As Object
DocumentLoaded = false
saveDocument
saveAsDocAndBackToODT
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusStarted&quot;),100)
doNotTrack
statusIndicator.Start(getTranslation(&quot;statusReplaceFontsInStyles&quot;),100)
replaceStyleFonts
statusIndicator.Start(getTranslation(&quot;statusConvertSymbolsInTargetFonts&quot;),100)
saveAndreload()
statusIndicator = ThisComponent.getCurrentController.statusIndicator
unicodeSymbolsConversion
statusIndicator.Start(getTranslation(&quot;statusFixingDiacriticCharactersKerning&quot;),100)
fixDiacriticKerning
statusIndicator.Start(getTranslation(&quot;statusCleaningManualFormatting&quot;),100)
cleanFormatting
statusIndicator.Start(getTranslation(&quot;statusReplaceWhiteBackground&quot;),100)
replaceWhiteBackgroundWithTransparent
statusIndicator.Start(getTranslation(&quot;statusRemovedUnusedStyles&quot;),100)
removeUnusedStyles
statusIndicator.Start(getTranslation(&quot;statusRemoveLinks&quot;),100)
removeHyperlinks
statusIndicator.Start(getTranslation(&quot;statusRemoveBookmarks&quot;),100)
disposeAllBookmarks
statusIndicator.Start(getTranslation(&quot;statusConfigureTables&quot;),100)
fixTableWidth
statusIndicator.Start(getTranslation(&quot;statusConfigureImagesAnchors&quot;),100)
fixDrawingAnchors
saveAndreload()
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusFixFrequentMistakes&quot;),100)
fixFrequentMistakes
statusIndicator.Start(getTranslation(&quot;statusRemovePageBreakAtStart&quot;),100)
removeFirstElementPageBreak
statusIndicator.Start(getTranslation(&quot;statusRemoveCustomPageStyles&quot;),100)
removeUserPageStyles
statusIndicator.Start(getTranslation(&quot;statusLoadingStylesFromTemplate&quot;),100)
loadArticleStyles
removeLibs
resetChapterNumberingRules
addTimeStampToProperties
saveCleanedVersion(&quot;Standard cleaning&quot;)
statusIndicator.end()
saveAndreload()
MsgBox getTranslation(&quot;cleaningFinished&quot;)
End Sub
&apos;Sub RegisterListener (ThisComponent)
&apos; oListener = CreateUnoListener( &quot;DocumentListener_&quot;,&quot;com.sun.star.document.XEventListener&quot; )
&apos; ThisComponent.com_sun_star_document_XEventBroadcaster_addEventListener( oListener )
&apos;End Sub
&apos;Sub DocumentListener_notifyEvent( o as object )
&apos; If o.EventName = &quot;OnLoad&quot; Then
&apos; DocumentLoaded = true
&apos; EndIf
&apos;end sub
&apos;Sub DocumentListener_disposing()
&apos;End Sub
Private Sub removeFirstElementPageBreak
Dim enum1 As Object
Dim enum1Element As Object
enum1 = ThisComponent.Text.createEnumeration
If enum1.hasMoreElements Then
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) OR enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
If enum1Element.BreakType &lt;&gt; com.sun.star.style.BreakType.NONE Then
enum1Element.PageDescName = &quot;&quot;
enum1Element.BreakType = com.sun.star.style.BreakType.NONE
EndIf
EndIf
EndIf
End Sub
Private Sub replaceStyleFonts
&apos; Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
replaceFontsInStyles(&quot;IPH Lib Serif&quot;,&quot;IPH Astra Serif&quot;)
replaceFontsInStyles(&quot;Liberation Serif&quot;,&quot;IPH Astra Serif&quot;)
replaceFontsInStyles(&quot;PTSerif&quot;,&quot;IPH Astra Serif&quot;)
replaceFontsInStyles(&quot;PT Serif&quot;,&quot;IPH Astra Serif&quot;)
replaceFontsInStyles(&quot;ArabicD&quot;,&quot;IPH Astra Serif&quot;)
replaceFontsInStyles(&quot;Palatino Linotype Greek&quot;,&quot;Tinos&quot;)
End Sub
Private Sub replaceFontsInStyles(oldFontStart As String,newFontName As String)
Dim propertySetInfo As Object
Dim oPositionOfMatch As Long
Dim oFamilies As Object
Dim sElements As Object
Dim oFamily As Object
Dim oStyle As Object
Dim fontName As String
oFamilies = Thiscomponent.StyleFamilies
sElements() = oFamilies.getElementNames()
For i = 0 to oFamilies.count -1
oFamily = oFamilies.getByName(sElements(i))
For j = 0 to oFamily.getCount -1
oStyle = oFamily.getByIndex(j)
propertySetInfo = oStyle.getPropertySetInfo()
If propertySetInfo.hasPropertyByName(&quot;CharFontName&quot;) Then
fontName = oStyle.getPropertyValue(&quot;CharFontName&quot;)
oPositionOfMatch = InStr(fontName, oldFontStart)
If oPositionOfMatch = 1 Then
oStyle.CharFontName = newFontName
If propertySetInfo.hasPropertyByName(&quot;CharFontNameComplex&quot;) Then
oStyle.CharFontNameComplex = newFontName
EndIf
If propertySetInfo.hasPropertyByName(&quot;CharFontNameAsian&quot;) Then
oStyle.CharFontNameAsian = newFontName
EndIf
EndIf
EndIf
Next
Next
End Sub
Private Sub unicodeSymbolsConversion
convertWLLatin2IPHAstra
convertSymbol
Dim sharedMarksRegExp As String
sharedMarksRegExp = &quot;([\u0020-\u002f\u003a\u003b\u00A0\u2010\u2013\u2014]+)?&quot;
Dim newFontName As String
newFontName = &quot;IPH Astra Serif&quot;
Dim RAtts(2) as new com.sun.star.beans.PropertyValue
RAtts(0).Name = &quot;CharFontName&quot;
RAtts(1).Name = &quot;CharFontNameComplex&quot;
RAtts(2).Name = &quot;CharFontNameAsian&quot;
&apos;Basic Astra
RAtts(0).Value = newFontName
RAtts(1).Value = newFontName
RAtts(2).Value = newFontName
&apos;Letterlike Symbols 2100—214F
&apos;Extended latin-1 0080—00FF
&apos;Cyrillic unicode block range \u0400-\u04FF
&apos;Basic Latin \u0020-\u007E
&apos;Combining diacritical marks 0301 0304 0303 0323 032e 0331 035f
combiningDiacritic_Astra = &quot;\u0301\u0303\u0304\u0308\u0323\u032e\u0331\u0341\u035f&quot;
Dim extendedLatinA_Astra As String
extendedLatinA_Astra = &quot;\u1e15\u1e17\u1e53\u0129\u0169&quot;
&apos;
&apos;
&apos;
&apos;General Punctuation \u2000-\u206f
&apos;Latin Extended A \u0100-\u017f
&apos;\u02bb Modifier Letter Turned Comma is in IPH Astra
&apos; unicodeConversionEverywhere(&quot;[\u0020-\u007F]+&quot;,RAtts)
unicodeConversionEverywhere(&quot;[\u0020-\u007f\u0080-\u00ff\u0400-\u04ff\u2000-\u206f\u2100-\u214f\u02bb\u0100-\u017f&quot; &amp; combiningDiacritic_Astra &amp; extendedLatinA_Astra &amp;&quot;]+&quot;,RAtts)
&apos;Arabic Scheherazade
&apos;Arabic Presentation Forms-A fb50-fdff
&apos;Arabic Presentation Forms-B fe70-feff
newFontName = &quot;Scheherazade&quot;
RAtts(0).Value = newFontName
RAtts(1).Value = newFontName
RAtts(2).Value = newFontName
unicodeConversionEverywhere(sharedMarksRegExp &amp; &quot;[\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+&quot; &amp; sharedMarksRegExp ,RAtts)
&apos;Greek Tinos
newFontName = &quot;Tinos&quot;
RAtts(0).Value = newFontName
RAtts(1).Value = newFontName
RAtts(2).Value = newFontName
&apos;Greek and Coptic 0370—03FF
&apos;Greek extended 1F00—1FFF
unicodeConversionEverywhere(sharedMarksRegExp &amp; &quot;[\u0370-\u03ff\u1f00-\u1fff]+&quot; &amp; sharedMarksRegExp,RAtts)
&apos;DejaVu Sans Mathematical operators
newFontName = &quot;DejaVu Sans&quot;
RAtts(0).Value = newFontName
RAtts(1).Value = newFontName
RAtts(2).Value = newFontName
&apos;\u2200-\u22FF Mathematical operators
&apos;\u2630-\u2637 Trigrams
&apos;\u4DC0-\u4DFF Trigrams
unicodeConversionEverywhere(&quot;[\u2200-\u22ff\u2630-\u2637\u4DC0-\u4DFF]+&quot;,RAtts)
newFontName = &quot;Noto Serif CJK JP&quot;
RAtts(0).Value = newFontName
RAtts(1).Value = newFontName
RAtts(2).Value = newFontName
&apos;\u2200-\u22FF CJK Unified Ideographs
&apos;\u21d2 двойная стрелка вправо
&apos;3000—303F Символы и пунктуация ККЯ
unicodeConversionEverywhere(sharedMarksRegExp &amp; &quot;[\u21d2\u302b\uff00-\uffef]+&quot; &amp; sharedMarksRegExp,RAtts)
newFontName = &quot;Noto Serif CJK SC&quot;
RAtts(0).Value = newFontName
RAtts(1).Value = newFontName
RAtts(2).Value = newFontName
&apos;\u2200-\u22FF CJK Unified Ideographs
&apos;\u4e00—\u9fff Унифицированные идеограммы ККЯ
&apos;\u3400-\u4db7\u4e00—\u9ff1 Найдены в Noto Sans CJK SC
&apos;\u3000-\u302a\u302c-\u303f В Noto Sans CJK SC
unicodeConversionEverywhere(sharedMarksRegExp &amp; &quot;[\u3000-\u302a\u302c-\u303f\u3400-\u4db7\u4e00-\u9ff1]+&quot; &amp; sharedMarksRegExp,RAtts)
End Sub
Private Sub unicodeConversionEverywhere(searchPattern As String,rAtts)
setAttributesBySearchPattern(searchPattern,RAtts)
End Sub
&apos;Replaces manual formatting text with font into character style with assigned font
Private Sub convertFontsToCharStyles
Dim oDoc As Object
Dim SDesc As Object
Dim founds As Object
Dim curFont As String
Dim srch(0) as new com.sun.star.beans.PropertyValue
oDoc = Thiscomponent
SDesc = Thiscomponent.createSearchDescriptor()
SDesc.SearchAll = true
SDesc.ValueSearch = false
SDesc.SearchStyles = false
SDesc.SearchRegularExpression = false
SDesc.SearchString = &quot;&quot;
srch(0).Name = &quot;CharFontName&quot;
SDesc.SetSearchAttributes(srch())
founds = Thiscomponent.findFirst(SDesc)
do while not isNull(founds)
curFont = founds.CharFontName
If IsEmpty(curFont) Then
curFont = &quot;IPH Astra Serif&quot;
EndIf
If curFont &lt;&gt; &quot;IPH Astra Serif&quot; AND curFont &lt;&gt; &quot;&quot; Then
If Not DocHasCharStyle(oDoc,curFont) Then
Dim oProps(2) As New com.sun.star.beans.PropertyValue
oProps(0).Name = &quot;CharFontName&quot;
oProps(1).Name = &quot;CharFontNameComplex&quot;
oProps(2).Name = &quot;CharFontNameAsian&quot;
oProps(0).Value = curFont
oProps(1).Value = curFont
oProps(2).Value = curFont
CreateCharacterStyle(curFont, oProps())
End If
founds.CharStyleNames = Array(curFont)
EndIf
founds = Thiscomponent.findNext(founds.getend, SDesc)
loop
End Sub
Private Sub removeUserPageStyles
Dim oStyles As Object
Dim oStyle As Object
Dim count As Long
Dim i As Long
oStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
count = oStyles.count - 1
For i = 0 to count
oStyle = oStyles.getByIndex(i)
If oStyle.isUserDefined Then
oStyles.removeByName(oStyle.getName)
count = oStyles.count - 1
&apos;restart if style removed as sorting is unreliable
i = -1
EndIf
Next i
End Sub
Sub removeAllFields()
Dim fields As Object
Dim fieldEnum As Object
Dim field As Object
fields = ThisComponent.getTextFields()
fieldEnum = fields.createEnumeration()
While fieldEnum.hasMoreElements
field = fieldEnum.nextElement()
field.dispose()
Wend
End Sub
Public Const RX_Greek_letters = &quot;\u0388-\u03ce&quot;
Public Const RX_Latin_up_alphabet = &quot;\u0041-\u005a&quot;
Public Const RX_Latin_low_alphabet = &quot;\u0061-\u007a&quot;
Public Const RX_Cyrillic_alphabet = &quot;\u0410-\u044f&quot;
Public Const RX_Comma = &quot;\u002c&quot;
Public Const RX_Digits = &quot;\u0030-\u0039&quot;
Public Const RX_Roman_numbers = &quot;MDCLXVI&quot;
Public Const RX_Letters_Dash = &quot;[&quot; &amp; RX_Latin_up_alphabet &amp; RX_Latin_low_alphabet &amp; RX_Cyrillic_alphabet &amp; RX_Greek_letters &amp; &quot;]&quot;
Public Const RX_Letters = &quot;[&quot; &amp; RX_Latin_up_alphabet &amp; RX_Latin_low_alphabet &amp; RX_Cyrillic_alphabet &amp; RX_Greek_letters &amp; &quot;]&quot;
Private Sub fixFrequentMistakes
Dim config As Object
config = initRedactionConfiguration()
Dim NBSP As String
Dim space As String
NBSP = &quot; &quot;
space = &quot; &quot;
&apos;Не должно быть символов табуляции
AskAndReplace(&quot;\t&quot;,&quot;&quot;)
&apos;Не должно быть подряд больше одного пробела
AskAndReplace(&quot;(?&lt;=[:space:])[:space:]+&quot;,&quot;&quot;)
&apos;Не должно быть ни одного пробела в начале абзацев
AskAndReplace(&quot;^[:space:]+&quot;,&quot;&quot;)
&apos;Не должно быть пробелов в конце абзацев
AskAndReplace(&quot;[:space:]+$&quot;,&quot;&quot;)
&apos;Не должно быть пустых абзацев
AskAndReplace(&quot;^$&quot;,&quot;&quot;)
&apos;Не должно быть пробелов перед знаками пунктуации .,;:?!)]}»¡¿”‘’
AskAndReplace(&quot;[:space:]+(?=[\.,;:?!\)\]\}»¡¿”’])&quot;,&quot;&quot;)
&apos;Не должно быть пробелов после скобок [({ и кавычек «„
AskAndReplace(&quot;(?&lt;=[\(\[\{«„])[:space:]&quot;,&quot;&quot;)
&apos;Между буквами среднее или длинное тире должно быть замененено на среднее и обрамлено пробелами
AskAndReplace(&quot;(?&lt;=&quot; &amp; RX_Letters_Dash &amp; &quot;)[—–]+(?=.)&quot;,NBSP &amp; &quot;&quot; &amp; NBSP)
AskAndReplace(&quot;(?&lt;=.)[—–]+(?=&quot; &amp; RX_Letters_Dash &amp; &quot;)&quot;,NBSP &amp; &quot;&quot; &amp; NBSP)
&apos;Между буквами дефисы-минусы, цифровые тире, средние тире и длинные тире заменяются на одно среднее тире
AskAndReplace(&quot;(?&lt;=&quot; &amp; RX_Letters_Dash &amp; &quot;[:space:])[-‒—−–]+(?=[:space:].)&quot;,&quot;&quot;)
AskAndReplace(&quot;(?&lt;=.[:space:])[-‒—−–]+(?=[:space:]&quot; &amp; RX_Letters_Dash &amp; &quot;)&quot;,&quot;&quot;)
&apos;Между двумя цифрами и тире не долнжо быть пробелов. А также тире должно быть цифровым.
&apos;Также проверяем, что перед искомым тире нет DOI
&apos;&apos;&apos;&apos;&apos;AskAndReplace(&quot;(?&lt;!DOI[0-9. /XVI:-‒–—−-]{1,50})(?&lt;=[:digit:])(?:[:space:])?[-‒–—−](?:[:space:])?(?=[:digit:])&quot;,&quot;&quot;)
&apos;Между двумя римскими цифрами и тире между ними не долнжо быть пробелов. А также тире должно быть средним
AskAndReplace(&quot;(?&lt;=[&quot; &amp; RX_Roman_numbers &amp; &quot;])(?:[:space:])?[-‒–—−]+(?:[:space:])?(?=[&quot; &amp; RX_Roman_numbers &amp; &quot;])&quot;,&quot;&quot;)
&apos;Между буквой и угловой открывающейся скобкой должен быть пробел
AskAndReplace(&quot;(?&lt;=&quot; &amp; RX_Letters &amp; &quot;)&lt;(?=…&gt;)&quot;,space &amp; &quot;&lt;&quot;)
&apos;Между угловой закрывающейся скобкой и буквой должен быть пробел
AskAndReplace(&quot;(?&lt;=&lt;…)&gt;(?=&quot; &amp; RX_Letters &amp; &quot;)&quot;,&quot;&gt;&quot; &amp; space)
If config.getPropertyValue(&quot;fixes_russian_iph&quot;) = &quot;true&quot; Then
&apos;между N. Y. не должно быть пробела
AskAndReplace(&quot;(?&lt;=N\.)[:space:](?=Y\.)&quot;,&quot;&quot;)
&apos;Между словом том и цифрой должен быть неразрывный пробел, а не обычный
AskAndReplace(&quot;(?&lt;=\b[тТ](ом|\.))\ (?=[:digit:])&quot;,NBSP)
&apos;Между словом серия и цифрой должен быть неразрывный пробел, а не обычный
AskAndReplace(&quot;(?&lt;=\b[сС](ерия|\.))\ +(?=[:digit:])&quot;,NBSP)
&apos;Между словом часть и цифрой должен быть неразрывный пробел, а не обычный
AskAndReplace(&quot;(?&lt;=\b[чЧ](асть|\.))\ +(?=[:digit:])&quot;,NBSP)
&apos;Между числом и &quot;г.&quot; должен быть неразрывный пробел, а не обычный
AskAndReplace(&quot;(?&lt;=[0-9])[:space:]*г(?=\.)&quot;,NBSP &amp; &quot;г&quot;)
&apos;Между инициалами и Фамилией должен быть неразрывный пробел, а не обычный
&apos;А.[м/б пробел]А.Иванов -&gt; А.[м/б пробел]А. Иванов
AskAndReplace(&quot;(?&lt;=[:upper:]\.[:space:]?[:upper:])\.[:space:]?(?=[:upper:][:lower:]{1,30})&quot;,&quot;.&quot; &amp; NBSP)
&apos; А.[пробел]А.Иванов -&gt; А.А. Иванов
AskAndReplace(&quot;(?&lt;=[:upper:])\.[:space:](?=[:upper:]\.[:space:][:upper:][:lower:]{1,30})&quot;,&quot;.&quot;)
&apos;Между Фамилией и инициалами должен быть неразрывный пробел, а не обычный
&apos;Иванов А.[м/б пробел]А. -&gt; Иванов А.А.
AskAndReplace(&quot;(?&lt;=[:upper:][:lower:]{1,30}[:space:][:upper:])\.[:space:]?(?=[:upper:]\.)&quot;,&quot;.&quot;)
&apos;Между &quot;и&quot; и &quot;т.&quot; должен быть неразрывный пробел, а не обычный
AskAndReplace(&quot;(?&lt;=\bи)\ (?=т\.)&quot;,NBSP)
&apos;Между &quot;т.&quot; и &quot;е./н./д./п./к.&quot; не должно быть пробела
AskAndReplace(&quot;(?&lt;=\bт)\.[:space:]?(?=[ендпк]\.)&quot;,&quot;.&quot;)
AskAndReplace(&quot;[ий][\u0306]+&quot;,&quot;й&quot;)
AskAndReplace(&quot;[ИЙ][\u0306]+&quot;,&quot;Й&quot;)
AskAndReplace(&quot;[её][\u0308]+&quot;,&quot;ё&quot;)
AskAndReplace(&quot;[ЕЁ][\u0308]+&quot;,&quot;Ё&quot;)
EndIf
End Sub
Private Sub loadArticleStyles
Dim dispatcher As Object
Dim filePath As String
Dim fileTest As Object
Dim predefined As String
Dim aArgs(0) As New com.sun.star.beans.PropertyValue
Dim config As Object
config = initRedactionConfiguration()
predefined = config.getPropertyValue(&quot;predefined_template&quot;)
filePath = getTemplateFile(predefined)
fileTest = CreateUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
If NOT fileTest.exists(filePath) Then
configureStyleFileDialog()
predefined = config.getPropertyValue(&quot;predefined_template&quot;)
filePath = getTemplateFile(predefined)
If NOT fileTest.exists(filePath) Then
&apos;MsgBox &quot;Файл стилей &quot; &amp; fileName &amp; &quot; не добавлен в Мои шаблоны. Не могу загрузить стили в текущий файл.&quot;
Exit Sub
EndIf
EndIf
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
aArgs(0).Name = &quot;OverwriteStyles&quot;
aArgs(0).Value = True
ThisComponent.StyleFamilies.loadStylesFromURL( filePath, aArgs() )
End Sub
Private Sub CreateCharacterStyle(sStyleName As String, oProps())
Dim i As Integer
Dim oFamilies As Object
Dim oStyle As Object
Dim oStyles As Object
oFamilies = ThisComponent.StyleFamilies
oStyles = oFamilies.getByName(&quot;CharacterStyles&quot;)
If oStyles.HasByName(sStyleName) Then
Exit Sub
End If
oStyle = ThisComponent.createInstance(&quot;com.sun.star.style.CharacterStyle&quot;)
For i=LBound(oProps) To UBound(oProps)
oStyle.setPropertyValue(oProps(i).Name, oProps(i).Value)
Next
oStyles.insertByName(sStyleName, oStyle)
End Sub
Private Function CreateProperty( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
CreateProperty() = oPropertyValue
End Function
Private Sub AskAndReplace(SearchString As String, oReplaceString As String)
Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
Dim ReplAttributes(0) as new com.sun.star.beans.PropertyValue
ReplaceFormatting(SearchString,oReplaceString,SrchAttributes,ReplAttributes, true)
End Sub
Private Function DocHasCharStyle(oDoc, sName$) As Boolean
Dim oStyles As Object
oStyles = oDoc.StyleFamilies.getByName(&quot;CharacterStyles&quot;)
DocHasCharStyle() = oStyles.hasByName(sName)
End Function
Private Function getTemplatePath() as String
Dim path as String
Dim settings As Object
Dim configProvider As Object
Dim params(0) As new com.sun.star.beans.PropertyValue
Dim convService As Object
configProvider = createUnoService( &quot;com.sun.star.configuration.ConfigurationProvider&quot; )
params(0).Name = &quot;nodepath&quot;
params(0).Value = &quot;/org.openoffice.Office.Paths/Paths&quot;
settings = configProvider.createInstanceWithArguments(&quot;com.sun.star.configuration.ConfigurationAccess&quot;, params() )
path = settings.Template.WritePath
convService = CreateUnoService(&quot;com.sun.star.util.PathSubstitution&quot;)
path = convService.substituteVariables(path, true)
path = ConvertToUrl(path)
getTemplatePath = path
End Function
Private Sub removeHyperlinks()
Dim aNote As Object
Dim x As Long
removeHLInText(ThisComponent.Text)
For x = 0 to ThisComponent.FootNotes.Count -1
aNote = ThisComponent.FootNotes.getByIndex(x)
removeHLInText(aNote.Text)
Next
For x = 0 to ThisComponent.EndNotes.Count -1
aNote = ThisComponent.EndNotes.getByIndex(x)
removeHLInText(aNote.Text)
Next
End Sub
Private Sub removeHLInText(textElement)
Dim enum1Element As Object
Dim enum1 As Object
Dim i As Integer
Dim cell As Object
Dim cellNames()
Dim cellText As Object
enum1 = textElement.createEnumeration()
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
removeHLInPara(enum1Element)
ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
cellNames = enum1Element.cellNames
For i = LBound(cellNames) To Ubound(cellNames)
cell = enum1Element.getCellByName(cellNames(i))
cellText = cell.getText()
removeHLInText(cellText)
Next i
Else
EndIf
Wend
End Sub
Private Sub removeHLInPara(para)
Dim enum1Element As Object
Dim enum1 As Object
Dim elPropertySetInfo As Object
Dim i As Integer
enum1 = para.createEnumeration()
While enum1.hasMoreElements
enum1Element = enum1.nextElement
elPropertySetInfo = enum1Element.getPropertySetInfo()
If elPropertySetInfo.hasPropertyByName(&quot;HyperLinkURL&quot;) Then
enum1Element.HyperLinkURL=&quot;&quot;
EndIf
Wend
End Sub
Private Sub disposeAllBookmarks()
Dim bookmarks As Object
Dim elementName As String
elementName = ThisComponent.Links.ElementNames(6)
bookmarks = ThisComponent.Links.getByName(elementName)
While bookmarks.hasElements()
bookmark = bookmarks.getByName(bookmarks.ElementNames(0))
bookmark.dispose()
Wend
End Sub
Private Sub removeManualPageBreaks
Dim oTextCursor As Object
Dim enum1 As Object
Dim enum1Element As Object
oTextCursor = ThisComponent.Text.CreateTextCursor()
enum1 = ThisComponent.Text.createEnumeration
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
If enum1Element.BreakType &lt;&gt; com.sun.star.style.BreakType.NONE Then
oTextCursor.goToRange(enum1Element.getAnchor(), false)
If NOT IsEmpty(oTextCursor.PageDescName) Then
oTextCursor.PageDescName = &quot;&quot;
End If
oTextCursor.BreakType = com.sun.star.style.BreakType.NONE
End If
ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
If NOT IsEmpty(enum1Element.PageDescName) Then
enum1Element.PageDescName = &quot;&quot;
End If
enum1Element.BreakType = com.sun.star.style.BreakType.NONE
EndIf
Wend
End Sub
Sub setAttributesBySearchPattern(searchPattern As String,ReplAttributes, Optional SrchAttributes)
doNotTrack
dim stringValue1 As String
dim stringValue2 As String
Dim oSearch As Object
Dim oTextCursor As Object
Dim oViewCursor As Object
Dim replace As Boolean
Dim attrName As string
Dim attrValue As String
Dim oFound As Object
Dim i As Long
Dim j As Long
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oSearch = ThisComponent.createSearchDescriptor()
oSearch.SearchString = searchPattern
&apos; Mri oSearch
oSearch.SearchRegularExpression=True
oSearch.SearchAll = True
If Not IsMissing (SrchAttributes) Then
If Not IsEmpty(SrchAttributes(0).Value) Then
oSearch.searchStyles = true
oSearch.SetSearchAttributes(SrchAttributes())
End If
EndIf
oFound = ThisComponent.findFirst(oSearch)
Do While Not IsNull(oFound)
replace = true
If Not IsMissing(SrchAttributes) Then
For j = LBound(SrchAttributes) To Ubound(SrchAttributes)
If oFound.getPropertySetInfo.hasPropertyByName(SrchAttributes(j).Name) Then
stringValue1 = &quot;&quot; &amp; oFound.getPropertyValue(SrchAttributes(j).Name)
stringValue2 = &quot;&quot; &amp; SrchAttributes(j).Value
If stringValue1 &lt;&gt; stringValue2 Then
replace = replace AND False
EndIf
Else
replace = replace AND False
EndIf
Next j
EndIf
If replace then
For i = LBound(ReplAttributes) To Ubound(ReplAttributes)
&apos;If oFound.getPropertySetInfo.hasPropertyByName(ReplAttributes(i).Name) Then
oFound.SetPropertyValue(ReplAttributes(i).Name, ReplAttributes(i).Value)
&apos;EndIf
Next i
EndIf
oFound = ThisComponent.findNext(oFound.End, oSearch)
Loop
End Sub
Private Sub saveAndreload()
Dim document As Object
Dim dispatcher As Object
&apos;Dim timeOut As Long
&apos;timeOut = 0
&apos;DocumentLoaded = false
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array())
dispatcher.executeDispatch(document, &quot;.uno:Reload&quot;, &quot;&quot;, 0, Array())
Wait 1000
&apos;RegisterListener (ThisComponent)
&apos;Do while DocumentLoaded = false
&apos; Wait 300
&apos; timeOut = timeOut + 300
&apos; If timeOut &gt; 30000 Then
&apos; MsgBox &quot;Time out&quot;
&apos; Exit sub
&apos; EndIf
&apos;Loop
&apos;DocumentLoaded = false
End Sub
Private Sub saveDocument()
Dim document As Object
Dim dispatcher As Object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array())
end Sub
Private Sub cleanFormatting
&apos;Не должно быть символов табуляции
AskAndReplace(&quot;\t&quot;,&quot;&quot;)
&apos;Не должно быть подряд больше одного пробела
AskAndReplace(&quot;(?&lt;=[:space:])[:space:]+&quot;,&quot;&quot;)
&apos;Не должно быть ни одного пробела в начале абзацев
AskAndReplace(&quot;^[:space:]+&quot;,&quot;&quot;)
&apos;Не должно быть пустых абзацев
AskAndReplace(&quot;^$&quot;,&quot;&quot;)
convertFormattingToUserFields
convertFontsToCharStyles()
replaceBaseWithStandard()
resetFootnotesStyle
removeDirectFormatting()
saveAndreload()
convertUserFieldsToFormatting
End Sub
Private Sub fixTableWidth()
Dim table As Object
Dim tables As Object
Dim count As Long
Dim i As Long
tables = ThisComponent.TextTables
count = ThisComponent.TextTables.getCount()
For i = 0 To count - 1
table = tables.getByIndex(i)
If table.HoriOrient = 6 Then
table.HoriOrient = 2
EndIf
If table.RelativeWidth = 0 Then
table.RelativeWidth = 100
EndIf
Next
End Sub
Private Sub fixDrawingAnchors()
Dim drawing As Object
Dim drawings As Object
drawings = ThisComponent.DrawPage
Dim count As Long
Dim i As Long
count = drawings.getCount()
For i = 0 To count - 1
drawing = drawings.getByIndex(i)
If drawing.AnchorType= com.sun.star.text.TextContentAnchorType.AT_PAGE Then
drawing.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
EndIf
Next
End Sub
Private Sub replaceBaseWithStandard
replaceParaStyle(&quot;Базовый&quot;,&quot;Основной текст&quot;)
replaceParaStyle(&quot;Default Style&quot;,&quot;Text Body&quot;)
resetSearchSettings()
End Sub
Private Sub replaceParaStyle(oldStyleName,newStyleName)
Dim document as Object
Dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
Dim args1(21) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;SearchItem.StyleFamily&quot;
args1(0).Value = 2
args1(1).Name = &quot;SearchItem.CellType&quot;
args1(1).Value = 0
args1(2).Name = &quot;SearchItem.RowDirection&quot;
args1(2).Value = true
args1(3).Name = &quot;SearchItem.AllTables&quot;
args1(3).Value = false
args1(4).Name = &quot;SearchItem.SearchFiltered&quot;
args1(4).Value = false
args1(5).Name = &quot;SearchItem.Backward&quot;
args1(5).Value = false
args1(6).Name = &quot;SearchItem.Pattern&quot;
args1(6).Value = true
args1(7).Name = &quot;SearchItem.Content&quot;
args1(7).Value = false
args1(8).Name = &quot;SearchItem.AsianOptions&quot;
args1(8).Value = false
args1(9).Name = &quot;SearchItem.AlgorithmType&quot;
args1(9).Value = 0
args1(10).Name = &quot;SearchItem.SearchFlags&quot;
args1(10).Value = 65536
args1(11).Name = &quot;SearchItem.SearchString&quot;
args1(11).Value = oldStyleName
args1(12).Name = &quot;SearchItem.ReplaceString&quot;
args1(12).Value = newStyleName
args1(13).Name = &quot;SearchItem.Locale&quot;
args1(13).Value = 255
args1(14).Name = &quot;SearchItem.ChangedChars&quot;
args1(14).Value = 2
args1(15).Name = &quot;SearchItem.DeletedChars&quot;
args1(15).Value = 2
args1(16).Name = &quot;SearchItem.InsertedChars&quot;
args1(16).Value = 2
args1(17).Name = &quot;SearchItem.TransliterateFlags&quot;
args1(17).Value = 1280
args1(18).Name = &quot;SearchItem.Command&quot;
args1(18).Value = 3
args1(19).Name = &quot;SearchItem.SearchFormatted&quot;
args1(19).Value = false
args1(20).Name = &quot;SearchItem.AlgorithmType2&quot;
args1(20).Value = 1
args1(21).Name = &quot;Quiet&quot;
args1(21).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ExecuteSearch&quot;, &quot;&quot;, 0, args1())
End Sub
Private Sub resetSearchSettings()
Dim document as Object
Dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args3(21) as new com.sun.star.beans.PropertyValue
args3(0).Name = &quot;SearchItem.StyleFamily&quot;
args3(0).Value = 2
args3(1).Name = &quot;SearchItem.CellType&quot;
args3(1).Value = 0
args3(2).Name = &quot;SearchItem.RowDirection&quot;
args3(2).Value = true
args3(3).Name = &quot;SearchItem.AllTables&quot;
args3(3).Value = false
args3(4).Name = &quot;SearchItem.SearchFiltered&quot;
args3(4).Value = false
args3(5).Name = &quot;SearchItem.Backward&quot;
args3(5).Value = false
args3(6).Name = &quot;SearchItem.Pattern&quot;
args3(6).Value = false
args3(7).Name = &quot;SearchItem.Content&quot;
args3(7).Value = false
args3(8).Name = &quot;SearchItem.AsianOptions&quot;
args3(8).Value = false
args3(9).Name = &quot;SearchItem.AlgorithmType&quot;
args3(9).Value = 0
args3(10).Name = &quot;SearchItem.SearchFlags&quot;
args3(10).Value = 65536
args3(11).Name = &quot;SearchItem.SearchString&quot;
args3(11).Value = &quot;&quot;
args3(12).Name = &quot;SearchItem.ReplaceString&quot;
args3(12).Value = &quot;&quot;
args3(13).Name = &quot;SearchItem.Locale&quot;
args3(13).Value = 255
args3(14).Name = &quot;SearchItem.ChangedChars&quot;
args3(14).Value = 2
args3(15).Name = &quot;SearchItem.DeletedChars&quot;
args3(15).Value = 2
args3(16).Name = &quot;SearchItem.InsertedChars&quot;
args3(16).Value = 2
args3(17).Name = &quot;SearchItem.TransliterateFlags&quot;
args3(17).Value = 1280
args3(18).Name = &quot;SearchItem.Command&quot;
args3(18).Value = 3
args3(19).Name = &quot;SearchItem.SearchFormatted&quot;
args3(19).Value = false
args3(20).Name = &quot;SearchItem.AlgorithmType2&quot;
args3(20).Value = 1
args3(21).Name = &quot;Quiet&quot;
args3(21).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ExecuteSearch&quot;, &quot;&quot;, 0, args3())
End Sub
Private Sub doNotTrack
Dim dispatcher As Object
Dim document As Object
Dim trackProperties(0) as new com.sun.star.beans.PropertyValue
Dim args1(0) as new com.sun.star.beans.PropertyValue
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
document = ThisComponent.CurrentController.Frame
trackProperties(0).Name = &quot;TrackChanges&quot;
trackProperties(0).Value = false
dispatcher.executeDispatch(document, &quot;.uno:TrackChanges&quot;, &quot;&quot;, 0, trackProperties())
args1(0).Name = &quot;ShowTrackedChanges&quot;
args1(0).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ShowTrackedChanges&quot;, &quot;&quot;, 0, args1())
End Sub
Private Sub removeDirectFormatting
Dim oDescriptor As Object
Dim dispatcher as Object
Dim document as Object
Dim x As Integer
Dim endNotes As Object
Dim aNote As Object
Dim endNoteText As Object
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim footNotes As Object
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
document = ThisComponent.CurrentController.Frame
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.jumpToFirstPage()
oViewCursor.gotoStart(false)
oViewCursor.gotoEnd(true)
dispatcher.executeDispatch(document, &quot;.uno:ResetAttributes&quot;, &quot;&quot;, 0, Array())
footNotes = thisComponent.Footnotes
For x = 0 to footNotes.Count -1
aNote = footNotes.getByIndex(x)
footNoteText = aNote.getText()
oTextcursor = footNoteText.createTextCursor()
oViewCursor.gotoRange(oTextcursor.getStart(),false)
oViewCursor.gotoEnd(true)
dispatcher.executeDispatch(document, &quot;.uno:ResetAttributes&quot;, &quot;&quot;, 0, Array())
Next
endNotes = thisComponent.Endnotes
for x = 0 to endNotes.Count -1
aNote = endNotes.getByIndex(x)
endNoteText = aNote.getText()
oTextcursor = endNoteText.createTextCursor()
oViewCursor.gotoRange(oTextcursor.getStart(),false)
oViewCursor.gotoEnd(true)
dispatcher.executeDispatch(document, &quot;.uno:ResetAttributes&quot;, &quot;&quot;, 0, Array())
next
oViewCursor.gotoStart(false)
End Sub
Private Sub resetFootnotesStyle
Dim oDescriptor As Object
Dim dispatcher as Object
Dim document As Object
Dim oViewCursor As Object
Dim allNotes As Object
Dim x As Integer
Dim aNote As Object
Dim oEnum As Object
Dim oCurPar As Object
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
document = ThisComponent.CurrentController.Frame
oViewCursor = ThisComponent.CurrentController.getViewCursor()
allNotes= thisComponent.FootNotes
for x = 0 to allNotes.Count -1
aNote = allNotes.getByIndex(x)
aNote.Anchor.CharStyleName=&quot;Footnote anchor&quot;
oEnum = aNote.Text.createEnumeration()
Do While oEnum.hasMoreElements()
oCurPar = oEnum.nextElement()
oCurPar.ParaStyleName = &quot;Footnote&quot;
Loop
Next
End Sub
Private Sub removeUnusedStyles
Dim sElements() as String
Dim oFamilies As Object
Dim oFamily As Object
Dim i As Integer
Dim oDoc as object
oDoc = ThisComponent
oFamilies = thiscomponent.StyleFamilies
sElements() = oFamilies.getElementNames()
For i = 0 to uBound(sElements()) -2
oFamily = oFamilies.getByName(sElements(i))
removeUnusedStyle(oFamily,sElements(i),True)
Next
End Sub
Private Sub removeUnusedStyle(oFamily ,sFamily as string, bAsk as Boolean)
Dim i As Integer
Dim sUsed() as String
sUsed() = getStyleNames(oFamily,bLocalized:=True,bUsed:=False,bUserDef:=true)
If uBound(sUsed()) &gt; -1 then
For i = 0 to uBound(sUsed())
oFamily.removeByName(sUsed(i))
Next
EndIf
End Sub
Private Sub convertFormatToEnclosure(identifier As String, styleNames, styleValues)
Dim leftEnclosure As String
Dim rightEnclosure As String
Dim oTextCursor As Object
Dim startTextRange As Object
Dim endTextRange As Object
Dim foundString As String
Dim SDesc As Object
Dim SrchAttributes(Ubound(styleNames)) as new com.sun.star.beans.PropertyValue
Dim i As Integer
Dim found As Object
leftEnclosure = compileLeftEnclosure(identifier)
rightEnclosure = compileRightEnclosure(identifier)
For i = 0 To Ubound(styleNames)
SrchAttributes(i).Name = styleNames(i)
SrchAttributes(i).Value = styleValues(i)
Next i
SDesc = Thiscomponent.createSearchDescriptor()
SDesc.SearchAll = true
SDesc.SearchRegularExpression = true
SDesc.SearchString = &quot;&quot;
SDesc.searchStyles = false
SDesc.SetSearchAttributes(SrchAttributes)
found = Thiscomponent.findFirst(SDesc)
Do While not isNull(found)
oTextCursor = found.Text.createTextCursor()
oTextCursor.goToRange(found.Start, false)
oTextCursor.goToRange(found.End, true)
For i = 0 To Ubound(styleNames)
oTextCursor.setPropertyToDefault(styleNames(i))
Next i
foundString = found.getString()
If Len(foundString) &lt;&gt; 0 Then
oTextCursor.collapseToEnd()
oTextCursor.String = rightEnclosure
endTextRange = oTextCursor.getEnd()
oTextCursor.goToRange(found.start,false)
oTextCursor.String = leftEnclosure
EndIf
found = Thiscomponent.findNext(found.End, SDesc)
Loop
End Sub
Private Sub convertEnclosuresToFormat(identifier As String, styleNames, styleValues)
Dim oTextCursor As Object
Dim startTextRange As Object
Dim endTextRange As Object
Dim leftEnclosure As String
Dim rightEnclosure As String
Dim SDesc As Object
Dim found As Object
leftEnclosure = compileLeftEnclosure(identifier)
rightEnclosure = compileRightEnclosure(identifier)
SDesc = Thiscomponent.createSearchDescriptor()
SDesc.SearchAll = true
SDesc.SearchRegularExpression = true
SDesc.SearchString = leftEnclosure + &quot;([^&quot; + identifier+ &quot;]*)&quot; + rightEnclosure
found = Thiscomponent.findFirst(SDesc)
Do While not isNull(found)
oTextCursor = found.Text.createTextCursor()
oTextCursor.goToRange(found.Start, false)
oTextCursor.goToRange(found.End, true)
oTextCursor.setPropertyValues(styleNames, styleValues)
oTextCursor.collapseToEnd()
oTextCursor.goLeft(Len(rightEnclosure), true)
oTextCursor.String = &quot;&quot;
endTextRange = oTextCursor.getEnd()
oTextCursor.goToRange(found.start,false)
oTextCursor.goRight(Len(leftEnclosure), true)
oTextCursor.String = &quot;&quot;
found = Thiscomponent.findNext(endTextRange, SDesc)
Loop
End Sub
Private Function compileSearchString(identifier) As String
compileSearchString = &quot;&lt;&quot; &amp; identifier &amp; &quot;&gt;&quot; &amp; &quot;(.*?)&quot; &amp; &quot;&lt;/&quot; &amp; identifier &amp; &quot;&gt;&quot;
End Function
Private Function compileLeftEnclosure(identifier) As String
compileLeftEnclosure = &quot;&lt;&quot; &amp; identifier &amp; &quot;&gt;&quot;
End Function
Private Function compileRightEnclosure(identifier) As String
compileRightEnclosure = &quot;&lt;/&quot; &amp; identifier &amp; &quot;&gt;&quot;
End Function
Private Sub toTextBold
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharWeight&quot;)
styleValues = Array(com.sun.star.awt.FontWeight.BOLD)
convertFormatToEnclosure(CHR(867), styleNames, styleValues)
End Sub
Private Sub fromTextBold
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharWeight&quot;)
styleValues = Array(com.sun.star.awt.FontWeight.BOLD)
convertEnclosuresToFormat(CHR(867), styleNames, styleValues)
End Sub
Private Sub toTextItalic
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharPosture&quot;)
styleValues = Array(com.sun.star.awt.FontSlant.ITALIC)
convertFormatToEnclosure(CHR(868), styleNames, styleValues)
End Sub
Private Sub fromTextItalic
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharPosture&quot;)
styleValues = Array(com.sun.star.awt.FontSlant.ITALIC)
convertEnclosuresToFormat(CHR(868), styleNames, styleValues)
End Sub
Private Sub toTextStrikeout
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharStrikeout&quot;)
styleValues = Array(com.sun.star.awt.FontStrikeout.SINGLE)
convertFormatToEnclosure(CHR(869), styleNames, styleValues)
End Sub
Private Sub fromTextStrikeout
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharStrikeout&quot;)
styleValues = Array(com.sun.star.awt.FontStrikeout.SINGLE)
convertEnclosuresToFormat(CHR(869), styleNames, styleValues)
End Sub
Private Sub toTextUnderline
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharUnderline&quot;)
styleValues = Array(com.sun.star.awt.FontUnderline.SINGLE)
convertFormatToEnclosure(CHR(870), styleNames, styleValues)
End Sub
Private Sub fromTextUnderline
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharUnderline&quot;)
styleValues = Array(com.sun.star.awt.FontUnderline.SINGLE)
convertEnclosuresToFormat(CHR(870), styleNames, styleValues)
End Sub
Private Sub toTextSuperscript
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,14000)
convertFormatToEnclosure(CHR(871), styleNames, styleValues)
End Sub
Private Sub fromTextSuperscript
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,14000)
convertEnclosuresToFormat(CHR(871), styleNames, styleValues)
End Sub
Private Sub toTextSubscript
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-14000)
convertFormatToEnclosure(CHR(872), styleNames, styleValues)
End Sub
Private Sub fromTextSubscript
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-14000)
convertEnclosuresToFormat(CHR(872), styleNames, styleValues)
End Sub
Private Sub toTextSuperscriptOld
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,101)
convertFormatToEnclosure(CHR(871), styleNames, styleValues)
End Sub
Private Sub fromTextSuperscriptOld
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,101)
convertEnclosuresToFormat(CHR(871), styleNames, styleValues)
End Sub
Private Sub toTextSubscriptOld
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-101)
convertFormatToEnclosure(CHR(872), styleNames, styleValues)
End Sub
Private Sub fromTextSubscriptOld
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-101)
convertEnclosuresToFormat(CHR(872), styleNames, styleValues)
End Sub
Private Sub toTextSparce
Dim i As Integer
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharKerning&quot;)
For i=70 To 70
styleValues = Array(i)
convertFormatToEnclosure(CHR(873) &amp; i, styleNames, styleValues)
Next
End Sub
Private Sub fromTextSparce
Dim i As Integer
Dim styleNames As Variant
Dim StyleValues As Variant
styleNames = Array(&quot;CharKerning&quot;)
For i=70 To 70
styleValues = Array(i)
convertEnclosuresToFormat(CHR(873) &amp; i, styleNames, styleValues)
Next
End Sub
Private Function confirm(description) As Boolean
If MsgBox (description, 4) =6 Then
confirm = true
Else
confirm = false
EndIf
End Function
Private Sub ReplaceFormatting(SearchString As String ,oReplaceString As String ,SrchAttributes,ReplAttributes, searchStyles)
Dim oReplace As Object
oReplace = ThisComponent.createReplaceDescriptor()
oReplace.SearchString = SearchString
oReplace.ReplaceString = oReplaceString
oReplace.SearchRegularExpression=True
oReplace.SearchCaseSensitive = True
oReplace.searchAll=True
If Not IsEmpty(SrchAttributes(0).Value) Then
oReplace.SetSearchAttributes(SrchAttributes())
oReplace.searchStyles = searchStyles
End If
If Not IsEmpty(ReplAttributes(0).Value) Then
oReplace.SetReplaceAttributes(ReplAttributes())
End If
ThisComponent.replaceAll(oReplace)
End Sub
Private Function getStyleNames(oFamily,bLocalized as Boolean, optional bUsed, optional bUserDef)
Dim oStyle As Object
Dim i As Long
Dim sNames() As Variant
Dim sName As String
Dim chkUse as Boolean
Dim chkUDef as Boolean
For i = 0 to oFamily.getCount -1
oStyle = oFamily.getByIndex(i)
If bLocalized then
sName = oStyle.DisplayName
Else
sName = oStyle.getName
Endif
If (vartype(bUsed) = 11)then
chkUse = (bUsed EQV oStyle.isInUse)
Else
chkUse = True
Endif
If (vartype(bUserDef) = 11) then
chkUDef = (bUserDef EQV oStyle.isUserDefined)
Else
chkUDef = True
EndIf
If sName = &quot;Автор&quot; Or sName = &quot;Автор по-английски&quot; Or sName = &quot;Ключевые слова&quot; Or sName = &quot;Текст списка литературы&quot; Or sName = &quot;Эпиграф&quot; or sName = &quot;Цитирование&quot; or sName = &quot;Сведения об авторе&quot; or sName = &quot;Аннотация&quot; Then
chkUse = False
Endif
If chkUse AND chkUDef then
bas_Pusharray sNames(),sName
Endif
Next
getStyleNames = sNames()
End Function
Sub bas_PushArray(xArray(),vNextElement)
Dim iUB As Long
Dim iLB As Long
iLB = lBound(xArray())
iUB = uBound(xArray())
If iLB &gt; iUB then
iUB = iLB
redim xArray(iLB To iUB)
Else
iUB = iUB +1
redim preserve xArray(iLB To iUB)
Endif
xArray(iUB) = vNextElement
End Sub
Private Sub replaceWhiteBackgroundWithTransparent
Dim description As String
Dim searchPattern As String
Dim SrchAttributes(1) as new com.sun.star.beans.PropertyValue
Dim ReplAttributes(1) as new com.sun.star.beans.PropertyValue
Dim statusIndicator As Object
searchPattern = &quot;&quot;
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(&quot;Замена белого фона на прозрачный начата&quot;,100)
SrchAttributes(0).Name = &quot;CharBackTransparent&quot;
SrchAttributes(0).Value = False
SrchAttributes(1).Name = &quot;CharBackColor&quot;
SrchAttributes(1).Value = 16777215
ReplAttributes(0).Name = &quot;CharBackTransparent&quot;
ReplAttributes(0).Value = True
ReplAttributes(1).Name = &quot;CharBackColor&quot;
ReplAttributes(1).Value = -1
setAttributesBySearchPattern(searchPattern,ReplAttributes,SrchAttributes)
statusIndicator.end()
End Sub
Sub convertSymbol
Dim newFontName As String
Dim oSearchString As String
Dim oReplaceString As String
&apos;newFontName = &quot;IPH Astra Serif&quot;
Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
Dim ReplAttributes(0) as new com.sun.star.beans.PropertyValue
SrchAttributes(0).Name = &quot;CharFontName&quot;
SrchAttributes(0).Value = &quot;Symbol&quot;
ReplAttributes(0).Name = &quot;CharFontName&quot;
ReplAttributes(0).Value = &quot;Noto Serif CJK JP&quot;
oSearchString = &quot;\uF0DE&quot;
oReplaceString = &quot;&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
oSearchString = &quot;\uF0DB&quot;
oReplaceString = &quot;&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;replaceFontsInStyles( &quot;WL LatinAllIn1Goth&quot;, newFontName)
End Sub
Private Sub convertWLLatin2IPHAstra
Dim newFontName As String
Dim oSearchString As String
Dim oReplaceString As String
&apos;newFontName = &quot;IPH Astra Serif&quot;
Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
Dim ReplAttributes(0) as new com.sun.star.beans.PropertyValue
SrchAttributes(0).Name = &quot;CharFontName&quot;
&apos;SrchAttributes(0).Value = &quot;WL LatinAllIn1Goth&quot;
ReplAttributes(0).Name = &quot;CharFontName&quot;
&apos;ReplAttributes(0).Value = newFontName
SrchAttributes(0).Value = Empty
ReplAttributes(0).Value = Empty
&apos;Replace macron below
oSearchString = &quot;(.)(\uF0D4)+&quot;
oReplaceString = &quot;$1̱&quot;
&apos;from WL
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
oSearchString = &quot;(.)\u0331&quot;
&apos;from unicode to remove direct formatting
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;Replace dot below
oSearchString = &quot;(.)(\uF0D6)+&quot;
oReplaceString = &quot;$1̣&quot;
&apos;from WL
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;from unicode to remove direct formatting
oSearchString = &quot;(.)\u0323&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;replace macron
oSearchString = &quot;(.)(\uF0F4)+&quot;
oReplaceString = &quot;$1̄&quot;
&apos;from WL
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;from unicode to remove direct formatting
oSearchString = &quot;(.)\u0304&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;replace space
oSearchString = &quot;\uF020&quot;
oReplaceString = &quot; &quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;replace comma
oSearchString = &quot;\uF02C&quot;
oReplaceString = &quot;,&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;replace accent
oSearchString = &quot;(.)(\uF0F1)+&quot;
oReplaceString = &quot;$1́&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
&apos;from unicode to remove direct formatting
oSearchString = &quot;(.)\u0341&quot;
ReplaceFormatting(oSearchString,oReplaceString,SrchAttributes,ReplAttributes, false)
replaceFontsInStyles( &quot;WL LatinAllIn1Goth&quot;, newFontName)
End Sub
Function getVersion As String
GlobalScope.BasicLibraries.LoadLibrary(&quot;Tools&quot;)
Dim oProduct As Object
oProduct=GetRegistryKeyContent(&quot;org.openoffice.Setup/Product&quot;)
getVersion=oProduct.getByName(&quot;ooSetupVersion&quot;)
End Function
Function getFullVersion As String
GlobalScope.BasicLibraries.LoadLibrary(&quot;Tools&quot;)
Dim oProduct As Object
oProduct=GetRegistryKeyContent(&quot;org.openoffice.Setup/Product&quot;)
getFullVersion=oProduct.getByName(&quot;ooSetupVersionAboutBox&quot;)
End Function
Private Sub convertFormatToUserFields(identifier As String, styleNames, styleValues)
Dim maxLength As Integer
maxLength = getMaxLength(identifier)
Dim leftField As String
Dim rightField As String
Dim i As Integer
Dim found As Object
leftField = &quot;left&quot; &amp; identifier
rightField = &quot;right&quot; &amp; identifier
Dim SrchAttributes(Ubound(styleNames)) as new com.sun.star.beans.PropertyValue
For i = Lbound(styleNames) To Ubound(styleNames)
SrchAttributes(i).Name = styleNames(i)
Next i
For i = Lbound(styleValues) To Ubound(styleValues)
SrchAttributes(i).Value = styleValues(i)
Next i
SDesc = Thiscomponent.createSearchDescriptor()
SDesc.SearchAll = true
SDesc.SearchRegularExpression = true
SDesc.SearchString = &quot;&quot;
SDesc.searchStyles = true
SDesc.SetSearchAttributes(SrchAttributes)
found = Thiscomponent.findFirst(SDesc)
i = 0
Do While not isNull(found)
If Len(found.String) &lt;&gt; 0 AND NOT IsNull(found.Text) Then
If maxLength &lt; 0 Or Len(found.String) &lt; maxLength Then
insertUserField(found.End,rightField &amp; i,&quot;&quot;)
insertUserField(found.start,leftField &amp; i,&quot;&quot;)
i = i + 1
EndIf
EndIf
found = Thiscomponent.findNext(found.End, SDesc)
Loop
End Sub
Function getMaxLength(identifier As String) As Integer
Dim config As Object
config = initRedactionConfiguration()
If identifier = &quot;SubScript&quot; Then
getMaxLength = CInt(config.getPropertyValue(&quot;subscript_max_length&quot;))
Exit Function
EndIf
If identifier = &quot;SuperScript&quot; Then
getMaxLength = CInt(config.getPropertyValue(&quot;superscript_max_length&quot;))
Exit Function
EndIf
getMaxLength = -1
End Function
Private Sub convertUserFieldsToFormat(identifier As String, styleNames , styleValues)
Dim oTextCursor As Object
Dim oMasters As Object
Dim endTextRange As Object
Dim leftFieldName As String
Dim rightFieldName As String
Dim leftFieldMaster As Object
Dim rightFieldMaster As Object
Dim leftField As Object
Dim rightField As Object
Dim leftAnchor As Object
Dim rightAnchor As Object
Dim i As Integer
oMasters = ThisComponent.getTextFieldMasters()
i = 0
Do
leftFieldName = &quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; &quot;left&quot; &amp; identifier &amp; i
rightFieldName = &quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; &quot;right&quot; &amp; identifier &amp; i
If oMasters.hasByName(leftFieldName) AND oMasters.hasByName(rightFieldName) Then
i=i+1
leftFieldMaster = oMasters.getByName(leftFieldName)
leftField = leftFieldMaster.DependentTextFields(0)
leftAnchor = leftField.getAnchor()
rightFieldMaster = oMasters.getByName(rightFieldName)
rightField = rightFieldMaster.DependentTextFields(0)
rightAnchor = rightField.getAnchor()
oTextCursor = leftAnchor.Text.createTextCursor()
oTextCursor.goToRange(leftAnchor.Start, false)
oTextCursor.goToRange(rightAnchor.End, true)
oTextCursor.setPropertyValues(styleNames, styleValues)
leftField.dispose()
leftFieldMaster.dispose()
rightField.dispose()
rightFieldMaster.dispose()
Else
Exit sub
EndIf
Loop
End Sub
Private Sub formatToUserFieldsBold
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharWeight&quot;)
styleValues = Array(com.sun.star.awt.FontWeight.BOLD)
convertFormatToUserFields(&quot;Bold&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatBold
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharWeight&quot;)
styleValues = Array(com.sun.star.awt.FontWeight.BOLD)
convertUserFieldsToFormat(&quot;Bold&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsItalic
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharPosture&quot;)
styleValues = Array(com.sun.star.awt.FontSlant.ITALIC)
convertFormatToUserFields(&quot;Italic&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatItalic
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharPosture&quot;)
styleValues = Array(com.sun.star.awt.FontSlant.ITALIC)
convertUserFieldsToFormat(&quot;Italic&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsStrikeout
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharStrikeout&quot;)
styleValues = Array(com.sun.star.awt.FontStrikeout.SINGLE)
convertFormatToUserFields(&quot;StrikeOut&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatStrikeout
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharStrikeout&quot;)
styleValues = Array(com.sun.star.awt.FontStrikeout.SINGLE)
convertUserFieldsToFormat(&quot;StrikeOut&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsUnderline
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharUnderline&quot;)
styleValues = Array(com.sun.star.awt.FontUnderline.SINGLE)
convertFormatToUserFields(&quot;UnderLine&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatUnderline
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharUnderline&quot;)
styleValues = Array(com.sun.star.awt.FontUnderline.SINGLE)
convertUserFieldsToFormat(&quot;UnderLine&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsSuperscript
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,14000)
convertFormatToUserFields(&quot;SuperScript&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatSuperscript
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,14000)
convertUserFieldsToFormat(&quot;SuperScript&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsSubscript
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-14000)
convertFormatToUserFields(&quot;SubScript&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatSubscript
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-14000)
convertUserFieldsToFormat(&quot;SubScript&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsSuperscriptOld
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,101)
convertFormatToUserFields(&quot;SuperScript&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatSuperscriptOld
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,101)
convertUserFieldsToFormat(&quot;SuperScript&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsSubscriptOld
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-101)
convertFormatToUserFields(&quot;SubScript&quot;, styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatSubscriptOld
Dim styleValues(1) As Integer
Dim styleNames(1) As String
styleNames = Array(&quot;CharEscapementHeight&quot;,&quot;CharEscapement&quot;)
styleValues = Array(58,-101)
convertUserFieldsToFormat(&quot;SubScript&quot;, styleNames, styleValues)
End Sub
Private Sub formatToUserFieldsSparce
Dim i As Integer
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharKerning&quot;)
i = 18
styleValues = Array(i)
convertFormatToUserFields(i &amp; &quot;Kerning&quot; , styleNames, styleValues)
i = 35
styleValues = Array(i)
convertFormatToUserFields(i &amp; &quot;Kerning&quot; , styleNames, styleValues)
i = 53
styleValues = Array(i)
convertFormatToUserFields(i &amp; &quot;Kerning&quot; , styleNames, styleValues)
i = 70
styleValues = Array(i)
convertFormatToUserFields(i &amp; &quot;Kerning&quot; , styleNames, styleValues)
End Sub
Private Sub userFieldsToFormatSparce
Dim i As Integer
Dim styleValues(0) As Integer
Dim styleNames(0) As String
styleNames = Array(&quot;CharKerning&quot;)
i = 18
styleValues = Array(i)
convertUserFieldsToFormat(i &amp; &quot;Kerning&quot;, styleNames, styleValues)
i = 35
styleValues = Array(i)
convertUserFieldsToFormat(i &amp; &quot;Kerning&quot;, styleNames, styleValues)
i = 53
styleValues = Array(i)
convertUserFieldsToFormat(i &amp; &quot;Kerning&quot;, styleNames, styleValues)
i = 70
styleValues = Array(i)
convertUserFieldsToFormat(i &amp; &quot;Kerning&quot;, styleNames, styleValues)
End Sub
Private Sub convertFormattingToText
Dim version As String
Dim smallNum As String
Dim bigNum As String
version = Trim(getVersion())
bigNum = Left(version, 1)
smallNum = Right(version, 1)
toTextBold()
toTextItalic()
toTextStrikeout()
toTextUnderline()
If CInt(bigNum) &lt; 6 OR (CInt(bigNum) = 6 AND CInt(smallNum &lt; 3) ) Then
toTextSuperscriptOld()
toTextSubscriptOld()
Else
toTextSuperscript()
toTextSubscript()
EndIf
toTextSparce()
End Sub
Private Sub convertFormattingToUserFields
Dim version As String
Dim smallNum As String
Dim bigNum As String
version = Trim(getVersion())
bigNum = Left(version, 1)
smallNum = Right(version, 1)
formatToUserFieldsBold
formatToUserFieldsItalic
formatToUserFieldsStrikeout
formatToUserFieldsUnderline
If CInt(bigNum) &lt; 6 OR (CInt(bigNum) = 6 AND CInt(smallNum &lt; 3) ) Then
formatToUserFieldsSuperscriptOld
formatToUserFieldsSubscriptOld
Else
formatToUserFieldsSuperscript
formatToUserFieldsSubscript
EndIf
formatToUserFieldsSparce
End Sub
Private Sub convertFormattingFromText
Dim version As String
version = Trim(getVersion())
Dim smallNum As String
Dim bigNum As String
version = Trim(getVersion())
bigNum = Left(version, 1)
smallNum = Right(version, 1)
fromTextSparce()
If CInt(bigNum) &lt; 6 OR (CInt(bigNum) = 6 AND CInt(smallNum &lt; 3) ) Then
fromTextSuperscriptOld()
fromTextSubscriptOld()
Else
fromTextSuperscript()
fromTextSubscript()
EndIf
fromTextUnderline()
fromTextStrikeout()
fromTextItalic()
fromTextBold()
End Sub
Private Sub convertUserFieldsToFormatting
Dim version As String
version = Trim(getVersion())
Dim smallNum As String
Dim bigNum As String
version = Trim(getVersion())
bigNum = Left(version, 1)
smallNum = Right(version, 1)
userFieldsToFormatSparce
If CInt(bigNum) &lt; 6 OR (CInt(bigNum) = 6 AND CInt(smallNum &lt; 3) ) Then
userFieldsToFormatSuperscriptOld
userFieldsToFormatSubscriptOld
Else
userFieldsToFormatSuperscript
userFieldsToFormatSubscript
EndIf
userFieldsToFormatUnderline
userFieldsToFormatStrikeout
userFieldsToFormatItalic
userFieldsToFormatBold
End Sub
Private Function insertUserField(cursor As Object,fieldName As String,fieldValue As String)
Dim oField As Object &apos;Field to insert
Dim oFieldMaster As Object
Dim oMasters As Object
oField = ThisComponent.createInstance(&quot;com.sun.star.text.textfield.User&quot;)
oMasters = ThisComponent.getTextFieldMasters()
If oMasters.hasByName(&quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; fieldName) Then
oFieldMaster = oMasters.getByName(&quot;com.sun.star.text.FieldMaster.User&quot; &amp; &quot;.&quot; &amp; fieldName)
oFieldMaster.Name = fieldName
oFieldMaster.Content = fieldValue
Else
oFieldMaster = ThisComponent.createInstance(&quot;com.sun.star.text.FieldMaster.User&quot;)
oFieldMaster.Name = fieldName
oFieldMaster.Content = fieldValue
EndIf
oField.attachTextFieldMaster(oFieldMaster)
cursor.Text.insertTextContent(cursor, oField, False)
oField.IsVisible = false
End Function
sub saveAsDocAndBackToODT
dim document as object
dim dispatcher as object
Dim path As String
Dim tmpName As String
Dim oldName As String
&apos;Dim timeOut As Long
&apos;timeOut = 0
&apos;DocumentLoaded = false
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oldName = ThisComponent.getURL()
tmpName = oldName &amp; &quot;--tmp&quot; &amp; &quot;.doc&quot;
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;URL&quot;
args1(0).Value = tmpName
args1(1).Name = &quot;FilterName&quot;
args1(1).Value = &quot;MS Word 97&quot;
dispatcher.executeDispatch(document, &quot;.uno:SaveAs&quot;, &quot;&quot;, 0, args1())
dispatcher.executeDispatch(document, &quot;.uno:Reload&quot;, &quot;&quot;, 0, Array())
args1(0).Value = oldName
args1(1).Value = &quot;writer8&quot;
dispatcher.executeDispatch(document, &quot;.uno:SaveAs&quot;, &quot;&quot;, 0, args1())
dispatcher.executeDispatch(document, &quot;.uno:Reload&quot;, &quot;&quot;, 0, Array())
&apos;RegisterListener (ThisComponent)
&apos;Do while DocumentLoaded = false
&apos; Wait 300
&apos; timeOut = timeOut + 300
&apos; If timeOut &gt; 30000 Then
&apos; MsgBox &quot;Time out&quot;
&apos; Exit sub
&apos; EndIf
&apos;Loop
&apos;DocumentLoaded = false
If FileExists(tmpName) Then
Kill(tmpName)
End If
end Sub
Sub addTimeStampToProperties
Dim docProps As Object
Dim userProps As Object
Dim curTime As String
On Error Goto exceptionHandlerProps
curTime = Now()
docProps = ThisComponent.getDocumentProperties()
userProps = docProps.UserDefinedProperties()
userProps.addProperty(curTime ,128,&quot;Cleaned by&quot; &amp; getUserName() &amp; &quot; with &quot; &amp; redactionExtensionVersion &amp; &quot; LO &quot; &amp; getFullVersion() )
exceptionHandlerProps:
Resume Next
End Sub
Function getUserName() As String
Dim oCP As Object
Dim oCUA As Object
Dim aProps(0) As New com.sun.star.beans.PropertyValue
oCP = GetProcessServiceManager().createInstance( &quot;com.sun.star.configuration.ConfigurationProvider&quot; )
aProps(0).Name = &quot;nodepath&quot;
aProps(0).Value = &quot;/org.openoffice.UserProfile/Data&quot;
oCUA = oCP.createInstanceWithArguments( &quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;, aProps )
getUserName = &quot; &quot; &amp; oCUA.getByName(&quot;givenname&quot;) &amp; &quot; &quot; &amp; oCUA.getByName(&quot;sn&quot;)
End Function
sub saveCleanedVersion(comment)
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;VersionComment&quot;
args1(0).Value = comment
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, args1())
end Sub
Sub resetChapterNumberingRules
Dim chapNumRules As Object
Dim numRulesProps As Variant
Dim numRuleProperty As Variant
Dim i As Integer
chapNumRules = ThisComponent.ChapterNumberingRules
For i = 0 To chapNumRules.Count - 1
numRulesProps = chapNumRules.getByIndex(i)
For n = LBound(numRulesProps) To UBound(numRulesProps)
numRuleProperty = numRulesProps(n)
If (numRuleProperty.Name = &quot;Prefix&quot;) Then
numRuleProperty.Value = &quot;&quot;
End If
If (numRuleProperty.Name = &quot;Suffix&quot;) Then
numRuleProperty.Value = &quot;&quot;
End If
If (numRuleProperty.Name = &quot;CharStyleName&quot;) Then
numRuleProperty.Value = &quot;Standard&quot;
End If
numRulesProps(n) = numRuleProperty
Next n
chapNumRules.replaceByIndex(i,numRulesProps)
Next i
End Sub
Private Sub replaceNumHyphen
StartTracking
replaceNumHyphenRegExp
StopTracking
End Sub
Sub replaceNumHyphenRegExp
AskAndReplace(&quot;(?&lt;!DOI[0-9. /XVI:-‒–—−-]{1,50})(?&lt;=[:digit:])(?:[:space:])?[-‒–—−](?:[:space:])?(?=[:digit:])&quot;,&quot;&quot;)
End sub
Sub fixBrokenCharBackTransparent
Dim footNotes As Object
Dim endNotes As Object
Dim i As Integer
Dim oStyles As Object
Dim pageStyles As Object
Dim pageStyle As Object
footNotes = thisComponent.footNotes
For i = 0 to footNotes.Count -1
setDefaultBackColorInText(footNotes.getByIndex(i).Text)
Next i
endNotes = thisComponent.footNotes
For i = 0 to footNotes.Count -1
setDefaultBackColorInText(endNotes.getByIndex(i).Text)
Next i
oStyles = ThisComponent.StyleFamilies
pageStyles = oStyles.getByName(oStyles.elementNames(2))
For i = 0 to pageStyles.Count -1
pageStyle = pageStyles.getByIndex(i)
If Not IsEmpty(pageStyle.FooterText) Then
setDefaultBackColorInText(pageStyle.FooterText)
EndIf
If Not IsEmpty(pageStyle.FooterTextFirst) Then
setDefaultBackColorInText(pageStyle.FooterTextFirst)
EndIf
If Not IsEmpty(pageStyle.FooterTextRight) Then
setDefaultBackColorInText(pageStyle.FooterTextRight)
EndIf
If Not IsEmpty(pageStyle.FooterTextLeft) Then
setDefaultBackColorInText(pageStyle.FooterTextLeft)
EndIf
If Not IsEmpty(pageStyle.HeaderText) Then
setDefaultBackColorInText(pageStyle.HeaderText)
EndIf
If Not IsEmpty(pageStyle.HeaderTextFirst) Then
setDefaultBackColorInText(pageStyle.HeaderTextFirst)
EndIf
If Not IsEmpty(pageStyle.HeaderTextRight) Then
setDefaultBackColorInText(pageStyle.HeaderTextRight)
EndIf
If Not IsEmpty(pageStyle.HeaderTextLeft) Then
setDefaultBackColorInText(pageStyle.HeaderTextLeft)
EndIf
Next i
setDefaultBackColorInText(ThisComponent.Text)
End Sub
Sub setDefaultBackColorInText(oText As Object)
If IsMissing(oText) Then
Exit sub
End If
Dim enum1Element As Object
Dim enum1 As Object
Dim enum2 As Object
Dim thisPortion As Object
Dim footnoteText As Object
Dim label As String
Dim labelNum As Integer
Dim i As Integer
Dim count As Integer
Dim cell As Object
Dim cellText As Object
enum1 = oText.Text.createEnumeration
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
If enum1Element.CharBackTransparent = false Then
enum1Element.setPropertyToDefault(&quot;CharBackTransparent&quot;)
EndIf
ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
cellNames = enum1Element.cellNames
For i = LBound(cellNames) To Ubound(cellNames)
cell = enum1Element.getCellByName(cellNames(i))
cellText = cell.getText()
setDefaultBackColorInText(cellText)
Next i
EndIf
Wend
End Sub
Function fixColoredBackgroundInDoc() As Boolean
Dim founds As Object
Dim sDesc As Object
Dim i As Long
Dim foundObjects() As Object
Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
SrchAttributes(0).Name = &quot;CharBackTransparent&quot;
SrchAttributes(0).Value = False
sDesc = Thiscomponent.createSearchDescriptor()
sDesc.SearchAll = true
sDesc.ValueSearch = false
sDesc.SearchRegularExpression = true
sDesc.searchStyles = true
sDesc.SetSearchAttributes(SrchAttributes())
founds = Thiscomponent.findAll(sDesc)
If founds.count &lt;&gt; 0 Then
foundObjects = convertXIndexAccessToArray(founds)
For i = LBound(foundObjects) To UBound(foundObjects)
foundObjects(i).CharBackTransparent = false
foundObjects(i).CharBackColor = -1
Next i
EndIf
End Function
Sub fixDiacriticKerning
Dim oSearch As Object
Dim oFound As Object
Dim oPara As Object
turnOffTracking()
oSearch = ThisComponent.createSearchDescriptor()
oSearch.SearchString = &quot;[\u0300-\u036F]&quot;
oSearch.SearchRegularExpression=True
oSearch.searchAll=True
oFound = ThisComponent.findFirst(oSearch)
Do While Not IsNull(oFound)
oPara = oFound.TextParagraph
fixDiacriticKerningInPara(oPara)
oFound = ThisComponent.findNext(oFound.End, oSearch)
Loop
End Sub
Sub fixDiacriticKerningInPara(oPara As Object)
Dim paraEnum As Object
Dim portion As Object
Dim prevPortion As Object
paraEnum = oPara.createEnumeration
If paraEnum.hasMoreElements Then
prevPortion = paraEnum.nextElement
While paraEnum.hasMoreElements
portion = paraEnum.nextElement
While isFirstCharDiacritic(portion)
moveFirstCharacter(portion, prevPortion)
Wend
prevPortion = portion
Wend
EndIf
End Sub
Function isFirstCharDiacritic(portion As Object) As Boolean
isFirstCharDiacritic = false
Dim portionText As String
Dim diaLowBound As Long
Dim diaHighBound As Long
Dim charNum As Long
diaLowBound = 768
diaHighBound = 879
portionText = portion.String
If Len(portionText) = 0 Then
Exit Function
EndIf
charNum = Asc(portionText)
If charNum &gt;= diaLowBound And charNum &lt;= diaHighBound Then
isFirstCharDiacritic = true
EndIf
End Function
Sub moveFirstCharacter(portion As Object, prevPortion As Object)
prevPortion.String = prevPortion.String &amp; Left(portion.String,1)
portion.String = Right(portion.String,Len(portion.String) - 1)
End Sub
</script:module>