bat Datei für einfachen Aufruf der verschiedenen Verzeichnisse dazu
This commit is contained in:
@@ -12,7 +12,11 @@ def analyze_and_normalize_path(d, path_type, path_id=""):
|
||||
report = []
|
||||
normalized = []
|
||||
changed = False
|
||||
|
||||
|
||||
# First check if path contains any arc commands
|
||||
if 'A' in d or 'a' in d:
|
||||
report.append(" Path contains arc commands - leaving unchanged")
|
||||
return original_d, report, False
|
||||
# Ensure path starts with M command
|
||||
if not d.strip().startswith('M'):
|
||||
d = 'M' + d[1:] if d.startswith('L') else 'M ' + d
|
||||
@@ -98,7 +102,144 @@ def analyze_and_normalize_path(d, path_type, path_id=""):
|
||||
full_report.append("Path not modified")
|
||||
|
||||
return new_d, '\n'.join(full_report)
|
||||
def analyze_and_normalize_path(d, path_type, path_id=""):
|
||||
"""Strictly normalize path direction and generate detailed report"""
|
||||
original_d = d
|
||||
report = []
|
||||
normalized = []
|
||||
changed = False
|
||||
|
||||
# First check if path contains any arc commands
|
||||
if 'A' in d or 'a' in d:
|
||||
report_header = f"[{path_id}-Analysis] Type: {path_type} (contains arcs)"
|
||||
full_report = [report_header,
|
||||
f"Original path: {original_d}",
|
||||
" Path contains arc commands - leaving unchanged",
|
||||
"Path not modified"]
|
||||
return original_d, '\n'.join(full_report)
|
||||
|
||||
# Ensure path starts with M command
|
||||
if not d.strip().startswith('M'):
|
||||
d = 'M' + d[1:] if d.startswith('L') else 'M ' + d
|
||||
report.append(" Fix: Added M command at path start")
|
||||
changed = True
|
||||
|
||||
# Parse path commands
|
||||
commands = []
|
||||
current_cmd = None
|
||||
for token in re.split('([A-Za-z])', d):
|
||||
if not token:
|
||||
continue
|
||||
if token in 'MLAZHVCSQTa-z':
|
||||
current_cmd = token
|
||||
else:
|
||||
if current_cmd:
|
||||
commands.append((current_cmd, token.strip()))
|
||||
|
||||
prev_x, prev_y = None, None
|
||||
|
||||
for cmd, params in commands:
|
||||
params = [float(p) for p in re.split('[, ]+', params.strip()) if p]
|
||||
|
||||
if cmd == 'M':
|
||||
if len(params) >= 2:
|
||||
x, y = params[0], params[1]
|
||||
normalized.append(f"M {x} {y}")
|
||||
prev_x, prev_y = x, y
|
||||
continue
|
||||
|
||||
if path_type == 'Line segment' and cmd == 'L':
|
||||
if len(params) >= 2 and prev_x is not None:
|
||||
x, y = params[0], params[1]
|
||||
need_swap = x < prev_x or (x == prev_x and y < prev_y)
|
||||
|
||||
if need_swap:
|
||||
new_segment = [f"M {x} {y}", f"L {prev_x} {prev_y}"]
|
||||
report.append(f" Need to swap start/end → New path: {' '.join(new_segment)}")
|
||||
normalized = new_segment
|
||||
changed = True
|
||||
else:
|
||||
normalized.append(f"L {x} {y}")
|
||||
report.append(" Path direction already correct, no changes made")
|
||||
|
||||
prev_x, prev_y = x, y
|
||||
continue
|
||||
|
||||
normalized.append(f"{cmd} {' '.join(map(str, params))}")
|
||||
|
||||
new_d = ' '.join(normalized)
|
||||
report_header = f"[{path_id}-Analysis] Type: {path_type}"
|
||||
full_report = [report_header, f"Original path: {original_d}"] + report
|
||||
|
||||
if changed:
|
||||
full_report.append(f"Modified path: {new_d}")
|
||||
else:
|
||||
full_report.append("Path not modified")
|
||||
|
||||
return new_d, '\n'.join(full_report)
|
||||
''' def analyze_and_normalize_path(d, path_type, path_id=""):
|
||||
"""Strictly normalize path direction and generate detailed report"""
|
||||
original_d = d
|
||||
report = []
|
||||
normalized = []
|
||||
changed = False
|
||||
|
||||
# First check if path contains any arc commands
|
||||
if 'A' in d or 'a' in d:
|
||||
report.append(" Path contains arc commands - leaving unchanged")
|
||||
return original_d, report, False
|
||||
|
||||
# Ensure path starts with M command
|
||||
if not d.strip().startswith('M'):
|
||||
d = 'M' + d[1:] if d.startswith('L') else 'M ' + d
|
||||
report.append(" Fix: Added M command at path start")
|
||||
changed = True
|
||||
|
||||
# Parse path commands
|
||||
commands = []
|
||||
current_cmd = None
|
||||
for token in re.split('([A-Za-z])', d):
|
||||
if not token:
|
||||
continue
|
||||
if token in 'MLAZHVCSQTa-z':
|
||||
current_cmd = token
|
||||
else:
|
||||
if current_cmd:
|
||||
commands.append((current_cmd, token.strip()))
|
||||
|
||||
prev_x, prev_y = None, None
|
||||
|
||||
for cmd, params in commands:
|
||||
params = [float(p) for p in re.split('[, ]+', params.strip()) if p]
|
||||
|
||||
if cmd == 'M':
|
||||
if len(params) >= 2:
|
||||
x, y = params[0], params[1]
|
||||
normalized.append(f"M {x} {y}")
|
||||
prev_x, prev_y = x, y
|
||||
continue
|
||||
|
||||
if path_type == 'Line segment' and cmd == 'L':
|
||||
if len(params) >= 2 and prev_x is not None:
|
||||
x, y = params[0], params[1]
|
||||
need_swap = x < prev_x or (x == prev_x and y < prev_y)
|
||||
|
||||
if need_swap:
|
||||
new_segment = [f"M {x} {y}", f"L {prev_x} {prev_y}"]
|
||||
report.append(f" Need to swap start/end → New path: {' '.join(new_segment)}")
|
||||
normalized = new_segment
|
||||
changed = True
|
||||
else:
|
||||
normalized.append(f"L {x} {y}")
|
||||
report.append(" Path direction already correct, no changes made")
|
||||
|
||||
prev_x, prev_y = x, y
|
||||
continue
|
||||
|
||||
normalized.append(f"{cmd} {' '.join(map(str, params))}")
|
||||
|
||||
normalized_path = ' '.join(normalized)
|
||||
return normalized_path if changed else original_d, report, changed '''
|
||||
def optimize_svg(input_path, output_path):
|
||||
"""Process single SVG file with all optimizations"""
|
||||
try:
|
||||
@@ -233,7 +374,7 @@ def optimize_svg(input_path, output_path):
|
||||
if stroke == '#0ff' or stroke == 'rgb(0,255,255)':
|
||||
elem.set('stroke', '#ffe31b')
|
||||
elif stroke == '#000' or stroke == 'rgb(255,0,0)'or stroke == 'rgb(0,0,0)':
|
||||
elem.set('stroke', '#ec2525')
|
||||
elem.set('stroke', '#ffe31b')
|
||||
elem.set('stroke-width', '1')
|
||||
|
||||
# Generate final XML
|
||||
|
||||
Reference in New Issue
Block a user