Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xslt update based on metanorma/mn-native-pdf@9a519d2b5102ad1c4b061a1b2e329a7d9721bb61 #1160

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 129 additions & 30 deletions lib/isodoc/iso/iso.amendment.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11435,10 +11435,11 @@
</xsl:template>

<xsl:template match="*[local-name() = 'image']">
<xsl:param name="indent">0</xsl:param>
<xsl:variable name="isAdded" select="../@added"/>
<xsl:variable name="isDeleted" select="../@deleted"/>
<xsl:choose>
<xsl:when test="ancestor::*[local-name() = 'title'] or not(parent::*[local-name() = 'figure']) or parent::*[local-name() = 'p']">
<xsl:when test="ancestor::*[local-name() = 'title'] or not(parent::*[local-name() = 'figure']) or parent::*[local-name() = 'p']"> <!-- inline image ( 'image:path' in adoc, with one colon after image) -->
<fo:inline padding-left="1mm" padding-right="1mm">
<xsl:if test="not(parent::*[local-name() = 'figure']) or parent::*[local-name() = 'p']">
<xsl:attribute name="padding-left">0mm</xsl:attribute>
Expand All @@ -11447,7 +11448,43 @@
<xsl:variable name="src">
<xsl:call-template name="image_src"/>
</xsl:variable>
<fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}" vertical-align="middle"/>

<xsl:variable name="scale">
<xsl:call-template name="getImageScale">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
</xsl:variable>

<!-- debug scale='<xsl:value-of select="$scale"/>', indent='<xsl:value-of select="$indent"/>' -->

<!-- <fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}" vertical-align="middle"/> -->
<fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}" vertical-align="middle">

<xsl:variable name="width">
<xsl:call-template name="setImageWidth"/>
</xsl:variable>
<xsl:if test="$width != ''">
<xsl:attribute name="width"><xsl:value-of select="$width"/></xsl:attribute>
</xsl:if>
<xsl:variable name="height">
<xsl:call-template name="setImageHeight"/>
</xsl:variable>
<xsl:if test="$height != ''">
<xsl:attribute name="height"><xsl:value-of select="$height"/></xsl:attribute>
</xsl:if>

<xsl:if test="$width = '' and $height = ''">
<xsl:if test="number($scale) &lt; 100">
<xsl:attribute name="content-width"><xsl:value-of select="number($scale)"/>%</xsl:attribute>
<!-- <xsl:attribute name="content-width">scale-to-fit</xsl:attribute>
<xsl:attribute name="content-height">100%</xsl:attribute>
<xsl:attribute name="width">100%</xsl:attribute>
<xsl:attribute name="scaling">uniform</xsl:attribute> -->
</xsl:if>
</xsl:if>

</fo:external-graphic>

</fo:inline>
</xsl:when>
<xsl:otherwise>
Expand All @@ -11468,50 +11505,42 @@
<xsl:attribute name="content-width">scale-down-to-fit</xsl:attribute>
<xsl:attribute name="scaling">uniform</xsl:attribute>

<xsl:apply-templates select="." mode="cross_image"/>
<xsl:apply-templates select="." mode="cross_image"/>

</fo:instream-foreign-object>
</xsl:when>
<xsl:otherwise>
<!-- <fo:block>debug block image:
<xsl:variable name="scale">
<xsl:call-template name="getImageScale">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat('scale=', $scale,', indent=', $indent)"/>
</fo:block> -->
<fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}" xsl:use-attribute-sets="image-graphic-style">
<xsl:if test="not(@mimetype = 'image/svg+xml') and (../*[local-name() = 'name'] or parent::*[local-name() = 'figure'][@unnumbered = 'true']) and not(ancestor::*[local-name() = 'table'])">

<xsl:if test="@width != '' and @width != 'auto' and @width != 'text-width' and @width != 'full-page-width' and @width != 'narrow'">
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
</xsl:if>

<xsl:if test="@height != '' and @height != 'auto'">
<xsl:attribute name="height">
<xsl:value-of select="@height"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="setImageWidthHeight"/>

<xsl:choose>
<xsl:when test="@width != '' and @width != 'auto' and @height != '' and @height != 'auto'">
<xsl:attribute name="scaling">non-uniform</xsl:attribute>
</xsl:when>
<xsl:otherwise>

<xsl:variable name="img_src">
<xsl:choose>
<xsl:when test="not(starts-with(@src, 'data:'))"><xsl:value-of select="concat($basepath, @src)"/></xsl:when>
<xsl:otherwise><xsl:value-of select="@src"/></xsl:otherwise>
</xsl:choose>
<xsl:variable name="scale">
<xsl:call-template name="getImageScale">
<xsl:with-param name="indent" select="$indent"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="image_width_effective">

<xsl:value-of select="$width_effective"/>

<xsl:variable name="scaleRatio">
1
</xsl:variable>

