fix: Fixed archive conversion. Fixed new para balance function

This commit is contained in:
Georgy Litvinov 2021-09-20 15:53:51 +02:00
parent fe1fc573eb
commit 797ff48837
4 changed files with 127 additions and 22 deletions

View file

@ -96,7 +96,7 @@
<value xml:lang="bs">Uravnotežite posljednji redak</value>
</prop>
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Archive.adjustLastLineCurPara</value>
<value>macro:///ePublishing.Archive.balanceCurParaLastLine</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>

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="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark26
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark27
End Sub
@ -172,6 +172,7 @@ sub convertIndesignPageBreaks
Exit Sub
EndIf
turnOffTracking()
setZoomToSpeedUpTasks()
balanceFootNotes()
Dim oViewCursor As Object
@ -231,6 +232,7 @@ sub convertIndesignPageBreaks
Wait 100
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End))
EndIf
&apos;check first character
oTextCursor.goRight(1,true)
nextPara = oTextCursor.End
@ -261,9 +263,10 @@ sub convertIndesignPageBreaks
EndIf
End If
If pageNumber - prevPageNumber &lt; 2 Then
&apos;If pageNumber - prevPageNumber &lt; 2 Then
&apos;stretchPrevPage(prevPara)
EndIf
&apos;EndIf
prevPageNumber = pageNumber
oFound = ThisComponent.findNext(oFound.End, oSearch)
@ -458,6 +461,18 @@ Sub stretchPrevPage()
oViewCursor.goToRange(oSavePosition,false)
End Sub
Sub balanceCurParaLastLine()
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim paraEnd As Object
Dim success As Boolean
Dim adjustType As Integer
fixViewCursor()
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.ParaIsHyphenation = true
success = balanceParaTail(oViewCursor.Start, false)
End Sub
Sub adjustLastLineCurPara()
Dim oViewCursor As Object
Dim oTextCursor As Object
@ -477,7 +492,7 @@ Sub adjustLastLineCurPara()
adjustType = oTextCursor.ParaAdjust
hyph = oTextCursor.ParaIsHyphenation
oTextCursor.ParaIsHyphenation = true
success = balanceParaTail(oTextCursor.Start)
success = balanceParaTail(oTextCursor.Start, true)
If success And adjustType = 2 Then
oTextCursor.ParaLastLineAdjust = 2
Else
@ -506,7 +521,7 @@ Sub balanceFootNote(textElement As Object)
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
oViewCursor.goToRange(enum1Element,false)
adjustLastLineCurPara()
balanceCurParaLastLine()
EndIf
Wend
End Sub
@ -540,7 +555,7 @@ End Function
Function balanceParaTail(targetPara As Object) As Boolean
Function balanceParaTail(targetPara As Object, strictMode As Boolean) As Boolean
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim oContent As Object
@ -553,10 +568,10 @@ Function balanceParaTail(targetPara As Object) As Boolean
oContentStart = getParaStart(oTextCursor)
oContentEnd = getParaEnd(oTextCursor)
oContent = getParaSelected(oContentStart,oContentEnd)
balanceParaTail = balanceContentTail(oContent)
balanceParaTail = balanceContentTail(oContent, strictMode)
End Function
Function balanceContentTail(oContent As Object) As Boolean
Function balanceContentTail(oContent As Object, strictMode As Boolean) As Boolean
&apos; Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
balanceContentTail = false
Dim oViewCursor As Object
@ -564,20 +579,18 @@ Function balanceContentTail(oContent As Object) As Boolean
Dim lineCount As Integer
Dim initialLineCount As Integer
Dim lineLen As Integer
Dim initialLineLen As Integer
Dim minLastLineLength As Integer
Dim medianLen As Integer
Dim paraLines() As Object
Dim decreaseKerningFailed As Boolean
Dim increaseKerningFailed As Boolean
Dim fallBackSuccess As Boolean
fallBackSuccess = false
decreaseKerningFailed = false
increaseKerningFailed = false
oViewCursor = ThisComponent.CurrentController.getViewCursor()
paraLen = Len(oContent.String)
paraLines = getContentLines(oContent)
initialLineCount = getParaLinesCount(paraLines)
lineLen = getParaLineLength(paraLines, 0)
initialLineLen = lineLen
medianLen = calculateMedianParaLen(oContent)
minLastLineLength = medianLen * 0.93
@ -600,9 +613,20 @@ Function balanceContentTail(oContent As Object) As Boolean
&apos;Tightened last line but it is still smaller than we need
fallBackSuccess = tryExpandPrevLines(oContent, minLastLineLength)
If Not fallBackSuccess Then
If strictMode Then
oContent.CharKerning = initialCharKerning
oViewCursor.collapseToEnd()
balanceContentTail = false
Else
paraLines = getContentLines(oContent)
lineLen = getParaLineLength(paraLines,0)
If (lineLen &lt; initialLineLen) Then
oContent.CharKerning = initialCharKerning
balanceContentTail = false
Else
balanceContentTail = true
EndIf
EndIf
oViewCursor.collapseToEnd()
Exit Function
EndIf
Exit Do
@ -657,10 +681,15 @@ End Function
Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Boolean
Dim lineCount As Integer
Dim finishLineCount As Integer
Dim initialLineCount As Integer
Dim paraLine As Object
Dim finishLastline As Object
Dim lineNum As Integer
Dim failedLines() As Integer
Dim lastLineCharKerning As Integer
Dim paraLines() As Object
Dim lineCharKerning As Integer
paraLines = getContentLines(oPara)
lineLen = getParaLineLength(paraLines,0)
initialLineCount = getParaLinesCount(paraLines)
@ -677,9 +706,16 @@ Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Bo
lineLen = getParaLineLength(paraLines,0)
If lineNum &gt; 1 And (lineCount &lt;&gt; initialLineCount Or paraLine.CharKerning &gt; MAX_CHAR_KERNING) Then
AddToArray(failedLines, lineNum)
decreaseCharKerning(paraLine)
lineCharKerning = decreaseCharKerning(paraLine)
paraLines = getContentLines(oPara)
lineCount = getParaLinesCount(paraLines)
If lineCount &gt; initialLineCount Then
Do While lineCount &gt; initialLineCount And lineCharKerning &gt; MIN_CHAR_KERNING
lineCharKerning = decreaseCharKerning(paraLine)
paraLines = getContentLines(oPara)
lineCount = getParaLinesCount(paraLines)
Loop
EndIf
lineLen = getParaLineLength(paraLines,0)
lineNum = 0
ElseIf lineNum = 1 And paraLine.CharKerning &gt; MAX_CHAR_KERNING Then
@ -692,8 +728,50 @@ Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Bo
Else
tryExpandPrevLines = false
EndIf
normalizeLastLine(oPara)
End Function
Sub normalizeLastLine(oPara As Object)
Dim lineCount As Integer
Dim finishLineCount As Integer
Dim initialLineCount As Integer
Dim paraLine As Object
Dim finishLastline As Object
Dim lineNum As Integer
Dim failedLines() As Integer
Dim lastLineCharKerning As Integer
Dim paraLines() As Object
Dim oTextCursor As Object
oTextCursor = oPara.Text.createTextCursorByRange(oPara)
oTextCursor.collapseToEnd()
If ( oTextCursor.CharKerning &gt; 0 ) Then
Exit Sub
EndIf
&apos;increase last line kerning to 0
paraLines = getContentLines(oPara)
lineCount = getParaLinesCount(paraLines)
finishLineCount = lineCount
finishLastline = paraLines(UBound(paraLines))
&apos;try just set 0 char kerning to last line, reduce kerning if failed
lastLineCharKerning = 0
finishLastline.CharKerning = lastLineCharKerning
paraLines = getContentLines(oPara)
lineCount = getParaLinesCount(paraLines)
If lineCount &gt; finishLineCount Then
Do While lineCount &gt; finishLineCount AND lastLineCharKerning &gt; MIN_CHAR_KERNING
lastLineCharKerning = lastLineCharKerning - 2
finishLastline.CharKerning = lastLineCharKerning
paraLines = getContentLines(oPara)
lineCount = getParaLinesCount(paraLines)
Loop
EndIf
End Sub
Function getParaLinesCount(paraLines() As Object) As Integer
getParaLinesCount = UBound(paraLines) + 1
@ -739,7 +817,7 @@ Function getContentLines(oContent As Object) As Variant
getContentLines = paraLines
End Function
Sub decreaseCharKerning(oPara As Object)
Function decreaseCharKerning(oPara As Object) As Integer
Dim initialCharKerning As Integer
Dim textExcerpts As Object
Dim textExcerpt As Object
@ -750,9 +828,10 @@ Sub decreaseCharKerning(oPara As Object)
If (initialCharKerning &gt;= MIN_CHAR_KERNING) Then
oPara.CharKerning = initialCharKerning - 2
EndIf
End Sub
decreaseCharKerning = initialCharKerning - 2
End Function
Sub increaseCharKerning(oPara As Object)
Function increaseCharKerning(oPara As Object) As Integer
Dim initialCharKerning As Integer
Dim textExcerpts As Object
Dim textExcerpt As Object
@ -761,7 +840,9 @@ Sub increaseCharKerning(oPara As Object)
initialCharKerning = oPara.CharKerning
EndIf
oPara.CharKerning = initialCharKerning + 2
End Sub
increaseCharKerning = initialCharKerning + 2
End Function
Function lastLineIsNotBalanced(lineLen As Integer,minLastLineLength As Integer) As Boolean
lastLineIsNotBalanced = true
If lineLen = 0 Then
@ -1162,4 +1243,26 @@ Sub subShellSort(mArray)
h = h \ 3
Loop
End Sub
sub setZoomToSpeedUpTasks
dim document as object
dim dispatcher as object
dim args1(2) as new com.sun.star.beans.PropertyValue
dim args2(1) as new com.sun.star.beans.PropertyValue
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
args1(0).Name = &quot;Zoom.Value&quot;
args1(0).Value = 60
args1(1).Name = &quot;Zoom.ValueSet&quot;
args1(1).Value = 28703
args1(2).Name = &quot;Zoom.Type&quot;
args1(2).Value = 0
dispatcher.executeDispatch(document, &quot;.uno:Zoom&quot;, &quot;&quot;, 0, args1())
args2(0).Name = &quot;ViewLayout.Columns&quot;
args2(0).Value = 1
args2(1).Name = &quot;ViewLayout.BookMode&quot;
args2(1).Value = false
dispatcher.executeDispatch(document, &quot;.uno:ViewLayout&quot;, &quot;&quot;, 0, args2())
end sub
</script:module>

View file

@ -15,6 +15,7 @@ Private Sub convertHyphInDoc()
statusIndicator = ThisComponent.getCurrentController.StatusIndicator
statusIndicator.Start(getTranslation(&quot;hyphenationsInProgress&quot;),10)
turnOffTracking
setZoomToSpeedUpTasks()
AcceptAllTrackedChanges
convertHyphInText(ThisComponent.Text)
&apos; Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )

View file

@ -29,6 +29,7 @@ Private Sub makeUpIssue
If NOT confirm(description) Then
Exit Sub
EndIf
setZoomToSpeedUpTasks()
EIFN = &quot;ЭиФН&quot;
PHA = &quot;ФА&quot;
@ -1316,7 +1317,7 @@ Function shrinkPageContent() As Boolean
decreaseContentCharHeight(targetContent(i), delta)
EndIf
If shrinkContentWithKerning(targetContent(i)) Then
balanceContentTail(targetContent(i))
balanceContentTail(targetContent(i),false)
EndIf
If isContentPageChanged(initPosition, initPageNum) Then
Exit Function