How to change the fonts of all equations in an impress presentation

Dear all,

I have a problem with Libreoffice Impressfor which I didn't find any
solution in internet.

My problem:
I have a presentation with lots of equations and I want to change the
fonts in this presentation. For normal text this is easily done changing
the corresponding styles. However, so far I didn't find a way to change
the fonts of all equations (in an efficient way, without modifying each
equation manually).

I understand that I need a macro for doing this. In the Math
documentation
http://wiki.documentfoundation.org/images/3/37/MG40-MathGuide.pdf on
page 46 I found a macro which works nicely in Libreoffice Writer, but
not in Impress.
On page 47 it is said that in Impress some modifications are necessary.
I made these modifications (hopefully correctly, I am not sure), but the
macro does not work, giving me the error message

BASIC runtime error.
Property or method not found: EmbeddedObjects

My macro is this (essentially the one from the documentation):

Sub ChangeFormatFormuleImpress
oCurrentController = ThisComponent.getCurrentController()
oTextDocument = oCurrentController.Model
oEmbeddedObjects = oTextDocument.EmbeddedObjects
nEndIndex = oEmbeddedObjects.Count-1
for nIndex=0 to nEndIndex
oMathObject = oEmbeddedObjects.getByIndex(nIndex)
oModel = oMathObject.Model
if (not isNull(oModel)) then
if(not isEmpty(oModel)) then
if oShape.supportsService("com.sun.star.drawing.OLE2Shape") then
if oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997" then
oModelFormula = oShape.Model
oModelFormula.BaseFontHeight = 12
oModel.BaseFontHeight = 12
policeCommune= "Arial"
' Variables
oModel.FontNameVariables= policeCommune
oModel.FontVariablesIsItalic=false
oModel.FontVariablesIsBold=false
' Functions
oModel.FontNameFunctions = policeCommune
oModel.FontFunctionsIsItalic=false
oModel.FontFunctionsIsBold=false
' Numbers
oModel.FontNameNumbers= policeCommune
oModel.FontNumbersIsItalic=false
oModel.FontNumbersIsBold=false
' Text
oModel.FontNameText= policeCommune
oModel.FontTextIsItalic=false
oModel.FontTextIsBold=false
' Update
oXCOEO = oMathObject.ExtendedControlOverEmbeddedObject
oXCOEO.update()
endif
endif ' if formula
endif ' if not empty
endif ' if not null
next nIndex
ThisComponent.reformat() ' Met à jour tous les éléments du document
End Sub

Because I have never written a Libreoffice macro before, I am lost here
and any help would be appreciated.

My system: Libreoffice 4.1.1, Linux, 64 bit

Markus

Hi Markus,

Markus Doerr schrieb:

Dear all,

I have a problem with Libreoffice Impressfor which I didn't find any
solution in internet.

My problem:
I have a presentation with lots of equations and I want to change the
fonts in this presentation. For normal text this is easily done changing
the corresponding styles. However, so far I didn't find a way to change
the fonts of all equations (in an efficient way, without modifying each
equation manually).

I understand that I need a macro for doing this. In the Math
documentation
http://wiki.documentfoundation.org/images/3/37/MG40-MathGuide.pdf on
page 46 I found a macro which works nicely in Libreoffice Writer, but
not in Impress.
On page 47 it is said that in Impress some modifications are necessary.

If you have not used a special style for the formulas, then using an input field will work for you. See macro below, put all in one tab in a module in basic IDE. I will sent you a document with that macro in private mail.

Kind regards
Regina

REM ***** BASIC *****
option explicit

sub main
  ChangeFormulaSizeDirectly
end sub
' The macro ChangeFormulaSizeDirectly changes the formula font size for selected
' formulas. The new font size has to be entered in an input box.

' Copyright (C) 2010; Regina Henschel
' Apache License, Version 2.0, rb.henschel@t-online.de

Rem === How To Use ===
' To change the font size of a set of formulas first select them and then run the
' macro ChangeFormulaSizeDirectly. Enter the new font size into the input box.
' The program effects formulas in nested groups as well.
' To change _all_ formulas on several slides in Impress, select the slides in the
' Slide-Sorter and then run the macro ChangeFormulaSizeDirectly.

