| View previous topic :: View next topic |
| Author |
Message |
brown1050 General User

Joined: 17 Aug 2007 Posts: 17
|
Posted: Fri Sep 28, 2007 6:18 am Post subject: Placement of TV scripting text frame |
|
|
I use text frames to place leftside camera & shot notations in television scripts in which narration & dialog is on the right side of the page (I don't use columns; the template is formatted with left margins at 3.6" and the left side of the page is empty, except for where text frames are placed). The following sub creates the frame and places it perfectly beside the line where the cursor is located...but ONLY on the first page. If I call the sub (from a toolbar icon) when my cursor is on any other page, it places the text frame at the very bottom of the first page. I've tried every 'anchor' position, but none makes a difference. I'd appreciate information on how to fix this. Thanks!
Sub InsertScriptSidecar
Dim ScriptDoc As Object
Dim ScriptPage As Object
Dim ScriptCursor As Object
Dim ScriptFrame As Object
Dim ScriptFrameCursor As Object
Dim v
LocationCursor = ThisComponent.CurrentController.getViewCursor()
v = LocationCursor.getPosition()
'this returns cursor positions as v.X and v.Y (horizonal and vertical locations)
'that can be used in placing the text frame next to the paragraph where the cursor is
ScriptDoc = ThisComponent
ScriptCursor = ScriptDoc.Text.createTextCursor()
'to enable setting text frame borders as invisible
Dim FrameBorder(0) As New com.sun.star.table.BorderLine
FrameBorder(0).Color = RGB(0,0,0)
FrameBorder(0).InnerLineWidth = 0
FrameBorder(0).OuterLineWidth = 0
FrameBorder(0).LineDistance = 0
ScriptFrame = ScriptDoc.createInstance("com.sun.star.text.TextFrame")
ScriptFrame.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
'also tried AT_CHARACTER, AT_FRAME, AS_CHARACTER, AT_PAGE
With ScriptFrame
.TopMargin = 15
.BottomMargin = 15
.LeftMargin = 0
.RightMargin = 0
.TopBorder = FrameBorder(0)
.BottomBorder = FrameBorder(0)
.LeftBorder = FrameBorder(0)
.RightBorder = FrameBorder(0)
.HoriOrient = com.sun.star.text.HoriOrientation.NONE
.HoriOrientRelation = com.sun.star.text.RelOrientation.PAGE_FRAME
.HoriOrientPosition = 1900
.VertOrient = com.sun.star.text.VertOrientation.NONE
.VertOrientRelation = com.sun.star.text.RelOrientation.PAGE_FRAME
.VertOrientPosition = v.Y + 1600 'from the vertical position of the viewcursor
.Width = 6500
.Height = 1000
End With
ScriptDoc.Text.insertTextContent(ScriptCursor, ScriptFrame, False)
ScriptFrameCursor = ScriptFrame.createTextCursor()
With ScriptFrameCursor
.CharFontName = "Thorndale"
.CharHeight = 12
.charWeight = com.sun.star.awt.FontWeight.NORMAL
.charPosture = com.sun.star.awt.FontSlant.ITALIC
.paraAdjust = com.sun.star.style.ParagraphAdjust.LEFT
.String = " "
End With
End Sub
Again, this works perfectly on the first page, but on subsequent pages it places the text frame at the extreme bottom of the first page. Also, although the cursor remains in the body of the script, is there a way to place it within the text frame when the frame is created? Thank you. |
|
| Back to top |
|
 |
vitcaro OOo Advocate


Joined: 20 Feb 2007 Posts: 256 Location: Italy
|
Posted: Fri Sep 28, 2007 9:59 am Post subject: |
|
|
If I am not wrong, you do not set the position of ScriptCursor in your code:
| Code: |
ScriptDoc.Text.insertTextContent(ScriptCursor, ScriptFrame, False)
|
|
|
| Back to top |
|
 |
brown1050 General User

Joined: 17 Aug 2007 Posts: 17
|
Posted: Sat Sep 29, 2007 5:09 pm Post subject: Got even more complicated, but was solved...Thank you! |
|
|
You were right. I needed to set the position of the text cursor, but the solution was much more complicated. The cursor Y position (v.Y) is always returned from the top of the page on which the cursor sits. But the page heights are incremented with each new page. For instance, if the page height is 25,000, then by page 3 the height has augmented to 50,000 plus the Y position of the cursor. That is why the frame was always inserted on the first page (because the Y position was re-set for each page, but the page heights were not). So I had to account for the accumulated page heights...no problem...then discovered that if the cursor sat in a paragraph that had begun on the preceeding page, the frame would be inserted at the beginning of the paragraph. So I had to check for that, and if it was true, move the cursor to the next paragraph so the insert would be on the proper page. (It IS confusing) I was helped by Andrew Pitonyak's book on the paragraph checks. And, for the record, here is a sub that works:
Sub InsertScriptSidecar
Dim ScriptDoc As Object
Dim StyleFamilies As Object
Dim PageStyles As Object
Dim ScriptPage As Object
Dim ScriptCursor As Object
Dim ScriptFrame As Object
Dim ScriptFrameCursor As Object
Dim ParaFlag as Integer
Dim PageNum as Integer, CheckPage as Integer
Dim PageHeight, VerticalPos, TopAdd
Dim v
ParaFlag = 0
LocationCursor = ThisComponent.CurrentController.getViewCursor()
ScriptCursor=ThisComponent.getText().CreateTextCursorByRange(LocationCursor)
SaveLocation = ThisComponent.getText().createTextCursorByRange(LocationCursor) 'in case you want to return the cursor
'to its original location after inserting the text frame
v = LocationCursor.getPosition()
'this returns cursor positions as v.X and v.Y (horizonal and vertical locations)
'that can be used in placing the text frame next to the paragraph where the cursor is
ScriptDoc = ThisComponent
StyleFamilies = ScriptDoc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
ScriptPage = PageStyles.getByName("Default")
'v.Y is incremental: it doesn't reset to zero for each new page, but accumulates by adding each page length
'to the next; for instance, if you're on page three, v.Y would produce a number that is the total height of
'the first two pages, plus the height of the y position on the third page. Therefore, you must get the PageHeight;
'find the page number, and subtract the incremental (total) height of all pages
'in order to get the vertical position on the page where you wish to place the frame;
'otherwise its vertical position will be at the top or bottom of the preceeding page
PageHeight = ScriptPage.Height
PageNum = LocationCursor.getPage()
VerticalPos = v.Y - ((PageNum - 1) * PageHeight)
Select Case PageNum
'Don't know why, but as the pages increment, the frame top position shifts slightly
'so I add a little to it
Case 1
TopAdd = 1500
Case 2
TopAdd = 1000
Case 3
TopAdd = 675
Case Else
TopAdd = 600
End Select
ScriptFrame = ScriptDoc.createInstance("com.sun.star.text.TextFrame")
'If the cursor is in a paragraph that begins on the preceeding page, the frame will
'be inserted on the preceeding page at v.Y unless you move the cursor to the next paragraph
'Therefore, go to the beginning of the paragraph and check what page you're on
If NOT ScriptCursor.isStartOfParagraph() Then
ScriptCursor.gotoStartOfParagraph(False)
LocationCursor.gotoRange(ScriptCursor, False)
End If
CheckPage = LocationCursor.getPage()
'If the paragraph begins on the same page, then go ahead and insert the frame
If CheckPage = PageNum Then
ScriptCursor.gotoRange(LocationCursor, False)
ScriptDoc.Text.insertTextContent(ScriptCursor, ScriptFrame, False)
Else
'if the paragraph begins on the preceeding page, go to the NEXT paragraph (the one that
'begins on the page where you're inserting the frame) and insert the frame
ParaFlag = 1
If NOT ScriptCursor.isEndOfParagraph() Then
ScriptCursor.gotoEndOfParagraph(False)
LocationCursor.gotoRange(ScriptCursor, False)
LocationCursor.goRight(1, False)
End If
ScriptCursor.gotoRange(LocationCursor, False)
ScriptDoc.Text.insertTextContent(ScriptCursor, ScriptFrame, False)
End If
Dim FrameBorder(0) As New com.sun.star.table.BorderLine
With FrameBorder(0)
.Color = RGB(0,0,0)
.InnerLineWidth = 0
.OuterLineWidth = 0
.LineDistance = 0
End With
With ScriptFrame
.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE 'also AT_CHARACTER, AT_FRAME, AS_CHARACTER, AT_PARAGRAPH, AT_PAGE
.TopMargin = 15
.BottomMargin = 25
.LeftMargin = 0
.RightMargin = 0
.BorderDistance = 0
.HoriOrient = com.sun.star.text.HoriOrientation.NONE 'LEFT
.HoriOrientRelation = com.sun.star.text.RelOrientation.PAGE_FRAME
.HoriOrientPosition = 1900
.VertOrient = com.sun.star.text.VertOrientation.NONE
.VertOrientRelation = com.sun.star.text.RelOrientation.PAGE_FRAME 'also FRAME (for para), TEXT_LINE, and CHAR
.VertOrientPosition = VerticalPos + TopAdd
.Width = 6500
.Height = 1000
.TopBorder = FrameBorder(0)
.BottomBorder = FrameBorder(0)
.LeftBorder = FrameBorder(0)
.RightBorder = FrameBorder(0)
End With
ScriptFrameCursor = ScriptFrame.createTextCursor()
With ScriptFrameCursor
.CharFontName = "Thorndale"
.CharHeight = 12
.charWeight = com.sun.star.awt.FontWeight.NORMAL
.charPosture = com.sun.star.awt.FontSlant.ITALIC
.paraAdjust = com.sun.star.style.ParagraphAdjust.LEFT
.String = " "
End With
'This places the cursor in the Text Frame; see below for alternate option
LocationCursor.gotoRange(ScriptFrameCursor, False)
'If you've moved the cursor to another paragraph so the frame insert will be
'properly positioned, put the cursor back where it was when you started this
'If ParaFlag = 1 Then LocationCursor.gotoRange(SaveLocation, False)
End Sub
'************************************************* |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|