From c1f94fcb4c8295867670aed5a7c8546ee72a5168 Mon Sep 17 00:00:00 2001 From: student_2333 Date: Tue, 6 Jun 2023 01:16:52 +0800 Subject: [PATCH] win2xcur support resize --- win2xcur/main/win2xcur.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/win2xcur/main/win2xcur.py b/win2xcur/main/win2xcur.py index a433595..2a34df5 100644 --- a/win2xcur/main/win2xcur.py +++ b/win2xcur/main/win2xcur.py @@ -1,4 +1,5 @@ import argparse +from ctypes import sizeof import os import sys import traceback @@ -9,9 +10,21 @@ from typing import BinaryIO from win2xcur import shadow from win2xcur.parser import open_blob +from win2xcur.parser.base import BaseParser from win2xcur.writer import to_x11 +def resize_cursor(cursor: BaseParser, size: int): + for f in cursor.frames: + for img in f: + width, height = img.image.size + x_ratio = size / width if width else 0 + y_ratio = size / height if height else 0 + spot_x, spot_y = img.hotspot + img.hotspot = (round(spot_x * x_ratio), round(spot_y * y_ratio)) + img.image.resize(size, size, 'point') + + def main() -> None: parser = argparse.ArgumentParser(description='Converts Windows cursors to X11 cursors.') parser.add_argument('files', type=argparse.FileType('rb'), nargs='+', @@ -32,6 +45,8 @@ def main() -> None: help='y-offset of shadow (as fraction of height)') parser.add_argument('-c', '--shadow-color', default='#000000', help='color of the shadow') + parser.add_argument('-z', '--size', type=int, default=0, + help='cursor size (px)') args = parser.parse_args() print_lock = Lock() @@ -46,6 +61,8 @@ def main() -> None: print(f'Error occurred while processing {name}:', file=sys.stderr) traceback.print_exc() else: + if args.size: + resize_cursor(cursor, args.size) if args.shadow: shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius, sigma=args.shadow_sigma, xoffset=args.shadow_x, yoffset=args.shadow_y)