Currently OOo does not seem to offer any off-the-shelf solution for automatically changing the size of all Math formulas in a document or a selection. This would be a pretty useful tool, in my opinion.
While waiting for a cleaner and brighter solution, a macro could be operated to this goal, according to the following logic:
- Code: Select all Expand viewCollapse view
1. create the collection of the embedded objects (in the document, or selection)
2. loop on the collection
3. if the current object is a formula,
3.1 apply the new size
3.2 and refresh
Ok, and I append below my current implementation, that, on the other hand, has two problems:
A. when the collection contains more than 20 (yes, exactly 20 is the threshold) formulas, the debugger is activated, with the error
"BASIC runtime error. - Object variable not set"
set by the line 3 above (the line
- Code: Select all Expand viewCollapse view
if oTR3.EmbeddedObject.supportsService("com.sun.star.formula.FormulaProperties") then
B. the logic for refreshing the resized formulas (line 3.2 above) does not work, so that the size change must be "manually notified " by double clicking one by one all the formulas.
Any suggestions to solve these issues A and B? Thank a lot everybody.
Luca
... and here is the code:
- Code: Select all Expand viewCollapse view
sub Prova
newSize = InputBox("New formula font size:", "BaseFontHeight", 10)
if isNull(newSize) or newSize = "" then exit sub
oDoc = ThisComponent
oSel = oDoc.CurrentController.Selection
if oSel.supportsService("com.sun.star.text.TextEmbeddedObject") then
if oSel.EmbeddedObject.supportsService("com.sun.star.formula.FormulaProperties") then
SetFormulaSize(oSel, newSize)
oDoc.reformat()
msgbox "ok..."
exit sub
endif
endif
if oSel.supportsService("com.sun.star.text.TextRanges") then
oTR = oSel.getByIndex(0)
oEnum = oTR.createEnumeration()
while oEnum.hasMoreElements()
oTR1 = oEnum.nextElement()
oEnum1 = oTR1.createEnumeration()
while oEnum1.hasMoreElements()
oTR2 = oEnum1.nextElement()
if oTR2.TextPortionType = "Frame" then
oEnum2 = oTR2.createContentEnumeration("com.sun.star.text.TextEmbeddedObject")
while oEnum2.hasMoreElements()
oTR3 = oEnum2.nextElement()
if oTR3.EmbeddedObject.supportsService("com.sun.star.formula.FormulaProperties") then
SetFormulaSize(oTR3, newSize) 'msgbox "Formula"
endif
wend
endif
wend
wend
oDoc.reformat()
msgbox "ok..."
exit sub
endif
end sub
sub SetFormulaSize(obj, newSize)
oFormula = obj.EmbeddedObject
oFormula.BaseFontHeight = newSize
temp = oFormula.Formula ' some tricks to force OO.o redraw formulas '*** THESE DO NOT WORK!***
oFormula.Formula = ""
oFormula.Formula = temp
end sub

