اضافه شدن قابلیت مقایسه شماتیک
This commit is contained in:
@@ -9,7 +9,7 @@ def clean(value): return CONTROL.sub('', str(value))
|
||||
def node(parent, tag, **attrs):
|
||||
return SubElement(parent, tag, {k.replace('_', '-'): clean(v) for k, v in attrs.items()})
|
||||
|
||||
def svg_document(doc: Document) -> bytes:
|
||||
def svg_document(doc: Document, annotations=None, id_prefix="") -> bytes:
|
||||
b = doc.sheet.bounds
|
||||
root = Element('svg', {'xmlns': 'http://www.w3.org/2000/svg', 'viewBox': f'{b.x} {b.y} {b.width} {b.height}',
|
||||
'preserveAspectRatio': 'xMidYMid meet', 'role': 'img', 'aria-label': 'Schematic'})
|
||||
@@ -17,11 +17,14 @@ def svg_document(doc: Document) -> bytes:
|
||||
defs = node(root, 'defs')
|
||||
for i, p in enumerate(doc.primitives):
|
||||
target = root
|
||||
if annotations is not None:
|
||||
annotation = annotations.get(p.component_id or p.object_id)
|
||||
target = node(root, 'g', data_object_id=p.component_id or p.object_id, data_change_id=annotation['id'] if annotation else '')
|
||||
if p.clip:
|
||||
clip = node(defs, 'clipPath', id=f'clip-{i}', clipPathUnits='userSpaceOnUse')
|
||||
clip = node(defs, 'clipPath', id=f'{id_prefix}clip-{i}', clipPathUnits='userSpaceOnUse')
|
||||
c = p.clip
|
||||
node(clip, 'rect', x=c.x, y=c.y, width=c.width, height=c.height)
|
||||
target = node(root, 'g', clip_path=f'url(#clip-{i})')
|
||||
target = node(target, 'g', clip_path=f'url(#{id_prefix}clip-{i})')
|
||||
if p.kind == 'path':
|
||||
n = node(target, 'path', d=p.path, stroke=p.stroke, fill=p.fill,
|
||||
stroke_width=p.width, stroke_linecap='round', stroke_linejoin='round', fill_rule=p.fill_rule)
|
||||
@@ -40,4 +43,14 @@ def svg_document(doc: Document) -> bytes:
|
||||
dominant_baseline=p.baseline, text_decoration='underline' if p.underline else 'none')
|
||||
n.set('{http://www.w3.org/XML/1998/namespace}space', 'preserve')
|
||||
n.text = clean(p.text)
|
||||
if annotations is not None:
|
||||
colors = {'added':'#16854b','removed':'#cf3545','modified':'#b87b09','moved':'#2676c5'}
|
||||
overlay = node(root, 'g', pointer_events='none')
|
||||
for annotation in annotations.values():
|
||||
b = annotation.get('bounds')
|
||||
if not b: continue
|
||||
color = colors[annotation['status']]
|
||||
node(overlay, 'rect', x=b['x']-2, y=b['y']-2, width=max(4,b['width']+4), height=max(4,b['height']+4),
|
||||
fill=color, fill_opacity='.09', stroke=color, stroke_width='1.5', vector_effect='non-scaling-stroke',
|
||||
data_change_id=annotation['id'], data_diff_box='true')
|
||||
return tostring(root, encoding='utf-8', xml_declaration=True)
|
||||
|
||||
مرجع در شماره جدید
مسدود کردن کاربر