Skip to content

Instantly share code, notes, and snippets.

@Lucas-C
Forked from charlesreiss/change_fonts.py
Created November 22, 2022 00:51
Show Gist options
  • Save Lucas-C/dd05c418748e56c0c8d8bbf885c24e68 to your computer and use it in GitHub Desktop.
Save Lucas-C/dd05c418748e56c0c8d8bbf885c24e68 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