Skip to content

Commit

Permalink
fix: Render unicode characters in SVG elements correctly (#832)
Browse files Browse the repository at this point in the history
* fix: Render unicode characters in SVG elements correctly

* fix: Stop the warning when SVG element ends with an unicode character
  • Loading branch information
kesara authored Jul 19, 2022
1 parent 63de72a commit ad44bb8
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 117 deletions.
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def norm(t):
#
text = norm('\n'.join( p.text for p in self.pdfxml.xpath('.//Page/text') ))
for e in self.root.xpath('./middle//*'):
if e.text and e.text.strip() and e.tag not in xml2rfc.util.unicode.unicode_content_tags:
if e.text and e.text.strip() and e.tag not in xml2rfc.util.unicode.unicode_content_tags and not xml2rfc.util.unicode.is_svg(e):
t = norm(e.text.split(None, 1)[0])
self.assertIn(t, text)

Expand Down
14 changes: 14 additions & 0 deletions tests/input/elements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,20 @@ Unordered list, third bullet, fourth element:
<xi:include href="./ietf.svg"/>
</artwork>
</li>
<li>
<t>Unicode SVG rendering test</t>
<artwork alt="Unicode SVG" type="svg" align="center">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 64">
<path d="M 8,16 L 8,48" fill="none" stroke="black"/>
<path d="M 64,16 L 64,48" fill="none" stroke="black"/>
<path d="M 8,16 L 64,16" fill="none" stroke="black"/>
<path d="M 8,48 L 64,48" fill="none" stroke="black"/>
<g class="text">
<text y="36" x="13">⊕⊖⊗⊘</text>
</g>
</svg>
</artwork>
</li>
</ul>
</section>
<section>
Expand Down
70 changes: 35 additions & 35 deletions tests/valid/elements.bom.text
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Table of Contents
3. Unordered list with sub-elements . . . . . . . . . . . . . . 5
4. Ordered list with sub-elements . . . . . . . . . . . . . . . 7
5. Definition list with sub-elements . . . . . . . . . . . . . . 9
6. Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6. Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7. Unicode Literals . . . . . . . . . . . . . . . . . . . . . . 13
7.1. Single Characters . . . . . . . . . . . . . . . . . . . . 13
7.2. Character Strings . . . . . . . . . . . . . . . . . . . . 15
Expand Down Expand Up @@ -358,6 +358,11 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
(Artwork only available as svg: No external link available, see
elements-00.html for artwork.)

* Unicode SVG rendering test

(Artwork only available as svg: No external link available, see
elements-00.html for artwork.)

4. Ordered list with sub-elements

1. Ordered list, first bullet. Indent="6".
Expand All @@ -377,15 +382,10 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
voluptate vivere. Sic faciam igitur, inquit: unam rem explicabo,
eamque maximam, de physicis alias, et quidem locis pluribus.

Ordered list, third bullet, second element:
+-------------------------------------------+
| |
| Artwork |
| |
+-------------------------------------------+

Ordered list, third bullet, third element: Definition list,
element dt.






Expand All @@ -394,6 +394,15 @@ Author, et al. Expires 13 January 2019 [Page 7]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


Ordered list, third bullet, second element:
+-------------------------------------------+
| |
| Artwork |
| |
+-------------------------------------------+

Ordered list, third bullet, third element: Definition list,
element dt.
Element dd. Nisi mihi Phaedrum, inquam, tu mentitum aut
Zenonem misisti.

Expand Down Expand Up @@ -433,15 +442,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
Case Ambiguity [RFC8174], Appendix A.1 / Key Words Case
Ambiguity [RFC8174] (Appendix A.1).

4.1 Sublist with '%p' parent counter element in the list
counter, item one

4.2 Item two.

4.3 Item three.






Expand All @@ -450,6 +450,13 @@ Author, et al. Expires 13 January 2019 [Page 8]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


4.1 Sublist with '%p' parent counter element in the list
counter, item one

4.2 Item two.

4.3 Item three.

5. Definition list with sub-elements

Term 1 Definition list, first bullet.
Expand Down Expand Up @@ -491,13 +498,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
1. Definition list, third bullet, fifth element: Ordered list,
element li. Text only.

2. Definition list, third bullet, fifth element: Ordered list,
element t. Nam cum ad me de virtute misisti. Quae est enim
contra Cyrenaicos satis acute, nihil ad iucunde vivendum
reperiri posse, quod coniunctione tali sit aptius. Quae etsi
mihi nullo modo nec divelli nec distrahi possint, sic de
iustitia iudicandum est, quae non modo non impediri rationem
amicitiae, si summum bonum diceret, primum in eo essent.



Expand All @@ -506,6 +506,14 @@ Author, et al. Expires 13 January 2019 [Page 9]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


2. Definition list, third bullet, fifth element: Ordered list,
element t. Nam cum ad me de virtute misisti. Quae est enim
contra Cyrenaicos satis acute, nihil ad iucunde vivendum
reperiri posse, quod coniunctione tali sit aptius. Quae etsi
mihi nullo modo nec divelli nec distrahi possint, sic de
iustitia iudicandum est, quae non modo non impediri rationem
amicitiae, si summum bonum diceret, primum in eo essent.

* UL within OL within DL, item one

* UL within OL within DL, item two
Expand Down Expand Up @@ -545,14 +553,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
voluptate vivere. Sic faciam igitur, inquit: unam rem explicabo,
eamque maximam, de physicis alias, et quidem locis pluribus.

6. Table










Expand All @@ -562,6 +562,8 @@ Author, et al. Expires 13 January 2019 [Page 10]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


6. Table

+-----+-----+-----------+
| | | |
+-----+-----+-----+-----+
Expand Down Expand Up @@ -611,8 +613,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018





Author, et al. Expires 13 January 2019 [Page 11]

Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
Expand Down
70 changes: 35 additions & 35 deletions tests/valid/elements.pages.text
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Table of Contents
3. Unordered list with sub-elements . . . . . . . . . . . . . . 5
4. Ordered list with sub-elements . . . . . . . . . . . . . . . 7
5. Definition list with sub-elements . . . . . . . . . . . . . . 9
6. Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
6. Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7. Unicode Literals . . . . . . . . . . . . . . . . . . . . . . 13
7.1. Single Characters . . . . . . . . . . . . . . . . . . . . 13
7.2. Character Strings . . . . . . . . . . . . . . . . . . . . 15
Expand Down Expand Up @@ -358,6 +358,11 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
(Artwork only available as svg: No external link available, see
elements-00.html for artwork.)

* Unicode SVG rendering test

(Artwork only available as svg: No external link available, see
elements-00.html for artwork.)

4. Ordered list with sub-elements

1. Ordered list, first bullet. Indent="6".
Expand All @@ -377,15 +382,10 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
voluptate vivere. Sic faciam igitur, inquit: unam rem explicabo,
eamque maximam, de physicis alias, et quidem locis pluribus.

Ordered list, third bullet, second element:
+-------------------------------------------+
| |
| Artwork |
| |
+-------------------------------------------+

Ordered list, third bullet, third element: Definition list,
element dt.






Expand All @@ -394,6 +394,15 @@ Author, et al. Expires January 13, 2019 [Page 7]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


Ordered list, third bullet, second element:
+-------------------------------------------+
| |
| Artwork |
| |
+-------------------------------------------+

Ordered list, third bullet, third element: Definition list,
element dt.
Element dd. Nisi mihi Phaedrum, inquam, tu mentitum aut
Zenonem misisti.

Expand Down Expand Up @@ -433,15 +442,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
Case Ambiguity [RFC8174], Appendix A.1 / Key Words Case
Ambiguity [RFC8174] (Appendix A.1).

4.1 Sublist with '%p' parent counter element in the list
counter, item one

4.2 Item two.

4.3 Item three.






Expand All @@ -450,6 +450,13 @@ Author, et al. Expires January 13, 2019 [Page 8]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


4.1 Sublist with '%p' parent counter element in the list
counter, item one

4.2 Item two.

4.3 Item three.

5. Definition list with sub-elements

Term 1 Definition list, first bullet.
Expand Down Expand Up @@ -491,13 +498,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
1. Definition list, third bullet, fifth element: Ordered list,
element li. Text only.

2. Definition list, third bullet, fifth element: Ordered list,
element t. Nam cum ad me de virtute misisti. Quae est enim
contra Cyrenaicos satis acute, nihil ad iucunde vivendum
reperiri posse, quod coniunctione tali sit aptius. Quae etsi
mihi nullo modo nec divelli nec distrahi possint, sic de
iustitia iudicandum est, quae non modo non impediri rationem
amicitiae, si summum bonum diceret, primum in eo essent.



Expand All @@ -506,6 +506,14 @@ Author, et al. Expires January 13, 2019 [Page 9]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


2. Definition list, third bullet, fifth element: Ordered list,
element t. Nam cum ad me de virtute misisti. Quae est enim
contra Cyrenaicos satis acute, nihil ad iucunde vivendum
reperiri posse, quod coniunctione tali sit aptius. Quae etsi
mihi nullo modo nec divelli nec distrahi possint, sic de
iustitia iudicandum est, quae non modo non impediri rationem
amicitiae, si summum bonum diceret, primum in eo essent.

* UL within OL within DL, item one

* UL within OL within DL, item two
Expand Down Expand Up @@ -545,14 +553,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
voluptate vivere. Sic faciam igitur, inquit: unam rem explicabo,
eamque maximam, de physicis alias, et quidem locis pluribus.

6. Table










Expand All @@ -562,6 +562,8 @@ Author, et al. Expires January 13, 2019 [Page 10]
Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018


6. Table

+-----+-----+-----------+
| | | |
+-----+-----+-----+-----+
Expand Down Expand Up @@ -611,8 +613,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018





Author, et al. Expires January 13, 2019 [Page 11]

Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018
Expand Down
16 changes: 15 additions & 1 deletion tests/valid/elements.prepped.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="info" docName="elements-00" indexInclude="false" ipr="trust200902" obsoletes="1234,5678,9012,3456,7890" prepTime="2022-05-09T06:41:10" scripts="Cherokee,Common,Greek,Han,Hebrew,Latin" sortRefs="true" submissionType="independent" symRefs="true" tocDepth="3" tocInclude="true">
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="info" docName="elements-00" indexInclude="false" ipr="trust200902" obsoletes="1234,5678,9012,3456,7890" prepTime="2022-07-12T11:20:45" scripts="Cherokee,Common,Greek,Han,Hebrew,Latin" sortRefs="true" submissionType="independent" symRefs="true" tocDepth="3" tocInclude="true">



Expand Down Expand Up @@ -544,6 +544,20 @@ Unordered list, third bullet, fourth element:
</svg>
</artwork>
</li>
<li pn="section-3-1.5">
<t indent="0" pn="section-3-1.5.1">Unicode SVG rendering test</t>
<artwork alt="Unicode SVG" type="svg" align="center" pn="section-3-1.5.2">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 64">
<path d="M 8,16 L 8,48" fill="none" stroke="black"/>
<path d="M 64,16 L 64,48" fill="none" stroke="black"/>
<path d="M 8,16 L 64,16" fill="none" stroke="black"/>
<path d="M 8,48 L 64,48" fill="none" stroke="black"/>
<g class="text">
<text y="36" x="13">⊕⊖⊗⊘</text>
</g>
</svg>
</artwork>
</li>
</ul>
</section>
<section numbered="true" removeInRFC="false" toc="include" pn="section-4">
Expand Down
5 changes: 5 additions & 0 deletions tests/valid/elements.text
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ Table of Contents
(Artwork only available as svg: No external link available, see
elements-00.html for artwork.)

* Unicode SVG rendering test

(Artwork only available as svg: No external link available, see
elements-00.html for artwork.)

4. Ordered list with sub-elements

1. Ordered list, first bullet. Indent="6".
Expand Down
16 changes: 15 additions & 1 deletion tests/valid/elements.v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<meta content="
This is the abstract.
" name="description">
<meta content="xml2rfc 3.12.7" name="generator">
<meta content="xml2rfc 3.13.0" name="generator">
<meta content="elements-00" name="ietf.draft">
<link href="tests/input/elements.xml" rel="alternate" type="application/rfc+xml">
<link href="#copyright" rel="license">
Expand Down Expand Up @@ -552,6 +552,20 @@ <h2 id="name-unordered-list-with-sub-ele">
<path d="M3,26h5v5h-5zM168,26h5v5h-5z"></path>
</svg><a href="#section-3-1.4.2" class="pilcrow"></a>
</div>
</li>
<li class="normal" id="section-3-1.5">
<p id="section-3-1.5.1">Unicode SVG rendering test<a href="#section-3-1.5.1" class="pilcrow"></a></p>
<div class="alignCenter art-svg artwork" id="section-3-1.5.2">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 64">
<path d="M 8,16 L 8,48" fill="none" stroke="black"></path>
<path d="M 64,16 L 64,48" fill="none" stroke="black"></path>
<path d="M 8,16 L 64,16" fill="none" stroke="black"></path>
<path d="M 8,48 L 64,48" fill="none" stroke="black"></path>
<g class="text">
<text y="36" x="13">⊕⊖⊗⊘</text>
</g>
</svg><a href="#section-3-1.5.2" class="pilcrow"></a>
</div>
</li>
</ul>
</section>
Expand Down
Loading

0 comments on commit ad44bb8

Please sign in to comment.