fix: multiple fixes for processing archive books

This commit is contained in:
Georgy Litvinov 2021-08-27 22:31:59 +02:00
parent 941ac1c9cc
commit 82c63c82ca
2 changed files with 128 additions and 49 deletions

View file

@ -1,11 +1,11 @@
<?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 archMark24
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark25
End Sub
Public Const MAX_CHAR_KERNING = 20
Public Const MIN_CHAR_KERNING = -15
Public Const MAX_CHAR_KERNING = 15
Public Const MIN_CHAR_KERNING = -10
Public Const MIN_SPACING_TO_SHRINK = 500
Sub resetNotesStyle
@ -173,12 +173,14 @@ sub convertIndesignPageBreaks
EndIf
turnOffTracking()
balanceFootNotes()
Dim oViewCursor As Object
oViewCursor = thisComponent.getCurrentController.getViewCursor
oViewCursor.jumpToFirstPage
Dim oSearch As Object
Dim oTextCursor As Object
Dim testCurs As Object
Dim firstLowercase As Boolean
Dim firstBreak As Boolean
firstBreak = true
@ -190,6 +192,7 @@ sub convertIndesignPageBreaks
Dim nextPara As Object
Dim prevPara As Object
Dim nextParaFirstCharacter As String
Dim stringContents As String
firstLowercase = false
oSearch = ThisComponent.createSearchDescriptor()
@ -202,7 +205,15 @@ sub convertIndesignPageBreaks
oTextCursor.gotoRange(oFound,false)
oTextCursor.gotoStartOfParagraph(false)
oTextCursor.gotoEndOfParagraph(true)
testCurs = oTextCursor.Text.createTextCursorByRange(oTextCursor.End)
testCurs.goRight(1,false)
testCurs.gotoEndOfParagraph(true)
&apos;In case two page breaks go together
stringContents = testCurs.String
If stringContents &lt;&gt; pageBreakMarker Then
oTextCursor.goRight(1,true)
EndIf
oTextCursor.String = &quot;&quot;
oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
&apos;Go to Start of new paragraph to shrink prev page if necessary
@ -355,7 +366,7 @@ Sub stretchPrevPage()
Dim curPara As Object
oViewCursor = thisComponent.getCurrentController.getViewCursor
oSavePosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oViewCursor.goToRange(prevPara, false)
&apos;oViewCursor.goToStartOfLine(false)
pageNumberCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
pageNumberCursor.goToStartOfWord(false)
@ -467,15 +478,42 @@ Sub adjustLastLineCurPara()
If success And adjustType = 2 Then
oTextCursor.ParaLastLineAdjust = 2
Else
TextCursor.ParaIsHyphenation = hyph
oTextCursor.ParaIsHyphenation = hyph
EndIf
End Sub
Sub balanceFootNotes()
Dim allNotes As Object
Dim aNote As Object
Dim x As Long
allNotes = ThisComponent.FootNotes
For x = 0 to allNotes.Count -1
aNote = allNotes.getByIndex(x)
balanceFootNote(aNote)
Next
End Sub
Sub balanceFootNote(textElement As Object)
Dim enum1Element As Object
Dim enum1 As Object
Dim oViewCursor As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
enum1 = textElement.createEnumeration()
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
oViewCursor.goToRange(enum1Element,false)
adjustLastLineCurPara()
EndIf
Wend
End Sub
Sub adjustLastLine(anchor As Object)
anchor.ParaAdjust = 2
anchor.ParaLastLineAdjust = 2
balanceParaTail(anchor)
Dim oViewCursor As Object
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.goToRange(anchor,false)
adjustLastLineCurPara()
End Sub
Sub adjustFirstLine(anchor As Object)
@ -560,6 +598,9 @@ Function balanceContentTail(oContent As Object) As Boolean
fallBackSuccess = tryExpandPrevLines(oContent, minLastLineLength)
If Not fallBackSuccess Then
oContent.CharKerning = initialCharKerning
oViewCursor.collapseToEnd()
balanceContentTail = false
Exit Function
EndIf
Exit Do
EndIf
@ -695,23 +736,12 @@ Function getContentLines(oContent As Object) As Variant
getContentLines = paraLines
End Function
Sub decreaseCharKerning(oPara As Object)
Dim initialCharKerning As Integer
Dim textExcerpts As Object
Dim textExcerpt As Object
initialCharKerning = MIN_CHAR_KERNING
If(IsEmpty(oPara.CharKerning)) Then
textExcerpts = oPara.createEnumeration()
While textExcerpts.hasMoreElements
textExcerpt = textExcerpts.nextElement
If Not IsEmpty(textExcerpt.CharKerning) Then
If textExcerpt.CharKerning &gt; initialCharKerning Then
initialCharKerning = textExcerpt.CharKerning
EndIf
EndIf
Wend
Else
initialCharKerning = MIN_CHAR_KERNING + 2
If Not (IsEmpty(oPara.CharKerning)) Then
initialCharKerning = oPara.CharKerning
EndIf
If (initialCharKerning &gt;= MIN_CHAR_KERNING) Then
@ -723,23 +753,12 @@ Sub increaseCharKerning(oPara As Object)
Dim initialCharKerning As Integer
Dim textExcerpts As Object
Dim textExcerpt As Object
initialCharKerning = MAX_CHAR_KERNING
If(IsEmpty(oPara.CharKerning)) Then
textExcerpts = oPara.createEnumeration()
While textExcerpts.hasMoreElements
textExcerpt = textExcerpts.nextElement
If Not IsEmpty(textExcerpt.CharKerning) Then
If textExcerpt.CharKerning &lt; initialCharKerning Then
initialCharKerning = textExcerpt.CharKerning
EndIf
EndIf
Wend
Else
initialCharKerning = MAX_CHAR_KERNING - 2
If Not (IsEmpty(oPara.CharKerning)) Then
initialCharKerning = oPara.CharKerning
EndIf
oPara.CharKerning = initialCharKerning + 2
End Sub
Function lastLineIsNotBalanced(lineLen As Integer,minLastLineLength As Integer) As Boolean
lastLineIsNotBalanced = true
If lineLen = 0 Then

