On 2009-09-29 20:36 Andrew Douglas Pitonyak wrote:
On 09/28/2009 06:59 PM, Eustace wrote:
On 2009-09-28 07:54 Eustace wrote:
How can I make a macro to increase or decrease the font size of a
document by a certain percent (f.e. 10%)?
emf
I recorded a macro to change the font size from 12 to 13 and then
opened it to edit it. I found the following relevant lines:
======================================================================
sub IncreaseFontSize
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(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FontHeight.Height"
args1(0).Value = 13
args1(1).Name = "FontHeight.Prop"
args1(1).Value = 100
args1(2).Name = "FontHeight.Diff"
args1(2).Value = 0
dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args1())
end sub
======================================================================
args2(0).Value is the resulting font size. Instead of
args1(0).Value = 13
I suppose I need something like:
args1(0).Value = getFontHeight() * 1.1
Actually I tried to replace the code as above, but the result was that
font size 12 became font size 2...
How do I get the current font size and then increase it?
And BTW what are the FontHeight.Prop, and FontHeight.Diff?
emf
This macro is tricky for many reasons
First, the macro works on the selected text. You would need to obtain
the font size, but what if different portions uses different font sizes?
The following macro is not very safe because it assumes that things are
the same everywhere.
Dim oSels As Object, oSel As Object
Dim lSelCount As Long, lWhichSelection As Long
oSels = ThisComponent.getCurrentSelection()
If IsNull(oSels) Then
Exit Sub
End If
If oSels.getCount() = 0 Then
Exit Sub
End If
oSel = oSels.getByIndex(0)
lSelCount = oSels.getCount()
For lWhichSelection = 0 To lSelCount - 1
oSel = oSels.getByIndex(lWhichSelection)
oSel.CharHeight = oSel.CharHeight * 1.1
Next
You may not like this because it will take you from 12 to 13.1 I believe.
The following converts to an integer, which may not be what you want:
Dim oSels As Object, oSel As Object
Dim lSelCount As Long, lWhichSelection As Long
oSels = ThisComponent.getCurrentSelection()
If IsNull(oSels) Then
Exit Sub
End If
If oSels.getCount() = 0 Then
Exit Sub
End If
oSel = oSels.getByIndex(0)
lSelCount = oSels.getCount()
For lWhichSelection = 0 To lSelCount - 1
oSel = oSels.getByIndex(lWhichSelection)
oSel.CharHeight = CInt(oSel.CharHeight * 1.1)
Next
This may be enough to get you started.
Thanks. The first is what I want. I'll have to make sure that all the
document uses the same font when I start. And I will have to add in the
beginning a command to select the whole text of the document, and at the
end to go to the beginning of the document. If I have any problems I'll
will post here again. BTW what is this language? Once upon a time I had
learned to use the language for WP macros...
emf
--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/itaintmebabe/itaintme.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]