Skip to content

Commit

Permalink
add viewBox in xy pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
xworld21 committed Aug 17, 2024
1 parent c3d682e commit b0cb340
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/LaTeXML/Package/xy.tex.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ DefConstructor('\lx@xy@svgnested Digested',
return (width => $w, height => $y1, depth => $y0->negate, transform => $transform); });

DefConstructor('\lx@xy@svg Digested',
"<ltx:picture><svg:svg overflow='visible' version='1.1' width='#pxwidth' height='#pxheight'>"
"<ltx:picture imagedepth='#imagedepth'><svg:svg overflow='visible' version='1.1' width='#pxwidth' height='#pxheight' viewBox='#minx #miny #pxwidth #pxheight'>"
. "<svg:g transform='#transform'>#1</svg:g>"
. "</svg:svg></ltx:picture>",
properties => sub {
Expand All @@ -101,14 +101,16 @@ DefConstructor('\lx@xy@svg Digested',
if $LaTeXML::DEBUG{xy};
my $w = $x1->subtract($x0);
my $h = $y1->subtract($y0);
my $x = $x0->negate->larger(Dimension(0));
my $x = $x0->negate;
my $yma = Dimension(LookupValue('IN_MATH') ? '2.5pt' : 0); # math-axis; fontdimen 22
my $y = $y1->add($yma->subtract($y0->larger(Dimension(0))));
my $miny = $yma->subtract($y0);
my $y = $y1->add($yma->subtract($y0));
my $transform = "matrix(1 0 0 -1 " . $x->pxValue . ' ' . $y->pxValue . ')';
Debug("XY size: " . ToString($w) . ' x ' . ToString($h) . ' + ' . 0 . ' @ ' . ToString($x) . ' x ' . ToString($y))

if $LaTeXML::DEBUG{xy};
return (width => $w, height => $h, pxwidth => $w->pxValue, pxheight => $h->pxValue,
minx => $x->pxValue, miny => $miny->pxValue, imagedepth => int($miny->pxValue + 0.5),
transform => $transform); });

DefPrimitive('\lx@xy@capturerange', sub {
Expand Down
22 changes: 21 additions & 1 deletion lib/LaTeXML/resources/XSLT/LaTeXML-picture-xhtml.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,29 @@
<xsl:call-template name="copy_foreign_attributes"/>
<xsl:apply-templates select="." mode="add_RDFa"/>
<!-- but copy other svg:svg attributes -->
<xsl:for-each select="svg:svg/@*">
<xsl:for-each select="svg:svg/@*[name() != 'style']">
<xsl:apply-templates select="." mode="copy-attribute"/>
</xsl:for-each>
<xsl:choose>
<xsl:when test="svg:svg/@style">
<xsl:for-each select="svg:svg/@style">
<xsl:call-template name="add_style">
<xsl:with-param name="extra_style">
<xsl:if test="@imagedepth">
<xsl:value-of select="concat('vertical-align:-',@imagedepth,'px')"/>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@imagedepth">
<xsl:attribute name="style">
<xsl:value-of select="concat('vertical-align:-',@imagedepth,'px')"/>
</xsl:attribute>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="svg:svg/*"/>
</xsl:element>
</xsl:template>
Expand Down

0 comments on commit b0cb340

Please sign in to comment.