1

AH Formatter で生成された PDF で、14 文字の文字列の後に強制的に改行したいと考えています。したがって、これは改行を試みていない私のxslコードです:

<xsl:attribute-set name="big" use-attribute-sets="bold">
  <xsl:attribute name="font-size">38pt</xsl:attribute>
  <xsl:attribute name="line-height">28.84pt</xsl:attribute>
  <xsl:attribute name="text-align">center</xsl:attribute>
  <xsl:attribute name="letter-spacing">1mm</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="small" use-attribute-sets="bold">
  <xsl:attribute name="font-size">27pt</xsl:attribute>
  <xsl:attribute name="line-height">27pt</xsl:attribute>
  <xsl:attribute name="text-align">center</xsl:attribute>
  <xsl:attribute name="letter-spacing">1mm</xsl:attribute>
</xsl:attribute-set>

<xsl:choose>
   <xsl:when test="string-length($count_cover)>=14">
      <fo:block xsl:use-attribute-sets="small">
         <xsl:apply-templates/>
      </fo:block>
    </xsl:when>
    <xsl:otherwise>          
      <fo:block xsl:use-attribute-sets="big">
         <xsl:apply-templates/>
      </fo:block>
   </xsl:otherwise>
</xsl:choose>

XSL-FO で改行を強制することは可能ですか?

4

3 に答える 3

2

タイトルが文字列に変換できる場合は、<fo:block/>改行として挿入できます。

<xsl:variable name="cover_title" as="xs:string" select="'Very Long Cover Title! Very Long Cover Title! Very Long Cover Title! '"/>
<xsl:variable name="count_cover" as="xs:integer" select="string-length($cover_title)"/>
<xsl:variable name="lf_position" as="xs:integer" select="14"/>

<xsl:template match="/">
    <xsl:choose>
        <xsl:when test="$count_cover gt $lf_position">
            <fo:block xsl:use-attribute-sets="small">
                <xsl:analyze-string select="$cover_title" regex=".{{1}}">
                    <xsl:matching-substring>
                        <xsl:value-of select="."/>
                        <xsl:if test="position() eq $lf_position">
                            <fo:block/>
                        </xsl:if>
                    </xsl:matching-substring>
                    <xsl:non-matching-substring/>
                </xsl:analyze-string>
            </fo:block>
        </xsl:when>
        <xsl:otherwise>
            <fo:block xsl:use-attribute-sets="big">
                <xsl:value-of select="$cover_title"/>
            </fo:block>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

結果:

<fo:block font-weight="bold" font-size="27pt" line-height="27pt" text-align="center" letter-spacing="1mm">Very Long Cove<fo:block/>r Title! Very Long Cover Title! Very Long Cover Title! </fo:block>

ただし、この方法では、単語の境界とハイフネーション制御が無視されます。本の表紙のタイトルを作るつもりなら、fo:block-container を使って AH Formatter の拡張機能を導入した方が良いでしょう。

  1. 表紙の固定位置とサイズのタイトルに fo:block-container を使用します。
  2. プロパティ @overflow="condense" を @axf:overflow-condense="font-size" で設定します。 https://www.antennahouse.com/product/ahf60/docs/ahf-ext.html#axf.overflow-condense
  3. fo:block-container 内に、タイトルコンテンツを格納する fo:block を配置します。
  4. AH Formatter は、コンテンツのボリュームに応じてフォント サイズを自動的に調整するため、目的の結果を得ることができます。

[例]

<fo:block-container position="absolute" top="..." left="..." width="..." height="..." overflow="condense" axf:overflow-condense="font-size" font-size="27pt" text-align="center">
    <fo:block>
       <fo:inline>Very Long Cover Title! Very Long Cover Title! Very Long Cover Title!</fo:inline>
    </fo:block>
</fo:block-container>
于 2016-04-27T06:50:11.273 に答える
2
  1. (部品番号などではなく) 単語を分割しようとしている場合、ハイフネーションを有効にすると、一定数の文字で分割するよりも良い結果が得られる場合があります。

  2. Inserting a line break in a PDF generated from XSL FO using <xsl:value-of> notesに対するこの回答のように、の代わりにlinefeed-treatment="preserve"and insertを使用できます。あなたができること&#xA;fo:block<xsl:value-of select="replace(., '(.{14})', '$1&#xA;')" />

  3. 代わりに、&#x200B;14 文字ごとにゼロ幅のスペース , を挿入して、AH Formatter をゼロ幅のスペースで改行させることができます。

<xsl:template match="text()">
      <xsl:value-of
          select="replace(replace(., '(\P{Zs}{14})', '$1&#x200B;'),
                          '&#x200B;(\p{Zs})',
                          '$1')" />
</xsl:template>`

内側replace()は 14 個の非スペース文字ごとに文字を挿入し、外側replace()は 15 番目の文字がスペース文字であった場合にそれを修正します。

プロポーショナル幅のフォントを使用している場合、14 文字の一部のシーケンス (たとえば、14 の固定幅のライニング番号を除く) は、他の文字よりも幅が広いまたは狭い場合があるため&#x200B;、より多くの文字の間に挿入して、AH Formatter がブレークする前にラインを埋めるために最善を尽くすことができます。

  1. axf:word-break="break-all"単語内でも改行を有効にするために使用できます。https://www.antennahouse.com/product/ahf63/ahf-ext.html#axf.word-breakを参照
于 2016-04-27T10:59:29.550 に答える