def process_scaling(ui_content: str, ratio: float) -> str:
tree = ElementTree.fromstring(ui_content)
for child in tree.iter('width'):
if child.text != '16777215':
child.text = str(int(int(child.text) * ratio))
for child in tree.iter('height'):
if child.text != '16777215':
child.text = str(int(int(child.text) * ratio))
for child in tree.iter("property"):
name = child.attrib.get('name', None)
if name == 'spacing' or name[-6:] == 'Margin' and len(child):
number = child[0]
number.text = str(int(int(number.text) * ratio))
ui_content = ElementTree.tostring(tree, encoding='unicode')
ui_content = ui_content.replace(' />\n', '/>\n')
return '<?xml version="1.0" encoding="UTF-8"?>\n' + ui_content + '\n'
评论列表
文章目录