fix: fixed kern increment/decrement while balancing para tail

This commit is contained in:
Georgy Litvinov 2021-08-24 15:01:11 +02:00
parent ab552a70db
commit 48ebe71c8e

View file

@ -4,6 +4,9 @@
End Sub
Public Const MAX_CHAR_KERNING = 20
Public Const MIN_CHAR_KERNING = -15
Sub resetNotesStyle
Dim oDescriptor As Object
Dim dispatcher As Object
@ -458,11 +461,10 @@ Sub adjustLastLineCurPara()
End Sub
Sub adjustLastLine(anchor As Object)
anchor.ParaAdjust = 2
anchor.ParaLastLineAdjust = 2
balancePara(anchor)
balanceParaTail(anchor)
End Sub
Sub adjustFirstLine(anchor As Object)
@ -485,7 +487,7 @@ Function isLowerCase(character As String) As Boolean
End Function
Sub balancePara(targetPara As Object)
Sub balanceParaTail(targetPara As Object)
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
Dim oViewCursor As Object
Dim oTextCursor As Object
@ -536,7 +538,7 @@ Sub balancePara(targetPara As Object)
paraLines = getParaLines(oPara)
lineCount = getParaLinesCount(paraLines)
lineLen = getParaLineLength(paraLines,0)
If (lineCount < initialLineCount ) OR (oPara.CharKerning < -15) Then
If (lineCount < initialLineCount ) OR (oPara.CharKerning < MIN_CHAR_KERNING) Then
'Tightened last line but it is still smaller than we need
fallBackSuccess = tryExpandPrevLines(oPara, minLastLineLength)
If Not fallBackSuccess Then
@ -568,14 +570,14 @@ Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Bo
paraLines = getParaLines(oPara)
lineCount = getParaLinesCount(paraLines)
lineLen = getParaLineLength(paraLines,0)
If lineNum > 1 And (lineCount <> initialLineCount Or paraLine.CharKerning > 20) Then
If lineNum > 1 And (lineCount <> initialLineCount Or paraLine.CharKerning > MAX_CHAR_KERNING) Then
AddToArray(failedLines, lineNum)
decreaseCharKerning(paraLine)
paraLines = getParaLines(oPara)
lineCount = getParaLinesCount(paraLines)
lineLen = getParaLineLength(paraLines,0)
lineNum = 0
ElseIf lineNum = 1 And paraLine.CharKerning > 20 Then
ElseIf lineNum = 1 And paraLine.CharKerning > MAX_CHAR_KERNING Then
tryExpandPrevLines = false
Exit Function
EndIf
@ -626,19 +628,45 @@ 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
oPara.CharKerning = 0
Else
oPara.CharKerning = oPara.CharKerning - 2
End If
textExcerpts = oPara.createEnumeration()
While textExcerpts.hasMoreElements
textExcerpt = textExcerpts.nextElement
If Not IsEmpty(textExcerpt.CharKerning) Then
If textExcerpt.CharKerning > initialCharKerning Then
initialCharKerning = textExcerpt.CharKerning
EndIf
EndIf
Wend
Else
initialCharKerning = oPara.CharKerning
EndIf
oPara.CharKerning = initialCharKerning - 2
End Sub
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
oPara.CharKerning = 0
Else
oPara.CharKerning = oPara.CharKerning + 2
End If
textExcerpts = oPara.createEnumeration()
While textExcerpts.hasMoreElements
textExcerpt = textExcerpts.nextElement
If Not IsEmpty(textExcerpt.CharKerning) Then
If textExcerpt.CharKerning < initialCharKerning Then
initialCharKerning = textExcerpt.CharKerning
EndIf
EndIf
Wend
Else
initialCharKerning = oPara.CharKerning
EndIf
oPara.CharKerning = initialCharKerning + 2
End Sub
Function lastLineIsNotBalanced(lineLen As Integer,minLastLineLength As Integer) As Boolean