Added check and clean strategy for broken paragraph setting charBackTransparent

This commit is contained in:
Georgy Litvinov 2021-06-06 13:15:27 +02:00
parent 07ae3e7d9c
commit 7c5aadcaad
6 changed files with 250 additions and 10 deletions

View file

@ -1,6 +1,6 @@
<?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 mark81
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Clean" script:language="StarBasic">Sub mark82
End Sub
@ -45,6 +45,7 @@ Private Sub makerUpMenu
dialog.getControl(&quot;removeBasic&quot;).Label = getTranslation(&quot;advancedMenuRemoveBasic&quot;)
dialog.getControl(&quot;resetChapterNumberingRules&quot;).Label = getTranslation(&quot;advancedMenuResetChapterNumberingRules&quot;)
dialog.getControl(&quot;convertFontsToCharStyles&quot;).Label = getTranslation(&quot;advancedMenuconvertFontsToCharStyles&quot;)
dialog.getControl(&quot;fixBrokenCharBackTransparent&quot;).Label = getTranslation(&quot;fixBrokenCharBackTransparentMenuItem&quot;)
dialog.getControl(&quot;Cancel&quot;).Label = getTranslation(&quot;buttonCancel&quot;)
dialog.getControl(&quot;OK&quot;).Label = getTranslation(&quot;buttonOK&quot;)
dialog.getControl(&quot;buttonLoad&quot;).Label = getTranslation(&quot;buttonLoad&quot;)
@ -152,6 +153,10 @@ Private Sub cleanAccordingTo(dialog As Object)
If dialog.getControl(&quot;convertFontsToCharStyles&quot;).state = 1 Then
convertFontsToCharStyles()
EndIf
If dialog.getControl(&quot;fixBrokenCharBackTransparent&quot;).state = 1 Then
fixBrokenCharBackTransparent()
EndIf
statusIndicator.end()
saveAndreload()
@ -1982,4 +1987,84 @@ Sub replaceNumHyphenRegExp
AskAndReplace(&quot;(?&lt;!DOI[0-9. /XVI:-‒–—−-]{1,50})(?&lt;=[:digit:])(?:[:space:])?[-‒–—−](?:[:space:])?(?=[:digit:])&quot;,&quot;&quot;)
End sub
Sub fixBrokenCharBackTransparent
Dim foonNotes 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
</script:module>

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="CleaningDialog" dlg:left="107" dlg:top="22" dlg:width="237" dlg:height="230" dlg:help-text="&amp;21.CleaningDialog.HelpText" dlg:closeable="true" dlg:moveable="true" dlg:title="&amp;22.CleaningDialog.Title">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="CleaningDialog" dlg:left="107" dlg:top="22" dlg:width="237" dlg:height="247" dlg:help-text="&amp;21.CleaningDialog.HelpText" dlg:closeable="true" dlg:moveable="true" dlg:title="&amp;22.CleaningDialog.Title">
<dlg:bulletinboard>
<dlg:button dlg:id="Cancel" dlg:tab-index="0" dlg:left="28" dlg:top="215" dlg:width="40" dlg:height="12" dlg:value="Отмена" dlg:button-type="cancel"/>
<dlg:button dlg:id="Cancel" dlg:tab-index="0" dlg:left="28" dlg:top="232" dlg:width="40" dlg:height="12" dlg:value="Отмена" dlg:button-type="cancel"/>
<dlg:button dlg:id="CommandButton1" dlg:tab-index="1" dlg:left="24" dlg:top="170" dlg:width="2" dlg:height="0" dlg:value="CommandButton1"/>
<dlg:button dlg:id="OK" dlg:tab-index="2" dlg:left="92" dlg:top="215" dlg:width="40" dlg:height="12" dlg:value="OK" dlg:button-type="ok"/>
<dlg:button dlg:id="OK" dlg:tab-index="2" dlg:left="92" dlg:top="232" dlg:width="40" dlg:height="12" dlg:value="OK" dlg:button-type="ok"/>
<dlg:checkbox dlg:id="fontsInStyles" dlg:tab-index="3" dlg:left="11" dlg:top="10" dlg:width="218" dlg:height="7" dlg:value="Заменить названия шрифтов в стилях" dlg:checked="false"/>
<dlg:checkbox dlg:id="removeLinks" dlg:tab-index="6" dlg:left="11" dlg:top="50" dlg:width="218" dlg:height="7" dlg:value="Удалить гиперссылки" dlg:checked="false"/>
<dlg:checkbox dlg:id="cleanFormatting" dlg:tab-index="5" dlg:left="11" dlg:top="30" dlg:width="218" dlg:height="7" dlg:value="Очистить форматирование" dlg:checked="false"/>
@ -20,7 +20,7 @@
<dlg:checkbox dlg:id="removeManualPageBreaks" dlg:tab-index="15" dlg:left="11" dlg:top="150" dlg:width="218" dlg:height="7" dlg:value="Удалить все разрывы страниц" dlg:checked="false"/>
<dlg:checkbox dlg:id="replaceWhiteBackground" dlg:tab-index="16" dlg:left="11" dlg:top="40" dlg:width="218" dlg:height="7" dlg:value="Заменить белый фон символов на прозрачный" dlg:checked="false"/>
<dlg:checkbox dlg:id="removeBasic" dlg:tab-index="17" dlg:left="11" dlg:top="160" dlg:width="218" dlg:height="7" dlg:value="Удалить макросы" dlg:checked="false"/>
<dlg:button dlg:id="buttonLoad" dlg:tab-index="18" dlg:left="158" dlg:top="215" dlg:width="52" dlg:height="12" dlg:value="loadTemplate">
<dlg:button dlg:id="buttonLoad" dlg:tab-index="18" dlg:left="158" dlg:top="232" dlg:width="52" dlg:height="12" dlg:value="loadTemplate">
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:Redaction.Configuration.setDeafultTemplate?language=Basic&amp;location=application" script:language="Script"/>
</dlg:button>
<dlg:checkbox dlg:id="removeAllFields" dlg:tab-index="19" dlg:left="11" dlg:top="170" dlg:width="218" dlg:height="7" dlg:value="Удалить все поля" dlg:checked="false"/>
@ -28,5 +28,6 @@
<dlg:checkbox dlg:id="resetChapterNumberingRules" dlg:tab-index="21" dlg:left="11" dlg:top="180" dlg:width="218" dlg:height="7" dlg:value="Сбросить настройки нумерации глав" dlg:checked="false"/>
<dlg:checkbox dlg:id="replaceNumHyphen" dlg:tab-index="22" dlg:left="11" dlg:top="190" dlg:width="218" dlg:height="7" dlg:value="Исправить тире между цифрами" dlg:checked="false"/>
<dlg:checkbox dlg:id="convertFontsToCharStyles" dlg:tab-index="23" dlg:left="11" dlg:top="200" dlg:width="218" dlg:height="7" dlg:value="Конвертировать шрифты в стили символов" dlg:checked="false"/>
<dlg:checkbox dlg:id="fixBrokenCharBackTransparent" dlg:tab-index="24" dlg:left="11" dlg:top="210" dlg:width="218" dlg:height="7" dlg:value="fixBrokenCharBackTransparent" dlg:checked="false"/>
</dlg:bulletinboard>
</dlg:window>

