How to "increase/decrease font size" with smaller steps?

as far as I see the “increase font” and “decrease font” buttons work in steps of 2…

I mean, if you select a line which has a 12 height and click those two buttons you get “14, 16, 18 etc.” with “increase font” and “10, 8, 6 etc.” with the “decrease font”

now I’m working on a macro trying to have a fine tuning with “increase font” and “decrease font” working with 0.5 steps…

I mean “12, 12.5, 13 etc.” or “11.5, 11, 10.5 etc.”

so I recorded the current “increase font” button action with the macro recorder and obtained this code:

sub test
dim document as object
dim dispatcher as object

document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, “.uno:Grow”, “”, 0, Array())
end sub

is there any way I can tweak the code in order to have an “.uno:Grow” increase in steps of 0.5 instead of the current steps of 2?

There is a very limited catalog of uno commands the dispatch helper can execute. If the command doesn’t accept parameters via a property array there are none (hard coded constants only). Otherwise the recorder would create and pass the properties. (No guarantee! I’m not a developer.)

What you want to achieve is, however, simple for selected text of uniform CharHeight. If theCharHeight (font size) is different for respective portions of the selected text, the action by the code posted below may be undefined. In my experiments the CharHeight was set to the value 2 then. Surely not what you want. To get it correctly done under this condition you would need to parse through the textportions.

Sub increaseCharHeightByChStep()
	Const cHstep = 0.5 
	REM Should be defined for the module header. You then can set it by a dedicated Sub.
theVC = ThisComponent.CurrentController.ViewCursor
theVC.CharHeight = theVC.CharHeight + cHstep
End Sub  

(Editing:)
Contradicting my comment below and confessing my noisome curiosity: Problem solved. Code:

Sub lookForMaxCharHeightInCurrentSelection()
REM Based on the code by "FJCC" from 
REM https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=77875&p=356394&hilit=viewcursor#p356394 
REM NO ERROR CATCHING AT ALL! Crude code! 
currentMaxCH = 0
theSel = ThisComponent.CurrentSelection
theSel0 = theSel.GetByIndex(0)
theEnum= theSel0.CreateEnumeration
Do While theEnum.HasMoreElements
	oneElement = TheEnum.NextElement
	oneSubEnum    = oneElement.CreateEnumeration
	Do While oneSubEnum.HasMoreElements
		oneSubElement = oneSubEnum.NextElement
		If oneSubElement.CharHeight>currentMaxCH Then currentMaxCH = _ 
		                                      oneSubElement.CharHeight
	Loop
Loop
MsgBox("The maximum CharHeight inside the CurrentSelection is: " & currentMaxCH)
End Sub

thank, the issue happen when you deal with different font size lines. I think the CharHeight doesn’t know which value to record and returns a 0 (but LibO gives it a “2” value since this is the smallest font size available).

how could I take the larger font size of the text selection then apply it to all lines to make the taxt uniform, and finally apply your code to do the “magic” ?

ViewCursor is the object knowing what is selected. Its property ‘CharHeight’ hasn’t a value at all if not the complete selection is uniform in this respect. To get the maximum occurring inside the selection you need to go through all the ‘TextPiece’ to find therein. That’s supposed to be annoying, but feasible as soon as you have the content of the selection as an object supporting the enumeration of subdivisions. I don’t know a way to get such an object, and will not do further research.

The ‘Text’ property of the ViewCursor is the complete text of the document (not including text contained in objects of the DrawPage). You need a cut-out part.
If you want to do the necessary research youself you may start with the API reference.
Valuable hints and examples of API usage in LibO (Star-) BASIC you will find in the famous texts by Andrew Pitonyak accessible from this webpage.

great. thanks for working on that code.

now the macro is fully functional on text selection with mixed font sizes.

here’s the code I modified to obtain an “increase” macro and a “decrease macro”.

sub IncreaseFontSize
ChangeFontSize(0.25)
end sub
 
sub DecreaseFontSize 
ChangeFontSize(-0.25)
end sub

Sub ChangeFontSize(increment)
dim myCursor as object
dim currentMaxCH as single
currentMaxCH = 0
theSel = ThisComponent.CurrentSelection
theSel0 = theSel.GetByIndex(0)
theEnum= theSel0.CreateEnumeration
Do While theEnum.HasMoreElements
    oneElement = TheEnum.NextElement
    oneSubEnum    = oneElement.CreateEnumeration
    Do While oneSubEnum.HasMoreElements
        oneSubElement = oneSubEnum.NextElement
        If oneSubElement.CharHeight>currentMaxCH Then currentMaxCH = oneSubElement.CharHeight
    Loop
Loop
myCursor = ThisComponent.getCurrentController.getViewCursor   
myCursor.CharHeight()= currentMaxCH + increment
myCursor.CharFontName()="Arial" 
End Sub

actually I set the “font size steps” to 0.25 since I wanted fine tuning.
anyway you may change it to whatever you need (0.5, 1, 2, 3 etc. etc.)

thanks for the precious help.
Tommy

Just want to remind you of:
REM NO ERROR CATCHING AT ALL! Crude code!
Your code won’t work as expected for selections not consisting of exactly one TextRange, and not at all if parts of a Textable are selected or a TextFrame…

just stumbled upon a text with a frame and the macro fails :frowning:

It is not common and fir sure not best practice to format text with inline codes. The most used inline codes will be Bold or Italic. I say with reason not Bold and Italic because in typography you don’t use more than one emphasis on the same word/text. In written text there is no reason to shout ;-).
Normally your problem would be resolved by using Typograms or Styles as they are called in LibreOffice.
Having made the styles to the different content types of your text, you just apply the fitting style, this will give you consquent use of - let say - Helvetica Light 10,5/13 for all text that has the same content type like headers of the same level, quotes and others.

The easy in-/decrease by 2 points buttons are in fact a kind of ‘for dummy’s’ solution. No offense intended.


Note: Character height is not the same as font size, there are typefaces that have different character height at the same font size!

thank for your message but this is not what I needed.
sometimes I write text that goes beyond a single page and the decrease button helps me fitting the text inside it. the current standard “2 steps” button is however too gross…
most of the time I just need to slightly decrease the character height to fit text in a single page, that’s why I needed some more fine tuning like 0.25 or 0.5

Styles (typograms) are designes to keep formatting consistent over the whole work, no matter if your document is half a page or more than 100 pages.
The objection against local formatting is that you have to ‘search and replace’ all those local edits you made if you want or have to change them.
Styles allow you to change and re-change the appearance of fx. a certain procedure name you used 371 times over 740 page in one go, without the need to know where they are in the document.