2009/9/30 Andrew Douglas Pitonyak <[email protected]>: > 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.
So this makes the fonts 10% larger, right? Why not just increase the size by one (oSel.CharHeight + 1) instead? Are there other reasons than the fact that most people maybe want HightOfFont1/HightOfFont2 to always be the same, which won't happen otherwise? J.R. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
