| 1 |
#!/usr/bin/python3 |
| 2 |
# Print the hotspot of a cursor SVG file at default size |
| 3 |
# Usage: ./hotspot_test.py <svg file> |
| 4 |
|
| 5 |
from PySide6.QtSvg import QSvgRenderer |
| 6 |
import sys |
| 7 |
import math |
| 8 |
|
| 9 |
# Displace the hotspot to the right and down by 1/100th of a pixel, then |
| 10 |
# floor. So if by some float error the hotspot is at 4.995, it will be |
| 11 |
# displaced to 5.005, then floored to 5. This is to prevent the hotspot |
| 12 |
# from potential off-by-one errors when the cursor is scaled. |
| 13 |
HOTSPOT_DISPLACE = 1 |
| 14 |
|
| 15 |
svg = QSvgRenderer(sys.argv[1]) |
| 16 |
scale = 100 |
| 17 |
hotspot = svg.transformForElement('hotspot').map(svg.boundsOnElement('hotspot')).boundingRect().topLeft() |
| 18 |
#print(hotspot.x(), hotspot.y()) |
| 19 |
hotspot_x = math.floor((hotspot.x() * scale + HOTSPOT_DISPLACE) / 100) |
| 20 |
hotspot_y = math.floor((hotspot.y() * scale + HOTSPOT_DISPLACE) / 100) |
| 21 |
print(hotspot_x, hotspot_y) |