Skip to content

Instantly share code, notes, and snippets.

@charlesreiss
Created June 9, 2015 20:24
Show Gist options
  • Save charlesreiss/baf1b1a12f721a633bd2 to your computer and use it in GitHub Desktop.
Save charlesreiss/baf1b1a12f721a633bd2 to your computer and use it in GitHub Desktop.
# LibreOffice macro script
import uno
def changeFontsWithin(object_list, to_font, to_weight=None):
for i in range(object_list.getCount()):
shape = object_list.getByIndex(i)
the_type = shape.getShapeType()
assert(shape.supportsService(the_type))
if shape.supportsService('com.sun.star.drawing.TextProperties'):
if to_font:
shape.CharFontName = to_font
if to_weight != None:
shape.CharWeight = to_weight
if shape.supportsService('com.sun.star.drawing.XShapes') or shape.supportsService('com.sun.star.drawing.GroupShape'):
changeFontsWithin(shape, to_font, to_weight)
if shape.supportsService('com.sun.star.text.XText') or shape.supportsService('com.sun.star.drawing.Text'):
cursor = shape.createTextCursor()
cursor.gotoStart(False)
cursor.gotoEnd(True)
if to_font:
cursor.CharFontName = to_font
if to_weight != None:
cursor.CharWeight = to_weight
def changeFontsToFreeSans(ctx = None):
selection = XSCRIPTCONTEXT.getDocument().getCurrentSelection()
changeFontsWithin(selection, 'FreeSans')
def changeFontsToFreeSansNormal(ctx = None):
selection = XSCRIPTCONTEXT.getDocument().getCurrentSelection()
changeFontsWithin(selection, 'FreeSans', 100.0)
def changeFontsToFreeSansBold(ctx = None):
selection = XSCRIPTCONTEXT.getDocument().getCurrentSelection()
changeFontsWithin(selection, 'FreeSans', 150.0)
g_exportedScripts = changeFontsToFreeSans, changeFontsToFreeSansNormal, changeFontsToFreeSansBold,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment