diff --git a/ePublishing/Footnotes.xba b/ePublishing/Footnotes.xba index 61365a8..1f1df6c 100644 --- a/ePublishing/Footnotes.xba +++ b/ePublishing/Footnotes.xba @@ -141,4 +141,4 @@ Private Sub doNotTrack args1(0).Value = true dispatcher.executeDispatch(document, ".uno:ShowTrackedChanges", "", 0, args1()) End Sub - + \ No newline at end of file diff --git a/ePublishing/journals.xba b/ePublishing/journals.xba index fba65dc..23deda6 100644 --- a/ePublishing/journals.xba +++ b/ePublishing/journals.xba @@ -1,6 +1,6 @@ -Private sub journalsMark3 +Private sub journalsMark5 End sub Dim templateName As String @@ -139,6 +139,7 @@ Private Sub makeUpIssue 'ThisComponent.FootnoteSettings.FootnoteCounting=1 'setHeadingsOutlineLevels statusIndicator.end() + MsgBox "Сборка выпуска завершена." End Sub Private Sub setPageNumbers() @@ -690,7 +691,6 @@ Private Sub takeDownOrpahns End Sub Private Sub takeLineIn - Globalscope.BasicLibraries.LoadLibrary( "Publishing" ) Dim oViewCursor As Object Dim oTextCursor As Object dim oEndPage As Object @@ -1074,8 +1074,6 @@ Private Sub updateLastPageFields statusIndicator.end() End Sub - - Function insertUserField(cursor,fieldName,fieldValue) Dim oField As Object 'Field to insert Dim oFieldMaster As Object @@ -1096,5 +1094,530 @@ Function insertUserField(cursor,fieldName,fieldValue) oTextCursor.Text.insertTextContent(oTextCursor, oField, False) End Function +Function updateUserField(fieldName,fieldValue) + Dim oFieldMaster As Object + Dim oMasters As Object + oMasters = ThisComponent.getTextFieldMasters() + If oMasters.hasByName("com.sun.star.text.FieldMaster.User" & "." & fieldName) Then + oFieldMaster = oMasters.getByName("com.sun.star.text.FieldMaster.User" & "." & fieldName) + oFieldMaster.Content = fieldValue + EndIf +End Function + +Sub createPageStyleByExample(newName) + dim document as object + dim dispatcher as object + document = ThisComponent.CurrentController.Frame + dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + dim args1(1) as new com.sun.star.beans.PropertyValue + args1(0).Name = "Param" + args1(0).Value = newName + args1(1).Name = "Family" + args1(1).Value = 8 + dispatcher.executeDispatch(document, ".uno:StyleNewByExample", "", 0, args1()) +end Sub + +sub sendRM + dim document as Object + dim dispatcher as Object + document = ThisComponent.CurrentController.Frame + dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + dispatcher.executeDispatch(document, ".uno:Delete", "", 0, Array()) +end Sub + +sub backspace + dim document as object + dim dispatcher as object + document = ThisComponent.CurrentController.Frame + dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array()) +end Sub +Sub shrinkPageContent + Dim oViewCursor As Object 'View cursor + Dim oTextCursor As Object 'Text cursor + Dim oViewCurInitPosition As Object + Dim oSaveEndSelection 'Text cursor + Dim oEnum 'Cursor enumeration + Dim oPar 'Current paragraph + Dim sTextContent$ 'Service name for text content. + Dim scaleWidthShrinkValue As Integer + Dim scaleCharHeight As Integer + Dim scaleIntervalHeight As Integer + Dim kernShrinkValue As Integer + Dim startOfPara As Boolean + 'saveCurrentVersion + kernShrinkValue = 8 + scaleWidthShrinkValue = 7 + scaleCharHeight = 2 + scaleIntervalHeight = 3 + sTextContent = "com.sun.star.text.TextContent" + oViewCursor = ThisComponent.CurrentController.getViewCursor() + oViewCurInitPosition = oViewcursor.Text.createTextCursorByRange(oViewCursor) + 'Check if we are at start of paragraph go to the end of previous paragraph + If oViewCursor.Text.createTextCursorByRange(oViewCursor).isStartOfParagraph() Then + oViewCursor.goLeft(1,false) + If Len(oViewCursor.String) <> 1 Then + oViewCursor.goRight(1,false) + End If + End If + + + 'Move right to select left and right characters and save position to the right + oViewCursor.goRight(1,false) + oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor) + 'Select last 2 characters + oViewCursor.goLeft(2,true) + If Len(oViewCursor.String) = 2 Then + oLastChars = oViewCursor.Text.createTextCursorByRange(oViewCursor) + 'Insert hyphen if needed + insertHyphen(oLastChars,oViewCursor) + End If + 'Return to initial position + oViewCursor.gotoRange(oSaveEndSelection,false) 'Go to end of text to check page changes + oViewCursor.goLeft(1,false) + 'Set saved position to initial state + oSaveEndSelection = oViewCursor.Text.createTextCursorByRange(oViewCursor) + + + oViewCursor.jumpToPreviousPage() + oViewCursor.jumpToStartOfPage() + oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor) + '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") Then + shrinkPageContent = false + oViewCursor.gotoRange(oViewCurInitPosition,false) + Exit Sub + EndIf + If oSaveEndSelection.Text.supportsService("com.sun.star.text.Endnote") OR oSaveEndSelection.Text.supportsService("com.sun.star.text.Footnote") Or oTextCursor.Text.supportsService("com.sun.star.text.CellProperties") Then + shrinkPageContent = false + oViewCursor.gotoRange(oViewCurInitPosition,false) + Exit Sub + EndIf + oTextCursor.gotoRange(oSaveEndSelection,true) + oViewCursor.gotoRange(oSaveEndSelection,false) 'Go to end of text to check page changes + + If shrinkIntervalHeight(oTextCursor,oViewCursor,scaleIntervalHeight) Then + 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 + + Exit Sub + End If + If shrinkCharHeight(oTextCursor,oViewCursor,scaleCharHeight) Then + 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 + + Exit Sub + End If + If shrinkKern(oTextCursor,oViewCursor,kernShrinkValue) Then + 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 + + Exit Sub + End If + + +End Sub + +Sub splitPages + Dim oViewCursor As Object 'View cursor + Dim oText 'Text object in current document + Dim oSaveEndSelection '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(oLastChars,oViewCursor) + 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 + + + + + +Function shrinkScaleWidth(oTextCursor,oViewCursor,iterations) As Boolean + Dim oParEnum 'paragraph enumeration + Dim oPar 'current paragraph + Dim oSecEnum 'sections enumeration + Dim oParSection 'paragraph text section + Dim pageNum 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 + oPar.charScaleWidth = 100 - i + If pageNum <> oViewCursor.getPage() Then + shrinkScaleWidth = true + Exit Function + End If + End If + Loop + Next i + shrinkScaleWidth = false +End Function + +Function shrinkKern(oTextCursor,oViewCursor,iterations) As Boolean + Dim oParEnum 'paragraph enumeration + Dim oPar 'current paragraph + Dim oSecEnum 'sections enumeration + Dim oParSection 'paragraph text section + Dim pageNum 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,oViewCursor,iterations) As Boolean + Dim oParEnum 'paragraph enumeration + Dim oPar 'current paragraph + Dim oSecEnum 'sections enumeration + Dim oParSection 'paragraph text section + Dim pageNum 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 + oPar.charHeight = roundHeight(oPar.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,oViewCursor,iterations) As Boolean + Dim oParEnum 'paragraph enumeration + Dim oPar 'current paragraph + Dim oSecEnum 'sections enumeration + Dim oParSection 'paragraph text section + Dim pageNum As Integer + Dim lineSpacing + 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 'Text cursor + Dim oSaveEndSelection 'Text cursor + Dim oEnum 'Cursor enumeration + Dim oText 'Text object in current document + Dim oPar 'Current paragraph + Dim sTextContent$ 'Service name for text content. + sTextContent = "com.sun.star.text.TextContent" + 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 insertPageBreak + rem ---------------------------------------------------------------------- + rem define variables + dim document as object + dim dispatcher as object + rem ---------------------------------------------------------------------- + rem get access to the document + document = ThisComponent.CurrentController.Frame + dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + + rem ---------------------------------------------------------------------- + dispatcher.executeDispatch(document, ".uno:InsertPagebreak", "", 0, Array()) + + +end sub + +Sub insertHyphen(oTextCursor,oViewCursor) + Dim lastChars + 'lastChars = oTextCursor.getString() + replacementhyp + 'MsgBox lastChars +End Sub + +sub replacementhyp + rem ---------------------------------------------------------------------- + rem define variables + dim document as object + dim dispatcher as object + rem ---------------------------------------------------------------------- + rem get access to the document + 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 + args1(1).Name = "SearchItem.CellType" + args1(1).Value = 0 + args1(2).Name = "SearchItem.RowDirection" + args1(2).Value = true + args1(3).Name = "SearchItem.AllTables" + args1(3).Value = false + args1(4).Name = "SearchItem.SearchFiltered" + args1(4).Value = false + args1(5).Name = "SearchItem.Backward" + args1(5).Value = false + args1(6).Name = "SearchItem.Pattern" + args1(6).Value = false + args1(7).Name = "SearchItem.Content" + args1(7).Value = false + args1(8).Name = "SearchItem.AsianOptions" + args1(8).Value = false + args1(9).Name = "SearchItem.AlgorithmType" + args1(9).Value = 1 + args1(10).Name = "SearchItem.SearchFlags" + args1(10).Value = 71680 + args1(11).Name = "SearchItem.SearchString" + args1(11).Value = "([a-zA-Zа-яА-Я])([a-zA-Zа-яА-Я])" + args1(12).Name = "SearchItem.ReplaceString" + args1(12).Value = "$1­$2" + args1(13).Name = "SearchItem.Locale" + args1(13).Value = 255 + args1(14).Name = "SearchItem.ChangedChars" + args1(14).Value = 2 + args1(15).Name = "SearchItem.DeletedChars" + args1(15).Value = 2 + args1(16).Name = "SearchItem.InsertedChars" + args1(16).Value = 2 + args1(17).Name = "SearchItem.TransliterateFlags" + args1(17).Value = 1024 + args1(18).Name = "SearchItem.Command" + args1(18).Value = 3 + args1(19).Name = "SearchItem.SearchFormatted" + args1(19).Value = false + args1(20).Name = "SearchItem.AlgorithmType2" + args1(20).Value = 2 + args1(21).Name = "Quiet" + args1(21).Value = true + + dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1()) + + +end sub +sub saveCurrentVersion + rem ---------------------------------------------------------------------- + rem define variables + dim document as object + dim dispatcher as object + rem ---------------------------------------------------------------------- + rem get access to the document + document = ThisComponent.CurrentController.Frame + dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") + + rem ---------------------------------------------------------------------- + dim args1(0) as new com.sun.star.beans.PropertyValue + args1(0).Name = "VersionComment" + args1(0).Value = "Вставка разрыва страниц" + + dispatcher.executeDispatch(document, ".uno:Save", "", 0, args1()) + +end sub + +Sub removeEmptyPage + + Dim oViewCursor As Object + oViewCursor = ThisComponent.CurrentController.getViewCursor() + oViewCursor.jumpToStartOfPage() + Dim oTextCursor As Object + oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor) + oViewCursor.jumpToEndOfPage() + oViewCursor.goToRange(oTextCursor,true) + + If oViewCursor.isCollapsed Then + oViewCursor.goLeft(1,false) + SendRM() + Else + oViewCursor.jumpToEndOfPage() + + End If + oViewCursor.collapseToEnd() + +End Sub + +Function getPageStyleNameFromEnum(enumElement) + If enumElement.pageDescName = "" AND Not IsEmpty(enumElement.getPropertyValue("PageStyleName")) Then + getPageStyleNameFromEnum = enumElement.pageStyleName + Else + getPageStyleNameFromEnum = enumElement.pageDescName + EndIf +End Function + +Function getPageNumber(cursor) + Dim oField 'Field to insert + oTextCursor = cursor.Text.createTextCursorByRange(cursor.Start) + oField = ThisComponent.createInstance("com.sun.star.text.textfield.PageNumber") + oField.NumberingType = 4 + oField.SubType = com.sun.star.text.PageNumberType.CURRENT + oTextCursor.Text.insertTextContent(oTextCursor, oField, False) + getPageNumber = oField.getPresentation(false) + oTextCursor.Text.removeTextContent(oField) +End Function + \ No newline at end of file diff --git a/ePublishing/script.xlb b/ePublishing/script.xlb index 5953b87..31ded4f 100644 --- a/ePublishing/script.xlb +++ b/ePublishing/script.xlb @@ -5,4 +5,4 @@ - + \ No newline at end of file