Skip to content

Commit cead2cf

Browse files
authored
Merge pull request #1210 from mathics/fix_to_svg
Fix to svg
2 parents 2c1dc75 + cc887a9 commit cead2cf

File tree

12 files changed

+172
-98
lines changed

12 files changed

+172
-98
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Enhancements
2929
* Improvements in handling products with infinite factors: ``0 Infinity``-> ``Indeterminate``, and ``expr Infinity``-> ``DirectedInfinite[expr]`.
3030
* ``SetDelayed`` now accept several conditions impossed both at LHS as well as RHS.
3131

32+
3233
Bug fixes
3334
+++++++++
3435

@@ -53,6 +54,13 @@ Miscellanea
5354
Windows under MSYS.
5455
* Include numpy version in version string. Show in CLI
5556
* Small CLI tweaks ``--colors=None`` added to match mathicsscript.
57+
* In the ``BaseExpression`` and derivated classes, the method ``boxes_to_xml`` now are called ``boxes_to_mathml``.
58+
* In the ``format`` method of the class ``Evaluation``, the builtin ``ToString`` is called instead of ``boxes_to_text``
59+
In order to control the final form of boxes from the user space in specific symbols and contexts.
60+
* ``GraphicsBox`` now have two methods: ``to_svg`` and ``to_mathml``. The first produces SVG plain text while the second produces ``<mglyph ...>``
61+
tags with base64 encoded svgs.
62+
* Improving the support for ``Inset`` and ``InsetBox``.
63+
5664

5765
2.0.0
5866
-----

mathics/autoload/formats/SVG/Export.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44

55

66
SVGExport[filename_, expr_, opts___] :=
7-
Module[{strm, data},
7+
Module[{strm, data, p, q, expr2},
88
strm = OpenWrite[filename];
99
If[strm === $Failed, Return[$Failed]];
10-
If[System`$UseSansSerif,
11-
data = StringTake[ToString[MathMLForm[expr]],{23,-8}],
12-
data = StringTake[ToString[MathMLForm[expr]],{23,-8}]];
13-
WriteString[strm, "<svg>" <> data <> "</svg>"];
10+
expr2 = If[Head[expr]=!=System`Graphics, System`Graphics[{System`Inset[ToString[expr]]}], expr];
11+
expr2= MathMLForm[expr2];
12+
data=ToString[expr2];
13+
p = StringPosition[data, "data:image/svg+xml;base64"][[1]][[2]];
14+
(*Let's assume that the end of the string is reached just before the last quote. *)
15+
q = StringPosition[data,"\""][[-1]][[-2]];
16+
data = StringTake[data ,{p+2,q-1}];
17+
WriteString[strm, System`Convert`B64Dump`B64Decode[data]];
1418
Close[strm];
1519
]
1620

mathics/builtin/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def get_option_values(self, leaves, **options):
710710
def boxes_to_text(self, leaves, **options) -> str:
711711
raise BoxConstructError
712712

713-
def boxes_to_xml(self, leaves, **options) -> str:
713+
def boxes_to_mathml(self, leaves, **options) -> str:
714714
raise BoxConstructError
715715

716716
def boxes_to_tex(self, leaves, **options) -> str:

mathics/builtin/compilation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def boxes_to_text(self, leaves=None, **options):
198198
leaves = self._leaves
199199
return leaves[0].value
200200

201-
def boxes_to_xml(self, leaves=None, **options):
201+
def boxes_to_mathml(self, leaves=None, **options):
202202
if leaves is None:
203203
leaves = self._leaves
204204
return leaves[0].value

0 commit comments

Comments
 (0)