From ef9976e4b275e4e5f42433d6221cf81c0607df7e Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Wed, 7 Apr 2021 19:52:40 +0800 Subject: [PATCH 1/2] make-xges: Perform a simplistic conversion of text annotations --- make-xges.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/make-xges.py b/make-xges.py index feda92e..99bc8e2 100755 --- a/make-xges.py +++ b/make-xges.py @@ -173,6 +173,35 @@ def add_webcams(self): self.opts.width - width, 0, width, height) + def _clean_shape(self, shape): + # Shapes are hidden by default, as the JavaScript player would + # make the visible as appropriate. + shape.set('style', shape.get('style').replace('visibility:hidden;', '')) + + # Add an SVG fallback to text shapes + switch = shape.find('./{http://www.w3.org/2000/svg}switch') + if switch is not None: + fo = switch.find('./{http://www.w3.org/2000/svg}foreignObject') + p = fo.find('./{http://www.w3.org/1999/xhtml}p') + #

tag contains lines separated by
elements + lines = [p.text] + for br in p.iterfind('./{http://www.w3.org/1999/xhtml}br'): + lines.append(br.tail) + + text = ET.Element('{http://www.w3.org/2000/svg}text') + text.set('x', fo.get('x')) + text.set('y', fo.get('y')) + for line in lines: + tspan = ET.Element('{http://www.w3.org/2000/svg}tspan') + tspan.set('x', fo.get('x')) + tspan.set('dy', '1em') + tspan.text = line + text.append(tspan) + + shape.set('style', shape.get('style').replace('color:', 'fill:')) + shape.remove(switch) + shape.append(text) + def add_slides(self, with_annotations): layer = self._add_layer('Slides') doc = ET.parse(os.path.join(self.opts.basedir, 'shapes.svg')) @@ -252,8 +281,7 @@ def add_slides(self, with_annotations): info = slides[canvas.get('image')] t = IntervalTree() for index, shape in enumerate(canvas.iterfind('./{http://www.w3.org/2000/svg}g[@class="shape"]')): - shape.set('style', shape.get('style').replace( - 'visibility:hidden;', '')) + self._clean_shape(shape) timestamp = round(float(shape.get('timestamp')) * Gst.SECOND) undo = round(float(shape.get('undo')) * Gst.SECOND) if undo < 0: From f04025227ecbebb07018522b0d2aba5f04f07dc3 Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Fri, 9 Apr 2021 09:50:34 +0800 Subject: [PATCH 2/2] make-xges: use 'fill:currentcolor' to set text colour --- make-xges.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/make-xges.py b/make-xges.py index 99bc8e2..80d1820 100755 --- a/make-xges.py +++ b/make-xges.py @@ -176,7 +176,7 @@ def add_webcams(self): def _clean_shape(self, shape): # Shapes are hidden by default, as the JavaScript player would # make the visible as appropriate. - shape.set('style', shape.get('style').replace('visibility:hidden;', '')) + style = shape.get('style').replace('visibility:hidden;', '') # Add an SVG fallback to text shapes switch = shape.find('./{http://www.w3.org/2000/svg}switch') @@ -198,10 +198,12 @@ def _clean_shape(self, shape): tspan.text = line text.append(tspan) - shape.set('style', shape.get('style').replace('color:', 'fill:')) + style += ';fill:currentcolor' shape.remove(switch) shape.append(text) + shape.set('style', style) + def add_slides(self, with_annotations): layer = self._add_layer('Slides') doc = ET.parse(os.path.join(self.opts.basedir, 'shapes.svg'))