MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / preprocess_svg_for_cairo

Function preprocess_svg_for_cairo

autofigure/generator.py:1073–1088  ·  view source on GitHub ↗
(svg_code: str)

Source from the content-addressed store, hash-verified

1071 return validate_svg_syntax(code)
1072
1073def preprocess_svg_for_cairo(svg_code: str) -> str:
1074 import re
1075
1076 svg_code = re.sub(r'\s*xmlns:xlink="[^"]*"', '', svg_code)
1077 svg_code = re.sub(r'\s*xmlns:xml="[^"]*"', '', svg_code)
1078
1079 if 'xmlns="http://www.w3.org/2000/svg"' not in svg_code:
1080 svg_code = svg_code.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"', 1)
1081
1082 svg_code = re.sub(r'xmlns="http://www\.w3\.org/2000/svg"\s+xmlns="http://www\.w3\.org/2000/svg"',
1083 'xmlns="http://www.w3.org/2000/svg"', svg_code)
1084
1085 svg_code = re.sub(r'\s{2,}', ' ', svg_code)
1086 svg_code = svg_code.strip()
1087
1088 return svg_code
1089
1090def svg_to_png(svg_code: str, output_path: str, attempt_repair: bool = False) -> Tuple[bool, Optional[str]]:
1091 try:

Callers 2

repair_svgFunction · 0.85
svg_to_pngFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected