From 0cae12bdbde6fa87f65025bc14ee5863f2526c4b Mon Sep 17 00:00:00 2001 From: Jens Kutilek Date: Tue, 9 Jan 2018 11:18:01 +0100 Subject: [PATCH] Add snippet manipulating raw table data --- Snippets/edit_raw_table_data.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Snippets/edit_raw_table_data.py diff --git a/Snippets/edit_raw_table_data.py b/Snippets/edit_raw_table_data.py new file mode 100644 index 000000000..91f116e59 --- /dev/null +++ b/Snippets/edit_raw_table_data.py @@ -0,0 +1,31 @@ +from fontTools.ttLib import TTFont +from fontTools.ttLib.tables.DefaultTable import DefaultTable + +font_path = "myfont.ttf" +output_path = "myfont_patched.ttf" + +table_tag = "DSIG" + + +# Get raw table data from the source font + +font = TTFont(font_path) +raw_data = font.getTableData(table_tag) + + +# Do something with the raw table data +# This example just sets an empty DSIG table. + +raw_data = "\0\0\0\1\0\0\0\0" + + +# Write the data back to the font + +# We could re-use the existing table when the source and target font are +# identical, but let's make a new empty table to be more universal. +table = DefaultTable(table_tag) +table.data = raw_data + +# Add the new table back into the source font and save under a new name. +font[table_tag] = table +font.save(output_path)