Skip to content

Commit

Permalink
JIS xslt refactored for horizontal digits, metanorma/metanorma-jis#257,
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Dec 12, 2024
1 parent bcc2930 commit bb628a2
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 58 deletions.
110 changes: 58 additions & 52 deletions xslt_src/common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -21224,7 +21224,7 @@
<!-- END: insert cover page image -->

<!-- https://github.com/metanorma/docs/blob/main/109.adoc -->
<xsl:variable name="regex_ja_spec_half_width">
<xsl:variable name="regex_ja_spec_half_width_">
\u0028 <!-- U+0028 LEFT PARENTHESIS (() -->
\u0029 <!-- U+0029 RIGHT PARENTHESIS ()) -->
\u007B <!-- U+007B LEFT CURLY BRACKET ({) -->
Expand All @@ -21234,6 +21234,7 @@
\u005B <!-- U+005B LEFT SQUARE BRACKET ([) -->
\u005D <!-- U+005D RIGHT SQUARE BRACKET (]) -->
</xsl:variable>
<xsl:variable name="regex_ja_spec_half_width" select="translate(normalize-space($regex_ja_spec_half_width_), ' ', '')"/>
<xsl:variable name="regex_ja_spec_">[
<!-- Rotate 90° clockwise -->
<xsl:value-of select="$regex_ja_spec_half_width"/>
Expand Down Expand Up @@ -21297,60 +21298,65 @@
</xsl:when>
<xsl:otherwise>
<xsl:if test="string-length($str) &gt; 0">
<xsl:variable name="horizontal_mode" select="normalize-space(ancestor::*[local-name() = 'span'][@class = 'horizontal'] and 1 = 1)"/>

<!-- <xsl:variable name="horizontal_mode" select="normalize-space(ancestor::*[local-name() = 'span'][@class = 'horizontal'] and 1 = 1)"/> -->
<xsl:variable name="char" select="substring($str,1,1)"/>

<xsl:variable name="char_half_width" select="normalize-space(java:matches(java:java.lang.String.new($char), concat('([', $regex_ja_spec_half_width, ']{1,})')))"/>

<fo:inline-container text-align="center"
alignment-baseline="central" width="1em" margin="0" padding="0"
text-indent="0mm" last-line-end-indent="0mm" start-indent="0mm" end-indent="0mm">
<xsl:if test="$char_half_width = 'true'">
<xsl:attribute name="width">0.5em</xsl:attribute>
<xsl:attribute name="baseline-shift">7%</xsl:attribute>
</xsl:if>
<xsl:if test="normalize-space($writing-mode) != ''">
<xsl:attribute name="writing-mode"><xsl:value-of select="$writing-mode"/></xsl:attribute>
<xsl:attribute name="reference-orientation">90</xsl:attribute>
</xsl:if>
<xsl:if test="normalize-space(java:matches(java:java.lang.String.new($char), concat('(', $regex_ja_spec, '{1,})'))) = 'true'">
<xsl:attribute name="reference-orientation">0</xsl:attribute>
</xsl:if>
<xsl:if test="$char = '゜' or $char = '。' or $char = '﹒' or $char = '.'">
<!-- Rotate 180°:
U+309C KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK (゜)
U+3002 IDEOGRAPHIC FULL STOP (。)
U+FE52 SMALL FULL STOP (﹒)
U+FF0E FULLWIDTH FULL STOP (.)
-->
<xsl:attribute name="reference-orientation">-90</xsl:attribute>
</xsl:if>
<fo:block-container width="1em"><!-- border="0.5pt solid blue" -->
<xsl:if test="$char_half_width = 'true'">
<xsl:attribute name="width">0.5em</xsl:attribute>
</xsl:if>
<fo:block line-height="1em">
<xsl:choose>
<xsl:when test="$horizontal_mode = 'true'">
<xsl:value-of select="$str"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$char_half_width = 'true'">
<fo:inline>
<xsl:attribute name="baseline-shift">7%</xsl:attribute>
<xsl:value-of select="$char"/>
</fo:inline>
</xsl:when>
<xsl:otherwise>
<fo:inline-container text-align="center"
alignment-baseline="central" width="1em" margin="0" padding="0"
text-indent="0mm" last-line-end-indent="0mm" start-indent="0mm" end-indent="0mm" role="SKIP">
<xsl:if test="normalize-space($writing-mode) != ''">
<xsl:attribute name="writing-mode"><xsl:value-of select="$writing-mode"/></xsl:attribute>
<xsl:attribute name="reference-orientation">90</xsl:attribute>
</xsl:if>
<xsl:if test="normalize-space(java:matches(java:java.lang.String.new($char), concat('(', $regex_ja_spec, '{1,})'))) = 'true'">
<xsl:attribute name="reference-orientation">0</xsl:attribute>
</xsl:if>
<xsl:if test="$char = '゜' or $char = '。' or $char = '﹒' or $char = '.'">
<!-- Rotate 180°:
U+309C KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK (゜)
U+3002 IDEOGRAPHIC FULL STOP (。)
U+FE52 SMALL FULL STOP (﹒)
U+FF0E FULLWIDTH FULL STOP (.)
-->
<xsl:attribute name="reference-orientation">-90</xsl:attribute>
</xsl:if>
<fo:block-container width="1em" role="SKIP"><!-- border="0.5pt solid blue" -->
<fo:block line-height="1em" role="SKIP">
<!-- <xsl:choose>
<xsl:when test="$horizontal_mode = 'true'">
<xsl:value-of select="$str"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$char"/>
</xsl:otherwise>
</xsl:choose> -->
<xsl:value-of select="$char"/>
</xsl:otherwise>
</xsl:choose>
</fo:block>
</fo:block-container>
</fo:inline-container>
<xsl:if test="$add_zero_width_space = 'true' and ($char = ',' or $char = '.' or $char = ' ' or $char = '·' or $char = ')' or $char = ']' or $char = '}')"><xsl:value-of select="$zero_width_space"/></xsl:if>
</fo:block>
</fo:block-container>
</fo:inline-container>
</xsl:otherwise>
</xsl:choose>

<xsl:if test="$horizontal_mode = 'false'">
<xsl:call-template name="insertVerticalChar">
<xsl:with-param name="str" select="substring($str, 2)"/>
<xsl:with-param name="writing-mode" select="$writing-mode"/>
<xsl:with-param name="reference-orientation" select="$reference-orientation"/>
<xsl:with-param name="add_zero_width_space" select="$add_zero_width_space"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$add_zero_width_space = 'true' and ($char = ',' or $char = '.' or $char = ' ' or $char = '·' or $char = ')' or $char = ']' or $char = '}')"><xsl:value-of select="$zero_width_space"/></xsl:if>
<!-- <xsl:if test="$horizontal_mode = 'false'"> -->
<xsl:call-template name="insertVerticalChar">
<xsl:with-param name="str" select="substring($str, 2)"/>
<xsl:with-param name="writing-mode" select="$writing-mode"/>
<xsl:with-param name="reference-orientation" select="$reference-orientation"/>
<xsl:with-param name="add_zero_width_space" select="$add_zero_width_space"/>
</xsl:call-template>
<!-- </xsl:if> -->
</xsl:if>
</xsl:otherwise>
</xsl:choose>
Expand All @@ -21363,13 +21369,13 @@
<xsl:param name="add_zero_width_space">false</xsl:param>
<fo:inline-container text-align="center"
alignment-baseline="central" width="1em" margin="0" padding="0"
text-indent="0mm" last-line-end-indent="0mm" start-indent="0mm" end-indent="0mm">
text-indent="0mm" last-line-end-indent="0mm" start-indent="0mm" end-indent="0mm" role="SKIP">
<xsl:if test="normalize-space($writing-mode) != ''">
<xsl:attribute name="writing-mode"><xsl:value-of select="$writing-mode"/></xsl:attribute>
<xsl:attribute name="reference-orientation">90</xsl:attribute>
</xsl:if>
<fo:block-container width="1em"> <!-- border="0.5pt solid green" -->
<fo:block line-height="1em">
<fo:block-container width="1em" role="SKIP"> <!-- border="0.5pt solid green" -->
<fo:block line-height="1em" role="SKIP">
<xsl:value-of select="$str"/>
</fo:block>
</fo:block-container>
Expand Down
52 changes: 46 additions & 6 deletions xslt_src/jis.international-standard.core.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,7 @@
</xsl:template>


<!-- replace horizontal to vertical oriented character -->
<xsl:template match="text()" mode="update_xml_step0">
<!-- from https://github.com/metanorma/docs/blob/main/109.adoc -->
<!--
Expand Down Expand Up @@ -2498,6 +2499,19 @@
<!-- Allocate non-Japanese text -->
<!-- ========================= -->

<xsl:template match="*[local-name() = 'span'][@class = 'horizontal']" mode="update_xml_step1" priority="3">
<xsl:element name="{$element_name_font_en_horizontal}" namespace="{$namespace_full}">
<xsl:apply-templates mode="update_xml_step1"/>
</xsl:element>
</xsl:template>
<xsl:template match="*[local-name() = 'span'][@class = 'horizontal']//text()" mode="update_xml_step1" priority="3">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="*[local-name() = 'span'][@class = 'norotate']" mode="update_xml_step1" priority="3">
<xsl:copy-of select="."/>
</xsl:template>

<!-- if vertical_layout = 'true', then font_en and font_en_bold are using for text rotation -->
<xsl:variable name="regex_en_base">\u00A0\u2002-\u200B\u3000-\u9FFF\uF900-\uFFFF</xsl:variable>
<xsl:variable name="regex_en_">
Expand Down Expand Up @@ -2584,17 +2598,43 @@
<xsl:template name="enclose_text_in_vertical_tag">
<xsl:param name="text" select="."/>
<xsl:param name="regex" select="$regex_en"/>
<xsl:variable name="text_vertical_" select="java:replaceAll(java:java.lang.String.new($text), $regex, concat($tag_font_en_vertical_open,'$1',$tag_font_en_vertical_close))"/>
<xsl:variable name="text_vertical">

<xsl:variable name="regex_two_digits">(^|[^\d])(\d{2,3})($|[^\d])</xsl:variable>

<xsl:variable name="text_width_two_or_three_digits_" select="java:replaceAll(java:java.lang.String.new($text), $regex_two_digits, concat('$1',$tag_font_en_horizontal_open,'$2',$tag_font_en_horizontal_close,'$3'))"/>
<xsl:variable name="text_width_two_or_three_digits">
<xsl:element name="text" namespace="{$namespace_full}">
<xsl:call-template name="replace_text_tags">
<xsl:with-param name="tag_open" select="$tag_font_en_vertical_open"/>
<xsl:with-param name="tag_close" select="$tag_font_en_vertical_close"/>
<xsl:with-param name="text" select="$text_vertical_"/>
<xsl:with-param name="tag_open" select="$tag_font_en_horizontal_open"/>
<xsl:with-param name="tag_close" select="$tag_font_en_horizontal_close"/>
<xsl:with-param name="text" select="$text_width_two_or_three_digits_"/>
</xsl:call-template>
</xsl:element>
</xsl:variable>
<xsl:copy-of select="xalan:nodeset($text_vertical)/*[local-name() = 'text']/node()"/>

<!-- <xsl:copy-of select="$text_width_two_or_three_digits"/> -->

<xsl:for-each select="xalan:nodeset($text_width_two_or_three_digits)/*[local-name() = 'text']/node()">

<xsl:choose>
<xsl:when test="self::text()">
<xsl:variable name="text_vertical_" select="java:replaceAll(java:java.lang.String.new(.), $regex, concat($tag_font_en_vertical_open,'$1',$tag_font_en_vertical_close))"/>
<xsl:variable name="text_vertical">
<xsl:element name="text" namespace="{$namespace_full}">
<xsl:call-template name="replace_text_tags">
<xsl:with-param name="tag_open" select="$tag_font_en_vertical_open"/>
<xsl:with-param name="tag_close" select="$tag_font_en_vertical_close"/>
<xsl:with-param name="text" select="$text_vertical_"/>
</xsl:call-template>
</xsl:element>
</xsl:variable>
<xsl:copy-of select="xalan:nodeset($text_vertical)/*[local-name() = 'text']/node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

<xsl:template name="enclose_text_in_horizontal_tag">
Expand Down

0 comments on commit bb628a2

Please sign in to comment.