View file

@ -298,6 +298,12 @@ Function getRussian(identifier As String) As String
Exit Function
Case &quot;foundColoredTextMessage&quot;
getRussian = &quot;Найден текст c непрозрачным фоном. Обычно это не подходит для электронных публикаций. Вместо белого цвета фона используйте «Без заливки»&quot;
Exit Function
Case &quot;invalidParagraphFormattingFound&quot;
getRussian = &quot;Найдены некорректные настройки форматирования параграфов. Необходима чистка.&quot;
Exit Function
Case &quot;fixBrokenCharBackTransparentMenuItem&quot;
getRussian = &quot;Исправить некорректные настройки цветовой заливки абзацев&quot;
Exit Function
Case Else
getRussian = &quot;Перевод не найден&quot;
@ -579,6 +585,12 @@ Function getEnglish(identifier As String) As String
Exit Function
Case &quot;foundColoredTextMessage&quot;
getEnglish = &quot;Found text with an opaque background. This is usually not suitable for electronic publishing. Use „No Fill“ instead of a white background &quot;
Exit Function
Case &quot;invalidParagraphFormattingFound&quot;
getEnglish = &quot;Incorrect paragraph formatting settings found. Cleaning required. &quot;
Exit Function
Case &quot;fixBrokenCharBackTransparentMenuItem&quot;
getEnglish = &quot;Fix incorrect color fill settings for paragraphs &quot;
Exit Function
Case Else
getEnglish = &quot;No translation&quot;
@ -860,6 +872,12 @@ Function getCroatian(identifier As String) As String
Case &quot;foundColoredTextMessage&quot;
getCroatian = &quot;Pronađen tekst s neprozirnom pozadinom. To obično nije prikladno za elektroničko izdavanje. Upotrijebite „Bez popunjavanja“ umjesto bijele pozadine &quot;
Exit Function
Case &quot;invalidParagraphFormattingFound&quot;
getCroatian = &quot;Pronađene su pogrešne postavke oblikovanja odlomaka. Potrebno čišćenje. &quot;
Exit Function
Case &quot;fixBrokenCharBackTransparentMenuItem&quot;
getCroatian = &quot;Ispravite netočne postavke ispunjavanja boja za odlomke &quot;
Exit Function
Case Else
getCroatian = &quot;No translation&quot;
End Select
@ -1140,6 +1158,12 @@ Function getSerbian(identifier As String) As String
Case &quot;foundColoredTextMessage&quot;
getSerbian = &quot;Пронађен је текст са непрозирном позадином. Ово обично није погодно за електронско издавање. Користите „Без попуњавања“ уместо беле позадине &quot;
Exit Function
Case &quot;invalidParagraphFormattingFound&quot;
getSerbian = &quot;Пронађене су нетачне поставке форматирања пасуса. Потребно чишћење. &quot;
Exit Function
Case &quot;fixBrokenCharBackTransparentMenuItem&quot;
getSerbian = &quot;Исправите нетачна подешавања попуњавања боја за пасусе &quot;
Exit Function
Case Else
getSerbian = &quot;No translation&quot;
End Select
@ -1420,6 +1444,12 @@ Function getBosnian(identifier As String) As String
Case &quot;foundColoredTextMessage&quot;
getBosnian = &quot;Pronađen tekst s neprozirnom pozadinom. To obično nije prikladno za elektroničko izdavanje. Upotrijebite „Bez popunjavanja“ umjesto bijele pozadine &quot;
Exit Function
Case &quot;invalidParagraphFormattingFound&quot;
getBosnian = &quot;Pronađene su pogrešne postavke oblikovanja odlomaka. Potrebno čišćenje. &quot;
Exit Function
Case &quot;fixBrokenCharBackTransparentMenuItem&quot;
getBosnian = &quot;Ispravite netočne postavke ispunjavanja boja za odlomke &quot;
Exit Function
Case Else
getBosnian = &quot;No translation&quot;
End Select

