SVGHMI: attempt to prevent crazy styling with HMI:TextStyleList when inkscape store style in tspan instead of text element. svghmi
authorEdouard Tisserant
Tue, 02 Mar 2021 17:30:13 +0100
branchsvghmi
changeset 3175 b2ba6eeb61ec
parent 3174 bc4194b73438
child 3176 81136a097012
child 3178 21cb76012c78
SVGHMI: attempt to prevent crazy styling with HMI:TextStyleList when inkscape store style in tspan instead of text element.
svghmi/gen_index_xhtml.xslt
svghmi/widget_list.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Tue Mar 02 10:11:45 2021 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Tue Mar 02 17:30:13 2021 +0100
@@ -5513,7 +5513,21 @@
     <xsl:text>    styles: {
 </xsl:text>
     <xsl:for-each select="$hmi_element/*[@inkscape:label]">
-      <xsl:variable name="style" select="func:refered_elements(.)[self::svg:text]/@style"/>
+      <xsl:variable name="text" select="func:refered_elements(.)[self::svg:text][1]"/>
+      <xsl:variable name="tspan" select="$text/svg:tspan[1]"/>
+      <xsl:variable name="style">
+        <xsl:choose>
+          <xsl:when test="$text/@style and $tspan/@style">
+            <xsl:value-of select="$text/@style"/>
+            <xsl:text>;</xsl:text>
+            <xsl:value-of select="$tspan/@style"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$text/@style"/>
+            <xsl:value-of select="$tspan/@style"/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
       <xsl:text>        </xsl:text>
       <xsl:value-of select="@inkscape:label"/>
       <xsl:text>: "</xsl:text>
--- a/svghmi/widget_list.ysl2	Tue Mar 02 10:11:45 2021 +0100
+++ b/svghmi/widget_list.ysl2	Tue Mar 02 17:30:13 2021 +0100
@@ -13,7 +13,13 @@
     param "hmi_element";
     |     styles: {
     foreach "$hmi_element/*[@inkscape:label]" {
-        const "style", "func:refered_elements(.)[self::svg:text]/@style";
+        const "text", "func:refered_elements(.)[self::svg:text][1]";
+        const "tspan", "$text/svg:tspan[1]";
+        const "style" choose {
+            when "$text/@style and $tspan/@style" > «$text/@style»;«$tspan/@style»
+            otherwise > «$text/@style»«$tspan/@style»
+
+        }
     |         «@inkscape:label»: "«$style»",
     }
     |     },