fix: Fixed archive conversion. Fixed new para balance function
This commit is contained in:
parent
fe1fc573eb
commit
797ff48837
4 changed files with 127 additions and 22 deletions
|
@ -96,7 +96,7 @@
|
||||||
<value xml:lang="bs">Uravnotežite posljednji redak</value>
|
<value xml:lang="bs">Uravnotežite posljednji redak</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="URL" oor:type="xs:string">
|
<prop oor:name="URL" oor:type="xs:string">
|
||||||
<value>macro:///ePublishing.Archive.adjustLastLineCurPara</value>
|
<value>macro:///ePublishing.Archive.balanceCurParaLastLine</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="Target" oor:type="xs:string">
|
<prop oor:name="Target" oor:type="xs:string">
|
||||||
<value>_self</value>
|
<value>_self</value>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
<!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
|
End Sub
|
||||||
|
|
||||||
|
@ -172,6 +172,7 @@ sub convertIndesignPageBreaks
|
||||||
Exit Sub
|
Exit Sub
|
||||||
EndIf
|
EndIf
|
||||||
turnOffTracking()
|
turnOffTracking()
|
||||||
|
setZoomToSpeedUpTasks()
|
||||||
|
|
||||||
balanceFootNotes()
|
balanceFootNotes()
|
||||||
Dim oViewCursor As Object
|
Dim oViewCursor As Object
|
||||||
|
@ -231,6 +232,7 @@ sub convertIndesignPageBreaks
|
||||||
Wait 100
|
Wait 100
|
||||||
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End))
|
pageNumber = getPageNumber(oTextCursor.Text.createTextCursorByRange(oTextCursor.End))
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
'check first character
|
'check first character
|
||||||
oTextCursor.goRight(1,true)
|
oTextCursor.goRight(1,true)
|
||||||
nextPara = oTextCursor.End
|
nextPara = oTextCursor.End
|
||||||
|
@ -261,9 +263,10 @@ sub convertIndesignPageBreaks
|
||||||
EndIf
|
EndIf
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If pageNumber - prevPageNumber < 2 Then
|
|
||||||
'stretchPrevPage(prevPara)
|
'If pageNumber - prevPageNumber < 2 Then
|
||||||
EndIf
|
'stretchPrevPage(prevPara)
|
||||||
|
'EndIf
|
||||||
|
|
||||||
prevPageNumber = pageNumber
|
prevPageNumber = pageNumber
|
||||||
oFound = ThisComponent.findNext(oFound.End, oSearch)
|
oFound = ThisComponent.findNext(oFound.End, oSearch)
|
||||||
|
@ -458,6 +461,18 @@ Sub stretchPrevPage()
|
||||||
oViewCursor.goToRange(oSavePosition,false)
|
oViewCursor.goToRange(oSavePosition,false)
|
||||||
End Sub
|
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()
|
Sub adjustLastLineCurPara()
|
||||||
Dim oViewCursor As Object
|
Dim oViewCursor As Object
|
||||||
Dim oTextCursor As Object
|
Dim oTextCursor As Object
|
||||||
|
@ -477,7 +492,7 @@ Sub adjustLastLineCurPara()
|
||||||
adjustType = oTextCursor.ParaAdjust
|
adjustType = oTextCursor.ParaAdjust
|
||||||
hyph = oTextCursor.ParaIsHyphenation
|
hyph = oTextCursor.ParaIsHyphenation
|
||||||
oTextCursor.ParaIsHyphenation = true
|
oTextCursor.ParaIsHyphenation = true
|
||||||
success = balanceParaTail(oTextCursor.Start)
|
success = balanceParaTail(oTextCursor.Start, true)
|
||||||
If success And adjustType = 2 Then
|
If success And adjustType = 2 Then
|
||||||
oTextCursor.ParaLastLineAdjust = 2
|
oTextCursor.ParaLastLineAdjust = 2
|
||||||
Else
|
Else
|
||||||
|
@ -506,7 +521,7 @@ Sub balanceFootNote(textElement As Object)
|
||||||
enum1Element = enum1.nextElement
|
enum1Element = enum1.nextElement
|
||||||
If enum1Element.supportsService("com.sun.star.text.Paragraph") Then
|
If enum1Element.supportsService("com.sun.star.text.Paragraph") Then
|
||||||
oViewCursor.goToRange(enum1Element,false)
|
oViewCursor.goToRange(enum1Element,false)
|
||||||
adjustLastLineCurPara()
|
balanceCurParaLastLine()
|
||||||
EndIf
|
EndIf
|
||||||
Wend
|
Wend
|
||||||
End Sub
|
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 oViewCursor As Object
|
||||||
Dim oTextCursor As Object
|
Dim oTextCursor As Object
|
||||||
Dim oContent As Object
|
Dim oContent As Object
|
||||||
|
@ -553,10 +568,10 @@ Function balanceParaTail(targetPara As Object) As Boolean
|
||||||
oContentStart = getParaStart(oTextCursor)
|
oContentStart = getParaStart(oTextCursor)
|
||||||
oContentEnd = getParaEnd(oTextCursor)
|
oContentEnd = getParaEnd(oTextCursor)
|
||||||
oContent = getParaSelected(oContentStart,oContentEnd)
|
oContent = getParaSelected(oContentStart,oContentEnd)
|
||||||
balanceParaTail = balanceContentTail(oContent)
|
balanceParaTail = balanceContentTail(oContent, strictMode)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Function balanceContentTail(oContent As Object) As Boolean
|
Function balanceContentTail(oContent As Object, strictMode As Boolean) As Boolean
|
||||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||||
balanceContentTail = false
|
balanceContentTail = false
|
||||||
Dim oViewCursor As Object
|
Dim oViewCursor As Object
|
||||||
|
@ -564,20 +579,18 @@ Function balanceContentTail(oContent As Object) As Boolean
|
||||||
Dim lineCount As Integer
|
Dim lineCount As Integer
|
||||||
Dim initialLineCount As Integer
|
Dim initialLineCount As Integer
|
||||||
Dim lineLen As Integer
|
Dim lineLen As Integer
|
||||||
|
Dim initialLineLen As Integer
|
||||||
Dim minLastLineLength As Integer
|
Dim minLastLineLength As Integer
|
||||||
Dim medianLen As Integer
|
Dim medianLen As Integer
|
||||||
Dim paraLines() As Object
|
Dim paraLines() As Object
|
||||||
Dim decreaseKerningFailed As Boolean
|
|
||||||
Dim increaseKerningFailed As Boolean
|
|
||||||
Dim fallBackSuccess As Boolean
|
Dim fallBackSuccess As Boolean
|
||||||
fallBackSuccess = false
|
fallBackSuccess = false
|
||||||
decreaseKerningFailed = false
|
|
||||||
increaseKerningFailed = false
|
|
||||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||||
paraLen = Len(oContent.String)
|
paraLen = Len(oContent.String)
|
||||||
paraLines = getContentLines(oContent)
|
paraLines = getContentLines(oContent)
|
||||||
initialLineCount = getParaLinesCount(paraLines)
|
initialLineCount = getParaLinesCount(paraLines)
|
||||||
lineLen = getParaLineLength(paraLines, 0)
|
lineLen = getParaLineLength(paraLines, 0)
|
||||||
|
initialLineLen = lineLen
|
||||||
medianLen = calculateMedianParaLen(oContent)
|
medianLen = calculateMedianParaLen(oContent)
|
||||||
minLastLineLength = medianLen * 0.93
|
minLastLineLength = medianLen * 0.93
|
||||||
|
|
||||||
|
@ -600,9 +613,20 @@ Function balanceContentTail(oContent As Object) As Boolean
|
||||||
'Tightened last line but it is still smaller than we need
|
'Tightened last line but it is still smaller than we need
|
||||||
fallBackSuccess = tryExpandPrevLines(oContent, minLastLineLength)
|
fallBackSuccess = tryExpandPrevLines(oContent, minLastLineLength)
|
||||||
If Not fallBackSuccess Then
|
If Not fallBackSuccess Then
|
||||||
oContent.CharKerning = initialCharKerning
|
If strictMode Then
|
||||||
|
oContent.CharKerning = initialCharKerning
|
||||||
|
balanceContentTail = false
|
||||||
|
Else
|
||||||
|
paraLines = getContentLines(oContent)
|
||||||
|
lineLen = getParaLineLength(paraLines,0)
|
||||||
|
If (lineLen < initialLineLen) Then
|
||||||
|
oContent.CharKerning = initialCharKerning
|
||||||
|
balanceContentTail = false
|
||||||
|
Else
|
||||||
|
balanceContentTail = true
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
oViewCursor.collapseToEnd()
|
oViewCursor.collapseToEnd()
|
||||||
balanceContentTail = false
|
|
||||||
Exit Function
|
Exit Function
|
||||||
EndIf
|
EndIf
|
||||||
Exit Do
|
Exit Do
|
||||||
|
@ -657,10 +681,15 @@ End Function
|
||||||
|
|
||||||
Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Boolean
|
Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Boolean
|
||||||
Dim lineCount As Integer
|
Dim lineCount As Integer
|
||||||
|
Dim finishLineCount As Integer
|
||||||
Dim initialLineCount As Integer
|
Dim initialLineCount As Integer
|
||||||
Dim paraLine As Object
|
Dim paraLine As Object
|
||||||
|
Dim finishLastline As Object
|
||||||
Dim lineNum As Integer
|
Dim lineNum As Integer
|
||||||
Dim failedLines() As Integer
|
Dim failedLines() As Integer
|
||||||
|
Dim lastLineCharKerning As Integer
|
||||||
|
Dim paraLines() As Object
|
||||||
|
Dim lineCharKerning As Integer
|
||||||
paraLines = getContentLines(oPara)
|
paraLines = getContentLines(oPara)
|
||||||
lineLen = getParaLineLength(paraLines,0)
|
lineLen = getParaLineLength(paraLines,0)
|
||||||
initialLineCount = getParaLinesCount(paraLines)
|
initialLineCount = getParaLinesCount(paraLines)
|
||||||
|
@ -677,9 +706,16 @@ Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Bo
|
||||||
lineLen = getParaLineLength(paraLines,0)
|
lineLen = getParaLineLength(paraLines,0)
|
||||||
If lineNum > 1 And (lineCount <> initialLineCount Or paraLine.CharKerning > MAX_CHAR_KERNING) Then
|
If lineNum > 1 And (lineCount <> initialLineCount Or paraLine.CharKerning > MAX_CHAR_KERNING) Then
|
||||||
AddToArray(failedLines, lineNum)
|
AddToArray(failedLines, lineNum)
|
||||||
decreaseCharKerning(paraLine)
|
lineCharKerning = decreaseCharKerning(paraLine)
|
||||||
paraLines = getContentLines(oPara)
|
paraLines = getContentLines(oPara)
|
||||||
lineCount = getParaLinesCount(paraLines)
|
lineCount = getParaLinesCount(paraLines)
|
||||||
|
If lineCount > initialLineCount Then
|
||||||
|
Do While lineCount > initialLineCount And lineCharKerning > MIN_CHAR_KERNING
|
||||||
|
lineCharKerning = decreaseCharKerning(paraLine)
|
||||||
|
paraLines = getContentLines(oPara)
|
||||||
|
lineCount = getParaLinesCount(paraLines)
|
||||||
|
Loop
|
||||||
|
EndIf
|
||||||
lineLen = getParaLineLength(paraLines,0)
|
lineLen = getParaLineLength(paraLines,0)
|
||||||
lineNum = 0
|
lineNum = 0
|
||||||
ElseIf lineNum = 1 And paraLine.CharKerning > MAX_CHAR_KERNING Then
|
ElseIf lineNum = 1 And paraLine.CharKerning > MAX_CHAR_KERNING Then
|
||||||
|
@ -692,8 +728,50 @@ Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Bo
|
||||||
Else
|
Else
|
||||||
tryExpandPrevLines = false
|
tryExpandPrevLines = false
|
||||||
EndIf
|
EndIf
|
||||||
|
normalizeLastLine(oPara)
|
||||||
|
|
||||||
|
|
||||||
End Function
|
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 > 0 ) Then
|
||||||
|
Exit Sub
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
'increase last line kerning to 0
|
||||||
|
paraLines = getContentLines(oPara)
|
||||||
|
lineCount = getParaLinesCount(paraLines)
|
||||||
|
finishLineCount = lineCount
|
||||||
|
finishLastline = paraLines(UBound(paraLines))
|
||||||
|
'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 > finishLineCount Then
|
||||||
|
Do While lineCount > finishLineCount AND lastLineCharKerning > 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
|
Function getParaLinesCount(paraLines() As Object) As Integer
|
||||||
getParaLinesCount = UBound(paraLines) + 1
|
getParaLinesCount = UBound(paraLines) + 1
|
||||||
|
@ -739,7 +817,7 @@ Function getContentLines(oContent As Object) As Variant
|
||||||
getContentLines = paraLines
|
getContentLines = paraLines
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Sub decreaseCharKerning(oPara As Object)
|
Function decreaseCharKerning(oPara As Object) As Integer
|
||||||
Dim initialCharKerning As Integer
|
Dim initialCharKerning As Integer
|
||||||
Dim textExcerpts As Object
|
Dim textExcerpts As Object
|
||||||
Dim textExcerpt As Object
|
Dim textExcerpt As Object
|
||||||
|
@ -750,9 +828,10 @@ Sub decreaseCharKerning(oPara As Object)
|
||||||
If (initialCharKerning >= MIN_CHAR_KERNING) Then
|
If (initialCharKerning >= MIN_CHAR_KERNING) Then
|
||||||
oPara.CharKerning = initialCharKerning - 2
|
oPara.CharKerning = initialCharKerning - 2
|
||||||
EndIf
|
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 initialCharKerning As Integer
|
||||||
Dim textExcerpts As Object
|
Dim textExcerpts As Object
|
||||||
Dim textExcerpt As Object
|
Dim textExcerpt As Object
|
||||||
|
@ -761,7 +840,9 @@ Sub increaseCharKerning(oPara As Object)
|
||||||
initialCharKerning = oPara.CharKerning
|
initialCharKerning = oPara.CharKerning
|
||||||
EndIf
|
EndIf
|
||||||
oPara.CharKerning = initialCharKerning + 2
|
oPara.CharKerning = initialCharKerning + 2
|
||||||
End Sub
|
increaseCharKerning = initialCharKerning + 2
|
||||||
|
End Function
|
||||||
|
|
||||||
Function lastLineIsNotBalanced(lineLen As Integer,minLastLineLength As Integer) As Boolean
|
Function lastLineIsNotBalanced(lineLen As Integer,minLastLineLength As Integer) As Boolean
|
||||||
lastLineIsNotBalanced = true
|
lastLineIsNotBalanced = true
|
||||||
If lineLen = 0 Then
|
If lineLen = 0 Then
|
||||||
|
@ -1162,4 +1243,26 @@ Sub subShellSort(mArray)
|
||||||
h = h \ 3
|
h = h \ 3
|
||||||
Loop
|
Loop
|
||||||
End Sub
|
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("com.sun.star.frame.DispatchHelper")
|
||||||
|
args1(0).Name = "Zoom.Value"
|
||||||
|
args1(0).Value = 60
|
||||||
|
args1(1).Name = "Zoom.ValueSet"
|
||||||
|
args1(1).Value = 28703
|
||||||
|
args1(2).Name = "Zoom.Type"
|
||||||
|
args1(2).Value = 0
|
||||||
|
dispatcher.executeDispatch(document, ".uno:Zoom", "", 0, args1())
|
||||||
|
args2(0).Name = "ViewLayout.Columns"
|
||||||
|
args2(0).Value = 1
|
||||||
|
args2(1).Name = "ViewLayout.BookMode"
|
||||||
|
args2(1).Value = false
|
||||||
|
dispatcher.executeDispatch(document, ".uno:ViewLayout", "", 0, args2())
|
||||||
|
end sub
|
||||||
</script:module>
|
</script:module>
|
|
@ -15,6 +15,7 @@ Private Sub convertHyphInDoc()
|
||||||
statusIndicator = ThisComponent.getCurrentController.StatusIndicator
|
statusIndicator = ThisComponent.getCurrentController.StatusIndicator
|
||||||
statusIndicator.Start(getTranslation("hyphenationsInProgress"),10)
|
statusIndicator.Start(getTranslation("hyphenationsInProgress"),10)
|
||||||
turnOffTracking
|
turnOffTracking
|
||||||
|
setZoomToSpeedUpTasks()
|
||||||
AcceptAllTrackedChanges
|
AcceptAllTrackedChanges
|
||||||
convertHyphInText(ThisComponent.Text)
|
convertHyphInText(ThisComponent.Text)
|
||||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||||
|
|
|
@ -29,6 +29,7 @@ Private Sub makeUpIssue
|
||||||
If NOT confirm(description) Then
|
If NOT confirm(description) Then
|
||||||
Exit Sub
|
Exit Sub
|
||||||
EndIf
|
EndIf
|
||||||
|
setZoomToSpeedUpTasks()
|
||||||
|
|
||||||
EIFN = "ЭиФН"
|
EIFN = "ЭиФН"
|
||||||
PHA = "ФА"
|
PHA = "ФА"
|
||||||
|
@ -1316,7 +1317,7 @@ Function shrinkPageContent() As Boolean
|
||||||
decreaseContentCharHeight(targetContent(i), delta)
|
decreaseContentCharHeight(targetContent(i), delta)
|
||||||
EndIf
|
EndIf
|
||||||
If shrinkContentWithKerning(targetContent(i)) Then
|
If shrinkContentWithKerning(targetContent(i)) Then
|
||||||
balanceContentTail(targetContent(i))
|
balanceContentTail(targetContent(i),false)
|
||||||
EndIf
|
EndIf
|
||||||
If isContentPageChanged(initPosition, initPageNum) Then
|
If isContentPageChanged(initPosition, initPageNum) Then
|
||||||
Exit Function
|
Exit Function
|
||||||
|
|
Loading…
Add table
Reference in a new issue