View file

@ -35,6 +35,7 @@ Sub validateButton
Dim needExtendedInfo As Boolean
Dim config As Object
Dim needFixColoredText As Boolean
Dim brokenCharBackTransparent As Boolean
config = initRedactionConfiguration()
Dim statusIndicator as Object
@ -84,11 +85,15 @@ Sub validateButton
needExtendedInfo = false
EndIf
brokenCharBackTransparent = hasbrokenCharBackTransparent
If (brokenCharBackTransparent) Then
MsgBox getTranslation(&quot;invalidParagraphFormattingFound&quot;)
EndIf
needFixColoredText = findColoredBackgroundInDoc
numberingsErros = printNumberingSymbols(needExtendedInfo)
statusIndicator.setValue(80)
If needFixColoredText OR numberingsErros OR badText OR badNumberings OR footnotesReport &lt;&gt; &quot;&quot; OR graphicsReport &lt;&gt; &quot;&quot; Or outlineInNotesReport &lt;&gt; &quot;&quot; Or sectionsReport &lt;&gt; &quot;&quot; OR oulineInTablesReport &lt;&gt; &quot;&quot; OR outlinePageStylesReport &lt;&gt; &quot;&quot; Then
If brokenCharBackTransparent OR needFixColoredText OR numberingsErros OR badText OR badNumberings OR footnotesReport &lt;&gt; &quot;&quot; OR graphicsReport &lt;&gt; &quot;&quot; Or outlineInNotesReport &lt;&gt; &quot;&quot; Or sectionsReport &lt;&gt; &quot;&quot; OR oulineInTablesReport &lt;&gt; &quot;&quot; OR outlinePageStylesReport &lt;&gt; &quot;&quot; Then
MsgBox getTranslation(&quot;validationWarning&quot;)
If badText Then
MsgBox getTranslation(&quot;validationBadSymbolsNotification&quot;)
@ -321,7 +326,7 @@ Function checkHeadingsInHeadersFooters As String
checkHeadingsInHeadersFooters = result
End Function
Function checkHeadingsInTextTables(oText As Object) As String
Function checkHeadingsInTextTables() As String
Dim enum1Element As Object
Dim enum1 As Object
Dim enum2 As Object
@ -436,6 +441,126 @@ Function isHeadingsInText(oText As Object) As Boolean
isHeadingsInText = false
End Function
Function hasBrokenCharBackTransparent As Boolean
Dim foonNotes As Object
Dim endNotes As Object
Dim i As Integer
Dim oStyles As Object
Dim pageStyles As Object
Dim pageStyle As Object
hasBrokenCharBackTransparent = isBackColorInText(ThisComponent.Text)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
footNotes = thisComponent.footNotes
For i = 0 to footNotes.Count -1
hasBrokenCharBackTransparent = isBackColorInText(footNotes.getByIndex(i).Text)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
Next i
endNotes = thisComponent.footNotes
For i = 0 to footNotes.Count -1
hasBrokenCharBackTransparent = isBackColorInText(endNotes.getByIndex(i).Text)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
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
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.FooterText)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.FooterTextFirst) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.FooterTextFirst)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.FooterTextRight) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.FooterTextRight)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.FooterTextLeft) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.FooterTextLeft)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.HeaderText) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.HeaderText)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.HeaderTextFirst) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.HeaderTextFirst)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.HeaderTextRight) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.HeaderTextRight)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
If Not IsEmpty(pageStyle.HeaderTextLeft) Then
hasBrokenCharBackTransparent = isBackColorInText(pageStyle.HeaderTextLeft)
If (hasBrokenCharBackTransparent) Then
Exit Function
EndIf
EndIf
Next i
End Function
Function isBackColorInText(oText As Object) As Boolean
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
isBackColorInText = true
Exit Function
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()
If isBackColorInText(cellText) Then
isBackColorInText = true
Exit Function
EndIf
Next i
EndIf
Wend
isBackColorInText = false
End Function
Function printNumberingSymbols(needExtendedInfo) As Boolean
Dim families As Object
Dim numStyles As Object
@ -864,7 +989,6 @@ Function findColoredBackgroundInDoc() As Boolean
sDesc.SearchAll = true
sDesc.ValueSearch = false
sDesc.SearchRegularExpression = true
sDesc.SearchString = searchString
sDesc.searchStyles = true
sDesc.SetSearchAttributes(SrchAttributes())
founds = Thiscomponent.findAll(sDesc)
@ -990,4 +1114,4 @@ sub openReport(fileName As String)
Kill(tmpName)
End If
End Sub
</script:module>
</script:module>

View file

@ -1 +1 @@
version=0.9.30
version=0.9.31

Binary file not shown.