From bfc47f424a6df497fdde2b6b706821189038a504 Mon Sep 17 00:00:00 2001 From: Link Date: Fri, 15 Nov 2024 16:22:36 +0800 Subject: [PATCH] fix(script): add ending for raw loader of ThorVG (#7186) Co-authored-by: SamNofee --- docs/details/libs/rlottie.rst | 4 +++- docs/details/widgets/lottie.rst | 4 +++- scripts/filetohex.py | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/details/libs/rlottie.rst b/docs/details/libs/rlottie.rst index 0b80739a5..d0067b195 100644 --- a/docs/details/libs/rlottie.rst +++ b/docs/details/libs/rlottie.rst @@ -81,7 +81,9 @@ array. E.g.: .. code-block:: shell - ./filetohex.py path/to/lottie.json > out.txt + ./filetohex.py path/to/lottie.json --filter-character --null-terminate > out.txt + +``--filter-character`` filters out non-ASCII characters and ``--null-terminate`` makes sure that a trailing zero is appended to properly close the string. To create an animation from raw data: diff --git a/docs/details/widgets/lottie.rst b/docs/details/widgets/lottie.rst index 264d31d50..dc098a9b1 100644 --- a/docs/details/widgets/lottie.rst +++ b/docs/details/widgets/lottie.rst @@ -69,7 +69,9 @@ array. E.g.: .. code-block:: shell - ./filetohex.py path/to/lottie.json > out.txt + ./filetohex.py path/to/lottie.json --filter-character --null-terminate > out.txt + +``--filter-character`` filters out non-ASCII characters and ``--null-terminate`` makes sure that a trailing zero is appended to properly close the string. To create an animation from data use :cpp:expr:`lv_lottie_set_src_data(lottie, data, sizeof(data))` diff --git a/scripts/filetohex.py b/scripts/filetohex.py index 73ad5a972..8e8b478cc 100755 --- a/scripts/filetohex.py +++ b/scripts/filetohex.py @@ -1,11 +1,18 @@ #!/usr/bin/env python3 import sys +import textwrap +import re with open(sys.argv[1], 'r') as file: s = file.read() b = bytearray() + +if '--filter-character' in sys.argv: + s = re.sub(r'[^\x00-\xff]', '', s) +if '--null-terminate' in sys.argv: + s += '\x00' + b.extend(map(ord, s)) -for a in b: print(hex(a), end =", ") - +print(textwrap.fill(', '.join([hex(a) for a in b]), 96)) \ No newline at end of file