Compare commits

..

No commits in common. "10804a68c84b20a9c7dd816930cc894f29f87f4d" and "133e509929b4c07ff46cc17febc9098e30dfe1b2" have entirely different histories.

4 changed files with 55 additions and 46 deletions

View file

@ -28,13 +28,13 @@ For example, if you want to convert [the sample cursor](sample/crosshair.cur)
to Linux format: to Linux format:
mkdir output/ mkdir output/
win2xcur sample/crosshair.cur -o output/ --size 32 48 64 win2xcur sample/crosshair.cur -o output/
`-s` can be specified to enable shadows. `-s` can be specified to enable shadows.
Multiple cursors files can be specified on the command line. Multiple cursors files can be specified on the command line.
For example, to convert a directory of cursors with shadows enabled: For example, to convert a directory of cursors with shadows enabled:
win2xcur input/*.{ani,cur} -o output/ --size 32 48 64 win2xcur input/*.{ani,cur} -o output/
For more information, run `win2xcur --help`. For more information, run `win2xcur --help`.
@ -43,7 +43,7 @@ For more information, run `win2xcur --help`.
For example, if you want to convert DMZ-White to Windows: For example, if you want to convert DMZ-White to Windows:
mkdir dmz-white/ mkdir dmz-white/
x2wincur /usr/share/icons/DMZ-White/cursors/* -o dmz-white/ --size 32 48 64 x2wincur /usr/share/icons/DMZ-White/cursors/* -o dmz-white/
## Troubleshooting ## Troubleshooting

View file

@ -32,10 +32,10 @@ def main() -> None:
help='y-offset of shadow (as fraction of height)') help='y-offset of shadow (as fraction of height)')
parser.add_argument('-c', '--shadow-color', default='#000000', parser.add_argument('-c', '--shadow-color', default='#000000',
help='color of the shadow') help='color of the shadow')
parser.add_argument('--scale', nargs='*', type=float, default=None, parser.add_argument('--scale', default=None, type=str,
help='Scale the cursor by the specified factor. Multi-scale "[0.125,0.1875,0.25]"') help='Scale the cursor by the specified factor. Multi-scale "[0.125,0.1875,0.25]"')
parser.add_argument('--size', nargs='*', type=int, default=None, parser.add_argument('--size', default=None, type=str,
help='Scale the cursor to the specified size. Multi-size "[32,48,64]"') help='Scale the cursor to the specified size. Multi-size "[32,28,64]"')
args = parser.parse_args() args = parser.parse_args()
print_lock = Lock() print_lock = Lock()
@ -51,11 +51,17 @@ def main() -> None:
traceback.print_exc() traceback.print_exc()
else: else:
if args.scale: if args.scale:
cursor.frames = scale.apply_to_frames_by_scales(cursor.frames, scales=args.scale) scales = eval(args.scale)
if isinstance(scales, (int, float)):
scale.apply_to_frames(cursor.frames, scale=scales)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, scales=scales)
elif args.size: elif args.size:
cursor.frames = scale.apply_to_frames_to_sizes(cursor.frames, sizes=args.size) sizes = eval(args.size)
else: if isinstance(sizes, (int, float)):
raise NotImplementedError('Please specify either --scale or --size') scale.apply_to_frames(cursor.frames, size=sizes)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, sizes=sizes)
if args.shadow: if args.shadow:
shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius, shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius,

View file

@ -18,9 +18,9 @@ def main() -> None:
help='X11 cursor files to convert (no extension)') help='X11 cursor files to convert (no extension)')
parser.add_argument('-o', '--output', '--output-dir', default=os.curdir, parser.add_argument('-o', '--output', '--output-dir', default=os.curdir,
help='Directory to store converted cursor files.') help='Directory to store converted cursor files.')
parser.add_argument('-S', '--scale', nargs='*', type=float, default=None, parser.add_argument('-S', '--scale', default=None, type=str,
help='Scale the cursor by the specified factor. Multi-scale "[0.125,0.1875,0.25]"') help='Scale the cursor by the specified factor. Multi-scale "[0.125,0.1875,0.25]"')
parser.add_argument('--size', nargs='*', type=int, default=None, parser.add_argument('--size', default=None, type=str,
help='Scale the cursor to the specified size. Multi-size "[32,28,64]"') help='Scale the cursor to the specified size. Multi-size "[32,28,64]"')
args = parser.parse_args() args = parser.parse_args()
@ -37,11 +37,17 @@ def main() -> None:
traceback.print_exc() traceback.print_exc()
else: else:
if args.scale: if args.scale:
cursor.frames = scale.apply_to_frames_by_scales(cursor.frames, scales=args.scale) scales = eval(args.scale)
if isinstance(scales, (int, float)):
scale.apply_to_frames(cursor.frames, scale=scales)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, scales=scales)
elif args.size: elif args.size:
cursor.frames = scale.apply_to_frames_to_sizes(cursor.frames, sizes=args.size) sizes = eval(args.size)
else: if isinstance(sizes, (int, float)):
raise NotImplementedError('Please specify either --scale or --size') scale.apply_to_frames(cursor.frames, size=sizes)
else:
cursor.frames = scale.apply_to_frames_MS(cursor.frames, sizes=sizes)
ext, result = to_smart(cursor.frames) ext, result = to_smart(cursor.frames)
output = os.path.join(args.output, os.path.basename(name) + ext) output = os.path.join(args.output, os.path.basename(name) + ext)

View file

@ -2,35 +2,32 @@ from typing import List
from win2xcur.cursor import CursorFrame from win2xcur.cursor import CursorFrame
def apply_to_frames_by_scales(frames: List[CursorFrame], *, scales: List[float] = None) -> List[CursorFrame]:
all_frames = []
for scale in scales:
for frame in frames:
frame = frame.clone()
for cursor in frame:
cursor.image.scale(
int(round(cursor.image.width * scale)),
int(round(cursor.image.height * scale)),
)
cursor.nominal = int(cursor.nominal * scale)
hx, hy = cursor.hotspot
cursor.hotspot = (int(hx * scale), int(hy * scale))
all_frames.append(frame)
return all_frames
def apply_to_frames_to_sizes(frames: List[CursorFrame], *, sizes: List[int] = None) -> List[CursorFrame]: def apply_to_frames(frames: List[CursorFrame], *, scale: float = None, size: int = None) -> None:
all_frames = [] for frame in frames:
for size in sizes: for cursor in frame:
for frame in frames: if size:
frame = frame.clone()
for cursor in frame:
scale = size / cursor.image.width scale = size / cursor.image.width
cursor.image.scale( cursor.image.scale(
size, size or int(round(cursor.image.width * scale)),
size, size or int(round(cursor.image.height * scale)),
) )
cursor.nominal = int(cursor.nominal * scale) cursor.nominal = int(cursor.nominal * scale)
hx, hy = cursor.hotspot hx, hy = cursor.hotspot
cursor.hotspot = (int(hx * scale), int(hy * scale)) cursor.hotspot = (int(hx * scale), int(hy * scale))
all_frames.append(frame)
return all_frames
def apply_to_frames_MS(frames: List[CursorFrame], *, scales: List[float] = None,
sizes: List[int] = None) -> List[CursorFrame]:
frames_MS = []
if scales is not None:
for scale in scales:
frames_s = [frame.clone() for frame in frames]
apply_to_frames(frames_s, scale=scale)
frames_MS.extend(frames_s)
else:
for size in sizes:
frames_s = [frame.clone() for frame in frames]
apply_to_frames(frames_s, size=size)
frames_MS.extend(frames_s)
return frames_MS