' Wählen Sie zunächst die Formeln aus und rufen anschließend das Makro
' ChangeFormulaSizeDirectly auf. Tragen Sie die neue Schriftgröße in das Eingabefeld
' ein. Die Formeln werden auch innerhalb von geschachtelten Gruppen geändert.
' Um in Impress _alle_ Formeln auf mehreren Folien zu ändern, wählen Sie die Folien in der
' Foliensortierung aus und rufen dann das Makro ChangeFormulaSizeDirectly auf.

sub ChangeFormulaSizeDirectly
dim oCurrentController as variant: oCurrentController = ThisComponent.getCurrentController()
dim oDoc as variant: oDoc=ThisComponent
if not(oCurrentController.supportsService("com.sun.star.drawing.DrawingDocumentDrawView")) then
  msgbox("Only for Draw and Impress documents.")
  exit sub
end if
dim oShapeCollection as variant: oShapeCollection = oCurrentController.Selection
if isEmpty(oShapeCollection) then
  msgbox("Nothing selected.")
  exit sub
end if
dim nVarType as integer: nVarType = VarType(oShapeCollection)
'9 object; Something is selected in Normal view
'8201=8192+9 array of object; Slides are selected in slide sorter.
if nVarType=9 then
  WorkOnNormalView(oShapeCollection)
else if nVarType=8201 then
    WorkOnSlideSorter(oShapeCollection)
  else
    exit sub
  end if
end if
oDoc.Modified = true
end sub

sub WorkOnNormalView(oShapeCollection as variant)
if not(oShapeCollection.supportsService("com.sun.star.drawing.ShapeCollection")) then
  exit sub
end if
dim sValue as string
sValue = InputBox("Enter new font size","Set Formula Font Size Directly","12")
dim nNewFontSize as integer: nNewFontSize = CInt(sValue)
dim nShapeIndex as long
dim nEndShapeIndex as long: nEndShapeIndex = oShapeCollection.Count-1
dim oShape as variant
for nShapeIndex=0 to nEndShapeIndex
  oShape = oShapeCollection(nShapeIndex)
  SetCharHeightDeep2(oShape,nNewFontSize) 'two parameters
next nShapeIndex
end sub

sub WorkOnSlideSorter(oPagesCollection as variant)
dim nPageIndex as long
dim nShapeIndex as long
dim nEndShapeIndex as long
dim oSelectedPage as variant
dim oShape as variant
dim sValue as string
sValue = InputBox("Enter new font size","Set Formula Font Size Directly","12")
dim nNewFontSize as integer: nNewFontSize = CInt(sValue)
' Iterate over all selected pages, then over all shapes.
for nPageIndex = LBound(oPagesCollection) to UBound(oPagesCollection)
  oSelectedPage = oPagesCollection(nPageIndex)
  nEndShapeIndex = oSelectedPage.Count - 1
  for nShapeIndex=0 to nEndShapeIndex
    oShape = oSelectedPage(nShapeIndex)
    SetCharHeightDeep2(oShape,nNewFontSize)
  next nShapeIndex
next nPageIndex
end sub

sub SetCharHeightDeep2(oShapeInOut as variant, nNewFontSizeIn as integer)
' recursive solution
dim sShapeType: sShapeType = oShapeInOut.ShapeType
if sShapeType = "com.sun.star.drawing.GroupShape" then
  dim nCount as long: nCount = oShapeInOut.Count
  dim nIndex as long
  dim nEndIndex as long: nEndIndex = nCount -1
  for nIndex = 0 to nEndindex
    SetCharHeightDeep2(oShapeInOut.getByIndex(nIndex),nNewFontSizeIn)
  next nIndex
else
  if oShapeInOut.supportsService("com.sun.star.drawing.OLE2Shape") then
    if oShapeInOut.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997" then
      'Math-object
      dim oModelFormula as variant: oModelFormula = oShapeInOut.Model
      oModelFormula.BaseFontHeight = nNewFontSizeIn
    endif
  endif
endif
end sub

Hi Regina,

Thank you very much for your quick and very helpful response.

For those who have similar problems in the future:

I used your macro and added some lines like
oModelFormula.BaseFontHeight = 22
oModelFormula.FontNameVariables= "Arial"
oModelFormula.FontVariablesIsItalic=false
oModelFormula.FontVariablesIsBold=false
etc. (as described in the Math documentation)
in function SetCharHeightDeep2 for changing the font size and all other
relevant attributes of my equations. (a quick-and-dirty solution,
without using message boxes).

This works perfectly now.

Kind regards,

Markus