Simple test creates a Writer document with some boxed text based on an array of strings. Put in a module and run test 1
Code: Select all
' ╔══════════════════╗
' ║This is an example║
' ║ of box drawing. ║
' ╚══════════════════╝
sub test1
oDoc = Stardesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0,Array())
wait 200
odoc.currentcontroller.componentwindow.setfocus
'font needs to be non proportional and support then unicode box characters.
'not "Courier New" is a Windows font
oDoc.currentcontroller.viewcursor.charfontname ="Courier New"
sarray=array("This is an example"," of box drawing. ")
'boxchars = "┌─┐││└─┘"
boxchars ="╔═╗║║╚═╝"
'boxchars ="░░░░░░░░"
'boxchars ="▓▓▓▓▓▓▓▓"
'boxchars ="████████"
'boxchars ="$$$$$$$$"
'boxchars ="▓▓▓▓▓▓▓▓"
'boxchars ="@@@@@@@@"
boxRoundStringArray(odoc,sarray,boxchars ,"' ")
end sub
sub boxRoundStringArray(doc,sarray,boxchars ,prestring)
for i = 0 to ubound(sarray)
leni= len(sarray(i))
if leni >mx then mx = leni
next
otext = doc.gettext
tc = otext.createtextcursorbyrange(otext.getstart)
tc.string =prestring & mid(boxchars,1,1) & string(mx,mid(boxchars,2,1)) & mid(boxchars,3,1)
tc.collapsetoend
oText.insertControlCharacter(tc, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
for i = 0 to ubound(sarray)
st =prestring & mid(boxchars,4,1) & sarray(i)
v = mx-len(sarray(i))
if v>0 then st = st & string(v," ")
st =st & mid(boxchars,5,1)
tc.string = st
tc.collapsetoend
oText.insertControlCharacter(tc, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
next
tc.string =prestring & mid(boxchars,6,1) & string(mx,mid(boxchars,7,1)) & mid(boxchars,8,1)
end sub
Code: Select all
sub test2
'┌───────────────────────────────────┐
'│Call insertSpacedlines │
'│in a Writer document │
'│to add some lines full │
'│of spaces. Write something │
'│using overtype mode. │
'│Use BLK select mode to │
'│select round it. Then choose │
'│a pattern and call drawboxBlKSel. │
'│A non-proportional font will be │
'│needed. │
'└───────────────────────────────────┘
'
boxchars = "┌─┐││└─┘"
'boxchars ="╔═╗║║╚═╝"
'boxchars ="░░░░░░░░"
'boxchars ="▓▓▓▓▓▓▓▓"
'boxchars ="████████"
'boxchars ="$$$$$$$$"
'boxchars ="▓▓▓▓▓▓▓▓"
'boxchars ="@@@@@@@@"
insertSpacedlines(20,40) 'CALL THIS FIRST IN A NEW WRITER DOCUMENT
'select a rectangle using BLK select mode
'THEN COMMENT OUT that line and uncomment the below line and run
'
' drawboxBlKSel boxchars
end sub
sub insertSpacedlines(no,width)
st=string(width," ")
otext=thiscomponent.text
tc = otext.createtextcursorbyrange(otext.getend)
for i= 1 to no
tc.string =st
tc.collapsetoend
oText.insertControlCharacter(tc, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
next
end sub
Sub DrawBoxBlKSel(boxchars as string)
dim boo as boolean
on error resume next
w = thiscomponent.currentcontroller.frame.componentwindow.windows(0).accessiblecontext.getaccessiblechild(0).accessiblecontext.getaccessiblechild(0)
for i = 0 to w.accessiblecontext.getaccessiblechildcount -1
a =w.accessiblecontext.getaccessiblechild(i)
with a
if .getselectionstart <> -1 then
if not boo then
boo = true
startline =i
end if
.replacetext .getselectionstart ,.getselectionstart+1,mid(boxchars,4,1)
.replacetext .getselectionend -1 ,.getselectionend,mid(boxchars,5,1)
endline=i
end if
end with
next
a =w.accessiblecontext.getaccessiblechild(startline)
with a
.replacetext .getselectionstart ,.getselectionstart+1,mid(boxchars,1,1)
.replacetext .getselectionend -1 ,.getselectionend,mid(boxchars,3,1)
st = string(.getselectionend-.getselectionstart-2,mid(boxchars,2,1)
.replacetext .getselectionstart+1,.getselectionend -1,st
end with
a =w.accessiblecontext.getaccessiblechild(endline)
with a
.replacetext .getselectionstart ,.getselectionstart+1,mid(boxchars,6,1)
.replacetext .getselectionend -1 ,.getselectionend,mid(boxchars,8,1)
st = string(.getselectionend-.getselectionstart-2,mid(boxchars,7,1))
.replacetext .getselectionstart+1,.getselectionend -1,st
end with
hr:
End Sub