fix rewritten shrink content function
This commit is contained in:
parent
f58b4f58de
commit
5bb9600439
2 changed files with 203 additions and 331 deletions
ePublishing
|
@ -6,6 +6,7 @@ End Sub
|
|||
|
||||
Public Const MAX_CHAR_KERNING = 20
|
||||
Public Const MIN_CHAR_KERNING = -15
|
||||
Public Const MIN_SPACING_TO_SHRINK = 500
|
||||
|
||||
Sub resetNotesStyle
|
||||
Dim oDescriptor As Object
|
||||
|
@ -487,13 +488,26 @@ Function isLowerCase(character As String) As Boolean
|
|||
End Function
|
||||
|
||||
|
||||
|
||||
Sub balanceParaTail(targetPara As Object)
|
||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
Dim oPara As Object
|
||||
Dim oParaStart As Object
|
||||
Dim oParaEnd As Object
|
||||
Dim oContent As Object
|
||||
Dim oContentStart As Object
|
||||
Dim oContentEnd As Object
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCursor.goToRange(targetPara, false)
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
|
||||
oContentStart = getParaStart(oTextCursor)
|
||||
oContentEnd = getParaEnd(oTextCursor)
|
||||
oContent = getParaSelected(oContentStart,oContentEnd)
|
||||
balanceContentTail(oContent)
|
||||
End Sub
|
||||
|
||||
Sub balanceContentTail(oContent As Object)
|
||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
Dim oViewCursor As Object
|
||||
Dim paraLen As Integer
|
||||
Dim lineCount As Integer
|
||||
Dim initialLineCount As Integer
|
||||
|
@ -507,24 +521,16 @@ Sub balanceParaTail(targetPara As Object)
|
|||
fallBackSuccess = false
|
||||
decreaseKerningFailed = false
|
||||
increaseKerningFailed = false
|
||||
|
||||
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCursor.goToRange(targetPara, false)
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
|
||||
oParaStart = getParaStart(oTextCursor)
|
||||
oParaEnd = getParaEnd(oTextCursor)
|
||||
oPara = getParaSelected(oParaStart,oParaEnd)
|
||||
paraLen = Len(oPara.String)
|
||||
paraLines = getParaLines(oPara)
|
||||
paraLen = Len(oContent.String)
|
||||
paraLines = getContentLines(oContent)
|
||||
initialLineCount = getParaLinesCount(paraLines)
|
||||
lineLen = getParaLineLength(paraLines, 0)
|
||||
medianLen = calculateMedianParaLen(oPara)
|
||||
medianLen = calculateMedianParaLen(oContent)
|
||||
minLastLineLength = medianLen * 0.93
|
||||
|
||||
If Not IsEmpty(oPara.CharKerning) Then
|
||||
initialCharKerning = oPara.CharKerning
|
||||
If Not IsEmpty(oContent.CharKerning) Then
|
||||
initialCharKerning = oContent.CharKerning
|
||||
Else
|
||||
initialCharKerning = 0
|
||||
End If
|
||||
|
@ -534,15 +540,15 @@ Sub balanceParaTail(targetPara As Object)
|
|||
EndIf
|
||||
|
||||
Do While lastLineIsNotBalanced(lineLen, minLastLineLength)
|
||||
decreaseCharKerning(oPara)
|
||||
paraLines = getParaLines(oPara)
|
||||
decreaseCharKerning(oContent)
|
||||
paraLines = getContentLines(oContent)
|
||||
lineCount = getParaLinesCount(paraLines)
|
||||
lineLen = getParaLineLength(paraLines,0)
|
||||
If (lineCount < initialLineCount ) OR (oPara.CharKerning < MIN_CHAR_KERNING) Then
|
||||
If (lineCount < initialLineCount ) OR (oContent.CharKerning < MIN_CHAR_KERNING) Then
|
||||
'Tightened last line but it is still smaller than we need
|
||||
fallBackSuccess = tryExpandPrevLines(oPara, minLastLineLength)
|
||||
fallBackSuccess = tryExpandPrevLines(oContent, minLastLineLength)
|
||||
If Not fallBackSuccess Then
|
||||
oPara.CharKerning = initialCharKerning
|
||||
oContent.CharKerning = initialCharKerning
|
||||
EndIf
|
||||
Exit Do
|
||||
EndIf
|
||||
|
@ -550,13 +556,56 @@ Sub balanceParaTail(targetPara As Object)
|
|||
oViewCursor.collapseToEnd()
|
||||
End Sub
|
||||
|
||||
Function shrinkContentWithKerning(oContent As Object) As Boolean
|
||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
shrinkContentWithKerning = false
|
||||
Dim paraLen As Integer
|
||||
Dim lineCount As Integer
|
||||
Dim saveLineCount As Integer
|
||||
Dim initialLineCount As Integer
|
||||
Dim contentLines() As Object
|
||||
Dim kerningValue As Integer
|
||||
contentLines = getContentLines(oContent)
|
||||
initialLineCount = getParaLinesCount(contentLines)
|
||||
saveLineCount = initialLineCount
|
||||
If Not IsEmpty(oContent.CharKerning) Then
|
||||
initialCharKerning = oContent.CharKerning
|
||||
Else
|
||||
initialCharKerning = 0
|
||||
End If
|
||||
kerningValue = initialCharKerning
|
||||
'Reduce kerning is useless if content is less than 2 lines long
|
||||
If initialLineCount < 2 Then
|
||||
Exit Function
|
||||
EndIf
|
||||
|
||||
Do While oContent.CharKerning > MIN_CHAR_KERNING
|
||||
decreaseCharKerning(oContent)
|
||||
contentLines = getContentLines(oContent)
|
||||
lineCount = getParaLinesCount(contentLines)
|
||||
If lineCount < saveLineCount Then
|
||||
kerningValue = oContent.CharKerning
|
||||
saveLineCount = lineCount
|
||||
EndIf
|
||||
Loop
|
||||
'If decrease kerning didn't reduce lines then retreat to latest value that changed lines count
|
||||
If kerningValue <> oContent.CharKerning Then
|
||||
oContent.CharKerning = kerningValue
|
||||
EndIf
|
||||
If initialCharKerning <> kerningValue Then
|
||||
shrinkContentWithKerning = true
|
||||
EndIf
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Boolean
|
||||
Dim lineCount As Integer
|
||||
Dim initialLineCount As Integer
|
||||
Dim paraLine As Object
|
||||
Dim lineNum As Integer
|
||||
Dim failedLines() As Integer
|
||||
paraLines = getParaLines(oPara)
|
||||
paraLines = getContentLines(oPara)
|
||||
lineLen = getParaLineLength(paraLines,0)
|
||||
initialLineCount = getParaLinesCount(paraLines)
|
||||
lineCount = initialLineCount
|
||||
|
@ -567,13 +616,13 @@ Function tryExpandPrevLines(oPara As Object, minLastLineLength As Integer) As Bo
|
|||
EndIf
|
||||
paraLine = paraLines(UBound(paraLines) - lineNum)
|
||||
increaseCharKerning(paraLine)
|
||||
paraLines = getParaLines(oPara)
|
||||
paraLines = getContentLines(oPara)
|
||||
lineCount = getParaLinesCount(paraLines)
|
||||
lineLen = getParaLineLength(paraLines,0)
|
||||
If lineNum > 1 And (lineCount <> initialLineCount Or paraLine.CharKerning > MAX_CHAR_KERNING) Then
|
||||
AddToArray(failedLines, lineNum)
|
||||
decreaseCharKerning(paraLine)
|
||||
paraLines = getParaLines(oPara)
|
||||
paraLines = getContentLines(oPara)
|
||||
lineCount = getParaLinesCount(paraLines)
|
||||
lineLen = getParaLineLength(paraLines,0)
|
||||
lineNum = 0
|
||||
|
@ -606,24 +655,32 @@ Function getParaLineLength(paraLines() As Object, lineNumber As Integer) As Inte
|
|||
|
||||
End Function
|
||||
|
||||
Function getParaLines(oPara As Object) As Variant
|
||||
Function getContentLines(oContent As Object) As Variant
|
||||
Dim oTextCursor As Object
|
||||
Dim oViewCursor As Object
|
||||
Dim paraLine As Object
|
||||
Dim paraLines() As Object
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
'initial value is 1 As paragraph can't be 0 lines long
|
||||
oTextCursor = oPara.Text.createTextCursorByRange(oPara)
|
||||
oTextCursor = oContent.Text.createTextCursorByRange(oContent)
|
||||
oTextCursor.collapseToStart()
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
While NOT oTextCursor.isEndOfParagraph()
|
||||
oViewCursor.gotoEndOfLine(true)
|
||||
paraLine = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
AddToArray(paraLines, paraLine)
|
||||
If (Len(oViewCursor.String) = 0) Then
|
||||
oTextCursor.goToRange(oViewCursor,false)
|
||||
oTextCursor.goRight(1,false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
oViewCursor.gotoEndOfLine(true)
|
||||
EndIf
|
||||
If (Len(oViewCursor.String) > 0) Then
|
||||
paraLine = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
AddToArray(paraLines, paraLine)
|
||||
EndIf
|
||||
oViewCursor.collapseToEnd()
|
||||
oTextCursor.goToRange(oViewCursor,false)
|
||||
Wend
|
||||
getParaLines = paraLines
|
||||
getContentLines = paraLines
|
||||
End Function
|
||||
|
||||
|
||||
|
@ -644,8 +701,10 @@ Sub decreaseCharKerning(oPara As Object)
|
|||
Wend
|
||||
Else
|
||||
initialCharKerning = oPara.CharKerning
|
||||
EndIf
|
||||
oPara.CharKerning = initialCharKerning - 2
|
||||
EndIf
|
||||
If (initialCharKerning >= MIN_CHAR_KERNING) Then
|
||||
oPara.CharKerning = initialCharKerning - 2
|
||||
EndIf
|
||||
End Sub
|
||||
|
||||
Sub increaseCharKerning(oPara As Object)
|
||||
|
|
|
@ -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="journals" script:language="StarBasic">Private sub journalsMark33
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="journals" script:language="StarBasic">Private sub journalsMark34
|
||||
End sub
|
||||
|
||||
Dim templateName As String
|
||||
|
@ -1132,67 +1132,6 @@ sub backspace
|
|||
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())
|
||||
end Sub
|
||||
|
||||
Function shrinkPageContent() As Boolean
|
||||
Dim oViewCursor As Object 'View cursor
|
||||
Dim oTextCursor As Object 'Text cursor
|
||||
Dim oViewCurInitPosition As Object
|
||||
Dim oSaveEndSelection As Object 'Text cursor
|
||||
Dim oEnum As Variant'Cursor enumeration
|
||||
Dim oPar As Object'Current paragraph
|
||||
Dim scaleCharHeight As Integer
|
||||
Dim scaleIntervalHeight As Integer
|
||||
Dim kernShrinkValue As Integer
|
||||
Dim startOfPara As Boolean
|
||||
|
||||
kernShrinkValue = 8
|
||||
scaleCharHeight = 2
|
||||
scaleIntervalHeight = 3
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCurInitPosition = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
'Move right to select left and right characters and save position to the right
|
||||
oTextCursor.goRight(1,false)
|
||||
oSaveEndSelection = oTextCursor.Text.createTextCursorByRange(oTextCursor)
|
||||
'Select last 2 characters
|
||||
oTextCursor.goLeft(2,true)
|
||||
If Len(oTextCursor.String) = 2 Then
|
||||
oLastChars = oTextCursor.Text.createTextCursorByRange(oTextCursor)
|
||||
oViewCursor.goToRange(oTextCursor, false)
|
||||
'Insert hyphen if needed
|
||||
insertHyphen()
|
||||
End If
|
||||
'Return to initial position
|
||||
oTextCursor.gotoRange(oSaveEndSelection,false) 'Go to end of text to check page changes
|
||||
oTextCursor.goLeft(1,false)
|
||||
'Set saved position to initial state
|
||||
oSaveEndSelection = oTextCursor.Text.createTextCursorByRange(oTextCursor)
|
||||
'If one of textRanges is Footnote or Endnote we can't select them so it is better to exit now
|
||||
If oTextCursor.Text.supportsService("com.sun.star.text.Endnote") OR _
|
||||
oTextCursor.Text.supportsService("com.sun.star.text.Footnote") OR _
|
||||
oTextCursor.Text.supportsService("com.sun.star.text.CellProperties") OR _
|
||||
oSaveEndSelection.Text.supportsService("com.sun.star.text.Endnote") OR _
|
||||
oSaveEndSelection.Text.supportsService("com.sun.star.text.Footnote") OR _
|
||||
oSaveEndSelection.Text.supportsService("com.sun.star.text.CellProperties") Then
|
||||
shrinkPageContent = false
|
||||
oViewCursor.gotoRange(oViewCurInitPosition,false)
|
||||
Exit Function
|
||||
EndIf
|
||||
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
oViewCursor.jumpToPreviousPage()
|
||||
oViewCursor.jumpToStartOfPage()
|
||||
oTextCursor.gotoRange(oSaveEndSelection,true)
|
||||
oViewCursor.gotoRange(oSaveEndSelection,false) 'Go to end of text to check page changes
|
||||
|
||||
If shrinkKern(oTextCursor,oViewCursor,kernShrinkValue) Or _
|
||||
shrinkCharHeight(oTextCursor,oViewCursor,scaleCharHeight) Or _
|
||||
shrinkIntervalHeight(oTextCursor,oViewCursor,scaleIntervalHeight) Then
|
||||
insertHardPageBreakIfNotOnPageBorder()
|
||||
Exit Function
|
||||
End If
|
||||
End Function
|
||||
|
||||
Sub configureCursorPositionForContentShrink()
|
||||
' Globalscope.BasicLibraries.LoadLibrary("MRILib")
|
||||
Dim oViewCursor As Object
|
||||
|
@ -1225,42 +1164,45 @@ Function isShrinkPageSucceded(initPosition As Object,initPageNum As String) As B
|
|||
oViewCursor.goToRange(initPosition,false)
|
||||
If (oViewCursor.getPage <> initPageNum) Then
|
||||
isShrinkPageSucceded = true
|
||||
Else
|
||||
oTextCursor = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
oTextCursor.goRight(1,false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
If oViewCursor.getPage <> initPageNum Then
|
||||
isShrinkPageSucceded = true
|
||||
EndIf
|
||||
EndIf
|
||||
End Function
|
||||
|
||||
Function getShrinkPageContentInitPosition() As Object
|
||||
Function breakParaAtCursor() As Object
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
Dim leftMargin As Long
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oTextCursor = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
If NOT oTextCursor.isEndOfParagraph() Then
|
||||
oTextCursor.goLeft(1,false)
|
||||
oTextCursor.goRight(2,true)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
insertHyphen()
|
||||
insertHyphen(oTextCursor)
|
||||
oTextCursor.goLeft(1,false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
insertPageBreak
|
||||
leftMargin = oViewCursor.ParaLeftMargin
|
||||
insertPara
|
||||
oViewCursor.ParaFirstLineIndent = leftMargin
|
||||
oTextCursor.goLeft(1,false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
getShrinkPageContentInitPosition = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
breakParaAtCursor = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
Else
|
||||
oTextCursor.goRight(1,false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
oViewCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
|
||||
oTextCursor.goLeft(1,false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
getShrinkPageContentInitPosition = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
breakParaAtCursor = oViewcursor.Text.createTextCursorByRange(oViewCursor)
|
||||
EndIf
|
||||
End Function
|
||||
|
||||
sub insertPara
|
||||
dim document as object
|
||||
dim dispatcher as object
|
||||
document = ThisComponent.CurrentController.Frame
|
||||
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
|
||||
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
|
||||
end sub
|
||||
|
||||
Function canShrinkContent() As Boolean
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
|
@ -1310,7 +1252,7 @@ Function canShrinkContent() As Boolean
|
|||
End Function
|
||||
|
||||
|
||||
Function shrinkPageContentNew() As Boolean
|
||||
Function shrinkPageContent() As Boolean
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
Dim initPosition As Object
|
||||
|
@ -1320,6 +1262,13 @@ Function shrinkPageContentNew() As Boolean
|
|||
Dim oPar As Object
|
||||
Dim startOfPara As Boolean
|
||||
Dim targetContent() As Object
|
||||
Dim delta As Double
|
||||
Dim rounds As Integer
|
||||
delta = 0.1
|
||||
rounds = 3
|
||||
Dim i As Integer
|
||||
Dim j As Integer
|
||||
shrinkPageContent = false
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
|
||||
configureCursorPositionForContentShrink()
|
||||
|
@ -1327,13 +1276,88 @@ Function shrinkPageContentNew() As Boolean
|
|||
Exit Function
|
||||
EndIf
|
||||
initPageNum = oViewcursor.getPage()
|
||||
initPosition = getShrinkPageContentInitPosition()
|
||||
initPosition = breakParaAtCursor()
|
||||
oViewcursor.goToRange(initPosition,false)
|
||||
oViewCursor.JumpToPreviousPage(false)
|
||||
oViewCursor.jumpToStartOfPage()
|
||||
startPosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
targetContent = selectContentToShrink(initPosition,startPosition)
|
||||
'TODO: Уменьшая отступы каждого параграфа от и до следующего
|
||||
' а также уменьшая кернинг, межстрочное расстояние и кегль
|
||||
For j = 0 To rounds
|
||||
For i = LBound(targetContent) To Ubound(targetContent)
|
||||
If (j > 0) Then
|
||||
decreaseContentCharHeight(targetContent(i), delta)
|
||||
EndIf
|
||||
If shrinkContentWithKerning(targetContent(i)) Then
|
||||
balanceContentTail(targetContent(i))
|
||||
EndIf
|
||||
If isShrinkPageSucceded(initPosition, initPageNum) Then
|
||||
Exit Function
|
||||
EndIf
|
||||
Next i
|
||||
Next j
|
||||
For i = LBound(targetContent) To Ubound(targetContent)
|
||||
shrinkContentSpacing(targetContent(i))
|
||||
If isShrinkPageSucceded(initPosition, initPageNum) Then
|
||||
Exit Function
|
||||
EndIf
|
||||
Next i
|
||||
For i = LBound(targetContent) To Ubound(targetContent)
|
||||
increaseContentCharHeight(targetContent(i), delta * rounds )
|
||||
Next i
|
||||
|
||||
End Function
|
||||
|
||||
Sub decreaseContentCharHeight(oContent As Object, delta As double)
|
||||
Dim contentEnum As Object'paragraph enumeration
|
||||
Dim textContentElement As Object'current paragraph
|
||||
Dim curHeight As Double
|
||||
contentEnum = oContent.createEnumeration()
|
||||
Do While contentEnum.hasMoreElements()
|
||||
textContentElement = contentEnum.nextElement()
|
||||
curHeight = textContentElement.charHeight
|
||||
textContentElement.charHeight = roundHeight(curHeight) - delta
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Sub increaseContentCharHeight(oContent As Object, delta As double)
|
||||
Dim contentEnum As Object'paragraph enumeration
|
||||
Dim textContentElement As Object'current paragraph
|
||||
Dim curHeight As Double
|
||||
contentEnum = oContent.createEnumeration()
|
||||
Do While contentEnum.hasMoreElements()
|
||||
textContentElement = contentEnum.nextElement()
|
||||
curHeight = textContentElement.charHeight
|
||||
textContentElement.charHeight = roundHeight(curHeight) + delta
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Function roundHeight(nHeight) As Double
|
||||
Dim lHeight As Double
|
||||
Dim hHeight As Double
|
||||
lHeight = Int(nHeight)
|
||||
hHeight = Int(nHeight)
|
||||
|
||||
Dim i%
|
||||
i=1
|
||||
Do While lHeight < nHeight And hHeight < nHeight
|
||||
lHeight = + i/10 + 0.001
|
||||
hHeight = + (i+0.5)/10
|
||||
i=i+1
|
||||
Loop
|
||||
roundHeight=lHeight
|
||||
End Function
|
||||
|
||||
Function shrinkContentSpacing(oContent As Object) As Boolean
|
||||
' Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
shrinkContentSpacing = false
|
||||
If oContent.ParaTopMargin > MIN_SPACING_TO_SHRINK Then
|
||||
oContent.ParaTopMargin = 0
|
||||
EndIf
|
||||
If oContent.ParaBottomMargin > MIN_SPACING_TO_SHRINK Then
|
||||
oContent.ParaTopMargin = 0
|
||||
EndIf
|
||||
End Function
|
||||
|
||||
Function selectContentToShrink(initPosition As Object, startPosition As Object)
|
||||
|
@ -1342,6 +1366,7 @@ Function selectContentToShrink(initPosition As Object, startPosition As Object)
|
|||
Dim startPageNum As Long
|
||||
Dim prevPageNum As Long
|
||||
Dim savePosition As Object
|
||||
Dim foundPrevPara As Boolean
|
||||
Dim targetContent() As Variant
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewcursor.goToRange(startPosition,false)
|
||||
|
@ -1349,10 +1374,6 @@ Function selectContentToShrink(initPosition As Object, startPosition As Object)
|
|||
oViewcursor.goToRange(initPosition,false)
|
||||
startPageNum = oViewcursor.getPage()
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
|
||||
'If Len(oTextCursor.String) > 0 Then
|
||||
' AddToArray(targetContent,oTextCursor.Text.createTextCursorByRange(oTextCursor))
|
||||
' EndIf
|
||||
Do While startPageNum = oViewcursor.getPage() OR prevPageNum = oViewcursor.getPage()
|
||||
savePosition = oTextCursor.getStart()
|
||||
oTextCursor.gotoStartOfParagraph(true)
|
||||
|
@ -1369,226 +1390,16 @@ Function selectContentToShrink(initPosition As Object, startPosition As Object)
|
|||
AddToArray(targetContent,oTextCursor.Text.createTextCursorByRange(oTextCursor))
|
||||
EndIf
|
||||
EndIf
|
||||
oTextCursor.gotoPreviousParagraph(false)
|
||||
foundPrevPara = oTextCursor.gotoPreviousParagraph(false)
|
||||
If (foundPrevPara = false) Then
|
||||
Exit Do
|
||||
EndIf
|
||||
oTextCursor.gotoEndOfParagraph(false)
|
||||
oViewCursor.goToRange(oTextCursor,false)
|
||||
Loop
|
||||
selectContentToShrink = targetContent
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Sub insertHardPageBreakIfNotOnPageBorder()
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
Dim pos1 As Integer
|
||||
Dim pos2 As Integer
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
If oTextCursor.isEndOfParagraph() Then
|
||||
pos1 = oViewCursor.getPage()
|
||||
oViewCursor.goRight(1,false)
|
||||
pos2 = oViewCursor.getPage()
|
||||
'If we moved right to the next para and page haven't changed insert pageBreak
|
||||
If pos1 = pos2 Then
|
||||
insertPageBreak
|
||||
End If
|
||||
Else
|
||||
insertPageBreak
|
||||
If Not IsNull(oTextCursor.ParaFirstLineIndent) Then
|
||||
oTextCursor.ParaFirstLineIndent = 0
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function shrinkKern(oTextCursor As Object, oViewCursor As Object,iterations As Integer) As Boolean
|
||||
Dim oParEnum As Object'paragraph enumeration
|
||||
Dim oPar As Object 'current paragraph
|
||||
Dim oSecEnum As Object'sections enumeration
|
||||
Dim oParSection As Object'paragraph text section
|
||||
Dim pageNum As Integer
|
||||
Dim i As Integer
|
||||
pageNum = oViewCursor.getPage()
|
||||
For i = 2 To iterations Step 2
|
||||
oParEnum = oTextCursor.createEnumeration()
|
||||
Do While oParEnum.hasMoreElements()
|
||||
oPar = oParEnum.nextElement()
|
||||
If oPar.supportsService("com.sun.star.text.Paragraph") Then
|
||||
oPar.CharKerning = 0 - i
|
||||
If pageNum <> oViewCursor.getPage() Then
|
||||
shrinkKern = true
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
Next i
|
||||
shrinkKern = false
|
||||
End Function
|
||||
|
||||
Function shrinkCharHeight(oTextCursor As Object, oViewCursor As Object, iterations As Integer) As Boolean
|
||||
Dim oParEnum As Object'paragraph enumeration
|
||||
Dim oPar As Object'current paragraph
|
||||
Dim oSecEnum As Object'sections enumeration
|
||||
Dim oParSection As Object'paragraph text section
|
||||
Dim pageNum As Integer
|
||||
Dim parCursor As Object
|
||||
Dim i As Integer
|
||||
pageNum = oViewCursor.getPage()
|
||||
For i = 1 To iterations Step 1
|
||||
oParEnum = oTextCursor.createEnumeration()
|
||||
Do While oParEnum.hasMoreElements()
|
||||
oPar = oParEnum.nextElement()
|
||||
If oPar.supportsService("com.sun.star.text.Paragraph") Then
|
||||
parCursor = oTextCursor.Text.createTextCursorByRange(oPar)
|
||||
parCursor.charHeight = roundHeight(parCursor.charHeight) - 0.1
|
||||
If pageNum <> oViewCursor.getPage() Then
|
||||
shrinkCharHeight = true
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
Next i
|
||||
shrinkCharHeight = false
|
||||
End Function
|
||||
|
||||
Function roundHeight(nHeight)
|
||||
Dim lHeight As Double
|
||||
Dim hHeight As Double
|
||||
lHeight = Int(nHeight)
|
||||
hHeight = Int(nHeight)
|
||||
|
||||
Dim i%
|
||||
i=1
|
||||
Do While lHeight < nHeight And hHeight < nHeight
|
||||
lHeight = + i/10 + 0.001
|
||||
hHeight = + (i+0.5)/10
|
||||
i=i+1
|
||||
Loop
|
||||
roundHeight=lHeight
|
||||
End Function
|
||||
|
||||
Function shrinkIntervalHeight(oTextCursor As Object ,oViewCursor As Object,iterations As Integer) As Boolean
|
||||
Dim oParEnum As Object 'paragraph enumeration
|
||||
Dim oPar As Object 'current paragraph
|
||||
Dim oSecEnum As Object 'sections enumeration
|
||||
Dim oParSection As Object 'paragraph text section
|
||||
Dim pageNum As Integer
|
||||
Dim lineSpacing As Object
|
||||
pageNum = oViewCursor.getPage()
|
||||
For i = 1 To iterations Step 1
|
||||
oParEnum = oTextCursor.createEnumeration()
|
||||
Do While oParEnum.hasMoreElements()
|
||||
oPar = oParEnum.nextElement()
|
||||
If oPar.supportsService("com.sun.star.text.Paragraph") Then
|
||||
lineSpacing = oPar.ParaLineSpacing
|
||||
If lineSpacing.Mode = 3 Then
|
||||
lineSpacing.Height = lineSpacing.Height * 0.98
|
||||
oPar.ParaLineSpacing = lineSpacing
|
||||
End If
|
||||
If pageNum <> oViewCursor.getPage() Then
|
||||
shrinkIntervalHeight = true
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
Next i
|
||||
shrinkIntervalHeight = false
|
||||
End Function
|
||||
|
||||
Sub savecursor()
|
||||
Dim oViewCursor As Object 'View cursor
|
||||
Dim oTextCursor As Object'Text cursor
|
||||
Dim oSaveEndSelection As Object 'Text cursor
|
||||
Dim oEnum As Object'Cursor enumeration
|
||||
Dim oText As Object'Text object in current document
|
||||
Dim oPar As Object'Current paragraph
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
REM oViewCursor.getText.insertString(oViewCursor.getStart(), CHR$(257), False)
|
||||
'If Not oViewCursor.jumpToPreviousPage() Then Exit Sub
|
||||
oViewCursor.jumpToPreviousPage()
|
||||
oViewCursor.jumpToStartOfPage()
|
||||
|
||||
'oViewCursor.goUp(10,true)
|
||||
'oViewCursor.getPage()
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
'oTextCursor.gotoStart(false)
|
||||
oTextCursor.gotoRange(oSaveEndSelection,true)
|
||||
|
||||
oParEnum = oTextCursor.createEnumeration()
|
||||
|
||||
Do While oParEnum.hasMoreElements()
|
||||
Dim oSubSection
|
||||
Dim oSecEnum
|
||||
|
||||
Do While oParEnum.hasMoreElements()
|
||||
oPar = oParEnum.nextElement()
|
||||
oPar.charScaleWidth = oPar.charScaleWidth - 1
|
||||
Dim charHeight
|
||||
charHeight= oPar.charHeight
|
||||
Dim lineSpacing
|
||||
lineSpacing = oPar.ParaLineSpacing
|
||||
MsgBox lineSpacing.Mode & lineSpacing.Height
|
||||
If oPar.supportsService("com.sun.star.text.Paragraph") Then
|
||||
nPars = nPars + 1
|
||||
oSecEnum = oPar.createEnumeration()
|
||||
s = s & nPars & ":"
|
||||
Do While oSecEnum.hasMoreElements()
|
||||
oParSection = oSecEnum.nextElement()
|
||||
oParSection.charScaleWidth = oParSection.charScaleWidth - 1
|
||||
oParSection.CharHeight = oParSection.CharHeight * 0.99
|
||||
s = s & oParSection.TextPortionType & " Scale " & oParSection.CharScaleWidth & " Scale " & oParSection.CharHeight & ":"
|
||||
Loop
|
||||
s = s & CHR$(10)
|
||||
If nPars MOD 10 = 0 Then
|
||||
MsgBox s, 0, "Paragraph Text Sections"
|
||||
s = ""
|
||||
End If
|
||||
End If
|
||||
Loop
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
|
||||
Sub splitPages
|
||||
Dim oViewCursor As Object 'View cursor
|
||||
Dim oText As Object 'Text object in current document
|
||||
Dim oSaveEndSelection As Object 'Text cursor
|
||||
'saveCurrentVersion
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
Dim saveFirstLineIndent As Boolean
|
||||
|
||||
'Check if we are at start of paragraph go to the end of previous paragraph
|
||||
If oViewCursor.Text.createTextCursorByRange(oViewCursor).isEndOfParagraph() Then
|
||||
oViewCursor.goRight(1,false)
|
||||
End If
|
||||
If oViewCursor.Text.createTextCursorByRange(oViewCursor).isStartOfParagraph() Then
|
||||
saveFirstLineIndent = true
|
||||
Else
|
||||
saveFirstLineIndent = false
|
||||
End If
|
||||
|
||||
oViewCursor.goRight(1,false)
|
||||
oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
'Select last 2 characters
|
||||
oViewCursor.goLeft(2,true)
|
||||
|
||||
If Len(oViewCursor.String) = 2 Then
|
||||
'Insert hyphen if needed
|
||||
oLastChars = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
insertHyphen()
|
||||
End If
|
||||
'Return to initial position
|
||||
oViewCursor.gotoRange(oSaveEndSelection,false) 'Go to end of text to check page changes
|
||||
oViewCursor.goLeft(1,false)
|
||||
insertPageBreak
|
||||
If Not saveFirstLineIndent Then
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
If Not IsNull(oTextCursor.ParaFirstLineIndent) Then
|
||||
oTextCursor.ParaFirstLineIndent = 0
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub insertPageBreak
|
||||
dim document as object
|
||||
dim dispatcher as object
|
||||
|
@ -1597,13 +1408,15 @@ Sub insertPageBreak
|
|||
dispatcher.executeDispatch(document, ".uno:InsertPagebreak", "", 0, Array())
|
||||
End Sub
|
||||
|
||||
Sub insertHyphen()
|
||||
dim document as object
|
||||
dim dispatcher as object
|
||||
Sub insertHyphen(twoCharactersToHyphen As Object)
|
||||
Dim oViewCursor As Object
|
||||
Dim document as Object
|
||||
Dim dispatcher as Object
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCursor.goToRange(twoCharactersToHyphen,false)
|
||||
document = ThisComponent.CurrentController.Frame
|
||||
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
|
||||
|
||||
rem ----------------------------------------------------------------------
|
||||
dim args1(21) as new com.sun.star.beans.PropertyValue
|
||||
args1(0).Name = "SearchItem.StyleFamily"
|
||||
args1(0).Value = 2
|
||||
|
|
Loading…
Add table
Reference in a new issue