<xsl:variable name="scale" select="java:org.metanorma.fop.Util.getImageScale($img_src, $image_width_effective, $height_effective)"/>
<xsl:if test="number($scale) &lt; 100">

<xsl:attribute name="content-width"><xsl:value-of select="$scale"/>%</xsl:attribute>

<xsl:attribute name="content-width"><xsl:value-of select="number($scale) * number($scaleRatio)"/>%</xsl:attribute>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
Expand All @@ -11527,6 +11556,62 @@
</xsl:choose>
</xsl:template>

<xsl:template name="setImageWidth">
<xsl:if test="@width != '' and @width != 'auto' and @width != 'text-width' and @width != 'full-page-width' and @width != 'narrow'">
<xsl:value-of select="@width"/>
</xsl:if>
</xsl:template>
<xsl:template name="setImageHeight">
<xsl:if test="@height != '' and @height != 'auto'">
<xsl:value-of select="@height"/>
</xsl:if>
</xsl:template>
<xsl:template name="setImageWidthHeight">
<xsl:variable name="width">
<xsl:call-template name="setImageWidth"/>
</xsl:variable>
<xsl:if test="$width != ''">
<xsl:attribute name="width">
<xsl:value-of select="$width"/>
</xsl:attribute>
</xsl:if>
<xsl:variable name="height">
<xsl:call-template name="setImageHeight"/>
</xsl:variable>
<xsl:if test="$height != ''">
<xsl:attribute name="height">
<xsl:value-of select="$height"/>
</xsl:attribute>
</xsl:if>
</xsl:template>

<xsl:template name="getImageScale">
<xsl:param name="indent"/>
<xsl:variable name="indent_left">
<xsl:choose>
<xsl:when test="$indent != ''"><xsl:value-of select="$indent"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="img_src">
<xsl:choose>
<xsl:when test="not(starts-with(@src, 'data:'))"><xsl:value-of select="concat($basepath, @src)"/></xsl:when>
<xsl:otherwise><xsl:value-of select="@src"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="image_width_effective">

<xsl:value-of select="$width_effective - number($indent_left)"/>

</xsl:variable>
<!-- <xsl:message>width_effective=<xsl:value-of select="$width_effective"/></xsl:message>
<xsl:message>indent_left=<xsl:value-of select="$indent_left"/></xsl:message>
<xsl:message>image_width_effective=<xsl:value-of select="$image_width_effective"/> for <xsl:value-of select="ancestor::ogc:p[1]/@id"/></xsl:message> -->
<xsl:variable name="scale" select="java:org.metanorma.fop.Util.getImageScale($img_src, $image_width_effective, $height_effective)"/>
<xsl:value-of select="$scale"/>
</xsl:template>

<xsl:template name="image_src">
<xsl:choose>
<xsl:when test="@mimetype = 'image/svg+xml' and $images/images/image[@id = current()/@id]">
Expand Down Expand Up @@ -14214,6 +14299,7 @@
</xsl:template>

<xsl:template match="*[local-name() = 'ul'] | *[local-name() = 'ol']">
<xsl:param name="indent">0</xsl:param>
<xsl:choose>
<xsl:when test="parent::*[local-name() = 'note'] or parent::*[local-name() = 'termnote']">
<fo:block-container role="SKIP">
Expand All @@ -14228,15 +14314,19 @@

<fo:block-container margin-left="0mm" role="SKIP">
<fo:block>
<xsl:apply-templates select="." mode="list"/>
<xsl:apply-templates select="." mode="list">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:when>
<xsl:otherwise>

<fo:block role="SKIP">
<xsl:apply-templates select="." mode="list"/>
<xsl:apply-templates select="." mode="list">
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>
</fo:block>

</xsl:otherwise>
Expand Down Expand Up @@ -14321,6 +14411,13 @@
</xsl:template>

<xsl:template match="*[local-name()='li']">
<xsl:param name="indent">0</xsl:param>
<!-- <fo:list-item xsl:use-attribute-sets="list-item-style">
<fo:list-item-label end-indent="label-end()"><fo:block>x</fo:block></fo:list-item-label>
<fo:list-item-body start-indent="body-start()" xsl:use-attribute-sets="list-item-body-style">
<fo:block>debug li indent=<xsl:value-of select="$indent"/></fo:block>
</fo:list-item-body>
</fo:list-item> -->
<fo:list-item xsl:use-attribute-sets="list-item-style">
<xsl:copy-of select="@id"/>

Expand All @@ -14345,7 +14442,9 @@

<xsl:call-template name="refine_list-item-body-style"/>

<xsl:apply-templates/>
<xsl:apply-templates>
<xsl:with-param name="indent" select="$indent"/>
</xsl:apply-templates>

<!-- <xsl:apply-templates select="node()[not(local-name() = 'note')]" />

Expand Down
Loading
Loading