lib/isodoc/ogc/ogc.reference-model.xsl in metanorma-ogc-2.5.6 vs lib/isodoc/ogc/ogc.reference-model.xsl in metanorma-ogc-2.5.7

- old
+ new

@@ -740,15 +740,19 @@ </fo:block-container> </xsl:template> <!-- Lato font doesn't contain 'thin space' glyph --> <xsl:template match="text()" priority="1"> - <xsl:value-of select="translate(., $thin_space, ' ')"/> + <xsl:call-template name="add_fo_character"> + <xsl:with-param name="text" select="translate(., $thin_space, ' ')"/> + </xsl:call-template> </xsl:template> <xsl:template match="ogc:title//text() | ogc:name//text()" priority="3" mode="contents"> - <xsl:value-of select="translate(., $thin_space, ' ')"/> + <xsl:call-template name="add_fo_character"> + <xsl:with-param name="text" select="translate(., $thin_space, ' ')"/> + </xsl:call-template> </xsl:template> <xsl:template match="*[local-name()='td']//text() | *[local-name()='th']//text()" priority="2"> <xsl:variable name="content"> <xsl:call-template name="add-zero-spaces-java"/> @@ -760,13 +764,60 @@ <xsl:variable name="content3" select="java:replaceAll(java:java.lang.String.new($content2), '(\w)(\()(\w)', '$1​$2$3')"/> <!-- replace sequence #x200B to one &#x200B --> <xsl:variable name="content4" select="java:replaceAll(java:java.lang.String.new($content3), '\u200b{2,}', '​')"/> - <xsl:value-of select="translate($content4, $thin_space, ' ')"/> + <xsl:call-template name="add_fo_character"> + <xsl:with-param name="text" select="translate($content4, $thin_space, ' ')"/> + </xsl:call-template> </xsl:template> + <xsl:template name="add_fo_character"> + <xsl:param name="text"/> + <!-- https://github.com/metanorma/mn-native-pdf/issues/672, https://issues.apache.org/jira/browse/FOP-3175 --> + <!-- Miscellaneous Symbols https://www.compart.com/en/unicode/block/U+2600 U+2600 - U+26FF --> + <!-- Dingbats https://www.compart.com/en/unicode/block/U+2700 U+2700 - U+27BF --> + <!-- Miscellaneous Symbols and Arrows https://www.compart.com/en/unicode/block/U+2b55 U+2B00 - U+2BFF--> + <!-- enclose chars into <fo:character character="..."/> --> + <xsl:variable name="regex_dingbats_chars">([\u2100-\u2BFF])</xsl:variable> <!-- \u1F300;-\u1F5FF; not working in fo:character --> + <xsl:variable name="element_name_fo_character">fo:character</xsl:variable> + <xsl:variable name="tag_element_name_fo_character_open">###<xsl:value-of select="$element_name_fo_character"/>###</xsl:variable> + <xsl:variable name="tag_element_name_fo_character_close">###/<xsl:value-of select="$element_name_fo_character"/>###</xsl:variable> + <xsl:variable name="text_" select="java:replaceAll(java:java.lang.String.new($text), $regex_dingbats_chars, concat($tag_element_name_fo_character_open,'$1',$tag_element_name_fo_character_close))"/> + <xsl:call-template name="replace_text_tags_fo_character"> + <xsl:with-param name="tag_open" select="$tag_element_name_fo_character_open"/> + <xsl:with-param name="tag_close" select="$tag_element_name_fo_character_close"/> + <xsl:with-param name="text" select="$text_"/> + </xsl:call-template> + </xsl:template> + + <!-- ###fo:character###A###/fo:character### --> + <xsl:template name="replace_text_tags_fo_character"> + <xsl:param name="tag_open"/> + <xsl:param name="tag_close"/> + <xsl:param name="text"/> + <xsl:choose> + <xsl:when test="contains($text, $tag_open)"> + <xsl:value-of select="substring-before($text, $tag_open)"/> + <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/> + + <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}"> + <xsl:attribute name="character"> + <xsl:value-of select="substring-before($text_after, $tag_close)"/> + </xsl:attribute> + </xsl:element> + + <xsl:call-template name="replace_text_tags_fo_character"> + <xsl:with-param name="tag_open" select="$tag_open"/> + <xsl:with-param name="tag_close" select="$tag_close"/> + <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise> + </xsl:choose> + </xsl:template> + <xsl:template match="node()" mode="sections"> <xsl:param name="initial-page-number"/> <fo:page-sequence master-reference="document" force-page-count="no-force" color="white"> <xsl:if test="$initial-page-number != ''"> <xsl:attribute name="initial-page-number">1</xsl:attribute> @@ -1055,10 +1106,12 @@ <!-- ====== --> <xsl:template match="ogc:p" name="paragraph"> <xsl:param name="inline" select="'false'"/> <xsl:param name="split_keep-within-line"/> + <xsl:param name="indent">0</xsl:param> + <!-- <fo:block>debug p indent=<xsl:value-of select="$indent"/></fo:block> --> <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/> <xsl:variable name="element-name"> <xsl:choose> <xsl:when test="$inline = 'true'">fo:inline</xsl:when> <xsl:when test="../@inline-header = 'true' and $previous-element = 'title'">fo:inline</xsl:when> <!-- first paragraph after inline title --> @@ -1090,10 +1143,11 @@ </xsl:if> </xsl:if> <xsl:apply-templates> <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/> + <xsl:with-param name="indent" select="$indent"/> </xsl:apply-templates> </xsl:element> <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')"> <fo:block margin-bottom="12pt"> <xsl:if test="ancestor::ogc:annex"> @@ -1112,31 +1166,32 @@ <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="ogc:ul | ogc:ol" mode="list" priority="2"> - <xsl:variable name="ul_indent">6mm</xsl:variable> - <fo:block-container margin-left="13mm"> - <xsl:if test="self::ogc:ul and not(ancestor::ogc:ul) and not(ancestor::ogc:ol)"> <!-- if first level --> - <xsl:attribute name="margin-left">4mm</xsl:attribute> - </xsl:if> - <xsl:if test="self::ogc:ul and ancestor::*[2][self::ogc:ul]"> <!-- ul/li/ul --> - <xsl:attribute name="margin-left"><xsl:value-of select="$ul_indent"/></xsl:attribute> - </xsl:if> - <xsl:if test="ancestor::ogc:table"> - <xsl:attribute name="margin-left">4mm</xsl:attribute> - </xsl:if> + <xsl:param name="indent">0</xsl:param> + <!-- <fo:block>debug ul ol indent=<xsl:value-of select="$indent"/></fo:block> --> + <xsl:variable name="ul_indent">6</xsl:variable> + <xsl:variable name="margin_left"> + <xsl:choose> + <xsl:when test="self::ogc:ul and not(ancestor::ogc:ul) and not(ancestor::ogc:ol)">4</xsl:when> <!-- if first level --> + <xsl:when test="self::ogc:ul and ancestor::*[2][self::ogc:ul]"><xsl:value-of select="$ul_indent"/></xsl:when> <!-- ul/li/ul --> + <xsl:when test="ancestor::ogc:table">4</xsl:when> + <xsl:otherwise>13</xsl:otherwise> + </xsl:choose> + </xsl:variable> + <fo:block-container margin-left="{$margin_left}mm"> <xsl:if test="ancestor::ogc:ul or ancestor::ogc:ol"> <xsl:attribute name="margin-top">10pt</xsl:attribute> <xsl:if test="ancestor::ogc:table"> <xsl:attribute name="margin-top">1mm</xsl:attribute> </xsl:if> </xsl:if> <fo:block-container margin-left="0mm"> <fo:list-block xsl:use-attribute-sets="list-style"> <xsl:if test="self::ogc:ul"> - <xsl:attribute name="provisional-distance-between-starts"><xsl:value-of select="$ul_indent"/></xsl:attribute> + <xsl:attribute name="provisional-distance-between-starts"><xsl:value-of select="$ul_indent"/>mm</xsl:attribute> </xsl:if> <xsl:if test="ancestor::ogc:table"> <xsl:attribute name="provisional-distance-between-starts">5mm</xsl:attribute> </xsl:if> <xsl:if test="ancestor::ogc:ul | ancestor::ogc:ol"> @@ -1146,11 +1201,13 @@ </xsl:if> </xsl:if> <xsl:if test="following-sibling::*[1][local-name() = 'ul' or local-name() = 'ol']"> <xsl:attribute name="margin-bottom">0pt</xsl:attribute> </xsl:if> - <xsl:apply-templates/> + <xsl:apply-templates> + <xsl:with-param name="indent" select="$indent + $ul_indent"/> + </xsl:apply-templates> </fo:list-block> </fo:block-container> </fo:block-container> </xsl:template> @@ -1254,13 +1311,17 @@ </xsl:variable> <xsl:value-of select="java:toUpperCase(java:java.lang.String.new($text))"/> </xsl:template> <xsl:template match="ogc:figure" priority="2"> + <xsl:param name="indent"/> + <!-- <fo:block>debug figure indent=<xsl:value-of select="$indent"/></fo:block> --> <fo:block-container id="{@id}" margin-top="12pt" margin-bottom="12pt"> <fo:block> - <xsl:apply-templates select="node()[not(local-name() = 'name')]"/> + <xsl:apply-templates select="node()[not(local-name() = 'name')]"> + <xsl:with-param name="indent" select="$indent"/> + </xsl:apply-templates> </fo:block> <xsl:call-template name="fn_display_figure"/> <xsl:for-each select="ogc:note"> <xsl:call-template name="note"/> </xsl:for-each> @@ -7933,23 +7994,60 @@ <xsl:call-template name="termsource"/> </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> <xsl:attribute name="padding-right">0mm</xsl:attribute> </xsl:if> <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> <fo:block xsl:use-attribute-sets="image-style"> @@ -7966,54 +8064,46 @@ <xsl:attribute name="width">100%</xsl:attribute> <xsl:attribute name="content-height">100%</xsl:attribute> <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:call-template name="setImageWidthHeight"/> - <xsl:if test="@height != '' and @height != 'auto'"> - <xsl:attribute name="height"> - <xsl:value-of select="@height"/> - </xsl:attribute> - </xsl:if> - <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> </xsl:if> @@ -8025,10 +8115,66 @@ </fo:block> </xsl:otherwise> </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]"> <xsl:value-of select="$images/images/image[@id = current()/@id]/@src"/> </xsl:when> @@ -10751,10 +10897,11 @@ </xsl:otherwise> </xsl:choose> </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"> <xsl:attribute name="margin-left"> <xsl:choose> @@ -10765,19 +10912,23 @@ <xsl:call-template name="refine_list_container_style"/> <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> </xsl:choose> </xsl:template> @@ -10858,10 +11009,17 @@ </fo:block> </xsl:if> </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"/> <xsl:call-template name="refine_list-item-style"/> @@ -10882,10 +11040,12 @@ <fo:list-item-body start-indent="body-start()" xsl:use-attribute-sets="list-item-body-style"> <fo:block role="SKIP"> <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')]" /> <xsl:for-each select="./bsi:note"> <xsl:call-template name="note"/> \ No newline at end of file