Hi!
I want to write script that randomly (from range i specify) changes size and font for every letter in the document. But i have no experience of writing such scripts at all . Please can someone help with this idea? (and sorry my English)
[Solved] Random font and size for letters
[Solved] Random font and size for letters
Last edited by Bondrenko on Mon Apr 22, 2013 12:16 am, edited 1 time in total.
Debian 6.0. OOo 3.2.1
-
- Posts: 56
- Joined: Thu Apr 22, 2010 5:03 am
Re: Random font and size for letters
Hi...
In Calc or Writer?... in Basic or Python?...
Best regards
In Calc or Writer?... in Basic or Python?...
Best regards
______________________________________________
Everything not given is lost
AOO 4.1 / LibO 4.3 on ArchLinux with Gnome3
Please, I do not answer private questions, you use the forum
Everything not given is lost
AOO 4.1 / LibO 4.3 on ArchLinux with Gnome3
Please, I do not answer private questions, you use the forum
Re: Random font and size for letters
Hi! Thanks for your reply!
Writer. Basic is more preferable.
Writer. Basic is more preferable.
Debian 6.0. OOo 3.2.1
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Random font and size for letters
I'm not clear on what you mean by a specified range, but, despite some problems to be mentioned, this might be a start.
This gets all the installed fonts, as an array of FontDescriptors. This will include such things as math and symbol fonts, and non-Latin alphabets, so it may include many more things than you want.
Then we can scan a text character-by-character, and randomly change the size and font of each
Apart from the use of the horrible Basic Rnd() function, the main problem I'm having with this is that the cursor seems to move extremely slowly as it proceeds into a paragraph, so this takes a long time to run on even a fairly short document. I might be missing something that others could spot.
This is roughly based on something I've done before, and I want to try it in another language to see if it has the same problems.
This gets all the installed fonts, as an array of FontDescriptors. This will include such things as math and symbol fonts, and non-Latin alphabets, so it may include many more things than you want.
Code: Select all
Function getFontList()
Dim w As Object
Dim dev As Object
Dim FontList
w = ThisComponent.CurrentController.Frame.ComponentWindow
dev = w.createDevice(100,100) 'Size (100, 100) is arbitrary
FontList = dev.getFontDescriptors()
getFontList = FontList
End Function
Code: Select all
Sub JumbleLetters()
Dim oDoc As Object
Dim oText As Object
Dim oCursor As Object
Dim MoreText As Boolean
Dim u As Long
Dim FontList
oDoc = ThisComponent
oText = oDoc.Text
FontList = getFontList()
u = UBound(FontList)
oCursor = oText.createTextCursor()
oCursor.gotoStart(False)
MoreText = oCursor.goRight(1,True)
do while MoreText
oCursor.CharHeight = Rnd()*24
oCursor.CharFontName = FontList(Int(Rnd()* u)).Name
oCursor.collapseToEnd()
MoreText = oCursor.goRight(1,True)
loop
End Sub
This is roughly based on something I've done before, and I want to try it in another language to see if it has the same problems.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Random font and size for letters
Charlie Young, thanks a lot! It works great!
But is there a way to select not all but some fonts i only need? for example only Times new roman, Arial and Dejavy sans and variety of their sizes between 12 and 17?
But is there a way to select not all but some fonts i only need? for example only Times new roman, Arial and Dejavy sans and variety of their sizes between 12 and 17?
Debian 6.0. OOo 3.2.1
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Random font and size for letters
That is simpler, I think. There are various ways to deal with the sizes in this case, but I'll just apply the same thing I'm doing with the fonts. Put as many font names and sizes as you want in the Array() statements. There need not be the same number of each.Bondrenko wrote:
But is there a way to select not all but some fonts i only need? for example only Times new roman, Arial and Dejavy sans and variety of their sizes between 12 and 17?
Code: Select all
Sub JumbleLetters2()
Dim oDoc As Object
Dim oText As Object
Dim oCursor As Object
Dim MoreText As Boolean
Dim nList As Long, nSize As Long
Dim FontList, FontSize
oDoc = ThisComponent
oText = oDoc.Text
FontList = Array("Arial","Times New Roman","DejaVu Sans","Century Gothic")
FontSize = Array(12,13,13.5,14,16.2,17)
nList = UBound(FontList)
nSize = UBound(FontSize)
MoreText = True
oCursor = oText.createTextCursor()
oCursor.gotoStart(False)
MoreText = oCursor.goRight(1,True)
do while MoreText
oCursor.CharHeight = FontSize(Int(Rnd()* nSize))
oCursor.CharFontName = FontList(Int(Rnd()* nList))
oCursor.collapseToEnd()
MoreText = oCursor.goRight(1,True)
loop
End Sub
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Random font and size for letters
Charlie Young you are my savior.
Exactly what i need! Thank you very much! =)
Exactly what i need! Thank you very much! =)
Debian 6.0. OOo 3.2.1