View file

@ -1225,12 +1225,6 @@ Function canShrinkContent() As Boolean
oViewCursor.goToRange(oSavePosition,false)
Exit Function
EndIf
&apos;If current paragraph has page break before
If oSavePosition.BreakType &lt;&gt; 0 Then
canShrinkContent = false
oViewCursor.goToRange(oSavePosition,false)
Exit Function
EndIf
initPageNum = oViewcursor.getPage()
oViewCursor.JumpToPreviousPage(false)
oViewCursor.jumpToStartOfPage()
@ -1241,12 +1235,23 @@ Function canShrinkContent() As Boolean
canShrinkContent = false
Exit Function
EndIf
&apos;If current paragraph has page break before
If oSavePosition.BreakType &lt;&gt; 0 Then
oTextCursor = oSavePosition.Text.createTextCursorByRange(oSavePosition)
oTextCursor.gotoStartOfParagraph(false)
oViewCursor.goToRange(oTextCursor,false)
If oViewCursor.getPage() = initPageNum Then
canShrinkContent = false
oViewCursor.goToRange(oSavePosition,false)
Exit Function
EndIf
EndIf
oViewCursor.goToRange(oSavePosition,false)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
Do While oViewcursor.getPage() = initPageNum
oTextCursor.gotoPreviousParagraph(false)
oViewCursor.goToRange(oTextCursor,false)
If oTextCursor.BreakType &lt;&gt; 0 Then
If oTextCursor.BreakType &lt;&gt; 0 AND oViewcursor.getPage() = initPageNum Then
canShrinkContent = false
oViewCursor.goToRange(oSavePosition,false)
Exit Function
@ -1270,6 +1275,8 @@ Function shrinkPageContent() As Boolean
Dim rounds As Integer
delta = 0.1
rounds = 3
Dim roundsLineHeight As Integer
roundsLineHeight = 3
Dim i As Integer
Dim j As Integer
shrinkPageContent = false
@ -1307,21 +1314,72 @@ Function shrinkPageContent() As Boolean
EndIf
Next i
Next j
For j = 1 To roundsLineHeight
For i = LBound(targetContent) To Ubound(targetContent)
decreaseIntervalHeight(targetContent(i))
If isShrinkPageSucceded(initPosition, initPageNum) Then
Exit Function
EndIf
Next i
Next j
For j = 1 To roundsLineHeight
For i = LBound(targetContent) To Ubound(targetContent)
increaseIntervalHeight(targetContent(i))
Next i
Next j
For i = LBound(targetContent) To Ubound(targetContent)
increaseContentCharHeight(targetContent(i), delta * rounds )
Next i
End Function
Function increaseIntervalHeight(oContent As Object) As Boolean
increaseIntervalHeight = false
Dim oParEnum As Object
Dim oPar As Object
Dim oSecEnum As Object
Dim oParSection As Object
Dim pageNum As Integer
Dim lineSpacing As Object
If Not IsMissing(oContent.ParaLineSpacing) Then
lineSpacing = oContent.ParaLineSpacing
If lineSpacing.Mode = 3 Then
lineSpacing.Height = lineSpacing.Height / 0.98
oContent.ParaLineSpacing = lineSpacing
increaseIntervalHeight = true
End If
End If
End Function
Function decreaseIntervalHeight(oContent As Object) As Boolean
decreaseIntervalHeight = false
Dim oParEnum As Object
Dim oPar As Object
Dim oSecEnum As Object
Dim oParSection As Object
Dim pageNum As Integer
Dim lineSpacing As Object
If Not IsMissing(oContent.ParaLineSpacing) Then
lineSpacing = oContent.ParaLineSpacing
If lineSpacing.Mode = 3 Then
lineSpacing.Height = lineSpacing.Height * 0.98
oContent.ParaLineSpacing = lineSpacing
decreaseIntervalHeight = true
End If
EndIf
End Function
Sub decreaseContentCharHeight(oContent As Object, delta As double)
Dim contentEnum As Object&apos;paragraph enumeration
Dim textContentElement As Object&apos;current paragraph
Dim curHeight As Double
Dim oTextCursor As Object
contentEnum = oContent.createEnumeration()
Do While contentEnum.hasMoreElements()
textContentElement = contentEnum.nextElement()
curHeight = textContentElement.charHeight
textContentElement.charHeight = roundHeight(curHeight) - delta
oTextCursor = textContentElement.Text.createTextCursorByRange(textContentElement)
curHeight = oTextCursor.charHeight
oTextCursor.charHeight = roundHeight(curHeight) - delta
Loop
End Sub
@ -1329,11 +1387,13 @@ Sub increaseContentCharHeight(oContent As Object, delta As double)
Dim contentEnum As Object&apos;paragraph enumeration
Dim textContentElement As Object&apos;current paragraph
Dim curHeight As Double
Dim oTextCursor As Object
contentEnum = oContent.createEnumeration()
Do While contentEnum.hasMoreElements()
textContentElement = contentEnum.nextElement()
curHeight = textContentElement.charHeight
textContentElement.charHeight = roundHeight(curHeight) + delta
oTextCursor = textContentElement.Text.createTextCursorByRange(textContentElement)
curHeight = oTextCursor.charHeight
oTextCursor.charHeight = roundHeight(curHeight) + delta
Loop
End Sub